:root {
  --bg: #fbfaf6;
  --surface: #ffffff;
  --text: #15171c;
  --muted: #646a75;
  --border: #e6e2d8;
  --accent: #0f7a5a;
  --accent-text: #ffffff;
  --accent-soft: #e3f1eb;
  --ok: #1f8a4c;
  --ok-soft: #e3f4ea;
  --bad: #c0392b;
  --bad-soft: #fbe9e7;
  --code-bg: #f4f2eb;
  --ink-card: #15171c;
  --ink-card-text: #f4f2eb;
  --c1: #0f7a5a;
  --c2: #e08a1e;
  --c3: #4a5bd4;
  --shadow: 0 1px 2px rgb(20 20 10 / 0.04), 0 8px 24px -12px rgb(20 20 10 / 0.12);
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f12;
    --surface: #15181d;
    --text: #ecebe6;
    --muted: #9aa0aa;
    --border: #262a31;
    --accent: #4fd1a5;
    --accent-text: #08130f;
    --accent-soft: #12302a;
    --ok: #5cc98a;
    --ok-soft: #173325;
    --bad: #ff7b6b;
    --bad-soft: #3a1d1a;
    --code-bg: #0a0c0f;
    --ink-card: #e9f3ee;
    --ink-card-text: #10261e;
    --c1: #4fd1a5;
    --c2: #f4b23e;
    --c3: #8b9cff;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 10px 30px -14px rgb(0 0 0 / 0.6);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.7 var(--sans); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
h1, h2, h3 { line-height: 1.2; font-family: var(--serif); font-weight: 600; letter-spacing: -0.015em; }
h1 { font-size: clamp(2rem, 5vw, 2.9rem); margin: 0.2em 0 0.5em; letter-spacing: -0.025em; }
h2 { font-size: 1.45rem; margin-top: 0; }
h3 { font-size: 1.2rem; margin: 1.8em 0 0.3em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
code, kbd { font: 0.86em var(--mono); background: var(--code-bg); padding: 0.12em 0.4em; border-radius: 5px; border: 1px solid var(--border); }
kbd { box-shadow: 0 1px 0 var(--border); }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- header / footer ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center; gap: 0.8rem; flex-wrap: wrap;
  padding: 0.75rem max(16px, calc((100vw - 1120px) / 2));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.brand {
  display: inline-flex; align-items: center; gap: 0.55rem;
  font: 600 1.15rem var(--serif); letter-spacing: -0.01em; color: var(--text); text-decoration: none;
}
.brand svg { width: 28px; height: 28px; }
.brand .mark-bg { fill: var(--accent); }
@media (prefers-color-scheme: dark) { .brand .mark-bg { fill: #0f7a5a; } }
.header-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
main { max-width: 760px; margin: 0 auto; padding: 0 16px 4rem; }
main.home { max-width: 1120px; }
.site-footer {
  max-width: 1120px; margin: 0 auto; padding: 2rem 16px 3rem;
  border-top: 1px solid var(--border); font-size: 0.85rem; color: var(--muted);
}
.site-footer p { max-width: 640px; margin: 0; }

/* ---------- buttons ---------- */
button, select, input, textarea { font: inherit; color: inherit; }
button, .button {
  font-size: 0.92rem; font-weight: 500; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.55em 1em; cursor: pointer; text-decoration: none; color: var(--text); display: inline-block;
  transition: border-color 0.2s, background 0.2s, transform 0.2s var(--ease), box-shadow 0.2s;
}
button:hover:not(:disabled), .button:hover { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }
button:active:not(:disabled), .button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: default; }
button.primary, .button.primary {
  background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600;
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.15) inset, 0 6px 16px -8px color-mix(in srgb, var(--accent) 80%, transparent);
}
button.primary:hover:not(:disabled), .button.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
button.run { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--accent); }
.pill { border-radius: 999px; font-size: 0.8rem; padding: 0.38em 0.9em; }
.pill.link { text-decoration: none; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.pill.ready { border-color: var(--ok); color: var(--ok); }
.pill.ready::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); margin-right: 0.45em; vertical-align: 0.12em; }

