:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --border: #d6d5ce;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #1c5cab;
  --accent-ink: #ffffff;
  --accent-soft: #e6effb;
  --series: #2a78d6;
  --series-muted: #b9b8b1;
  --whisker: #3a3936;
  --good: #006300;
  --critical: #b3261e;
  --focus: #1c5cab;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --border: #3d3d3a;
    --grid: #2c2c2a;
    --axis: #4a4a46;
    --accent: #86b6ef;
    --accent-ink: #0b0b0b;
    --accent-soft: #1d2a3b;
    --series: #3987e5;
    --series-muted: #5c5b56;
    --whisker: #e8e7e0;
    --good: #3ec43e;
    --critical: #f28b82;
    --focus: #86b6ef;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242422;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --border: #3d3d3a;
  --grid: #2c2c2a;
  --axis: #4a4a46;
  --accent: #86b6ef;
  --accent-ink: #0b0b0b;
  --accent-soft: #1d2a3b;
  --series: #3987e5;
  --series-muted: #5c5b56;
  --whisker: #e8e7e0;
  --good: #3ec43e;
  --critical: #f28b82;
  --focus: #86b6ef;
}

*, *::before, *::after { box-sizing: border-box; }

/* The hidden attribute must win over component display rules (e.g. .flag-badge). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 16px/1.55 var(--font);
  overflow-wrap: anywhere;
}

.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }

h1 { font-size: 1.6rem; line-height: 1.25; margin: 1.25rem 0 .75rem; }
h2 { font-size: 1.2rem; margin: 2rem 0 .75rem; }
.card h2 { margin-top: 0; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main:focus { outline: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link { position: absolute; left: -9999px; top: 0; background: var(--surface); color: var(--text); padding: 8px 12px; z-index: 10; }
.skip-link:focus { left: 8px; top: 8px; }

.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.brand { margin: 0; padding: 12px 0; font-weight: 650; }
.site-footer { border-top: 1px solid var(--border); margin-top: 3rem; padding: 1rem 0 2rem; color: var(--text-2); font-size: .875rem; }
.site-footer p { margin: .25rem 0; }

.loading { color: var(--text-2); margin-top: 2rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 1rem 0;
}

.notice {
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  padding: 12px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 1rem 0;
}
.notice p:last-child { margin-bottom: 0; }
.notice-error { border-left-color: var(--critical); background: var(--surface-2); }
.notice-plain { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--text-2); }

.hint { color: var(--text-2); font-size: .9rem; }

.field { margin: 1rem 0; }
.field label { display: block; font-weight: 600; margin-bottom: .35rem; }
.length-row { display: flex; gap: 12px; align-items: center; }
.length-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
input[type="number"], input[type="text"], select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--text-2);
  border-radius: 6px;
  padding: 8px 10px;
}
input[type="number"] { width: 5.5rem; }
input[type="text"] { width: 100%; max-width: 22rem; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: .5rem; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 1rem; }

.btn {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--text-2);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-quiet { border-color: transparent; background: transparent; text-decoration: underline; }
.btn[aria-disabled="true"], .btn:disabled {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-2);
  cursor: not-allowed;
  filter: none;
}
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }

/* Quiz */
.quiz-status { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 1.25rem; }
.quiz-status p { margin: 0; }
.q-count { font-weight: 650; }
.q-answered { color: var(--text-2); }
.progress { height: 8px; background: var(--grid); border-radius: 4px; margin: .5rem 0 0; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--series); border-radius: 4px; transition: width .2s ease; }

.question-card { margin-top: 1rem; }
.stem { font-size: 1.075rem; margin-bottom: 1rem; }
.flag-badge { display: inline-block; font-size: .85rem; font-weight: 600; color: var(--text); background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 999px; padding: 2px 10px; }

