/* ============================================================
   RustPath stylesheet
   Light theme by default, dim mode via [data-theme="dim"].
   Prose is serif, code and UI chrome are monospace / sans.
   ============================================================ */

:root {
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --bg: #f7f4ee;
  --bg-soft: #f1ede3;
  --surface: #fffdf9;
  --ink: #28241f;
  --muted: #6d675e;
  --faint: #9b958a;
  --border: #e6e0d3;
  --border-strong: #d3cab8;

  --accent: #b8451f;
  --accent-strong: #97351a;
  --accent-soft: #f6e3da;
  --accent-ink: #8a3418;

  --gold: #b8860b;
  --gold-soft: #f7edd2;

  --ok: #3c7a3f;
  --ok-soft: #e4efe2;
  --warn: #96590b;
  --warn-soft: #f7ecd7;
  --err: #b3382c;
  --err-soft: #f8e4e0;

  --code-bg: #f3efe5;
  --code-border: #e0d9c8;
  --code-ink: #33302a;
  --syn-kw: #a1451c;
  --syn-str: #55763c;
  --syn-num: #2f5f8f;
  --syn-com: #8d8778;
  --syn-type: #1f6e6e;
  --syn-fn: #8a5a1f;
  --syn-attr: #8a6a1f;
  --syn-op: #5a544b;

  --shadow: 0 1px 2px rgb(35 28 16 / 0.05), 0 10px 28px rgb(35 28 16 / 0.08);
  --shadow-soft: 0 1px 2px rgb(35 28 16 / 0.04), 0 4px 14px rgb(35 28 16 / 0.05);
  --radius: 14px;
  --radius-sm: 9px;
}

[data-theme="dim"] {
  --bg: #171512;
  --bg-soft: #1e1b17;
  --surface: #221f1a;
  --ink: #ece7de;
  --muted: #a69f92;
  --faint: #7d766a;
  --border: #343029;
  --border-strong: #4a443a;

  --accent: #e06b3e;
  --accent-strong: #ea7d51;
  --accent-soft: #3a261d;
  --accent-ink: #f0926a;

  --gold: #d9ad4e;
  --gold-soft: #3a3018;

  --ok: #85c089;
  --ok-soft: #22301f;
  --warn: #d19a4e;
  --warn-soft: #332817;
  --err: #e07b6f;
  --err-soft: #3a211d;

  --code-bg: #12110e;
  --code-border: #2c2823;
  --code-ink: #ddd6c9;
  --syn-kw: #ef8354;
  --syn-str: #a3c47c;
  --syn-num: #82b1d4;
  --syn-com: #7d7668;
  --syn-type: #6cc1b4;
  --syn-fn: #d9b36a;
  --syn-attr: #c2a24b;
  --syn-op: #b5aea1;

  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 12px 30px rgb(0 0 0 / 0.45);
  --shadow-soft: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 14px rgb(0 0 0 / 0.3);
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.65;
  transition: background-color 0.25s ease, color 0.25s ease;
}

::selection { background: var(--accent-soft); color: var(--accent-ink); }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }

button {
  font-family: var(--sans);
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.shell {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
}

/* ---------- header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 28px;
  height: 62px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.brand-mark { width: 30px; height: 30px; display: block; }

.site-nav {
  display: flex;
  gap: 4px;
  font-family: var(--sans);
  font-size: 14px;
  margin-right: auto;
}

.site-nav a {
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 999px;
  font-weight: 500;
}

.site-nav a:hover { color: var(--ink); background: var(--bg-soft); }
.site-nav a.active { color: var(--accent-ink); background: var(--accent-soft); }

.header-controls { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  transition: color 0.15s, border-color 0.15s, transform 0.15s;
}

.icon-btn:hover { color: var(--ink); border-color: var(--border-strong); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.off { color: var(--faint); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}

.chip-progress { color: var(--accent-ink); background: var(--accent-soft); border-color: transparent; }
.chip-new { color: var(--ok); background: var(--ok-soft); border-color: transparent; }

/* ---------- footer ---------- */

.site-footer {
  margin-top: 90px;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  font-family: var(--sans);
}

.footer-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 36px;
  padding: 40px 0 26px;
}

.footer-brand { font-family: var(--serif); font-weight: 700; font-size: 19px; }
.footer-h { font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 8px; }
.footer-note { font-size: 13.5px; color: var(--muted); line-height: 1.6; margin: 0; }
.footer-base {
  padding: 16px 0 22px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--faint);
}

