:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #f6f2e9;
  --muted: #b9c3ca;
  --deep: #101b28;
  --panel: #17293a;
  --line: #d9c7a4;
  --focus: #fff1a6;
  --attack: #df5b52;
  --boost: #4ca8dc;
  --defense: #61ad70;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--deep); }
button, input { font: inherit; }
button { min-width: 44px; min-height: 44px; color: var(--ink); background: #223a4f; border: 2px solid #4c6679; border-radius: 10px; padding: 0.45rem 0.72rem; font-weight: 750; cursor: pointer; }
button:hover { background: #2b4961; }
button:focus-visible, input:focus-visible { outline: 4px solid var(--focus); outline-offset: 2px; }
button[aria-pressed="true"] { color: #101b28; background: var(--focus); border-color: var(--focus); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

#game-shell { width: 100vw; height: 100vh; display: grid; grid-template-rows: 27% 6% 67%; background: #101b28; color: var(--ink); }
.question-band { position: relative; z-index: 5; padding: clamp(10px, 1.35vh, 18px) clamp(14px, 1.5vw, 28px) clamp(8px, 1vh, 14px); background: linear-gradient(180deg, #0d1723 0%, #142536 100%); border-bottom: 1px solid #324859; display: grid; grid-template-rows: auto auto 1fr auto; gap: clamp(4px, 0.7vh, 10px); }
.phase-row, .question-copy, .status-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-width: 0; }
.phase-copy { display: flex; align-items: baseline; gap: 0.8rem; white-space: nowrap; }
.eyebrow { color: #8dd3df; font-weight: 850; letter-spacing: 0.08em; text-transform: uppercase; font-size: clamp(15px, 1.15vw, 22px); }
.round-label, .status-row { color: var(--muted); font-size: clamp(13px, 0.92vw, 18px); font-weight: 650; }
.teacher-controls { display: flex; gap: 0.4rem; justify-content: flex-end; }
.teacher-controls button { min-height: 40px; height: 40px; padding-block: 0.25rem; font-size: clamp(12px, 0.8vw, 16px); }
.danger-control { border-color: #8f514d; }
.question-copy h1 { margin: 0; font-size: clamp(27px, 2.35vw, 45px); line-height: 1.04; letter-spacing: -0.025em; max-width: 88%; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.countdown { flex: 0 0 auto; min-width: 4ch; text-align: right; color: #ffe2a7; font-size: clamp(28px, 2.4vw, 46px); font-weight: 900; font-variant-numeric: tabular-nums; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(5px, 0.55vw, 10px); min-height: 0; }
.choice-grid.tactical { grid-template-columns: repeat(3, 1fr); }
.choice { min-height: 0; height: 100%; display: grid; grid-template-columns: clamp(28px, 2.2vw, 42px) 1fr; align-items: center; gap: 0.6rem; background: #1c3144; border: 2px solid #415c70; border-radius: 10px; padding: 0.25rem 0.65rem; text-align: left; }
.choice-slot { display: grid; place-items: center; aspect-ratio: 1; border-radius: 8px; background: #f1e5ca; color: #172535; font-size: clamp(18px, 1.55vw, 30px); font-weight: 950; }
.choice-text { font-size: clamp(17px, 1.32vw, 25px); line-height: 1.05; font-weight: 800; }
.choice small { display: block; margin-top: 0.15rem; color: #d7e0e5; font-size: 0.63em; font-weight: 650; }
.choice.attack { border-color: var(--attack); background: linear-gradient(135deg, #4b262b, #2a303d); }
.choice.boost { border-color: var(--boost); background: linear-gradient(135deg, #173c59, #253547); }
.choice.defense { border-color: var(--defense); background: linear-gradient(135deg, #1e432f, #293a3c); }
.choice.correct-choice { border-color: #8ddf96; background: linear-gradient(135deg, #1d5135, #1d3942); box-shadow: inset 0 0 0 2px #bdf5b8; }
.status-row { min-height: 18px; }
.status-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tracker { position: relative; z-index: 4; display: grid; grid-template-columns: clamp(26px, 3vw, 52px) 1fr clamp(32px, 3.5vw, 60px); align-items: center; padding: 0 clamp(12px, 1.4vw, 28px); background: #101b28; box-shadow: 0 8px 22px #08101988; }
.tracker-end { color: var(--line); text-align: center; font-size: clamp(22px, 2.15vw, 40px); line-height: 1; }
.tracker-line { height: 4px; position: relative; background: linear-gradient(90deg, #8ca1aa, #ead5aa); box-shadow: 0 1px 0 #ffffff55; }
.tracker-token { position: absolute; top: 50%; width: clamp(26px, 2.4vw, 44px); height: clamp(26px, 2.4vw, 44px); transform: translate(-50%, -50%); border-radius: 50% 44% 50% 42%; border: 3px solid #f9edda; display: grid; place-items: center; color: #fff; font-weight: 950; font-size: clamp(11px, 0.9vw, 17px); box-shadow: 0 4px 8px #0009; transition: left 450ms cubic-bezier(.2,.8,.2,1); }

.race-region { position: relative; min-height: 0; overflow: hidden; background: #203b4b; }
#race-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.team-overlays { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; pointer-events: none; }
.team-panel { position: relative; min-width: 0; min-height: 0; border: 1px solid #0c1823; overflow: hidden; }
.team-label { position: absolute; top: 8px; left: 10px; display: flex; align-items: center; gap: 0.45rem; padding: 0.25rem 0.65rem; border: 2px solid var(--team-color); border-radius: 999px; background: #10202bd9; box-shadow: 0 4px 14px #0007; font-size: clamp(13px, 1vw, 20px); font-weight: 900; letter-spacing: 0.04em; }
.team-emblem { width: 1.2em; height: 1.2em; display: grid; place-items: center; border-radius: 45%; background: var(--team-color); color: #101820; font-size: 0.75em; }
.team-score { color: #fff0c9; font-variant-numeric: tabular-nums; }
.team-event { position: absolute; z-index: 4; top: 47px; left: 12px; max-width: 70%; padding: 0.18rem 0.48rem; border-radius: 7px; color: #fff5cf; background: #10202bd9; font-size: clamp(11px, 0.78vw, 15px); font-weight: 900; letter-spacing: 0.035em; }
.team-event:empty { display: none; }
.racer-row { position: absolute; left: 17%; right: 13%; top: 26%; height: 42%; display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; gap: 1.4%; }
.racer { position: relative; justify-self: center; width: min(84%, 62px); aspect-ratio: 0.78; display: grid; place-items: center; transform-origin: bottom center; transition: transform 220ms ease, filter 220ms ease; }
.racer-body { width: 74%; height: 70%; position: absolute; bottom: 0; border: 3px solid #f6e8cf; border-radius: 48% 48% 34% 34%; background: linear-gradient(160deg, color-mix(in srgb, var(--team-color) 80%, white), var(--team-dark)); box-shadow: 0 5px 10px #00101a88; }
.racer-body::before, .racer-body::after { content: ""; position: absolute; top: -16%; width: 31%; aspect-ratio: 1; background: inherit; border: 3px solid #f6e8cf; transform: rotate(45deg); z-index: -1; }
.racer-body::before { left: 4%; }
.racer-body::after { right: 4%; }
.racer-id { position: relative; z-index: 2; font-size: clamp(11px, 0.82vw, 17px); font-weight: 950; color: #fff; text-shadow: 0 2px 2px #000; }
.racer-state { position: absolute; z-index: 3; right: -4%; top: -4%; width: clamp(21px, 1.7vw, 32px); aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; background: #142432; border: 2px solid #f5ead3; color: #fff; font-size: clamp(13px, 1.1vw, 21px); font-weight: 950; box-shadow: 0 3px 7px #0008; }
.racer[data-status="ready"] { transform: translateY(5%); filter: drop-shadow(0 0 9px #e9db9b); }
.racer[data-status="correct"] { transform: translateY(-8%) rotate(-2deg); }
.racer[data-status="correct"] .racer-state { background: #236a45; }
.racer[data-status="incorrect"] { transform: translateY(4%) rotate(3deg); filter: saturate(0.7); }
.racer[data-status="incorrect"] .racer-state { background: #743c3c; }
.racer[data-status="missing"] { opacity: 0.72; filter: grayscale(0.65); }
.racer[data-status="missing"] .racer-state { background: #4c5860; }

.system-overlay, .results-panel { position: absolute; z-index: 10; inset: 0; display: grid; place-items: center; padding: 3%; background: #07111cd9; backdrop-filter: blur(5px); }
.system-overlay[hidden], .results-panel[hidden] { display: none; }
.overlay-card { width: min(720px, 90%); padding: 2rem; border-radius: 20px; background: #172b3c; border: 3px solid #e4cfa7; box-shadow: 0 24px 80px #000c; text-align: center; }
.overlay-card h2 { margin: 0 0 0.5rem; font-size: clamp(30px, 3vw, 54px); }
.overlay-card p { color: #d1dbe0; font-size: clamp(18px, 1.5vw, 28px); }
.overlay-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.25rem; }
.primary-control { background: #f0d27f; color: #14202a; border-color: #fff0bd; }
.results-card { width: min(980px, 92%); text-align: center; }
.results-card h2 { margin: 0 0 1rem; font-size: clamp(38px, 4vw, 72px); }
.podium { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.8rem; align-items: end; }
.podium-team { padding: 1rem 0.5rem; border: 3px solid var(--team-color); background: #102331e8; border-radius: 18px 18px 6px 6px; min-height: 120px; display: grid; place-items: center; }
.podium-team:first-child { min-height: 190px; }
.podium-team:nth-child(2) { min-height: 160px; }
.podium-place { font-size: clamp(28px, 3vw, 54px); font-weight: 950; }

.simulator-panel { position: fixed; z-index: 30; top: 8px; right: 8px; width: min(420px, calc(100vw - 16px)); max-height: calc(100vh - 16px); overflow: auto; padding: 1rem; border: 2px solid #6f8da3; border-radius: 16px; background: #10202ff5; box-shadow: 0 20px 70px #000d; color: var(--ink); }
.simulator-heading { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.simulator-heading strong, .simulator-heading span { display: block; }
.simulator-heading span { color: var(--muted); font-size: 0.85rem; }
.seed-field, .toggle-field { display: flex; align-items: center; gap: 0.55rem; margin: 0.8rem 0; font-weight: 750; }
.seed-field input { min-width: 0; flex: 1; padding: 0.55rem; border: 2px solid #5f7d93; border-radius: 8px; color: var(--ink); background: #0b1824; }
.simulator-actions, .simulator-footer { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 0.7rem 0; }
.student-controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; }
.student-control { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 0.25rem; padding: 0.3rem; border-radius: 7px; background: #1d3345; font-size: 0.78rem; }
.student-control select { min-width: 0; color: var(--ink); background: #0d1d2a; border: 1px solid #638196; border-radius: 4px; }
.camera-video { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

#game-shell[data-reduced-motion="true"] *,
#game-shell[data-capture="true"] * { animation: none !important; transition-duration: 0ms !important; scroll-behavior: auto !important; }

@media (max-height: 760px) {
  .question-band { padding-top: 7px; padding-bottom: 6px; gap: 3px; }
  .teacher-controls button { min-height: 44px; height: 44px; padding: 0.15rem 0.5rem; }
  .question-copy h1 { font-size: clamp(30px, 2.2vw, 34px); }
  .choice-text { font-size: 20px; }
  .status-row { font-size: 12px; }
  #game-shell[data-long-question="true"] .question-copy h1 { font-size: 30px; line-height: 0.98; }
  #game-shell[data-long-question="true"] .choice { grid-template-columns: 24px 1fr; gap: 0.35rem; padding: 0.05rem 0.45rem; }
  #game-shell[data-long-question="true"] .choice-slot { font-size: 16px; border-radius: 6px; }
  #game-shell[data-long-question="true"] .choice-text { font-size: 20px; line-height: 1; }
}