.options { border: 0; margin: 0; padding: 0; display: grid; gap: 10px; }
.option {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  background: var(--surface);
}
.option:hover { border-color: var(--text-2); }
.option input { margin: .3rem 0 0; width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.option .letter { font-weight: 700; min-width: 1.4rem; }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.option:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.option input:focus-visible { outline: none; }

.quiz-nav { display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; margin-top: 1rem; }
.quiz-nav .btn { flex: 1 1 8rem; }
.kbd-hint { margin-top: .75rem; }
kbd { font: .8rem/1 var(--font); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 2px 5px; background: var(--surface); }

.navigator-wrap { margin-top: 1rem; }
.navigator { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.navigator button {
  width: 100%;
  min-height: 44px;
  font: inherit;
  font-size: .9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  position: relative;
}
.navigator button.answered { background: var(--accent-soft); border-color: var(--accent); }
.navigator button.flagged::after { content: "⚑"; position: absolute; top: 1px; right: 3px; font-size: .7rem; }
.navigator button[aria-current="true"] { outline: 2px solid var(--text); outline-offset: 1px; }

.submit-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.submit-row .hint { margin: 0; flex: 1 1 14rem; }
.tooltip-wrap { position: relative; display: inline-block; }
.tooltip-wrap[data-tip]:hover::after,
.tooltip-wrap[data-tip]:focus-within::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: max-content;
  max-width: min(18rem, 80vw);
  background: var(--text);
  color: var(--page);
  font-size: .85rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 6px;
  z-index: 5;
}

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  max-width: min(32rem, calc(100vw - 32px));
  padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin-top: 0; }

/* Report */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 1rem 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile-label { font-size: .875rem; color: var(--text-2); margin: 0; }
.tile-value { font-size: 2rem; font-weight: 650; margin: .15rem 0 0; }
.tile-note { font-size: .8rem; color: var(--text-2); margin: .15rem 0 0; }

.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.data-table { border-collapse: collapse; width: 100%; font-size: .925rem; }
.data-table th, .data-table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table thead th { font-weight: 650; color: var(--text-2); white-space: nowrap; }
.data-table tbody th { font-weight: 600; min-width: 11rem; }

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap; }
.status-icon { font-size: 1rem; line-height: 1; }
.status-strength { color: var(--good); }
.status-weakness { color: var(--critical); }
.status-adequate, .status-insufficient { color: var(--text-2); }

.viz { margin: 1.5rem 0; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.viz figcaption { margin-bottom: .75rem; }
.viz-title { display: block; font-weight: 650; }
.viz-sub { display: block; font-size: .85rem; color: var(--text-2); }
.viz-row { margin: 0 0 10px; }
.viz-label { display: flex; justify-content: space-between; gap: 10px; font-size: .875rem; margin-bottom: 2px; }
.viz-label .viz-value { color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.viz svg { display: block; width: 100%; overflow: visible; }
.viz .bar { fill: var(--series); }
.viz .bar-muted { fill: var(--series-muted); }
.viz .track { fill: var(--grid); }
.viz .whisker { stroke: var(--whisker); stroke-width: 2; stroke-linecap: round; }
.viz .target { stroke: var(--text-2); stroke-width: 1.5; }
.viz .axis-text { fill: var(--text-2); font: 12px var(--font); }
.viz .axis-line { stroke: var(--axis); stroke-width: 1; }

.guidance-card { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--critical); border-radius: 0 var(--radius) var(--radius) 0; padding: 14px 16px; margin: .75rem 0; }
.guidance-card h3 { margin: 0 0 .5rem; font-size: 1.05rem; }
.guidance-card ul { margin: .25rem 0 .5rem 1.1rem; padding: 0; }

.plain-list { padding-left: 1.2rem; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; margin: .5rem 0 .75rem; }
.filters label { display: flex; flex-direction: column; font-size: .875rem; font-weight: 600; gap: 4px; }

.review-list { list-style: none; padding: 0; margin: 0; }
.review-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0 0 12px; }
.review-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: .5rem; }
.tag { font-size: .78rem; border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; color: var(--text-2); }
.tag-strong { color: var(--text); border-color: var(--text-2); font-weight: 600; }
.review-options { list-style: none; padding: 0; margin: .5rem 0; display: grid; gap: 6px; }
.review-options li { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.review-options li.is-correct { border-color: var(--good); border-width: 2px; }
.review-options li.is-chosen:not(.is-correct) { border-color: var(--critical); border-width: 2px; }
.review-options .marker { font-weight: 700; font-size: .8rem; margin-left: 6px; }
.review-options .marker-correct { color: var(--good); }
.review-options .marker-chosen { color: var(--critical); }
.review-options .why { display: block; font-size: .875rem; color: var(--text-2); margin-top: 4px; }
.review-expl { margin: .5rem 0 0; }

.report-actions { margin-top: 2rem; }

@media (max-width: 480px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 16px; }
  .quiz-nav .btn { flex: 1 1 100%; }
  .tile-value { font-size: 1.6rem; }
}