/* ---------- generic buttons & cards ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s, color 0.15s;
}

.btn svg { width: 15px; height: 15px; }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-soft); }
.btn-primary:hover { background: var(--accent-strong); color: #fff; }

.btn-ghost { background: transparent; color: var(--ink); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--bg-soft); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

/* ---------- home hero ---------- */

.hero {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 44px;
  align-items: center;
  padding: 64px 0 40px;
}

.hero-kicker {
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.hero-kicker::before {
  content: "";
  width: 26px;
  height: 2px;
  background: var(--accent);
  display: inline-block;
}

.hero h1 {
  font-size: clamp(34px, 4.6vw, 52px);
  line-height: 1.08;
  letter-spacing: -0.015em;
  font-weight: 700;
  margin: 0 0 18px;
}

.hero h1 em { font-style: italic; color: var(--accent); }

.hero-lede {
  font-size: 19px;
  color: var(--muted);
  max-width: 54ch;
  margin: 0 0 26px;
}

.hero-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 30px; }

.hero-stats { display: flex; gap: 34px; font-family: var(--sans); flex-wrap: wrap; }

.stat b { display: block; font-size: 24px; font-weight: 700; color: var(--ink); letter-spacing: -0.02em; line-height: 1.2; }
.stat span { font-size: 12.5px; color: var(--muted); }

.hero-side { display: flex; flex-direction: column; gap: 18px; }

.featured-card { padding: 24px; position: relative; overflow: hidden; }
.featured-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(320px 140px at 85% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%);
  pointer-events: none;
}

.featured-top { display: flex; gap: 16px; align-items: center; }
.featured-title { font-family: var(--sans); font-size: 12px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
.featured-name { font-size: 23px; font-weight: 700; margin: 0 0 4px; }
.featured-desc { font-size: 14.5px; color: var(--muted); margin: 0 0 14px; line-height: 1.55; }
.featured-cta { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }

.ring { position: relative; flex: none; }
.ring svg { display: block; }
.ring-bg { stroke: var(--border); }
.ring-val { stroke: var(--accent); transition: stroke-dashoffset 0.7s cubic-bezier(0.3, 0.7, 0.3, 1); }
.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--sans);
}
.ring-label b { font-size: 15px; }
.ring-label span { font-size: 9.5px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }

.newlist { padding: 18px 22px 14px; }
.newlist-head {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.newlist-head .dot { width: 7px; height: 7px; border-radius: 999px; background: var(--accent); animation: pulse 2.2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.45; transform: scale(0.8); } }

.newlist ul { list-style: none; margin: 0; padding: 0; }
.newlist li + li { border-top: 1px dashed var(--border); }
.newlist a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 2px;
  color: var(--ink);
  font-size: 14.5px;
}
.newlist a:hover .nl-title { color: var(--accent); }
.nl-series { font-family: var(--sans); font-size: 11px; font-weight: 600; color: var(--muted); background: var(--bg-soft); border: 1px solid var(--border); padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.nl-title { flex: 1; min-width: 0; }
.nl-date { font-family: var(--sans); font-size: 11.5px; color: var(--faint); white-space: nowrap; }

/* ---------- section headers ---------- */

.section { padding: 34px 0 10px; }
.section-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 22px; }
.section-head h2 { font-size: 26px; margin: 0; letter-spacing: -0.01em; }
.section-head .sub { font-family: var(--sans); font-size: 13.5px; color: var(--muted); }

/* ---------- series library grid ---------- */

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 22px;
  padding-bottom: 20px;
}

.series-card {
  display: flex;
  flex-direction: column;
  padding: 24px;
  color: var(--ink);
  position: relative;
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.series-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--border-strong); }

.series-art {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent-ink);
  margin-bottom: 16px;
}
.series-art svg { width: 24px; height: 24px; }

.series-card h3 { font-size: 20px; margin: 0 0 6px; }
.series-tag { font-size: 14px; color: var(--muted); margin: 0 0 16px; line-height: 1.5; flex: 1; }

.series-meta {
  display: flex;
  gap: 14px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.series-meta span { display: inline-flex; align-items: center; gap: 5px; }
.series-meta svg, .chip svg { width: 13px; height: 13px; flex: none; }

.series-progress { font-family: var(--sans); font-size: 12.5px; }
.series-progress .bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 7px;
}
.series-progress .bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--gold)));
  border-radius: 999px;
  transition: width 0.7s cubic-bezier(0.3, 0.7, 0.3, 1);
}
.series-progress .row { display: flex; justify-content: space-between; color: var(--muted); }
.series-progress .row b { color: var(--ink); }

