/* Visual direction: Swedish roadside. Sign yellow, asphalt ink, cool stone. */
/* Archivo (SIL Open Font License, fonts/OFL.txt), served from this site: no requests to Google. */
@font-face {
  font-family: "Archivo";
  src: url("fonts/archivo-variable.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}

:root {
  --stone: #e9ecea;        /* page background */
  --paper: #f8f9f7;        /* secondary surface */
  --ink: #15191e;          /* primary text, asphalt */
  --muted: #545d66;        /* muted text, 6.2:1 on stone */
  --line: #c9cfcc;         /* dividers */
  --sign: #ffd200;         /* the one accent: road-sign yellow */
  --ok: #1d7a3a;
  --ok-tint: #dcefe1;
  --bad: #b3261e;
  --bad-tint: #f7e0de;

  /* traffic scenes (scenes.js) */
  --ground: #b9c7b0;
  --asphalt: #4b5057;
  --pavement: #d3d6d2;
  --cyclepath: #8a6f66;
  --marking: #f4f4f0;
  --scene-edge: #15191e;
  --scene-glass: #1d2a36;
  --building: #cfc5b4;

  --font: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --text-heading: 1.5rem;
  --text-body: 1.0625rem;
  --text-sm: 0.875rem;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --measure: 46rem;
}
@media (prefers-color-scheme: dark) {
  :root {
    --stone: #14181c;
    --paper: #1d2328;
    --ink: #eef0ee;
    --muted: #a3acb4;
    --line: #333c44;
    --ok: #6fd28d;
    --ok-tint: #17301f;
    --bad: #ff8a80;
    --bad-tint: #3a1d1b;
    --ground: #2a3528;
    --asphalt: #3a3f45;
    --pavement: #5b6064;
    --cyclepath: #6a5049;
    --marking: #d9dad4;
    --scene-edge: #0b0d10;
    --building: #5e574d;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--stone);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text-body);
  line-height: 1.55;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; width: 100%; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.wrap { max-width: var(--measure); margin: 0 auto; padding: 0 16px; }
:focus-visible { outline: 3px solid var(--sign); outline-offset: 2px; }

/* ---------- header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: var(--measure);
  margin: 0 auto;
  width: 100%;
  padding: 20px 16px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.75rem;
  font-weight: 800;
  font-stretch: 112%;
  letter-spacing: -0.03em;
}
.brand-mark { width: 34px; height: 34px; }
.header-status { color: var(--muted); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }

/* ---------- home ---------- */
.masthead { padding-top: 32px; padding-bottom: 28px; }
.masthead h1 {
  /* rem + vw so the heading also grows with the OS text size; max is under 2.5x the min */
  font-size: clamp(2.4rem, 1.6rem + 4vw, 4.25rem);
  font-weight: 800;
  font-stretch: 115%;
  line-height: 0.98;
  letter-spacing: -0.04em;
  max-width: 14ch;
}
.masthead p { margin-top: 14px; max-width: 52ch; color: var(--muted); }

.exam-band {
  background: var(--sign);
  color: #15191e;
  padding: 32px 0;
}
.exam-band .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px 32px;
  flex-wrap: wrap;
}
.exam-band h2 { font-size: var(--text-heading); font-weight: 800; letter-spacing: -0.02em; }
.exam-band p { max-width: 44ch; margin-top: 6px; }

.section { padding: 40px 0 8px; }
.section h2 { font-size: var(--text-heading); font-weight: 800; letter-spacing: -0.02em; }
.section > .wrap > p { margin-top: 6px; color: var(--muted); }

.topics { list-style: none; margin: 20px 0 0; padding: 0; border-top: 1px solid var(--line); }
.topics li { border-bottom: 1px solid var(--line); }
.topic {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 16px;
  width: 100%;
  padding: 16px 4px;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 160ms var(--ease);
}
.topic:hover { background: var(--paper); }
.topic strong { font-weight: 650; }
.topic .meta { color: var(--muted); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.topic .bar { grid-column: 1 / -1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.topic .bar span { display: block; height: 100%; background: var(--ok); }
.topic.flagged strong { color: var(--bad); }

.progress-note {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 20px 0 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border-radius: 6px;
  padding: 12px 22px;
  border: 2px solid var(--ink);
  background: var(--ink);
  color: var(--stone);
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
  /* The small lift on hover is movement, so it only happens when reduced motion is off. */
  @media (prefers-reduced-motion: no-preference) {
    transition: transform 140ms var(--ease), background-color 160ms var(--ease), color 160ms var(--ease);
    &:hover:not(:disabled) { transform: translateY(-1px); }
    &:active:not(:disabled) { transform: translateY(0); }
  }
}
.btn:disabled { opacity: .4; cursor: default; }
.exam-band .btn { background: #15191e; border-color: #15191e; color: #ffd200; }
.link-btn {
  font: inherit;
  font-size: var(--text-sm);
  background: none;
  border: 0;
  padding: 4px 0;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link-btn:hover { color: var(--ink); }

/* ---------- question ---------- */
.q-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding-top: 12px;
  color: var(--muted);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}
.timer { color: var(--ink); font-weight: 700; font-size: var(--text-body); }
.timer.low { color: var(--bad); }

/* Progress drawn as a road centre line */
.road {
  position: relative;
  height: 10px;
  margin: 12px 0 28px;
  background: var(--ink);
  border-radius: 2px;
  overflow: hidden;
}
.road::before {
  content: "";
  position: absolute;
  inset: 4px 0;
  background: repeating-linear-gradient(90deg, var(--stone) 0 14px, transparent 14px 26px);
  opacity: .5;
}
.road span {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--sign);
  @media (prefers-reduced-motion: no-preference) {
    transition: width 240ms var(--ease);
  }
}

.sign { display: flex; justify-content: center; margin-bottom: 24px; }
.sign svg { width: 132px; height: auto; filter: drop-shadow(0 2px 0 rgba(0,0,0,.12)); }

.question h1 {
  font-size: var(--text-heading);
  font-weight: 750;
  line-height: 1.25;
  letter-spacing: -0.02em;
  max-width: 34ch;
}

.options { border: 0; margin: 20px 0 0; padding: 0; }
.option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  margin-bottom: 8px;
  background: var(--paper);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 160ms var(--ease), background-color 160ms var(--ease);
}
.option:not(.locked):hover { border-color: var(--line); }
.option input {
  appearance: none;
  flex: none;
  width: 20px;
  height: 20px;
  margin: 0;
  border: 2px solid var(--muted);
  border-radius: 50%;
  display: grid;
  place-content: center;
  transition: border-color 160ms var(--ease);
}
.option input::after {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink);
  transform: scale(0);
  @media (prefers-reduced-motion: no-preference) {
    transition: transform 140ms var(--ease);
  }
}
.option input:checked { border-color: var(--ink); }
.option input:checked::after { transform: scale(1); }
.option:not(.locked):has(input:checked) { border-color: var(--ink); }
.option.correct { background: var(--ok-tint); border-color: var(--ok); }
.option.correct input { border-color: var(--ok); }
.option.correct input::after { background: var(--ok); }
.option.wrong { background: var(--bad-tint); border-color: var(--bad); }
.option.wrong input { border-color: var(--bad); }
.option.wrong input::after { background: var(--bad); }
.option.locked { cursor: default; }

.explain {
  margin-top: 16px;
  padding: 16px 18px;
  border-left: 4px solid var(--sign);
  background: var(--paper);
  max-width: 65ch;
}
.explain .verdict { font-weight: 750; margin-right: 4px; }
.explain .verdict.ok { color: var(--ok); }
.explain .verdict.bad { color: var(--bad); }
.src { display: block; margin-top: 8px; color: var(--muted); font-size: var(--text-sm); }

.q-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 28px 0 40px;
}
.q-actions .right { display: flex; gap: 10px; }
.btn.ghost { background: transparent; color: var(--ink); }

/* ---------- result ---------- */
.result { padding-top: 40px; padding-bottom: 32px; }
.score {
  font-size: clamp(3.5rem, 2.5rem + 6vw, 6.5rem);
  font-weight: 800;
  font-stretch: 115%;
  letter-spacing: -0.05em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.score.pass { color: var(--ok); }
.score.fail { color: var(--bad); }
.result p { margin: 12px 0 24px; max-width: 52ch; }
.section-title { font-size: var(--text-heading); font-weight: 800; letter-spacing: -0.02em; }
.review { list-style: none; padding: 0; margin: 16px 0 40px; border-top: 1px solid var(--line); }
.review li { padding: 20px 0; border-bottom: 1px solid var(--line); }
.review h3 { font-size: var(--text-body); font-weight: 700; }
.review .sign { justify-content: flex-start; margin: 12px 0 0; }
.review .sign svg { width: 72px; }
.review .answers { margin: 10px 0 0; padding: 0; list-style: none; }
.review .answers li { padding: 2px 0; border: 0; }
.yours { color: var(--bad); }
.right-answer { color: var(--ok); }

/* ---------- footer ---------- */
.site-footer {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 32px 16px 40px;
  color: var(--muted);
  font-size: var(--text-sm);
}
.site-footer p { max-width: 65ch; }

/* ---------- confirmation dialog ---------- */
dialog {
  width: min(28rem, calc(100% - 32px));
  padding: 24px;
  border: 0;
  border-radius: 10px;
  background: var(--stone);
  color: var(--ink);
}
dialog h1 { font-size: var(--text-heading); font-weight: 800; letter-spacing: -0.02em; }
dialog p { margin-top: 8px; color: var(--muted); }
dialog::backdrop { background: rgb(10 12 14 / 0.55); }
/* Without both rules, scrolling over the backdrop or inside the dialog scrolls the page behind it. */
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop { overflow: hidden; overscroll-behavior: contain; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 24px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* em, not px, so the breakpoint also kicks in when the text size is turned up */
@media (max-width: 35em) {
  .brand { font-size: 1.5rem; }
  .exam-band .btn { width: 100%; }
  .q-actions { flex-wrap: wrap; }
}

/* ---------- exam setting switch ---------- */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  cursor: pointer;
  font-weight: 600;
}
.switch input {
  appearance: none;
  flex: none;
  width: 42px;
  height: 24px;
  margin: 0;
  border-radius: 12px;
  background: rgb(21 25 30 / 0.25);
  border: 2px solid #15191e;
  position: relative;
  cursor: pointer;
  transition: background-color 160ms var(--ease);
}
.switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #15191e;
  @media (prefers-reduced-motion: no-preference) {
    transition: translate 160ms var(--ease);
  }
}
.switch input:checked { background: #15191e; }
.switch input:checked::after { translate: 18px 0; background: #ffd200; }
.switch input:focus-visible { outline: 3px solid #15191e; outline-offset: 2px; }

/* ---------- coverage page ---------- */
.coverage { padding-top: 12px; padding-bottom: 40px; }
.coverage > h1 { font-size: clamp(1.9rem, 1.4rem + 2vw, 2.6rem); font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; }
.coverage > p { margin-top: 12px; max-width: 62ch; color: var(--muted); }
.coverage section { margin-top: 32px; }
.coverage h2 { font-size: var(--text-heading); font-weight: 800; letter-spacing: -0.02em; }
.area-meta { color: var(--muted); font-size: var(--text-sm); margin-top: 2px; }
.coverage .topics { margin-top: 12px; }
.topic .ref { grid-column: 1 / -1; color: var(--muted); font-size: var(--text-sm); }
.topic.missing {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 16px;
  padding: 16px 4px;
}
.topic.missing strong { font-weight: 650; }
.topic.missing .meta { color: var(--bad); font-weight: 600; }
.coverage .sources { margin: 32px 0 20px; font-size: var(--text-sm); }
.coverage .sources a { color: inherit; }
.coverage-btn { margin-top: 16px; }

/* ---------- traffic scenes ---------- */
.scene { margin: 0 0 24px; }
.scene-stage {
  max-width: 24rem;
  margin: 0 auto;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--ink);
}
.scene-stage svg { display: block; width: 100%; height: auto; }
/* Driver's view: 16:9, wider than the map. The box keeps its size while three.js loads. */
.scene-3d {
  aspect-ratio: 16 / 9;
  max-width: 44rem;
  margin: 0 auto;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--ink);
  background: #c9dceb;
}
.scene-3d canvas { display: block; width: 100%; height: 100%; }
.scene:has(.scene-3d) figcaption { max-width: 44rem; }
.scene-map .scene-stage { max-width: 18rem; margin: 10px 0 6px; }
.scene figcaption { max-width: 24rem; margin: 12px auto 0; }
.scene-controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.scene figcaption > p { font-size: var(--text-sm); }
.scene details { margin-top: 6px; font-size: var(--text-sm); }
.scene summary { cursor: pointer; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.scene details p { margin-top: 6px; max-width: 60ch; }
.watch-first {
  margin: 20px 0 0;
  padding: 14px 16px;
  background: var(--paper);
  border-left: 4px solid var(--sign);
  color: var(--muted);
}
.review .scene { margin: 12px 0 0; }
.review .scene-stage, .review .scene figcaption { max-width: 14rem; margin-left: 0; }