@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .site-header, .site-footer .wrap > p:last-child, .skip-link, .actions, .filters, #start, #quiz, dialog, .loading { display: none !important; }
  .card, .viz, .tile, .table-scroll, .review-item, .guidance-card { break-inside: avoid; border-color: #999; background: #fff; }
  .viz .bar, .progress-fill { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .review-item { page-break-inside: avoid; }
  a { color: #000; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (forced-colors: active) {
  .viz .bar { fill: CanvasText; }
  .viz .bar-muted { fill: GrayText; }
  .viz .whisker, .viz .target { stroke: CanvasText; }
}

/* Read aloud */
.speech-controls { margin-top: 1rem; }
.speech-controls[hidden] { display: none; }
.speech-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.speech-auto { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; }
.speech-settings { margin-top: .5rem; }
.speech-fields { display: grid; grid-template-columns: max-content 1fr; gap: 8px 12px; align-items: center; margin-top: .5rem; max-width: 32rem; }
.speech-fields label { font-size: .875rem; font-weight: 600; }
.speech-fields select { min-width: 0; max-width: 100%; }
.read-expl { margin-top: .5rem; }
@media (max-width: 480px) {
  .speech-fields { grid-template-columns: 1fr; }
}
/* Question-type hint in the report */
.type-hint { margin: .5rem 0 1rem; padding: .75rem 1rem; border: 1px solid var(--border); border-left: 4px solid var(--critical); border-radius: var(--radius); background: var(--surface-2); }
.type-hint[hidden] { display: none; }

/* Immediate feedback (opt-in) */
.feedback-toggle { margin: .5rem 0; }
.feedback-toggle .hint { margin: .25rem 0 0; }
.feedback { margin-top: 1rem; padding: .75rem 1rem; border: 1px solid var(--border); border-left-width: 4px; border-radius: var(--radius); background: var(--surface-2); }
.feedback[hidden] { display: none; }
.feedback-ok { border-left-color: var(--good); }
.feedback-miss { border-left-color: var(--critical); }
.feedback-verdict { margin: 0 0 .5rem; font-weight: 700; }
.feedback p { margin: .4rem 0; }
@media print { .feedback, .feedback-toggle { display: none !important; } }

/* Voice answers */
.voice-controls { margin-top: 1rem; }
.voice-controls[hidden], #voice-intro[hidden], #voice-active[hidden] { display: none; }
.voice-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.voice-indicator { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; font-weight: 600; min-width: 8rem; }
.voice-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--text-2); background: transparent; box-sizing: border-box; }
.voice-indicator[data-state="listening"] .voice-dot { background: var(--critical); border-color: var(--critical); }
.voice-indicator[data-state="processing"] .voice-dot { background: var(--accent); border-color: var(--accent); border-radius: 3px; }
@media (prefers-reduced-motion: no-preference) {
  .voice-indicator[data-state="listening"] .voice-dot { animation: voice-pulse 1.2s ease-in-out infinite; }
}
@keyframes voice-pulse { 50% { opacity: .35; } }
@media print {
  .speech-controls, .voice-controls, .read-expl { display: none !important; }
}

/* Tracks and code (Python track) */
.track-toggle { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem 1rem; margin: .75rem 0 1rem; }
.track-toggle legend { font-weight: 600; padding: 0 .25rem; }
.track-toggle label { display: inline-flex; align-items: center; gap: 6px; }
.code-block { margin: .75rem 0 1rem; padding: .75rem 1rem; overflow-x: auto; white-space: pre; tab-size: 4; font-size: .9rem; line-height: 1.45; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.code-block:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: .92em; }
:not(pre) > code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 .25em; }
@media print { .code-block { white-space: pre-wrap; overflow: visible; } .track-toggle { display: none !important; } }

/* Commute mode */
.commute-letters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 1rem; }
.commute-letters .btn { font-size: 1.6rem; font-weight: 700; min-height: 4.5rem; }
#commute-run .quiz-nav { margin-top: 1.25rem; }
#commute-next { flex: 1 1 100%; order: -1; min-height: 4.5rem; font-size: 1.35rem; font-weight: 700; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
@media (max-width: 480px) {
  .commute-letters { grid-template-columns: repeat(2, 1fr); }
}
@media print { #commute { display: none !important; } }

/* Review deck */
.deck-due { font-size: 1.15rem; font-weight: 700; margin: .25rem 0; }
.deck-line { margin: 0 0 1rem; padding: .6rem 1rem; border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); background: var(--surface-2); }
