/* tetris — game.css
 * Layout of HUDs, board, virtual pad and overlay. */

/* Single source of truth for board size: --board-h (CSS pixels, no DPR/transform).
 * Set by app.js fitToScreen() based on available viewport, then multiplied by the
 * user's manual zoom (60–160%). All downstream sizes (canvas, HUDs, gap) derive
 * from this so the layout cannot disagree with itself. */
.game-wrap {
  /* v1.4.1: both --board-h AND --board-w set explicitly by app.js (applyBoardSize).
   * The JS computes an INTEGER cell size that fits both height & width budgets,
   * then sets --board-h = cell*20 and --board-w = cell*10. CSS never derives
   * either dimension from the other — that was the v1.4.0 bug: --board-w =
   * calc(--board-h/2) plus a CSS transition meant the canvas's width and height
   * could disagree mid-transition, leaving a phantom empty band at the bottom
   * of the board frame. No transitions on board dims — instant snap. */
  --board-h: 600px;
  --board-w: 300px;
  --hud-w: clamp(96px, calc(var(--board-h) * .22), 150px);
  --gap: clamp(8px, calc(var(--board-h) * .03), 22px);

  display: grid;
  /* v1.4.3: middle column is `auto` (not `var(--board-w)`) so .board-frame
   * shrink-wraps tightly around its canvas. Otherwise, with global border-box
   * box-sizing, the frame's content area = --board-w minus 18px (padding+border),
   * so the canvas (at --board-w) would overflow the frame's right edge by ~18px. */
  grid-template-columns: var(--hud-w) auto var(--hud-w);
  gap: var(--gap);
  justify-content: center;
  /* align-items: start makes HUD columns match the board's intrinsic height
   * instead of stretching to the tallest sibling. Combined with the board
   * canvas being height: var(--board-h), this guarantees the row's effective
   * height = the board's height — no empty space below the board on zoom-out. */
  align-items: start;
  /* No transform: scale() anywhere. Zoom is realized by changing --board-h
   * directly, which makes the canvas's CSS size change — so getBoundingClientRect()
   * and canvas.width agree, no aliasing, no smear, no empty space mismatch.
   * No CSS transition on --board-h / --board-w either: a 200 ms tween between
   * old and new sizes made renderer.resize() (called after a double-rAF) capture
   * an intermediate width while the final height kept growing — exactly what
   * produced the empty band reported in v1.4.0. Snap instantly instead. */
}

/* HUDs flex to fill the board's height: HOLD (or NEXT) sits flush at the top,
 * the remaining HUD block (STATS / KEYS) anchored at the bottom. This keeps
 * both side rails visually aligned with the top and bottom of the board
 * regardless of how tall the board ends up. */
.hud { height: var(--board-h); justify-content: space-between; }

.hud { display: flex; flex-direction: column; gap: 14px; }
.hud-block {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 12px;
  backdrop-filter: blur(8px);
}
.hud-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}
.hud-block canvas {
  display: block; width: 100%; height: auto;
  image-rendering: pixelated;
}
.hud-hint {
  margin-top: 6px;
  font-size: 10px;
  letter-spacing: .04em;
  color: var(--color-text-muted);
  text-align: center;
  line-height: 1.3;
  opacity: .85;
}
.hud-hint kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  padding: 1px 4px;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  background: var(--color-surface);
}
/* Show mobile hint only on coarse pointers (touch), desktop hint on fine pointers */
.hud-hint .hint-mobile { display: none; }
@media (pointer: coarse) {
  .hud-hint .hint-desktop { display: none; }
  .hud-hint .hint-mobile { display: inline; }
}
.stats { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; }
.stats dt { color: var(--color-text-muted); font-size: 12px; }
.stats dd {
  margin: 0;
  font-family: var(--font-game);
  font-variant-numeric: tabular-nums lining-nums;
  font-size: 15px; font-weight: 600;
  text-align: right;
}
.keys { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; font-size: 12px; color: var(--color-text-muted); }
.keys kbd { margin-right: 2px; }

