:root {
  --page: #081011;
  --surface: #101a1b;
  --surface-2: #162324;
  --surface-3: #1b2b2c;
  --text: #edf7f4;
  --text-soft: #c4d3d0;
  --muted: #8fa4a0;
  --border: #2a3e3e;
  --border-soft: #1e3030;
  --mint: #5eead4;
  --coral: #ff8c7a;
  --amber: #f7c667;
  --blue: #79b8ff;
  --violet: #c4b5fd;
  --green: #4ade80;
  --danger: #ff7f96;
  --code: #050b0c;
  --rail: 292px;
  --radius: 8px;
  --shadow: 0 18px 50px -32px rgba(0, 0, 0, 0.85);
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --ground: var(--page);
  --ink: var(--text);
  --ink-soft: var(--text-soft);
  --faint: var(--muted);
  --accent: var(--mint);
  --accent-ink: #06100f;
}

:root[data-theme="light"] {
  --page: #f4f8f7;
  --surface: #ffffff;
  --surface-2: #edf4f2;
  --surface-3: #e3eeeb;
  --text: #10201f;
  --text-soft: #304542;
  --muted: #485e5a;
  --border: #c9d9d5;
  --border-soft: #dce7e4;
  --mint: #00695d;
  --coral: #b74336;
  --amber: #855900;
  --blue: #1769aa;
  --violet: #6d28d9;
  --green: #2f7d32;
  --danger: #bd314d;
  --code: #0b1415;
  --accent-ink: #ffffff;
  --shadow: 0 18px 50px -34px rgba(14, 39, 35, 0.35);
}

* { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  overflow-x: clip;
}
body {
  margin: 0;
  overflow-x: clip;
  background: var(--page);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--mint); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
/* Caption text contrasts more with the page than body text does, so colour alone cannot mark a link there (WCAG 1.4.1). */
figcaption a { text-decoration: underline; text-underline-offset: 3px; }
button, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 3px; }
::selection { background: var(--mint); color: #06100f; }

#progress {
  position: fixed;
  inset: 0 auto auto 0;
  z-index: 70;
  width: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--mint), var(--amber), var(--coral));
}

.course-layout {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  max-width: 1480px;
  margin: 0 auto;
}
.course-rail {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow: hidden;
  border-right: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--surface) 84%, var(--page));
}
.rail-head { padding: 24px 22px 16px; border-bottom: 1px solid var(--border-soft); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  flex: none;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 7px;
  border: 1px solid color-mix(in srgb, var(--mint) 55%, var(--border));
  border-radius: 8px;
  background: var(--surface-2);
}
.brand-mark span { border-radius: 2px; background: var(--mint); }
.brand-mark span:nth-child(2) { background: var(--coral); }
.brand-mark span:nth-child(3) { background: var(--amber); }
.brand-mark span:nth-child(4) { background: var(--blue); }
.brand-copy { font-size: 13px; font-weight: 750; line-height: 1.25; }
.brand-copy small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.kos-academy-link { display: inline-flex; margin-top: 14px; font-size: 12px; font-weight: 700; }
.rail-meter { padding: 14px 22px 7px; }
.rail-meter .bar { height: 4px; overflow: hidden; border-radius: 99px; background: var(--surface-3); }
.rail-meter .bar span { display: block; width: 0; height: 100%; background: var(--mint); }
.rail-meter .pct { margin-top: 6px; color: var(--muted); font-size: 11px; letter-spacing: 0.04em; }
.course-toc {
  height: calc(100vh - 150px);
  overflow-y: auto;
  padding: 5px 14px 32px;
  scrollbar-color: var(--border) transparent;
  scrollbar-width: thin;
}
.course-toc .toc-group {
  padding: 18px 10px 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}
