/* Light Bench — dark lab-instrument theme (layout follows Photon Lab).
   One dark palette on purpose: laser light reads best on black. */
:root {
  --bg: #070a14;
  --panel: #0e1322;
  --panel-2: #141b2e;
  --line: #222b45;
  --line-strong: #33406a;
  --text: #e6ebf7;
  --muted: #8b95b3;
  --accent: #ffc24d;
  --accent-rgb: 255, 194, 77;
  --accent-ink: #1a1204;
  --good: #4fd18a;
  --bad: #ff7a7a;
  --warn: #ff9b6a;
  --cool: #8fd3ff;
  --radius: 12px;
  --base: 16px;
  --sans: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Atkinson Hyperlegible Mono", ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { font-size: var(--base); }
body {
  margin: 0;
  background: radial-gradient(1200px 500px at 70% -10%, rgba(var(--accent-rgb), 0.06), transparent 60%), var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.45;
  overflow-x: hidden;
}
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
b, strong { font-weight: 650; }
[hidden] { display: none !important; }

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 40;
  background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: 8px;
}
.skip-link:focus { top: 8px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(7, 10, 20, 0.88); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px 0;
}
.topbar-row { display: flex; align-items: center; gap: 10px; max-width: 1280px; margin: 0 auto; }
.back-link {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; flex: none;
  border-radius: 8px; text-decoration: none; color: var(--muted); border: 1px solid var(--line);
}
.back-link:hover { color: var(--text); border-color: var(--line-strong); }
.wordmark { margin: 0; font-size: 1.05rem; letter-spacing: 0.02em; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.wordmark-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 10px var(--accent), 0 0 22px rgba(var(--accent-rgb), 0.5);
}
.topic-pill {
  margin-left: auto; font-size: 0.72rem; color: var(--cool); border: 1px solid rgba(143, 211, 255, 0.45);
  border-radius: 999px; padding: 3px 10px; white-space: nowrap;
}
.tabs { display: flex; gap: 4px; max-width: 1280px; margin: 6px auto 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs [role="tab"], .side-tabs [role="tab"] { position: relative; transition: color 0.15s ease; }
.tabs [role="tab"] {
  min-height: 42px; border: 0; border-radius: 0; background: transparent; color: var(--muted);
  font-weight: 600; padding: 8px 12px; white-space: nowrap; flex: none;
}
.tabs [role="tab"]::after, .side-tabs [role="tab"]::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 0; height: 2px; border-radius: 2px;
  background: var(--accent); transform: scaleX(0); transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.side-tabs [role="tab"]::after { height: 3px; left: 6px; right: 6px; }
.tabs [role="tab"][aria-selected="true"]::after, .side-tabs [role="tab"][aria-selected="true"]::after {
  transform: scaleX(1); box-shadow: 0 0 10px rgba(var(--accent-rgb), 0.6);
}
.tabs [role="tab"][aria-selected="true"], .tabs [role="tab"]:hover { color: var(--text); }
.tabs .tab-num { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); margin-right: 6px; }
.tabs [role="tab"]:hover:not(:disabled) { border-color: transparent; }

