/* ============================================================================
   Shared game chrome.

   Loaded by every page under /games and /embed/games. It deliberately holds only
   what belongs to *all* games - motion, focus, tap behaviour, typography
   smoothing. Anything that gives a game its own identity stays in that game's
   own <style> block, which loads after this file and therefore wins.
   ========================================================================== */

:root {
  --gx-brand:        #0A2540;
  --gx-brand-accent: #1a6aff;
  --gx-focus:        #1a6aff;
  --gx-focus-ring:   0 0 0 3px rgba(26, 106, 255, .45);
}

/* ── Typography and tap behaviour ──────────────────────────────────────── */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Every game builds its controls out of buttons and divs, and a 300ms tap delay
   on an older WebView reads as the game being slow rather than the browser. */
button,
[role="button"],
.gm-play-btn,
[class*="-btn"],
[class*="-key"],
[class*="-tile"],
[class*="-cell"],
[class*="-pad"],
[class*="-opt"] {
  touch-action: manipulation;
}

/* ── Focus ─────────────────────────────────────────────────────────────── */

/* Not one of the twenty games showed a focus ring, so a keyboard or switch user
   had no way to tell what was selected. :focus-visible keeps it off for mouse
   and touch, where a persistent ring after every tap looks like a bug. */
:focus-visible {
  outline: 2px solid var(--gx-focus);
  outline-offset: 2px;
  box-shadow: var(--gx-focus-ring);
  border-radius: 4px;
}

/* Canvas games take focus so arrow keys reach them; the ring belongs on the
   element the player is actually looking at. */
canvas:focus-visible {
  outline-offset: 4px;
}

/* ── Motion ────────────────────────────────────────────────────────────── */

/* Twenty-eight looping animations across the catalogue and no reduced-motion
   handling anywhere. Durations are collapsed rather than set to `none` on
   purpose: an animation with `both` or `forwards` fill holds its end state, and
   removing it outright would leave tiles that fade in stuck invisible. Reducing
   the duration keeps every end state and removes the movement. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Scrollbars ────────────────────────────────────────────────────────── */

/* Long pages (the How to Play sections) look unfinished next to a default
   desktop scrollbar. */
