:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --text: #1c2333;
  --muted: #5d6679;
  --border: #e2e6ef;
  --primary: #2f6fed;
  --primary-soft: #e8efff;
  --accent: #0e9f6e;
  --accent-soft: #e3f7ef;
  --warn: #a86400;
  --warn-soft: #fff4e0;
  --danger: #c2362f;
  --danger-soft: #fdeceb;
  --code-bg: #111827;
  --code-text: #e5e7eb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #151b24;
    --surface-2: #1b2330;
    --text: #e6e9ef;
    --muted: #9aa4b5;
    --border: #2a3342;
    --primary: #6d9cff;
    --primary-soft: #1a2640;
    --accent: #34c38f;
    --accent-soft: #10291f;
    --warn: #f0b35a;
    --warn-soft: #2d2212;
    --danger: #ff7b72;
    --danger-soft: #2d1616;
    --code-bg: #0a0e14;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 20px; }

/* ---- header / footer ---- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-header .wrap { display: flex; align-items: center; gap: 24px; height: 60px; }
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; font-size: 14px; font-weight: 800;
}
.site-header nav { display: flex; gap: 18px; margin-left: auto; font-size: 14px; flex-wrap: wrap; }
.site-header nav a { color: var(--muted); }
.site-header nav a:hover, .site-header nav a[aria-current="page"] { color: var(--text); text-decoration: none; }

.site-footer {
  margin-top: 64px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 14px;
  padding: 24px 0 40px;
}

/* ---- hero ---- */
.hero { padding: 56px 0 32px; }
.hero h1 { font-size: clamp(2rem, 4vw, 3rem); line-height: 1.15; margin: 0 0 16px; letter-spacing: -0.02em; }
.hero .lead { max-width: 720px; }
.hero .actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }

.button {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px;
  background: var(--primary); color: #fff; font-weight: 600; font-size: 15px;
  border: 1px solid transparent; cursor: pointer;
}
.button:hover { text-decoration: none; filter: brightness(1.05); }
.button.ghost { background: transparent; color: var(--text); border-color: var(--border); }

.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 12px; font-weight: 700; color: var(--primary); margin: 0 0 8px; }
.lead { font-size: 1.15rem; color: var(--muted); margin: 0; }

/* ---- sections, cards ---- */
section { margin: 40px 0; }
h2 { font-size: 1.6rem; line-height: 1.3; margin: 48px 0 12px; letter-spacing: -0.01em; }
h3 { font-size: 1.2rem; margin: 28px 0 8px; }
p, ul, ol { margin: 0 0 14px; }
li { margin: 4px 0; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  color: var(--text);
  display: block;
}
a.card:hover { text-decoration: none; border-color: var(--primary); }
.card .num { font-size: 13px; font-weight: 700; color: var(--primary); }
.card h3 { margin: 4px 0 6px; font-size: 1.05rem; }
.card p { color: var(--muted); font-size: 14px; margin: 0; }

.path { counter-reset: step; list-style: none; padding: 0; }
.path li {
  counter-increment: step; position: relative;
  padding: 14px 16px 14px 56px; margin: 10px 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.path li::before {
  content: counter(step); position: absolute; left: 16px; top: 14px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}

/* ---- lesson layout ---- */
.lesson { max-width: 820px; padding-top: 40px; }
.lesson h1 { font-size: clamp(1.8rem, 3.4vw, 2.5rem); line-height: 1.2; margin: 0 0 14px; letter-spacing: -0.02em; }

.toc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 20px; margin: 24px 0; font-size: 15px; }
.toc strong { display: block; margin-bottom: 4px; }
.toc ol { margin: 0; padding-left: 20px; }

.callout { border-radius: var(--radius); padding: 14px 18px; margin: 18px 0; border: 1px solid var(--border); background: var(--surface-2); }
.callout > strong:first-child { display: block; margin-bottom: 4px; }
.callout.tip { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.callout.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.callout.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.callout.note { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 30%, transparent); }

code { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
pre { background: var(--code-bg); color: var(--code-text); padding: 16px 18px; border-radius: var(--radius); overflow-x: auto; font-size: 14px; line-height: 1.6; margin: 16px 0; }
pre code { background: none; padding: 0; color: inherit; font-size: inherit; }

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

.formula { text-align: center; font-family: "Cambria Math", "STIX Two Math", Georgia, serif; font-size: 1.15rem; padding: 14px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); margin: 16px 0; }

/* ---- pipeline diagram ---- */
.flow { display: flex; flex-wrap: wrap; align-items: stretch; gap: 8px; margin: 18px 0; }
.flow .step { flex: 1 1 120px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 14px; text-align: center; }
.flow .step b { display: block; font-size: 13px; color: var(--primary); }
.flow .arrow { align-self: center; color: var(--muted); font-weight: 700; }
.flow-label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 20px 0 0; }

/* ---- self check ---- */
details { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; margin: 10px 0; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 8px; }

/* ---- pager ---- */
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 48px; flex-wrap: wrap; }
.pager a { flex: 1 1 240px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; color: var(--text); }
.pager a:hover { border-color: var(--primary); text-decoration: none; }
.pager small { display: block; color: var(--muted); font-size: 13px; }
.pager .next { text-align: right; }

/* ---- lab ---- */
.lab { max-width: 1080px; padding-top: 40px; }
.lab-grid { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) { .lab-grid { grid-template-columns: minmax(0, 1fr); } }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel h2 { font-size: 1.05rem; margin: 0 0 12px; }
.field { margin-bottom: 14px; }
.field label { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field label output { color: var(--primary); font-variant-numeric: tabular-nums; }
.field input[type="range"] { width: 100%; accent-color: var(--primary); }
.field textarea, .field input[type="text"], .field select {
  width: 100%; font: inherit; font-size: 15px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; }
.chip:hover { border-color: var(--primary); }
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.stat b { font-variant-numeric: tabular-nums; }
.result { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 10px 0; background: var(--bg); }
.result header { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.result header b { color: var(--text); }
.bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 6px 0 8px; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); }
.result p { margin: 0; font-size: 14px; }
mark { background: color-mix(in srgb, var(--warn) 30%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
.muted { color: var(--muted); }
.terms { font-size: 13px; color: var(--muted); }
.terms code { font-size: 12px; }

/* ---- table of contents, repeated on every page ---- */
.doc { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 40px; align-items: start; }
.doc > main { min-width: 0; }
.doc .lesson, .doc .lab { max-width: none; }
.doc .home .hero { padding-top: 40px; }
.site-toc { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; padding: 40px 0 24px; font-size: 14px; }
.site-toc ul { list-style: none; margin: 0 0 6px; padding: 0; }
.site-toc li { margin: 0; }
.site-toc a { display: block; padding: 5px 10px; border-radius: 8px; color: var(--muted); line-height: 1.4; }
.site-toc a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.site-toc a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.toc-title { font-weight: 700; margin: 0 0 8px; padding: 0 10px; }
.toc-group { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 16px 0 4px; padding: 0 10px; }
.toc-sections { margin: 4px 0 8px 12px !important; border-left: 1px solid var(--border); }
.toc-sections a { font-size: 13px; padding: 3px 10px; }
.lab-grid > div { min-width: 0; }
@media (max-width: 1100px) { .lab-grid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 900px) {
  .doc { grid-template-columns: 1fr; gap: 0; }
  .site-toc { position: static; max-height: none; padding: 20px 0 0; border-bottom: 1px solid var(--border); }
  .toc-sections { display: none; }
}

/* ---- narrow screens: a header that wraps, a compact table of contents ---- */
.brand { white-space: nowrap; }
@media (max-width: 640px) {
  .site-header .wrap { height: auto; min-height: 56px; flex-wrap: wrap; gap: 4px 16px; padding-top: 10px; padding-bottom: 10px; }
  .site-header nav { margin-left: 0; gap: 4px 14px; font-size: 13px; }
  .site-toc { padding-top: 14px; padding-bottom: 10px; }
  .site-toc .toc-group { display: none; }
  .site-toc ul { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 6px; }
  .site-toc a { padding: 3px 10px; border: 1px solid var(--border); border-radius: 999px; font-size: 13px; background: var(--surface); }
  .lesson h1, .hero h1 { overflow-wrap: anywhere; }
}
