/* ============================================================
   shared.css — retro terminal arcade
   Unified design system for the games hub and every game page.
   ============================================================ */

:root {
  /* Palette (dark, amber-CRT) */
  --bg:        #0a0a0a;
  --bg-2:      #0d0d0c;
  --panel:     #111110;
  --panel-2:   #161614;
  --fg:        #e8e8e6;
  --muted:     #8a8a85;
  --dim:       #555550;
  --border:    #1f1f1d;
  --border-hi: #3a3a36;
  --accent:    #f5c542;   /* amber */
  --accent-2:  #8affc1;   /* mint */
  --danger:    #ff6b6b;
  --warn:      #ffd166;

  /* Backward-compat aliases (older pages) */
  --text: var(--fg);

  /* Typography */
  --font-mono: "Fira Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Scale */
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;

  /* Radii / spacing */
  --r-sm: 3px;
  --r-md: 4px;
  --tap: 44px;     /* minimum tap target */
  --gutter: 16px;
}

/* Light mode — cream paper + ink, amber/mint retained darker */
@media (prefers-color-scheme: light) {
  :root {
    --bg:        #f4f1e8;
    --bg-2:      #ece8dc;
    --panel:     #ebe6d6;
    --panel-2:   #e0dac6;
    --fg:        #141412;
    --muted:     #6a6a62;
    --dim:       #a39e8c;
    --border:    #c9c2ac;
    --border-hi: #a39e8c;
    --accent:    #9a6a00;
    --accent-2:  #2a7a55;
    --danger:    #b83232;
    --warn:      #8a6a14;
  }
}
html[data-theme="light"] {
  --bg: #f4f1e8; --bg-2: #ece8dc; --panel: #ebe6d6; --panel-2: #e0dac6;
  --fg: #141412; --muted: #6a6a62; --dim: #a39e8c;
  --border: #c9c2ac; --border-hi: #a39e8c;
  --accent: #9a6a00; --accent-2: #2a7a55; --danger: #b83232; --warn: #8a6a14;
}
html[data-theme="dark"] {
  --bg: #0a0a0a; --bg-2: #0d0d0c; --panel: #111110; --panel-2: #161614;
  --fg: #e8e8e6; --muted: #8a8a85; --dim: #555550;
  --border: #1f1f1d; --border-hi: #3a3a36;
  --accent: #f5c542; --accent-2: #8affc1; --danger: #ff6b6b; --warn: #ffd166;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: var(--fs-md);
  line-height: 1.55;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--fg); text-decoration: none; }
a:hover { color: var(--accent); }

/* Subtle scanline atmosphere (hidden when user prefers reduced motion) */
body::before {
  content: "";
  position: fixed; inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0, transparent 2px,
    rgba(255,255,255,0.018) 2px, rgba(255,255,255,0.018) 3px
  );
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: overlay;
}
@media (prefers-reduced-motion: reduce) {
  body::before { display: none; }
}

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 20px max(28px, env(safe-area-inset-bottom));
  position: relative;
  z-index: 2;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 500;
  letter-spacing: 0.2px;
}
.topbar h1::before {
  content: "$ ";
  color: var(--accent);
  font-weight: 500;
}
.topbar .back {
  color: var(--muted);
  font-size: var(--fs-sm);
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
}
.topbar .back:hover { color: var(--fg); }

/* ---------- Panel ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px 18px 20px;
  position: relative;
}
.panel + .panel { margin-top: 16px; }

/* ---------- Rows + status ---------- */
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  justify-content: space-between;
  align-items: baseline;
}
.status {
  color: var(--muted);
  font-size: var(--fs-sm);
  margin: 0 0 10px;
  min-height: 1.4em;
  letter-spacing: 0.2px;
}
.status strong, .status b { color: var(--fg); font-weight: 500; }
.status .ok  { color: var(--accent-2); }
.status .hot { color: var(--accent); }
.status .bad { color: var(--danger); }

/* ---------- Buttons ---------- */
button, .btn {
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-md);
  padding: 8px 14px;
  min-height: var(--tap);
  font-size: var(--fs-sm);
  font-family: inherit;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, transform 0.04s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
button:hover, .btn:hover {
  background: var(--panel);
  border-color: var(--accent);
  color: var(--accent);
}
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

