/* ══════════════════════════════════════════════════════════════════════
   OUROBOROS

   The canvas does the spectacle; the chrome around it stays quiet and cold
   so the only saturated light on the page is the snake. Panels are glass over
   the live board — the game keeps breathing behind every menu.
   ══════════════════════════════════════════════════════════════════════ */

:root {
  --void:        #04050c;
  --void-2:      #080b16;
  --ink:         #e8f1ff;
  --ink-dim:     #8fa3c4;
  --ink-faint:   #5a6b87;

  --cyan:        #5ef0ff;
  --mint:        #8affd4;
  --gold:        #ffc24d;
  --magenta:     #e05cff;
  --danger:      #ff3b5c;

  --line:        rgba(94, 240, 255, 0.18);
  --line-strong: rgba(94, 240, 255, 0.42);
  --glass:       rgba(8, 12, 24, 0.72);
  --glass-2:     rgba(12, 17, 32, 0.9);

  --font-display: 'Space Grotesk', 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --pad: clamp(8px, 1.6vmin, 18px);
  --radius: 4px;
  --shadow-glow: 0 0 24px rgba(94, 240, 255, 0.16);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--void);
  color: var(--ink);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  /* A game you can accidentally text-select mid-run is a game you lose. */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── frame ─────────────────────────────────────────────────────────── */

#app {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--pad);
  padding: var(--pad) var(--pad) 0;
  padding-bottom: max(var(--pad), env(safe-area-inset-bottom));
  max-width: min(96vw, 1100px);
  margin: 0 auto;
}

/* ── HUD ───────────────────────────────────────────────────────────── */

#hud {
  display: grid;
  gap: 6px;
  transition: opacity 320ms ease, transform 320ms ease;
}
#app[data-screen="title"] #hud,
#app[data-screen="help"] #hud,
#app[data-screen="settings"] #hud {
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}

.hud-row { display: grid; align-items: center; }
.hud-top { grid-template-columns: 1fr auto 1fr; gap: var(--pad); }
.hud-cell { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.hud-right { align-items: flex-end; text-align: right; }
.hud-center { align-items: center; }

.hud-label {
  font-size: clamp(9px, 1.3vmin, 11px);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--cyan);
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-sub {
  font-family: var(--font-mono);
  font-size: clamp(9px, 1.25vmin, 11px);
  color: var(--ink-dim);
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(26px, 5.4vmin, 44px);
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 0 18px rgba(94, 240, 255, 0.55), 0 0 46px rgba(94, 240, 255, 0.22);
  transition: transform 90ms ease-out, text-shadow 200ms ease;
}
.score.bump { transform: scale(1.16); }
.score.hot { text-shadow: 0 0 20px rgba(255, 194, 77, 0.7), 0 0 54px rgba(255, 138, 60, 0.35); }

#hud-chain { color: var(--gold); letter-spacing: 0.16em; text-transform: uppercase; }

.hud-meters {
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: var(--pad);
}

.meter {
  position: relative;
  height: 14px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}
.meter-fill {
  position: absolute; inset: 0;
  transform-origin: left center;
  background: linear-gradient(90deg, #2fd9a5, var(--mint) 60%, #d9fff0);
  box-shadow: 0 0 14px rgba(125, 255, 212, 0.45);
  transition: transform 120ms linear, background 400ms ease, box-shadow 400ms ease;
}
.meter.low .meter-fill {
  background: linear-gradient(90deg, #b3321f, var(--gold));
  box-shadow: 0 0 18px rgba(255, 144, 64, 0.6);
  animation: meter-panic 620ms ease-in-out infinite;
}
@keyframes meter-panic { 50% { opacity: 0.55; } }
.meter-label {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 8px; letter-spacing: 0.3em; text-transform: uppercase;
  color: rgba(4, 5, 12, 0.75); font-weight: 700;
  mix-blend-mode: hard-light;
}
/* Pure mode has no light meter at all — a permanently full, greyed-out bar
   is a control that lies about being disabled. */
.meter.off { display: none; }
.meter.idle { opacity: 0.28; }

.fangs, .length {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
  font-size: clamp(9px, 1.3vmin, 11px);
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-faint);
  transition: color 240ms ease, filter 240ms ease;
}
.fangs svg { width: 15px; height: 15px; fill: currentColor; }
.fangs.ready { color: var(--gold); filter: drop-shadow(0 0 7px rgba(255, 194, 77, 0.7)); }
.fangs.off { display: none; }
.length {
  /* Without a rule between them, "FANGS" and "8 SEG" read as one phrase. */
  padding-left: 10px;
  border-left: 1px solid var(--line);
}
#hud.no-fangs .length { padding-left: 0; border-left: none; }
.length .unit { opacity: 0.45; }

/* ── stage ─────────────────────────────────────────────────────────── */

#stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  min-width: 0;
  /* Makes cqh below resolve against the stage, which is the only box that
     knows how much room is left after the HUD and the pad have taken theirs. */
  container-type: size;
}

/* The largest square that fits the space left over. */
#board {
  display: block;
  width: min(100%, 100cqh);
  aspect-ratio: 1;
  border-radius: var(--radius);
  background: var(--void);
  box-shadow:
    0 0 0 1px rgba(94, 240, 255, 0.1),
    0 24px 90px rgba(0, 0, 0, 0.7),
    0 0 120px rgba(47, 143, 255, 0.07);
}

