:root {
  --bg: #f6f8f6;
  --surface: #ffffff;
  --ink: #1c2b22;
  --muted: #5c6f63;
  --accent: #1f7a53;
  --accent-soft: #e3f2ea;
  --sun: #d68f16;
  --border: #d8e2db;
  --shadow: 0 1px 3px rgba(20, 50, 35, .08), 0 6px 20px rgba(20, 50, 35, .06);
  --radius: 14px;
  --maxw: 760px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10171300;
    --bg: #0f1512;
    --surface: #161e19;
    --ink: #e7efe9;
    --muted: #9fb2a6;
    --accent: #4cc38a;
    --accent-soft: #17241d;
    --sun: #f0c14b;
    --border: #26332b;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 2.5rem 1.25rem 5rem; }

a { color: var(--accent); }

/* Homepage hero */
.hero { text-align: center; margin-bottom: 3rem; }
.hero .kicker { color: var(--muted); letter-spacing: .12em; text-transform: uppercase; font-size: .75rem; font-weight: 600; }
.hero h1 { font-size: 2.6rem; line-height: 1.15; margin: .4rem 0 .3rem; }
.hero .author { color: var(--muted); margin: 0; }
.hero p.intro { color: var(--muted); max-width: 52ch; margin: 1.2rem auto 0; }

/* Chapter list */
.toc { list-style: none; padding: 0; margin: 0; display: grid; gap: .9rem; }
.toc a {
  display: flex; align-items: baseline; gap: 1rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.3rem;
  text-decoration: none; color: var(--ink);
  box-shadow: var(--shadow); transition: transform .12s ease, border-color .12s ease;
}
.toc a:hover { transform: translateY(-2px); border-color: var(--accent); }
.toc .num { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.toc .ch-title { font-weight: 600; }
.toc .ch-sub { display: block; color: var(--muted); font-size: .9rem; font-weight: 400; }

/* Chapter page */
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }
.topbar a { text-decoration: none; font-weight: 600; }
.chapter-kicker { color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-size: .75rem; font-weight: 700; }
article h1 { font-size: 2.1rem; line-height: 1.2; margin: .2rem 0 1.4rem; }
article h2 { font-size: 1.4rem; margin-top: 2.4rem; }
article p, article li { max-width: 68ch; }

figure { margin: 2rem 0; text-align: center; }
figure svg, figure img { max-width: 100%; height: auto; }
figcaption { color: var(--muted); font-size: .9rem; margin-top: .6rem; }

/* Callout box */
.callout {
  background: var(--accent-soft); border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1rem 1.2rem; margin: 1.8rem 0;
}
.callout strong { color: var(--accent); }

/* Media links */
.media-link {
  display: inline-flex; align-items: center; gap: .5rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: .45rem 1rem; margin: .25rem .3rem .25rem 0;
  text-decoration: none; font-size: .95rem; font-weight: 600;
  box-shadow: var(--shadow);
}
.media-link:hover { border-color: var(--accent); }
.media-link .icon { font-size: 1.1rem; }

/* Prev / next */
.chapter-nav { display: flex; justify-content: space-between; margin-top: 3.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.chapter-nav a { text-decoration: none; font-weight: 600; }
.chapter-nav span { color: var(--muted); }

footer.site { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 4rem; }

/* ---- Inline term links (open a video / audio explaining that term) ---- */
.term {
  color: var(--accent); font-weight: 600; text-decoration: none;
  border-bottom: 1.5px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 2px; padding-bottom: .5px;
  transition: background .15s ease, border-color .15s ease;
}
.term::after {
  content: "\25B8"; font-size: .62em; color: var(--sun);
  vertical-align: .35em; margin-left: .15em; font-weight: 700;
}
.term.audio::after { content: "\266A"; }
.term:hover, .term:focus-visible {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-color: var(--accent); outline: none;
}
.term:focus-visible { outline: 2px solid var(--sun); outline-offset: 2px; }

/* Legend explaining the clickable terms */
.legend { font-size: .85rem; color: var(--muted); margin: 1.2rem 0 0; }
.legend .tip {
  display: inline-block; text-transform: uppercase; letter-spacing: .12em;
  font-size: .62rem; font-weight: 700; color: var(--accent);
  border: 1px solid var(--border); border-radius: 5px;
  padding: .05rem .4rem; margin-right: .4rem; vertical-align: .08em;
}
.legend .term::after { content: ""; margin: 0; }

/* Photosystem cards */
.ps-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin: 1.8rem 0; }
.ps { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); }
.ps h3 { margin: 0 0 .2rem; font-size: 1.15rem; }
.ps .peak { font-size: .75rem; font-weight: 700; color: var(--sun); }
.ps p { font-size: .92rem; margin: .5rem 0 0; color: var(--muted); max-width: none; }

/* Diagram card (keeps wide SVGs scrollable, theme-aware surface) */
.figcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1rem .75rem; box-shadow: var(--shadow); overflow-x: auto; }
.figcard svg { min-width: 440px; }

/* Equation strip */
.equation {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.2rem; margin: 1.6rem 0; color: var(--muted);
  font-family: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
  font-size: .9rem; line-height: 1.6; overflow-x: auto;
}
.equation b { color: var(--sun); font-weight: 700; }
.equation .g { color: var(--accent); font-weight: 700; }
