/* Course typography, blue accent, and persistent navigation from the AS–AD site. */
:root {
  --bg: #f3f5f8;
  --surface: #fff;
  --surface2: #e9eff7;
  --ink: #1c2433;
  --muted: #515d70;
  --rule: #cbd4e0;
  --control: #7d8798;
  --accent: #1f5fa8;
  --danger: #a8261d;
  --success: #23704a;
  --serif: "Source Serif 4", Georgia, serif;
  --sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
  box-sizing: border-box;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161f;
    --surface: #19202c;
    --surface2: #222d3d;
    --ink: #e5e9f1;
    --muted: #aeb9ca;
    --rule: #3e4b5f;
    --control: #8492a6;
    --accent: #8cbcf4;
    --danger: #ff998e;
    --success: #83d3a3;
    color-scheme: dark;
  }
}
*, *::before, *::after { box-sizing: inherit; }
[hidden] { display: none !important; }
html { scroll-padding-top: 152px; }
body { margin: 0; color: var(--ink); background: var(--bg); font: 17px/1.62 var(--serif); }
a { color: var(--accent); text-underline-offset: .16em; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
h1, h2, h3, legend, button, select, label, .btn, .small { font-family: var(--sans); }
h1, h2, h3 { line-height: 1.18; }
h1 { font-size: clamp(2rem, 5vw, 3.05rem); letter-spacing: -.028em; margin: 0; }
h2 { margin: 1.5em 0 .5em; font-size: 1.3rem; }
h3 { font-size: 1.06rem; }
p { margin: 0 0 .95em; }
sub, sup { font-size: .72em; line-height: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.topnav { position: sticky; top: 0; z-index: 4; background: var(--surface); border-bottom: 1px solid var(--rule); font-family: var(--sans); }
.header-row, .lesson-nav { max-width: 1160px; margin-inline: auto; padding-inline: 20px; }
.header-row { display: flex; align-items: center; gap: 14px; min-height: 55px; }
.brand { margin-right: auto; color: var(--ink); text-decoration: none; font-weight: 700; font-size: .98rem; }
.home-link { flex: none; color: var(--ink); text-decoration: none; font-size: .88rem; font-weight: 700; border: 1px solid var(--rule); padding: 6px 10px; border-radius: 6px; }
.home-link:hover { background: var(--surface2); }
.lesson-nav { overflow-x: auto; scrollbar-width: thin; }
.lesson-nav ol { display: flex; gap: 4px; list-style: none; margin: 0; padding: 4px 0 7px; }
.lesson-nav a { display: block; padding: 4px 10px; border-radius: 5px; white-space: nowrap; text-decoration: none; color: var(--muted); font-size: .88rem; }
.lesson-nav a:hover, .lesson-nav [aria-current] { background: var(--surface2); color: var(--ink); }
.lesson-nav [aria-current] { font-weight: 700; }
.attempted { color: var(--success); font-size: .78rem; }
.skip-link { position: fixed; top: 8px; left: 16px; z-index: 8; padding: 8px 14px; background: var(--surface); transform: translateY(-160%); }
.skip-link:focus { transform: none; }

main { max-width: 1160px; margin-inline: auto; padding: 26px 20px 58px; }
#lesson-heading { width: fit-content; }
.unit-head { border-top: 2px solid var(--ink); padding-top: 22px; margin: 0 0 14px; }
.prose { max-width: 69ch; }
.lede { font-size: 1.22rem; }
.small { font-size: .89rem; color: var(--muted); }
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); gap: 30px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 17px; }
.panel > h2:first-child { margin-top: 0; }
.preview p { margin: .7em 0 .2em; }
.equation, .math {
  margin: 13px 0 16px;
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  background: var(--surface2);
  border-radius: 0 6px 6px 0;
}
.eq-line { font-size: 1.2rem; line-height: 1.68; overflow-wrap: anywhere; }
.math-product { white-space: nowrap; }
.fraction { display: inline-flex; flex-direction: column; max-width: 100%; text-align: center; vertical-align: middle; }
.fraction > span:first-child { border-bottom: 1px solid; padding-inline: 4px; }
details { border: 1px solid var(--rule); background: var(--surface); border-radius: 7px; margin: 8px 0; max-width: 69ch; }
summary { font: 650 .95rem/1.4 var(--sans); cursor: pointer; padding: 10px 12px; }
.reveal-body { padding: 8px 12px 4px; border-top: 1px solid var(--rule); }
.calibration, .calculation { padding-left: 1.35rem; }
.calibration li, .calculation li { margin: .5em 0; }
.btnrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
button, .btn {
  display: inline-block; min-height: 39px; padding: 8px 11px; border: 1px solid var(--control); border-radius: 6px;
  color: var(--ink); background: var(--surface); font-size: .89rem; line-height: 1.4; text-decoration: none; cursor: pointer;
}
button:hover, .btn:hover { border-color: var(--ink); }
.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); font-weight: 650; }
button[aria-disabled="true"], button:disabled { opacity: .68; cursor: default; }
button[aria-pressed="true"] { border-color: var(--accent); background: var(--surface2); font-weight: 700; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; max-width: 69ch; border-top: 1px solid var(--rule); margin-top: 24px; padding-top: 16px; }