/* ── toasts ────────────────────────────────────────────────────────── */

#toasts {
  position: absolute;
  left: 50%; top: 12%;
  transform: translateX(-50%);
  display: grid; gap: 4px; justify-items: center;
  pointer-events: none;
  z-index: 4;
}
.toast {
  font-family: var(--font-mono);
  font-size: clamp(11px, 1.9vmin, 15px);
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--cyan);
  text-shadow: 0 0 16px currentColor;
  animation: toast 1500ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  white-space: nowrap;
}
.toast.gold { color: var(--gold); }
.toast.magenta { color: var(--magenta); }
.toast.danger { color: var(--danger); }
@keyframes toast {
  0%   { opacity: 0; transform: translateY(10px) scale(0.92); }
  14%  { opacity: 1; transform: translateY(0) scale(1); }
  72%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-16px); }
}

/* ── screens ───────────────────────────────────────────────────────── */

.screen {
  position: absolute; inset: 0;
  /* An explicit 1fr track, not just place-items: an auto-sized row is an
     indefinite height, and the panel's `max-height: 100%` silently resolves to
     `none` against it — letting tall panels grow past the viewport. */
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  padding: var(--pad);
  /* Light enough that the attract run keeps playing visibly behind the menu —
     the first thing you see should be the game, not a splash image. */
  background: radial-gradient(ellipse at center, rgba(4, 5, 12, 0.34), rgba(2, 3, 8, 0.78));
  backdrop-filter: blur(3px) saturate(0.85);
  -webkit-backdrop-filter: blur(3px) saturate(0.85);
  z-index: 5;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 200ms;
}
.screen.on { opacity: 1; visibility: visible; }
.screen.on .panel { animation: panel-in 280ms cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes panel-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
}

.panel {
  --panel-pad: clamp(16px, 3.2vmin, 30px);
  width: min(100%, 400px);
  max-height: 100%;
  padding: var(--panel-pad);
  display: grid; gap: clamp(12px, 2.2vmin, 20px);
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.1);
  -webkit-backdrop-filter: blur(16px) saturate(1.1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-glow), 0 30px 80px rgba(0, 0, 0, 0.6);
  /* clipped corner — a small tell that this is a machine, not a webpage */
  clip-path: polygon(0 14px, 14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%);
  /* Non-negotiable: clip-path silently eats anything past max-height, so a
     panel that outgrows a short viewport would hide its own buttons. Scrolling
     is ugly here; a menu with no reachable Play button is broken. */
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.panel::-webkit-scrollbar, .panel-body::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-track, .panel-body::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb, .panel-body::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 3px;
}
/* These manage their own inner scroll region — see .panel-body. */
.panel-scroll { overflow: hidden; }

/* The action row sticks to the bottom of its panel. On a short viewport (a
   landscape phone, a small iframe) the content above it can outgrow the panel;
   this guarantees Play / Again / Back are on screen without hunting for them.
   The negative margin lets it sit flush against the panel's padding edge so
   content scrolls under it rather than into a dead gap. */
.panel:not(.panel-scroll) > .stack.row,
.panel > .title-actions {
  position: sticky;
  bottom: calc(-1 * var(--panel-pad));
  margin-bottom: calc(-1 * var(--panel-pad));
  padding-bottom: var(--panel-pad);
  background: var(--glass-2);
  box-shadow: 0 -14px 16px -10px var(--glass-2);
}
.panel-wide { width: min(100%, 560px); }

/* Long panels scroll their middle only, so the heading and the action that
   closes them are always on screen. A panel whose only button is below the
   fold is a dead end on a short screen. */