.series-needs { margin-top: 12px; font-family: var(--sans); font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.series-needs svg { width: 12px; height: 12px; }

/* ---------- series page ---------- */

.series-hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 34px;
  align-items: center;
  padding: 46px 0 30px;
}

.crumbs { font-family: var(--sans); font-size: 12.5px; color: var(--faint); margin-bottom: 14px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { margin: 0 7px; color: var(--border-strong); }

.series-hero h1 { font-size: clamp(28px, 3.6vw, 40px); margin: 0 0 10px; letter-spacing: -0.015em; }
.series-hero .desc { color: var(--muted); font-size: 17px; max-width: 62ch; margin: 0 0 18px; }
.series-facts { display: flex; gap: 12px; flex-wrap: wrap; }

.series-progress-box { text-align: center; font-family: var(--sans); }
.series-progress-box .pct { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 10px; }
.series-progress-box .pct b { color: var(--ink); }
.series-continue { margin-top: 12px; }

.map-card { padding: 26px 26px 18px; margin-bottom: 34px; }
.map-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 6px; }
.map-head h2 { font-size: 21px; margin: 0; }
.map-head .sub { font-family: var(--sans); font-size: 12.5px; color: var(--muted); }
.map-scroll { overflow-x: auto; padding: 10px 2px 6px; }
.map-svg { display: block; margin: 0 auto; width: 100%; height: auto; min-width: 560px; }

.g-node { cursor: pointer; }
.g-node circle.body {
  fill: var(--surface);
  stroke: var(--border-strong);
  stroke-width: 1.5;
  transition: stroke 0.15s, filter 0.15s;
}
.g-node text.num {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
  fill: var(--muted);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}
.g-node text.lbl {
  font-family: var(--sans);
  font-size: 10.5px;
  fill: var(--muted);
  text-anchor: middle;
  pointer-events: none;
}
.g-node.done circle.body { fill: var(--accent); stroke: var(--accent); }
.g-node.done text.num { fill: #fff; }
.g-node.avail circle.body { stroke: var(--accent); }
.g-node.avail text.num { fill: var(--accent-ink); }
.g-node:hover circle.body { stroke: var(--accent); filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 45%, transparent)); }
.g-node.dragging { cursor: grabbing; }

.g-edge { fill: none; stroke: var(--border-strong); stroke-width: 1.6; }
.g-edge.hot { stroke: var(--accent); stroke-width: 2.2; }
.g-edge.done-edge { stroke: color-mix(in srgb, var(--accent) 55%, var(--border-strong)); }

.map-legend {
  display: flex;
  gap: 18px;
  font-family: var(--sans);
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 10px;
  flex-wrap: wrap;
}
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.map-legend i { width: 11px; height: 11px; border-radius: 999px; display: inline-block; }
.legend-done { background: var(--accent); }
.legend-avail { background: var(--surface); border: 1.5px solid var(--accent); }
.legend-open { background: var(--surface); border: 1.5px solid var(--border-strong); }

/* ---------- chapter list ---------- */

.ch-list { display: flex; flex-direction: column; gap: 10px; padding-bottom: 30px; }

.ch-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.ch-row:hover { border-color: var(--border-strong); box-shadow: var(--shadow-soft); transform: translateX(2px); }

.ch-check {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1.7px solid var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  background: var(--surface);
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.1s;
}

.ch-check:hover { transform: scale(1.12); }
.ch-row.done .ch-check { background: var(--accent); border-color: var(--accent); color: #fff; }
.ch-check svg { width: 13px; height: 13px; }

.ch-num { font-family: var(--mono); font-size: 12px; color: var(--faint); width: 26px; text-align: right; }

.ch-main { flex: 1; min-width: 0; }
.ch-title { font-family: var(--sans); font-weight: 600; font-size: 15px; }
.ch-row.done .ch-title { color: var(--muted); }
.ch-sub { font-family: var(--sans); font-size: 12px; color: var(--faint); margin-top: 2px; }
.ch-arrow { color: var(--faint); flex: none; transition: transform 0.15s, color 0.15s; }
.ch-row:hover .ch-arrow { transform: translateX(3px); color: var(--accent); }
.ch-arrow svg { width: 15px; height: 15px; display: block; }

/* ---------- chapter page layout ---------- */

.chapter-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 56px;
  padding: 40px 0 0;
  align-items: start;
}