@supports (scrollbar-width: thin) {
  html { scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 6px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: #94a3b8; background-clip: content-box; }

/* ── Selection ─────────────────────────────────────────────────────────── */

::selection { background: rgba(26, 106, 255, .2); }


/* ============================================================================
   Shared chrome.

   The frame around a game - stats bar, overlay, buttons, How to Play - is the
   same product in every game. What differs is the colour, and that stays each
   game's own. A game opts in by setting four tokens on its wrapper:

     .g2-wrap {
       --gx-accent:  #8f7a66;   the game's colour
       --gx-ink:     #fff;      text that sits on the accent
       --gx-surface: #faf8ef;   the soft tint behind bars and tiles
       --gx-line:    #ede0c8;   the border that goes with that tint
     }

   Everything below then takes those on. No game needs to restate the layout,
   and 2048 still looks like 2048.
   ========================================================================== */

.gx-scope {
  --gx-accent:  #1a6aff;
  --gx-ink:     #ffffff;
  --gx-surface: #eff6ff;
  --gx-line:    #dbeafe;
  --gx-text:    #1f2937;
  --gx-muted:   #6b7280;
  --gx-overlay: rgba(255, 255, 255, .97);
  --gx-panel:   #ffffff;
  --gx-display: 'Nunito', 'Poppins', sans-serif;
  --gx-body:    'Poppins', sans-serif;
}

/* Snake is built on a near-black board and would read as a different product if the
   shared chrome forced it light. Only the surfaces flip; the layout is identical. */
.gx-dark {
  --gx-text:    #f8fafc;
  --gx-muted:   rgba(255, 255, 255, .58);
  --gx-overlay: rgba(8, 20, 12, .94);
  --gx-panel:   rgba(255, 255, 255, .04);
}
.gx-dark .gx-btn-ghost { border-color: rgba(255, 255, 255, .18); color: rgba(255, 255, 255, .72); }
.gx-dark .gx-hint      { color: rgba(255, 255, 255, .42); }

/* ── Stats bar ─────────────────────────────────────────────────────────── */

.gx-top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 16px;
  background: var(--gx-surface);
  border-bottom: 2px solid var(--gx-line);
}
.gx-top-item {
  display: flex; flex-direction: column; align-items: center;
  min-width: 52px;
}
.gx-top-lbl {
  font-family: var(--gx-body);
  font-size: .56rem; font-weight: 800;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--gx-accent); white-space: nowrap;
}
.gx-top-val {
  font-family: var(--gx-display);
  font-size: 1rem; font-weight: 900; line-height: 1.2;
  color: var(--gx-text);
}
.gx-top-val.is-warn { color: #ef4444; }
/* Some games need two controls up here (2048 has Undo as well as New). */
.gx-top-actions { display: flex; gap: 6px; flex: none; }

/* Mounted by game-sound.js. Sized to the 44px touch target rather than the glyph. */
.gx-sound-btn {
  flex: none; border: none; background: none; cursor: pointer;
  font-size: 1.05rem; line-height: 1;
  min-width: 34px; min-height: 34px; padding: 4px 6px;
  border-radius: 50px; opacity: .75;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .12s, background .12s;
}
.gx-sound-btn:hover { opacity: 1; background: rgba(0, 0, 0, .05); }
.gx-dark .gx-sound-btn:hover { background: rgba(255, 255, 255, .1); }

/* ── Buttons ───────────────────────────────────────────────────────────── */

.gx-btn-sm {
  flex: none; border: none; cursor: pointer;
  background: var(--gx-accent); color: var(--gx-ink);
  border-radius: 50px; padding: 8px 16px;
  font-family: var(--gx-body); font-size: .76rem; font-weight: 800;
  -webkit-tap-highlight-color: transparent;
}
.gx-btn {
  border: none; cursor: pointer;
  background: var(--gx-accent); color: var(--gx-ink);
  border-radius: 50px; padding: 13px 34px;
  font-family: var(--gx-display); font-size: 1rem; font-weight: 800;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
  transition: transform .12s;
  -webkit-tap-highlight-color: transparent;
}
.gx-btn:active { transform: scale(.96); }
.gx-btn-ghost {
  background: none; border: 2px solid #e5e7eb; color: var(--gx-muted);
  border-radius: 50px; padding: 9px 22px; cursor: pointer;
  font-family: var(--gx-display); font-size: .84rem; font-weight: 700;
  text-decoration: none; display: inline-block;
  -webkit-tap-highlight-color: transparent;
}

/* ── Overlay ───────────────────────────────────────────────────────────── */

.gx-overlay {
  position: absolute; inset: 0; z-index: 70;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; padding: 24px; text-align: center;
  background: var(--gx-overlay);
  backdrop-filter: blur(6px);
  overflow-y: auto;
}
.gx-overlay.hidden { display: none; }

/* Some games have a light card but a *dark* overlay dropped over the play area - balloon-pop
   and catch-the-fruit both do. Flipping the whole game to .gx-dark would wrongly darken their
   light How to Play panels, so the inversion is scoped to the overlay alone. Result tiles go
   translucent too: a white value on a light tile would be invisible. */
.gx-overlay-dark {
  --gx-text:  #f8fafc;
  --gx-muted: rgba(255, 255, 255, .72);
}
.gx-overlay-dark .gx-result {
  background: rgba(255, 255, 255, .1);
  border-color: rgba(255, 255, 255, .18);
}
.gx-overlay-dark .gx-btn-ghost {
  border-color: rgba(255, 255, 255, .3);
  color: rgba(255, 255, 255, .85);
}
.gx-ov-emoji { font-size: 3rem; line-height: 1; }
.gx-ov-title {
  margin: 0; font-family: var(--gx-display);
  font-size: 1.8rem; font-weight: 900; color: var(--gx-text);
}
.gx-ov-sub {
  margin: 0; max-width: 300px; line-height: 1.6;
  font-family: var(--gx-body); font-size: .9rem; color: var(--gx-muted);
}

/* ── Result tiles ──────────────────────────────────────────────────────── */

.gx-result-row {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 10px; margin: 4px 0;
}
.gx-result {
  background: var(--gx-surface); border: 2px solid var(--gx-line);
  border-radius: 14px; padding: 10px 18px;
}
.gx-result-val {
  font-family: var(--gx-display); font-size: 1.5rem;
  font-weight: 900; line-height: 1.1; color: var(--gx-text);
}
.gx-result-lbl {
  font-family: var(--gx-body); font-size: .58rem; font-weight: 800;
  letter-spacing: .06em; text-transform: uppercase; color: var(--gx-accent);
}

/* ── Picker list (difficulty, mode, size) ──────────────────────────────── */

.gx-list {
  display: flex; flex-direction: column; gap: 8px;
  width: 100%; max-width: 270px; margin-top: 4px;
}
.gx-list-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; cursor: pointer;
  background: var(--gx-surface); border: 2px solid var(--gx-line);
  border-radius: 14px; padding: 12px 16px;
  font-family: var(--gx-body);
  transition: border-color .12s;
}
.gx-list-item:hover { border-color: var(--gx-accent); }
.gx-list-name { font-size: .95rem; font-weight: 800; color: var(--gx-text); }
.gx-list-meta { font-size: .68rem; font-weight: 700; color: var(--gx-accent); text-align: right; }

/* ── Hint line ─────────────────────────────────────────────────────────── */

.gx-hint {
  font-family: var(--gx-body); font-size: .76rem; font-weight: 600;
  color: #9ca3af; text-align: center; min-height: 16px;
}

/* ── How to Play ───────────────────────────────────────────────────────── */

.gx-how {
  padding: 30px 20px 48px;
  background: var(--gx-surface);
  border-top: 2px solid var(--gx-line);
}
.gx-how h2 {
  margin: 0 0 20px; text-align: center;
  font-family: var(--gx-display); font-size: 1.3rem; font-weight: 800;
  color: var(--gx-accent);
}
.gx-how-grid {
  display: grid; gap: 12px; max-width: 520px; margin: 0 auto;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.gx-how-card {
  background: var(--gx-panel); border: 2px solid var(--gx-line);
  border-radius: 16px; padding: 16px 12px; text-align: center;
}
.gx-how-card .icon { display: block; font-size: 1.9rem; margin-bottom: 8px; }
.gx-how-card h3 {
  margin: 0 0 4px; font-family: var(--gx-display);
  font-size: .84rem; font-weight: 800; color: var(--gx-text);
}
.gx-how-card p {
  margin: 0; font-family: var(--gx-body);
  font-size: .77rem; line-height: 1.5; color: var(--gx-muted);
}