.panel-scroll { grid-template-rows: auto minmax(0, 1fr) auto; }
.panel-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  gap: clamp(12px, 2.2vmin, 20px);
  /* fades the cut-off edge so it reads as "more below" */
  mask-image: linear-gradient(#000 calc(100% - 22px), transparent);
  -webkit-mask-image: linear-gradient(#000 calc(100% - 22px), transparent);
  padding-bottom: 4px;
}

.panel h2 {
  margin: 0;
  font-size: clamp(15px, 2.4vmin, 19px);
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--cyan);
}
.panel h3 {
  margin: 6px 0 0;
  font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--ink-dim);
}
.panel p { margin: 0; color: var(--ink-dim); line-height: 1.55; font-size: 13px; }

.stack { display: grid; gap: 8px; }
.stack.row {
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: stretch;
}
@media (max-width: 420px) {
  .stack.row { grid-auto-flow: row; }
}

/* ── title ─────────────────────────────────────────────────────────── */

.panel-title { width: min(100%, 440px); text-align: center; justify-items: center; }
.wordmark { display: grid; justify-items: center; gap: 6px; }
.sigil {
  width: clamp(64px, 13vmin, 96px);
  height: auto;
  filter: drop-shadow(0 0 22px rgba(94, 240, 255, 0.45));
  animation: sigil-spin 26s linear infinite;
}
@keyframes sigil-spin { to { transform: rotate(360deg); } }

.wordmark h1 {
  margin: 0;
  font-size: clamp(28px, 7.2vmin, 52px);
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1;
  background: linear-gradient(100deg, var(--cyan), var(--mint) 45%, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 26px rgba(94, 240, 255, 0.3));
}
.tagline {
  font-size: clamp(10px, 1.7vmin, 12px) !important;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--ink-faint) !important;
}

.modes { display: grid; gap: 6px; width: 100%; }
.mode {
  display: grid;
  /* Named areas, not auto-placement: the tagline is hidden on short screens,
     and with implicit placement its removal reshuffles the name and the score
     into each other's columns. */
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "dot name best"
    "dot tag  best";
  align-items: center;
  gap: 2px 10px;
  padding: 10px 12px;
  text-align: left;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
  border-left: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  color: var(--ink-dim);
  font-family: inherit;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}
.mode:hover { background: rgba(94, 240, 255, 0.05); color: var(--ink); }
.mode[aria-checked="true"] {
  border-left-color: var(--cyan);
  background: rgba(94, 240, 255, 0.08);
  color: var(--ink);
  box-shadow: inset 0 0 30px rgba(94, 240, 255, 0.06);
}
.mode-name {
  grid-area: name;
  font-size: 13px; font-weight: 500; letter-spacing: 0.16em; text-transform: uppercase;
}
.mode-tag { grid-area: tag; font-size: 11px; color: var(--ink-faint); }
.mode-best {
  grid-area: best;
  font-family: var(--font-mono); font-size: 11px; color: var(--gold);
  text-align: right; white-space: nowrap;
}
.mode-dot {
  grid-area: dot;
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; opacity: 0.35;
}
.mode[aria-checked="true"] .mode-dot {
  opacity: 1; color: var(--cyan); box-shadow: 0 0 10px currentColor;
}

.title-actions {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  width: 100%;
}
.title-actions #btn-play { grid-column: 1 / -1; }
.hint {
  font-size: 10px !important;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint) !important;
}

/* ── buttons ───────────────────────────────────────────────────────── */