/* Board */
.board-frame {
  position: relative;
  background: var(--color-board-bg);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 8px;
  /* v1.4.3: width:max-content + overflow:hidden together guarantee the frame
   * is sized exactly to its canvas (canvas drives width, frame's padding adds
   * to outer width) AND any future bleed-past-edge cannot escape the rounded
   * border. Fixes the right-overflow bug where cells were drawn past the frame. */
  width: max-content;
  overflow: hidden;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
html[data-theme="classic"] .board-frame { box-shadow: 0 0 0 1px var(--color-border); }
html[data-theme="color"] .board-frame { box-shadow: inset 0 0 0 2px var(--color-border); border-radius: 4px; }
html[data-theme="color"] .hud-block { border-radius: 4px; box-shadow: inset 0 0 0 2px var(--color-border); }

/* Board dimensions.
 * Base 300x600. On taller windows we expand both dims while preserving the
 * 1:2 aspect ratio so the playfield naturally fills more vertical space
 * without ever clipping. clamp() picks the size based on viewport height. */
/* Canvas derives directly from --board-h. No clamps, no dvh, no aspect-ratio
 * override — width is exactly half the height, always. JS snaps --board-h to
 * a multiple of ROWS (20) so the cell size (= width/10 = height/20) is an
 * integer number of CSS pixels — that's what guarantees the play grid
 * aligns pixel-perfectly with the board frame at every zoom level. */
#game-canvas {
  display: block;
  width: var(--board-w);
  height: var(--board-h);
  image-rendering: auto;
}

/* Overlay (title / pause / game over).
 * The full-board dim+blur backdrop. .overlay-card is a properly styled
 * floating card centered inside it — not a bare grid — so the Press Start
 * screen reads as a real modal: padded, rounded, bordered, glowed. */
/* v1.4.3: solid rgba background BEFORE color-mix() so iOS Safari (which can
 * fail color-mix() silently and end up transparent → invisible overlay) has
 * a reliable fallback. Same for the card. */
