/* Fundamentals of Mathematics: page shell, typography and text components.
   Figure components (plots, controls, legends, readouts) are in figures.css.

   Colour tokens. The canvas code reads --ink, --muted, --faint, --space, --space-2,
   --line, --line-bright, the six data colours and --chapter/--figure-accent, so
   these names must not change. Light ("paper") is the default; dark applies on
   screen only when html[data-theme="dark"], and never while printing. */

:root {
  --space: #FBF9F4;            /* page background */
  --space-2: #FBF9F4;          /* surfaces: cards, figure panels (same cream as the page) */
  --space-3: #F4F0E8;          /* sunken surface */
  --ink: #1B1B1E;
  --muted: #55555C;
  --faint: #6B6B70;
  --line: #E4DED3;
  --line-bright: #CFC7B9;
  --accent: #A8323E;           /* short heading bars and small markers (muted red) */
  --accent-text: #9A2B36;      /* links and labels */
  --control: #3E5C84;          /* sliders, progress, active tabs, primary button (muted ink blue) */
  --control-hover: #2F4868;
  --on-accent: #FFFFFF;
  --highlight: var(--accent-text);
  --highlight-wash: #F8F2E6;   /* formula wash (slide cream) */

  /* Data colours. In prose: orange, teal, red, blue, purple, green. */
  --gold: #B86A00;
  --aqua: #0E7C7B;
  --coral: #C8102E;
  --blue: #287DA8;
  --violet: #8255B0;
  --green: #398345;

  --chapter: var(--accent);
  --chapter-rgb: 168, 50, 62;
  --figure-accent: var(--gold); /* set per chapter by app.js */

  --serif: "Source Serif 4", "Source Serif Pro", Georgia, Cambria, "Times New Roman", serif;
  --sans: Inter, "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
  --max: 58rem;                /* one column for every section: text, figures, definitions, checkpoints */
  --gutter: clamp(16px, 4vw, 40px);
  --measure: 100%;             /* text fills the column, so all sections share both edges */
  --radius: 6px;
  --header-h: 56px;
  --figure-sticky-top: calc(var(--header-h) + 8px);
  color-scheme: light;
}

@media screen {
  html[data-theme="dark"]:not(.is-printing) {
    --space: #14161B;
    --space-2: #1B1E24;
    --space-3: #22252C;
    --ink: #ECEAE4;
    --muted: #A9A9B1;
    --faint: #8A8A93;
    --line: #30333B;
    --line-bright: #454953;
    --accent: #D9737D;
    --accent-text: #E58A93;
    --control: #93B1D8;
    --control-hover: #B5CBE8;
    --on-accent: #14161B;
    --highlight-wash: #1F2128;
    --gold: #F2A93B;
    --aqua: #4FC2BE;
    --coral: #FF6F7D;
    --blue: #6CB4E4;
    --violet: #B794E6;
    --green: #6FCF7F;
    --chapter-rgb: 217, 115, 125;
    color-scheme: dark;
  }
}

/* Base ---------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--space); scroll-behavior: smooth; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--space);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.6;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p, ol, ul, figure, figcaption { margin: 0; }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.25; letter-spacing: 0; color: var(--ink); }
h1 { font-size: clamp(2.1rem, 1.7rem + 1.4vw, 2.6rem); line-height: 1.15; }
h2 { font-size: clamp(1.55rem, 1.4rem + .6vw, 1.8rem); }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.0625rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button { margin: 0; padding: 0; background: none; border: 0; cursor: pointer; }
img, svg, canvas { display: block; max-width: 100%; }
a { color: var(--accent-text); text-decoration-thickness: 1px; text-underline-offset: .18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--control); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
/* Headings and sections receive focus only programmatically (after navigation). */
[tabindex="-1"]:focus { outline: none; }
::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
noscript { position: fixed; right: 16px; bottom: 16px; z-index: 100; padding: 12px 16px; color: var(--on-accent); background: var(--accent); font-family: var(--sans); font-size: .9375rem; }