.chapter-head { margin-bottom: 8px; }
.chapter-head h1 { font-size: clamp(28px, 3.4vw, 38px); line-height: 1.15; letter-spacing: -0.015em; margin: 0 0 12px; }
.chapter-meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 26px; }

.mark-done-bar { margin: 26px 0 8px; }

/* ---------- table of contents ---------- */

.toc {
  position: sticky;
  top: 86px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  font-family: var(--sans);
  font-size: 13px;
  padding: 4px 0 20px;
}

.toc-title { font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); margin: 0 0 10px 12px; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a {
  display: block;
  padding: 5px 12px;
  color: var(--muted);
  border-left: 2px solid var(--border);
  line-height: 1.4;
  transition: color 0.15s, border-color 0.15s;
}
.toc a:hover { color: var(--ink); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }

/* ---------- prose ---------- */

.prose { font-size: 17.5px; }
.prose p { margin: 0 0 18px; }
.prose h2 {
  font-size: 25px;
  letter-spacing: -0.01em;
  margin: 44px 0 16px;
  padding-top: 10px;
  scroll-margin-top: 90px;
  position: relative;
}
.prose h2 .anchor {
  opacity: 0;
  margin-left: 8px;
  color: var(--faint);
  font-size: 0.7em;
  transition: opacity 0.15s;
}
.prose h2:hover .anchor { opacity: 1; }
.prose code, .inline-code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 5px;
  padding: 1.5px 6px;
  white-space: nowrap;
}
.prose ul, .prose ol { margin: 0 0 18px; padding-left: 26px; }
.prose li { margin-bottom: 6px; }
.prose strong { font-weight: 700; }

.callout {
  display: flex;
  gap: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  padding: 14px 16px;
  margin: 22px 0;
  font-size: 15.5px;
}
.callout svg { width: 17px; height: 17px; flex: none; margin-top: 4px; }
.callout.tip { border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); background: var(--ok-soft); }
.callout.tip svg { color: var(--ok); }
.callout.warn { border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); background: var(--warn-soft); }
.callout.warn svg { color: var(--warn); }
.callout.info svg { color: var(--accent); }
.callout p { margin: 0; }
.callout p + p { margin-top: 8px; }

/* ---------- static code blocks ---------- */

.codeblock { margin: 22px 0; }
.codeblock .cb-caption {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.codeblock pre, .play-out pre {
  margin: 0;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius-sm);
  padding: 15px 18px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.62;
  color: var(--code-ink);
  tab-size: 4;
}

/* CodeMirror runMode token colors (shared with playground theme) */
.cm-keyword { color: var(--syn-kw); font-weight: 500; }
.cm-string, .cm-string-2 { color: var(--syn-str); }
.cm-number { color: var(--syn-num); }
.cm-comment { color: var(--syn-com); font-style: italic; }
.cm-type, .cm-variable-3, .cm-builtin { color: var(--syn-type); }
.cm-def, .cm-variable-2 { color: var(--syn-fn); }
.cm-meta, .cm-attribute { color: var(--syn-attr); }
.cm-operator { color: var(--syn-op); }
.cm-atom { color: var(--syn-num); }

/* ---------- playground ---------- */

.playground {
  margin: 26px 0;
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--code-bg);
  box-shadow: var(--shadow-soft);
}

.pg-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--code-border);
  background: color-mix(in srgb, var(--code-bg) 55%, var(--surface));
}

.pg-dots { display: flex; gap: 6px; }
.pg-dots i { width: 10px; height: 10px; border-radius: 999px; background: var(--border-strong); }
.pg-dots i:first-child { background: var(--accent); opacity: 0.75; }

.pg-caption { font-family: var(--sans); font-size: 12.5px; font-weight: 600; color: var(--muted); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pg-status {
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--bg-soft);
  color: var(--faint);
  white-space: nowrap;
}
.pg-status.ok { background: var(--ok-soft); color: var(--ok); }
.pg-status.err { background: var(--err-soft); color: var(--err); }
.pg-status.busy { background: var(--accent-soft); color: var(--accent-ink); animation: pulse 1.2s infinite; }
.pg-status.cached { background: var(--gold-soft); color: var(--gold); }

