/* game.css — Depthbound.
 *
 * Split out of game.html when the game grew an engine: the HTML is now a
 * shell, the behaviour is in engine/, and the look is here.
 *
 * The palette is 1op's, held to the dark end because the game is the one
 * place on the site that is a room rather than a page. Depth worlds tint
 * themselves through --ink, set per depth by [data-depth] below; everything
 * chrome-coloured stays constant so the furniture does not move underfoot.
 */

:root {
  --bg:        #08090e;
  --bg-2:      #0d0f17;
  --panel:     #0b0d14;
  --line:      #1b1f2c;
  --gold:      #e8a020;
  --coral:     #e8654a;
  --green:     #2d9b6e;
  --blue:      #3d7cc9;
  --amber:     #d4952a;
  --violet:    #7b5ea7;
  --text:      #e6e7ee;
  --dim:       rgba(230, 231, 238, 0.55);
  --dimmer:    rgba(230, 231, 238, 0.34);
  --ink:       #8fc7ff;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}

/* Per-depth accent. Art direction lives in worlds.js; this mirrors the same
   six inks so the chrome agrees with the canvas. */
#hud-layer[data-depth="0"] { --ink: #8fc7ff; }
#hud-layer[data-depth="1"] { --ink: #ffc46b; }
#hud-layer[data-depth="2"] { --ink: #ff7ad0; }
#hud-layer[data-depth="3"] { --ink: #b98cff; }
#hud-layer[data-depth="4"] { --ink: #6ee7a8; }
#hud-layer[data-depth="wall"] { --ink: #cfd3e0; }

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  height: 100%;
  overflow: hidden;
  /* Stop iOS rubber-band scroll and double-tap zoom from fighting the game. */
  overscroll-behavior: none;
  touch-action: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* Wide: a panel takes a COLUMN beside the game.
   Narrow: it takes a ROW beneath it.
   Either way the canvas is resized rather than covered — an overlay sheet put
   the ship (y = 0.5, so 422px on a 844px phone) behind a 520px drawer, which
   is a game you cannot see while reading about it. */
#stage {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 0;
  grid-template-rows: 1fr;
  transition: grid-template-columns 220ms ease, grid-template-rows 220ms ease;
}
/* On a wide screen a panel takes a column, so the game is never covered.
   Below 900px the panels become bottom sheets — see the media query. */
@media (min-width: 900px) {
  body[data-panel="lab"] #stage,
  body[data-panel="build"] #stage { grid-template-columns: 1fr 420px; }
}

#viewport { position: relative; overflow: hidden; }
#game { display: block; width: 100%; height: 100%; touch-action: none; }

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

#hud-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
}
#hud-layer button { pointer-events: auto; }

.hud-top { display: flex; align-items: flex-start; gap: 12px; }
.hud-stats { display: flex; gap: 18px; }
.hud-stat { display: flex; flex-direction: column; line-height: 1.15; }
.hud-k { font-size: 9px; letter-spacing: 0.18em; color: var(--dimmer); }
.hud-v { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }

.hud-depth { flex: 1; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.hud-depth-n {
  font-size: 11px; letter-spacing: 0.30em; font-weight: 700; color: var(--ink);
}
.hud-depth-t { font-size: 10px; letter-spacing: 0.16em; color: var(--dimmer); }

.hud-btns { display: flex; gap: 6px; }
.hud-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: rgba(10, 12, 20, 0.62);
  border: 1px solid var(--line);
  color: var(--dim);
  border-radius: 9px;
  font-family: var(--mono); font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: color 140ms, border-color 140ms;
}
.hud-btn:hover { color: var(--text); border-color: var(--ink); }

.hud-run {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  top: calc(max(12px, env(safe-area-inset-top)) + 46px);
  font-size: 9.5px; letter-spacing: 0.22em; color: var(--dimmer);
  pointer-events: auto; cursor: pointer;
  padding: 3px 9px; border: 1px solid var(--line); border-radius: 99px;
  background: rgba(10, 12, 20, 0.5);
}
.hud-run:hover { color: var(--ink); border-color: var(--ink); }