/* A short red bar above chapter titles and section headings, as on the slides. */
.section-title::before,
.chapter-label::before,
.home-head h1::before,
.chapter-opening > h2:first-child::before {
  display: block;
  width: 36px;
  height: 4px;
  margin-bottom: 14px;
  content: "";
  background: var(--accent);
}

/* Page blocks share one content width, aligned with the header. */
.home-view,
.chapter-hero,
.lesson-navigation-inner,
.chapter-opening,
.lab-section,
.explorer-section,
.concept-section,
.finance-application,
.checkpoint-section,
.video-section,
.chapter-footer,
.site-footer {
  width: min(calc(100% - 2 * var(--gutter)), var(--max));
  margin-inline: auto;
}

/* Buttons ------------------------------------------------------------------- */

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  color: var(--on-accent);
  background: var(--control);
  border-radius: 4px;
  font: 600 .9375rem/1.2 var(--sans);
  transition: background-color 150ms ease;
}
.primary-button:hover { background: var(--control-hover); }
.text-button {
  min-height: 44px;
  color: var(--accent-text);
  font: .875rem/1.4 var(--sans);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .2em;
}
.text-button:hover { text-decoration-thickness: 2px; }

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 10px 16px;
  color: var(--space);
  background: var(--ink);
  font: .9375rem var(--sans);
  transform: translateY(-160%);
}
.skip-link:focus { transform: none; }

/* Header -------------------------------------------------------------------- */

.site-header {
  position: fixed;
  inset: 0 0 auto;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--header-h);
  padding-inline: max(var(--gutter), calc((100% - var(--max)) / 2));
  background: var(--space);
  border-bottom: 1px solid var(--line);
}
/* Scrolling slides the in-chapter bar over the header; both share one height. */
.site-header.is-covered { visibility: hidden; }
.brand {
  min-width: 0;
  padding: 4px 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.15;
  text-align: left;
}
.brand:hover { color: var(--accent-text); }
.chapter-nav { display: flex; align-self: stretch; margin-left: auto; }
.chapter-nav button {
  position: relative;
  min-width: 36px;
  padding: 0 8px;
  color: var(--muted);
  font: 500 .9375rem/1 var(--sans);
  font-variant-numeric: tabular-nums;
  transition: color 150ms ease;
}
.chapter-nav button:hover { color: var(--ink); }
.chapter-nav button.is-active { color: var(--ink); font-weight: 600; }
.chapter-nav button.is-active::after {
  position: absolute;
  right: 9px;
  bottom: 12px;
  left: 9px;
  height: 2px;
  content: "";
  background: var(--control);
}
.header-actions { display: flex; align-items: center; gap: 8px; margin-left: 12px; }
.theme-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--muted);
  border: 1px solid var(--line-bright);
  border-radius: 4px;
  transition: color 150ms ease, border-color 150ms ease;
}
.theme-button:hover { color: var(--ink); border-color: var(--ink); }
.theme-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.theme-button .theme-sun { display: none; }
[data-theme="dark"] .theme-button .theme-sun { display: block; }
[data-theme="dark"] .theme-button .theme-moon { display: none; }
.map-button {
  height: 36px;
  padding: 0 12px;
  color: var(--ink);
  border: 1px solid var(--line-bright);
  border-radius: 4px;
  font: 500 .875rem/1 var(--sans);
  white-space: nowrap;
  transition: border-color 150ms ease;
}
.map-button:hover { border-color: var(--ink); }