.playground .CodeMirror {
  height: auto;
  background: var(--code-bg);
  color: var(--code-ink);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.62;
  padding: 6px 4px;
}
.playground .CodeMirror-scroll { max-height: 460px; }
.playground .CodeMirror-gutters {
  background: var(--code-bg);
  border-right: 1px solid var(--code-border);
}
.playground .CodeMirror-linenumber { color: var(--faint); font-size: 12px; }
.playground .CodeMirror-cursor { border-left: 2px solid var(--accent); }
.playground .CodeMirror-selected { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.playground .CodeMirror-focused .CodeMirror-selected { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.playground .CodeMirror-matchingbracket { color: var(--accent) !important; outline: 1px solid var(--accent); }

.pg-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--code-border);
  background: color-mix(in srgb, var(--code-bg) 55%, var(--surface));
  font-family: var(--sans);
  flex-wrap: wrap;
}

.pg-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.pg-btn:hover { background: var(--bg-soft); }
.pg-btn svg { width: 12px; height: 12px; }
.pg-btn.run { background: var(--accent); border-color: var(--accent); color: #fff; }
.pg-btn.run:hover { background: var(--accent-strong); }
.pg-hint { font-size: 11px; color: var(--faint); margin-left: auto; }

.play-out { border-top: 1px dashed var(--code-border); display: none; }
.play-out.show { display: block; }
.play-out .po-tag {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 8px 18px 0;
}
.play-out pre { border: none; border-radius: 0; margin: 0; padding-top: 8px; background: color-mix(in srgb, var(--code-bg) 70%, var(--surface)); }
.play-out .out-err { color: var(--err); }
.play-out .out-warn { color: var(--warn); }
.play-out .out-dim { color: var(--faint); }
.play-out .po-note { font-family: var(--sans); font-size: 11.5px; color: var(--faint); padding: 0 18px 10px; }

/* ---------- diff widget ---------- */

.diffwidget { margin: 26px 0; border: 1px solid var(--code-border); border-radius: var(--radius); overflow: hidden; background: var(--code-bg); box-shadow: var(--shadow-soft); }

.diff-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--code-border);
  background: color-mix(in srgb, var(--code-bg) 55%, var(--surface));
  font-family: var(--sans);
}
.diff-caption { font-size: 12.5px; font-weight: 600; color: var(--muted); flex: 1; }
.diff-state { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }

.diff-apply {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 13px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s, transform 0.12s;
}
.diff-apply:hover { background: var(--accent-strong); }
.diff-apply:active { transform: scale(0.96); }
.diff-apply svg { width: 12px; height: 12px; }
.diffwidget[data-state="after"] .diff-apply { background: var(--surface); color: var(--ink); border: 1px solid var(--border-strong); }

.diff-body { padding: 10px 0; font-family: var(--mono); font-size: 13.5px; line-height: 1.62; overflow-x: auto; }

.dl {
  display: flex;
  gap: 0;
  min-height: 1.62em;
  padding: 0 18px 0 0;
  max-height: 1.62em;
  overflow: hidden;
  white-space: pre;
  transition: max-height 0.38s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.38s, padding 0.38s, background 0.8s;
}
.dl .dl-sign { width: 34px; flex: none; text-align: center; color: var(--faint); user-select: none; }
.dl .dl-code { color: var(--code-ink); }
.dl.del .dl-sign { color: var(--err); }
.dl.add .dl-sign { color: var(--ok); }

.dl.add { max-height: 0; min-height: 0; opacity: 0; padding-top: 0; padding-bottom: 0; }
.dl.add .dl-code { display: inline-block; min-width: max-content; }

.diffwidget[data-state="after"] .dl.add { max-height: 1.62em; min-height: 1.62em; opacity: 1; }
.diffwidget[data-state="after"] .dl.del { max-height: 0; min-height: 0; opacity: 0; }

.dl.flash-add { background: var(--ok-soft); }
.dl.flash-del { background: var(--err-soft); }

/* ---------- prev / next ---------- */

.pn-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 48px 0 10px; }
.pn-card {
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.pn-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-soft); }
.pn-card.next { text-align: right; }
.pn-tag { font-family: var(--sans); font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); display: block; margin-bottom: 5px; }
.pn-title { font-family: var(--sans); font-weight: 600; font-size: 15px; }
.pn-card.disabled { opacity: 0.45; pointer-events: none; }

/* ---------- comments ---------- */

