/* Sinwar Snake. Tokens: cards and lobby follow jslc:shell-context (html[data-theme]); the stage, HUD and deck are
   night artwork in both themes; standalone launches dark (spec 2.4). */
:root {
  --accent: #9bb01f;
  --accent-fill: color-mix(in srgb, var(--accent) 75%, #111a2d);
  --of-paper: #15110a;
  --of-ink: #f4f2dc;
  --muted: #c9c6ab;
  --eyebrow: #c8df4a;
  --of-warn: #e6a23c;
  --of-primary-soft: #9db8ff;
  --night: #0e0b07;
  --pressed: #556314;
  --btn-bg: color-mix(in srgb, var(--of-ink) 7%, transparent);
  --btn-line: color-mix(in srgb, var(--accent) 55%, transparent);
  --focus: #ffffff;
  --motion-press: 80ms;
  --motion-fast: 140ms;
  --motion-base: 200ms;
  --motion-sheet: 280ms;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  color-scheme: dark;
}
html[data-theme="light"] {
  --of-paper: #f4f1e3;
  --of-ink: #1f1c12;
  --muted: #555140;
  --eyebrow: #56660a;
  --pressed: #d9deb4;
  --btn-bg: color-mix(in srgb, var(--of-ink) 5%, #ffffff00);
  --btn-line: color-mix(in srgb, #56660a 45%, transparent);
  --focus: #1f1c12;
  color-scheme: light;
}
@media (display-mode: standalone) {
  html[data-theme="light"] {
    --of-paper: #15110a; --of-ink: #f4f2dc; --muted: #c9c6ab; --eyebrow: #c8df4a; --pressed: #556314;
    --btn-bg: color-mix(in srgb, var(--of-ink) 7%, transparent); --btn-line: color-mix(in srgb, var(--accent) 55%, transparent);
    --focus: #ffffff; color-scheme: dark;
  }
}

/* ---- PWA shell block, verbatim from spec 2.4 ---- */
html{touch-action:manipulation;-webkit-text-size-adjust:100%}
html,body{position:fixed;inset:0;margin:0;overflow:hidden;overscroll-behavior:none;background:var(--of-paper)}
.game-shell{display:grid;grid-template-rows:auto 1fr auto;height:100%;height:100dvh;
  --T:env(safe-area-inset-top,0px);--R:env(safe-area-inset-right,0px);--B:env(safe-area-inset-bottom,0px);--L:env(safe-area-inset-left,0px);--G:12px}
.hud{min-height:calc(44px + var(--T));padding:var(--T) calc(var(--R) + var(--G)) 0 calc(var(--L) + var(--G));background:#05070b;color:#f3f6ff}
.stage{position:relative;min-height:0;padding:8px calc(var(--R) + var(--G)) 8px calc(var(--L) + var(--G))}
#board{touch-action:none;display:block;margin:0 auto}
.deck{padding:0 calc(var(--R) + var(--G)) calc(var(--B) + 8px) calc(var(--L) + var(--G))}
.hud,.deck,.stage,canvas,button{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
button{touch-action:manipulation;-webkit-tap-highlight-color:transparent;min-width:44px;min-height:44px;font-size:16px}
button:active{background:var(--pressed);transition:background var(--motion-press,80ms) var(--ease-out,ease-out)}
.card-body{overflow:auto;overscroll-behavior:contain;min-height:0;touch-action:pan-y pinch-zoom}
input,select,textarea{font-size:max(16px,1rem);-webkit-user-select:text;user-select:text}
/* ---- end verbatim block ---- */

/* The one grid column never grows past the viewport: long HUD text or a wide canvas cannot push the page sideways. */
.game-shell {
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  overflow: hidden;
  background: var(--night);
  color: var(--of-ink);
  font: 500 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
button {
  font-family: inherit;
  font-weight: 750;
  color: inherit;
  background: var(--btn-bg);
  border: 1px solid var(--btn-line);
  border-radius: 8px;
  cursor: pointer;
}
button:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---- HUD: one row, never wraps ---- */
.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  box-sizing: border-box;
  min-width: 0;
  border-bottom: 1px solid #1d2230;
}
.hud-button {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  color: #f3f6ff;
  background: #121722;
  border-color: #2b3345;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}
.hud-button:active { background: #263049; }
.hud-button svg { width: 22px; height: 22px; fill: currentColor; }
.hud-button:focus-visible { outline-color: #ffffff; }
.hud-stats {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  gap: 6px;
  max-width: 560px;
  margin: 0 auto;
  overflow: hidden;
}
.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  white-space: nowrap;
  line-height: 1.1;
}
.hud-stat small {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .09em;
  color: #97a0b8;
}
.hud-stat b {
  font-size: clamp(12px, 3.7vw, 16px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #f3f6ff;
}
.hud-stat.best b { color: #c8df4a; }
#app[data-state="lobby"] #pause-button,
#app[data-state="over"] #pause-button,
#app[data-state="lobby"] .hud-stat:not(.best) { visibility: hidden; }

/* ---- stage ---- */
.stage { background: var(--night); overflow: hidden; }
#board { max-width: 100%; }
.speed-pill,
.stage-chip {
  position: absolute;
  top: 12px;
  left: 50%;
  translate: -50% 0;
  padding: 3px 12px;
  border-radius: 999px;
  font: 800 12px/1.4 system-ui, sans-serif;
  letter-spacing: .06em;
  pointer-events: none;
  white-space: nowrap;
}
.speed-pill { background: var(--of-warn); color: #1d1204; box-shadow: 0 2px 10px #0008; }
.stage-chip { top: 44px; background: #000c; color: #f4f2dc; border: 1px solid #9bb01f99; font-weight: 700; }

/* ---- deck (D-pad scheme only; swipe and halves leave it empty) ---- */
.deck { background: var(--night); }
.deck:empty { padding-top: 0; }
.dpad {
  display: flex;
  justify-content: center;
  gap: 8px;
  opacity: var(--deck-opacity, 1);
}
.deck button {
  width: var(--btn-w, 72px);
  height: var(--btn-h, 64px);
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  display: grid;
  place-items: center;
  color: #f4f2dc;
  background: #211b10;
  border: 1px solid #6f7a2c;
  border-radius: 12px;
  box-shadow: inset 0 -3px 0 #0006;
}
.deck button:active,
.deck button[data-held] { background: #556314; }
.deck svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.deck .sprint { width: 88px; height: 44px; align-self: center; font-size: 13px; letter-spacing: .06em; border-radius: 999px; border-color: var(--of-warn); color: var(--of-warn); }
#app[data-one-handed="true"] .dpad { display: grid; grid-template-columns: repeat(2, var(--btn-w)); justify-content: end; }
#app[data-one-handed="true"][data-handed="left"] .dpad { justify-content: start; }
#app[data-handed="left"] .dpad { flex-direction: row-reverse; }
#app[data-one-handed="true"][data-handed="left"] .dpad { direction: rtl; }
/* Landscape D-pad: left/right on one rail, up/down on the other, beside the board. */
#app[data-scheme="dpad"][data-landscape="true"] .stage {
  padding-left: calc(var(--L) + var(--G) + var(--rail, 88px));
  padding-right: calc(var(--R) + var(--G) + var(--rail, 88px));
}
#app[data-scheme="dpad"][data-landscape="true"] .deck {
  position: absolute;
  inset: calc(44px + var(--T)) 0 0 0;
  padding: 0;
  pointer-events: none;
  background: none;
}
#app[data-scheme="dpad"][data-landscape="true"] .dpad {
  height: 100%;
  display: grid;
  grid-template-columns: var(--btn-w) 1fr var(--btn-w);
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  align-content: center;
  padding: 0 calc(var(--R) + var(--G)) calc(var(--B) + 8px) calc(var(--L) + var(--G));
  box-sizing: border-box;
}
#app[data-scheme="dpad"][data-landscape="true"] .dpad button { pointer-events: auto; }
#app[data-landscape="true"] .dpad [data-dir="left"] { grid-area: 1 / 1; align-self: end; }
#app[data-landscape="true"] .dpad [data-dir="right"] { grid-area: 2 / 1; align-self: start; }
#app[data-landscape="true"] .dpad [data-dir="up"] { grid-area: 1 / 3; align-self: end; }
#app[data-landscape="true"] .dpad [data-dir="down"] { grid-area: 2 / 3; align-self: start; }

/* ---- card layers: below the HUD, above the stage; one translucent card each (PWA 9) ---- */
.card-layer,
.scrim {
  position: fixed;
  inset: calc(44px + var(--T)) 0 0 0;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  padding: 12px calc(var(--R) + 12px) calc(var(--B) + 12px) calc(var(--L) + 12px);
  background: rgba(4, 3, 1, .35);
  z-index: 4;
}
.scrim { inset: 0; padding-top: calc(var(--T) + 12px); z-index: 6; background: rgba(0, 0, 0, .35); }
.card {
  position: relative;
  box-sizing: border-box;
  width: min(28rem, 100%);
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y pinch-zoom;
  padding: 20px;
  color: var(--of-ink);
  background: color-mix(in srgb, var(--of-paper) 72%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid color-mix(in srgb, var(--of-ink) 14%, transparent);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
@supports not (backdrop-filter: blur(1px)) {
  .card { background: color-mix(in srgb, var(--of-paper) 94%, transparent); }
}
.explainer-card { max-height: calc(100dvh - var(--T) - var(--B) - 24px); }
.card h1 { font-size: 28px; font-weight: 800; line-height: 1.1; margin: 4px 0 0; letter-spacing: -.01em; }
.card h2 { font-size: 20px; font-weight: 800; line-height: 1.2; margin: 4px 0 8px; }
.card h3 { font-size: 15px; font-weight: 800; margin: 16px 0 4px; }
.card p { margin: 8px 0; }
.eyebrow { font-size: 12px; font-weight: 800; letter-spacing: .14em; color: var(--eyebrow); }
.lede { font-size: 16px; }
.muted { color: var(--muted); font-size: 14px; }

.primary {
  display: block;
  width: 100%;
  min-height: 52px;
  margin: 12px 0 8px;
  font-size: 18px;
  font-weight: 800;
  color: #ffffff;
  background: var(--accent-fill);
  border: 1px solid color-mix(in srgb, var(--accent) 70%, #000);
  border-radius: 10px;
  box-shadow: 0 2px 0 #0005, inset 0 1px 0 #ffffff33;
}
.primary:active { background: color-mix(in srgb, var(--accent) 55%, #111a2d); }
.ghost { background: var(--btn-bg); }
.row { display: flex; gap: 8px; }
.row > button { flex: 1 1 auto; min-width: 0; padding: 0 12px; font-size: 15px; white-space: nowrap; }
#lobby-row { flex-wrap: wrap; }
#lobby-row p { flex-basis: 100%; margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.text-button {
  display: block;
  margin: 8px auto 0;
  padding: 0 12px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Lobby */
.lobby-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ceo { position: relative; flex: none; margin: 0; width: 76px; height: 76px; }
.ceo-crop {
  position: relative;
  width: 76px;
  height: 76px;
  overflow: hidden;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #6f7a4a, #2b2e1c);
  border: 2px solid var(--accent);
  box-sizing: border-box;
}
.ceo-crop img { position: absolute; width: 352px; height: 176px; left: -30px; top: 2px; max-width: none; }
.ceo figcaption {
  position: absolute;
  bottom: -6px;
  left: 50%;
  translate: -50% 0;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-fill);
  color: #fff;
  font: 900 11px/1.5 system-ui, sans-serif;
  letter-spacing: .12em;
}
.ceo.small { width: 52px; height: 52px; }
.ceo.small .ceo-crop { width: 52px; height: 52px; }
.ceo.small .ceo-crop img { width: 240px; height: 120px; left: -20px; top: 1px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 0; }
.chip { padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; background: color-mix(in srgb, var(--accent) 22%, transparent); border: 1px solid var(--btn-line); }
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 14px 0 0;
  padding: 4px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--of-ink) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--of-ink) 14%, transparent);
}
.segmented button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}
.segmented button[aria-pressed="true"] {
  background: var(--of-paper);
  color: var(--of-ink);
  border-color: var(--btn-line);
  box-shadow: 0 1px 4px #0004, inset 0 -2px 0 var(--accent);
}
.best-line { margin: 4px 0 12px; font-size: 15px; color: var(--muted); text-align: center; }
.best-line b { color: var(--of-ink); font-variant-numeric: tabular-nums; }
@media (orientation: landscape) and (max-height: 540px) {
  .lobby-card { width: min(46rem, 100%); display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; align-items: start; }
  .lobby-card .lobby-intro { grid-row: span 5; }
  .lobby-card .segmented { margin-top: 0; }
}

/* Pause and game over */
.pause-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pause-grid button { font-size: 15px; white-space: nowrap; }
.pause-grid .wide { grid-column: 1 / -1; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.stat { padding: 8px 10px; border-radius: 8px; background: color-mix(in srgb, var(--of-ink) 6%, transparent); }
.stat small { display: block; font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--muted); }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
.score-big { display: flex; align-items: baseline; gap: 8px; margin: 4px 0; }
.score-big b { font-size: 36px; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--eyebrow); }
.top-five { margin: 4px 0 8px; padding: 0; list-style: none; font-size: 14px; font-variant-numeric: tabular-nums; }
.top-five li { display: flex; justify-content: space-between; padding: 3px 8px; border-radius: 6px; }
.top-five li.me { background: color-mix(in srgb, var(--accent) 25%, transparent); font-weight: 800; }
.warn { color: var(--of-warn); font-weight: 700; font-size: 14px; }
.wide-button { width: 100%; }
@media (orientation: landscape) and (max-height: 540px) {
  .card.split { width: min(46rem, 100%); display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; align-items: start; }
  .card.split h3 { margin-top: 0; }
  .card.split .primary { margin-top: 0; }
  .card.split .stat-grid { margin-bottom: 0; }
  .explainer-card { width: min(48rem, 100%); display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; align-items: start; }
  .explainer-card .ex-b > :first-child { margin-top: 52px; }
  .explainer-card .ex-b p { font-size: 15px; line-height: 1.35; margin: 6px 0; }
  .explainer-card .ex-b .muted, .explainer-card .ex-b .hint { font-size: 13px; }
  .explainer-card .ex-b h3 { margin-top: 8px; }
}

/* Explainer (PWA 7b form) */
.explainer-card header { padding-right: 52px; }
.explainer-close { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; padding: 0; display: grid; place-items: center; }
.explainer-close svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2; fill: none; }
.how-row { display: grid; grid-template-columns: 48px 1fr; gap: 12px; align-items: center; margin: 10px 0; }
.how-icon { width: 48px; height: 48px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; color: var(--eyebrow); }
.joke { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.hint { font-size: 13px; color: var(--muted); }
.foot { margin-top: 12px; text-align: center; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: opacity 120ms !important; transform: none !important; }
}
#sound-button[aria-pressed="false"] .sound-on,
#sound-button[aria-pressed="true"] .sound-off { display: none; }
/* Light theme: the 72 % paper card sits on a lightened layer so it reads as paper, not as grey over the night stage. */
html[data-theme="light"] .card-layer { background: rgba(244, 241, 227, .55); }
@media (display-mode: standalone) { html[data-theme="light"] .card-layer { background: rgba(4, 3, 1, .35); } }
