:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel2: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --accent2: #f0883e;
  --green: #3fb950;
  --red: #f85149;
  --purple: #bc8cff;
  --yellow: #e3b341;
}
* { box-sizing: border-box; }
html { font-size: 16px; }
/* Defensive base case: ANY <pre>/<code> anywhere on the page is contained
   and scrollable by default, even ones that don't go through the named
   .code-panel/.notes-panel/.jupyter-panel pipelines (e.g. bare markdown
   fenced blocks like <pre><code class="language-python">). More specific
   rules below only need to add padding/color, not re-declare overflow. */
pre {
  overflow-x: auto; white-space: pre; max-width: 100%;
}
code {
  overflow-wrap: break-word; word-break: break-word;
}
pre code {
  overflow-wrap: normal; word-break: normal;
}
body {
  margin: 0; font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text);
}
main { max-width: 1900px; margin: 0 auto; padding: 28px 48px 90px; }

/* ---------- sidebar (all pages, manually collapsible) ---------- */
.sidebar-toggle {
  position: fixed; top: 16px; left: 12px; z-index: 40;
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); font-size: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: left .2s ease;
}
.sidebar-toggle::before { content: "\203A"; }
html[data-sidebar="open"] .sidebar-toggle { left: 250px; }
html[data-sidebar="open"] .sidebar-toggle::before { content: "\2039"; }
.site-sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 264px; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--border); padding: 18px 0 30px; z-index: 30;
  transform: translateX(-100%); transition: transform .2s ease;
}
html[data-sidebar="open"] .site-sidebar { transform: translateX(0); }
.site-sidebar .brand {
  display: block; padding: 0 20px 14px; margin-bottom: 10px; border-bottom: 1px solid var(--border);
  color: var(--text); text-decoration: none; font-size: 16px; font-weight: 700;
}
.site-sidebar ol { list-style: none; margin: 0; padding: 0 10px; counter-reset: none; }
.site-sidebar li a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px;
  color: var(--text-dim); text-decoration: none; font-size: 13.5px; line-height: 1.4;
}
.site-sidebar li a:hover { background: var(--panel2); color: var(--text); }
.site-sidebar li a.active { background: var(--panel2); color: var(--accent); font-weight: 600; }
.site-sidebar .nav-num {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%; background: #22293a; color: var(--text-dim); font-size: 11px;
}
.site-sidebar li a.active .nav-num { background: var(--accent); color: #04101f; }
.site-main { margin-left: 0; transition: margin-left .2s ease; }

@media (min-width: 981px) {
  html[data-sidebar="open"] .site-main { margin-left: 264px; }
}
@media (max-width: 980px) {
  html[data-sidebar="open"] .site-main::after {
    content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 25;
  }
  main { padding: 60px 20px 80px; }
}

/* ---------- top nav (step pages) ---------- */
header.topbar {
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 20;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
}
.topnav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.topnav a { color: var(--accent); text-decoration: none; font-size: 16px; }
.topnav a:hover { text-decoration: underline; }
.nav-arrows { display: flex; align-items: center; gap: 16px; }
.nav-prev.disabled, .nav-next.disabled { color: var(--text-dim); opacity: .4; }
.step-counter { color: var(--text-dim); font-size: 15px; font-family: 'Cascadia Code', Consolas, monospace; }

/* ---------- index page ---------- */
.site-title { margin: 0 0 8px; font-size: 30px; }
.site-subtitle { color: var(--text-dim); font-size: 15px; max-width: 800px; margin: 0; line-height: 1.6; }
.step-list {
  list-style: none; margin: 28px 0 0; padding: 0; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 12px;
}
.step-list li { margin: 0; }
.step-list a {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px; height: 100%;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: 15.5px;
}
.step-list a:hover { border-color: var(--accent); }

/* ---------- step title ---------- */
h1 {
  font-size: 28px; font-weight: 600; margin: 22px 0 18px; line-height: 1.6;
}
.step-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #04101f;
  font-weight: 700; font-size: 14px; margin-right: 10px; vertical-align: middle;
}

/* ---------- diagram ---------- */
.diagram-section { margin-bottom: 20px; }
.diagram-svg-wrap {
  background: #0a0e14; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; display: flex; justify-content: center; overflow: auto;
}
.diagram-svg-wrap svg { width: 100%; height: auto; max-width: 1760px; }
.diagram-placeholder { color: var(--text-dim); font-size: 14px; padding: 40px; text-align: center; }
.diagram-caption { font-size: 13.5px; color: var(--text-dim); margin-top: 10px; text-align: center; }