.comments { margin: 56px 0 30px; border-top: 1px solid var(--border); padding-top: 30px; }
.comments-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.comments-head h2 { font-size: 22px; margin: 0; }
.comments-count { font-family: var(--sans); font-size: 12.5px; color: var(--muted); }
.comments-mode { font-family: var(--sans); font-size: 11.5px; color: var(--gold); background: var(--gold-soft); display: none; border-radius: 999px; padding: 3px 10px; margin-left: auto; }
.comments.local-mode .comments-mode { display: inline-block; }

.c-form { margin: 18px 0 26px; }
.c-form .fields { display: flex; gap: 10px; margin-bottom: 10px; }
.c-input, .c-textarea {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 12px;
  transition: border-color 0.15s;
}
.c-input:focus, .c-textarea:focus { border-color: var(--accent); outline: none; }
.c-input { width: 220px; }
.c-textarea { width: 100%; min-height: 84px; resize: vertical; line-height: 1.5; }
.c-form .actions { display: flex; align-items: center; gap: 12px; }
.c-form .hint { font-family: var(--sans); font-size: 11.5px; color: var(--faint); }

.c-thread { margin-bottom: 20px; }
.c-item { display: flex; gap: 12px; }
.c-avatar {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 14px;
}
.c-body { flex: 1; min-width: 0; }
.c-meta { display: flex; align-items: baseline; gap: 10px; font-family: var(--sans); margin-bottom: 3px; }
.c-author { font-weight: 600; font-size: 13.5px; }
.c-time { font-size: 11.5px; color: var(--faint); }
.c-text { font-size: 15px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.c-reply-btn {
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  padding: 4px 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.c-reply-btn:hover { color: var(--accent); }
.c-reply-btn svg { width: 12px; height: 12px; }
.c-children { margin-left: 46px; margin-top: 16px; display: flex; flex-direction: column; gap: 16px; border-left: 2px solid var(--border); padding-left: 18px; }
.c-empty { color: var(--faint); font-style: italic; margin: 18px 0; }

/* ---------- celebration ---------- */

.celebrate {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.celebrate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 18px;
  padding: 26px 40px 20px;
  text-align: center;
  font-family: var(--sans);
  animation: card-pop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes card-pop { from { transform: scale(0.6) translateY(18px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }
.celebrate-card svg.tick { width: 84px; height: 84px; display: block; margin: 0 auto 10px; }
.tick .tick-circle { stroke-dasharray: 220; stroke-dashoffset: 220; animation: draw 0.6s 0.05s ease-out forwards; }
.tick .tick-mark { stroke-dasharray: 60; stroke-dashoffset: 60; animation: draw 0.4s 0.5s ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.celebrate-title { font-weight: 700; font-size: 16px; margin: 0 0 3px; }
.celebrate-sub { font-size: 12.5px; color: var(--muted); margin: 0; }

.confetti {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  animation: confetti-fly 0.95s cubic-bezier(0.15, 0.6, 0.4, 1) forwards;
}
@keyframes confetti-fly {
  0% { transform: translate(0, 0) rotate(0deg) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(0.5); opacity: 0; }
}

.celebrate.out .celebrate-card { animation: card-fade 0.3s forwards; }
@keyframes card-fade { to { transform: translateY(8px); opacity: 0; } }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  font-family: var(--sans);
  font-size: 13.5px;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- view transition ---------- */

.view-enter { animation: view-in 0.35s ease-out both; }
@keyframes view-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- responsive ---------- */

@media (max-width: 1080px) {
  .chapter-layout { grid-template-columns: 1fr; }
  .toc { display: none; }
}

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; padding-top: 40px; gap: 26px; }
  .series-hero { grid-template-columns: 1fr; }
  .series-progress-box { display: flex; align-items: center; gap: 18px; text-align: left; }
  .series-progress-box .pct { margin-top: 0; }
  .footer-grid { grid-template-columns: 1fr; gap: 22px; }
  .pn-nav { grid-template-columns: 1fr; }
  .c-children { margin-left: 20px; }
}

@media (max-width: 640px) {
  .shell { width: calc(100% - 32px); }
  .site-nav { display: none; }
  .header-inner { gap: 12px; }
  .chip-progress { display: none; }
  .prose { font-size: 16.5px; }
  .hero h1 { font-size: 34px; }
  .c-form .fields { flex-direction: column; }
  .c-input { width: 100%; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .confetti { display: none; }
}