.quiz { min-inline-size: 0; max-width: 69ch; margin: 24px 0 18px; border: 1px solid var(--control); border-radius: 9px; padding: 14px 16px 9px; background: var(--surface); }
.quiz legend { font-size: .95rem; padding: 0 6px; font-weight: 700; }
.field { display: grid; gap: 5px; margin-bottom: 12px; }
.field label { font-size: .9rem; font-weight: 650; }
textarea, input, select {
  color: var(--ink); background: var(--surface); border: 1px solid var(--control); border-radius: 5px;
  width: 100%; min-width: 0; padding: 8px 9px; font: 1rem/1.4 var(--sans);
}
textarea { resize: vertical; }
select { max-width: 21rem; }
.feedback, .help { font: .91rem/1.5 var(--sans); margin: 9px 0; }
.help { background: var(--surface2); padding: 8px 10px; border-radius: 6px; }

.baseline-panel { margin-top: 22px; }
.path-controls { display: flex; flex-wrap: wrap; gap: 10px 20px; margin-bottom: 12px; }
#period-readout { font-family: var(--sans); font-weight: 650; }
.plots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.plot { margin: 0; border: 1px solid var(--rule); border-radius: 6px; padding: 8px; min-width: 0; }
.plot figcaption { font: .91rem/1.3 var(--sans); }
.plot figcaption span { display: block; color: var(--muted); margin-top: 2px; font-size: .8rem; }
.plot svg { display: block; width: 100%; }
.plot text { fill: var(--muted); font: 12px var(--sans); }
.grid-line { stroke: var(--rule); }
.period-line { stroke: var(--control); stroke-dasharray: 4 3; }
.data-line { stroke: var(--accent); stroke-width: 2.6; fill: none; }
.data-point { fill: var(--accent); }
.path-tables { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.data { border-collapse: collapse; width: 100%; font: .86rem/1.32 var(--sans); font-variant-numeric: tabular-nums; margin-bottom: 12px; }
.data caption { text-align: left; font-weight: 700; padding: 4px 0 7px; }
.data th, .data td { padding: 6px 7px; text-align: left; border-bottom: 1px solid var(--rule); }
.data thead th { color: var(--muted); vertical-align: bottom; }
.data .selected { background: var(--surface2); }

dialog { width: min(760px, calc(100vw - 20px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink); border: 1px solid var(--control); border-radius: 9px; padding: 0; }
dialog::backdrop { background: rgb(16 24 38 / .58); }
.dialog-head { display: flex; justify-content: space-between; gap: 8px; position: sticky; top: 0; align-items: center; background: var(--surface); border-bottom: 1px solid var(--rule); padding: 8px 14px; }
.dialog-head h2 { margin: 0; font-size: 1.13rem; }
.notation-body { padding: 12px 14px; }
.notation-table th:first-child { white-space: nowrap; }
.notation-table td, .notation-table th { vertical-align: top; }
@media (max-width: 820px) {
  .overview-grid, .path-tables { grid-template-columns: minmax(0, 1fr); gap: 12px; }
}
@media (max-width: 620px) {
  .header-row, .lesson-nav { padding-inline: 12px; }
  .header-row { gap: 8px; }
  main { padding: 18px 12px 44px; }
  .unit-head { padding-top: 14px; }
  .plots { grid-template-columns: minmax(0, 1fr); }
  .plot svg { max-width: 350px; margin: auto; }
  .panel, .quiz { padding-inline: 10px; }
  .data { font-size: .77rem; }
  .data th, .data td { padding-inline: 4px; }
  .notation-table td { overflow-wrap: anywhere; }
  .pager-detail { display: none; }
  .eq-line { font-size: 1.1rem; }
}

/* Draft state and review. */
.draft-bar {
  max-width: 1160px; margin: 0 auto; padding: 3px 20px 6px;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 1px 14px;
  color: var(--muted); font-size: .79rem;
}
.draft-bar [data-status="saved"] { color: var(--success); }
.draft-bar :is([data-status="unavailable"], [data-status="archive"], [data-status="conflict"]) { color: var(--danger); font-weight: 650; }
#manage-draft { padding: 0; border: 0; min-height: 0; background: none; color: var(--accent); text-decoration: underline; font-size: inherit; }
.review { max-width: 74ch; }
.identity-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.review ul { margin: 0 0 16px; padding-left: 1.3rem; }
#completion, #download-feedback, #draft-dialog-status { font: .93rem/1.5 var(--sans); margin-top: 10px; }
.markdown-copy { display: block; margin-top: 10px; font: .86rem/1.5 ui-monospace, monospace; overflow-wrap: anywhere; }
.reset-row { border-top: 1px solid var(--rule); margin-top: 17px; padding-top: 12px; }
.dialog-body { padding: 12px 14px 16px; }
@media (max-width: 620px) {
  .draft-bar { padding-inline: 12px; }
  .identity-fields { grid-template-columns: minmax(0, 1fr); gap: 0; }
}
