body{margin:0}
/* Layout: one centred column. SVG stage (knowledge base panel over closure panel), key,
   narration line, control bar, then the optional knowledge-base editor. */
:root {
  --bg: #eef1f0;
  --panel: #fbfcfb;
  --ink: #1d2a2e;
  --muted: #5b6a6f;
  --line: #d2d9d7;
  --accent: #2c4f7c;
  --accent-ink: #ffffff;
  --band: #e4ecf5;
  --node: #dde2e3;
  --node-stroke: #a7b1b4;
  --node-ink: #4a565b;
  --true: #2e9a5a;
  --true-line: #1d7442;
  --true-ink: #ffffff;
  --probe: #cf870b;
  --miss: #c2483a;

  --font-display: "Newsreader", Georgia, "Times New Roman", serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121618; --panel: #1a1f22; --ink: #e3e8e9; --muted: #9aa6aa; --line: #2d3539;
    --accent: #8fb3e6; --accent-ink: #0e1620; --band: #1f2a37;
    --node: #2e363a; --node-stroke: #4d585d; --node-ink: #b9c3c6;
    --true: #36a865; --true-line: #74d79b; --true-ink: #06150c;
    --probe: #f0ad3a; --miss: #ec7766;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121618; --panel: #1a1f22; --ink: #e3e8e9; --muted: #9aa6aa; --line: #2d3539;
  --accent: #8fb3e6; --accent-ink: #0e1620; --band: #1f2a37;
  --node: #2e363a; --node-stroke: #4d585d; --node-ink: #b9c3c6;
  --true: #36a865; --true-line: #74d79b; --true-ink: #06150c;
  --probe: #f0ad3a; --miss: #ec7766;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
}

.wrap {
  max-width: 940px;
  margin: 0 auto;
  padding-inline: 20px;
  padding-block: 28px 56px;
  display: grid;
  gap: 18px;
}

/* ---------- Intro ---------- */
.intro { display: grid; gap: 6px; }
.eyebrow {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(30px, 4.4vw, 40px);
  line-height: 1.08;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.lede { margin: 0; max-width: 66ch; color: var(--muted); }

/* ---------- Stage ---------- */
.stage { display: grid; gap: 10px; min-width: 0; }
.stage-scroll { overflow-x: auto; }
#stage { display: block; width: 100%; height: auto; min-width: 560px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  color: var(--muted);
}
.legend li { display: inline-flex; align-items: center; gap: 7px; }
.sw {
  display: inline-block;
  width: 24px;
  height: 15px;
  border-radius: 8px;
  border: 1.5px solid var(--node-stroke);
  background: var(--node);
}
.sw.probe { border: 2.5px solid var(--probe); }
.sw.miss { border: 2px dashed var(--miss); }
.sw.true { background: var(--true); border-color: var(--true-line); }

/* ---------- Narration ---------- */
.status {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
  margin: 0;
  min-height: 3.2em;
  font-size: 15.5px;
}
.chip {
  flex: none;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 9px;
  border-radius: 5px;
  background: var(--band);
  color: var(--accent);
  white-space: nowrap;
}
.msg { flex: 1 1 280px; min-width: 0; }
.atom { font-family: var(--font-mono); font-weight: 600; }
.atom.t { color: var(--true-line); }
.atom.f { color: var(--miss); }

/* ---------- Controls ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 28px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 15px;
  font: 500 14px/1.2 var(--font-body);
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn.primary {
  min-width: 112px;
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}
.btn.primary:hover:not(:disabled) { border-color: var(--accent); filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: default; }
.icon { width: 14px; height: 14px; fill: currentColor; }

.slider {
  flex: 1 1 230px;
  min-width: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}
.slider-label { font-size: 13.5px; color: var(--muted); white-space: nowrap; }
input[type="range"] { width: 100%; min-width: 0; accent-color: var(--accent); }
output {
  min-width: 7ch;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.btn:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Editor ---------- */