.overlay {
  position: absolute; inset: 8px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  background: rgba(0, 0, 0, .55);
  background: color-mix(in srgb, var(--color-board-bg) 78%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  text-align: center;
  padding: 16px;
  transition: opacity .2s;
}
.overlay[hidden] { display: none; }
.overlay-card {
  display: grid;
  gap: 14px;
  /* Sized to scale with the larger desktop boards while staying readable. */
  width: min(260px, calc(100% - 32px));
  padding: 24px 22px 22px;
  border-radius: 14px;
  background: rgba(20, 20, 24, .92);
  background: color-mix(in srgb, var(--color-surface) 92%, transparent);
  border: 1px solid var(--color-border);
  box-shadow:
    0 1px 0 rgba(255,255,255,.04) inset,
    0 18px 50px rgba(0,0,0,.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.overlay-card h1 {
  font-family: var(--font-game);
  font-size: 22px; margin: 0;
  letter-spacing: .04em;
}
.overlay-card p { margin: 0; color: var(--color-text-muted); font-size: 13px; }
.overlay-card .cta {
  background: var(--color-accent); color: var(--color-on-accent);
  border: none; padding: 12px 18px; border-radius: 10px;
  font: inherit; font-weight: 600; cursor: pointer;
  font-family: var(--font-game);
  letter-spacing: .04em;
  margin-top: 2px;
}
.overlay-card .cta:active { transform: scale(.97); }
.overlay-card small { color: var(--color-text-muted); font-size: 11px; margin-top: 4px; }

/* Virtual pad */
.vpad {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: min(360px, 100%);
}
body.vpad-on .vpad { display: grid; }
.vbtn {
  height: 56px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: 10px;
  font-size: 22px;
  font-family: inherit;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background .12s, transform .08s;
}
.vbtn:active { background: var(--color-surface-hover); transform: scale(.96); }
.vbtn-drop { background: color-mix(in srgb, var(--color-accent) 18%, var(--color-surface)); }

/* =====================================================================
 * MOBILE-ONLY HUD HIDDEN ON DESKTOP
 * The .mobile-bar element exists in the DOM for all viewports but must
 * NEVER show on desktop. The mobile media query below re-enables it.
 * ===================================================================== */
.mobile-bar { display: none; }

/* =====================================================================
 * MOBILE (v1.5.0 redesign) — fullscreen board + gesture-first
 * =====================================================================
 * Goals:
 *   - The BOARD is the entire screen, edge-to-edge. No padding, no margin,
 *     no frame border eating pixels. The play area is the primary surface.
 *   - A minimal top floating bar shows HOLD · stats · NEXT, overlaid on the
 *     board with a subtle backdrop so it never blocks play.
 *   - Gestures are the primary control: tap=rotate, swipe L/R=move,
 *     swipe down=soft drop, swipe up=hard drop, long-press=hold.
 *   - The vpad is a floating safety net: at very low opacity by default
 *     (so users can DISCOVER the gestures), reveals at full opacity when
 *     touched on a non-swipe area. Tap a button to act, tap outside to dismiss. */
@media (max-width: 760px) {
  /* v1.5.3 — lock the document so iOS Safari can't rubber-band scroll the
   * whole page during a soft-drop drag. `position: fixed` on body removes
   * the document from the scroll container entirely — stronger than just
   * `overflow: hidden`, which iOS sometimes still scrolls past.
   *
   * Using `100dvh` (not `100%`) so the body matches the *visual* viewport,
   * not the layout viewport. Without this iOS anchors `position: fixed`
   * children (vpad, mobile-bar) to a body that's taller than the painted
   * area, which pushed the vpad ~200px above the screen edge. */
  html, body {
    overflow: hidden;
    overscroll-behavior: none;
    position: fixed;
    width: 100%;
    height: 100dvh;
    touch-action: none;
  }

  /* TOPBAR — collapsed to nothing (its actions moved into .mobile-bar). */
  .topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    padding: 6px 10px;
    padding-top: max(6px, env(safe-area-inset-top));
    background: transparent;
    border-bottom: none;
    z-index: 30;
    pointer-events: none;
    display: none; /* mobile-bar replaces this entirely on phones */
  }

  /* STAGE — occupies the FULL viewport. Board is the hero. */
  .stage {
    gap: 0;
    padding: 0;
    height: 100dvh;
    width: 100vw;
    justify-content: center;
    align-items: stretch;
  }

  /* GAME-WRAP — just a positioning context. */
  .game-wrap {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    gap: 0;
    width: 100%;
    height: 100%;
    align-items: stretch;
    justify-items: center;
  }

  /* Side HUDs hidden on mobile (content mirrored into .mobile-bar). */
  .hud-left, .hud-right, .hud-keys { display: none; }

  /* BOARD-FRAME — edge-to-edge, no padding, no border, no rounded corners.
   * v1.5.2 — `touch-action: none` tells iOS we handle every gesture on the
   * board ourselves. Without this, swiping down still triggered Safari's
   * page-scroll / pull-to-refresh on top of our soft-drop handler, which
   * felt like the play area was sliding under the finger. */
  /* v1.5.4 — canvas pinned to the BOTTOM of the frame (was: centered).
   * The canvas snaps to an integer cell size, so there's almost always a
   * few px of slack between `--board-h` and the height budget. Centering
   * split that slack equally above & below, which left ~80–170 px of empty
   * black space *under* the bottom playfield row — right where the user
   * expected the vpad to live. Anchoring the canvas to the bottom shoves
   * all of the slack up under the floating mobile-bar instead. Net effect:
   * bottom playfield row hugs the home-indicator area, and the vpad
   * overlays the lowest few rows of the board (classic touch tetris). */
  .board-frame {
    grid-row: 1; grid-column: 1;
    padding: 0;
    border: none;
    border-radius: 0;
    width: 100%;
    height: 100%;
    align-self: stretch;
    justify-self: stretch;
    background: var(--color-board-bg);
    box-shadow: none;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    overflow: hidden;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
  }
  #game-canvas {
    width: var(--board-w);
    height: var(--board-h);
  }

  /* MOBILE BAR — single floating horizontal strip with HOLD · stats · NEXT + actions.
   * Positioned just below the safe-area top, overlaid on the board.
   *
   * v1.5.3 — tucked tighter to the status bar (no extra +6 padding) so the
   * top of the board gains ~14 px of vertical room. */
  .mobile-bar {
    position: fixed;
    top: max(4px, env(safe-area-inset-top));
    left: 8px; right: 8px;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 10px;
    background: rgba(15, 15, 20, .65);
    border: 1px solid rgba(255, 255, 255, .06);
    backdrop-filter: blur(6px) saturate(140%);
    -webkit-backdrop-filter: blur(6px) saturate(140%);
    font-family: var(--font-game);
    color: rgba(255, 255, 255, .92);
  }
  .mobile-bar .mb-mini {
    display: flex; align-items: center; gap: 6px;
    flex: 0 0 auto;
  }
  .mobile-bar .mb-mini-label {
    font-size: 8px; letter-spacing: .12em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .55);
  }
  .mobile-bar canvas {
    display: block;
    image-rendering: pixelated;
    background: rgba(0, 0, 0, .3);
    border-radius: 4px;
  }
  .mobile-bar #hold-canvas-mobile { width: 36px; height: 36px; }
  .mobile-bar #next-canvas-mobile { width: 30px; height: 36px; }
  /* Single horizontal row of stats: label val · label val · label val · label val.
   * Using inline-flex via grid auto-flow column keeps the chip compact at
   * 390 px and the values stay right of their labels. */
  .mobile-bar .mb-stats {
    flex: 1 1 auto;
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: 1fr;
    grid-auto-columns: auto;
    align-items: baseline;
    gap: 2px 8px;
    min-width: 0;
    font-variant-numeric: tabular-nums lining-nums;
    overflow: hidden;
  }
  .mobile-bar .mb-stat-l {
    font-size: 8px; letter-spacing: .1em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .5);
    margin-right: 2px;
  }
  .mobile-bar .mb-stat-v {
    font-size: 12px; font-weight: 600;
    text-align: left;
    color: rgba(255, 255, 255, .95);
    font-family: var(--font-game);
    margin-right: 4px;
  }
  .mb-actions {
    display: flex; gap: 4px; flex: 0 0 auto;
  }
  .mb-actions .iconbtn {
    height: 28px; min-width: 28px; font-size: 13px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .14);
    color: rgba(255, 255, 255, .82);
    border-radius: 6px;
  }

  /* VPAD — floating, very-low-opacity hint by default; full-opacity when
   * the user touches the board (revealed for ~3 s, see input.js).
   *
   * v1.5.5 — centered vertically (was: pinned to bottom). Centering on
   * the play area reads more naturally with the canvas pinned to the
   * bottom of the frame: the d-pad floats at thumb height in the middle
   * of the screen, exactly where the hand naturally rests. Use `top: 50%`
   * + `translate(-50%, -50%)` so the pad doesn't care about Safari
   * vs Chrome chrome differences — the viewport center is the viewport
   * center on every iOS browser. */
  .vpad {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 25;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: 1fr 1fr;
    gap: 5px;
    width: min(360px, calc(100vw - 16px));
    /* v1.5.4 — default opacity bumped slightly (0.08 → 0.15) so the pad is
     * actually visible as a hint when the game starts; touchstart still
     * reveals to full opacity (.96) for 3 s. */
    opacity: 0.15;
    transition: opacity .25s ease;
    pointer-events: none;
  }
  body.vpad-reveal .vpad {
    opacity: 0.96;
    pointer-events: auto;
  }
  /* body.vpad-on is ignored on mobile — the v1.5.0 hint-mode is always shown. */
  body.vpad-on .vpad { display: grid; }

  .vbtn {
    height: clamp(38px, 6dvh, 50px);
    font-size: clamp(16px, 4vw, 20px);
    border-radius: 9px;
    border: 1px solid rgba(255, 255, 255, .14);
    background: rgba(15, 15, 20, .82);
    color: rgba(255, 255, 255, .92);
  }
  .vbtn-drop {
    font-weight: 700;
    background: color-mix(in srgb, var(--color-accent) 32%, rgba(15, 15, 20, .82));
    border-color: color-mix(in srgb, var(--color-accent) 60%, rgba(255, 255, 255, .14));
  }

  /* OVERLAY (title / pause / game over) — fullscreen on mobile, solid bg.
   *
   * v1.5.6 — z-index bumped from 50 → 60 (above the mobile-bar at 30 and
   * vpad at 25), and we use `body:has(...)` below to suppress the vpad +
   * mobile-bar entirely while the overlay is visible so the title /
   * pause / game-over modal reads as a real 100 % takeover. The solid
   * bg is also bumped to .85 for a more decisive dim. */
  .overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .85);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-radius: 0;
    padding: 24px;
    z-index: 60;
  }
  .overlay-card {
    padding: 20px 18px;
    width: min(280px, calc(100% - 32px));
    gap: 12px;
    background: rgba(20, 20, 24, .98);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .overlay-card h1 { font-size: 24px; }
  .overlay-card p { font-size: 13px; }
  .overlay-card small { font-size: 10px; line-height: 1.5; }
  /* v1.5.6 — friendly heads-up on mobile that the game is better on a
   * real keyboard. Subtle, italic, slightly warmer color so it doesn't
   * compete with the cheat-sheet `<small>` above it. */
  .overlay-card .mobile-tip {
    font-size: 10px;
    font-style: italic;
    color: color-mix(in srgb, var(--color-accent) 60%, var(--color-text-muted));
    margin-top: 2px;
    line-height: 1.4;
  }

  /* v1.5.6 — while a modal (start overlay OR a native dialog) is open,
   * hide the floating mobile-bar and the vpad so the modal reads as a
   * real full-screen takeover. iOS Safari/Chrome sometimes paint
   * `position: fixed` siblings on top of the <dialog> top-layer; this
   * forces them out. `body:has(.overlay:not([hidden]))` catches the
   * title / pause / game-over screen; `body.dialog-open` (set from JS
   * via MutationObserver) catches the settings + game-over dialogs. */
  body:has(.overlay:not([hidden])) .mobile-bar,
  body:has(.overlay:not([hidden])) .vpad,
  body.dialog-open .mobile-bar,
  body.dialog-open .vpad {
    display: none !important;
  }

  /* Footer hidden on mobile to keep the single-screen rule. */
  .footer { display: none; }
}

