/* Học Toán: a squared-paper exercise book. Ballpoint blue is the action colour, the teacher's red
   pen marks mistakes, and a highlighter picks out what to do next. */

:root {
  --paper: #fbf8ef;
  --paper-grid: #e4e9f1;
  --surface: #ffffff;
  --ink: #1c2740;
  --ink-2: #4b5772;
  --line: #d8d5c8;
  --line-strong: #b9b6a8;

  --pen: #1f4fbf;
  --pen-dark: #153a8e;
  --pen-tint: #e6edfb;
  --ok: #17784a;
  --ok-dark: #0f5a36;
  --ok-tint: #def3e6;
  --bad: #c42b27;
  --bad-dark: #941d1a;
  --bad-tint: #fce7e5;
  --warn: #8a5800;
  --warn-tint: #fff3d1;
  --marker: #ffd84d;
  --star: #e5a200;

  --font-display: "Baloo 2", "Be Vietnam Pro", system-ui, sans-serif;
  --font-body: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;

  --radius-s: 6px;
  --radius-m: 10px;
  --gutter: 1rem;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.55 var(--font-body);
}
body.paper {
  background-image:
    linear-gradient(var(--paper-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--paper-grid) 1px, transparent 1px);
  background-size: 24px 24px;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; line-height: 1.2; margin: 0; }