button.primary, .btn.primary {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}
button.primary:hover, .btn.primary:hover {
  background: rgba(245, 197, 66, 0.08);
}

button.ghost, .btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}
button.ghost:hover { color: var(--fg); border-color: var(--border-hi); background: transparent; }

button.danger { color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: rgba(255, 107, 107, 0.08); }

/* Icon-plus-label buttons in toolbars */
.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  min-width: var(--tap);
  justify-content: center;
}
.tool-btn .glyph { color: var(--dim); font-size: var(--fs-md); }
.tool-btn:hover .glyph { color: var(--accent); }

/* ---------- Focus ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible, .btn:focus-visible, select:focus-visible, input:focus-visible {
  outline-offset: 1px;
}

/* ---------- Controls rows + toolbars ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}
.controls.center { justify-content: center; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
  justify-content: center;
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid var(--border);
}

/* ---------- Chips (difficulty, filters) ---------- */
.chips {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-2);
}
.chip {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-family: inherit;
  font-size: var(--fs-sm);
  padding: 6px 12px;
  min-height: 34px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--r-sm);
}
.chip:hover { color: var(--fg); }
.chip[aria-pressed="true"], .chip.active {
  background: var(--panel);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--border-hi);
}

/* ---------- Keyboard hint pill ---------- */
.kbd {
  display: inline-block;
  background: var(--bg-2);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-sm);
  padding: 2px 7px;
  font-size: var(--fs-xs);
  color: var(--muted);
  font-family: var(--font-mono);
  letter-spacing: 0.4px;
}

/* ---------- Prompt box (homepage, win banners) ---------- */
.prompt {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 8px 12px;
  background: var(--panel);
}
.prompt .sigil, .prompt .\$ { color: var(--accent); }
.prompt .cmd { color: var(--fg); }
.caret {
  display: inline-block;
  width: 7px; height: 14px;
  background: var(--accent);
  vertical-align: -2px;
  animation: blink 1.1s steps(1) infinite;
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .caret { animation: none; } }

/* ---------- ASCII title block (per-game headers) ---------- */
.ascii {
  color: var(--dim);
  font-size: 10px;
  line-height: 1.15;
  letter-spacing: -0.5px;
  white-space: pre;
  user-select: none;
  margin: 0 0 14px;
  overflow-x: auto;
}
@media (min-width: 720px) { .ascii { font-size: 12px; } }

/* ---------- Game header bar (ASCII title + chips + actions) ---------- */
.gamehead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.gamehead .actions {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Section header ---------- */
.section-head {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  text-transform: uppercase;
  font-size: var(--fs-sm);
  letter-spacing: 1px;
  margin: 24px 0 14px;
}
.section-head::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, var(--border), transparent);
}

/* ---------- Board container utilities ---------- */
.board-wrap {
  display: flex;
  justify-content: center;
  margin: 6px 0;
}
.board, .mem, .ms, .board2048 {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- Win / toast banner ---------- */
.banner {
  border: 1px solid var(--accent);
  background: rgba(245, 197, 66, 0.08);
  color: var(--accent);
  padding: 10px 14px;
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  margin: 12px 0;
  animation: flash 0.6s ease-out;
}
.banner.win { color: var(--accent-2); border-color: var(--accent-2); background: rgba(138, 255, 193, 0.08); }
@keyframes flash {
  0%   { background: rgba(245, 197, 66, 0.35); }
  100% { background: rgba(245, 197, 66, 0.08); }
}
@media (prefers-reduced-motion: reduce) { .banner { animation: none; } }

/* ---------- Staggered board fade-in (used on cell load) ---------- */
@keyframes cell-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: cell-in 0.24s ease-out both; }
@media (prefers-reduced-motion: reduce) { .fade-in { animation: none; } }

/* ---------- Footer ---------- */
.footer-note {
  color: var(--muted);
  font-size: var(--fs-sm);
  margin-top: 18px;
  text-align: center;
}

/* ---------- Mobile polish ---------- */
@media (max-width: 560px) {
  .wrap { padding: 20px 14px 32px; }
  .topbar h1 { font-size: var(--fs-md); }
  .panel { padding: 14px; }
  .ascii { font-size: 9px; }
}
