/* ==========================================================================
   Race Vehicle Dynamics — course stylesheet
   Tokens first; light theme by default, dark via prefers-color-scheme or
   the [data-theme] toggle stored by course.js.
   ========================================================================== */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --border: #dcdcd6;
  --text: #1c1d1f;
  --text-muted: #5b5e63;
  --accent: #c0262d;          /* racing red */
  --accent-ink: #ffffff;
  --accent-soft: #fbe9e9;
  --link: #1f5fbf;

  --ok: #1d7a46;
  --ok-soft: #e4f4ea;
  --bad: #b3261e;
  --bad-soft: #fbe7e5;
  --warn: #a15c00;
  --warn-soft: #fdf1df;

  --key: #1f5fbf;      --key-soft: #e8f0fc;
  --try: #6a3fb5;      --try-soft: #f0eafa;
  --rcvd: #8a5a00;     --rcvd-soft: #fbf3e2;
  --miscon: #b3261e;   --miscon-soft: #fbe7e5;
  --example: #1d7a46;  --example-soft: #e4f4ea;

  /* Plot series — distinguishable in both themes */
  --s1: #1f5fbf;
  --s2: #d1495b;
  --s3: #2a9d6f;
  --s4: #8a5cc7;
  --s5: #c98a00;
  --grid: #e6e6e1;
  --axis: #8b8e93;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sidebar-w: 300px;
  --topbar-h: 56px;
  --content-w: 760px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141518;
    --surface: #1c1e22;
    --surface-2: #24272c;
    --border: #34373d;
    --text: #e8e8e6;
    --text-muted: #a2a5ab;
    --accent: #ef5350;
    --accent-ink: #1a0b0b;
    --accent-soft: #3a1f21;
    --link: #7fb0ff;
    --ok: #5cc98a;  --ok-soft: #173525;
    --bad: #ff7a70; --bad-soft: #3c1d1b;
    --warn: #f0b04a; --warn-soft: #3a2c14;
    --key: #7fb0ff;     --key-soft: #1a2638;
    --try: #b99cf0;     --try-soft: #271f38;
    --rcvd: #e7b65c;    --rcvd-soft: #33291a;
    --miscon: #ff7a70;  --miscon-soft: #3c1d1b;
    --example: #5cc98a; --example-soft: #173525;
    --s1: #6ea8ff; --s2: #ff7a8a; --s3: #4fd1a0; --s4: #b99cf0; --s5: #f0c050;
    --grid: #2b2e33;
    --axis: #7d8188;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #141518;
  --surface: #1c1e22;
  --surface-2: #24272c;
  --border: #34373d;
  --text: #e8e8e6;
  --text-muted: #a2a5ab;
  --accent: #ef5350;
  --accent-ink: #1a0b0b;
  --accent-soft: #3a1f21;
  --link: #7fb0ff;
  --ok: #5cc98a;  --ok-soft: #173525;
  --bad: #ff7a70; --bad-soft: #3c1d1b;
  --warn: #f0b04a; --warn-soft: #3a2c14;
  --key: #7fb0ff;     --key-soft: #1a2638;
  --try: #b99cf0;     --try-soft: #271f38;
  --rcvd: #e7b65c;    --rcvd-soft: #33291a;
  --miscon: #ff7a70;  --miscon-soft: #3c1d1b;
  --example: #5cc98a; --example-soft: #173525;
  --s1: #6ea8ff; --s2: #ff7a8a; --s3: #4fd1a0; --s4: #b99cf0; --s5: #f0c050;
  --grid: #2b2e33;
  --axis: #7d8188;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.65;
}
a { color: var(--link); }
img, svg { max-width: 100%; }
h1, h2, h3, h4 { line-height: 1.25; margin: 1.6em 0 .5em; }
h1 { font-size: 2rem; margin-top: 0; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.15rem; }
p, ul, ol { margin: 0 0 1em; }
code { font-family: var(--font-mono); font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2.5em 0; }
.muted { color: var(--text-muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar__brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__logo { width: 28px; height: 28px; border-radius: 6px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 13px; font-weight: 800; flex: none; }
.topbar__spacer { flex: 1; }
.topbar__progress { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-muted); white-space: nowrap; }
.progress-bar { width: 120px; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.icon-btn {
  white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; height: 36px; min-width: 36px; padding: 0 10px; cursor: pointer; font: inherit; font-size: 14px;
}
.icon-btn:hover { background: var(--surface-2); }
.nav-toggle { display: none; }

.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: calc(100vh - var(--topbar-h)); }
.layout--full { grid-template-columns: minmax(0, 1fr); }

.sidebar {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 16px 12px 40px;
  font-size: 14.5px;
}
.sidebar a { color: inherit; text-decoration: none; }
.nav-home { display: block; padding: 6px 10px; border-radius: 6px; font-weight: 600; margin-bottom: 8px; }
.nav-home:hover { background: var(--surface-2); }
.nav-module { margin-bottom: 4px; }
.nav-module > summary {
  list-style: none; cursor: pointer; padding: 8px 10px; border-radius: 6px;
  display: flex; gap: 8px; align-items: baseline; font-weight: 600;
}
.nav-module > summary::-webkit-details-marker { display: none; }
.nav-module > summary:hover { background: var(--surface-2); }
.nav-module__num { color: var(--accent); font-variant-numeric: tabular-nums; min-width: 1.4em; }
.nav-module ul { list-style: none; margin: 0 0 6px; padding: 0 0 0 20px; }
.nav-lesson a {
  display: flex; gap: 8px; align-items: baseline;
  padding: 5px 10px; border-radius: 6px; color: var(--text-muted);
}
.nav-lesson a:hover { background: var(--surface-2); color: var(--text); }
.nav-lesson a[aria-current="page"] { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.nav-lesson__mark { flex: none; width: 1em; text-align: center; font-size: 12px; }
.nav-lesson__num { flex: none; min-width: 2.2em; font-variant-numeric: tabular-nums; color: var(--text-muted); }
.nav-lesson a[aria-current="page"] .nav-lesson__num { color: var(--accent); }
.nav-lesson--done .nav-lesson__mark { color: var(--ok); }
.nav-lesson--planned a { opacity: .7; font-style: italic; }

.main { padding: 32px 24px 80px; min-width: 0; }
.content { max-width: var(--content-w); margin: 0 auto; }
.content--wide { max-width: 1100px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .nav-toggle { display: inline-block; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-h); bottom: 0; width: min(86vw, var(--sidebar-w));
    height: auto; transform: translateX(-100%); transition: transform .2s; z-index: 25; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  .topbar__progress .progress-bar { display: none; }
  .main { padding: 24px 16px 64px; }
  body { font-size: 16px; }
}

/* ---------- Lesson header & footer ---------- */
.lesson-kicker { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
.lesson-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 20px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; padding: 2px 10px; border-radius: 99px;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.chip--rcvd { background: var(--rcvd-soft); color: var(--rcvd); border-color: transparent; }
.chip--ready { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip--draft { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip--planned { background: var(--surface-2); }
.chip--optional { background: var(--try-soft); color: var(--try); border-color: transparent; }

.objectives {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 28px;
}
.objectives h2 { font-size: 1rem; margin: 0 0 8px; }
.objectives ul { margin: 0; padding-left: 1.2em; }

.lesson-footer {
  margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--border);
}
.complete-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-size: 15px; font-weight: 600;
  padding: 9px 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn--primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn--done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pager a {
  display: block; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); text-decoration: none; color: var(--text); font-size: 15px;
}
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.pager .next { text-align: right; grid-column: 2; }

/* ---------- Content blocks ---------- */
.lesson-section { scroll-margin-top: calc(var(--topbar-h) + 12px); }

.callout {
  --c: var(--key); --c-soft: var(--key-soft);
  border-left: 4px solid var(--c);
  background: var(--c-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 14px 18px; margin: 1.4em 0;
}
.callout > :last-child { margin-bottom: 0; }
.callout__title { font-weight: 700; color: var(--c); font-size: 14px; text-transform: uppercase; letter-spacing: .05em; margin: 0 0 6px; }
.callout--key { --c: var(--key); --c-soft: var(--key-soft); }
.callout--try { --c: var(--try); --c-soft: var(--try-soft); }
.callout--rcvd { --c: var(--rcvd); --c-soft: var(--rcvd-soft); }
.callout--misconception { --c: var(--miscon); --c-soft: var(--miscon-soft); }
.callout--example { --c: var(--example); --c-soft: var(--example-soft); }

/* Expandable derivation: collapsed by default, opens in place. */
.derivation {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); margin: 1.4em 0;
}
.derivation > summary {
  list-style: none; cursor: pointer; padding: 10px 16px;
  display: flex; gap: 10px; align-items: center;
  font-weight: 600; color: var(--link); border-radius: var(--radius);
}
.derivation > summary::-webkit-details-marker { display: none; }
.derivation > summary::before {
  content: ""; flex: none; width: 7px; height: 7px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s ease;
}
.derivation[open] > summary::before { transform: rotate(45deg); }
.derivation > summary:hover { background: var(--surface-2); }
.derivation__hint { font-weight: 400; color: var(--text-muted); font-size: 14px; margin-left: auto; }
.derivation[open] .derivation__hint { display: none; }
.derivation__body { padding: 4px 18px 14px; border-top: 1px solid var(--border); }
.derivation__body > :last-child { margin-bottom: 0; }
.derivation__step { font-weight: 600; margin: 1em 0 .3em; }
@media (max-width: 480px) {
  .derivation > summary { padding: 10px 12px; }
  .derivation__body { padding: 4px 10px 12px; }
}

.equation { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
/* Any display math (including inside callouts) scrolls rather than widening the page on phones. */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.eq-label { color: var(--text-muted); font-size: 14px; }

figure { margin: 1.6em 0; }
figure svg { display: block; margin: 0 auto; }
figcaption { font-size: 14px; color: var(--text-muted); text-align: center; margin-top: 8px; }
.fig-stroke { stroke: var(--text); }
.fig-fill { fill: var(--text); }
.fig-muted { stroke: var(--text-muted); }
.fig-text { fill: var(--text); font-family: var(--font-sans); font-size: 14px; }
.fig-halo { paint-order: stroke; stroke: var(--bg); stroke-width: 4px; }
.fig-chassis { fill: var(--surface-2); stroke: var(--axis); }
.fig-joint { fill: var(--bg); stroke: var(--text); stroke-width: 2; }
.fig-accent { stroke: var(--accent); fill: var(--accent); }
.fig-s1 { stroke: var(--s1); } .fig-s1-fill { fill: var(--s1); }
.fig-s2 { stroke: var(--s2); } .fig-s2-fill { fill: var(--s2); }

table.data { border-collapse: collapse; width: 100%; font-size: 15px; margin: 1em 0 1.4em; }
table.data th, table.data td { border-bottom: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
table.data th { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.table-wrap { overflow-x: auto; }

/* ---------- Widgets ---------- */
.widget {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin: 1.6em 0;
}
.widget__title { font-weight: 700; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.widget__title::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.widget__desc { color: var(--text-muted); font-size: 14.5px; margin-bottom: 14px; }
.widget__body { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 20px; align-items: start; }
.widget__body--stack { grid-template-columns: minmax(0, 1fr); }
.widget__controls { display: flex; flex-direction: column; gap: 12px; }
.widget__plots { display: grid; gap: 16px; min-width: 0; }
.widget__plots--2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }   /* two side by side only when each gets 300px+ */
.widget__plots--3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
@media (max-width: 820px) {
  .widget__body { grid-template-columns: minmax(0, 1fr); }
  .widget__plots { order: -1; }
  .widget__plots--2 { grid-template-columns: minmax(0, 1fr); }
}
.widget-fallback { color: var(--text-muted); font-style: italic; }

.control { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 14px; }
.control label { color: var(--text-muted); }
.control output { font-variant-numeric: tabular-nums; font-weight: 600; }
.control input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
.control-group-title { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-sm { font: inherit; font-size: 13px; padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.btn-sm:hover { background: var(--surface-2); }
.btn-sm[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.readouts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 4px; }
.readout { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.readout__label { font-size: 12px; color: var(--text-muted); }
.readout__value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.readout--ok .readout__value { color: var(--ok); }
.readout--warn .readout__value { color: var(--warn); }
.readout--bad .readout__value { color: var(--bad); }
.status-line { font-size: 14px; padding: 8px 12px; border-radius: 8px; background: var(--surface-2); }
.status-line--ok { background: var(--ok-soft); color: var(--ok); }
.status-line--warn { background: var(--warn-soft); color: var(--warn); }
.status-line--bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- Plots (assets/js/plot.js) ---------- */
.plot { width: 100%; height: auto; display: block; overflow: visible; touch-action: none; }
.plot text { font-family: var(--font-sans); font-size: 12px; fill: var(--text-muted); }
.plot .plot__label { font-size: 13px; fill: var(--text); }
.plot .plot__grid { stroke: var(--grid); stroke-width: 1; }
.plot .plot__axis { stroke: var(--axis); stroke-width: 1.2; }
.plot .plot__zero { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }
.plot .series { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.plot .series--thin { stroke-width: 1.5; }
.plot .series--dash { stroke-dasharray: 6 5; }
.plot .area { stroke: none; opacity: .14; }
.plot .c1 { stroke: var(--s1); } .plot .f1 { fill: var(--s1); }
.plot .c2 { stroke: var(--s2); } .plot .f2 { fill: var(--s2); }
.plot .c3 { stroke: var(--s3); } .plot .f3 { fill: var(--s3); }
.plot .c4 { stroke: var(--s4); } .plot .f4 { fill: var(--s4); }
.plot .c5 { stroke: var(--s5); } .plot .f5 { fill: var(--s5); }
.plot .cm { stroke: var(--text-muted); } .plot .fm { fill: var(--text-muted); }
.plot .marker { stroke: var(--surface); stroke-width: 2; }
.plot .handle { cursor: grab; }
.plot .handle:active { cursor: grabbing; }
.plot .annot { font-size: 12px; font-weight: 600; }
.plot .annot.f1 { fill: var(--s1); } .plot .annot.f2 { fill: var(--s2); } .plot .annot.f3 { fill: var(--s3); } .plot .annot.f4 { fill: var(--s4); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; }
.legend i.area { width: 14px; height: 12px; opacity: .22; }
.legend i.dash { background: repeating-linear-gradient(90deg, currentColor 0 5px, transparent 5px 9px) !important; height: 2px; }

/* ---------- Checks: multiple choice & numeric ---------- */
.check-block { margin: 1.6em 0; display: grid; gap: 16px; }
.mcq, .numeric {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px;
}
.mcq__label, .numeric__label { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.mcq__prompt { margin-bottom: 10px; }
.mcq__options { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.mcq__option {
  width: 100%; text-align: left; font: inherit; font-size: 15.5px; line-height: 1.45;
  padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); cursor: pointer;
  display: flex; gap: 10px;
}
.mcq__option:hover { border-color: var(--link); }
.mcq__option-letter { font-weight: 700; color: var(--text-muted); flex: none; }
.mcq__option.is-correct { border-color: var(--ok); background: var(--ok-soft); }
.mcq__option.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.feedback { margin-top: 10px; padding: 10px 14px; border-radius: 8px; font-size: 15px; }
.feedback:empty { display: none; }
.feedback--ok { background: var(--ok-soft); }
.feedback--bad { background: var(--bad-soft); }
.feedback strong:first-child { margin-right: 4px; }

.numeric__row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 4px; }
.numeric__input {
  font: inherit; font-size: 16px; width: 140px; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.numeric__input:focus { outline: 2px solid var(--link); outline-offset: 1px; }
.numeric__units { color: var(--text-muted); }
.numeric__input { flex: 1 1 220px; max-width: 340px; font-family: var(--font-mono); font-size: 15px; }
.numeric__preview { font-size: 14px; min-height: 1.4em; margin: 2px 0 4px; font-variant-numeric: tabular-nums; cursor: help; }
.numeric__preview.is-tip { color: var(--text-muted); }
.numeric__preview.is-value { color: var(--text); font-family: var(--font-mono); font-weight: 600; }
.numeric__preview.is-error { color: var(--warn); }
.numeric details { margin-top: 8px; }
.numeric summary { cursor: pointer; color: var(--link); font-size: 14.5px; }
.numeric details > div { padding: 8px 0 0 14px; border-left: 2px solid var(--border); margin-top: 6px; font-size: 15.5px; }

/* ---------- Home page ---------- */
.hero { padding: 12px 0 24px; }
.hero h1 { font-size: 2.4rem; margin-bottom: .2em; }
.hero p { font-size: 1.15rem; color: var(--text-muted); max-width: 46em; }
.hero__actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin: 20px 0 32px; }
.module-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 8px;
}
.module-card__num { font-size: 13px; font-weight: 800; color: var(--accent); letter-spacing: .06em; text-transform: uppercase; }
.module-card h3 { margin: 0; font-size: 1.15rem; }
.module-card p { font-size: 15px; color: var(--text-muted); margin: 0; }
.module-card ul { list-style: none; padding: 0; margin: 6px 0 0; font-size: 14.5px; display: grid; gap: 4px; }
.module-card li a { text-decoration: none; }
.module-card li.is-planned a { color: var(--text-muted); font-style: italic; }
.module-card li .tick { color: var(--ok); margin-left: 4px; }
.module-card__foot { margin-top: auto; display: flex; flex-wrap: wrap; gap: 6px; padding-top: 6px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } .hero h1 { font-size: 1.9rem; } }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.panel h2 { margin-top: 0; font-size: 1.15rem; }
.panel ul { padding-left: 1.2em; margin: 0; }

/* ---------- Planned-lesson stub ---------- */
.stub-banner {
  border: 1px dashed var(--border); border-radius: var(--radius); padding: 14px 18px; background: var(--surface-2);
  color: var(--text-muted); margin-bottom: 24px; font-size: 15px;
}

@media print {
  .topbar, .sidebar, .lesson-footer, .nav-toggle { display: none !important; }
  .layout { display: block; }
  .numeric details { display: block; }
}

/* ---------- Load-transfer car diagram ---------- */
.car-svg { width: 100%; max-width: 440px; display: block; margin: 0 auto; }
.car-svg .car-body { fill: var(--surface-2); stroke: var(--axis); stroke-width: 1.5; }
.car-svg .car-cockpit { fill: var(--surface); stroke: var(--axis); stroke-width: 1; }
.car-svg .car-tire { fill: var(--text-muted); opacity: .55; }
.car-svg .car-label { font-family: var(--font-sans); font-size: 13px; fill: var(--text-muted); }
.car-svg .car-value { font-family: var(--font-sans); font-size: 15px; font-weight: 700; fill: var(--text); font-variant-numeric: tabular-nums; }
.car-svg .load-ghost { fill: none; stroke: var(--axis); stroke-dasharray: 4 4; }
.car-svg .load-circle { fill: var(--text-muted); fill-opacity: .25; stroke: var(--text-muted); stroke-width: 2; transition: r .15s; }
.car-svg .load-circle.is-up { fill: var(--s2); stroke: var(--s2); }
.car-svg .load-circle.is-down { fill: var(--s1); stroke: var(--s1); }
.car-svg .car-cg { fill: var(--text); }
.car-svg .car-arrow { stroke: var(--s4); stroke-width: 3; }
.car-svg .car-arrowhead { fill: var(--s4); }

/* Let interactives break out of the reading column on wide screens. */
@media (min-width: 1280px) {
  .lesson .widget {
    width: min(1060px, calc(100vw - var(--sidebar-w) - 64px));
    position: relative; left: 50%; transform: translateX(-50%);
  }
  .widget__body { grid-template-columns: 260px minmax(0, 1fr); }
}

/* ---------- Hands-off top-view animation (Lesson 1.2) ---------- */
.anim-svg { width: 100%; display: block; background: var(--surface-2); border-radius: 8px; }
.anim-svg .anim-edge { stroke: var(--axis); stroke-width: 2; }
.anim-svg .anim-lane { stroke: var(--axis); stroke-width: 2; fill: none; opacity: .7; }
.anim-svg .anim-orig { stroke: var(--s2); stroke-width: 1.5; stroke-dasharray: 8 6; opacity: .8; }
.anim-svg .anim-post { stroke: var(--text-muted); stroke-width: 2; }
.anim-svg .anim-mark { font-family: var(--font-sans); font-size: 11px; fill: var(--text-muted); }
.anim-svg .anim-trail { stroke: var(--s1); stroke-width: 2; opacity: .55; }
.anim-svg .anim-body { fill: var(--s1); stroke: var(--surface); stroke-width: 1.5; }
.anim-svg .anim-glass { fill: var(--surface); opacity: .75; }
.anim-svg .anim-nose { fill: var(--surface); opacity: .9; }
.anim-svg .anim-wheel { fill: var(--text); }
.anim-svg .anim-ghost rect { fill: none; stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 4 3; }
.anim-svg .anim-vel { stroke: var(--s4); stroke-width: 3; }
.anim-svg .anim-arrowhead { fill: var(--s4); }
.anim-svg .anim-gust { stroke: var(--s5); stroke-width: 3; }
.anim-svg .anim-gusthead { fill: var(--s5); }
.anim-svg .anim-gust-label { font-family: var(--font-sans); font-size: 12px; font-weight: 700; fill: var(--s5); }
.anim-svg .anim-hud { font-family: var(--font-sans); font-size: 13px; fill: var(--text); font-variant-numeric: tabular-nums; }
.anim-svg .anim-big { font-family: var(--font-sans); font-size: 28px; font-weight: 800; fill: var(--bad); }
.anim-svg .anim-orig-arrow { stroke: var(--s2); stroke-width: 2; }
.anim-svg .anim-orighead { fill: var(--s2); }

/* ---------- Home: calculator help ---------- */
.calc-help { margin-top: 24px; }
.calc-demo { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 4px 0 20px; }
.calc-demo .numeric__label { display: block; }
.calc-example { font-family: var(--font-mono); font-size: 12.5px; }
.calc-tables h3 { margin: 12px 0 6px; font-size: 1rem; }
.calc-tables table.data { margin-top: 4px; font-size: 14.5px; }
.calc-tables td code, .calc-tips code { white-space: nowrap; }
.calc-tips li { margin-bottom: 6px; }

/* ---------- FBD builder (Lesson 0.1) ---------- */
.fbd-svg { width: 100%; max-width: 520px; display: block; margin: 0 auto; }
.fbd-svg .fbd-ground { stroke: var(--axis); stroke-width: 2; }
.fbd-svg .fbd-car { fill: var(--surface-2); stroke: var(--axis); stroke-width: 1.5; }
.fbd-svg .fbd-tire { fill: var(--text-muted); opacity: .6; }
.fbd-svg .fbd-cg { fill: var(--text); }
.fbd-svg .fbd-label { font-family: var(--font-sans); font-size: 13px; fill: var(--text-muted); }
.fbd-svg .fbd-flabel { font-family: var(--font-sans); font-size: 13px; font-weight: 700; }
.fbd-svg .fbd-arrow { stroke-width: 3.5; fill: none; }
.fbd-svg .fbd-head { stroke: none; }
.fbd-svg .f-sel { stroke: var(--s1); fill: var(--s1); }
.fbd-svg .f-ok { stroke: var(--ok); fill: var(--ok); }
.fbd-svg .f-bad { stroke: var(--bad); fill: var(--bad); }
.fbd-svg .f-missing { stroke: var(--warn); fill: var(--warn); opacity: .8; }
.fbd-svg .f-net { stroke: var(--s4); fill: var(--s4); }
.fbd-svg line.f-net { stroke-dasharray: 6 4; stroke-width: 2.5; }
.fbd-svg line.f-missing { stroke-dasharray: 5 4; }
.fbd-svg text.fbd-flabel { stroke: var(--surface); stroke-width: 3px; paint-order: stroke; stroke-dasharray: none; opacity: 1; }
.fbd-svg .fbd-head-f { fill: var(--s1); } .fbd-svg .fbd-head-ok { fill: var(--ok); }
.fbd-svg .fbd-head-bad { fill: var(--bad); } .fbd-svg .fbd-head-net { fill: var(--s4); }
.fbd-list { display: grid; gap: 6px; }
.fbd-item { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; font-size: 14px; line-height: 1.4; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; }
.fbd-item input { margin-top: 3px; accent-color: var(--accent); }
.fbd-why { grid-column: 2; font-size: 13px; color: var(--text-muted); }
.fbd-why:empty { display: none; }
.fbd-item.is-ok { border-color: var(--ok); background: var(--ok-soft); }
.fbd-item.is-bad { border-color: var(--bad); background: var(--bad-soft); }
.fbd-item.is-missing { border-color: var(--warn); background: var(--warn-soft); }

/* ---------- 3-D axes (Lesson 0.2) ---------- */
.a3-svg { width: 100%; display: block; background: var(--surface-2); border-radius: 8px; cursor: grab; touch-action: none; }
.a3-svg:active { cursor: grabbing; }
.a3-svg .a3-grid { stroke: var(--grid); stroke-width: 1; }
.a3-svg .a3-face { stroke: var(--surface); stroke-width: .8; stroke-linejoin: round; }
.a3-svg .a3-body { fill: var(--s1); }
.a3-svg .a3-pod { fill: var(--s1); }
.a3-svg .a3-cockpit { fill: var(--text); }
.a3-svg .a3-suit { fill: var(--s2); }
.a3-svg .a3-helmet { fill: var(--s5); }
.a3-svg .a3-hoop { fill: var(--axis); }
.a3-svg .a3-wing { fill: var(--text); }
.a3-svg .a3-arm { fill: var(--text-muted); }
.a3-svg .a3-wheel { fill: var(--text); }
.a3-svg .a3-tread { fill: var(--text); stroke: var(--text); }
.a3-svg .a3-hub { fill: var(--axis); stroke: var(--text); }
.a3-svg .a3-cg { fill: var(--text); }
.a3-svg .a3-axis { stroke-width: 3; }
.a3-svg .a3-x { stroke: var(--s2); } .a3-svg .a3-head-x, .a3-svg .a3-x-t { fill: var(--s2); }
.a3-svg .a3-y { stroke: var(--s3); } .a3-svg .a3-head-y, .a3-svg .a3-y-t { fill: var(--s3); }
.a3-svg .a3-z { stroke: var(--s5); } .a3-svg .a3-head-z, .a3-svg .a3-z-t { fill: var(--s5); }
.a3-svg .a3-label { font-family: var(--font-sans); font-size: 14px; font-weight: 700; paint-order: stroke; stroke: var(--surface-2); stroke-width: 3px; }
.a3-svg .a3-arc { fill: none; stroke-width: 1.8; opacity: .55; }
.a3-svg .a3-arc.is-active { stroke-width: 3; opacity: 1; }

/* ---------- Top-view angles (Lesson 0.2) ---------- */
.at-svg { width: 100%; max-width: 480px; display: block; margin: 0 auto; }
.at-svg .at-body { fill: var(--surface-2); stroke: var(--axis); stroke-width: 1.5; }
.at-svg .at-wheel { fill: var(--text); opacity: .8; }
.at-svg .at-cg { fill: var(--text); }
.at-svg .at-axis { stroke: var(--axis); stroke-width: 1.5; }
.at-svg .at-head-ax { fill: var(--axis); }
.at-svg .at-axis-label { font-family: var(--font-sans); font-size: 13px; font-weight: 700; fill: var(--text-muted); }
.at-svg .at-note { font-family: var(--font-sans); font-size: 12px; fill: var(--text-muted); }
.at-svg .at-heading { stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.at-svg .at-vel { stroke: var(--s4); stroke-width: 2.5; }
.at-svg .at-head-v { fill: var(--s4); }
.at-svg .at-force, .at-svg .at-yaw { stroke: var(--s5); stroke-width: 3; fill: none; }
.at-svg .at-head-f { fill: var(--s5); }
.at-svg .at-arc { fill: none; stroke-width: 2; }
.at-svg .at-angle { font-family: var(--font-sans); font-size: 13px; font-weight: 700; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.at-svg .at-beta { stroke: var(--s1); fill: var(--s1); }
.at-svg .at-delta { stroke: var(--s3); fill: var(--s3); }
.at-svg .at-alpha { stroke: var(--s2); fill: var(--s2); }
.at-svg .at-yawt { fill: var(--s5); stroke: var(--surface); }
.at-svg text.at-angle { stroke: var(--surface); }
.at-svg .at-leader { stroke: var(--grid); stroke-width: 1; stroke-dasharray: 2 3; }
.at-svg polygon.at-wedge { stroke: none; opacity: .28; }
.at-svg polyline.at-arc { fill: none; stroke-width: 3; }
.at-svg line.at-lead { stroke-width: 1; stroke-dasharray: 2 3; opacity: .75; }

/* ---------- Module 3 widgets ---------- */
.plot .area.bar-solid { opacity: .85; }
.brake-plot-row { display: grid; grid-template-columns: minmax(0, 1fr) 130px; gap: 12px; align-items: start; }
@media (max-width: 600px) { .brake-plot-row { grid-template-columns: minmax(0, 1fr); } .brake-car { max-width: 140px; margin: 0 auto; } }
.brake-car svg { width: 100%; display: block; }
.brake-car .bk-body { fill: var(--surface-2); stroke: var(--axis); stroke-width: 1.5; }
.brake-car .bk-wheel { fill: var(--text-muted); transition: fill .15s; }
.brake-car .bk-wheel.is-locked { fill: var(--bad); }
.brake-car .bk-label { font-family: var(--font-sans); font-size: 11.5px; fill: var(--text-muted); }
.plot .annot.bar-label { fill: #fff; font-size: 13px; }
.fbd-key { font-size: 13.5px; color: var(--text-muted); text-align: center; margin: 2px 0 8px; min-height: 1.3em; font-variant-numeric: tabular-nums; }
.fig-s4 { stroke: var(--s4); } .fig-s4-fill { fill: var(--s4); }
.fig-muted-fill { fill: var(--text-muted); }
.fig-dash { stroke-dasharray: 4 4; }
.fig-wheelc { fill: var(--text-muted); fill-opacity: .55; stroke: var(--axis); stroke-width: 1.5; }
.fig-dimlabel { font-style: italic; fill: var(--text-muted); }
.fig-s3 { stroke: var(--s3); } .fig-s3-fill { fill: var(--s3); }
.fig-step { fill: #fff; font-family: var(--font-sans); font-size: 12px; font-weight: 800; }
/* Keep formulas in tables on one line (KaTeX otherwise allows breaks after = and binary operators). */
table.data .katex { white-space: nowrap; }

/* Tire insets in the load-transfer explorer */
.car-svg.car-svg--wide { max-width: 640px; }
.car-svg .ti-frame { fill: var(--surface); stroke: var(--border); stroke-width: 1; }
.car-svg .ti-leader { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 3; }
.car-svg .ti-title { font-family: var(--font-sans); font-size: 12px; font-weight: 700; fill: var(--text); font-variant-numeric: tabular-nums; }
.car-svg .ti-used { font-family: var(--font-sans); font-size: 11px; fill: var(--text-muted); font-variant-numeric: tabular-nums; }
.car-svg .ti-used.is-near { fill: var(--warn); font-weight: 700; }
.car-svg .ti-used.is-sat { fill: var(--bad); font-weight: 700; }
.car-svg .ti-axis { stroke: var(--axis); stroke-width: 1; }
.car-svg .ti-axislab { font-family: var(--font-sans); font-size: 9.5px; fill: var(--text-muted); }
.car-svg .ti-static { stroke: var(--text-muted); stroke-width: 1.2; stroke-dasharray: 4 3; }
.car-svg .ti-curve { stroke: var(--text-muted); stroke-width: 2.2; }
.car-svg .ti-curve.is-up { stroke: var(--s2); }
.car-svg .ti-curve.is-down { stroke: var(--s1); }
.car-svg .ti-peak { stroke: var(--grid); stroke-width: 1; stroke-dasharray: 2 3; }
.car-svg .ti-op-line { stroke: var(--s4); stroke-width: 1; stroke-dasharray: 3 3; }
.car-svg .ti-op { fill: var(--s4); stroke: var(--surface); stroke-width: 1.5; }
.car-svg .ti-op.is-sat { fill: var(--bad); }
.car-svg .ti-limit { font-family: var(--font-sans); font-size: 12.5px; font-weight: 700; fill: var(--bad); }
.plot.is-dragging, .plot.is-dragging .handle { cursor: grabbing; }
.plot { -webkit-user-select: none; user-select: none; }
.widget__plots--2 > .span-all { grid-column: 1 / -1; width: min(100%, 560px); justify-self: center; }
/* Plots created with fixedText: text renders at a constant on-screen size (12px, labels 13px) */
.plot.plot--fixed-text text { font-size: calc(12px * var(--pt, 1)); }
.plot.plot--fixed-text .plot__label { font-size: calc(13px * var(--pt, 1)); }
.plot.plot--fixed-text .annot { font-size: calc(12px * var(--pt, 1)); }

/* Load-transfer component colors (Lesson 3.2): same as the explorer and diagrams */
table.data tr.lt-row { --lt: var(--text-muted); }
table.data tr.lt-unsprung { --lt: var(--s5); }
table.data tr.lt-geometric { --lt: var(--s2); }
table.data tr.lt-elastic { --lt: var(--s3); }
table.data tr.lt-row > td:first-child { border-left: 4px solid var(--lt); white-space: nowrap; }
table.data tr.lt-row > td:first-child strong { color: var(--lt); }
.lt-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--lt); margin-right: 7px; vertical-align: 0; }

/* ---------- Reference pages (formula sheet) ---------- */
.content--ref { max-width: 960px; }
.nav-module--ref-first { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 8px; }
.module-card--ref { border-style: dashed; background: var(--surface-2); }
.lead { font-size: 1.08rem; color: var(--text-muted); }
.formula-jump { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 8px; }
.chip--link { text-decoration: none; color: var(--link); }
.chip--link:hover { background: var(--surface); border-color: var(--link); }
.formula-print { margin-left: auto; }
.formula-module h3 { font-size: 1.1rem; margin: 1.6em 0 .2em; }
.formula-module h3 a { text-decoration: none; color: var(--text); }
.formula-module h3 a:hover { color: var(--link); }
.formula-lesson__num { color: var(--accent); font-variant-numeric: tabular-nums; margin-right: .5em; }
.formula-table { table-layout: fixed; }
.formula-table th:nth-child(1), .formula-table td:nth-child(1) { width: 24%; }
.formula-table th:nth-child(2), .formula-table td:nth-child(2) { width: 44%; }
.formula-table td:nth-child(2) { overflow-x: auto; overflow-y: hidden; }
.formula-table td:nth-child(3) { color: var(--text-muted); font-size: 14.5px; }
table.data.formula-table td { vertical-align: middle; }
.formula-table td:nth-child(2) { line-height: 2.5; }   /* room between stacked fractions */
table.data.formula-table tr.lt-row > td:first-child { white-space: normal; }
.symbol-table td:first-child { white-space: nowrap; width: 9.5em; }
.symbol-table td:last-child { color: var(--text-muted); font-size: 14.5px; white-space: nowrap; }
.symbol-table tr.group td { background: var(--surface-2); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); padding: 5px 10px; }
.formula-note { font-size: 14.5px; margin-top: -0.6em; }
.formula-pending { --c: var(--text-muted); --c-soft: var(--surface-2); margin-top: 2.4em; }
.formula-pending ul { margin: 0; }

/* On phones, stack each formula row: name, then formula, then the note. */
@media (max-width: 640px) {
  .formula-table thead { display: none; }
  .formula-table, .formula-table tbody, .formula-table tr, .formula-table td { display: block; width: auto !important; }
  .formula-table tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.data.formula-table td { border: 0; padding: 2px 10px; }
  .formula-table td:nth-child(1) { font-weight: 600; }
  table.data.formula-table td:nth-child(2) { padding: 4px 10px; line-height: 2.2; }
  table.data.formula-table tr.lt-row > td { border-left: 4px solid var(--lt); }
  .symbol-table td:last-child { white-space: normal; }
}

@media print {
  .formula-jump, .formula-pending { display: none !important; }
  .content--ref { max-width: none; }
  .formula-table tr, .symbol-table tr { break-inside: avoid; }
  .formula-module h2, .formula-module h3 { break-after: avoid; }
  .formula-module h3 a { color: inherit; }
}

/* Glossary */
.gloss-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 8px 0 6px; }
.gloss-filter {
  font: inherit; font-size: 15px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); width: min(100%, 340px);
}
.gloss-filter:focus { outline: 2px solid var(--link); outline-offset: 1px; }
.gloss-count { font-size: 14px; }
.gloss-letters { display: flex; flex-wrap: wrap; gap: 2px; margin: 4px 0 10px; font-weight: 700; font-size: 14px; }
.gloss-letters a, .gloss-letters span { display: inline-block; min-width: 1.7em; text-align: center; padding: 3px 0; border-radius: 5px; text-decoration: none; }
.gloss-letters a:hover { background: var(--surface-2); }
.gloss-letters .is-empty { color: var(--border); }
.gloss-letter { font-size: 1.3rem; color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 4px; margin: 1.4em 0 .4em; scroll-margin-top: calc(var(--topbar-h) + 12px); }
.gloss { margin: 0; padding: 10px 12px; border-radius: 8px; scroll-margin-top: calc(var(--topbar-h) + 12px); }
.gloss dt { font-weight: 700; }
.gloss dd { margin: 3px 0 0; color: var(--text); }
.gloss:target { background: var(--accent-soft); }
.gloss__lesson {
  display: inline-block; margin-left: 8px; font-size: 12.5px; font-weight: 600; text-decoration: none;
  padding: 1px 8px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.gloss__lesson:hover { border-color: var(--link); }
@media print {
  .gloss-tools, .gloss-letters { display: none !important; }
  .gloss { break-inside: avoid; padding: 4px 0; }
}

/* openengineering.ca: link back to the site (top of the sidebar) and license line */
.sidebar a.nav-site {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px 12px; margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted); font-size: 13.5px; font-weight: 600;
}
.sidebar a.nav-site:hover { color: var(--text); }
.nav-site__arrow { color: var(--accent); }
.site-license { margin-top: 48px; margin-bottom: 0; padding-top: 14px; border-top: 1px solid var(--border); font-size: 13.5px; color: var(--text-muted); }
.site-license a { color: inherit; }
@media print { .nav-site { display: none !important; } }