/* ---------- home ---------- */
.kicker {
  margin: 0 0 0.6rem; font: 600 0.72rem var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent);
}
.hero {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: clamp(1.5rem, 5vw, 4rem); align-items: center;
  padding: clamp(2rem, 7vw, 5.5rem) 0 clamp(2rem, 5vw, 4rem);
}
.hero h1 { font-size: clamp(2.5rem, 6.4vw, 4.6rem); line-height: 1.02; margin: 0 0 1.4rem; font-weight: 500; letter-spacing: -0.035em; }
.hero h1 em { color: var(--accent); font-style: italic; }
.lede { font-size: 1.12rem; color: var(--muted); max-width: 34rem; }
.hero .actions { margin-top: 1.6rem; }
.hero .button { padding: 0.75em 1.3em; font-size: 0.98rem; border-radius: 12px; }
.stats { display: flex; gap: clamp(1.2rem, 4vw, 2.4rem); margin-top: 2.4rem; padding-top: 1.4rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.stat strong { display: block; font: 500 1.7rem/1 var(--serif); letter-spacing: -0.02em; }
.stat span { font-size: 0.8rem; color: var(--muted); }

.hero-fig {
  margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow); overflow: hidden;
}
.fig-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 0.8rem;
  padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--border); font: 0.75rem var(--mono); color: var(--muted);
}
.fig-bar code { background: none; border: 0; padding: 0; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fig-bar code::before { content: "In [1]  "; color: var(--muted); }
.readout { white-space: nowrap; font-variant-numeric: tabular-nums; }
.hero-plot { display: block; width: 100%; aspect-ratio: 1 / 0.82; }
.hero-fig figcaption { padding: 0.65rem 0.9rem 0.8rem; font-size: 0.8rem; color: var(--muted); border-top: 1px solid var(--border); }

.feature-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin: 1rem 0 4.5rem; }
.feature { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 1.4rem 1.3rem 1.2rem; }
.feature .icon {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px;
  background: var(--accent-soft); color: var(--accent);
}
.feature .icon svg { width: 21px; height: 21px; }
.feature h3 { margin: 1rem 0 0.3rem; font-size: 1.15rem; }
.feature p { margin: 0; font-size: 0.93rem; color: var(--muted); line-height: 1.6; }

.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1.6rem; }
.section-head h2 { font-size: clamp(1.8rem, 4vw, 2.5rem); font-weight: 500; letter-spacing: -0.03em; margin: 0; }
.path-progress { min-width: 220px; text-align: right; }
.progress.home { max-width: none; margin-top: 0.35rem; }