.btn {
  appearance: none;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 2px;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, box-shadow 140ms ease, transform 90ms ease;
}
.btn:hover { background: rgba(94, 240, 255, 0.1); border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.btn-primary {
  color: var(--void);
  background: linear-gradient(100deg, var(--cyan), var(--mint));
  border-color: transparent;
  font-weight: 700;
  box-shadow: 0 0 26px rgba(94, 240, 255, 0.3);
}
.btn-primary:hover {
  background: linear-gradient(100deg, #7ff5ff, #a6ffe1);
  box-shadow: 0 0 38px rgba(94, 240, 255, 0.45);
}
.btn-ghost { background: none; border-color: rgba(255, 255, 255, 0.08); color: var(--ink-faint); }
.btn-ghost:hover { color: var(--danger); border-color: rgba(255, 59, 92, 0.4); background: rgba(255, 59, 92, 0.06); }

.btn-icon { padding: 10px; display: grid; place-items: center; }
.btn-icon svg { width: 17px; height: 17px; fill: currentColor; }
.btn-icon.muted { color: var(--ink-faint); opacity: 0.5; }

/* ── game over ─────────────────────────────────────────────────────── */

.panel-over { text-align: center; justify-items: center; }
.death-cause {
  font-size: 12px !important;
  letter-spacing: 0.24em; text-transform: uppercase;
  color: var(--danger) !important;
}
.final { display: grid; justify-items: center; gap: 2px; }
.final-score {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(44px, 11vmin, 76px);
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(100deg, var(--cyan), var(--mint) 40%, var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 30px rgba(94, 240, 255, 0.35));
  animation: score-in 620ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes score-in { from { opacity: 0; transform: scale(0.7); filter: blur(8px); } }
.final-label {
  font-size: 10px; letter-spacing: 0.36em; text-transform: uppercase; color: var(--ink-faint);
}
.final-label.record { color: var(--gold); animation: record-pulse 1.4s ease-in-out infinite; }
@keyframes record-pulse { 50% { opacity: 0.45; } }

/* Six stats, always 3×2. auto-fit gives a ragged last row at most panel
   widths, which reads as a layout accident rather than a scoreboard. */
.run-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  width: 100%;
  background: var(--line);
  border: 1px solid var(--line);
}
.run-stat {
  display: grid; gap: 2px; padding: 8px 4px;
  background: var(--void-2);
  text-align: center;
}
.run-stat b {
  font-family: var(--font-mono); font-size: 15px; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.run-stat span {
  font-size: 8px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-faint);
}

.submit-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; width: 100%; }
.submit-row.hidden { display: none; }
#name-input {
  padding: 11px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line);
  border-radius: 2px;
  min-width: 0;
}
#name-input::placeholder { color: var(--ink-faint); letter-spacing: 0.12em; text-transform: none; }
#name-input:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 18px rgba(94, 240, 255, 0.2); }
.submit-status {
  font-family: var(--font-mono); font-size: 11px !important; min-height: 1em;
  color: var(--ink-faint) !important;
}
.submit-status.good { color: var(--mint) !important; }
.submit-status.bad { color: var(--gold) !important; }

/* ── leaderboard ───────────────────────────────────────────────────── */

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  padding: 7px 12px;
  font-family: inherit; font-size: 10px; font-weight: 500;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-faint);
  background: none; border: 1px solid transparent; border-bottom: 2px solid transparent;
  cursor: pointer; transition: color 140ms, border-color 140ms;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--cyan); border-bottom-color: var(--cyan); }

.board-scope { display: flex; gap: 4px; }
.board-wrap { max-height: min(46vh, 380px); overflow-y: auto; overscroll-behavior: contain; }
/* Fixed layout so the name column is the one that gives — with `auto` the
   score and detail columns win the space and every name becomes "C…". */