@media (max-width: 679px) {
  .chapter-nav { display: none; }
  .header-actions { margin-left: auto; }
  .brand { font-size: 1rem; }
  /* In a chapter the bar below has its own Contents button. */
  body:has(#chapter-view:not([hidden])) .site-header .map-button { display: none; }
}

/* Home: table of contents ---------------------------------------------------- */

.home-view { padding: calc(var(--header-h) + 56px) 0 72px; }
.home-lede { max-width: var(--measure); margin-top: 16px; color: var(--muted); font-size: 1.25rem; line-height: 1.5; }
.home-actions { margin-top: 28px; }
.home-contents { margin-top: 64px; }
.course-map-note { max-width: var(--measure); margin-top: 8px; color: var(--muted); font: .9375rem/1.5 var(--sans); }
.journey-grid { margin: 24px 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line-bright); }
.journey-card {
  position: relative;
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr) 15rem;
  gap: 6px 24px;
  padding: 22px 0 24px;
  border-bottom: 1px solid var(--line);
}
.journey-number { color: var(--accent-text); font: 600 1.375rem/1.3 var(--serif); font-variant-numeric: lining-nums; }
.journey-copy { min-width: 0; }
.journey-copy h3 { font-size: 1.375rem; line-height: 1.3; }
.journey-copy h3 button { color: var(--ink); font-weight: 600; text-align: left; transition: color 150ms ease; }
/* The title button's hit area covers the whole entry. */
.journey-copy h3 button::after { position: absolute; inset: 0; content: ""; }
.journey-card:hover h3 button { color: var(--accent-text); }
.journey-copy h3 button:focus-visible { outline: none; }
.journey-card:has(h3 button:focus-visible) { outline: 2px solid var(--control); outline-offset: 4px; }
.journey-summary { max-width: var(--measure); margin-top: 6px; }
.journey-topics { max-width: var(--measure); margin-top: 8px; color: var(--muted); font: .875rem/1.55 var(--sans); }
.journey-topics span { color: var(--ink); font-weight: 600; }
.journey-meta { display: grid; align-content: start; gap: 6px; padding-top: 6px; color: var(--muted); font: .875rem/1.45 var(--sans); }
.journey-meta progress, .dialog-card progress {
  width: 100%;
  height: 4px;
  margin-top: 4px;
  overflow: hidden;
  appearance: none;
  background: var(--line);
  border: 0;
  border-radius: 2px;
  accent-color: var(--control);
}
.journey-meta progress::-webkit-progress-bar { background: var(--line); }
.journey-meta progress::-webkit-progress-value { background: var(--control); }
.journey-meta progress::-moz-progress-bar { background: var(--control); }
.home-usage { max-width: var(--measure); margin-top: 64px; }
.home-usage p { margin-top: 12px; }
.home-resources { margin-top: 64px; }
.home-resources > p { max-width: var(--measure); margin-top: 12px; }
.video-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px; margin-top: 28px; }
.video-card { min-width: 0; }
.video-frame { aspect-ratio: 16 / 9; overflow: hidden; background: var(--space-2); border: 1px solid var(--line); border-radius: var(--radius); }
.video-frame iframe { display: block; width: 100%; height: 100%; border: 0; }
/* A thumbnail stands in for the player until it is pressed (see app.js). The 4:3
   thumbnail is cropped to 16:9, which removes YouTube's letterbox bars. */