/* ── the equation strip ──────────────────────────────────────────────── */
/* Small, permanent, and visibly alive. This is the hinge between "a game"
   and "the equation is the game", so it is the one HUD element that is
   allowed to move. */

.eqstrip {
  margin-top: auto;
  align-self: center;
  max-width: min(96vw, 860px);
  padding: 8px 14px 9px;
  background: rgba(9, 11, 18, 0.72);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(9px); -webkit-backdrop-filter: blur(9px);
  text-align: center;
  transition: border-color 180ms, box-shadow 180ms;
}
.eqstrip.held { border-color: var(--ink); box-shadow: 0 0 22px -6px var(--ink); }
.eq-src { font-size: 13px; letter-spacing: 0.02em; white-space: nowrap; overflow-x: auto; scrollbar-width: none; }
.eq-src::-webkit-scrollbar { display: none; }
.eq-op { color: var(--ink); font-weight: 700; }
.eq-t  { color: var(--dim); }
.eq-x  {
  color: #fff; font-weight: 700;
  text-shadow: 0 0 calc(var(--live, 0) * 14px) var(--ink);
}
.eq-chain { display: flex; gap: 14px; justify-content: center; margin-top: 5px; flex-wrap: wrap; }
.eq-cell { display: flex; gap: 5px; align-items: baseline; font-size: 10.5px; }
.eq-k { color: var(--dimmer); letter-spacing: 0.1em; }
.eq-v { color: var(--text); font-variant-numeric: tabular-nums; }
.eq-cell.hot .eq-v { color: var(--gold); }
.eq-cell.bad .eq-v { color: var(--coral); }

/* ── toast ───────────────────────────────────────────────────────────── */

.toast {
  position: absolute;
  left: 50%; bottom: 96px; transform: translate(-50%, 12px);
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: rgba(12, 14, 22, 0.94);
  border: 1px solid var(--ink);
  border-radius: 11px;
  font-size: 12px;
  opacity: 0; pointer-events: none;
  transition: opacity 260ms ease, transform 260ms ease;
  max-width: min(92vw, 520px);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast-a {
  pointer-events: auto;
  background: var(--ink); color: #08090e;
  border: 0; border-radius: 99px;
  padding: 5px 11px; font-family: var(--mono); font-size: 10px;
  font-weight: 700; letter-spacing: 0.12em; cursor: pointer; white-space: nowrap;
}

/* ── cards ───────────────────────────────────────────────────────────── */

.cards {
  position: absolute; inset: 0;
  display: none; place-items: center;
  background: radial-gradient(ellipse at center, rgba(8,9,14,0.80), rgba(8,9,14,0.96));
  pointer-events: auto;
  padding: 20px;
  overflow-y: auto;
}
.cards.on { display: grid; }
.card {
  max-width: 560px; width: 100%;
  text-align: center;
  animation: cardin 260ms cubic-bezier(0.2, 0.7, 0.3, 1);
}
@keyframes cardin { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.card-kicker { font-size: 10px; letter-spacing: 0.34em; color: var(--ink); margin-bottom: 10px; }
.card-h1 {
  font-size: clamp(22px, 5vw, 40px);
  letter-spacing: 0.02em; line-height: 1.06; font-weight: 800;
  margin-bottom: 12px;
}
.card-title .card-h1 { letter-spacing: -0.01em; }

/* The wordmark. One word, wide tracking, a hairline, and a bound underneath
   that moves as the player climbs. No gradient, no bevel, no mascot — the word
   is doing the work and 1op's register is quiet. */
.wordmark {
  font-size: clamp(28px, 7.2vw, 58px);
  font-weight: 300;
  letter-spacing: 0.22em;
  text-indent: 0.22em;            /* optical centring against the tracking */
  line-height: 1;
  margin-bottom: 14px;
  color: var(--text);
}
.wordmark-rule {
  width: min(240px, 58%);
  height: 1px;
  margin: 0 auto 8px;
  background: linear-gradient(90deg, transparent, var(--ink), transparent);
}
.wordmark-bound {
  font-size: 10px;
  letter-spacing: 0.36em;
  text-indent: 0.36em;
  color: var(--ink);
  margin-bottom: 18px;
}
.card-secondary { display: flex; gap: 8px; justify-content: center; margin-top: 14px; }
.card-secondary .card-alt { margin: 0; }
.card-sub { font-size: 15px; color: var(--ink); letter-spacing: 0.14em; margin-bottom: 10px; }
.card-lede { font-size: 13px; color: var(--dim); line-height: 1.65; margin-bottom: 16px; }
.card-eq {
  display: inline-block;
  font-size: 13px; color: var(--text);
  background: var(--panel); border: 1px solid var(--line);
  padding: 9px 14px; border-radius: 9px; margin-bottom: 6px;
  max-width: 100%; overflow-x: auto;
}
.card-eqnote { font-size: 12px; color: var(--gold); margin-bottom: 14px; }
.card-witness { font-size: 11.5px; color: var(--green); margin: 10px 0; }
.card-foot { font-size: 11px; color: var(--dimmer); margin-top: 14px; line-height: 1.6; }
.card-cta {
  margin-top: 16px;
  background: var(--ink); color: #08090e;
  border: 0; border-radius: 99px;
  padding: 11px 26px;
  font-family: var(--mono); font-size: 12px; font-weight: 800; letter-spacing: 0.18em;
  cursor: pointer;
}
.card-cta:hover { filter: brightness(1.12); }
.card-alt {
  margin: 10px 0 0 10px;
  background: transparent; color: var(--dim);
  border: 1px solid var(--line); border-radius: 99px;
  padding: 10px 20px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em;
  cursor: pointer;
}
.card-alt:hover { color: var(--text); border-color: var(--ink); }
.share-input {
  width: 100%; margin-top: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); font-family: var(--mono); font-size: 11px; padding: 9px 11px;
}
.opt-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
  font-size: 12px; color: var(--dim); text-align: left;
}
.opt-row input[type="range"] { width: 160px; accent-color: var(--ink); }
.opt-row input[type="checkbox"] { accent-color: var(--ink); }