.editor {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
}
.editor summary { cursor: pointer; font-weight: 500; }
.hint { margin: 10px 0; max-width: 66ch; font-size: 14px; color: var(--muted); }
.hint code {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--band);
  color: var(--ink);
}
textarea {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  resize: vertical;
}
.editor-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 10px; }
.error { flex: 1 1 200px; margin: 0; font-size: 13.5px; color: var(--miss); }

/* ---------- SVG stage contents ---------- */
.panel-bg { fill: var(--panel); stroke: var(--line); stroke-width: 1; }
.panel-title { font-family: var(--font-display); font-size: 23px; font-weight: 600; fill: var(--ink); }
.panel-sub { font-family: var(--font-body); font-size: 13px; fill: var(--muted); }
.section-label { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.14em; fill: var(--muted); }
.end { text-anchor: end; }
.count { font-family: var(--font-mono); font-size: 13px; fill: var(--muted); }

.row-band { fill: var(--band); opacity: 0; transition: opacity 0.25s; }
.row.is-focus .row-band { opacity: 1; }
.row-label { font-family: var(--font-mono); font-size: 13px; font-weight: 500; fill: var(--muted); dominant-baseline: central; }
.conj { font-family: var(--font-body); font-size: 19px; fill: var(--muted); text-anchor: middle; dominant-baseline: central; }
.arrow { stroke: var(--muted); stroke-width: 2; transition: stroke 0.35s; }
.arrowhead { fill: var(--muted); transition: fill 0.35s; }
.row.is-fired .arrow { stroke: var(--true); }
.row.is-fired .arrowhead { fill: var(--true); }
.row-status { font-family: var(--font-mono); font-size: 12px; fill: var(--muted); text-anchor: end; dominant-baseline: central; }
.row.is-fired .row-status { fill: var(--true-line); }

.node .body { fill: var(--node); stroke: var(--node-stroke); stroke-width: 1.5; transition: fill 0.35s, stroke 0.35s; }
.node text {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  fill: var(--node-ink);
  text-anchor: middle;
  dominant-baseline: central;
  transition: fill 0.35s;
}
.node.is-true .body { fill: var(--true); stroke: var(--true-line); }
.node.is-true text { fill: var(--true-ink); }
.node .ring { fill: none; stroke: var(--probe); stroke-width: 2.5; opacity: 0; transition: opacity 0.2s; }
.node.is-probe .ring { opacity: 1; animation: ringpulse 0.9s ease-in-out infinite; }
.node.is-miss .ring { opacity: 1; stroke: var(--miss); stroke-width: 2; stroke-dasharray: 5 4; }
.node.pop { animation: pop 0.45s cubic-bezier(0.3, 1.4, 0.5, 1); transform-box: fill-box; transform-origin: center; }

.caption { font-family: var(--font-mono); font-size: 11px; fill: var(--muted); text-anchor: middle; }
.placeholder { font-family: var(--font-body); font-size: 14px; font-style: italic; fill: var(--muted); dominant-baseline: central; transition: opacity 0.3s; }
.placeholder.is-hidden { opacity: 0; }

.badge rect { fill: var(--band); }
.badge-text {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  fill: var(--accent);
  text-anchor: middle;
  dominant-baseline: central;
}
.badge.is-done rect { fill: var(--true); }
.badge.is-done .badge-text { fill: var(--true-ink); }

.trail { fill: none; stroke: var(--true); stroke-width: 1.5; stroke-dasharray: 3 5; opacity: 0.7; transition: opacity 0.6s; }
.trail.fade { opacity: 0; }

@keyframes ringpulse { 0%, 100% { stroke-opacity: 1; } 50% { stroke-opacity: 0.3; } }
@keyframes pop { 0% { transform: scale(0.6); } 70% { transform: scale(1.1); } 100% { transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  .node.is-probe .ring, .node.pop { animation: none; }
  .row-band, .node .body, .node text, .trail { transition: none; }
}