/* Extra-small phones (<= 360 px) — shave a few more pixels from chrome. */
@media (max-width: 360px) {
  .mobile-bar { padding: 5px 6px; gap: 6px; }
  .mobile-bar #hold-canvas-mobile { width: 32px; height: 32px; }
  .mobile-bar #next-canvas-mobile { width: 26px; height: 32px; }
  .mobile-bar .mb-stat-v { font-size: 12px; }
  .vbtn { height: clamp(40px, 6.5dvh, 54px); font-size: 18px; }
}

/* Landscape phones — vpad shares the row with the board instead of stacking. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .stage {
    height: 100dvh;
    padding: 4px 6px;
  }
  .game-wrap {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto 1fr;
  }
  .game-wrap > .hud-left { grid-row: 1; grid-column: 1 / -1; }
  .game-wrap > .hud-right { grid-row: 1; grid-column: 1 / -1; justify-self: end; }
  .game-wrap > .board-frame { grid-row: 2; grid-column: 1; }
  .vpad {
    grid-row: 2; grid-column: 2;
    width: 220px;
    align-self: center;
  }
  .vbtn { height: clamp(44px, 12dvh, 56px); }
}

/* Short windows: shrink the overlay card a bit. Board sizing handled by
 * fitToScreen() via --board-h. */
