/* Driving & Riding course — shared stylesheet.
   Typography after Tufte: one readable column, serif body, quiet UI, figures that carry the load.
   Diagram vocabulary (d-*) is documented in DIAGRAMS.md. */

:root {
  --bg: #fffff8;
  --bg-soft: #f6f4ea;
  --ink: #1b1b1b;
  --muted: #6a6a63;
  --rule: #dcd8c8;
  --accent: #a3271f;        /* Tufte red: emphasis, warnings */
  --link: #1d5fa8;
  --ok: #2c7a3f;
  --desk: #5b4b8a;          /* desk-mode label */
  --vehicle: #b0651c;       /* vehicle-mode label */

  /* Diagram palette */
  --d-ground: #e4e1d3;      /* verge, footpath, plots */
  --d-road: #5d6166;        /* asphalt */
  --d-mark: #f7f7f2;        /* road markings */
  --d-yellow: #e9b525;      /* yellow markings, amber */
  --d-self: #1f6feb;        /* the learner's vehicle, always blue */
  --d-other: #8d939a;       /* other traffic */
  --d-heavy: #c4762b;       /* buses and trucks */
  --d-auto: #2f9e57;        /* auto-rickshaws */
  --d-person: #d1495b;      /* pedestrians */
  --d-danger: rgba(214, 48, 49, 0.30);
  --d-safe: rgba(46, 160, 67, 0.28);
  --d-sight: rgba(255, 214, 10, 0.30); /* sightlines, mirror coverage */
  --d-path: #1f6feb;
  --d-alt: #d63031;         /* wrong path, mistake */
  --d-label: #1b1b1b;
  --d-label-on-road: #ffffff;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Charter, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
  --measure: 38rem;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --bg-soft: #1f1f1d;
    --ink: #e6e4dc;
    --muted: #9a988f;
    --rule: #3a3935;
    --accent: #ef6a5f;
    --link: #79b0f0;
    --ok: #59b46c;
    --desk: #a99ad6;
    --vehicle: #e3a35c;
    --d-ground: #2b2b28;
    --d-road: #4a4e53;
    --d-label: #e6e4dc;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1.125rem/1.6 var(--serif);
}
main, .page-head, .page-foot { max-width: var(--measure); margin: 0 auto; padding: 0 1.1rem; }

/* ---------- Navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; gap: 0.75rem;
  padding: 0.55rem 1.1rem;
  font: 0.85rem/1.3 var(--sans);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule);
}
.topbar a { color: var(--ink); text-decoration: none; }
.topbar .where { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.page-head { padding-top: 2rem; }
.kicker { font: 600 0.78rem/1.2 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0; }
h1 { font-weight: 400; font-size: 2.1rem; line-height: 1.15; margin: 0.35rem 0 0.8rem; }
h2 { font-weight: 400; font-style: italic; font-size: 1.55rem; line-height: 1.25; margin: 2.6rem 0 0.6rem; }
h3 { font-weight: 600; font-size: 1.12rem; margin: 1.8rem 0 0.4rem; }
p, ul, ol { margin: 0 0 1rem; }
ul, ol { padding-left: 1.3rem; }
li { margin-bottom: 0.3rem; }
a { color: var(--link); text-underline-offset: 2px; }
strong { font-weight: 650; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

/* The one-line promise at the top of a lesson */
.win {
  font-size: 1.2rem; line-height: 1.45; font-style: italic; color: var(--muted);
  border-left: 3px solid var(--accent); padding-left: 0.8rem; margin: 0 0 1.4rem;
}
.meta { font: 0.85rem/1.4 var(--sans); color: var(--muted); }

/* Inline citation: a small linked source name next to the claim */
a.src {
  font: 0.72rem/1 var(--sans); letter-spacing: 0.02em;
  color: var(--muted); text-decoration: none;
  border: 1px solid var(--rule); border-radius: 3px; padding: 0.05rem 0.3rem;
  white-space: nowrap; vertical-align: 0.1em;
}
a.src:hover { color: var(--link); border-color: var(--link); }

/* ---------- Desk mode / vehicle mode ---------- */
.mode { margin-top: 2.8rem; }
.mode > .mode-label {
  display: inline-block; font: 700 0.72rem/1 var(--sans); letter-spacing: 0.12em; text-transform: uppercase;
  padding: 0.35rem 0.55rem; border-radius: 3px; color: #fff;
}
.mode.desk > .mode-label { background: var(--desk); }
.mode.vehicle > .mode-label { background: var(--vehicle); }
.mode > h2:first-of-type { margin-top: 0.7rem; }

