:root {
  color-scheme: dark;
  --bg: #0b0b0c;
  --panel: #151517;
  --panel-2: #1c1c1f;
  --line: #303034;
  --text: #f5f5f2;
  --muted: #96969d;
  --accent: #f0c443;
  --accent-soft: #2b2615;
  --good: #7ddc94;
  --bad: #ff7b72;
  --warn: #f0c443;
  --radius: 8px;
  --topbar-h: 68px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button, a { color: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- chrome ---------- */
.topbar { height: var(--topbar-h); padding: 0 24px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #222225; position: sticky; top: 0; background: rgba(11,11,12,.96); z-index: 20; }
.brand { border: 0; background: transparent; display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 0; text-align: left; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; background: var(--accent); color: #0b0b0c; font-weight: 900; border-radius: 5px; flex: none; }
.brand strong, .brand small { display: block; line-height: 1; letter-spacing: .13em; }
.brand strong { font-size: 13px; }
.brand small { font-size: 9px; color: var(--muted); margin-top: 5px; }
.topnav { display: flex; gap: 6px; align-items: center; }
.nav-btn, .discord-link { border: 0; background: transparent; color: var(--muted); padding: 10px 12px; font-size: 12px; font-weight: 800; letter-spacing: .1em; cursor: pointer; border-radius: 5px; text-decoration: none; white-space: nowrap; }
.nav-btn:hover, .nav-btn.active, .discord-link:hover { background: var(--panel-2); color: var(--text); }
.app-shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 48px 0 72px; }
.view { display: none; }
.view.active { display: block; }

/* ---------- setup ---------- */
.hero-panel { max-width: 760px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 10px; color: var(--accent); font-size: 11px; font-weight: 900; letter-spacing: .17em; }
.hero-panel h1, .page-heading h2 { margin: 0; font-size: clamp(38px, 7vw, 72px); letter-spacing: -.055em; line-height: .94; }
.hero-copy, .page-heading p, .helper-copy { color: var(--muted); max-width: 700px; line-height: 1.65; }
.helper-copy { margin: 12px 0 0; font-size: 12px; }
.rule-box { margin-top: 22px; display: inline-flex; gap: 14px; align-items: center; background: var(--accent-soft); border-left: 3px solid var(--accent); padding: 12px 15px; border-radius: 0 var(--radius) var(--radius) 0; }
.rule-box strong { color: var(--accent); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.rule-box span { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.inline-warning { margin: 0 0 18px; padding: 12px 14px; border-radius: var(--radius); background: #2a1a17; border-left: 3px solid var(--bad); color: #ffd6d2; font-size: 13px; }
.setup-grid { display: grid; grid-template-columns: 1.1fr 1.6fr; gap: 14px; }
.panel { background: var(--panel); border: 1px solid #242428; border-radius: var(--radius); padding: 18px; }
.panel-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.panel-heading.compact { margin-bottom: 10px; }
.panel-heading span { font-size: 12px; font-weight: 900; letter-spacing: .13em; }
.panel-heading small { color: var(--muted); text-align: right; }
.mode-panel { grid-column: 1 / -1; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label span { min-height: 72px; display: grid; place-items: center; text-align: center; background: #202023; color: #b8b8be; border-radius: 6px; cursor: pointer; font-weight: 800; }
.segmented label small { color: #777780; font-weight: 600; }
.segmented input:checked + span { background: var(--accent); color: #111; }
.segmented input:checked + span small { color: #4d421d; }
.fields-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.field { background: #1e1e21; padding: 10px 12px; border-radius: 6px; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.field-wide { grid-column: 1 / -1; }
.field-check { cursor: pointer; }
.field span { color: #b7b7bd; font-size: 12px; }
.field small { color: #707078; }
.field input[type="number"] { width: 96px; background: #111113; color: var(--text); border: 0; border-radius: 4px; padding: 9px; text-align: right; }
.field input[type="checkbox"] { accent-color: var(--accent); width: 18px; height: 18px; }
.check-row { display: flex; align-items: center; gap: 9px; margin-top: 12px; color: #bdbdc2; font-size: 13px; }
.check-row input { accent-color: var(--accent); }
.toggle-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.stream-toggle, .shape-toggle { background: #1e1e21; border-radius: 6px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.stream-toggle input, .shape-toggle input { accent-color: var(--accent); flex: none; }
.stream-toggle b { width: 24px; height: 24px; display: grid; place-items: center; background: #0f0f10; color: var(--accent); border-radius: 4px; font-size: 12px; flex: none; }
.shape-toggle small { color: var(--accent); font-weight: 800; }
.shape-panel { margin-top: 16px; }
.shapes-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
.start-btn { grid-column: 1 / -1; min-height: 72px; background: var(--accent); color: #111; border: 0; border-radius: var(--radius); cursor: pointer; font-weight: 950; letter-spacing: .06em; }
.start-btn span, .start-btn small { display: block; }
.start-btn small { font-weight: 700; opacity: .62; margin-top: 4px; }

/* ---------- game: always fits the viewport, never scrolls ---------- */
body.in-game { overflow: hidden; }
body.in-game .app-shell { padding: 10px 0 12px; height: calc(100dvh - var(--topbar-h)); }
#game-view.active { display: flex; flex-direction: column; height: 100%; gap: 8px; }
.game-topline { display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 10px; flex: none; }
.game-topline > * { min-width: 0; }
.topline-actions { display: flex; gap: 6px; justify-self: end; }
#quit-session { justify-self: start; }
.quiet-btn, .secondary-btn { border: 0; background: #1b1b1e; color: #b6b6bc; padding: 9px 12px; border-radius: 5px; cursor: pointer; font-size: 11px; font-weight: 850; letter-spacing: .08em; white-space: nowrap; }
.quiet-btn:hover, .secondary-btn:hover { background: #26262a; color: var(--text); }
.session-meta { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 11px; letter-spacing: .08em; color: var(--muted); white-space: nowrap; overflow: hidden; }
.session-meta b { color: var(--accent); }
.progress-track { height: 4px; background: #1e1e21; flex: none; border-radius: 2px; overflow: hidden; }
.progress-track div { height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }

.game-hud { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 8px 14px; background: var(--panel); border-radius: 7px; color: var(--muted); font-size: 12px; }
.game-hud strong { color: var(--accent); font-size: clamp(18px, 2.4vw, 24px); letter-spacing: .03em; white-space: nowrap; }
.game-hud.warmup strong { color: var(--muted); }
#hud-rule { text-align: right; }

.game-stage { flex: 1 1 auto; min-height: 0; position: relative; display: grid; place-items: center; container-type: size; overflow: hidden; }
.grid-2d { width: min(100%, 62vh); height: min(100%, 62vh); display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 8px; }
.solo-stage { width: min(100%, 62vh); height: min(100%, 62vh); display: none; place-items: center; }
#cube-3d { width: min(100%, 62vh); height: min(100%, 62vh); display: none; }
@supports (width: 1cqh) {
  .grid-2d, .solo-stage, #cube-3d { width: min(100cqw, 100cqh); height: min(100cqw, 100cqh); }
}
.grid-cell, .solo-cell { background: #141416; border: 1px solid #1d1d20; border-radius: 6px; display: grid; place-items: center; min-width: 0; min-height: 0; }
.solo-cell { width: 74%; height: 74%; }
.grid-cell.active, .solo-cell.active { background: #232327; border-color: #3a3a41; box-shadow: inset 0 0 0 2px rgba(240,196,67,.28); }
.stimulus-svg { width: 88%; height: 88%; overflow: visible; }
.stimulus-outline { fill: rgba(245,245,242,.035); stroke: var(--text); stroke-width: 3; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.glyph-node { fill: none; stroke: var(--accent); stroke-width: 3.4; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.neutral-marker circle { fill: none; stroke: #3c3c43; stroke-width: 3; vector-effect: non-scaling-stroke; }
.pause-overlay { position: absolute; inset: 0; background: rgba(11,11,12,.88); display: grid; place-items: center; align-content: center; gap: 8px; font-size: 22px; font-weight: 950; letter-spacing: .18em; border-radius: 8px; }
.pause-overlay small { font-size: 11px; font-weight: 700; letter-spacing: .1em; color: var(--muted); }
.pause-overlay[hidden] { display: none; }

.response-deck { flex: none; display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 8px; }
.response-card { min-width: 0; background: var(--panel); border-radius: 7px; padding: 9px 8px; text-align: center; }
.response-card.hidden { display: none; }
.response-channel { display: block; color: #777780; font-size: 9px; font-weight: 900; letter-spacing: .09em; }
.response-card strong { min-height: 2.3em; display: grid; place-items: center; margin: 2px 0 6px; font-size: clamp(11px, 1.5vw, 16px); line-height: 1.15; overflow-wrap: anywhere; }
.response-btn { width: 100%; border: 0; background: #29292d; padding: 11px 6px; border-radius: 5px; cursor: pointer; font-weight: 900; font-size: 11px; letter-spacing: .08em; transition: background .12s ease; }
.response-btn.pressed { background: var(--accent); color: #111; }
.response-btn.hit { background: var(--good); color: #111; }
.response-btn.false-alarm, .response-btn.miss { background: var(--bad); color: #111; }
.response-btn.correct-rejection { background: #3a4b3d; color: #d7f0dc; }
.response-deck.warmup .response-btn { opacity: .4; cursor: not-allowed; }
.verdict { height: 14px; margin-top: 5px; display: block; font-size: 9px; font-weight: 900; letter-spacing: .07em; }
.verdict.good { color: var(--good); }
.verdict.bad { color: var(--bad); }
.verdict.warn { color: var(--warn); }

/* ---------- results / wiki / history ---------- */
.results-wrap { text-align: center; max-width: 760px; margin: 5vh auto; }
.results-wrap h2 { font-size: clamp(72px,16vw,150px); line-height: 1; margin: 8px 0; color: var(--accent); letter-spacing: -.08em; }
.muted { color: var(--muted); }
.result-streams { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; margin: 30px 0; }
.result-card { background: var(--panel); padding: 18px 10px; border-radius: 7px; }
.result-card span { display:block;color:var(--muted);font-size:10px;font-weight:850;letter-spacing:.08em; }
.result-card strong { display:block;font-size:28px;margin-top:6px; }
.result-card small { display:block; margin-top:4px; color:#b9b9be; font-size: 11px; }
.result-actions { display:flex;justify-content:center;gap:8px; }
.primary-btn { background: var(--accent); color: #111; border:0;border-radius:5px;padding:13px 18px;font-weight:900;cursor:pointer; }
.page-heading { margin-bottom: 28px; }
.page-heading h2 { font-size: clamp(36px,6vw,60px); }
.wiki-section { margin: 28px 0; }
.wiki-section h3 { font-size: 13px; letter-spacing: .12em; color: var(--accent); }
.wiki-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.wiki-card { background: var(--panel); border-radius: 7px; padding: 16px; }
.wiki-card h4 { margin: 0 0 7px; }
.wiki-card p, .wiki-card li { color: var(--muted); line-height: 1.55; font-size: 13px; }
.wiki-card b, .wiki-card strong { color: var(--text); }
.key-rule { background: var(--accent-soft); border-left: 3px solid var(--accent); padding: 16px 18px; border-radius: 0 7px 7px 0; margin: 14px 0 18px; }
.key-rule p { color: #ecdcb0; font-size: 14px; line-height: 1.6; margin: 6px 0 0; }
.key-rule h4 { margin: 0; color: var(--accent); letter-spacing: .04em; }
.relation-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.relation-entry { background: var(--panel); border-radius: 7px; padding: 14px; display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: start; }
.relation-art { background: #0f0f10; border-radius: 6px; padding: 6px; }
.relation-art svg { width: 100%; height: auto; display: block; }
.relation-entry h4 { margin: 0 0 2px; font-size: 16px; }
.relation-entry .family-tag { display: inline-block; font-size: 9px; font-weight: 900; letter-spacing: .1em; color: #0b0b0c; background: var(--accent); border-radius: 3px; padding: 2px 6px; margin-bottom: 8px; }
.relation-entry p { margin: 0 0 6px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.relation-entry .worked { color: #cfcfd5; background: #0f0f10; border-radius: 5px; padding: 8px 10px; font-size: 12px; }
.decision-list { counter-reset: step; list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.decision-list li { background: var(--panel); border-radius: 6px; padding: 12px 14px 12px 44px; position: relative; color: var(--muted); font-size: 13px; line-height: 1.55; }
.decision-list li::before { counter-increment: step; content: counter(step); position: absolute; left: 12px; top: 11px; width: 22px; height: 22px; display: grid; place-items: center; background: var(--accent); color: #111; border-radius: 4px; font-size: 11px; font-weight: 900; }
.symbol-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.symbol-tile { background:#0f0f10;border-radius:5px;padding:10px;text-align:center; }
.symbol-tile svg { width: 100%; height: auto; }
.symbol-tile span { display:block; font-size:11px; color:#b8b8be; margin-top:6px; }
.wiki-table { width:100%;border-collapse:collapse;background:var(--panel);border-radius:7px;overflow:hidden; }
.wiki-table th,.wiki-table td { padding:12px;border-bottom:1px solid #28282c;text-align:left;font-size:12px; }
.wiki-table th { color:#7d7d85;font-size:10px;letter-spacing:.08em; }
.history-list { display:grid;gap:8px; }
.history-item { background:var(--panel);padding:14px;border-radius:7px;display:grid;grid-template-columns:1.2fr .6fr 1.8fr;align-items:center;gap:12px; }
.history-item small { color:var(--muted); }
.history-item strong { color:var(--accent);font-size:22px; }
.history-streams { display:flex;gap:10px;justify-content:flex-end;font-size:11px;color:#b9b9be; flex-wrap:wrap; }
.empty-state { padding:32px;background:var(--panel);border-radius:7px;color:var(--muted);text-align:center; }
code { color: var(--accent); }

/* ---------- relation cheat sheet modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(6,6,7,.82); display: grid; place-items: center; padding: 18px; z-index: 40; }
.modal[hidden] { display: none; }
.modal-card { background: var(--panel); border: 1px solid #2a2a2f; border-radius: var(--radius); width: min(880px, 100%); max-height: min(86dvh, 900px); overflow: auto; padding: 20px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.sheet-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 8px; }
.sheet-tile { background: #0f0f10; border-radius: 6px; padding: 10px; text-align: center; }
.sheet-tile svg { width: 100%; height: auto; }
.sheet-tile b { display: block; font-size: 12px; margin-top: 6px; }
.sheet-tile span { display: block; font-size: 10.5px; color: var(--muted); line-height: 1.4; margin-top: 4px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .relation-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .topbar{padding:0 12px}
  .app-shell{width:min(100% - 20px,1120px);padding-top:28px}
  .setup-grid{grid-template-columns:1fr}
  .settings-panel,.stream-panel{grid-column:1}
  .fields-grid{grid-template-columns:1fr}
  .field-wide { grid-column: auto; }
  .result-streams{grid-template-columns:repeat(2,1fr)}
  .wiki-grid{grid-template-columns:1fr}
  .history-item{grid-template-columns:1fr}
  .history-streams{justify-content:flex-start}
  .brand strong{font-size:11px}
  .topnav{gap:0}
  .nav-btn, .discord-link{padding:9px 7px;font-size:11px}
  .session-meta{gap:8px;font-size:10px}
  .segmented label span{font-size:12px}
  .symbol-row{grid-template-columns:repeat(2,minmax(0,1fr))}
  .shapes-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .sheet-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .game-hud { padding: 7px 10px; font-size: 11px; }
  #hud-rule { display: none; }
  .relation-entry { grid-template-columns: 78px 1fr; }
}
@media (max-width: 560px) {
  #mode-label { display: none; }
  #relation-help { font-size: 0; padding: 9px 11px; }
  #relation-help::after { content: 'HELP'; font-size: 10px; }
}
@media (max-width: 430px) {
  :root { --topbar-h: 60px; }
  .brand-mark{width:32px;height:32px}
  .brand small{display:none}
  .discord-link{display:none}
  .toggle-grid { grid-template-columns: 1fr; }
  .response-card{padding:7px 5px}
  .response-btn{padding:10px 4px;font-size:10px}
  .response-channel{font-size:8px}
  .quiet-btn { padding: 8px 9px; font-size: 10px; }
  .grid-2d { gap: 6px; }
}
@media (max-height: 640px) {
  .game-hud strong { font-size: 17px; }
  .response-card strong { min-height: 20px; }
  .response-btn { padding: 9px 5px; }
}