/* the wall's zero table */
.wall-table { margin: 14px auto 4px; max-width: 340px; }
.wall-row {
  display: flex; justify-content: space-between;
  padding: 5px 0; border-bottom: 1px solid var(--line);
  font-size: 11.5px;
}
.wall-k { color: var(--dim); }
.wall-b { color: var(--text); font-variant-numeric: tabular-nums; }
.wall-inf .wall-k, .wall-inf .wall-b { color: var(--coral); font-weight: 700; }

/* ── evidence ────────────────────────────────────────────────────────── */

.ev-row { display: flex; gap: 9px; align-items: baseline; flex-wrap: wrap; justify-content: center; }
.ev-badge {
  font-size: 9px; font-weight: 800; letter-spacing: 0.18em;
  padding: 3px 8px; border-radius: 99px; border: 1px solid currentColor;
  white-space: nowrap;
}
.ev-proved  { color: var(--green); }
.ev-partial { color: var(--amber); }
.ev-pending { color: var(--dimmer); }
.ev-def     { color: var(--blue); }
.ev-play    { color: var(--dimmer); }
.ev-claim { font-size: 11.5px; color: var(--text); line-height: 1.55; }
.ev-note  { font-size: 10.5px; color: var(--dimmer); margin-top: 5px; }
.ev-open  { font-size: 10.5px; color: var(--amber); margin-top: 7px; line-height: 1.55; }
.ev-cites {
  list-style: none;
  margin: 10px auto 0;
  font-size: 10px;
  max-width: 460px;
  text-align: left;
}
.ev-cites li { padding: 3px 0; color: var(--dimmer); line-height: 1.5; }
.ev-cites a { color: var(--blue); text-decoration: none; }
.ev-cites a:hover { text-decoration: underline; }
.ev-cite-name { color: var(--dim); }
.ev-lean { color: var(--green); }