/* ---------- buttons ---------- */
button, select, input { font: inherit; color: inherit; }
button {
  min-height: 44px; padding: 8px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--panel-2);
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease, transform 0.12s ease, box-shadow 0.2s ease;
}
@media (hover: hover) { button:hover:not(:disabled) { border-color: var(--accent); } }
button:active:not(:disabled) { transform: scale(0.97); }
.ic { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:where(button:has(> .ic)) { display: inline-flex; align-items: center; justify-content: center; gap: 0.45em; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button[aria-pressed="true"] { background: rgba(var(--accent-rgb), 0.14); border-color: var(--accent); color: var(--accent); }
.ghost { background: transparent; }
.small { min-height: 36px; padding: 4px 10px; font-size: 0.85rem; }
.tiny { min-height: 30px; padding: 2px 8px; font-size: 0.78rem; border-radius: 7px; }
.fire {
  position: relative; isolation: isolate;
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700;
  padding-inline: 20px; box-shadow: 0 0 18px rgba(var(--accent-rgb), 0.35);
}
.fire:hover:not(:disabled) { background: #ffd47f; }
.fire.on { background: transparent; color: var(--accent); }
.fire .ic { width: 1.3em; height: 1.3em; stroke-width: 2.2; }
.fire.launch::after {
  content: ""; position: absolute; inset: -1px; border-radius: inherit; border: 2px solid var(--accent);
  pointer-events: none; animation: launch 0.55s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.fire.launch .ic { animation: dart 0.45s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes launch { from { opacity: 0.9; transform: scale(1); } to { opacity: 0; transform: scale(1.12, 1.6); } }
@keyframes dart { 40% { transform: translateX(5px); } }
button[data-predict][aria-pressed="true"] { animation: pick 0.3s cubic-bezier(0.22, 1, 0.36, 1); box-shadow: 0 0 14px rgba(var(--accent-rgb), 0.25); }
@keyframes pick { 0% { transform: scale(0.94); } 60% { transform: scale(1.04); } 100% { transform: scale(1); } }
.verdict.fresh > * { animation: fresh 0.35s cubic-bezier(0.22, 1, 0.36, 1) both; }
.verdict.fresh > :nth-child(2) { animation-delay: 0.05s; }
.verdict.fresh > :nth-child(3) { animation-delay: 0.1s; }
@keyframes fresh { from { opacity: 0; transform: translateY(4px); } }
.verdict.cheer { animation: cheer 0.9s ease-out; }
@keyframes cheer { from { box-shadow: 0 0 0 0 rgba(79, 209, 138, 0.55); } to { box-shadow: 0 0 0 14px rgba(79, 209, 138, 0); } }

/* ---------- layout ---------- */
main { max-width: 1280px; margin: 0 auto; padding: 14px 16px 40px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 14px; align-items: start; }
.workspace.side-collapsed { grid-template-columns: minmax(0, 1fr); }
.workspace.side-collapsed .side { display: none; }
.stage-col { min-width: 0; }
.stage {
  position: relative; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #05070f;
}
.stage > .side-toggle { position: absolute; top: 5px; right: 8px; z-index: 2; min-height: 32px; padding: 2px 10px; }
.rule {
  margin: 0; padding: 8px 6rem 8px 12px; font-size: 0.85rem; color: var(--muted);
  border-bottom: 1px solid var(--line); background: rgba(14, 19, 34, 0.7);
}
.rule-key {
  display: inline-block; font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent); border: 1px solid rgba(var(--accent-rgb), 0.4); border-radius: 4px; padding: 0 5px; margin-right: 6px;
}
.formula { font-family: "Cambria Math", "STIX Two Math", Georgia, serif; color: var(--text); font-weight: 600; }
.canvas-box { position: relative; }
.stage-canvas { display: block; width: 100%; height: clamp(320px, 56vh, 600px); touch-action: none; cursor: grab; }
.stage-canvas:active { cursor: grabbing; }
.stage-canvas:focus-visible { outline-offset: -3px; }
.status {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; margin: 0; padding: 6px 12px;
  border-top: 1px solid var(--line); background: rgba(14, 19, 34, 0.7);
  font-family: var(--mono); font-size: 0.78rem; color: var(--text);
}
.status .illus { color: var(--muted); font-family: var(--sans); font-size: 0.72rem; }

.actionbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0 0; }
.predict { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.predict-label { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text); margin-right: 2px; }
.predict-q { color: var(--muted); font-size: 0.88rem; margin-right: 4px; }
.predict-options { display: contents; }
.predict button { min-height: 40px; padding: 6px 12px; font-size: 0.9rem; }
.predict.cue button[data-predict] { animation: cue 1.8s ease-in-out infinite; }
@keyframes cue { 0%, 100% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0); } 50% { box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.35); } }
.fire-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.score { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }

.verdict {
  margin-top: 10px; padding: 12px 14px; border-radius: 10px; background: var(--panel);
  border: 1px solid var(--line); border-left: 4px solid var(--line-strong); min-height: 4.2em;
}
.verdict-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-bottom: 2px; }
.verdict strong { display: block; font-size: 1.08rem; }
.verdict p { margin: 0; color: var(--muted); font-size: 0.92rem; }
.verdict .tag { display: inline-block; font-family: var(--mono); font-size: 0.75rem; border-radius: 4px; padding: 1px 6px; }
.verdict .tag.right { background: rgba(79, 209, 138, 0.15); color: var(--good); }
.verdict .tag.wrong { background: rgba(255, 122, 122, 0.15); color: var(--bad); }
.verdict.good { border-left-color: var(--good); }
.verdict.good strong { color: var(--good); }
.verdict.bad { border-left-color: var(--bad); }
.verdict.bad strong { color: var(--bad); }
.verdict.info { border-left-color: var(--accent); }
.verdict.info strong { color: var(--accent); }
.verdict .budget {
  display: block; margin-top: 8px; padding: 6px 8px; border-radius: 6px; background: #05070f;
  font-family: var(--mono); font-size: 0.82rem; color: var(--text); white-space: pre-line; overflow-wrap: anywhere;
}

