/* Blockfall base styles. Theme tokens per SPEC §8.3: these are the dark defaults; at startup Rust
   resolves dark/light/auto and the colour-blind palette and sets the tokens inline on <html>. */
:root {
  --bg: #0b0f1a;
  --panel: #131a2a;
  --grid: rgba(255, 255, 255, 0.05);
  --text: #e6ebf5;
  --accent: #7c9cff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { overscroll-behavior: none; }
#app { min-height: 100%; display: grid; place-items: center; padding: 16px; }

/* --cell (one board cell in CSS px) is set from Rust to fit the viewport. */
#game {
  --cell: 24px;
  --gap: 16px;
  display: grid;
  grid-template-columns: calc(var(--cell) * 3.5) calc(var(--cell) * 10) calc(var(--cell) * 3.5);
  grid-template-areas: "hold board next" "stats board next";
  grid-template-rows: auto 1fr;
  gap: var(--gap);
  align-items: start;
}
#hold-panel { grid-area: hold; }
#board-wrap { grid-area: board; position: relative; width: calc(var(--cell) * 10); height: calc(var(--cell) * 20);
  /* Gestures on the board must not scroll or zoom the page (SPEC §9.3). */
  touch-action: none; }
#next-panel { grid-area: next; }
#stats { grid-area: stats; }
h2 { margin: 0 0 6px; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.7; }
#hold, #next, #board { display: block; border-radius: 12px; background: var(--panel); box-shadow: inset 0 0 0 1px var(--grid); }
#hold { width: calc(var(--cell) * 3.5); height: calc(var(--cell) * 2.5); }
#next { width: calc(var(--cell) * 3.5); height: calc(var(--cell) * 12.5); }
#board { width: 100%; height: 100%; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35), inset 0 0 0 1px var(--grid); }

#stats { margin: 0; display: grid; gap: 10px; }
#stats div { background: var(--panel); border-radius: 12px; padding: 8px 12px; box-shadow: inset 0 0 0 1px var(--grid); }
#stats dt { font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.7; }
#stats dd { margin: 2px 0 0; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }

#game.paused #board-wrap { filter: blur(6px); }
#game.paused { opacity: 0.6; }

/* Level-up toast (SPEC §8.4); opacity is driven from Rust while the toast fades out,
   or left to `.show` alone under reduced motion (instant on/off, §8.5). */
#toast { position: absolute; left: 50%; top: 12%; transform: translateX(-50%); padding: 6px 16px;
  border-radius: 999px; background: var(--panel); color: var(--text); font-weight: 700; pointer-events: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35), inset 0 0 0 1px var(--grid); opacity: 0; }
#toast.show { opacity: 1; }

/* Screens (SPEC §12): the start menu, settings, game over and pause overlays. `[hidden]` must win
   over the `display` rules below, so it is forced with `!important`. */
[hidden] { display: none !important; }
.screen { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px;
  background: rgba(4, 7, 14, 0.72); overflow-y: auto; }
.panel { width: min(560px, 100%); max-height: 100%; overflow-y: auto; padding: 24px;
  border-radius: 18px; background: var(--panel); color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5), inset 0 0 0 1px var(--grid); }
.panel h1 { margin: 0 0 16px; font-size: 2rem; letter-spacing: 0.02em; }
.panel h2 { margin: 20px 0 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0 4px; }
button { font: inherit; cursor: pointer; padding: 10px 18px; border-radius: 10px;
  border: 1px solid var(--grid); background: rgba(255, 255, 255, 0.06); color: var(--text); }
button:hover { background: rgba(255, 255, 255, 0.12); }
button.primary { background: var(--accent); color: #0b0f1a; border-color: transparent; font-weight: 700; }
#menu .actions { flex-direction: column; }
#menu .actions button { width: 100%; }
#help-panel ul { margin: 0; padding-left: 20px; line-height: 1.7; }
#menu-scores-list { padding-left: 22px; line-height: 1.6; }
.hint { opacity: 0.7; font-size: 0.9rem; }
.new-high { color: var(--accent); font-weight: 700; }

#gameover-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 16px 0; }
#gameover-stats div { background: rgba(255, 255, 255, 0.05); border-radius: 10px; padding: 8px 12px;
  box-shadow: inset 0 0 0 1px var(--grid); }
#gameover-stats dt { font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.7; }
#gameover-stats dd { margin: 2px 0 0; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.settings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 18px; }
.settings-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }
.settings-grid label.check { flex-direction: row; align-items: center; gap: 8px; }
.settings-grid select, .settings-grid input[type="number"] { font: inherit; padding: 6px 8px;
  border-radius: 8px; border: 1px solid var(--grid); background: rgba(0, 0, 0, 0.25); color: var(--text); }
.settings-grid input[type="range"] { width: 100%; }

#bind-list { display: grid; gap: 6px; margin-bottom: 16px; }
.bind-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.bind-row button { min-width: 96px; font-variant-numeric: tabular-nums; }

#pause-btn { position: fixed; top: 12px; right: 12px; z-index: 5; font-size: 0.85rem; padding: 6px 12px; }

/* On-screen buttons (SPEC §9.3): only on narrow screens, and only while playing — Rust toggles
   `hidden`, the media query below keeps the row off wide screens. */
#touch-controls { display: none; }

#countdown { position: fixed; inset: 0; z-index: 8; display: grid; place-items: center;
  font-size: clamp(4rem, 18vw, 10rem); font-weight: 800; color: var(--text);
  text-shadow: 0 8px 40px rgba(0, 0, 0, 0.6); pointer-events: none; }

@media (max-width: 639px) {
  #app { padding: 8px; }
  #game {
    --gap: 8px;
    grid-template-columns: calc(var(--cell) * 3) calc(var(--cell) * 7);
    grid-template-areas: "hold next" "board board" "stats stats";
    grid-template-rows: auto;
    justify-content: center;
  }
  #board-wrap { justify-self: center; }
  #hold-panel h2, #next-panel h2 { display: none; }
  #hold { width: calc(var(--cell) * 3); height: calc(var(--cell) * 2); }
  #next { width: calc(var(--cell) * 7); height: calc(var(--cell) * 2); }
  #stats { grid-template-columns: repeat(3, 1fr); width: calc(var(--cell) * 10); }
  #stats div { padding: 4px 8px; }
  #touch-controls:not([hidden]) { display: flex; gap: 8px; width: min(100%, 26rem); margin-top: 8px;
    justify-content: center; touch-action: none; }
  #touch-controls button { flex: 1 1 0; min-width: 0; padding: 12px 4px; font-size: 1.05rem;
    line-height: 1; user-select: none; -webkit-user-select: none; }
}