/* ---------- Figures and diagrams ---------- */
figure { margin: 1.6rem -0.4rem; }
figure > svg, svg.diagram { display: block; width: 100%; height: auto; border-radius: 6px; }
figcaption { font: 0.86rem/1.45 var(--sans); color: var(--muted); margin-top: 0.5rem; padding: 0 0.4rem; }
figcaption b { color: var(--ink); }
.legend { display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; font: 0.78rem/1.3 var(--sans); color: var(--muted); padding: 0.3rem 0.4rem 0; }
.legend i { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 2px; vertical-align: -0.1rem; margin-right: 0.3rem; }
.legend .self { background: var(--d-self); } .legend .other { background: var(--d-other); }
.legend .heavy { background: var(--d-heavy); } .legend .auto { background: var(--d-auto); }
.legend .danger { background: var(--d-danger); } .legend .safe { background: var(--d-safe); }
.legend .sight { background: var(--d-sight); } .legend .path { background: var(--d-path); }
.legend .alt { background: var(--d-alt); }

/* Diagram vocabulary: apply as classes on SVG elements */
.d-bg { fill: var(--bg-soft); }
.d-ground { fill: var(--d-ground); }
.d-road { fill: var(--d-road); }
.d-mark { stroke: var(--d-mark); stroke-width: 1.5; fill: none; }
.d-dash { stroke: var(--d-mark); stroke-width: 1.5; stroke-dasharray: 30 30; fill: none; }   /* 3 m dash, 3 m gap at 10 units/m */
.d-stopline { stroke: var(--d-mark); stroke-width: 4; fill: none; }
.d-yellow { stroke: var(--d-yellow); stroke-width: 1.5; fill: none; }
.d-kerb { stroke: #b9b5a4; stroke-width: 2.5; fill: none; }
.d-zebra { fill: var(--d-mark); }
.d-island { fill: var(--d-ground); stroke: #b9b5a4; stroke-width: 2; }

.d-self { color: var(--d-self); }
.d-other { color: var(--d-other); }
.d-heavy { color: var(--d-heavy); }
.d-auto { color: var(--d-auto); }
.d-person { color: var(--d-person); }
.d-ghost { opacity: 0.35; }

.d-danger { fill: var(--d-danger); stroke: none; }
.d-safe { fill: var(--d-safe); stroke: none; }
.d-sight { fill: var(--d-sight); stroke: none; }
.d-path { fill: none; stroke: var(--d-path); stroke-width: 2.5; stroke-dasharray: 8 6; stroke-linecap: round; marker-end: url(#d-arrow); }
.d-path.solid { stroke-dasharray: none; }
.d-alt { fill: none; stroke: var(--d-alt); stroke-width: 2.5; stroke-dasharray: 8 6; stroke-linecap: round; marker-end: url(#d-arrow-alt); }
.d-pointer { fill: none; stroke: var(--d-label); stroke-width: 1; }
.d-label { fill: var(--d-label); font: 600 13px var(--sans); }
.d-label.small { font-size: 11px; font-weight: 500; }
.d-label.big { font-size: 16px; }
.d-label.on-road { fill: var(--d-label-on-road); }
.d-label.danger { fill: var(--d-alt); }
.d-label.ok { fill: var(--ok); }
.d-label.mid { text-anchor: middle; }
.d-label.end { text-anchor: end; }
.d-glass { fill: #9fc3e6; opacity: 0.55; }
.d-dash-panel { fill: #2a2d31; }

/* ---------- Stepper: step-through animated figure ---------- */
.stepper { position: relative; }
.stepper [data-steps] { transition: opacity 350ms ease; }
.stepper [data-steps].off { opacity: 0; pointer-events: none; }
.stepper .captions { list-style: none; padding: 0; margin: 0; }
.stepper .captions li { display: none; font: 0.95rem/1.45 var(--sans); color: var(--ink); padding: 0.6rem 0.4rem 0; min-height: 3.2em; }
.stepper .captions li.on { display: block; }
.stepper .captions li b { color: var(--d-self); }
.stepper-controls { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.4rem 0; font: 0.85rem var(--sans); }
.stepper-controls .count { color: var(--muted); min-width: 3.5rem; text-align: center; }
.stepper-controls .play { margin-left: auto; }

button, .btn {
  font: 600 0.88rem/1 var(--sans);
  padding: 0.6rem 0.9rem; border-radius: 6px;
  border: 1px solid var(--rule); background: var(--bg-soft); color: var(--ink);
  cursor: pointer; touch-action: manipulation; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--muted); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary, .btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ---------- Why? boxes (optional depth) ---------- */
details.why {
  margin: 1rem 0 1.2rem; border-left: 3px solid var(--rule); padding: 0.1rem 0 0.1rem 0.9rem;
}
details.why > summary { cursor: pointer; font: 600 0.9rem/1.6 var(--sans); color: var(--muted); }
details.why[open] > summary { margin-bottom: 0.4rem; }
details.why > :last-child { margin-bottom: 0.4rem; }

/* ---------- Key procedure: a numbered routine worth memorising ---------- */
.routine {
  counter-reset: step; list-style: none; padding: 0; margin: 1.2rem 0 1.5rem;
  border-top: 1px solid var(--rule);
}
.routine > li {
  counter-increment: step; position: relative;
  padding: 0.65rem 0 0.65rem 2.6rem; margin: 0; border-bottom: 1px solid var(--rule);
}
.routine > li::before {
  content: counter(step); position: absolute; left: 0; top: 0.6rem;
  width: 1.75rem; height: 1.75rem; border-radius: 50%;
  font: 700 0.85rem/1.75rem var(--sans); text-align: center; color: var(--bg); background: var(--ink);
}
.routine > li > b:first-child { display: block; }

/* Rule callouts: short, only for things that must not be missed */
.note {
  font-size: 1rem; background: var(--bg-soft); border-radius: 6px; padding: 0.8rem 1rem; margin: 1.2rem 0;
}
.note.warn { border-left: 4px solid var(--accent); }
.note.law { border-left: 4px solid var(--desk); }
.note.india { border-left: 4px solid var(--vehicle); }
.note > .tag { display: block; font: 700 0.7rem/1.2 var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.3rem; }
.note > :last-child { margin-bottom: 0; }

/* ---------- Retrieval: recall prompts ---------- */
.recall { margin: 1.5rem 0; }
.recall > h3 { margin-top: 0; }
details.card {
  border: 1px solid var(--rule); border-radius: 6px; margin: 0.5rem 0; background: var(--bg);
}
details.card > summary { cursor: pointer; padding: 0.7rem 0.9rem; font: 1rem/1.45 var(--serif); list-style: none; display: flex; justify-content: space-between; align-items: baseline; gap: 0.8rem; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "Reveal"; flex: none; font: 600 0.72rem/1.9 var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
details.card[open] > summary::after { content: "Hide"; }
details.card > div { padding: 0 0.9rem 0.8rem; color: var(--ink); border-top: 1px dashed var(--rule); padding-top: 0.6rem; }

/* ---------- Quiz ---------- */
.quiz { border: 1px solid var(--rule); border-radius: 8px; padding: 1rem; margin: 1.3rem 0; }
.quiz > .q { font-weight: 600; margin-bottom: 0.8rem; }
.quiz > figure { margin: 0.6rem 0 0.8rem; }
.quiz .options { display: grid; gap: 0.5rem; }
.quiz .options button {
  text-align: left; font: 1rem/1.4 var(--serif); padding: 0.7rem 0.85rem; background: var(--bg);
}
.quiz .options button.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--bg)); }
.quiz .options button.wrong { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--bg)); }
.quiz .why-answer { display: none; margin-top: 0.8rem; font-size: 1rem; color: var(--ink); }
.quiz.answered .why-answer { display: block; }
.quiz .verdict { font: 700 0.8rem var(--sans); letter-spacing: 0.06em; text-transform: uppercase; margin-right: 0.4rem; }
.quiz .verdict.right { color: var(--ok); } .quiz .verdict.wrong { color: var(--accent); }
.quiz [data-correct] { } /* authoring hook only */
.quiz-source { font: 0.75rem var(--sans); color: var(--muted); margin-top: 0.5rem; }

/* ---------- Drill cards (vehicle mode) ---------- */
.drill { border: 2px solid var(--vehicle); border-radius: 10px; padding: 1rem 1rem 0.6rem; margin: 1.5rem 0; }
.drill > h3 { margin-top: 0; }
.drill .drill-meta { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; font: 0.82rem/1.4 var(--sans); color: var(--muted); margin-bottom: 0.8rem; }
.drill .drill-meta span::before { content: "• "; color: var(--vehicle); }
.drill .pass { list-style: none; padding: 0; border-top: 1px dashed var(--rule); padding-top: 0.6rem; }
.drill .pass::before { content: "Pass when"; display: block; font: 700 0.72rem/1.2 var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--vehicle); margin-bottom: 0.4rem; }
.drill .pass li { display: flex; gap: 0.6rem; align-items: flex-start; }
.drill .pass input { width: 1.2rem; height: 1.2rem; margin-top: 0.25rem; accent-color: var(--ok); flex: none; }
.drill .faults { font-size: 1rem; }
.drill .passed-on { font: 600 0.8rem var(--sans); color: var(--ok); margin: 0 0 0.6rem; }

/* Fault → fix table */
table { width: 100%; border-collapse: collapse; font: 0.92rem/1.45 var(--sans); margin: 1rem 0 1.4rem; }
th { text-align: left; font-weight: 700; border-bottom: 2px solid var(--ink); padding: 0.4rem 0.5rem 0.4rem 0; }
td { border-bottom: 1px solid var(--rule); padding: 0.5rem 0.5rem 0.5rem 0; vertical-align: top; }
.table-wrap { overflow-x: auto; }

/* ---------- End-of-lesson blocks ---------- */
.primary-source, .ask {
  font: 0.95rem/1.5 var(--sans); padding: 0.9rem 1rem; border-radius: 8px; margin: 1.2rem 0;
}
.primary-source { background: var(--bg-soft); }
.ask { border: 1px dashed var(--muted); }
.primary-source > .tag, .ask > .tag { display: block; font: 700 0.7rem/1.2 var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.3rem; }
.lesson-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 2rem 0 1rem; }
.page-foot { padding-bottom: 3rem; font: 0.85rem var(--sans); color: var(--muted); }
.pager { display: flex; justify-content: space-between; gap: 1rem; border-top: 1px solid var(--rule); padding-top: 1rem; margin-top: 2rem; }
.pager a { text-decoration: none; max-width: 48%; }
.pager .next { text-align: right; margin-left: auto; }
.pager small { display: block; color: var(--muted); }

/* ---------- Simulator ---------- */
.sim { border: 1px solid var(--rule); border-radius: 10px; padding: 0.8rem; margin: 1.5rem -0.4rem; background: var(--bg-soft); font-family: var(--sans); }
.sim canvas { display: block; width: 100%; height: auto; border-radius: 6px; background: #20242a; touch-action: none; }
.sim .sim-task { font: 0.9rem/1.4 var(--sans); margin: 0 0 0.6rem; }
.sim .sim-task b { color: var(--accent); }
.sim .controls { display: grid; gap: 0.7rem; margin-top: 0.8rem; }
.sim .control { display: grid; grid-template-columns: 5.2rem 1fr; align-items: center; gap: 0.6rem; font-size: 0.82rem; }
.sim .control span.hint { grid-column: 2; font-size: 0.72rem; color: var(--muted); margin-top: -0.5rem; display: flex; justify-content: space-between; }
.sim input[type=range] { width: 100%; height: 2.2rem; accent-color: var(--d-self); }
.sim .buttons { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.sim .buttons button.on { background: var(--d-self); color: #fff; border-color: var(--d-self); }
.sim .result { font: 600 0.9rem/1.4 var(--sans); min-height: 1.4em; margin-top: 0.6rem; }
.sim .result.ok { color: var(--ok); } .sim .result.bad { color: var(--accent); }

/* ---------- Index / dashboard ---------- */
.part { margin: 2rem 0; }
.part h2 { margin: 0 0 0.6rem; font-size: 1.3rem; }
.lesson-list { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--rule); }
.lesson-list li { margin: 0; border-bottom: 1px solid var(--rule); }
.lesson-list a { display: flex; gap: 0.8rem; align-items: baseline; padding: 0.6rem 0; text-decoration: none; color: var(--ink); }
.lesson-list .num { font: 0.8rem var(--mono); color: var(--muted); flex: none; }
.lesson-list .state { margin-left: auto; font: 600 0.72rem var(--sans); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); flex: none; }
.lesson-list .state.done { color: var(--ok); }
.lesson-list .state.due { color: var(--accent); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 0.6rem; margin: 1.2rem 0; }
.tiles a { display: block; padding: 0.8rem; border: 1px solid var(--rule); border-radius: 8px; text-decoration: none; color: var(--ink); font: 600 0.92rem/1.3 var(--sans); }
.tiles a small { display: block; font-weight: 400; color: var(--muted); margin-top: 0.2rem; }

/* ---------- Reference sheets: dense, printable ---------- */
body.reference main { max-width: 52rem; }
body.reference .sheet { columns: 2 22rem; column-gap: 2rem; }
body.reference .sheet > section { break-inside: avoid; margin-bottom: 1.4rem; }
body.reference h2 { font-size: 1.2rem; margin: 0 0 0.4rem; font-style: normal; font-weight: 700; font-family: var(--sans); }

@media print {
  .topbar, .lesson-actions, .stepper-controls, .pager, .ask, .sim .controls { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  details.card > div, details.why > * { display: block !important; }
  a { color: inherit; }
  figure, .drill, .quiz, section { break-inside: avoid; }
}

@media print {
  body.reference .sheet { columns: 2 16rem; column-gap: 1rem; font-size: 9pt; line-height: 1.25; }
  body.reference table { font-size: 8pt; line-height: 1.2; margin: 0.4rem 0 0.6rem; }
  body.reference .page-head { padding-top: 0.25rem; }
  body.reference .sheet > section { margin-bottom: 0.5rem; }
  body.reference .sheet p { margin-bottom: 0.4rem; }
  body.reference h2 { font-size: 11pt; line-height: 1.2; margin-bottom: 0.3rem; }
}

/* ---------- Practice plan and review ---------- */
.stage { margin: 2rem 0; }
.stage > h2 { margin: 0 0 0.3rem; font-size: 1.25rem; }
.stage > p { font: 0.9rem/1.45 var(--sans); color: var(--muted); }
.drill-row { display: flex; gap: 0.7rem; align-items: baseline; padding: 0.55rem 0; border-bottom: 1px solid var(--rule); font: 0.95rem/1.4 var(--sans); }
.drill-row a { color: var(--ink); text-decoration: none; }
.drill-row .vehicle { font-size: 0.75rem; color: var(--muted); }
.drill-row .status { margin-left: auto; flex: none; font: 700 0.7rem var(--sans); letter-spacing: 0.06em; text-transform: uppercase; }
.drill-row .status.passed { color: var(--ok); } .drill-row .status.ready { color: var(--vehicle); } .drill-row .status.locked { color: var(--muted); }
.drill-row small { display: block; color: var(--muted); font-size: 0.78rem; }
.panel { background: var(--bg-soft); border-radius: 10px; padding: 1rem; margin: 1.4rem 0; font: 0.95rem/1.5 var(--sans); }
.panel h2 { font: 700 0.75rem/1.2 var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 0 0 0.5rem; font-style: normal; }
.panel ul { margin: 0; }
.from-lesson { font: 0.75rem var(--sans); color: var(--muted); margin-top: 0.5rem; }
textarea { width: 100%; min-height: 6rem; font: 0.95rem/1.4 var(--sans); padding: 0.6rem; border-radius: 6px; border: 1px solid var(--rule); background: var(--bg); color: var(--ink); }

@media (min-width: 46rem) {
  body { font-size: 1.2rem; }
  h1 { font-size: 2.5rem; }
}

/* simulator readouts (HTML, so they stay crisp on phones) */
.sim .readout { display: flex; justify-content: space-between; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.5rem; font: 600 0.95rem/1.3 var(--sans); }
.sim .readout .speed { font-variant-numeric: tabular-nums; }
.sim .readout .state.ok { color: var(--ok); } .sim .readout .state.bad { color: var(--accent); } .sim .readout .state.warn { color: #b7791f; }
.sim .pedalbar { position: relative; height: 0.7rem; border-radius: 0.35rem; background: var(--rule); margin-top: 0.5rem; overflow: hidden; }
.sim .pedalbar .pos { position: absolute; inset: 0 auto 0 0; background: var(--d-self); }
.sim .pedalbar .bite { position: absolute; top: 0; bottom: 0; background: rgba(233, 181, 37, 0.75); z-index: 1; }
.sim .pedalbar-labels { display: flex; justify-content: space-between; font: 0.72rem var(--sans); color: var(--muted); }
.sim .control span.hint { margin-top: -0.7rem; }