.board {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
}
.board td { padding: 7px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
.board tr.you { background: rgba(94, 240, 255, 0.07); }
.board tr.you td { color: var(--cyan); }
.board .r { width: 3em; color: var(--ink-faint); text-align: right; }
.board .r.top { color: var(--gold); font-weight: 700; }
.board .n {
  width: auto;
  color: var(--ink); letter-spacing: 0.08em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.board .s {
  width: 6.5em;
  text-align: right; color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums;
}
.board .d {
  width: 11em;
  text-align: right; color: var(--ink-faint); font-size: 10px;
  white-space: nowrap; overflow: hidden;
}
.board-empty { padding: 24px 0; text-align: center; color: var(--ink-faint); font-size: 12px; }
.board-note { font-size: 11px !important; color: var(--ink-faint) !important; min-height: 1em; }

/* ── help ──────────────────────────────────────────────────────────── */

.help-grid { display: grid; gap: 12px; }
.help-item { display: grid; grid-template-columns: 22px 1fr; gap: 12px; align-items: start; }
.help-item strong {
  display: block; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink);
}
.help-item p { font-size: 12px; margin-top: 3px; }
.help-item em { color: var(--mint); font-style: normal; }
.help-thesis {
  padding: 12px; border-left: 2px solid var(--gold);
  background: rgba(255, 194, 77, 0.05);
  font-size: 12px !important; color: var(--ink) !important;
}
.help-thesis em { color: var(--gold); font-style: normal; font-weight: 700; }

.chip { width: 18px; height: 18px; border-radius: 50%; margin-top: 1px; }
.chip-mote   { background: var(--cyan); box-shadow: 0 0 14px var(--cyan); }
.chip-ember  { background: var(--gold); box-shadow: 0 0 14px var(--gold); border-radius: 2px; transform: rotate(45deg); }
.chip-prism  { background: var(--magenta); box-shadow: 0 0 14px var(--magenta); clip-path: polygon(50% 0, 100% 100%, 0 100%); border-radius: 0; }
.chip-bloom  { background: #b53cff; box-shadow: 0 0 14px #ff3c8a; clip-path: polygon(50% 0,62% 38%,100% 50%,62% 62%,50% 100%,38% 62%,0 50%,38% 38%); border-radius: 0; }
.chip-light  { background: linear-gradient(#8affd4, #2fd9a5); box-shadow: 0 0 14px var(--mint); }
.chip-bite   { background: linear-gradient(var(--gold), var(--danger)); box-shadow: 0 0 14px var(--danger); }
.chip-fangs  { background: var(--gold); clip-path: polygon(0 20%,100% 20%,80% 100%,50% 55%,20% 100%); border-radius: 0; }
.chip-chain  { background: linear-gradient(var(--cyan), var(--gold)); box-shadow: 0 0 14px var(--gold); }

.keys { margin: 0; padding: 0; list-style: none; display: grid; gap: 7px; }
.keys li { font-size: 12px; color: var(--ink-dim); display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
kbd {
  font-family: var(--font-mono); font-size: 10px;
  padding: 2px 6px; border-radius: 2px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-bottom-width: 2px;
  color: var(--ink);
}

/* ── settings ──────────────────────────────────────────────────────── */

.settings { display: grid; gap: 2px; }
.setting {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px;
  padding: 11px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.setting.inert { opacity: 0.4; }
.setting-text strong {
  display: block; font-size: 12px; font-weight: 500;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink);
}
.setting-text span { font-size: 11px; color: var(--ink-faint); }

.switch {
  position: relative; width: 42px; height: 22px;
  border-radius: 11px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.5);
  cursor: pointer; transition: background 180ms ease, border-color 180ms ease;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--ink-faint);
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1), background 180ms ease;
}
.switch[aria-checked="true"] { background: rgba(94, 240, 255, 0.18); border-color: var(--cyan); }
.switch[aria-checked="true"]::after {
  transform: translateX(20px);
  background: var(--cyan);
  box-shadow: 0 0 12px var(--cyan);
}
.switch:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.setting input[type="text"] {
  width: 140px; padding: 8px 10px;
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink); background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line); border-radius: 2px;
}
.setting input[type="text"]:focus { outline: none; border-color: var(--cyan); }

/* ── touch controls ────────────────────────────────────────────────── */

#controls {
  display: grid;
  /* minmax(0,…) so the pad column can actually shrink; a plain 1fr floors at
     the pad's min-content width and pushes the whole page sideways. */
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: var(--pad);
  min-height: 0;
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 6px;
  width: min(196px, 100%);
  justify-self: center;
}
.pad-up    { grid-area: 1 / 2; }
.pad-left  { grid-area: 2 / 1; }
.pad-down  { grid-area: 2 / 2; }
.pad-right { grid-area: 2 / 3; }

.pad-btn {
  appearance: none;
  aspect-ratio: 1.5;
  display: grid; place-items: center;
  font-size: 14px;
  color: var(--cyan);
  background: rgba(94, 240, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 3px;
  cursor: pointer;
  transition: background 90ms ease, transform 90ms ease;
}
.pad-btn:active {
  background: rgba(94, 240, 255, 0.25);
  transform: scale(0.94);
}

.sys { display: flex; gap: 6px; }

/* The pad is a phone affordance; on a real keyboard it is just clutter. */
@media (hover: hover) and (pointer: fine) {
  .pad { display: none; }
  #controls { grid-template-columns: minmax(0, 1fr); justify-items: end; }
}

/* ── wide layout ───────────────────────────────────────────────────── */
/* On a landscape screen the board is height-bound, so stacking the HUD above
   it just makes the board smaller while a third of the window sits empty.
   Above this breakpoint the HUD becomes a side rail and the board takes the
   full height it can get. */

@media (min-width: 880px) and (min-aspect-ratio: 1/1) {
  #app {
    grid-template-columns: minmax(0, 1fr) clamp(200px, 21vw, 262px);
    grid-template-rows: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "stage hud"
      "stage controls"
      "credit credit";
    max-width: min(96vw, 1400px);
  }
  #hud     { grid-area: hud; align-content: start; align-self: start; }
  #stage   { grid-area: stage; }
  #controls{ grid-area: controls; align-self: end; }
  .credit  { grid-area: credit; }

  /* The rail stays legible on the title screen too — an empty column reads
     as a bug, so it holds the mode and your best until a run starts. */
  #app[data-screen="title"] #hud,
  #app[data-screen="help"] #hud,
  #app[data-screen="settings"] #hud {
    opacity: 1;
    transform: none;
  }

  #hud {
    gap: 14px;
    padding: 16px 14px;
    background: var(--glass);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    clip-path: polygon(0 12px, 12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%);
  }
  .hud-top, .hud-meters { grid-template-columns: 1fr; gap: 14px; }
  .hud-center, .hud-right { align-items: flex-start; text-align: left; }
  .score { font-size: clamp(34px, 3.4vw, 50px); }
  .hud-cell { gap: 3px; }
  .hud-left  { order: 1; }
  .hud-center{ order: 2; }
  .hud-right { order: 3; flex-direction: row; gap: 8px; align-items: baseline; }
  .meter { height: 16px; }
  .fangs, .length { justify-content: space-between; }
}