@media (max-height: 720px) {
  .game-wrap { gap: 10px; }
  .overlay-card { padding: 18px 18px 16px; gap: 10px; }
}

/* Modern theme — overlay CTA (Press Start) uses a SHAKE animation.
 * A symmetric left-right wobble with zero net displacement: the button
 * starts and ends at exactly the same X, and swings briefly to each side
 * by only a few pixels. Followed by a long rest phase so the motion stays
 * an attention-grabber rather than a distraction. The translation amount
 * is small enough that the button never approaches its container edges. */
html[data-theme="modern"] .overlay-card .cta {
  position: relative;
  transform-origin: center;
}
@keyframes cta-shake {
  0%, 70%, 100% { transform: translateX(0); }
  74%  { transform: translateX(-4px); }
  78%  { transform: translateX(4px); }
  82%  { transform: translateX(-3px); }
  86%  { transform: translateX(3px); }
  90%  { transform: translateX(-2px); }
  94%  { transform: translateX(2px); }
}

/* =====================================================================
 * MODERN — extra animations and effects (all IN-PLACE, no horizontal drift)
 * ===================================================================== */
html[data-theme="modern"] .board-frame {
  box-shadow:
    0 0 0 1px var(--color-border),
    0 0 30px color-mix(in srgb, var(--color-accent) 18%, transparent),
    0 18px 60px rgba(0,0,0,.4);
  animation: modern-pulse 6s ease-in-out infinite;
}
@keyframes modern-pulse {
  0%, 100% { box-shadow: 0 0 0 1px var(--color-border), 0 0 24px color-mix(in srgb, var(--color-accent) 12%, transparent), 0 18px 60px rgba(0,0,0,.4); }
  50%      { box-shadow: 0 0 0 1px var(--color-border), 0 0 40px color-mix(in srgb, var(--color-accent) 28%, transparent), 0 18px 70px rgba(0,0,0,.5); }
}