/* ── side panels ─────────────────────────────────────────────────────── */

.side {
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: none;
  font-size: 12px;
}
body[data-panel="lab"] #lab-panel,
body[data-panel="build"] #builder-panel { display: block; }

.lab-head, .b-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.lab-title, .b-title { font-size: 11px; font-weight: 800; letter-spacing: 0.26em; color: var(--ink); white-space: nowrap; }
.b-tag { flex: 1; }
.lab-sub { font-size: 10px; color: var(--dimmer); letter-spacing: 0.12em; }
.b-tag { font-size: 9.5px; color: var(--dimmer); letter-spacing: 0.1em; }
.lab-close, .b-close {
  margin-left: auto; width: 26px; height: 26px;
  background: transparent; border: 1px solid var(--line); border-radius: 7px;
  color: var(--dim); cursor: pointer; font-family: var(--mono);
}

.lab-sec { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.lab-sec h3 { display: flex; align-items: baseline; gap: 8px; margin-bottom: 9px; }
.lab-step {
  width: 16px; height: 16px; flex: 0 0 16px;
  display: inline-grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--ink); color: var(--ink);
  font-size: 8.5px; font-weight: 800;
}
.lab-h { font-size: 10px; font-weight: 800; letter-spacing: 0.2em; }
.lab-hint { font-size: 9.5px; color: var(--dimmer); font-weight: 400; letter-spacing: 0.04em; }
.lab-note { font-size: 10px; color: var(--dimmer); line-height: 1.6; margin-bottom: 9px; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; }
.kv-k { color: var(--dimmer); font-size: 10.5px; }
.kv-v { color: var(--text); font-size: 11px; font-variant-numeric: tabular-nums; text-align: right; }

.lab-treemeta { margin-bottom: 9px; }
.tsrc { display: block; font-size: 11px; color: var(--text); word-break: break-all; line-height: 1.5; }
.tchips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.chip {
  font-size: 9px; letter-spacing: 0.1em; color: var(--dim);
  border: 1px solid var(--line); border-radius: 99px; padding: 2px 7px;
}
.chip-eq { color: var(--gold); border-color: var(--gold); }
.chip-custom { color: var(--coral); border-color: var(--coral); }
.chip-2d { color: var(--ink); border-color: var(--ink); }
.b-2d { color: var(--ink); border-color: var(--ink); }