.course-toc a {
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.35;
}
.course-toc a:hover, .course-toc a.active { background: var(--surface-2); color: var(--text); text-decoration: none; }
.course-toc .n { min-width: 18px; color: color-mix(in srgb, var(--muted) 70%, transparent); font-family: var(--mono); font-size: 10px; }
.course-toc { counter-reset: toc; }
.course-toc a { counter-increment: toc; }
.course-toc .n::before { content: counter(toc, decimal-leading-zero); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(12px);
}
.icon-btn {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--mint); color: var(--mint); }
.theme-fixed { position: fixed; top: 18px; right: 20px; z-index: 60; }
.theme-fixed .icon-btn { box-shadow: var(--shadow); }
.sun { display: none; }
:root[data-theme="light"] .sun { display: block; }
:root[data-theme="light"] .moon { display: none; }

main { min-width: 0; padding: 0 clamp(20px, 5vw, 72px); }
.course-wrap { max-width: 900px; margin: 0 auto; counter-reset: section; }
.hero { padding: 70px 0 46px; border-bottom: 1px solid var(--border); }
.eyebrow { color: var(--mint); font-size: 12px; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; }
.hero h1 {
  max-width: 16ch;
  margin: 18px 0 22px;
  color: var(--text);
  font-size: clamp(2.45rem, 6vw, 4.5rem);
  line-height: 1.02;
  letter-spacing: 0;
  text-wrap: balance;
}
.hero .dek { max-width: 68ch; margin: 0; color: var(--text-soft); font-size: 1.15rem; line-height: 1.65; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 27px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
}
.chip i { width: 6px; height: 6px; border-radius: 50%; background: var(--mint); }
.chip:nth-child(2) i { background: var(--amber); }
.chip:nth-child(3) i { background: var(--coral); }

section {
  counter-increment: section;
  padding: 54px 0;
  border-bottom: 1px solid var(--border-soft);
  scroll-margin-top: 24px;
}
.section-head { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 14px; align-items: start; }
.section-number {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--mint) 36%, var(--border));
  border-radius: 7px;
  background: color-mix(in srgb, var(--mint) 9%, var(--surface));
  color: var(--mint);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 800;
}
.section-number::before { content: counter(section, decimal-leading-zero); }
h2 { margin: 0; font-size: clamp(1.55rem, 3vw, 2rem); line-height: 1.2; letter-spacing: 0; text-wrap: balance; }
.section-sub { margin: 11px 0 26px 52px; color: var(--muted); font-size: 1rem; }
h3 { margin: 34px 0 12px; color: var(--text); font-size: 1.24rem; line-height: 1.3; }
h4 { margin: 0 0 9px; color: var(--mint); font-size: 0.98rem; }
p { margin: 0 0 17px; }
ul, ol { margin: 0 0 19px; padding-left: 24px; }
li { margin-bottom: 8px; }
li::marker { color: var(--mint); }
strong { color: var(--text); }
code { font-family: var(--mono); }
p code, li code, td code { padding: 2px 6px; border: 1px solid var(--border-soft); border-radius: 5px; background: var(--surface-2); color: var(--text); font-size: 0.86em; }