html[data-theme="modern"] .hud-block {
  background:
    linear-gradient(135deg, rgba(255,255,255,.06) 0%, transparent 50%),
    var(--color-surface);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 8px 20px rgba(0,0,0,.18);
}

/* Brand mark: in-place breathing instead of full rotation.
 * A 4-block logo rotating 360° looked off-axis and unbalanced. Now it
 * gently scales/breathes and the inner rects twinkle in sequence —
 * still alive, never wandering. */
html[data-theme="modern"] .brand svg {
  animation: brand-breathe 3.2s ease-in-out infinite;
  transform-origin: center;
}
@keyframes brand-breathe {
  0%, 100% { transform: scale(1);    filter: drop-shadow(0 0 4px color-mix(in srgb, var(--color-accent) 30%, transparent)); }
  50%      { transform: scale(1.06); filter: drop-shadow(0 0 10px color-mix(in srgb, var(--color-accent) 55%, transparent)); }
}
html[data-theme="modern"] .brand svg rect {
  animation: modern-twinkle 2.4s ease-in-out infinite;
  transform-origin: center;
  transform-box: fill-box;
}
html[data-theme="modern"] .brand svg rect:nth-child(2) { animation-delay: .2s; }
html[data-theme="modern"] .brand svg rect:nth-child(3) { animation-delay: .4s; }
html[data-theme="modern"] .brand svg rect:nth-child(4) { animation-delay: .6s; }
@keyframes modern-twinkle {
  0%, 100% { opacity: .55; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.08); }
}

html[data-theme="modern"] #game-canvas {
  filter: drop-shadow(0 0 8px color-mix(in srgb, var(--color-accent) 25%, transparent));
}

/* Hold / Next panels: very subtle vertical breathing (max 2px) so the
 * panels feel alive without distracting from the falling pieces. */