h1 { font-size: clamp(1.75rem, 5vw, 2.25rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.125rem; }
p { margin: 0; }
a { color: var(--pen); text-underline-offset: 2px; }
a:hover { color: var(--pen-dark); }
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.875em; background: var(--pen-tint); padding: 0 0.25rem; border-radius: 3px; }
small, .small { font-size: 0.8125rem; }
.muted { color: var(--ink-2); font-weight: 400; }
.prewrap { white-space: pre-line; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.875rem; }
.icon { flex: none; vertical-align: -0.2em; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

:focus-visible { outline: 3px solid var(--pen); outline-offset: 2px; border-radius: 3px; }
[tabindex="-1"]:focus-visible { outline: none; }

/* --- Brand & top bar ------------------------------------------------------------------------ */

.brand { color: var(--ink); text-decoration: none; font-family: var(--font-display); font-weight: 800; font-size: 1.375rem; white-space: nowrap; }
.brand:hover { color: var(--ink); }
.brand small { font-family: var(--font-body); font-weight: 500; font-size: 0.8125rem; color: var(--ink-2); }
.brand-mark, .marker { background: linear-gradient(transparent 58%, var(--marker) 58%, var(--marker) 92%, transparent 92%); padding: 0 0.15em; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.625rem var(--gutter);
  background: var(--surface);
  border-bottom: 2px solid var(--ink);
}
.topbar-user { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.topbar-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.link-button {
  border: 0; background: none; padding: 0.25rem; cursor: pointer;
  color: var(--pen); font: inherit; font-size: 0.875rem; text-decoration: underline; text-underline-offset: 2px;
}
.link-button:hover { color: var(--pen-dark); }
.link-danger { color: var(--bad); }
.link-danger:hover { color: var(--bad-dark); }

/* --- Buttons: chunky, with a press-down feel ---------------------------------------------------- */

.btn {
  --btn-bg: var(--surface); --btn-fg: var(--ink); --btn-edge: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 44px; padding: 0.5rem 1.125rem 0.5625rem;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 2px solid var(--btn-edge); border-bottom-width: 4px; border-radius: var(--radius-m);
  font: 700 1rem/1.2 var(--font-body); text-decoration: none; cursor: pointer;
  transition: transform 80ms ease, border-bottom-width 80ms ease, background-color 120ms ease;
}
.btn:hover { color: var(--btn-fg); filter: brightness(0.97); }
.btn:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 2px; margin-bottom: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { --btn-bg: var(--pen); --btn-fg: #fff; --btn-edge: var(--pen-dark); }
.btn-ok { --btn-bg: var(--ok); --btn-fg: #fff; --btn-edge: var(--ok-dark); }
.btn-bad { --btn-bg: var(--bad); --btn-fg: #fff; --btn-edge: var(--bad-dark); }
.btn-danger { --btn-bg: var(--surface); --btn-fg: var(--bad); --btn-edge: var(--bad); }
.btn-quiet { --btn-bg: var(--surface); --btn-fg: var(--ink); }
.btn-block { width: 100%; }
.btn-large { min-height: 52px; padding-inline: 1.5rem; font-size: 1.0625rem; }
.btn-small { min-height: 34px; padding: 0.25rem 0.75rem; font-size: 0.875rem; border-bottom-width: 3px; }

/* --- Forms ---------------------------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field > label, .field-label { font-weight: 600; font-size: 0.9375rem; margin: 0; }
input:not([type="checkbox"]):not([type="radio"]), textarea, select {
  width: 100%; min-height: 44px; padding: 0.5rem 0.75rem;
  background: var(--surface); color: var(--ink);
  border: 2px solid var(--line-strong); border-radius: var(--radius-s);
  font: inherit;
}
textarea { resize: vertical; }
textarea.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.875rem; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--pen); box-shadow: 0 0 0 2px var(--pen-tint); }
input[type="checkbox"], input[type="radio"] { width: 1.125rem; height: 1.125rem; margin: 0.1875rem 0 0; accent-color: var(--pen); flex: none; }
.check { display: flex; align-items: flex-start; gap: 0.5rem; cursor: pointer; }
.hint { font-size: 0.8125rem; color: var(--ink-2); min-height: 0; }
.hint.is-error { color: var(--bad); font-weight: 600; }

.flash-stack { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.flash { padding: 0.625rem 0.875rem; border-radius: var(--radius-s); border-left: 4px solid; font-size: 0.9375rem; font-weight: 500; }
.flash-success { background: var(--ok-tint); border-color: var(--ok); color: var(--ok-dark); }
.flash-error { background: var(--bad-tint); border-color: var(--bad); color: var(--bad-dark); }
.flash-warn { background: var(--warn-tint); border-color: var(--warn); color: var(--warn); margin-bottom: 1rem; }
.error-list { margin: 0.25rem 0 0; padding-left: 1.125rem; }
.flash > .error-list:first-child { margin-top: 0; }

/* --- Login & error pages ------------------------------------------------------------------- */

.center-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem var(--gutter); }
.login-card {
  width: 100%; max-width: 24rem; display: flex; flex-direction: column; gap: 1rem;
  padding: 1.5rem; background: var(--surface);
  border: 2px solid var(--ink); border-bottom-width: 5px; border-radius: var(--radius-m);
}
.login-sub { color: var(--ink-2); margin-top: -0.625rem; }
.login-tag { font-family: var(--font-body); font-size: 0.875rem; font-weight: 500; color: var(--ink-2); }
.error-box { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 1rem; max-width: 30rem; }
.error-code { font: 800 4rem/1 var(--font-display); color: var(--bad); transform: rotate(-4deg); }
.error-box h1 { font-size: 1.375rem; }

/* --- Student pages -------------------------------------------------------------------------- */

.page { max-width: 46rem; margin: 0 auto; padding: 1.5rem var(--gutter) 3rem; }
.page-wide { max-width: 64rem; }
.page-head { margin-bottom: 1.25rem; }
.page-sub { color: var(--ink-2); margin-top: 0.25rem; }
.eyebrow { color: var(--ink-2); font-weight: 600; font-size: 0.9375rem; }
.crumb { margin-bottom: 0.75rem; font-size: 0.9375rem; }
.section-title { font-size: 1.125rem; margin-bottom: 0.625rem; }
.empty { padding: 2.5rem 1.5rem; text-align: center; background: var(--surface); border: 2px dashed var(--line-strong); border-radius: var(--radius-m); display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
.empty .btn { margin-top: 0.5rem; }

.tag {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.0625rem 0.5rem; border-radius: 999px;
  font-size: 0.8125rem; font-weight: 600; white-space: nowrap;
}
.tag-ok { background: var(--ok-tint); color: var(--ok-dark); }
.tag-bad { background: var(--bad-tint); color: var(--bad-dark); }
.tag-pen { background: var(--pen-tint); color: var(--pen-dark); }
.tag-new { background: var(--marker); color: var(--ink); }
.tag-muted { background: #ece9dd; color: var(--ink-2); }

.stars { display: inline-flex; gap: 1px; vertical-align: middle; }
.star { fill: #dcd9cc; }
.star.is-on { fill: var(--star); }

/* Home: like a contents page, with a teacher's red margin line */
.toc { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 2px solid var(--ink); border-radius: var(--radius-m); overflow: hidden; }
.toc-row + .toc-row { border-top: 1px solid var(--line); }
.toc-link { display: grid; grid-template-columns: 2.75rem 1fr; gap: 0.25rem 0.75rem; align-items: center; padding: 0.875rem 1rem 0.875rem 0; color: inherit; text-decoration: none; }
a.toc-link:hover { background: var(--pen-tint); color: inherit; }
.toc-num { align-self: stretch; display: grid; place-items: center; grid-row: span 2; border-right: 2px solid #eab1ac; font: 700 1.25rem var(--font-display); color: var(--ink-2); }
.toc-body { display: flex; flex-direction: column; min-width: 0; }
.toc-title { font: 700 1.125rem/1.3 var(--font-display); }
.toc-meta { color: var(--ink-2); font-size: 0.875rem; }
.toc-status { grid-column: 2; display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.status-locked .toc-title, .status-locked .toc-num { color: var(--ink-2); }
.status-locked .toc-link { background: #f6f4ec; cursor: not-allowed; }
@media (min-width: 600px) {
  .toc-link { grid-template-columns: 3.25rem 1fr auto; }
  .toc-status { grid-column: 3; grid-row: 1 / span 2; justify-content: flex-end; }
}

/* Topic page */
.topic-grid { display: grid; gap: 1.5rem; }
@media (min-width: 900px) { .topic-grid { grid-template-columns: minmax(0, 1fr) 20rem; align-items: start; } }
.video-frame { aspect-ratio: 16 / 9; background: var(--ink); border: 2px solid var(--ink); border-radius: var(--radius-m); overflow: hidden; }
.video-frame iframe { display: block; width: 100%; height: 100%; border: 0; }
.watch-progress { margin-top: 0.625rem; display: flex; flex-direction: column; align-items: flex-start; gap: 0.25rem; }
.watch-bar { width: 100%; height: 10px; background: var(--surface); border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; }
.watch-fill { height: 100%; background: var(--pen); transform: scaleX(0); transform-origin: left; transition: transform 300ms linear; }
.watch-text { font-size: 0.875rem; color: var(--ink-2); }
.rules { padding: 1.125rem; background: var(--surface); border: 2px solid var(--ink); border-bottom-width: 5px; border-radius: var(--radius-m); }
.facts { margin: 0 0 1rem; }
.facts > div { display: flex; justify-content: space-between; gap: 1rem; padding: 0.375rem 0; border-bottom: 1px solid var(--line); }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; font-weight: 600; text-align: right; }
.fact-key dd { background: var(--marker); padding: 0 0.375rem; border-radius: 3px; font-weight: 700; }
.best-line { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.notice { display: flex; gap: 0.5rem; padding: 0.625rem 0.75rem; background: #f6f4ec; border-radius: var(--radius-s); font-weight: 500; }
.history { margin-top: 2rem; }
.history-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-m); overflow: hidden; }
.history-list li + li { border-top: 1px solid var(--line); }
.history-list a { display: flex; align-items: center; flex-wrap: wrap; gap: 0.25rem 0.75rem; padding: 0.625rem 0.875rem; color: inherit; text-decoration: none; }
.history-list a:hover { background: var(--pen-tint); }
.history-date { color: var(--ink-2); font-size: 0.875rem; margin-right: auto; }
.history-score { font-weight: 700; }

/* --- Game ----------------------------------------------------------------------------------- */

.play-body { overflow-x: hidden; }
.game { min-height: 100vh; display: flex; flex-direction: column; }
.hud {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.75rem;
  padding: 0.5rem var(--gutter);
  background: var(--surface); border-bottom: 2px solid var(--ink);
}
.hud-exit { display: grid; place-items: center; width: 40px; height: 40px; margin-left: -0.5rem; color: var(--ink-2); border-radius: var(--radius-s); }
.hud-exit:hover { background: #f1eee3; color: var(--ink); }
.hud-progress { display: flex; gap: 3px; min-width: 0; }
.hud-progress span { flex: 1 1 0; min-width: 2px; height: 10px; background: #e6e3d7; border-radius: 2px; }
.hud-progress span.is-current { background: var(--pen); }
.hud-progress span[data-mark="correct"] { background: var(--ok); }
.hud-progress span[data-mark="wrong"], .hud-progress span[data-mark="timeout"] { background: var(--bad); }
.hud-stats { display: flex; align-items: center; gap: 0.625rem; }
.hud-score { font: 800 1.25rem/1 var(--font-display); white-space: nowrap; }
.hud-score small { font: 500 0.75rem var(--font-body); color: var(--ink-2); }
.hud-streak { background: var(--marker); padding: 0 0.5rem; border-radius: 999px; font-size: 0.8125rem; font-weight: 700; white-space: nowrap; }
.hud-lives { display: inline-flex; gap: 1px; }
.heart { display: inline-flex; }
.heart svg { fill: #dcd9cc; }
.heart.is-on svg { fill: var(--bad); }
.hud-sound { display: grid; place-items: center; width: 40px; height: 40px; margin-right: -0.5rem; padding: 0; border: 0; background: none; color: var(--ink-2); cursor: pointer; border-radius: var(--radius-s); }
.hud-sound:hover { background: #f1eee3; color: var(--ink); }
.hud-sound .sound-off, .hud-sound.is-off .sound-on { display: none; }
.hud-sound.is-off .sound-off { display: block; }
@media (max-width: 480px) {
  .hud { grid-template-columns: auto 1fr auto; }
  .hud-progress { grid-column: 1 / -1; grid-row: 2; }
  .hud-stats { grid-column: 3; justify-content: flex-end; }
  .hud-exit { grid-column: 1; }
  .hud-streak { order: -1; }
}

.timer { height: 10px; background: #e6e3d7; overflow: hidden; }
.timer-fill { height: 100%; background: var(--pen); transform-origin: left; transition: transform 100ms linear, background-color 200ms ease; }
.timer[data-level="warn"] .timer-fill { background: #d98a00; }
.timer[data-level="danger"] .timer-fill { background: var(--bad); }

.stage { flex: 1; width: 100%; max-width: 46rem; margin: 0 auto; padding: 1.5rem var(--gutter) 2rem; }
.stage-loading { text-align: center; color: var(--ink-2); padding-top: 3rem; }

.ready { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 0.875rem; padding-top: 2rem; }
.ready h1 { font-size: clamp(2rem, 7vw, 3rem); }
.ready-rules { list-style: none; margin: 0 0 0.5rem; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }
.ready-rules li { padding: 0.25rem 0.75rem; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 999px; font-size: 0.9375rem; font-weight: 500; }

.question-meta { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.75rem; }
.question-number { font: 700 1.0625rem var(--font-display); color: var(--ink-2); }
.question-clocks { display: flex; align-items: center; gap: 0.5rem; }
.clock { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.clock-total { color: var(--ink-2); font-size: 0.875rem; font-weight: 600; }
.clock-question { min-width: 4.5rem; text-align: center; padding: 0.0625rem 0.625rem; background: var(--pen-tint); color: var(--pen-dark); border-radius: 999px; }
.clock-question[data-level="warn"] { background: var(--warn-tint); color: var(--warn); }
.clock-question[data-level="danger"] { background: var(--bad); color: #fff; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

.question-prompt {
  font-size: clamp(1.375rem, 4.5vw, 1.875rem); font-weight: 700; line-height: 1.35;
  white-space: pre-line; overflow-wrap: anywhere; overflow-x: auto;
  margin-bottom: 1.25rem; padding: 1.25rem;
  background: var(--surface); border: 2px solid var(--ink); border-radius: var(--radius-m);
}
/* Inline fractions render small by default, which is too hard to read in a maths game. */
.question-prompt .katex { font-size: 1.3em; }
.option-text .katex { font-size: 1.45em; }
.feedback-answer .katex, .feedback-explain .katex { font-size: 1.25em; }
.review .katex, .row-body .katex, .math-preview .katex { font-size: 1.2em; }

.options { display: grid; gap: 0.625rem; }
@media (min-width: 620px) { .options { grid-template-columns: 1fr 1fr; } }
.option {
  display: flex; align-items: center; gap: 0.75rem; width: 100%; min-height: 60px;
  padding: 0.625rem 0.875rem; text-align: left; cursor: pointer;
  background: var(--surface); color: var(--ink);
  border: 2px solid var(--line-strong); border-bottom-width: 5px; border-radius: var(--radius-m);
  font: 600 1.0625rem/1.3 var(--font-body);
  transition: transform 80ms ease, border-color 100ms ease, background-color 100ms ease;
}
/* Hover sticks after a tap on touch screens, and a highlighted option would read as a hint. */
@media (hover: hover) {
  .option:hover:not(:disabled) { border-color: var(--pen); background: var(--pen-tint); }
}
.option:active:not(:disabled) { transform: translateY(3px); border-bottom-width: 2px; margin-bottom: 3px; }
.option:disabled { cursor: default; color: var(--ink); }
.option-key {
  flex: none; display: grid; place-items: center; width: 1.875rem; height: 1.875rem;
  background: #f1eee3; border-radius: var(--radius-s);
  font: 700 0.9375rem var(--font-display); color: var(--ink-2);
}
.option-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.option-mark { flex: none; display: inline-flex; }
.option.is-picked { border-color: var(--pen); background: var(--pen-tint); }
.option.is-correct { border-color: var(--ok); background: var(--ok-tint); color: var(--ok-dark); }
.option.is-correct .option-key { background: var(--ok); color: #fff; }
.option.is-wrong { border-color: var(--bad); background: var(--bad-tint); color: var(--bad-dark); }
.option.is-wrong .option-key { background: var(--bad); color: #fff; }
.option.is-dim { opacity: 0.55; }

.answer-form { display: flex; flex-direction: column; gap: 0.375rem; }
.answer-form label { font-weight: 600; }
.answer-row { display: flex; gap: 0.5rem; }
.answer-row input { flex: 1; min-width: 0; min-height: 56px; font-size: 1.25rem; font-weight: 600; border-color: var(--ink); }
.answer-row input.is-correct { border-color: var(--ok); background: var(--ok-tint); color: var(--ok-dark); }
.answer-row input.is-wrong { border-color: var(--bad); background: var(--bad-tint); color: var(--bad-dark); }
.answer-row .btn { min-height: 56px; }
.answer-hint { font-size: 0.875rem; color: var(--ink-2); }

.feedback {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  max-height: 70vh; overflow-y: auto;
  border-top: 4px solid; animation: slide-up 180ms ease-out;
}
.feedback[data-mark="correct"] { background: var(--ok-tint); border-color: var(--ok); color: var(--ok-dark); }
.feedback[data-mark="wrong"], .feedback[data-mark="timeout"] { background: var(--bad-tint); border-color: var(--bad); color: var(--bad-dark); }
@keyframes slide-up { from { transform: translateY(100%); } }
.feedback-inner { max-width: 46rem; margin: 0 auto; padding: 0.875rem var(--gutter) 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.feedback-text { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.feedback-title { display: flex; align-items: center; gap: 0.5rem; font: 800 1.375rem/1.2 var(--font-display); }
.feedback-answer { font-weight: 700; overflow-wrap: anywhere; }
.feedback-explain { color: var(--ink); white-space: pre-line; overflow-wrap: anywhere; }
.feedback .btn { width: 100%; }
@media (min-width: 620px) {
  .feedback-inner { flex-direction: row; align-items: center; justify-content: space-between; gap: 1.5rem; }
  .feedback-text { flex: 1; }
  .feedback .btn { width: auto; flex: none; }
}

.net-error {
  position: fixed; left: var(--gutter); right: var(--gutter); top: 4.5rem; z-index: 20;
  max-width: 30rem; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.625rem 0.875rem; background: var(--ink); color: #fff; border-radius: var(--radius-m); font-weight: 500;
}

/* --- Result --------------------------------------------------------------------------------- */

.scorecard {
  position: relative; margin-bottom: 2rem; padding: 1.5rem;
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem; text-align: center;
  background: var(--surface); border: 2px solid var(--ink); border-bottom-width: 5px; border-radius: var(--radius-m);
}
.stamp {
  padding: 0.125rem 0.875rem; margin-bottom: 0.25rem;
  border: 4px double currentColor; border-radius: var(--radius-s);
  font: 800 1.75rem/1.2 var(--font-display); text-transform: uppercase; letter-spacing: 0.04em;
  transform: rotate(-5deg); animation: stamp-in 320ms cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.scorecard.is-pass .stamp { color: var(--ok); }
.scorecard.is-fail .stamp { color: var(--bad); }
@keyframes stamp-in { from { opacity: 0; transform: rotate(-5deg) scale(1.8); } }
.scorecard-title { font-size: clamp(1.25rem, 4vw, 1.625rem); }
.scorecard-score { font-size: 1.125rem; }
.scorecard-score strong { font: 800 2.75rem/1.1 var(--font-display); }
.scorecard-need { color: var(--ink-2); margin-top: -0.25rem; }
.scorecard-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem 1.75rem; margin: 0.5rem 0; }
.scorecard-stats dt { color: var(--ink-2); font-size: 0.8125rem; }
.scorecard-stats dd { margin: 0; font: 700 1.25rem var(--font-display); }
.scorecard-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.625rem; margin-top: 0.5rem; }

.review { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.625rem; }
.review-item { display: flex; gap: 0.75rem; padding: 0.75rem 0.875rem; background: var(--surface); border: 1px solid var(--line-strong); border-left-width: 5px; border-radius: var(--radius-s); }
.review-item.is-correct { border-left-color: var(--ok); }
.review-item.is-wrong, .review-item.is-timeout { border-left-color: var(--bad); }
.review-mark { flex: none; width: 3.75rem; display: flex; flex-direction: column; align-items: center; gap: 0.125rem; font-size: 0.75rem; font-weight: 700; text-align: center; color: var(--ink-2); }
.is-correct .review-mark { color: var(--ok); }
.is-wrong .review-mark, .is-timeout .review-mark { color: var(--bad); }
.review-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.25rem; overflow-wrap: anywhere; }
.review-prompt { font-weight: 600; white-space: pre-line; }
.review-num { color: var(--ink-2); }
.review-label { color: var(--ink-2); font-size: 0.875rem; }
.review-given { color: var(--bad-dark); text-decoration: line-through; text-decoration-color: var(--bad); }
.review-explain { font-size: 0.9375rem; color: var(--ink-2); padding-left: 0.625rem; border-left: 2px solid var(--line); white-space: pre-line; }

.confetti { position: fixed; inset: 0; z-index: 30; overflow: hidden; pointer-events: none; }
.confetti i { position: absolute; top: -12px; width: 9px; height: 14px; animation: confetti-fall linear forwards; }
@keyframes confetti-fall { to { transform: translate(var(--drift), 105vh) rotate(var(--spin)); } }

/* --- Admin ---------------------------------------------------------------------------------- */

.admin-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1.25rem;
  padding: 0.5rem var(--gutter);
  background: var(--surface); border-bottom: 2px solid var(--ink);
}
.admin-bar form { margin-left: auto; }
.admin-nav { display: flex; gap: 0.125rem; order: 3; width: 100%; overflow-x: auto; }
.admin-nav a { padding: 0.375rem 0.75rem; color: var(--ink-2); font-weight: 600; font-size: 0.9375rem; text-decoration: none; border-radius: var(--radius-s); white-space: nowrap; }
.admin-nav a:hover { background: #f1eee3; color: var(--ink); }
.admin-nav a[aria-current="page"] { background: var(--pen-tint); color: var(--pen-dark); }
@media (min-width: 720px) { .admin-nav { order: 0; width: auto; } }

.admin-main { max-width: 72rem; margin: 0 auto; padding: 1.25rem var(--gutter) 3rem; }
.admin-head { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem 1rem; margin-bottom: 1rem; }
.admin-head h1 { font-size: 1.625rem; }
.head-links { display: flex; gap: 1rem; font-size: 0.9375rem; }

.panel { background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-m); padding: 1rem; margin: 0 0 1rem; min-width: 0; }
.panel > h2 { margin-bottom: 0.75rem; }
.panel legend { font: 700 1.125rem var(--font-display); padding: 0 0.375rem; margin-left: -0.375rem; }
.panel-flush { padding: 0; overflow: hidden; }
.panel-title { padding: 0.875rem 1rem 0.625rem; }
.panel-pad { padding: 0 1rem 1rem; }
.panel-narrow { max-width: 40rem; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.75rem; }
fieldset.panel { display: flex; flex-direction: column; gap: 0.875rem; }
details.panel summary { font: 700 1.125rem var(--font-display); cursor: pointer; }
details.panel[open] summary { margin-bottom: 0.75rem; }

.form-stack { display: flex; flex-direction: column; gap: 0.875rem; }
.form-stack > .panel { margin: 0; }
.form-grid { display: grid; gap: 0.875rem; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.625rem; }
.video-preview { max-width: 28rem; }
.danger-zone { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.5rem; padding: 1rem; border: 1px solid var(--bad); border-radius: var(--radius-m); background: var(--surface); }
.danger-zone h2 { font-size: 1.0625rem; color: var(--bad-dark); }

/* position: relative contains .visually-hidden headers, which would otherwise escape the scroll
   area and widen the whole page on phones. */
.table-wrap { overflow-x: auto; position: relative; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.table th, .table td { padding: 0.625rem 0.875rem; text-align: left; vertical-align: top; border-top: 1px solid var(--line); }
.table thead th { border-top: 0; background: #f6f4ec; font-size: 0.8125rem; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.table tbody th { font-weight: 600; }
@media (max-width: 720px) { .hide-narrow { display: none; } }
.cell-move form { display: flex; gap: 0.125rem; }
.cell-actions { white-space: nowrap; text-align: right; }
.cell-actions a { margin-left: 0.625rem; font-size: 0.875rem; }
.warn-line { margin-top: 0.25rem; padding: 0.125rem 0.5rem; background: var(--warn-tint); color: var(--warn); font-size: 0.8125rem; font-weight: 500; border-radius: 3px; }

.icon-btn { display: grid; place-items: center; width: 28px; height: 28px; padding: 0; background: none; border: 1px solid transparent; border-radius: var(--radius-s); color: var(--ink-2); cursor: pointer; }
.icon-btn:hover:not(:disabled) { background: #f1eee3; color: var(--ink); border-color: var(--line-strong); }
.icon-btn:disabled { opacity: 0.25; cursor: default; }

.switch { position: relative; width: 46px; height: 26px; padding: 0; background: #cfccbf; border: 0; border-radius: 999px; cursor: pointer; transition: background-color 120ms ease; }
.switch.is-on { background: var(--ok); }
.switch-knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: transform 120ms ease; }
.switch.is-on .switch-knob { transform: translateX(20px); }

.setup-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.setup-list li { display: flex; align-items: center; gap: 0.625rem; }
.setup-list .is-done { color: var(--ink-2); }
.setup-mark { display: grid; place-items: center; width: 1.625rem; height: 1.625rem; background: var(--pen-tint); color: var(--pen-dark); border-radius: 50%; font-size: 0.8125rem; font-weight: 700; flex: none; }
.is-done .setup-mark { background: var(--ok-tint); color: var(--ok-dark); }

.stat-row { display: flex; flex-wrap: wrap; gap: 0.625rem; margin: 0 0 1rem; }
.stat-row > div { flex: 1 1 8rem; padding: 0.625rem 0.875rem; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-m); }
.stat-row dt { color: var(--ink-2); font-size: 0.8125rem; }
.stat-row dd { margin: 0; font: 700 1.375rem/1.3 var(--font-display); }

.two-col { display: grid; gap: 1rem; align-items: start; }
.two-col > .panel { margin: 0; }
@media (min-width: 860px) { .two-col { grid-template-columns: minmax(0, 1fr) 22rem; } }

.question-layout { display: grid; gap: 1rem; align-items: start; }
@media (min-width: 960px) { .question-layout { grid-template-columns: minmax(0, 1fr) 26rem; } }
.question-side { min-width: 0; }
.question-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.question-row { display: flex; gap: 0.5rem; padding: 0.625rem 0.75rem; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-s); }
.row-move { display: flex; flex-direction: column; gap: 0.125rem; flex: none; }
.row-move .icon-btn { width: 24px; height: 24px; }
.row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.25rem; overflow-wrap: anywhere; }
.row-options { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.25rem; font-size: 0.875rem; }
.row-options li { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0 0.5rem; background: #f6f4ec; border-radius: 3px; }
.row-options li.is-correct { background: var(--ok-tint); color: var(--ok-dark); font-weight: 600; }
.row-accepted { font-size: 0.875rem; color: var(--ok-dark); font-weight: 600; }
.row-actions { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 0.125rem; font-size: 0.875rem; }

.type-switch { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; }
.panel .type-switch legend { padding: 0; margin: 0 0 0.25rem; font: 600 0.9375rem var(--font-body); }
.math-preview { margin-top: 0.375rem; padding: 0.5rem 0.75rem; background: var(--pen-tint); border-radius: var(--radius-s); white-space: pre-line; overflow-x: auto; }
.option-rows { display: flex; flex-direction: column; gap: 0.375rem; margin-top: 0.25rem; }
.option-row { display: flex; align-items: center; gap: 0.5rem; }
.option-row input[type="radio"] { margin: 0; }
.option-row input:not([type="radio"]) { min-height: 38px; padding-block: 0.25rem; }
.option-row .option-key { width: 1.5rem; height: 1.5rem; font-size: 0.8125rem; }

.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; margin-bottom: 1rem; }
.filter-bar .field { flex: 1 1 12rem; max-width: 20rem; }
.pager { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.5rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