.video-facade { position: relative; display: block; width: 100%; height: 100%; overflow: hidden; color: #fff; background: #111; text-decoration: none; }
.video-facade img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform 200ms ease, opacity 200ms ease; }
.video-facade::after { position: absolute; inset: auto 0 0; height: 45%; content: ""; background: linear-gradient(transparent, rgba(0, 0, 0, .72)); pointer-events: none; }
.video-play { position: absolute; top: 50%; left: 50%; z-index: 1; width: 68px; height: 48px; transform: translate(-50%, -50%); background: rgba(27, 27, 30, .82); border-radius: 12px; transition: background 150ms ease; }
.video-play::before { position: absolute; top: 50%; left: 50%; content: ""; transform: translate(-35%, -50%); border-style: solid; border-width: 10px 0 10px 17px; border-color: transparent transparent transparent #fff; }
.video-title { position: absolute; right: 14px; bottom: 10px; left: 14px; z-index: 1; overflow: hidden; font: 600 .875rem/1.35 var(--sans); text-overflow: ellipsis; white-space: nowrap; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); }
.video-facade:hover .video-play, .video-facade:focus-visible .video-play { background: #E2001A; }
.video-facade:hover img { transform: scale(1.02); }
.video-facade:focus-visible { outline: 3px solid var(--control); outline-offset: -3px; }
.video-section { padding: 48px 0; }
.video-section-intro { max-width: var(--measure); margin-top: 12px; }
.video-section .video-grid { margin-top: 24px; }
.video-card h3 { margin-top: 16px; font-size: 1.25rem; line-height: 1.3; }
.video-card p { margin-top: 8px; }
.video-card .video-source { margin-top: 4px; color: var(--muted); font: .9375rem/1.45 var(--sans); }
.video-picks { color: var(--muted); font: .875rem/1.55 var(--sans); }
.video-link { font: 600 .9375rem/1.45 var(--sans); }

@media (max-width: 860px) {
  .journey-card { grid-template-columns: 2rem minmax(0, 1fr); }
  .journey-meta { grid-column: 2; max-width: 20rem; }
  .video-grid { grid-template-columns: minmax(0, 1fr); max-width: var(--measure); }
}
@media (max-width: 520px) {
  .home-view { padding-top: calc(var(--header-h) + 36px); }
  .home-lede { font-size: 1.125rem; }
  .journey-copy h3 { font-size: 1.25rem; }
}

/* Chapter header and in-chapter navigation ---------------------------------- */

.chapter-hero { padding: calc(var(--header-h) + 48px) 0 36px; }
.chapter-label { color: var(--accent-text); font: 600 .9375rem/1.3 var(--sans); }
.chapter-hero h1 { max-width: 30ch; margin-top: 8px; }
.chapter-summary { max-width: var(--measure); margin-top: 14px; color: var(--muted); font-size: 1.25rem; line-height: 1.5; }

.lesson-navigation {
  position: sticky;
  top: 0;
  z-index: 55;
  display: flex;
  flex-direction: column;
  height: var(--header-h);
  background: var(--space);
  border-block: 1px solid var(--line);
}
.lesson-navigation-inner { display: flex; flex: 1; align-items: center; gap: 12px; min-height: 0; }
.lesson-links { display: flex; align-self: stretch; }
.lesson-links a {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 8px;
  color: var(--muted);
  font: .875rem/1.2 var(--sans);
  text-decoration: none;
  white-space: nowrap;
  transition: color 150ms ease;
}
.lesson-links a:first-child { padding-left: 0; }
.lesson-links a:hover { color: var(--ink); }
.lesson-links a[aria-current] { color: var(--ink); font-weight: 500; }
.lesson-links a[aria-current]::after { position: absolute; right: 8px; bottom: 8px; left: 8px; height: 2px; content: ""; background: var(--control); }
.lesson-links a:first-child[aria-current]::after { left: 0; }
.lesson-jump-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.lesson-jump {
  width: 180px;
  min-width: 0;
  height: 36px;
  margin-left: auto;
  padding: 0 8px;
  color: var(--ink);
  background: var(--space-2);
  border: 1px solid var(--line-bright);
  border-radius: 4px;
  font: .8125rem var(--sans);
  text-overflow: ellipsis;
  flex: none;
}
.reading-label { min-width: 58px; color: var(--muted); font: .8125rem var(--sans); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.lesson-map-button { flex: none; }
.reading-track { height: 2px; }
.reading-track span { display: block; width: 0; height: 100%; background: var(--control); }
#chapter-view section[id], #chapter-view article[id] { scroll-margin-top: calc(var(--header-h) + 20px); }

@media (max-width: 1099px) { .reading-label { display: none; } }
@media (max-width: 899px) {
  .lesson-links { display: none; }
  .lesson-jump { flex: 1; width: auto; margin-left: 0; }
}
/* Set by fitLessonNavigation in app.js when the bar would overflow. */
.lesson-navigation.hide-reading .reading-label { display: none; }
.lesson-navigation.is-compact .lesson-links { display: none; }
.lesson-navigation.is-compact .lesson-jump { flex: 1; width: auto; max-width: 28rem; margin-left: 0; }
.lesson-navigation.is-compact .lesson-map-button { margin-left: auto; }

/* Chapter sections ----------------------------------------------------------- */

.chapter-opening { padding: 24px 0 40px; }
.lab-section, .explorer-section, .concept-section, .finance-application, .checkpoint-section { padding: 48px 0; }
.lab-heading, .explorer-heading, .concept-heading, .checkpoint-copy { max-width: var(--measure); margin-bottom: 28px; }
.lab-heading > p, .explorer-heading > p { margin-top: 12px; color: var(--muted); }

/* Running prose fills the same column as the figures, definitions and checkpoints. */
.lesson-prose > :is(p, ul, ol, h2, h3, h4, details, blockquote, .worked-step) { max-width: var(--measure); }
.lesson-prose > * + * { margin-top: 1em; }
.lesson-prose > h2 { margin-bottom: .25em; }
.lesson-prose > h3 { margin-top: 1.75em; }
.lesson-prose > h2 + *, .lesson-prose > h3 + * { margin-top: .5em; }
.lesson-prose :is(ul, ol) { padding-left: 1.4em; }
.lesson-prose li + li { margin-top: .4em; }
.lesson-prose strong { font-weight: 600; }
.lesson-prose details { padding: 14px 18px; background: var(--highlight-wash); border-radius: 4px; }
.lesson-prose summary { color: var(--ink); font: 600 .9375rem/1.4 var(--sans); cursor: pointer; }
.lesson-prose details[open] summary { margin-bottom: 8px; }
.lesson-prose details > p + p { margin-top: .75em; }
.lesson-prose > .formula { max-width: var(--measure); }
.worked-step { padding: 2px 0 2px 18px; border-left: 2px solid var(--line-bright); }
.application-figure { margin-block: 32px; }

.table-scroll { max-width: 100%; overflow-x: auto; }
.cash-flow-table { width: 100%; max-width: var(--measure); border-collapse: collapse; font-size: 1rem; font-variant-numeric: tabular-nums; }
.cash-flow-table caption { padding-bottom: 8px; color: var(--muted); font: .875rem/1.5 var(--sans); text-align: left; }
.cash-flow-table th, .cash-flow-table td { padding: 8px 12px 8px 0; text-align: left; border-bottom: 1px solid var(--line); }
.cash-flow-table thead th { color: var(--ink); font: 600 .875rem/1.4 var(--sans); border-top: 1px solid var(--line-bright); border-bottom-color: var(--line-bright); }
.cash-flow-table tbody tr:last-child > * { border-bottom-color: var(--line-bright); }

/* Display formulas: centred on a cream wash, no side bar. */
.formula {
  display: block;
  min-width: 0;
  max-width: 100%;
  padding: 14px 18px;
  overflow-x: auto;
  color: var(--ink);
  background: var(--highlight-wash);
  border-radius: 4px;
  text-align: center;
}
/* Several rows form one left-aligned block, centred as a whole. */
.formula[data-typeset="true"] { display: grid; grid-template-columns: minmax(0, max-content); justify-content: center; }
.formula .katex-display { margin: 0; text-align: left; }
.formula .katex-display > .katex { text-align: left; }
.formula .katex { font-size: 1.12rem; }
.math-line { display: block; min-width: 0; max-width: 100%; }
.math-line + .math-line { margin-top: 6px; }
.katex-display > .katex { white-space: normal; }
.katex-display .base { margin-block: 3px; }
.katex { font-size: 1.06em; text-rendering: auto; }
.math-fallback { font-family: "Cambria Math", "STIX Two Math", var(--serif); }

/* Definitions and results ---------------------------------------------------- */

.concept-list { max-width: var(--measure); border-top: 1px solid var(--line-bright); }
.concept-card { min-width: 0; padding: 26px 0 30px; border-bottom: 1px solid var(--line); }
.concept-card h3 { font-size: 1.1875rem; font-weight: 400; line-height: 1.4; }
.concept-label { margin-right: .3em; color: var(--accent-text); font-weight: 600; }
.concept-body { min-width: 0; }
.concept-body > p, .concept-body > .concept-insight { margin-top: 10px; }
.concept-insight > p + p, .concept-insight > .formula + p { margin-top: 16px; }
.concept-insight > .formula { margin-block: 16px; }
.concept-body > p .katex-display { overflow-x: auto; overflow-y: hidden; }
.concept-body > .formula, .concept-body > .rules-table-wrap { margin-top: 18px; }
.concept-body > .formula + p, .concept-body > .rules-table-wrap + p { margin-top: 16px; }
.concept-insight { color: var(--muted); }
.formula-connection { color: var(--muted); font-size: 1rem; font-style: italic; }
/* Wide screens: the label and title in a left column and the statement beside them. */
@media screen and (min-width: 900px) {
  .concept-card { display: grid; grid-template-columns: 13rem minmax(0, 1fr); column-gap: 40px; }
  .concept-card h3 { align-self: start; }
  .concept-label { display: block; margin-right: 0; }
  .concept-body > :first-child { margin-top: 0; }
}
/* Proofs, recipes, examples and remarks that follow a concept (the `extras` field). */
.concept-extra { margin-top: 18px; }
.concept-extra > * + * { margin-top: .6em; }
.concept-extra :is(ul, ol) { padding-left: 1.4em; }
.concept-extra li + li { margin-top: .4em; }
.concept-extra strong { font-weight: 600; }
.concept-extra { padding: 14px 18px; background: var(--highlight-wash); border-radius: 4px; }
.concept-extra + .concept-extra { margin-top: 10px; }
.concept-extra > summary { color: var(--ink); font: 600 .9375rem/1.4 var(--sans); cursor: pointer; }
.concept-extra[open] > summary { margin-bottom: 8px; }

/* Textbook tables: horizontal rules only. */
.rules-table-wrap { min-width: 0; overflow-x: auto; }
.rules-table { width: 100%; border-collapse: collapse; font-size: 1rem; line-height: 1.5; }
.rules-table th, .rules-table td { padding: 10px 16px 10px 0; text-align: left; vertical-align: top; }
.rules-table th:last-child, .rules-table td:last-child { padding-right: 0; }
.rules-table thead th { color: var(--ink); font: 600 .875rem/1.4 var(--sans); border-top: 1px solid var(--line-bright); border-bottom: 1px solid var(--line-bright); }
.rules-table tbody > tr > * { border-bottom: 1px solid var(--line); }
.rules-table tbody > tr:last-child > * { border-bottom-color: var(--line-bright); }
.rules-table tbody th { font-weight: 600; }
.rules-table td:nth-child(3) { color: var(--muted); }
/* Formulas stay on one line; words in every column wrap, so no column crowds the others. */
@media (min-width: 700px) {
  .rules-table td:nth-child(2) .katex { white-space: nowrap; }
}
.rules-table .katex-display { margin: 0; }
.rules-table td div + div { margin-top: 6px; }
.table-column-label { display: none; }
@media (max-width: 699px) {
  .rules-table thead { display: none; }
  .rules-table tbody > tr { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .rules-table tbody > tr:first-child { border-top: 1px solid var(--line-bright); }
  .rules-table tbody > tr > * { padding: 0; border: 0 !important; }
  .table-column-label { display: block; color: var(--muted); font: 600 .75rem/1.4 var(--sans); }
}

/* Checkpoint questions ------------------------------------------------------- */

.checkpoint-copy > p { margin-top: 10px; }
.checkpoint-instructions { color: var(--muted); font-size: 1rem; }
.score-line { color: var(--ink); font: 500 .9375rem/1.4 var(--sans); }
.score-line strong { font-weight: 600; font-variant-numeric: tabular-nums; }
.quiz-list { display: grid; gap: 16px; }
.quiz-card { min-width: 0; padding: 20px 22px 22px; background: var(--space-2); border: 1px solid var(--line); border-radius: var(--radius); }
.quiz-index { font: .875rem/1.4 var(--sans); }
.quiz-number { font-weight: 600; }
.attempt-label { margin-left: 8px; color: var(--muted); }
.quiz-question { margin-top: 6px; font-size: 1.0625rem; }
.quiz-feedback {
  display: none;
  margin-top: 14px;
  padding: 12px 16px;
  background: var(--space-3);
  border-left: 3px solid var(--line-bright);
  border-radius: 0 4px 4px 0;
  font-size: 1rem;
}
.quiz-feedback > strong:first-child { margin-right: .25em; font: 600 .9375rem var(--sans); }
.quiz-card.is-answered .quiz-feedback, .quiz-card.is-retrying .quiz-feedback { display: block; }
.quiz-card.is-correct .quiz-feedback { border-left-color: var(--green); }
.quiz-card.is-wrong .quiz-feedback { border-left-color: var(--coral); }
.quiz-card.is-retrying .quiz-feedback { border-left-color: var(--gold); }
.quiz-options { display: grid; gap: 8px; margin-top: 16px; }
.quiz-option {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 9px 14px 9px 12px;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.5;
  text-align: left;
  background: var(--space-2);
  border: 1px solid var(--line-bright);
  border-left-width: 4px;
  border-radius: 4px;
  transition: border-color 150ms ease, background-color 150ms ease;
}
.quiz-option > span { min-width: 0; }
.quiz-option:hover:not(:disabled) { background: var(--space-3); border-color: var(--ink); }
.quiz-option:disabled { cursor: default; }
.quiz-card.is-answered .quiz-option:not(.is-answer):not(.is-selected) { color: var(--muted); }
.option-letter {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin-top: -1px;
  color: var(--muted);
  border: 1px solid var(--line-bright);
  border-radius: 50%;
  font: 600 .8125rem/1 var(--sans);
}
.quiz-option.is-answer { border-color: var(--line-bright); border-left-color: var(--green); }
.quiz-option.is-answer .option-letter { color: var(--space-2); background: var(--green); border-color: var(--green); }
.quiz-option.is-selected:not(.is-answer) { border-left-color: var(--coral); }
.quiz-option.is-selected:not(.is-answer) .option-letter { color: var(--space-2); background: var(--coral); border-color: var(--coral); }
.quiz-option .katex-display { margin: .35em 0; }
.question-reset { display: block; min-height: 44px; margin-top: 8px; color: var(--accent-text); font: .875rem var(--sans); text-decoration: underline; text-underline-offset: .2em; }
.quiz-retry { justify-self: start; }
.quiz-print-answer { display: none; }

/* Chapter and site footers ---------------------------------------------------- */

.chapter-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px 32px;
  margin-top: 16px;
  padding: 28px 0 56px;
  border-top: 1px solid var(--line-bright);
}
.next-label { color: var(--muted); font: .875rem/1.4 var(--sans); }
.chapter-footer h2 { margin-top: 4px; font-size: 1.375rem; }
.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 24px;
  padding: 24px 0 40px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font: .875rem/1.5 var(--sans);
}
.site-footer .text-button { margin-left: auto; }
.footer-note { flex-basis: 100%; margin-top: 8px; color: var(--faint); font-size: .8125rem; }
.footer-note a { color: inherit; text-decoration: underline; }
.footer-note a:hover { color: var(--ink); }
.home-view:not([hidden]) ~ .site-footer { border-top-color: var(--line-bright); }

/* Contents dialog ------------------------------------------------------------- */

.course-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  color: var(--ink);
  background: var(--space-2);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .16);
}
.course-dialog::backdrop { background: rgba(20, 22, 27, .45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 24px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: 1.5rem; }
.dialog-close { display: grid; place-items: center; width: 36px; height: 36px; color: var(--muted); border: 1px solid var(--line-bright); border-radius: 4px; font: 1.4rem/1 var(--sans); }
.dialog-close:hover { color: var(--ink); border-color: var(--ink); }
.dialog-grid { display: grid; }
.dialog-card {
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr);
  gap: 2px 16px;
  width: 100%;
  padding: 14px 24px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  transition: background-color 150ms ease;
}
.dialog-card:last-child { border-bottom: 0; }
.dialog-card:hover { background: var(--space-3); }
.dialog-card[aria-current] { box-shadow: inset 3px 0 0 var(--control); }
.dialog-card:focus-visible { outline-offset: -2px; }
.dialog-number { grid-row: 1 / span 3; padding-top: 3px; color: var(--accent-text); font: 600 .875rem/1.4 var(--sans); }
.dialog-card strong { font: 600 1.125rem/1.35 var(--serif); }
.dialog-card small { color: var(--muted); font: 1rem/1.5 var(--serif); }
.dialog-progress { color: var(--muted); font: .8125rem/1.5 var(--sans); }
@media (max-width: 520px) {
  .dialog-head { padding: 12px 16px; }
  .dialog-card { grid-template-columns: minmax(0, 1fr); padding: 12px 16px; }
  .dialog-number { grid-row: auto; padding-top: 0; }
}