.credit {
  display: block;
  padding: 8px 0 4px;
  text-align: center;
  font-size: 9px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: rgba(143, 163, 196, 0.35);
  text-decoration: none;
  transition: color 200ms ease;
}
.credit:hover { color: var(--cyan); }

/* ── a11y / preferences ────────────────────────────────────────────── */

/* Swaps the two colours that carry meaning (cyan food, gold ember) for a
   blue/yellow pair that survives deuteranopia and protanopia. */
.daltonize {
  --cyan: #4db8ff;
  --mint: #9fd0ff;
  --gold: #ffd93d;
  --magenta: #ff8ae0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Short viewports — a landscape phone, a split window, a modest iframe. The
   title screen is the tallest thing in the app, so it sheds its decoration
   before it ever has to scroll. Everything load-bearing stays. */
@media (max-height: 640px) {
  .panel { --panel-pad: clamp(12px, 2vmin, 16px); gap: 10px; }
  .sigil { width: clamp(38px, 8vmin, 54px); }
  .wordmark h1 { font-size: clamp(22px, 5.4vmin, 34px); }
  .wordmark { gap: 2px; }
  .tagline, .hint { display: none; }
  .mode { padding: 7px 10px; }
  .mode-tag { font-size: 10px; }
  .btn { padding: 9px 12px; }
  .run-stat { padding: 5px 4px; }
  .help-grid { gap: 9px; }
}

@media (max-height: 460px) {
  .mode-tag { display: none; }
  .sigil { display: none; }
  .panel { --panel-pad: 10px; gap: 7px; }
  .wordmark h1 { font-size: clamp(20px, 5vmin, 26px); }
  .mode { padding: 5px 9px; }
  .btn { padding: 7px 10px; font-size: 11px; }
  .death-cause { font-size: 10px !important; }
  .final-score { font-size: clamp(30px, 9vmin, 46px); }
  .run-stat { padding: 3px 2px; }
  .run-stat b { font-size: 12px; }
  .run-stat span { font-size: 7px; }
  .board-wrap { max-height: 34vh; }
}

/* Short-and-wide (landscape phone, or an iframe on a blog): the board is the
   thing, so the chrome collapses around it rather than squeezing it. */
@media (max-height: 560px) and (orientation: landscape) {
  #app { max-width: 100vw; padding: 6px; gap: 6px; }
  .hud-meters { display: none; }
  .pad { width: min(150px, 100%); }
  .credit { display: none; }
}

@media (max-width: 480px) {
  .title-actions { grid-template-columns: 1fr 1fr; }
  .title-actions #btn-board { grid-column: 1; }
  .board .d { display: none; }
  .board .s { width: 7em; }
}

/* Portrait phones: the board is width-bound, so the height left over can't
   make it bigger — give it to the thumbs instead. Bigger pad, better game. */
@media (max-aspect-ratio: 1/1) and (hover: none) {
  .pad { width: min(260px, 100%); gap: 8px; }
  .pad-btn { aspect-ratio: 1.25; font-size: 17px; }
  #controls { align-items: end; }
  .length { border-left: none; padding-left: 0; }
  .hud-meters { grid-template-columns: minmax(0, 1fr) auto; row-gap: 6px; }
  .length { grid-column: 2; justify-self: end; }
}