.lab-tree { font-size: 11px; }
.lab-swap { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.lab-swapbtn {
  background: transparent; border: 1px solid var(--ink); border-radius: 7px;
  color: var(--ink); font-family: var(--mono); font-size: 9.5px;
  letter-spacing: 0.1em; padding: 6px 10px; cursor: pointer;
}
.lab-swapbtn:hover { background: var(--ink); color: #08090e; }

.lab-zeros {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}
.z-k { color: var(--dimmer); font-size: 10.5px; }
.z-v { color: var(--text); font-size: 11px; text-align: right; font-variant-numeric: tabular-nums; }
.z-note { grid-column: 1 / -1; font-size: 10px; color: var(--dimmer); line-height: 1.55; margin-top: 5px; }
.tnode {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 2px 6px; border-radius: 5px;
  /* --live is written per frame from the node's own rate of change. */
  background: rgba(255, 255, 255, calc(var(--live, 0) * 0.07));
}
.tnode.on-path { border-left: 2px solid var(--ink); }
.tnode.off-domain .tval { color: var(--coral); }
.tname { color: var(--dim); }
.t-eml { color: var(--ink); font-weight: 700; }
.t-x { color: #fff; font-weight: 700; }
.t-c { color: var(--dim); }
.tval { color: var(--text); font-variant-numeric: tabular-nums; }

.xray-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.xray-tab {
  background: transparent; border: 1px solid var(--line); border-radius: 6px;
  color: var(--dim); font-family: var(--mono); font-size: 10px;
  padding: 4px 9px; cursor: pointer;
}
.xray-tab.on { color: #08090e; background: var(--ink); border-color: var(--ink); font-weight: 700; }
.xray-check { font-size: 9.5px; line-height: 1.5; margin-bottom: 7px; }
.xray-check.ok { color: var(--green); }
.xray-check.bad { color: var(--coral); }
.xray-check.unknown { color: var(--dimmer); }
.xray-src {
  background: #070810; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; font-size: 10.5px; line-height: 1.55;
  overflow-x: auto; white-space: pre; color: #cdd2e0; max-height: 320px;
}

.modrow { border-bottom: 1px solid var(--line); padding: 5px 0; }
.modrow summary { display: flex; gap: 8px; align-items: baseline; cursor: pointer; list-style: none; }
.modrow summary::-webkit-details-marker { display: none; }
.modname { font-size: 10.5px; color: var(--text); }
.modmeta { margin-left: auto; display: flex; gap: 8px; font-size: 9px; color: var(--dimmer); }
.vok { color: var(--green); } .vpart { color: var(--amber); } .vnone { color: var(--dimmer); }
.moddesc { font-size: 10px; color: var(--dimmer); line-height: 1.55; margin: 5px 0; }
.modlive { font-size: 10px; color: var(--dim); font-variant-numeric: tabular-nums; }

/* ── builder ─────────────────────────────────────────────────────────── */

.b-budget { display: flex; gap: 6px; padding: 10px 14px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
/* The EML-depth chip is what goes over, not the bound. */
.b-budget.over .b-chip:not(.b-bound) { color: var(--coral); border-color: var(--coral); }
.b-bound { color: var(--ink); border-color: var(--ink); letter-spacing: 0.14em; }
.b-chip { font-size: 9px; letter-spacing: 0.1em; color: var(--dim); border: 1px solid var(--line); border-radius: 99px; padding: 2px 8px; }
.b-locked {
  display: none;
  margin: 0 14px 12px;
  padding: 10px 12px;
  border: 1px solid var(--amber);
  border-radius: 9px;
  font-size: 11px; line-height: 1.6; color: var(--dim);
}
.b-locked.on { display: block; }
.b-locked strong { color: var(--amber); }

.b-cols { display: block; }
.b-left { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.b-right { padding: 12px 14px; }
.b-tree { margin-bottom: 10px; }
.b-node {
  display: block; width: 100%; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--text); font-family: var(--mono); font-size: 11.5px;
  padding: 3px 6px; cursor: pointer;
}
.b-node:hover { border-color: var(--line); }
.b-node.sel { border-color: var(--ink); background: rgba(255,255,255,0.05); }
.b-eml { color: var(--ink); font-weight: 700; }
.b-x { color: #fff; font-weight: 700; }
.b-c { color: var(--dim); }

.b-palette { border-top: 1px solid var(--line); padding-top: 10px; }
.b-plabel { font-size: 9px; letter-spacing: 0.18em; color: var(--dimmer); margin-bottom: 7px; }
.b-op {
  display: inline-block; margin: 0 5px 5px 0;
  background: transparent; border: 1px solid var(--line); border-radius: 6px;
  color: var(--dim); font-family: var(--mono); font-size: 10.5px; padding: 5px 9px; cursor: pointer;
}
.b-op:hover:not(:disabled) { color: var(--text); border-color: var(--ink); }
.b-op:disabled { opacity: 0.35; cursor: not-allowed; }
.b-crow { display: flex; align-items: center; gap: 7px; margin-top: 7px; flex-wrap: wrap; }
.b-clabel { font-size: 9.5px; color: var(--dimmer); letter-spacing: 0.12em; }
.b-crow input[type="range"] { flex: 1; min-width: 110px; accent-color: var(--ink); }
.b-cval { font-size: 10.5px; color: var(--text); width: 42px; font-variant-numeric: tabular-nums; }
.b-const {
  background: transparent; border: 1px solid var(--line); border-radius: 5px;
  color: var(--dim); font-family: var(--mono); font-size: 10px; padding: 3px 7px; cursor: pointer;
}
.b-preview { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; display: block; }
.b-src { display: block; font-size: 11px; color: var(--text); margin: 9px 0 6px; word-break: break-all; line-height: 1.5; }
.b-status { font-size: 10.5px; line-height: 1.55; min-height: 30px; }
.b-status.ok { color: var(--green); }
.b-status.bad { color: var(--coral); }
.b-presets { display: flex; flex-wrap: wrap; gap: 5px; margin: 9px 0; }
.b-preset {
  background: transparent; border: 1px solid var(--line); border-radius: 99px;
  color: var(--dim); font-family: var(--mono); font-size: 10px; padding: 4px 10px; cursor: pointer;
}
.b-preset:hover:not(:disabled) { color: var(--text); border-color: var(--ink); }
.b-preset:disabled { opacity: 0.3; cursor: not-allowed; }
.b-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.b-btn {
  background: transparent; border: 1px solid var(--line); border-radius: 7px;
  color: var(--dim); font-family: var(--mono); font-size: 10.5px; padding: 7px 12px; cursor: pointer;
}
.b-btn:hover:not(:disabled) { color: var(--text); border-color: var(--ink); }
.b-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.b-fly { background: var(--ink); color: #08090e; border-color: var(--ink); font-weight: 800; letter-spacing: 0.12em; margin-left: auto; }

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

#touch-ui { display: none; position: absolute; inset: auto 0 0 0; padding: 0 18px 26px; pointer-events: none; }
body.touch #touch-ui { display: flex; justify-content: flex-end; }
.dashbtn {
  pointer-events: auto;
  width: 88px; height: 88px; border-radius: 50%;
  background: rgba(232, 160, 32, 0.14);
  border: 2px solid rgba(232, 160, 32, 0.6);
  color: var(--gold);
  font-family: var(--mono); font-size: 12px; font-weight: 800; letter-spacing: 0.14em;
  margin-bottom: env(safe-area-inset-bottom);
}
.dashbtn:active { background: rgba(232, 160, 32, 0.32); }

/* ── narrow viewports: panels become bottom sheets ───────────────────── */

@media (max-width: 899px) {
  #stage { grid-template-columns: 1fr; grid-template-rows: 1fr 0; }
  body[data-panel="lab"] #stage,
  body[data-panel="build"] #stage { grid-template-rows: 1fr min(54vh, 460px); }
  .side {
    border-left: 0;
    border-top: 2px solid var(--ink);
    border-radius: 14px 14px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    min-height: 0;
  }

  /* 390px does not fit SCORE + SPEED + a centred depth + five buttons on one
     line; it wrapped "DEPTH" and "0" onto separate lines and ran into the
     buttons. Stack the depth under the row instead, beside the run chip. */
  .hud-depth {
    position: absolute;
    left: 0; right: 0;
    top: calc(max(12px, env(safe-area-inset-top)) + 44px);
    flex-direction: row;
    gap: 8px;
    justify-content: center;
    white-space: nowrap;
    pointer-events: none;
  }
  .hud-depth-t { color: var(--dimmer); }
  .hud-run { top: calc(max(12px, env(safe-area-inset-top)) + 66px); }
  /* 34px is under the 44px touch-target guideline. */
  .hud-btn { width: 40px; height: 40px; }
  /* .hud-depth is absolute here, so it no longer flexes the buttons right. */
  .hud-btns { gap: 4px; margin-left: auto; }

  .eqstrip { margin-bottom: 4px; }
  body.touch .eqstrip { margin-bottom: 112px; }
  .toast { bottom: 150px; }
  .b-preview { max-height: 150px; }
}

/* Phone portrait: five buttons is one too many. Fullscreen goes — the page is
   already full-bleed there and iOS Safari on iPhone has no element fullscreen
   anyway, so the button was a no-op taking up a thumb's width. */
@media (max-width: 430px) {
  .hud-btn[aria-label="Fullscreen"] { display: none; }
  .hud-v { font-size: 17px; }
  .hud-stats { gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
  .toast { transition: none; }
}