@media (max-width: 520px) {
  .lab-section, .explorer-section, .concept-section, .finance-application, .checkpoint-section, .video-section { padding-block: 36px; }
  .chapter-hero { padding-top: calc(var(--header-h) + 32px); }
  .chapter-summary { font-size: 1.125rem; }
  .quiz-card { padding: 18px 16px; }
  .formula { padding-inline: 12px; }
  .formula .katex { font-size: 1rem; }
  .site-footer .text-button { margin-left: 0; }
}

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

/* Print: light palette, controls hidden, figures kept ------------------------ */

@media print {
  @page { size: A4; margin: 15mm; }
  html, body { background: #fff !important; }
  body { font-size: 10.5pt; }
  .site-header, .skip-link, .lesson-navigation, .chapter-footer, .site-footer, .course-dialog,
  .primary-button, .text-button, .question-reset, .quiz-retry, .checkpoint-instructions, .home-resources, .video-section, noscript { display: none !important; }
  .home-view, .chapter-hero, .chapter-opening, .lab-section, .explorer-section, .concept-section,
  .finance-application, .checkpoint-section { width: auto; padding: 14pt 0; }
  .chapter-hero { padding-top: 0; }
  h1 { font-size: 24pt; }
  h2 { font-size: 16pt; }
  h2, h3, h4 { break-after: avoid; }
  .chapter-summary { font-size: 12pt; }
  .lesson-prose > *, .concept-list, .quiz-list { max-width: none; }
  .lesson-prose details, .concept-extra { background: none; border: 1px solid var(--line); }
  .lesson-prose details summary { list-style: none; }
  .lesson-prose details summary::marker { content: ""; }
  .lesson-prose a::after { content: " (" attr(href) ")"; color: var(--faint); font-size: .85em; }
  .formula, .rules-table tr, .cash-flow-table tr { break-inside: avoid; }
  .table-scroll { overflow: visible; }
  .lesson-prose > .table-scroll > .cash-flow-table { max-width: none; }
  .concept-card, .quiz-card, table { break-inside: auto; }
  .quiz-card { background: none; }
  .quiz-feedback { display: block; background: none; }
  .quiz-card.is-retrying .quiz-feedback { display: none; }
  .quiz-card.is-retrying .quiz-print-answer { display: block; margin-top: 12px; }
}