.part {
  display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 1.5rem;
  padding: 1.6rem 0; border-top: 1px solid var(--border);
}
.part-label span { font: 600 0.72rem var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.part-label h3 { margin: 0.3rem 0 0; font-size: 1.35rem; }
.lesson-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
.lesson-list a {
  display: grid; grid-template-columns: 2.4rem 1fr auto; align-items: center; gap: 0.75rem; height: 100%;
  padding: 0.85rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  color: var(--text); text-decoration: none;
  transition: border-color 0.2s, transform 0.25s var(--ease), box-shadow 0.25s;
}
.lesson-list a:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); transform: translateY(-2px); box-shadow: var(--shadow); }
.lesson-list .num {
  display: grid; place-items: center; width: 2.4rem; height: 2.4rem; border-radius: 10px;
  background: var(--code-bg); border: 1px solid var(--border); color: var(--muted); font: 600 0.8rem var(--mono);
}
.lesson-list a:hover .num { color: var(--accent); }
.lesson-list a.done .num { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.lesson-list .title { font-size: 0.98rem; line-height: 1.35; font-weight: 500; }
.lesson-list .meta { font: 0.75rem var(--mono); color: var(--muted); white-space: nowrap; }
.lesson-list a.done .meta { color: var(--ok); }

.cta {
  display: flex; justify-content: space-between; align-items: center; gap: 2rem; flex-wrap: wrap;
  margin-top: 4rem; padding: clamp(1.6rem, 4vw, 2.6rem); border-radius: 22px;
  background: var(--ink-card); color: var(--ink-card-text);
}
.cta > div { max-width: 36rem; }
.cta .kicker { color: color-mix(in srgb, var(--ink-card-text) 60%, transparent); }
.cta h2 { font-size: clamp(1.6rem, 3.4vw, 2.2rem); font-weight: 500; letter-spacing: -0.025em; margin: 0 0 0.5rem; }
.cta p { margin: 0; opacity: 0.75; }
.cta .button.primary { background: var(--ink-card-text); color: var(--ink-card); border-color: transparent; box-shadow: none; padding: 0.8em 1.4em; }
.cta .button.primary:hover { background: color-mix(in srgb, var(--ink-card-text) 85%, var(--accent)); }

/* ---------- lesson ---------- */
.crumbs { font-size: 0.9rem; padding-top: 1.4rem; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.eyebrow { font: 600 0.72rem var(--mono); text-transform: uppercase; letter-spacing: 0.12em; color: var(--accent); margin: 2rem 0 0; }
article > h1 { font-weight: 500; font-size: clamp(2.1rem, 5.5vw, 3.1rem); line-height: 1.08; letter-spacing: -0.03em; margin-bottom: 1.2rem; }
.prose { font-size: 1.04rem; }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li { margin: 0.35em 0; }
.prose li::marker { color: var(--accent); }
.prose strong { font-weight: 650; }
.formula {
  margin: 1.4rem 0; padding: 1rem 1.2rem; text-align: center; overflow-x: auto;
  background: var(--accent-soft); border-radius: 12px; font: 600 1rem var(--serif);
}
.nest { font-size: 0.92rem; margin: 1.2rem 0; }
.nest div { border: 1px solid var(--border); border-radius: 12px; padding: 0.55rem 0.8rem 0.65rem; background: var(--surface); }
.nest div div { margin-top: 0.45rem; background: var(--accent-soft); border-color: transparent; }
.nest div div div { background: var(--surface); border-color: var(--border); }
.nest div div div div { background: var(--accent); color: var(--accent-text); font-weight: 600; border-color: transparent; }
table.grid { width: 100%; border-collapse: collapse; font-size: 0.92rem; display: block; overflow-x: auto; }
table.grid th, table.grid td { text-align: left; vertical-align: top; padding: 0.55em 0.7em; border-bottom: 1px solid var(--border); }
table.grid th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
details.setup { margin: 0.5rem 0 1.2rem; font-size: 0.88rem; color: var(--muted); }
details.setup summary, .exercise summary { cursor: pointer; }
details.setup pre, pre.solution { font: 0.82rem/1.55 var(--mono); background: var(--code-bg); border: 1px solid var(--border); padding: 0.9rem; border-radius: 10px; overflow-x: auto; color: var(--text); }

/* ---------- code cells (notebook style) ---------- */
.cell { margin: 1.3rem 0 1.6rem; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
textarea.code {
  display: block; width: 100%; min-height: 3rem; resize: vertical; overflow: hidden;
  font: 0.86rem/1.6 var(--mono); tab-size: 4; white-space: pre; overflow-x: auto;
  padding: 0.9rem 1rem; background: var(--code-bg); border: 0; border-bottom: 1px solid var(--border); border-radius: 0; color: var(--text);
}
textarea.code:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.cell-bar {
  display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; padding: 0.45rem 0.5rem;
  background: var(--surface);
}
.cell-bar button { padding: 0.38em 0.85em; font-size: 0.84rem; border-radius: 8px; }
.cell-output { margin: 0; padding: 0.7rem 1rem 0.8rem; border-top: 1px solid var(--border); overflow-x: auto; position: relative; }
.cell-output::before { content: "Out"; display: block; font: 600 0.68rem var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.3rem; }
.cell-output:empty { display: none; }
.cell-output pre { margin: 0.2rem 0; font: 0.82rem/1.55 var(--mono); white-space: pre-wrap; word-break: break-word; }
.cell-output pre.error { color: var(--bad); background: var(--bad-soft); padding: 0.7rem; border-radius: 8px; }
.cell-output img { max-width: 100%; height: auto; display: block; margin: 0.4rem 0; border-radius: 8px; background: #fff; }
.table-wrap { overflow-x: auto; }
.table-wrap table { border-collapse: collapse; font: 0.8rem var(--mono); }
.table-wrap th, .table-wrap td { padding: 0.3em 0.7em; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.table-wrap thead th { color: var(--muted); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 1.4rem 1.4rem 1.3rem; margin: 2.2rem 0; box-shadow: var(--shadow); }
.card > h2 { font-size: 1.35rem; font-weight: 600; margin-bottom: 0.6rem; }
.card .cell { box-shadow: none; }
.card .cell-bar { background: var(--surface); }
.exercise { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); background: linear-gradient(var(--surface), var(--surface)) padding-box; position: relative; }
.card > textarea.code { margin-top: 1rem; border: 1px solid var(--border); border-radius: 12px 12px 0 0; }
.card > .cell-bar { border: 1px solid var(--border); border-top: 0; border-radius: 0 0 12px 12px; }
.card > .cell-output { margin-top: 0.6rem; border: 1px solid var(--border); border-radius: 12px; }
.exercise details { margin-top: 0.8rem; font-size: 0.92rem; }
.exercise summary { color: var(--accent); }
.verdict { margin-top: 0.8rem; padding: 0.75rem 0.95rem; border-radius: 10px; font-weight: 600; white-space: pre-wrap; }
.verdict.pass { background: var(--ok-soft); color: var(--ok); }
.verdict.fail { background: var(--bad-soft); color: var(--bad); }
.field { margin: 0.9rem 0; }
.field label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.3rem; }
.field input, .field textarea {
  width: 100%; padding: 0.65em 0.8em; border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
}
.field textarea { resize: vertical; line-height: 1.5; }
.field :focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1rem; }
.ai-output { white-space: pre-wrap; margin-top: 1rem; }
.ai-output:not(:empty), .ai-output.busy { padding: 1rem 1.1rem; background: var(--bg); border-left: 3px solid var(--accent); border-radius: 8px; }
.ai-output.busy:empty::after { content: "Thinking…"; color: var(--muted); }
.tutor-mode { margin: 0.8rem 0 0; font-weight: 600; }

/* ---------- quiz ---------- */
.quiz ol { padding-left: 1.2rem; }
.quiz li { margin-bottom: 1.4rem; }
.quiz li::marker { font-family: var(--mono); color: var(--muted); }
.quiz .q { margin: 0 0 0.5rem; font-weight: 600; }
.options { display: grid; gap: 0.45rem; }
.option { text-align: left; border-radius: 10px; padding: 0.65em 0.95em; }
.option.right { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.why { margin: 0.5rem 0 0; font-size: 0.9rem; }
.why.pass { color: var(--ok); }
.why.fail { color: var(--bad); }

/* ---------- resources ---------- */
.resources { list-style: none; padding: 0; margin: 0; display: grid; gap: 1rem; }
.resource a { font-weight: 600; }
.resource .provider { color: var(--muted); font-size: 0.9rem; }
.resource .tags { display: inline-flex; gap: 0.3rem; margin-left: 0.4rem; flex-wrap: wrap; }
.tag { font-size: 0.7rem; font-weight: 600; padding: 0.15em 0.6em; border-radius: 99px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.tag.cert { background: var(--ok-soft); color: var(--ok); }
.resource .note { display: block; font-size: 0.9rem; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 1.2rem 0; }
.chip { border-radius: 99px; font-size: 0.85rem; padding: 0.35em 0.9em; }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; font-size: 0.95rem; margin-top: 3rem;
}
.pager a {
  display: block; padding: 1rem 1.1rem; border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
  text-decoration: none; color: var(--text); font-weight: 500; transition: border-color 0.2s;
}
.pager a:hover { border-color: var(--accent); }
.pager a:last-child { text-align: right; }

/* ---------- dialog / progress ---------- */
dialog {
  max-width: min(480px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text); padding: 1.5rem; box-shadow: 0 30px 80px -20px rgb(0 0 0 / 0.45);
}
dialog::backdrop { background: rgb(10 12 10 / 0.5); backdrop-filter: blur(3px); }
.model-option { display: grid; gap: 0.15rem; width: 100%; text-align: left; margin: 0.6rem 0; padding: 0.9rem 1rem; border-radius: 12px; }
.model-option span { font-size: 0.85rem; }
.progress { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: 1rem; }
.progress .bar { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width 0.4s var(--ease); }
.progress.home .bar { background: var(--accent); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; padding-top: 2rem; }
  .feature-grid { grid-template-columns: 1fr; margin-bottom: 3rem; }
  .part { grid-template-columns: 1fr; gap: 0.8rem; }
}
@media (max-width: 640px) {
  body { font-size: 16px; }
  .site-header { position: static; }
  .lesson-list { grid-template-columns: 1fr; }
  .path-progress { text-align: left; min-width: 0; width: 100%; }
  .pager { grid-template-columns: 1fr; }
  .pager a:last-child { text-align: left; }
  .header-actions .pill { font-size: 0.75rem; padding: 0.35em 0.7em; }
  .fig-bar code::before { content: ""; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
