/* Layout: one centered column on a stadium-green field; brick-red lanes carry the race. */
:root {
  --field: #10302a;
  --field-2: #173f36;
  --track: #b5452f;
  --track-dark: #8f3322;
  --chalk: #f4efe4;
  --chalk-dim: #b9c4bd;
  --gold: #e9b43c;
  --right: #6fd39a;
  --wrong: #ff8a7a;
  --display: 'Big Shoulders Display', 'Arial Narrow', Impact, sans-serif;
  --body: 'Atkinson Hyperlegible', 'Segoe UI', system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--field);
  color: var(--chalk);
  font: 17px/1.5 var(--body);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 24px 48px;
}
main { max-width: 760px; margin: 0 auto; display: grid; gap: 22px; }
main.wide { max-width: 1100px; }
h1, h2 { font-family: var(--display); font-weight: 800; text-transform: uppercase; margin: 0; line-height: 0.95; text-wrap: balance; }
h1 { font-size: clamp(44px, 9vw, 84px); letter-spacing: 0.01em; }
h2 { font-size: clamp(26px, 5vw, 40px); }
p { margin: 0; }
.eyebrow { font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: 0.14em; color: var(--gold); font-size: 15px; }
.muted { color: var(--chalk-dim); }
.question { font-size: clamp(20px, 3.4vw, 28px); line-height: 1.35; font-weight: 700; text-wrap: balance; }

input, button { font: inherit; }
input[type=text] {
  width: 100%; padding: 14px 16px; border-radius: 6px; border: 2px solid var(--chalk-dim);
  background: var(--field-2); color: var(--chalk);
}
button {
  cursor: pointer; border: 0; border-radius: 6px; padding: 14px 20px;
  background: var(--gold); color: #1d1606; font-weight: 700;
}
button:disabled { opacity: 0.45; cursor: default; }
.option:disabled { opacity: 1; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--chalk); outline-offset: 2px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }

