:root {
  --bg: #f7f5f1;
  --bg-surface: #ffffff;
  --bg-raised: #f0ede6;
  --text-primary: #1a1d1b;
  --text-secondary: #46504a;
  --text-muted: #4c554a;
  --accent: #0f6e5c;
  --accent-strong: #0a4f42;
  --accent-soft: #d9ede8;
  --border: #dcd7cc;
  --border-strong: #b9b2a2;
  --warn: #6f3414;
  --warn-soft: #f4e2d4;
  --link: #0a5a4a;
  --shadow: 0 1px 3px rgba(20, 20, 15, 0.08);
  --rail-dot: #b9b2a2;
  --code-bg: #eee9df;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12140f;
    --bg-surface: #191c16;
    --bg-raised: #20241d;
    --text-primary: #f1efe8;
    --text-secondary: #c3c9bd;
    --text-muted: #9aa295;
    --accent: #56c9a8;
    --accent-strong: #86ddc0;
    --accent-soft: #1c3b32;
    --border: #33372c;
    --border-strong: #474d3c;
    --warn: #eab588;
    --warn-soft: #3a2a1a;
    --link: #6fd6b6;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --rail-dot: #474d3c;
    --code-bg: #20241d;
  }
}

:root[data-theme="dark"] {
  --bg: #12140f;
  --bg-surface: #191c16;
  --bg-raised: #20241d;
  --text-primary: #f1efe8;
  --text-secondary: #c3c9bd;
  --text-muted: #9aa295;
  --accent: #56c9a8;
  --accent-strong: #86ddc0;
  --accent-soft: #1c3b32;
  --border: #33372c;
  --border-strong: #474d3c;
  --warn: #eab588;
  --warn-soft: #3a2a1a;
  --link: #6fd6b6;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --rail-dot: #474d3c;
  --code-bg: #20241d;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: "Source Serif 4", Georgia, "Iowan Old Style", serif;
  font-size: 1.08rem;
  line-height: 1.68;
}
h1, h2, h3, h4, .display {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}
a { color: var(--link); }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
img { max-width: 100%; height: auto; display: block; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
a.visually-hidden:focus {
  position: fixed; top: 0.6rem; left: 0.6rem; width: auto; height: auto;
  margin: 0; padding: 0.5rem 0.9rem; clip: auto; overflow: visible; white-space: normal;
  background: var(--bg-surface); color: var(--text-primary); border: 1px solid var(--border-strong);
  border-radius: 0.3rem; z-index: 100; font-family: system-ui, sans-serif; font-size: 0.9rem;
}

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 1rem;
  height: 3.1rem; padding: 0 0.9rem;
  background: color-mix(in srgb, var(--bg-surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.86rem;
}
.topbar .home { font-weight: 700; color: var(--text-primary); text-decoration: none; white-space: nowrap; }
.topnav {
  display: flex; gap: 1.1rem; overflow-x: auto; scrollbar-width: none;
  -ms-overflow-style: none; white-space: nowrap;
}
.topnav::-webkit-scrollbar { display: none; }
.topnav a { color: var(--text-secondary); text-decoration: none; padding: 0.2rem 0; border-bottom: 2px solid transparent; }
.topnav a[aria-current="true"] { color: var(--accent-strong); border-bottom-color: var(--accent); }
.spacer { flex: 1 1 auto; }
.chip {
  color: var(--text-secondary); text-decoration: none; padding: 0.25rem 0.6rem;
  border: 1px solid var(--border); border-radius: 999px; white-space: nowrap;
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; border-radius: 999px; border: 1px solid var(--border);
  background: transparent; color: var(--text-primary); cursor: pointer; flex: none;
}
.icon-btn svg[hidden] { display: none; }
.icon-btn svg { display: block; }

/* ---------- reading rail ---------- */
.rail {
  position: fixed; right: 1.4rem; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 0.9rem; z-index: 30;
}
.rail-dot { position: relative; display: flex; align-items: center; text-decoration: none; }
.rail-dot .dot {
  width: 6px; height: 6px; border-radius: 999px; background: var(--rail-dot);
  transition: transform 0.15s ease, background 0.15s ease;
}
.rail-dot.active .dot { background: var(--accent); transform: scale(1.45); }
.rail-label {
  position: absolute; right: 1.1rem; top: 50%; transform: translateY(-50%);
  background: var(--bg-surface); color: var(--text-primary); border: 1px solid var(--border);
  padding: 0.15rem 0.55rem; border-radius: 0.3rem; font-size: 0.78rem;
  white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity 0.12s ease;
  font-family: system-ui, sans-serif; box-shadow: var(--shadow);
}
.rail-dot:hover .rail-label, .rail-dot:focus-visible .rail-label { opacity: 1; }
@media (max-width: 76rem) { .rail { display: none; } }
@media print { .rail, .topbar { display: none; } }

/* ---------- layout ---------- */
main { display: block; }
.wrap { max-width: 42rem; margin: 0 auto; padding: 0 1.25rem; }
.wide { max-width: 56rem; }
section { scroll-margin-top: 3.6rem; padding: 2.6rem 0; border-top: 1px solid var(--border); }
section:first-of-type { border-top: none; }

.hero { padding: 3rem 0 2.4rem; }
.kicker {
  font-family: system-ui, sans-serif; text-transform: uppercase; letter-spacing: 0.08em;
  font-size: 0.78rem; color: var(--accent-strong); font-weight: 600; margin: 0 0 0.9rem;
}
.hero h1 { font-size: clamp(1.9rem, 4.4vw, 2.9rem); line-height: 1.15; margin: 0 0 1.1rem; }
.deck { font-size: 1.22rem; color: var(--text-secondary); line-height: 1.55; margin: 0 0 1.4rem; }
.byline { font-family: system-ui, sans-serif; font-size: 0.86rem; color: var(--text-muted); }

h2.section-title { font-size: clamp(1.4rem, 2.6vw, 1.85rem); margin: 0 0 0.4rem; }
.section-kicker { font-family: system-ui, sans-serif; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); margin: 0 0 0.5rem; }
.lede { font-size: 1.08rem; color: var(--text-secondary); margin: 0.6rem 0 1.2rem; }

p { margin: 0 0 1.05rem; }
.wrap > p, .prose p { max-width: 40rem; }
strong { color: var(--text-primary); }

.stat-line {
  display: inline-flex; align-items: baseline; gap: 0.4rem;
  font-family: system-ui, sans-serif; font-weight: 700; color: var(--accent-strong);
}

blockquote.pull {
  margin: 1.6rem 0; padding: 0 0 0 1.1rem; border-left: 3px solid var(--accent);
  font-family: "Fraunces", serif; font-size: 1.25rem; line-height: 1.4; color: var(--text-primary);
}

.caveat {
  background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--border));
  border-radius: 0.5rem; padding: 0.85rem 1rem; margin: 1.2rem 0;
  font-size: 0.95rem; color: var(--text-primary);
}
.caveat strong { color: var(--warn); }