/* ---------- step info / prose (full-bleed, matching the diagram width) ---------- */
.step-info code.blk {
  display: block; background: #0a0e14; border: 1px solid var(--border); border-radius: 6px;
  padding: 14px 18px; font-family: 'Cascadia Code', Consolas, monospace; font-size: 18px;
  color: #d2a8ff; white-space: pre; overflow-x: auto; margin: 12px 0;
}
.shape-line { font-family: 'Cascadia Code', Consolas, monospace; font-size: 18px; margin: 10px 0; }
.shape-line .tag { display: inline-block; padding: 4px 11px; border-radius: 4px; background: #1f2937; color: var(--green); border: 1px solid var(--border); }
.step-info p { font-size: 20px; line-height: 1.9; color: var(--text); margin: 14px 0; }
code.inline { background: #1f2937; padding: 2px 7px; border-radius: 4px; color: var(--accent2); font-size: 18px; font-family: 'Cascadia Code', Consolas, monospace; }
.step-title code.inline { white-space: nowrap; }

.aside {
  margin: 16px 0; padding: 18px 24px; border-radius: 6px; font-size: 18px; line-height: 1.85;
  border-left: 4px solid var(--yellow); background: #241d10;
}
.aside b { color: var(--yellow); }
.aside.evidence { border-left-color: var(--green); background: #0f2415; }
.aside.evidence b { color: var(--green); }
.aside.warn { border-left-color: var(--red); background: #2a1414; }
.aside.warn b { color: var(--red); }
.aside ul { margin: 10px 0 0; padding-left: 22px; }
.aside li { margin: 6px 0; }

.code-panel {
  background: #0a0e14; border: 1px solid var(--border); border-radius: 8px;
  margin: 18px 0; overflow-x: auto;
}
.code-panel .code-title {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px;
  padding: 11px 20px; border-bottom: 1px solid var(--border); background: var(--panel2);
  font-size: 15.5px; color: var(--text-dim); font-family: 'Cascadia Code', Consolas, monospace;
}
.code-panel .code-title b { color: var(--accent); font-weight: 600; }
.code-panel pre {
  margin: 0; padding: 18px 22px; font-family: 'Cascadia Code', Consolas, monospace;
  font-size: 18px; line-height: 1.85; color: #9da5b4; white-space: pre; overflow-x: auto;
}
.code-panel .hl {
  display: block; margin: 0 -22px; padding: 2px 19px;
  background: rgba(248,81,73,0.16); border-left: 3px solid var(--red);
  color: #ff9d97; font-weight: 700;
}
.code-panel .dim { opacity: .45; }

.internals {
  margin: 16px 0; padding: 16px 20px; border-radius: 6px; font-size: 17.5px; line-height: 1.75;
  border-left: 4px solid var(--purple); background: #1e1530; color: var(--text);
}
.internals b { color: var(--purple); }

/* ---------- bilingual source panels (Jupyter code + Chinese notes) ---------- */
.source-panel { margin: 32px 0; padding-top: 18px; border-top: 1px dashed var(--border); }
.source-panel h2 { font-size: 21px; margin: 0 0 14px; }
.source-note { font-size: 14.5px; font-weight: 400; color: var(--text-dim); }
.source-note code { font-size: 14px; }

.source-panel details {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  margin-bottom: 12px; overflow: hidden;
}
.source-panel summary {
  cursor: pointer; padding: 12px 16px; font-size: 16px; color: var(--text-dim);
  font-family: 'Cascadia Code', Consolas, monospace; user-select: none;
}
.source-panel summary code { color: var(--accent2); }
.source-panel summary:hover { color: var(--text); }
.source-panel details[open] summary { border-bottom: 1px solid var(--border); }
.source-panel details > *:not(summary) { padding: 0 4px; }

.notes-panel details > div { padding: 6px 20px 16px; }
.notes-panel h2, .notes-panel h3 { color: var(--accent); font-size: 20px; }
.notes-panel p { font-size: 18.5px; line-height: 1.9; }
.notes-panel table { border-collapse: collapse; font-size: 17px; width: 100%; margin: 12px 0; display: block; overflow-x: auto; }
.notes-panel th, .notes-panel td { border: 1px solid var(--border); padding: 10px 14px; text-align: left; white-space: nowrap; }
.notes-panel th { background: var(--panel2); }
.notes-panel pre { background: #0a0e14; border: 1px solid var(--border); border-radius: 6px; padding: 12px 16px; overflow-x: auto; font-size: 17px; white-space: pre; }
.notes-panel code { background: #1f2937; padding: 2px 6px; border-radius: 4px; color: var(--accent2); font-size: 17px; word-break: break-word; }
.notes-panel pre code { background: none; padding: 0; color: inherit; }
.notes-panel blockquote { border-left: 3px solid var(--border); margin: 12px 0; padding: 6px 16px; color: var(--text-dim); }

.jupyter-panel .hl-code { font-size: 18px; padding: 14px 18px; border-radius: 0 0 8px 8px; overflow-x: auto; }
.jupyter-panel .hl-code pre { margin: 0; white-space: pre; }

footer { text-align: center; color: var(--text-dim); font-size: 14px; padding: 34px; }