.lead { color: var(--text-soft); font-size: 1.08rem; line-height: 1.75; }
.definition {
  margin: 24px 0;
  padding: 20px 22px;
  border-left: 4px solid var(--mint);
  background: var(--surface);
  color: var(--text-soft);
}
.definition strong { display: block; margin-bottom: 7px; color: var(--mint); font-size: 12px; letter-spacing: 0.11em; text-transform: uppercase; }
.callout {
  margin: 24px 0;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.callout .label { margin-bottom: 8px; color: var(--mint); font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.callout.warning .label { color: var(--amber); }
.callout.danger .label { color: var(--danger); }
.callout.architect .label { color: var(--blue); }
.callout p:last-child { margin-bottom: 0; }

.grid-2, .grid-3 { display: grid; gap: 14px; margin: 22px 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card { padding: 19px 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.card p:last-child { margin-bottom: 0; }
.card h3 { margin: 0 0 9px; color: var(--mint); font-size: 0.98rem; line-height: inherit; }
.kos-glossary { display: grid; grid-template-columns: minmax(9.5rem, max-content) 1fr; gap: 10px 20px; margin: 0 0 24px; }
.kos-glossary dt { color: var(--text); font-weight: 750; }
.kos-glossary dd { margin: 0; color: var(--text-soft); }
@media (max-width: 640px) { .kos-glossary { grid-template-columns: 1fr; gap: 2px; } .kos-glossary dd { margin-bottom: 10px; } }
.kos-arithmetic { margin: 6px 0 26px; padding: 2px 0 2px 14px; border-left: 3px solid var(--border); }
.kos-arithmetic summary { color: var(--muted); font-size: 0.92rem; font-weight: 700; cursor: pointer; }
.kos-arithmetic[open] summary { margin-bottom: 12px; }
.card .kicker { color: var(--coral); font-family: var(--mono); font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }

.table-wrap {
  max-width: 100%;
  min-width: 0;
  margin: 22px 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--border-soft); text-align: left; vertical-align: top; }
thead th { background: var(--surface-2); color: var(--muted); font-size: 0.73rem; letter-spacing: 0.08em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }

pre, .code-block {
  max-width: 100%;
  min-width: 0;
  margin: 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code);
  color: #d9e7e3;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
}
pre { padding: 19px 21px; }
.block { position: relative; margin: 22px 0; }
.copy-btn {
  position: absolute;
  top: 9px;
  right: 9px;
  z-index: 2;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
}
.copy-btn:hover { border-color: var(--mint); color: var(--mint); }

/* the UA default is `figure { margin: 1em 40px }`. .architecture-figure has always
   overridden it, but the spine courses use a bare <figure>, so their diagrams were
   indented 40px each side and rendered 80px narrower than the column allows. */
figure { margin: 28px 0; }
.architecture-figure { margin: 28px 0; }
.architecture-figure figcaption { margin-top: 12px; color: var(--muted); font-size: 0.86rem; line-height: 1.55; }
.figure-frame {
  display: grid;
  min-height: 260px;
  place-items: center;
  overflow: hidden;
  padding: clamp(18px, 4vw, 36px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.figure-frame svg { display: block; width: 100%; max-width: 780px; height: auto; margin: 0 auto; }
.mobile-figure { display: none; }
.mobile-flow {
  display: grid;
  gap: 28px;
  margin: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  list-style: none;
}
.mobile-flow li {
  position: relative;
  margin: 0;
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
}
.mobile-flow li + li::before {
  content: "↓";
  position: absolute;
  top: -27px;
  left: 50%;
  color: var(--mint);
  font-size: 18px;
  font-weight: 800;
  transform: translateX(-50%);
}
.mobile-flow strong { display: block; color: var(--text); font-size: 0.94rem; }
.mobile-flow span { display: block; margin-top: 3px; color: var(--muted); font-size: 0.8rem; line-height: 1.45; }

.steps { counter-reset: step; list-style: none; padding: 0; }
.steps li { counter-increment: step; position: relative; min-height: 38px; padding-left: 48px; }
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--mint);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 800;
}
.checklist { list-style: none; padding: 0; }
.checklist li { position: relative; padding-left: 28px; }
.checklist li::before { content: "✓"; position: absolute; left: 0; color: var(--mint); font-weight: 800; }

.qa { margin: 20px 0; border-top: 1px solid var(--border); }
.qa details { padding: 17px 0; border-bottom: 1px solid var(--border); }
.qa summary { color: var(--text); font-weight: 750; cursor: pointer; }
.qa details p { margin: 12px 0 0; color: var(--text-soft); }
.reference-list { padding-left: 20px; }
.reference-list li { margin-bottom: 13px; }
.reference-list span { display: block; color: var(--muted); font-size: 0.88rem; }

.course-footer { padding: 38px 0 72px; color: var(--muted); font-size: 0.85rem; }
#totop {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 55;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
}
#totop.show { opacity: 1; pointer-events: auto; }
#scrim { display: none; }

@media screen and (max-width: 1000px) {
  .course-layout { grid-template-columns: minmax(0, 1fr); }
  .course-rail { position: fixed; inset: 0 auto 0 0; z-index: 60; width: 304px; transform: translateX(-102%); transition: transform 180ms ease; }
  .course-rail.open { transform: translateX(0); }
  .topbar { display: flex; }
  main section[id] { scroll-margin-top: 76px; }
  .theme-fixed { display: none; }
  #scrim { position: fixed; inset: 0; z-index: 58; display: block; background: rgba(0, 0, 0, 0.62); opacity: 0; pointer-events: none; transition: opacity 180ms ease; }
  #scrim.show { opacity: 1; pointer-events: auto; }
  .hero { padding-top: 42px; }
}

/* A 940-unit diagram squeezed into a 390px phone renders its smallest labels at
   2.8px. Hold the size it has on a desktop and let the figure pan sideways —
   the same treatment .kos-architecture already uses. */
@media screen and (max-width: 860px) {
  figure { overflow-x: auto; overscroll-behavior-x: contain;
           scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
  figure > svg { min-width: 800px; }
  /* the framed figures swap to their mobile flow below 680px, but between there
     and 860px they were squeezing labels to 5.4px */
  .architecture-figure .figure-frame { overflow-x: auto; overscroll-behavior-x: contain;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent; padding-inline: 14px; }
  .architecture-figure .figure-frame > svg { min-width: 760px; }
}

@media screen and (max-width: 680px) {
  body { font-size: 16px; }
  main { padding-inline: 18px; }
  .hero h1 { font-size: 2.5rem; }
  section { padding: 42px 0; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .section-sub { margin-left: 0; }
  .architecture-figure .figure-frame { display: none; }
  .architecture-figure .mobile-figure { display: block; }
  .architecture-figure.mobile-explained > svg { display: none; }
  .architecture-figure.evidence-photo .figure-frame { display: grid; min-height: 0; padding: 8px !important; }
  .architecture-figure.evidence-photo .mobile-figure { margin-top: 12px; }
  th, td { min-width: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; }
}

@media print {
  :root, :root[data-theme="light"], :root[data-theme="dark"] {
    --page: #fff; --surface: #fff; --surface-2: #f1f5f4; --surface-3: #e3eeeb;
    --text: #111; --text-soft: #252525;
    --muted: #555; --border: #bbb; --border-soft: #ddd; --mint: #006b5f; --code: #f4f4f4;
    /* accents are ink on paper, so they take the light-theme values, not the dark ones */
    --coral: #b74336; --amber: #855900; --blue: #1769aa;
    --violet: #6d28d9; --green: #2f7d32; --danger: #bd314d;
    --shadow: none;
  }
  .course-rail, .topbar, .theme-fixed, #progress, #totop, #scrim, .copy-btn { display: none !important; }
  .course-layout { display: block; }
  main { padding: 0; }
  .course-wrap { max-width: none; }
  section { padding: 22px 0; page-break-inside: auto; }
  .card, .callout, .definition, .architecture-figure, .table-wrap, pre { page-break-inside: avoid; }
  /* the spine courses use a bare <figure>, so .architecture-figure never matched
     them and their diagrams were free to split across a page break */
  figure, .table-wrap table { page-break-inside: avoid; break-inside: avoid; }
  figcaption { page-break-before: avoid; break-before: avoid; }
  .mobile-figure { display: none !important; }
  /* every layout breakpoint is scoped to `screen`, so nothing below should be
     reachable here. It is a cheap guard: a min-width that leaks into print has
     no scrollbar to recover it, it just slices the right edge off the paper. */
  figure, .figure-frame { overflow: visible !important; }
  /* on a 703px A4 text column the frame's 4vw padding cost 56px, shrinking every
     framed diagram to 645px and its smallest labels to 4.7pt */
  .figure-frame { padding: 6px !important; min-height: 0 !important; }
  figure > svg, .figure-frame > svg { min-width: 0 !important; max-width: 100% !important; }
  pre { color: #111; }
}