html[data-theme="modern"] #hold-canvas,
html[data-theme="modern"] #next-canvas {
  animation: modern-float 5s ease-in-out infinite;
}
html[data-theme="modern"] #next-canvas { animation-delay: -2.5s; }
@keyframes modern-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-2px); }
}

/* CTA gradient + the shake animation. The gradient is static (no animated
 * background-position) so the only motion is the controlled shake. Glow
 * pulses gently along with each shake to give the impulse some weight. */
html[data-theme="modern"] .overlay-card .cta {
  background: linear-gradient(135deg,
    var(--color-accent) 0%,
    color-mix(in srgb, var(--color-accent) 60%, #9b5cff) 50%,
    var(--color-accent) 100%);
  box-shadow: 0 0 22px color-mix(in srgb, var(--color-accent) 38%, transparent);
  animation:
    cta-shake 2.4s ease-in-out infinite,
    cta-glow 2.4s ease-in-out infinite;
  will-change: transform, box-shadow;
}
@keyframes cta-glow {
  0%, 70%, 100% { box-shadow: 0 0 18px color-mix(in srgb, var(--color-accent) 30%, transparent); }
  85%           { box-shadow: 0 0 32px color-mix(in srgb, var(--color-accent) 60%, transparent); }
}

/* Stats values glow staggered — calm equalizer feel down the right rail. */
html[data-theme="modern"] .stats dd {
  text-shadow: 0 0 8px color-mix(in srgb, var(--color-accent) 30%, transparent);
  animation: stats-glow 2.8s ease-in-out infinite;
}
html[data-theme="modern"] .stats dd:nth-of-type(2) { animation-delay: .4s; }
html[data-theme="modern"] .stats dd:nth-of-type(3) { animation-delay: .8s; }
html[data-theme="modern"] .stats dd:nth-of-type(4) { animation-delay: 1.2s; }
@keyframes stats-glow {
  0%, 100% { text-shadow: 0 0 6px  color-mix(in srgb, var(--color-accent) 22%, transparent); }
  50%      { text-shadow: 0 0 14px color-mix(in srgb, var(--color-accent) 55%, transparent); }
}

/* Animated underline accent beneath each HUD label — fades in/out only. */
html[data-theme="modern"] .hud-label {
  position: relative;
}
html[data-theme="modern"] .hud-label::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: -3px;
  height: 1px;
  background: linear-gradient(90deg,
    transparent,
    color-mix(in srgb, var(--color-accent) 80%, transparent),
    transparent);
  animation: hud-underline-pulse 3s ease-in-out infinite;
  opacity: .6;
}
@keyframes hud-underline-pulse {
  0%, 100% { opacity: .25; }
  50%      { opacity: .9; }
}

/* Aurora wash behind the board — soft radial gradients that scale gently
 * in place. Clipped by .game-wrap so it never escapes the layout. */
