:root {
  color-scheme: light;
  --paper: #f5f7f4;
  --surface: #ffffff;
  --header-surface: #ffffff;
  --header-hover: #e8efeb;
  --ink: #17231f;
  --muted: #52645e;
  --forest: #185a47;
  --forest-dark: #103d32;
  --slate: #344a52;
  --line: #cbd6d0;
  --soft: #e8efeb;
  --accent: #c9a227;
  --accent-contrast: #241d00;
  --button-ink: #ffffff;
  --callout: #fbf8ed;
  --footer-ink: #e8f0eb;
  --footer-surface: #103d32;
  --max: 1160px;
  --measure: 72ch;
}

/* The automatic palette remains useful when the optional theme script is unavailable.
   --header-surface and --footer-surface intentionally keep their prior values here:
   only the page background, cards, and text tone were desaturated toward neutral gray/black. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --paper: #0c0e0d;
    --surface: #191c1b;
    --header-surface: #1b2521;
    --header-hover: #4d6a58;
    --ink: #e7e9e8;
    --muted: #a5aba8;
    --forest: #6f9c87;
    --forest-dark: #b7c7bf;
    --slate: #bcc2bf;
    --line: #383e3b;
    --soft: #212524;
    --accent: #e3c45c;
    --accent-contrast: #171300;
    --button-ink: #0c1210;
    --callout: #302d1c;
    --footer-ink: #edf4ef;
    --footer-surface: #0b211a;
  }
}

html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0c0e0d;
  --surface: #191c1b;
  --header-surface: #1b2521;
  --header-hover: #4d6a58;
  --ink: #e7e9e8;
  --muted: #a5aba8;
  --forest: #6f9c87;
  --forest-dark: #b7c7bf;
  --slate: #bcc2bf;
  --line: #383e3b;
  --soft: #212524;
  --accent: #e3c45c;
  --accent-contrast: #171300;
  --button-ink: #0c1210;
  --callout: #302d1c;
  --footer-ink: #edf4ef;
  --footer-surface: #0b211a;
}

html[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 1rem; line-height: 1.65; }
a { color: var(--forest-dark); }
a:hover { color: var(--forest); }
h1, h2, h3, h4 { color: var(--forest-dark); line-height: 1.2; }
h1 { margin: 0 0 1rem; font-size: clamp(2.35rem, 5vw, 3.5rem); letter-spacing: -0.04em; }
h2 { margin: 2.8rem 0 1rem; font-size: clamp(1.75rem, 3vw, 2.6rem); letter-spacing: -0.025em; }
h3 { margin: 1.8rem 0 0.65rem; font-size: 1.35rem; }
p { max-width: var(--measure); }
ul, ol { padding-left: 1.35rem; }
li + li { margin-top: 0.4rem; }

.container { width: min(calc(100% - 2.5rem), var(--max)); margin: 0 auto; }
.skip-link { position: absolute; z-index: 10; top: -4rem; left: 1rem; padding: 0.6rem 0.85rem; color: var(--paper); background: var(--forest-dark); }
.skip-link:focus { top: 0.75rem; }
.site-header { border-bottom: 1px solid var(--line); background: var(--header-surface); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 4.8rem; }
.header-inner > .site-nav { margin-left: auto; }
.brand { color: var(--forest-dark); font-size: 1.35rem; font-weight: 750; letter-spacing: -0.03em; text-decoration: none; }
.brand span { color: var(--forest); }
.site-nav { display: flex; flex-wrap: wrap; gap: 0.2rem; }
.site-nav a { padding: 0.55rem 0.7rem; color: var(--slate); font-size: 0.94rem; text-decoration: none; }
.site-nav a:hover, .site-nav a:focus-visible, .site-nav a[aria-current="page"] { color: var(--ink); background: var(--header-hover); }
.theme-toggle { display: inline-grid; flex: 0 0 auto; place-items: center; width: 44px; height: 44px; margin-left: 0.25rem; padding: 0; border: 1px solid var(--line); color: var(--ink); background: var(--header-surface); cursor: pointer; visibility: hidden; }
.theme-toggle.is-ready { visibility: visible; }
.theme-toggle:hover { border-color: var(--forest); background: var(--header-hover); }
.theme-icon { display: block; position: relative; width: 1.25rem; height: 1.25rem; overflow: hidden; border: 1px solid var(--ink); border-radius: 50%; background: var(--button-ink); }
.theme-icon::before { content: ""; position: absolute; inset: 0 50% 0 0; background: #111; }
.theme-icon::after { content: ""; position: absolute; inset: 0 0 0 50%; background: #fff; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.site-footer { margin-top: 4rem; padding: 2rem 0; color: var(--footer-ink); background: var(--footer-surface); }
.footer-inner { display: flex; justify-content: space-between; gap: 2rem; align-items: baseline; }
.site-footer .brand, .site-footer a, .site-footer .brand span { color: var(--footer-ink); }
.site-footer p { margin: 0; font-size: 0.93rem; }
.footer-links { display: flex; gap: 1.1rem; flex-wrap: wrap; }

.page-heading { padding: 4.5rem 0 2.5rem; border-bottom: 1px solid var(--line); }
.page-heading .lead { max-width: 66ch; margin: 0; color: var(--muted); font-size: 1.2rem; }
.eyebrow { margin: 0 0 0.8rem; color: var(--forest); font-size: 0.78rem; font-weight: 750; letter-spacing: 0.13em; text-transform: uppercase; }
.breadcrumb { padding-top: 1.2rem; color: var(--muted); font-size: 0.9rem; }
.breadcrumb a { color: var(--muted); }
.section-intro { max-width: 70ch; color: var(--muted); }
.home-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(250px, 0.75fr); gap: 4rem; align-items: start; padding: 5rem 0 2rem; }
.home-layout .lead { max-width: 62ch; color: var(--muted); font-size: 1.22rem; }
.home-aside { padding: 1.5rem; border-left: 4px solid var(--forest); background: var(--surface); }
.home-aside h2 { margin-top: 0; font-size: 1.3rem; }
.home-aside ul { margin-bottom: 0; }
.button { display: inline-block; padding: 0.7rem 1rem; border: 1px solid var(--forest); color: var(--button-ink); background: var(--forest); font-weight: 700; text-decoration: none; }
.button:hover, .button:focus-visible { color: var(--button-ink); background: var(--forest-dark); }
.button.secondary { color: var(--forest-dark); background: transparent; }
.button.secondary:hover, .button.secondary:focus-visible { color: var(--button-ink); background: var(--forest); }
.button-row { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 1.5rem 0; }
.home-section { padding: 2rem 0; border-top: 1px solid var(--line); }
.course-list { margin: 1rem 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.course-list li { display: grid; grid-template-columns: 5rem 1fr auto; gap: 1rem; align-items: baseline; padding: 1.1rem 0; border-bottom: 1px solid var(--line); }
.course-list strong { color: var(--forest); font-size: 0.85rem; letter-spacing: 0.08em; }
.course-list a { font-weight: 700; }
.course-list span { color: var(--muted); font-size: 0.92rem; }
.callout { margin: 1.5rem 0; padding: 1rem 1.2rem; border-left: 4px solid var(--accent); background: var(--callout); }
.callout p:last-child { margin-bottom: 0; }
.equation { margin: 1.3rem 0; padding: 1rem 1.2rem; overflow-x: auto; border: 1px solid var(--line); color: var(--forest-dark); background: var(--soft); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 1.1rem; }
.table-wrap { margin: 1.5rem 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
caption { margin-bottom: 0.5rem; color: var(--muted); text-align: left; }
th, td { padding: 0.7rem 0.8rem; border: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--forest-dark); background: var(--soft); }
.course-path { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem; margin: 2rem 0; }
.path { padding: 1.4rem; border-top: 4px solid var(--forest); background: var(--surface); }
.path h3 { margin-top: 0; }
.lesson-layout { display: grid; grid-template-columns: 13rem minmax(0, 1fr); gap: 3rem; padding: 2.5rem 0; }
.lesson-sidebar { position: sticky; top: 1rem; align-self: start; }
.toc { border-left: 2px solid var(--line); }
.toc > strong { display: block; width: 100%; padding: 0.55rem 0.75rem; color: var(--forest-dark); background: var(--soft); }
.toc a { display: block; padding: 0.35rem 0.75rem; color: var(--muted); font-size: 0.9rem; text-decoration: none; }
.toc a:hover, .toc a:focus-visible { color: var(--forest-dark); background: var(--soft); }
.lesson-sidebar > .note, .toc + .note { margin-top: 1.5rem; }
.lesson-content { min-width: 0; }
.lesson-content > section { margin-bottom: 3rem; }
.objectives { padding: 1.2rem 1.4rem; border: 1px solid var(--line); background: var(--surface); }
.objectives h2 { margin-top: 0; font-size: 1.35rem; }
.worked-example { margin: 1.5rem 0; padding: 1.2rem 1.4rem; border-left: 4px solid var(--forest); background: var(--surface); }
.worked-example h3 { margin-top: 0; }
.note { padding: 1rem 1.2rem; border: 1px solid var(--line); background: var(--soft); }
.lesson-sidebar .note h2 { margin-top: 0; font-size: 1.1rem; }
.practice { padding: 1.4rem; border: 1px solid var(--line); background: var(--surface); }
.practice h2 { margin-top: 0; }
details { margin: 0.85rem 0; padding: 0.75rem 0.9rem; border-top: 1px solid var(--line); }
summary { cursor: pointer; color: var(--forest-dark); font-weight: 700; }
.sources { padding-top: 1rem; border-top: 1px solid var(--line); }
.sources li { margin-bottom: 0.55rem; }
.lesson-nav { display: flex; justify-content: space-between; gap: 1rem; padding: 1.3rem 0; border-top: 1px solid var(--line); }
.lesson-nav a { max-width: 48%; }
.checklist { padding-left: 1.25rem; }
.checklist li::marker { color: var(--forest); }
.prose { max-width: var(--measure); }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.print-only { display: none; }

/* Revision hooks used by the home, student, and reference pages. */
.home-hero { padding: 4.5rem 0 2.5rem; border-bottom: 1px solid var(--line); }
.home-hero .lead { max-width: 62ch; margin: 0; color: var(--muted); font-size: 1.22rem; }
.audience-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; margin: 2rem auto 3rem; }
.audience-card { padding: 1.4rem; border: 1px solid var(--line); background: var(--surface); }
.audience-card h2 { margin-top: 0; font-size: 1.45rem; }
.resource-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; margin: 1.5rem 0; }
.resource-links > a, .resource-links > div { display: block; padding: 1rem; border: 1px solid var(--line); background: var(--surface); }
.resource-links > a { font-weight: 700; }
.periodic-table { margin: 1.5rem 0; padding: 0; }
.periodic-table figure { margin: 1rem; }
.periodic-table figure > a:first-child { display: block; padding: 1rem; background: #fff; }
.periodic-table img { display: block; width: 100%; height: auto; }

@media (max-width: 760px) {
  .container { width: min(calc(100% - 1.5rem), var(--max)); }
  .header-inner { align-items: center; flex-wrap: wrap; padding: 0.8rem 0; }
  .header-inner > .site-nav { order: 3; margin-left: 0; }
  .brand { margin-right: auto; }
  .site-nav { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .site-nav a { white-space: nowrap; }
  .home-layout { grid-template-columns: 1fr; gap: 1.5rem; padding-top: 3rem; }
  .course-list li { grid-template-columns: 4rem 1fr; }
  .course-list span { grid-column: 2; }
  .course-path { grid-template-columns: 1fr; }
  .audience-grid { grid-template-columns: 1fr; }
  .lesson-layout { grid-template-columns: 1fr; gap: 1.5rem; }
  .lesson-sidebar { position: static; }
  .toc { display: flex; flex-wrap: wrap; border-left: 0; border-bottom: 2px solid var(--line); }
  .toc a { padding: 0.45rem 0.6rem; }
  .footer-inner { align-items: flex-start; flex-direction: column; }
}

@media print {
  :root, :root:not([data-theme]), html[data-theme="dark"], html[data-theme="light"] { color-scheme: light; --paper: #fff; --surface: #fff; --ink: #000; --muted: #333; --forest: #174d3c; --forest-dark: #123b2e; --slate: #223b42; --line: #999; --soft: #f1f1f1; --callout: #f7f3df; --footer-surface: #fff; --footer-ink: #000; --button-ink: #fff; }
  body { color: #000; background: #fff; }
  .site-header, .site-footer, .skip-link, .lesson-sidebar, .button-row, .lesson-nav { display: none; }
  .container { width: 100%; }
  .lesson-layout { display: block; }
  .page-heading { padding-top: 0; }
  a { color: #000; }
  .print-only { display: block; }
}

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