figure { margin: 1.6rem 0; }
figure img, figure svg { border-radius: 0.4rem; border: 1px solid var(--border); background: var(--bg-surface); }
figcaption {
  font-family: system-ui, sans-serif; font-size: 0.84rem; color: var(--text-muted);
  margin-top: 0.5rem; line-height: 1.45;
}
figcaption .credit { display: block; margin-top: 0.15rem; }

/* mechanism steps */
.mechanism { display: grid; gap: 0; margin: 1.6rem 0 2rem; }
.mstep {
  display: grid; grid-template-columns: 2.4rem 1fr; gap: 0.9rem;
  padding: 0.9rem 0; border-bottom: 1px dashed var(--border);
}
.mstep:last-child { border-bottom: none; }
.mstep .num {
  font-family: "Fraunces", serif; font-weight: 700; font-size: 1.3rem; color: var(--accent);
  display: flex; align-items: flex-start; justify-content: center;
}
.mstep h3 { font-size: 1.02rem; margin: 0 0 0.25rem; font-family: system-ui, sans-serif; font-weight: 700; }
.mstep p { margin: 0; font-size: 0.98rem; color: var(--text-secondary); }

/* timeline */
.timeline { position: relative; margin: 1.8rem 0 2rem; padding-left: 1.6rem; }
.timeline::before { content: ""; position: absolute; left: 0.28rem; top: 0.3rem; bottom: 0.3rem; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: 1.4rem; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: ""; position: absolute; left: -1.6rem; top: 0.35rem; width: 9px; height: 9px;
  border-radius: 999px; background: var(--accent); border: 2px solid var(--bg);
}
.tl-year { font-family: system-ui, sans-serif; font-weight: 700; color: var(--accent-strong); font-size: 0.92rem; }
.tl-item p { margin: 0.2rem 0 0; color: var(--text-secondary); font-size: 0.98rem; }

/* comparison table */
.table-scroll { overflow-x: auto; margin: 1.4rem 0 2rem; border: 1px solid var(--border); border-radius: 0.5rem; }
table { border-collapse: collapse; width: 100%; min-width: 40rem; font-size: 0.92rem; font-family: system-ui, sans-serif; }
th, td { text-align: left; padding: 0.65rem 0.8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { background: var(--bg-raised); color: var(--text-primary); font-weight: 700; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
td.num { font-variant-numeric: tabular-nums; }

.card-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); margin: 1.4rem 0 2rem; }
.card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 0.6rem; padding: 1.1rem 1.2rem; }
.card h3 { font-size: 1rem; margin: 0 0 0.4rem; font-family: system-ui, sans-serif; }
.card p { margin: 0; font-size: 0.94rem; color: var(--text-secondary); }

.method {
  font-size: 0.94rem; color: var(--text-secondary); background: var(--bg-raised);
  border-radius: 0.6rem; padding: 1.2rem 1.3rem; margin: 1.2rem 0;
}
.method a { color: var(--link); }

footer.site-footer {
  border-top: 1px solid var(--border); margin-top: 2rem; padding: 2rem 1.25rem 3rem;
  font-family: system-ui, sans-serif; font-size: 0.86rem; color: var(--text-muted);
  text-align: center;
}
footer.site-footer a { color: var(--text-secondary); }

@media (max-width: 30rem) {
  section { padding: 1.9rem 0; }
  .hero { padding: 2rem 0 1.6rem; }
}
