:root {
  --bg: #fbfaf8;
  --bg-alt: #f3f0eb;
  --surface: #ffffff;
  --text: #1c1917;
  --muted: #5f5a54;
  --border: #e4dfd8;
  --accent: #ea6a0c;
  --accent-strong: #c2550a;
  --accent-soft: #fff1e6;
  --blue: #2563eb;
  --green: #059669;
  --red: #dc2626;
  --code-bg: #f4f1ec;
  --shadow: 0 1px 2px rgba(28, 25, 23, .06), 0 8px 24px rgba(28, 25, 23, .06);
  --radius: 14px;
  --max: 1120px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141210;
    --bg-alt: #1c1917;
    --surface: #211e1b;
    --text: #f1ede8;
    --muted: #a8a29e;
    --border: #34302b;
    --accent: #fb8a3c;
    --accent-strong: #fdba74;
    --accent-soft: #2b1c10;
    --blue: #60a5fa;
    --green: #34d399;
    --red: #f87171;
    --code-bg: #1a1715;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent-strong); text-underline-offset: 2px; }
a:hover { color: var(--accent); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }
code { background: var(--code-bg); padding: .1em .35em; border-radius: 5px; border: 1px solid var(--border); overflow-wrap: anywhere; }
pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; overflow-x: auto; line-height: 1.5; }
pre code { background: none; border: 0; padding: 0; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -.01em; }
h2 { font-size: 1.75rem; margin: 2.4em 0 .6em; }
h3 { font-size: 1.2rem; margin: 1.8em 0 .4em; }
.wrap { max-width: var(--max); margin: 0 auto; padding: 0 16px; }
.prose { max-width: 780px; }

/* Header */
.site-header { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.site-header .wrap { display: flex; align-items: center; gap: 24px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.brand svg { width: 28px; height: 28px; }
.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 8px; font-size: .95rem; }
.nav a:hover { color: var(--text); background: var(--bg-alt); }
.nav a[aria-current="page"] { color: var(--accent-strong); background: var(--accent-soft); }

/* Hero */
.hero { padding: 72px 0 40px; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); margin: 0 0 .3em; max-width: 18ch; }
.hero .lead { font-size: 1.2rem; color: var(--muted); max-width: 60ch; margin: 0 0 1.6em; }
.page-hero { padding: 56px 0 8px; }
.page-hero h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0 0 .3em; }
.page-hero .lead { color: var(--muted); font-size: 1.1rem; max-width: 65ch; }
.eyebrow { color: var(--accent-strong); font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; margin: 0 0 .6em; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px; border-radius: 10px; font-weight: 600; text-decoration: none; border: 1px solid var(--border); color: var(--text); background: var(--surface); }
.btn:hover { color: var(--text); border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }

.shot { border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); overflow: hidden; background: var(--surface); margin: 0; }
.shot figcaption { font-size: .9rem; color: var(--muted); padding: 10px 14px; border-top: 1px solid var(--border); }
.hero .shot { margin-top: 44px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin: 28px 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.stat b { display: block; font-size: 1.7rem; line-height: 1.15; }
.stat span { color: var(--muted); font-size: .92rem; }

/* Features */
.section { padding: 24px 0 8px; }
.section.alt { background: var(--bg-alt); border-block: 1px solid var(--border); padding: 24px 0 56px; margin-top: 48px; }
.feature { display: grid; grid-template-columns: 1fr 1.35fr; gap: 40px; align-items: center; margin: 56px 0; }
.feature.reverse { grid-template-columns: 1.35fr 1fr; }
.feature.reverse > .text { order: 2; }
.feature h3 { margin-top: 0; font-size: 1.4rem; }
.feature p { color: var(--muted); }
.feature ul { padding-left: 1.2em; color: var(--muted); }
.feature li { margin: .25em 0; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin: 24px 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.card h4 { margin: 0 0 .4em; font-size: 1.02rem; }
.card p { margin: 0; color: var(--muted); font-size: .95rem; }
.two-shots { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 24px 0; align-items: start; }

/* Callouts */
.note, .warn, .tip { border-radius: 12px; padding: 14px 18px; margin: 20px 0; border: 1px solid var(--border); background: var(--surface); }
.note { border-left: 4px solid var(--blue); }
.warn { border-left: 4px solid var(--red); }
.tip { border-left: 4px solid var(--green); }
.note > :first-child, .warn > :first-child, .tip > :first-child { margin-top: 0; }
.note > :last-child, .warn > :last-child, .tip > :last-child { margin-bottom: 0; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 16px 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--bg-alt); font-weight: 600; }
tr:last-child td { border-bottom: 0; }

/* Layout with TOC */
.doc { display: grid; grid-template-columns: 220px 1fr; gap: 48px; padding-bottom: 40px; }
.toc { position: sticky; top: 84px; align-self: start; font-size: .92rem; }
.toc p { font-weight: 600; margin: 24px 0 8px; }
.toc ol { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--border); }
.toc a { display: block; padding: 4px 12px; color: var(--muted); text-decoration: none; margin-left: -2px; border-left: 2px solid transparent; }
.toc a:hover { color: var(--text); border-left-color: var(--accent); }
.doc article { min-width: 0; max-width: 800px; }
.doc article h2:first-child { margin-top: 1em; }
.steps { counter-reset: step; list-style: none; padding: 0; }
.steps > li { counter-increment: step; position: relative; padding-left: 44px; margin: 18px 0; }
.steps > li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); font-weight: 700; display: grid; place-items: center; font-size: .9rem; }
.formula { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--accent-soft); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; overflow-wrap: anywhere; line-height: 1.8; }
.sources { font-size: .93rem; }
.sources li { margin: .5em 0; }
.sources .src-title { font-weight: 600; }
.diagram { overflow-x: auto; margin: 24px 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.diagram svg { width: 100%; height: auto; display: block; }
.diagram figcaption { font-size: .9rem; color: var(--muted); margin-top: 8px; }
svg .d-line { stroke: var(--muted); }
svg .d-box { fill: var(--bg-alt); stroke: var(--border); }
svg .d-accent { fill: var(--accent-soft); stroke: var(--accent); }
svg .d-text { fill: var(--text); font: 600 14px system-ui, sans-serif; }
svg .d-sub { fill: var(--muted); font: 12px system-ui, sans-serif; }
svg .d-curve { stroke: var(--accent); fill: none; }
svg .d-curve2 { stroke: var(--blue); fill: none; }
svg .d-grid { stroke: var(--border); }
svg .d-axis { stroke: var(--muted); }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding: 32px 0 48px; color: var(--muted); font-size: .92rem; margin-top: 48px; }
.site-footer .wrap { display: flex; gap: 24px; justify-content: space-between; flex-wrap: wrap; }

@media (max-width: 860px) {
  .feature, .feature.reverse, .two-shots { grid-template-columns: 1fr; gap: 20px; }
  .feature.reverse > .text { order: 0; }
  .doc { grid-template-columns: 1fr; gap: 0; }
  .toc { position: static; }
  .diagram svg { min-width: 620px; }
  .hero { padding-top: 44px; }
  .nav { margin-left: 0; }
}