.options { display: grid; gap: 10px; }
.option {
  text-align: left; background: var(--field-2); color: var(--chalk);
  border: 2px solid #2d5a4e; font-weight: 400; display: flex; gap: 12px; align-items: baseline;
}
.option b { font-family: var(--display); font-size: 22px; color: var(--gold); min-width: 1ch; }
.option.picked { border-color: var(--gold); }
.option.correct { border-color: var(--right); background: #1d4a3a; }
.option.incorrect { border-color: var(--wrong); }

.timer { height: 8px; background: var(--field-2); border-radius: 4px; overflow: hidden; }
.timer > i { display: block; height: 100%; background: var(--gold); width: 100%; transform-origin: left; }

.result { font-family: var(--display); font-size: 34px; font-weight: 800; text-transform: uppercase; }
.result.good { color: var(--right); }
.result.bad { color: var(--wrong); }
.note { background: var(--field-2); border-left: 4px solid var(--gold); padding: 14px 16px; border-radius: 0 6px 6px 0; }

/* Track */
.track { background: var(--track); border-radius: 8px; padding: 6px 0; position: relative; overflow: hidden; }
.lane {
  position: relative; height: 44px; border-bottom: 2px solid rgba(244, 239, 228, 0.55);
  margin-inline: 10px 34px;
}
.lane:last-child { border-bottom: 0; }
.track::after {
  content: ''; position: absolute; top: 0; bottom: 0; right: 20px; width: 10px;
  background: repeating-conic-gradient(var(--chalk) 0 25%, #1a1a1a 0 50%) 0 0 / 10px 10px;
}
.runner {
  position: absolute; top: 50%; left: 0; transform: translate(0, -50%);
  display: flex; align-items: center; gap: 8px; white-space: nowrap;
  transition: left 1.6s cubic-bezier(.3, .7, .3, 1);
}
.runner .dot {
  width: 22px; height: 22px; border-radius: 50%; background: var(--chalk);
  box-shadow: 0 0 0 3px var(--track-dark); flex: none;
}
.runner .tag { font-weight: 700; font-size: 14px; text-shadow: 0 1px 2px #0006; }
.board .lane { height: 24px; }
.board .runner .dot { width: 14px; height: 14px; }
.board .runner .tag { font-size: 12px; }
.board .runner { transition-duration: 7s; transition-timing-function: cubic-bezier(.45, .05, .25, 1); }
.lane.mine .dot { background: var(--gold); }
.lane.mine .tag { color: var(--gold); }
.lane.top .dot { background: var(--gold); }

.score { font-variant-numeric: tabular-nums; }

/* Podium */
.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; align-items: end; }
.step { text-align: center; opacity: 0; transform: translateY(16px); transition: opacity .6s, transform .6s; }
.step.show { opacity: 1; transform: none; }
.step .name { font-weight: 700; font-size: clamp(15px, 2.4vw, 22px); overflow-wrap: anywhere; }
.step .block {
  margin-top: 8px; background: var(--chalk); color: var(--field); border-radius: 6px 6px 0 0;
  font-family: var(--display); font-weight: 800; font-size: clamp(34px, 6vw, 60px); display: grid; place-items: center;
}
.step.p1 .block { height: 150px; background: var(--gold); color: #1d1606; }
.step.p2 .block { height: 110px; }
.step.p3 .block { height: 80px; background: #d7c9b0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--field-2); border: 1px solid #2d5a4e; padding: 4px 10px; border-radius: 999px; font-size: 14px; }
.stat { font-family: var(--display); font-size: 56px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.error { color: var(--wrong); min-height: 1.5em; }

@media (prefers-reduced-motion: reduce) {
  .runner, .board .runner, .step { transition: none; }
}

/* 3D mode: the scene fills the screen, the 2D UI floats on top as panels. */
#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; z-index: 0; }
.has3d main { position: relative; z-index: 1; }
.has3d .track { display: none; }
.has3d .panel {
  background: rgba(16, 48, 42, 0.9); border-radius: 14px; padding: 18px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: grid; gap: 14px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.has3d .step .block { height: 46px !important; font-size: 28px; }
.has3d .podium { gap: 8px; }

.player.has3d main { margin-top: 36vh; }
.player.has3d main.tall { margin-top: 58vh; }
.player.has3d .options { gap: 8px; }
.player.has3d .option { padding: 11px 14px; }

.host.has3d { padding: 0; }
.host.has3d .hud {
  position: fixed; z-index: 2; top: calc(12px + env(safe-area-inset-top, 0px)); right: max(12px, env(safe-area-inset-right, 0px));
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: calc(100vw - min(460px, 36vw) - 48px);
}
.host.has3d .hud > * { flex: 0 0 auto; }
.host.has3d .hud button { padding: 8px 12px; font-size: 13px; }
.host.has3d main.wide {
  position: fixed; left: max(16px, env(safe-area-inset-left, 0px)); top: calc(16px + env(safe-area-inset-top, 0px));
  width: min(460px, 36vw); max-height: calc(100vh - 32px); overflow: auto; margin: 0;
}
.host.has3d main.wide h1 { font-size: clamp(38px, 4.6vw, 64px); }
.host.has3d .question { font-size: clamp(18px, 1.7vw, 24px); }
.host.has3d .chips { display: none; }
@media (max-width: 900px) {
  .host.has3d main.wide { width: calc(100vw - 32px); top: auto; bottom: 16px; max-height: 50vh; }
  .host.has3d .hud { max-width: calc(100vw - 24px); }
}
.host .options.grid2 { grid-template-columns: 1fr 1fr; }
.host.has3d .options.grid2, .host .options.grid2.one { grid-template-columns: 1fr; }
@media (max-width: 700px) { .host .options.grid2 { grid-template-columns: 1fr; } }
.ghost { background: transparent; color: var(--chalk); border: 2px solid var(--chalk-dim); }
.finish-line { font-family: var(--display); font-size: 30px; font-weight: 800; text-transform: uppercase; color: var(--gold); }
[hidden] { display: none !important; }

/* Topic diagrams: one card, steps reveal parts with fades and growing bars. */
.dg { display: grid; gap: 14px; }
.dg h2 { font-size: clamp(26px, 3.4vw, 44px); }
.dg-stage { display: grid; gap: 14px; min-height: 0; }
.dg-hide { opacity: 0; transform: translateY(8px) scale(0.97); pointer-events: none; position: absolute !important; visibility: hidden; }
.dg-stage > *, .dg-row > *, .dg-col > *, .dg-stack > *, .dg-flow > *, .dg-check { transition: opacity .5s, transform .5s; }
.dg-row { display: flex; gap: 18px; align-items: center; justify-content: center; flex-wrap: wrap; position: relative; }
.dg-col { display: grid; gap: 8px; justify-items: center; text-align: center; flex: 1 1 140px; min-width: 0; position: relative; }
.dg-stack { display: grid; gap: 12px; position: relative; }
.dg-label { font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--chalk-dim); font-size: 15px; }
.dg-big { font-family: var(--display); font-weight: 800; font-size: clamp(24px, 3vw, 38px); line-height: 1.05; font-variant-numeric: tabular-nums; }
.dg-big s { color: var(--chalk-dim); }
.dg-note { color: var(--chalk-dim); font-size: 14px; }
.good { color: var(--right); }
.dg-arrow { font-family: var(--display); font-weight: 800; font-size: 26px; color: var(--gold); white-space: nowrap; }
.dg-arrow.back { color: var(--right); }

.dg-tank { position: relative; width: 120px; height: 160px; border: 4px solid var(--chalk); border-top: 0; border-radius: 0 0 16px 16px; overflow: hidden; background: #0c2621; }
.dg-water { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(#5ab0ff, #2f7ed8); transition: height 1.2s cubic-bezier(.3,.7,.3,1); }
.dg-limit { position: absolute; left: -4px; right: -4px; bottom: 17%; border-top: 3px dashed var(--gold); }
.dg-limit span { position: absolute; right: 4px; top: -24px; font-size: 12px; color: var(--gold); font-weight: 700; white-space: nowrap; }
.dg-blocks { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; width: 100%; max-width: 360px; }
.dg-blk { background: var(--gold); color: #1d1606; border-radius: 6px; padding: 8px 2px; display: grid; gap: 2px; font-size: 11px; font-weight: 700; transition: transform .6s, opacity .6s, background .6s; }
.dg-blk b { font-family: var(--display); font-size: 18px; }
.dg-blk.broken { background: #3b6b5e; color: var(--chalk); transform: rotate(-8deg) translateY(6px); opacity: .6; }
.dg-lockbox { background: #2a3a36; border: 2px dashed var(--chalk-dim); border-radius: 10px; padding: 14px; display: grid; gap: 4px; justify-items: center; }
.dg-lockbox b { font-family: var(--display); font-size: 28px; }
.dg-lock { width: 26px; height: 20px; background: var(--gold); border-radius: 4px; position: relative; margin-top: 12px; }
.dg-lock::before { content: ''; position: absolute; left: 4px; right: 4px; top: -14px; height: 16px; border: 4px solid var(--gold); border-bottom: 0; border-radius: 10px 10px 0 0; }

.bars-row { align-items: end; }
.dg-vbar { width: 64px; height: 170px; background: #0c2621; border-radius: 8px; position: relative; overflow: hidden; margin: 0 auto; }
.dg-vbar i { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 8px 8px 0 0; transition: height 1.2s cubic-bezier(.3,.7,.3,1); }
.dg-vbar.money i { background: #5ab0ff; }
.dg-vbar.fee i { background: var(--wrong); }
.dg-vbar.fixed i { background: var(--gold); }
.dg-pair { display: flex; gap: 12px; justify-content: center; }
.dg-pair > div { display: grid; gap: 6px; justify-items: center; font-size: 13px; color: var(--chalk-dim); }

.dg-hbar { display: flex; height: 52px; border-radius: 10px; overflow: hidden; background: #0c2621; width: 100%; }
.dg-hbar i { display: flex; align-items: center; justify-content: center; overflow: hidden; white-space: nowrap; font-style: normal; font-weight: 700; transition: width 1.2s cubic-bezier(.3,.7,.3,1); }
.dg-hbar i.owed { background: var(--wrong); color: #3a0d0d; }
.dg-hbar i.parked { background: var(--right); color: #0d2a1b; }
.dg-hbar i.money { background: #5ab0ff; color: #0b2238; }
.dg-callout { background: #24483f; border-radius: 10px; padding: 14px 16px; font-size: clamp(16px, 1.6vw, 20px); text-align: center; }
.dg-callout.good { border: 2px solid var(--right); }

.dg-meter { width: 220px; height: 120px; position: relative; overflow: hidden; }
.dg-arc { position: absolute; inset: 0 0 -100px 0; border-radius: 50%; background: conic-gradient(from -90deg, #ff6b5a 0 25%, #e9b43c 0 35%, #6fd39a 0 50%, transparent 0); -webkit-mask: radial-gradient(circle at 50% 50%, transparent 62px, #000 63px); mask: radial-gradient(circle at 50% 50%, transparent 62px, #000 63px); }
.dg-needle { position: absolute; left: calc(50% - 3px); bottom: 0; width: 6px; height: 100px; background: var(--chalk); border-radius: 3px; transform-origin: 50% 100%; transition: transform 1.2s cubic-bezier(.3,1.4,.4,1); }
.dg-meter-n { position: absolute; left: 0; right: 0; bottom: 4px; text-align: center; font-family: var(--display); font-weight: 800; font-size: 30px; }
.dg-emi { display: grid; gap: 6px; width: 100%; max-width: 360px; }
.dg-emi > div { display: flex; justify-content: space-between; gap: 10px; background: #24483f; border-radius: 8px; padding: 8px 12px; font-variant-numeric: tabular-nums; }
.dg-emi .sum { border: 2px solid var(--right); }
.dg-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.dg-chips span { background: var(--gold); color: #1d1606; padding: 8px 14px; border-radius: 999px; font-weight: 700; }

.dg-flow { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; position: relative; }
.dg-tile { background: #24483f; border-radius: 12px; padding: 14px 16px; display: grid; gap: 4px; text-align: center; min-width: 140px; }
.dg-tile span { color: var(--chalk-dim); font-size: 14px; }
.dg-tile b { font-family: var(--display); font-size: 30px; }
.dg-tile em { font-style: normal; font-weight: 700; }

.dg-check { background: #24483f; border-left: 4px solid var(--gold); border-radius: 0 10px 10px 0; padding: 14px 18px; }
.dg-check ul { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 6px; }
.dg-cap { font-size: clamp(17px, 1.7vw, 22px); line-height: 1.4; min-height: 2.8em; }
.dg-dots { display: flex; gap: 6px; }
.dg-dots i { width: 22px; height: 6px; border-radius: 3px; background: #2d5a4e; }
.dg-dots i.done { background: var(--chalk-dim); }
.dg-dots i.on { background: var(--gold); }

/* Phone: tabs and question navigator */
.tabs { display: flex; gap: 6px; background: #0c2621; padding: 4px; border-radius: 10px; }
.tabs button { flex: 1; background: transparent; color: var(--chalk-dim); padding: 10px; font-size: 15px; }
.tabs button.on { background: var(--gold); color: #1d1606; }
.tabs .badge { background: var(--wrong); color: #2a0b06; border-radius: 999px; padding: 0 7px; margin-left: 6px; font-size: 13px; }
.progress { display: grid; gap: 6px; }
.progress .bar { height: 10px; background: #0c2621; border-radius: 5px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; background: var(--right); transition: width .6s; }
.qnav { display: flex; flex-wrap: wrap; gap: 6px; }
.qnav button { min-width: 44px; padding: 8px 10px; background: #0c2621; color: var(--chalk); border: 2px solid #2d5a4e; font-size: 14px; }
.qnav button.done { border-color: var(--right); color: var(--right); }
.qnav button.sel { background: var(--gold); color: #1d1606; border-color: var(--gold); }
.qnav button:disabled { opacity: .35; }
.toast { position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); z-index: 5; background: var(--gold); color: #1d1606; font-weight: 700; padding: 10px 18px; border-radius: 999px; box-shadow: 0 6px 24px rgba(0,0,0,.35); transition: opacity .4s; }
.review { display: grid; gap: 10px; }
.review > div { background: #24483f; border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; }
.review .ok { color: var(--right); font-weight: 700; }
.review .no { color: var(--wrong); font-weight: 700; }

/* Host: big diagram card beside the left control column */
.host .board-card { display: grid; gap: 14px; }
.host.has3d .board-card {
  position: fixed; z-index: 1; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: calc(min(460px, 36vw) + 32px); max-height: calc(100vh - 150px); overflow: auto;
}
.host .ctrl { display: flex; gap: 8px; flex-wrap: wrap; }
.host .ctrl > * { flex: 1 1 120px; }
.host .qprog { display: grid; gap: 6px; }
.host .qprog div { display: grid; grid-template-columns: 40px 1fr 116px; gap: 8px; align-items: center; font-size: 14px; font-variant-numeric: tabular-nums; }
.host .qprog .bar { height: 10px; background: #0c2621; border-radius: 5px; overflow: hidden; }
.host .qprog .bar i { display: block; height: 100%; background: var(--right); }
.host .qprog .locked { opacity: .4; }
@media (max-width: 900px) {
  .host.has3d .board-card { left: 16px; top: auto; bottom: auto; position: relative; max-height: none; }
}

@media (max-width: 520px) {
  .dg h2 { font-size: 26px; }
  .dg-row { gap: 10px; }
  .dg-tank { width: 84px; height: 104px; }
  .dg-vbar { width: 44px; height: 110px; }
  .dg-big { font-size: 22px; }
  .dg-arrow { font-size: 20px; }
  .dg-blk { padding: 6px 1px; font-size: 9px; }
  .dg-blk b { font-size: 14px; }
  .dg-meter { width: 170px; height: 94px; }
  .dg-arc { -webkit-mask: radial-gradient(circle at 50% 50%, transparent 48px, #000 49px); mask: radial-gradient(circle at 50% 50%, transparent 48px, #000 49px); }
  .dg-needle { height: 78px; }
  .dg-tile { min-width: 0; flex: 1 1 100px; padding: 10px; }
  .dg-tile b { font-size: 22px; }
  .dg-hbar { height: 44px; font-size: 13px; }
  .dg-label { font-size: 13px; }
  .player.has3d main { margin-top: 30vh; }
}
.has3d .board-card, .player.has3d .panel { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(16, 48, 42, 0.95); }
@media (max-width: 520px) { .dg-limit span { font-size: 10px; right: 2px; top: -18px; } }

/* Gain, pluses and minuses */
.dg-gain { background: #24483f; border: 2px solid var(--gold); border-radius: 12px; padding: 16px 18px; display: grid; gap: 6px; }
.dg-gain-v { font-family: var(--display); font-weight: 800; font-size: clamp(34px, 4.4vw, 60px); line-height: 1; color: var(--gold); text-wrap: balance; }
.dg-pc { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dg-pc > div { background: #24483f; border-radius: 12px; padding: 14px 16px; border-top: 4px solid var(--right); }
.dg-pc .minus { border-top-color: var(--wrong); }
.dg-pc .plus .eyebrow { color: var(--right); }
.dg-pc .minus .eyebrow { color: var(--wrong); }
.dg-pc ul { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 6px; }
.dg-sum { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
@media (max-width: 520px) { .dg-pc { grid-template-columns: 1fr; } }
.yn { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.yn button { padding: 16px 10px; font-size: 17px; background: #0c2621; color: var(--chalk); border: 2px solid #2d5a4e; }
.yn button.picked { background: var(--gold); color: #1d1606; border-color: var(--gold); }
.qcard { display: grid; gap: 10px; background: #0c2621; border-radius: 12px; padding: 14px; border: 2px solid var(--gold); }
.results { display: grid; gap: 10px; }
.results .r { display: grid; gap: 4px; }
.results .r .lbl { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
.results .rbar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; background: #0c2621; font-size: 13px; font-weight: 700; }
.results .rbar i { display: flex; align-items: center; padding-inline: 8px; font-style: normal; white-space: nowrap; transition: width 1s; }
.results .rbar .y { background: var(--right); color: #0d2a1b; }
.results .rbar .n { background: var(--gold); color: #1d1606; }
.results .headline { font-family: var(--display); font-weight: 800; font-size: clamp(24px, 3vw, 36px); color: var(--gold); text-transform: uppercase; line-height: 1.05; }

/* Player on a desktop browser: 3D on the left, the question and topic on the right */
@media (min-width: 901px) {
  .player.has3d main {
    position: fixed; z-index: 1; margin: 0; max-width: none;
    top: calc(16px + env(safe-area-inset-top, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    right: max(16px, env(safe-area-inset-right, 0px)); width: min(560px, 45vw); overflow: auto;
  }
  .player.has3d main.tall { margin: 0; }
  .player.has3d main > .panel { min-height: 100%; align-content: start; }
}
@media (min-width: 901px) { .player .toast { left: calc((100vw - min(560px, 45vw) - 32px) / 2); } }
.yn.opts { grid-template-columns: 1fr; }
.yn.opts button { text-align: left; }
.dg-chips.leak span { background: var(--wrong); color: #2a0b06; }
.titles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.titles > div { background: #24483f; border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; border-top: 4px solid var(--gold); }
.titles b { font-family: var(--display); font-size: clamp(22px, 2.6vw, 32px); text-transform: uppercase; overflow-wrap: anywhere; }
.results .ans { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; }
.results .ans .ok { color: var(--right); font-weight: 700; }
.results .ans .no { color: var(--wrong); font-weight: 700; }
@media (max-width: 520px) { .titles { grid-template-columns: 1fr; } }