html[data-theme="modern"] .game-wrap { position: relative; }
html[data-theme="modern"] .game-wrap::before {
  content: '';
  position: absolute; inset: -10px;
  background:
    radial-gradient(60% 40% at 30% 30%, color-mix(in srgb, var(--color-accent) 14%, transparent), transparent 70%),
    radial-gradient(50% 40% at 70% 70%, color-mix(in srgb, #9b5cff 14%, transparent), transparent 70%);
  filter: blur(30px);
  z-index: -1;
  pointer-events: none;
  animation: aurora-breathe 9s ease-in-out infinite;
}
@keyframes aurora-breathe {
  0%, 100% { opacity: .55; transform: scale(1); }
  50%      { opacity: .9;  transform: scale(1.04); }
}

/* Overlay card (Press Start / Pause / Game Over) — modern theme makeover.
 * Layered gradient background (subtle top sheen + accent tint), a brighter
 * accent border, and a soft accent-coloured vignette that pulses gently. */
html[data-theme="modern"] .overlay-card {
  background:
    linear-gradient(180deg, rgba(255,255,255,.06) 0%, transparent 40%),
    radial-gradient(120% 80% at 50% 0%, color-mix(in srgb, var(--color-accent) 12%, transparent) 0%, transparent 60%),
    color-mix(in srgb, var(--color-surface) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-accent) 35%, var(--color-border));
  animation: overlay-glow 4s ease-in-out infinite;
}
@keyframes overlay-glow {
  0%, 100% { box-shadow: 0 1px 0 rgba(255,255,255,.05) inset, 0 20px 60px rgba(0,0,0,.55), 0 0 30px color-mix(in srgb, var(--color-accent) 14%, transparent); }
  50%      { box-shadow: 0 1px 0 rgba(255,255,255,.07) inset, 0 24px 80px rgba(0,0,0,.6),  0 0 60px color-mix(in srgb, var(--color-accent) 30%, transparent); }
}

/* Classic theme — crisp single-pixel border, no glow, no blur. */
html[data-theme="classic"] .overlay-card {
  background: var(--color-surface);
  border-radius: 0;
  box-shadow: 0 0 0 1px var(--color-border);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  animation: none;
}

/* Color (Game Boy Color) theme — chunky pixel border, tight radius. */
html[data-theme="color"] .overlay-card {
  border-radius: 4px;
  box-shadow: inset 0 0 0 2px var(--color-border), 0 8px 20px rgba(0,0,0,.35);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  animation: none;
}


/* =====================================================================
 * CLASSIC — strict B&W, kill all theme bling
 * ===================================================================== */
html[data-theme="classic"] .board-frame { box-shadow: 0 0 0 1px var(--color-border); animation: none; }
html[data-theme="classic"] .brand svg, html[data-theme="classic"] .brand svg rect { animation: none; opacity: 1 !important; }
html[data-theme="classic"] #game-canvas { filter: none; }
html[data-theme="classic"] .hud-block { backdrop-filter: none; background: var(--color-surface); box-shadow: none; }
html[data-theme="classic"] .overlay { backdrop-filter: none; }
html[data-theme="classic"] .stats dd { text-shadow: none; }
html[data-theme="classic"] #hold-canvas, html[data-theme="classic"] #next-canvas { animation: none; }

/* =====================================================================
 * COLOR — chunky pixel borders, no glow
 * ===================================================================== */
html[data-theme="color"] .board-frame { box-shadow: inset 0 0 0 3px var(--color-border); border-radius: 4px; animation: none; }
html[data-theme="color"] .hud-block { border-radius: 4px; box-shadow: inset 0 0 0 2px var(--color-border); backdrop-filter: none; }
html[data-theme="color"] .overlay-card .cta { border-radius: 4px; box-shadow: inset 0 0 0 2px var(--color-border); }
html[data-theme="color"] .vbtn { border-radius: 4px; }
html[data-theme="color"] .brand svg, html[data-theme="color"] .brand svg rect { animation: none; opacity: 1 !important; }
html[data-theme="color"] #game-canvas { filter: none; image-rendering: pixelated; }
html[data-theme="color"] .stats dd { text-shadow: none; }
html[data-theme="color"] #hold-canvas, html[data-theme="color"] #next-canvas { animation: none; }

/* =====================================================================
 * Footer
 * ===================================================================== */
.footer {
  text-align: center;
  padding: 18px 12px 28px;
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1.7;
}
.footer a {
  color: var(--color-text);
  text-decoration: none;
  border-bottom: 1px solid var(--color-border);
  transition: color .15s, border-color .15s;
}
.footer a:hover { color: var(--color-accent); border-bottom-color: var(--color-accent); }
html[data-theme="modern"] .footer a:hover { text-shadow: 0 0 8px color-mix(in srgb, var(--color-accent) 50%, transparent); }
html[data-theme="color"] .footer { font-family: var(--font-game); font-size: 9px; line-height: 1.9; letter-spacing: .04em; }
.footer .sep { opacity: .4; margin: 0 8px; }