/* ---------- side panel ---------- */
.side {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0;
  position: sticky; top: 104px; max-height: calc(100vh - 118px); display: flex; flex-direction: column;
}
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 8px 0 6px; border-bottom: 1px solid var(--line); }
.side-tabs { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.side-tabs [role="tab"] {
  min-height: 46px; border: 0; border-radius: 0; background: transparent;
  color: var(--muted); font-weight: 600; font-size: 0.9rem; padding: 8px 10px; white-space: nowrap;
}
.side-tabs [role="tab"]:hover, .side-tabs [role="tab"][aria-selected="true"] { color: var(--text); }
.side-body { padding: 14px; overflow-y: auto; overscroll-behavior: contain; }
.side-page:not([hidden]) { animation: page-in 0.22s ease-out; }
@keyframes page-in { from { opacity: 0; transform: translateY(3px); } }
.page-sec + .page-sec { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
.page-sec h3 { font-size: 0.95rem; margin: 0 0 8px; }
.lesson-goal, .key-idea { margin: 0; color: var(--muted); font-size: 0.92rem; }
.key-idea { color: var(--text); padding: 8px 10px; border-radius: 8px; border: 1px solid rgba(var(--accent-rgb), 0.35); background: rgba(var(--accent-rgb), 0.06); }
.side-backdrop { position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, 0.55); }

.big-readouts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.big-readouts > div { background: #05070f; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.big-readouts .label { display: block; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.big-readouts .value { display: block; font-family: var(--mono); font-size: 1.15rem; font-variant-numeric: tabular-nums; color: var(--accent); white-space: nowrap; }
.big-readouts .value.tir { color: var(--warn); }

.field { margin: 0 0 14px; min-width: 0; }
.field label, .field-title { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.muted { color: var(--muted); font-weight: 400; }
output { font-family: var(--mono); font-weight: 400; font-size: 0.85rem; color: var(--accent); text-align: right; }
input[type="range"] { width: 100%; min-height: 34px; accent-color: var(--accent); }
.hint { font-size: 0.8rem; color: var(--muted); margin: 6px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { min-height: 38px; padding: 5px 10px; font-size: 0.85rem; }
.chips.add button { flex: 1 1 30%; }
.remove { margin-top: 8px; width: 100%; }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.sw { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; box-shadow: 0 0 6px currentColor; }
.sw.red { background: #ff3c32; color: #ff3c32; } .sw.green { background: #3cff5a; color: #3cff5a; }
.sw.blue { background: #5078ff; color: #5078ff; } .sw.white { background: conic-gradient(#ff3c32, #ffd400, #3cff5a, #00a0ff, #8c00ff, #ff3c32); color: #fff; }

.readouts { margin: 0; font-size: 0.85rem; }
.readouts div { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); }
.readouts dt { color: var(--muted); }
.readouts dd { margin: 0; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.graph { display: block; width: 100%; height: 220px; border-radius: 8px; background: #05070f; }

.tasks { padding-left: 1.2em; margin: 0; font-size: 0.92rem; }
.tasks li { margin-bottom: 10px; }
.tasks p { margin: 0 0 2px; }
details summary { cursor: pointer; }
.tasks summary { color: var(--accent); font-size: 0.85rem; min-height: 32px; display: flex; align-items: center; }
.tasks details p { background: #05070f; border: 1px solid var(--line); padding: 8px 10px; border-radius: 8px; margin: 4px 0 0; color: var(--muted); }

/* ---------- quiz ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
h2 { font-size: 1rem; margin: 0 0 10px; }
.recap { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.recap > div { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 2px; font-size: 0.85rem; color: var(--muted); }
.recap .rule-key { justify-self: start; }
.recap .formula { font-size: 1.1rem; }
.quiz-card, .recap { max-width: 980px; margin-inline: auto; }
.quiz-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.quiz-score { margin: 0; font-family: var(--mono); color: var(--accent); }
.quiz { padding-left: 1.4em; }
.quiz > li { margin: 0 0 22px; }
.quiz .question { margin: 0 0 8px; font-weight: 600; white-space: pre-line; }
.quiz .options { display: grid; gap: 6px; }
.quiz .options button { text-align: left; display: flex; gap: 10px; align-items: flex-start; background: #05070f; }
.quiz .options button .letter { font-family: var(--mono); font-weight: 700; min-width: 1.2em; color: var(--muted); }
.quiz .options button.correct { border-color: var(--good); background: rgba(79, 209, 138, 0.12); }
.quiz .options button.wrong { border-color: var(--bad); background: rgba(255, 122, 122, 0.12); }
.quiz .options button:disabled { opacity: 1; cursor: default; }
.quiz .explain { margin: 8px 0 0; padding: 10px 12px; border-radius: 8px; background: #05070f; border: 1px solid var(--line); font-size: 0.9rem; color: var(--muted); }
.quiz .explain strong { color: var(--text); }
.quiz .explain button { margin-top: 8px; min-height: 36px; font-size: 0.85rem; }

/* ---------- guide dialog ---------- */
dialog { padding: 0; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--panel); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(3px); }
dialog[open] { animation: dialog-in 0.24s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
dialog.guide-dialog { width: min(760px, calc(100vw - 32px)); max-height: 86vh; display: none; flex-direction: column; }
dialog.guide-dialog[open] { display: flex; }
.guide-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.guide-dialog-head h2 { margin: 0; font-size: 1.1rem; }
.guide-dialog-body { padding: 14px 18px 18px; overflow-y: auto; font-size: 0.95rem; }
.guide-dialog-body h3 { margin: 18px 0 6px; font-size: 1rem; color: var(--accent); }
.guide-dialog-body h3:first-child { margin-top: 0; }
.guide-dialog-body ul { padding-left: 1.2em; color: var(--muted); font-size: 0.88rem; }
.guide-dialog-body li { margin-bottom: 6px; }
.map-row { display: grid; grid-template-columns: minmax(0, 15rem) minmax(0, 1fr); gap: 16px; align-items: start; }
.map {
  display: grid; gap: 4px; aspect-ratio: 16 / 10; font-size: 0.72rem; color: var(--muted);
  grid-template-columns: 1fr 1fr 0.9fr; grid-template-rows: 1fr auto auto;
  grid-template-areas: "stage stage panel" "predict fire panel" "card card panel";
}
.map > div { position: relative; border: 1px solid var(--line-strong); border-radius: 6px; background: #05070f; padding: 4px 6px 4px 24px; display: flex; flex-direction: column; justify-content: center; }
.map i { position: absolute; left: 4px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font: 700 0.68rem/16px var(--sans); text-align: center; font-style: normal; }
.map-stage { grid-area: stage; }
.map-panel { grid-area: panel; justify-content: flex-start !important; padding-top: 6px !important; }
.map-panel i { top: 14px; }
.map-panel span { margin-top: 3px; padding: 1px 4px; border-radius: 4px; background: var(--panel); font-size: 0.66rem; }
.map-predict { grid-area: predict; }
.map-fire { grid-area: fire; color: var(--accent) !important; }
.map-card { grid-area: card; min-height: 2rem; }
.map-key { margin: 0; padding-left: 1.4em; font-size: 0.9rem; }
.map-key li { margin-bottom: 4px; }
.map-key li::marker { color: var(--accent); font-weight: 700; }
.map-key b { margin-right: 4px; }
.flow { list-style: none; margin: 0 0 8px; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; counter-reset: step; }
.flow li {
  counter-increment: step; position: relative; display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 2px; padding: 8px 4px; border: 1px solid var(--line); border-radius: 8px; font-size: 0.8rem; color: var(--muted);
}
.flow li + li::before { content: "›"; position: absolute; left: -7px; top: 22px; color: var(--accent); font-weight: 700; }
.flow b { color: var(--text); font-size: 0.92rem; }
.flow b::before { content: counter(step) ". "; color: var(--accent); }
.flow-ui { display: flex; gap: 3px; justify-content: center; align-items: center; min-height: 30px; flex-wrap: wrap; }
.mini { display: inline-block; padding: 2px 7px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--text); font-size: 0.72rem; white-space: nowrap; }
.chip { border-radius: 999px; }
.fire-chip { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.tag-good { color: var(--good); border-color: rgba(79, 209, 138, 0.5); }
.flow-again { font-size: 1.2rem; color: var(--accent); line-height: 1; }
.keys { margin: 8px 0 0; color: var(--muted); font-size: 0.85rem; }
.model-notes { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.model-notes summary { color: var(--accent); font-weight: 600; min-height: 32px; }
kbd { font-family: var(--mono); font-size: 0.85em; padding: 0 5px; border-radius: 4px; border: 1px solid var(--line-strong); background: #05070f; color: var(--text); }

/* ---------- desktop: one screen ---------- */
/* Header, bench, action bar and result share one viewport height, so the light and its explanation are on screen together. */
@media (min-width: 901px) {
  :root { --base: clamp(16px, 0.4vw + 10.5px, 19px); --bar-h: 3.5rem; }
  .topbar { display: flex; align-items: center; gap: 10px; height: var(--bar-h); padding: 0 20px; }
  .topbar-row { display: contents; }
  .back-link { order: 1; }
  .wordmark { order: 2; margin-right: 14px; }
  .tabs { order: 3; margin: 0 auto 0 0; align-self: stretch; max-width: none; }
  .tabs [role="tab"] { min-height: 100%; padding-inline: 12px; }
  .topic-pill { order: 4; margin-left: 0; }
  #guide-toggle { order: 5; }

  main { max-width: none; padding: 14px 20px; }
  .workspace {
    grid-template-columns: minmax(0, 1fr) clamp(290px, 24vw, 420px); gap: 16px; align-items: stretch;
    height: min(calc(100vh - var(--bar-h) - 30px), 75vw);
    height: min(calc(100dvh - var(--bar-h) - 30px), 75vw);
  }
  .stage-col { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
  .stage { flex: 1 1 0; min-height: 11rem; display: flex; flex-direction: column; }
  .canvas-box { flex: 1 1 0; min-height: 0; }
  .canvas-box > .stage-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
  .rule { font-size: 0.95rem; }
  .actionbar { padding: 0; gap: 10px 16px; }
  .actionbar button { white-space: nowrap; }
  .fire { min-height: 50px; font-size: 1.05rem; padding-inline: 26px; }
  .side-close { display: none; }
  .verdict { margin-top: 0; flex: none; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto); column-gap: 20px; row-gap: 4px; align-items: center; align-content: start; height: 7.6rem; overflow: hidden; padding: 12px 16px; }
  .verdict-head { grid-column: 1; grid-row: 1; }
  .verdict > p { grid-column: 1 / -1; grid-row: 2; }
  .verdict strong { font-size: 1.15rem; }
  .verdict .budget { grid-column: 2; grid-row: 1; margin: 0; max-width: min(30rem, 42vw); padding: 6px 10px; border: 1px solid var(--line); }
  .side { position: static; max-height: none; height: 100%; min-height: 0; }
  .side-body { flex: 1 1 auto; min-height: 0; }
}
@media (min-width: 901px) and (max-width: 1279px) {
  .pill-long, .topic-pill { display: none; }
  .tabs [role="tab"] { padding-inline: 8px; font-size: 0.9rem; }
  .tabs .tab-num { display: none; }
  .verdict { grid-template-columns: minmax(0, 1fr); height: 9rem; overflow-y: auto; }
  .verdict .budget { grid-column: 1; grid-row: 3; justify-self: start; max-width: 100%; font-size: 0.8rem; }
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .workspace, .workspace.side-collapsed { grid-template-columns: 1fr; }
  .recap { grid-template-columns: 1fr; }
  .workspace .side, .workspace.side-collapsed .side {
    display: flex; position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
    width: min(380px, 90vw); max-height: none; border-radius: 0; border-width: 0 0 0 1px;
    transform: translateX(105%); visibility: hidden;
    transition: transform 0.25s ease, visibility 0s linear 0.25s;
  }
  .workspace .side.open { transform: none; visibility: visible; transition: transform 0.25s ease; }
}
@media (max-width: 600px) {
  main { padding: 10px 12px 32px; }
  .topbar { padding: 6px 12px 0; }
  .topbar-row { gap: 6px; }
  .topic-pill { font-size: 0.66rem; padding: 2px 8px; }
  .pill-long { display: none; }
  .wordmark { font-size: 0.98rem; }
  .tabs [role="tab"] { padding: 8px 9px; font-size: 0.88rem; }
  .stage-canvas { height: 300px; }
  .rule { font-size: 0.8rem; }
  .map-row { grid-template-columns: 1fr; }
  .map { max-width: 16rem; }
  .flow { grid-template-columns: 1fr; }
  .flow li { flex-direction: row; justify-content: flex-start; text-align: left; gap: 8px; }
  .flow li + li::before { content: none; }
  .flow-ui { min-width: 6.5rem; justify-content: flex-start; }
  /* Keep predict + fire reachable under the tall bench. */
  .actionbar {
    flex-direction: column; align-items: stretch;
    position: sticky; bottom: 0; z-index: 5; padding: 8px 0 10px;
    background: rgba(7, 10, 20, 0.94); backdrop-filter: blur(6px);
  }
  .predict-q { flex-basis: 100%; order: 1; margin: 0; }
  .predict-label { order: 0; }
  .predict-options { display: flex; gap: 6px; order: 2; flex-basis: 100%; }
  .predict button { flex: 1 1 0; min-width: 0; padding: 6px 6px; font-size: 0.82rem; }
  .fire-row .fire { flex: 1; padding-inline: 12px; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  button, .workspace .side, .workspace .side.open { transition: none; }
  .verdict.cheer, .predict.cue button[data-predict] { animation: none; }
  button:active:not(:disabled) { transform: none; }
  .fire.launch::after, .fire.launch .ic, button[data-predict][aria-pressed="true"], .verdict.fresh > *,
  .side-page:not([hidden]), dialog[open] { animation: none; }
  .tabs [role="tab"]::after, .side-tabs [role="tab"]::after { transition: none; }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
