
/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Design Tokens ── */
:root {
  /* Brand */
  --primary: #1a3764;
  --primary-light: #2563eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;

  /* Surfaces — Light */
  --bg: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-muted: #f1f5f9;
  --bg-inset: #e8edf4;

  /* Text — Light */
  --text: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;

  /* Border */
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  /* Sidebar */
  --sidebar-bg: #0c1526;
  --sidebar-border: rgba(255,255,255,0.05);
  --sidebar-text: #8da2c0;
  --sidebar-text-active: #ffffff;
  --sidebar-hover: rgba(255,255,255,0.04);
  --sidebar-active: rgba(37,99,235,0.18);
  --sidebar-accent: #60a5fa;
  --sidebar-section: #3d5a80;
  --sidebar-width: 272px;

  /* TOC */
  --toc-width: 232px;

  /* Code */
  --code-bg: #1e293b;
  --code-header: #0f172a;
  --code-text: #e2e8f0;

  /* Blockquote */
  --bq-bg: #eff6ff;
  --bq-border: #3b82f6;

  /* Callouts */
  --cn-note-bg: #eff6ff;       --cn-note-b: #3b82f6;   --cn-note-t: #1d4ed8;
  --cn-tip-bg: #f0fdf4;        --cn-tip-b: #22c55e;    --cn-tip-t: #15803d;
  --cn-warn-bg: #fffbeb;       --cn-warn-b: #f59e0b;   --cn-warn-t: #b45309;
  --cn-imp-bg: #fef2f2;        --cn-imp-b: #ef4444;    --cn-imp-t: #b91c1c;
  --cn-bp-bg: #f0fdfa;         --cn-bp-b: #14b8a6;     --cn-bp-t: #0f766e;
  --cn-arch-bg: #faf5ff;       --cn-arch-b: #a855f7;   --cn-arch-t: #7e22ce;
  --cn-hc-bg: #f0f9ff;         --cn-hc-b: #0ea5e9;     --cn-hc-t: #0369a1;
  --cn-iv-bg: #fff7ed;         --cn-iv-b: #f97316;     --cn-iv-t: #c2410c;
  --cn-sa-bg: #f8fafc;         --cn-sa-b: #94a3b8;     --cn-sa-t: #475569;

  /* Tables */
  --th-bg: #1a3764;   --th-text: #ffffff;
  --tr-alt: #f8fafc;  --tr-hover: #f0f6ff;  --td-border: #e2e8f0;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.07), 0 4px 6px rgba(0,0,0,0.04);

  /* Radius */
  --r-sm: 4px; --r: 8px; --r-lg: 12px; --r-xl: 16px;

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', Consolas, 'Courier New', monospace;

  /* Layout */
  --topbar-h: 56px;
  --content-max: 780px;
  --tx: 150ms cubic-bezier(0.4,0,0.2,1);
}

/* ── Dark Mode ── */
[data-theme="dark"] {
  --bg: #0b1120;  --bg-subtle: #101928;  --bg-muted: #1a2438;  --bg-inset: #243046;
  --text: #f1f5f9;  --text-secondary: #cbd5e1;  --text-muted: #94a3b8;  --text-subtle: #64748b;
  --border: #1e2d45;  --border-strong: #2d3f5a;
  --bq-bg: rgba(59,130,246,0.08);
  --cn-note-bg: rgba(59,130,246,0.08);   --cn-note-t: #93c5fd;
  --cn-tip-bg: rgba(34,197,94,0.08);     --cn-tip-t: #86efac;
  --cn-warn-bg: rgba(245,158,11,0.08);   --cn-warn-t: #fcd34d;
  --cn-imp-bg: rgba(239,68,68,0.08);     --cn-imp-t: #fca5a5;
  --cn-bp-bg: rgba(20,184,166,0.08);     --cn-bp-t: #5eead4;
  --cn-arch-bg: rgba(168,85,247,0.08);   --cn-arch-t: #d8b4fe;
  --cn-hc-bg: rgba(14,165,233,0.08);     --cn-hc-t: #7dd3fc;
  --cn-iv-bg: rgba(249,115,22,0.08);     --cn-iv-t: #fdba74;
  --cn-sa-bg: rgba(148,163,184,0.06);    --cn-sa-t: #94a3b8;
  --th-bg: #1a2d4a;  --th-text: #93c5fd;  --tr-alt: #0f1928;  --tr-hover: #152035;  --td-border: #1e2d45;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.4);
}

/* ── Reset ── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font); font-size: 16px; line-height: 1.75; color: var(--text); background: var(--bg); display: flex; min-height: 100vh; }

/* ── Reading Progress Bar ── */
#reading-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0%;
  background: linear-gradient(90deg, #2563eb, #7c3aed, #06b6d4);
  z-index: 300; transition: width 80ms linear; pointer-events: none;
}

/* ── Left Sidebar ── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-width);
  background: var(--sidebar-bg); border-right: 1px solid var(--sidebar-border);
  display: flex; flex-direction: column; z-index: 100; overflow: hidden;
  transition: transform var(--tx);
}
.sidebar-header {
  padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--sidebar-border); flex-shrink: 0;
}
.sidebar-brand { text-decoration: none; display: flex; flex-direction: column; gap: 0.18rem; }
.sidebar-brand-label {
  font-size: 0.6rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--sidebar-section); display: block;
}
.sidebar-brand-title {
  font-size: 0.82rem; font-weight: 700; color: #fff; line-height: 1.3; display: block;
}
.sidebar-nav {
  overflow-y: auto; flex: 1; padding: 0.5rem 0 2rem;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.08) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ── Sidebar Sections (collapsible) ── */
.nav-section { margin-top: 0.25rem; }
.nav-section-header {
  width: 100%; background: none; border: none; cursor: pointer;
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 1.25rem; color: var(--sidebar-section);
  font-size: 0.65rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  font-family: var(--font); transition: color var(--tx), background var(--tx);
  border-top: 1px solid var(--sidebar-border); margin-top: 0.35rem;
}
.nav-section-header:hover { color: var(--sidebar-accent); background: var(--sidebar-hover); }
.nav-section-icon { font-size: 0.75rem; flex-shrink: 0; }
.nav-section-label { flex: 1; text-align: left; line-height: 1.3; }
.nav-section-arrow {
  font-size: 0.8rem; transition: transform 200ms ease; color: var(--sidebar-section); flex-shrink: 0;
}
.nav-section-arrow.open { transform: rotate(90deg); }
.nav-section-items { display: none; }
.nav-section-items.open { display: block; }

.nav-link {
  display: flex; align-items: baseline; gap: 0.5rem;
  padding: 0.35rem 1.25rem 0.35rem 1.75rem;
  color: var(--sidebar-text); text-decoration: none;
  font-size: 0.815rem; line-height: 1.4;
  border-left: 2px solid transparent;
  transition: background var(--tx), color var(--tx), border-color var(--tx);
}
.nav-link:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-link.active {
  background: var(--sidebar-active); color: var(--sidebar-text-active);
  border-left-color: var(--sidebar-accent); font-weight: 600;
}
.nav-link-title { flex: 1; }
.nav-link-time { font-size: 0.65rem; color: var(--sidebar-section); flex-shrink: 0; font-family: var(--mono); }
.nav-link.active .nav-link-time { color: rgba(255,255,255,0.45); }

/* ── Content Wrapper ── */
.content-wrapper {
  margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column; min-width: 0;
  transition: margin-right var(--tx);
}
body.has-toc .content-wrapper { margin-right: var(--toc-width); }

/* ── Topbar ── */
.topbar {
  position: sticky; top: 0; height: var(--topbar-h);
  background: rgba(255,255,255,0.92); backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  border-bottom: 1px solid var(--border); display: flex; align-items: center;
  padding: 0 1.5rem; gap: 0.75rem; z-index: 50;
}
[data-theme="dark"] .topbar { background: rgba(11,17,32,0.92); }
.menu-toggle {
  display: none; background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 0.4rem; border-radius: var(--r-sm); transition: color var(--tx), background var(--tx);
  flex-shrink: 0; font-size: 1.2rem;
}
.menu-toggle:hover { color: var(--text); background: var(--bg-muted); }
.breadcrumb {
  display: flex; align-items: center; gap: 0.35rem; font-size: 0.78rem;
  color: var(--text-muted); flex: 1; overflow: hidden; white-space: nowrap; min-width: 0;
}
.breadcrumb a { color: var(--accent); text-decoration: none; flex-shrink: 0; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb-sep { color: var(--border-strong); flex-shrink: 0; }
.breadcrumb-section { flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; }
.breadcrumb-current { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.topbar-reading-time { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }
.topbar-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--r-sm);
  color: var(--text-secondary); cursor: pointer; padding: 0.3rem 0.65rem;
  font-size: 0.75rem; font-family: var(--font); display: flex; align-items: center; gap: 0.35rem;
  transition: border-color var(--tx), background var(--tx), color var(--tx); white-space: nowrap;
}
.topbar-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--bg-subtle); }
.search-trigger kbd { font-size: 0.65rem; background: var(--bg-muted); border: 1px solid var(--border-strong); border-radius: 3px; padding: 0.08rem 0.3rem; color: var(--text-muted); font-family: var(--font); }
@media print { .topbar-actions .topbar-btn:not(.print-btn) { display: none; } }

/* ── Article ── */
.article-wrap { max-width: var(--content-max); margin: 0 auto; padding: 2.5rem 2rem 4rem; width: 100%; }
article { font-size: 1rem; line-height: 1.78; }
article h1 {
  font-size: 2rem; font-weight: 800; color: var(--primary); line-height: 1.2;
  margin-bottom: 2rem; letter-spacing: -0.025em;
}
[data-theme="dark"] article h1 { color: #93c5fd; }
article h2 {
  font-size: 1.3rem; font-weight: 700; color: var(--primary);
  margin: 2.75rem 0 0.9rem; padding-bottom: 0.4rem;
  border-bottom: 1.5px solid var(--border); scroll-margin-top: calc(var(--topbar-h) + 1.5rem);
  display: flex; align-items: center; gap: 0.5rem;
}
[data-theme="dark"] article h2 { color: #93c5fd; border-color: var(--border); }
article h3 {
  font-size: 1.05rem; font-weight: 700; color: var(--text);
  margin: 2rem 0 0.6rem; scroll-margin-top: calc(var(--topbar-h) + 1.5rem);
}
article h4 {
  font-size: 0.875rem; font-weight: 700; color: var(--text-secondary);
  margin: 1.5rem 0 0.4rem; letter-spacing: 0.04em; text-transform: uppercase;
}
.heading-anchor {
  opacity: 0; font-size: 0.75em; color: var(--text-subtle); text-decoration: none;
  transition: opacity var(--tx); margin-left: 0.25rem;
}
article h2:hover .heading-anchor, article h3:hover .heading-anchor { opacity: 1; }
article p { margin-bottom: 1.1rem; }
article a { color: var(--accent); text-decoration: none; }
article a:hover { text-decoration: underline; }
article ul, article ol { margin: 0.35rem 0 1.1rem 1.35rem; }
article li { margin-bottom: 0.3rem; }
article li > ul, article li > ol { margin-top: 0.2rem; margin-bottom: 0.2rem; }
article strong { font-weight: 700; }
article em { font-style: italic; }
article code {
  font-family: var(--mono); font-size: 0.83em; background: var(--bg-muted);
  color: #e11d48; padding: 0.13em 0.4em; border-radius: var(--r-sm);
  border: 1px solid var(--border); font-weight: 500;
}
[data-theme="dark"] article code { color: #f9a8d4; background: var(--bg-inset); }
article hr { border: none; border-top: 1px solid var(--border); margin: 2.5rem 0; }

/* ── Code Blocks ── */
.code-block-wrapper {
  position: relative; margin: 1.5rem 0; border-radius: var(--r-lg);
  overflow: hidden; box-shadow: var(--shadow-md);
}
.code-block-header {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--code-header); padding: 0.45rem 1rem;
}
.code-lang-badge {
  font-size: 0.68rem; font-family: var(--mono); color: #60a5fa;
  letter-spacing: 0.05em; font-weight: 500; text-transform: lowercase;
}
.copy-btn {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  color: #94a3b8; border-radius: var(--r-sm); padding: 0.2rem 0.6rem;
  font-size: 0.68rem; cursor: pointer; transition: all var(--tx); font-family: var(--font); font-weight: 500;
}
.copy-btn:hover { background: rgba(255,255,255,0.12); color: #fff; border-color: rgba(255,255,255,0.2); }
.copy-btn.copied { color: #4ade80; border-color: #4ade80; background: rgba(74,222,128,0.08); }
.code-block-wrapper pre {
  margin: 0; overflow-x: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent; background: var(--code-bg);
}
.code-block-wrapper pre::-webkit-scrollbar { height: 4px; }
.code-block-wrapper pre::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }
.code-block-wrapper pre code {
  display: block; padding: 1.1rem 1rem; font-family: var(--mono); font-size: 0.82rem;
  line-height: 1.7; background: transparent; border: none; color: var(--code-text); white-space: pre;
  border-radius: 0;
}

/* ── Mermaid Diagrams ── */
.mermaid-wrapper {
  margin: 1.75rem 0; border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--bg-subtle); overflow: hidden; box-shadow: var(--shadow);
}
.mermaid-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.45rem 0.85rem; border-bottom: 1px solid var(--border);
  background: var(--bg-muted);
}
.mermaid-label {
  font-size: 0.67rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-muted);
}
.mermaid-fullscreen-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--r-sm);
  color: var(--text-muted); cursor: pointer; padding: 0.18rem 0.5rem; font-size: 0.7rem;
  transition: all var(--tx); font-family: var(--font);
}
.mermaid-fullscreen-btn:hover { border-color: var(--accent); color: var(--accent); }
.mermaid-body { padding: 1.5rem; text-align: center; overflow-x: auto; }
.mermaid-body .mermaid { display: inline-block; max-width: 100%; }

/* ── Tables ── */
.table-wrapper {
  overflow-x: auto; margin: 1.5rem 0; border-radius: var(--r-lg);
  border: 1px solid var(--td-border); box-shadow: var(--shadow);
}
article table { width: 100%; border-collapse: collapse; font-size: 0.875rem; line-height: 1.5; }
article thead { position: sticky; top: 0; }
article thead tr { background: var(--th-bg); }
article thead th {
  padding: 0.7rem 1rem; text-align: left; font-weight: 600;
  color: var(--th-text); font-size: 0.78rem; letter-spacing: 0.03em; white-space: nowrap;
}
article tbody tr:nth-child(even) { background: var(--tr-alt); }
article tbody tr:hover { background: var(--tr-hover); transition: background 80ms; }
article td { padding: 0.6rem 1rem; border-bottom: 1px solid var(--td-border); vertical-align: top; }
article td code { font-size: 0.78em; }

/* ── Callout Boxes ── */
.callout {
  margin: 1.5rem 0; border-radius: var(--r-lg); border-left: 4px solid;
  overflow: hidden; box-shadow: var(--shadow-sm);
}
.callout-header {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.55rem 1rem; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em;
}
.callout-body { padding: 0.75rem 1rem; font-size: 0.93rem; line-height: 1.65; }
.callout-body p { margin-bottom: 0.5rem; }
.callout-body p:last-child { margin-bottom: 0; }
.callout-body code { font-size: 0.82em; }

.callout-note    { border-color: var(--cn-note-b);  background: var(--cn-note-bg); }
.callout-note    .callout-header { color: var(--cn-note-t);  background: rgba(59,130,246,0.08); }
.callout-tip     { border-color: var(--cn-tip-b);   background: var(--cn-tip-bg); }
.callout-tip     .callout-header { color: var(--cn-tip-t);   background: rgba(34,197,94,0.08); }
.callout-warning { border-color: var(--cn-warn-b);  background: var(--cn-warn-bg); }
.callout-warning .callout-header { color: var(--cn-warn-t);  background: rgba(245,158,11,0.08); }
.callout-important { border-color: var(--cn-imp-b); background: var(--cn-imp-bg); }
.callout-important .callout-header { color: var(--cn-imp-t); background: rgba(239,68,68,0.08); }
.callout-best-practice { border-color: var(--cn-bp-b); background: var(--cn-bp-bg); }
.callout-best-practice .callout-header { color: var(--cn-bp-t); background: rgba(20,184,166,0.08); }
.callout-arch    { border-color: var(--cn-arch-b);  background: var(--cn-arch-bg); }
.callout-arch    .callout-header { color: var(--cn-arch-t);  background: rgba(168,85,247,0.08); }
.callout-healthcare { border-color: var(--cn-hc-b); background: var(--cn-hc-bg); }
.callout-healthcare .callout-header { color: var(--cn-hc-t); background: rgba(14,165,233,0.08); }
.callout-interview { border-color: var(--cn-iv-b);  background: var(--cn-iv-bg); }
.callout-interview .callout-header { color: var(--cn-iv-t);  background: rgba(249,115,22,0.08); }
.callout-see-also { border-color: var(--cn-sa-b);  background: var(--cn-sa-bg); }
.callout-see-also .callout-header { color: var(--cn-sa-t);  background: rgba(148,163,184,0.06); }

/* Generic blockquote (no callout detected) */
article blockquote {
  margin: 1.5rem 0; padding: 0.85rem 1.2rem; background: var(--bq-bg);
  border-left: 4px solid var(--bq-border); border-radius: 0 var(--r) var(--r) 0;
  color: var(--text-secondary); font-size: 0.94rem;
}
article blockquote p { margin-bottom: 0; }
article blockquote strong { color: var(--primary); }
[data-theme="dark"] article blockquote strong { color: #93c5fd; }

/* ── Chapter Navigation ── */
.chapter-nav {
  display: flex; justify-content: space-between; gap: 1rem;
  margin-top: 3.5rem; padding-top: 2rem; border-top: 1px solid var(--border);
}
.chapter-nav a {
  display: flex; flex-direction: column; gap: 0.3rem; padding: 1rem 1.2rem;
  border: 1px solid var(--border); border-radius: var(--r-lg); text-decoration: none;
  color: var(--text); flex: 1; max-width: 48%;
  transition: border-color var(--tx), background var(--tx), box-shadow var(--tx);
}
.chapter-nav a:hover {
  border-color: var(--accent); background: var(--bg-subtle);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.08);
}
.nav-dir { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); font-weight: 700; }
.nav-title { font-size: 0.875rem; font-weight: 600; line-height: 1.35; }
.next-chapter { text-align: right; margin-left: auto; }

/* ── Page Footer ── */
.page-footer {
  padding: 1rem 2rem; max-width: var(--content-max); margin: 0 auto; width: 100%;
  font-size: 0.72rem; color: var(--text-muted);
  display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid var(--border); gap: 1rem;
}

/* ── Right TOC Sidebar ── */
.toc-sidebar {
  position: fixed; top: var(--topbar-h); right: 0; bottom: 0;
  width: var(--toc-width); padding: 1.5rem 1.25rem 2rem;
  overflow-y: auto; border-left: 1px solid var(--border); background: var(--bg);
  scrollbar-width: thin; scrollbar-color: var(--border) transparent; display: none;
}
body.has-toc .toc-sidebar { display: block; }
.toc-sidebar::-webkit-scrollbar { width: 3px; }
.toc-sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }
.toc-heading {
  font-size: 0.65rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 0.75rem; display: block;
}
.toc-list { list-style: none; display: flex; flex-direction: column; gap: 0.05rem; }
.toc-item-h2 .toc-link { font-size: 0.78rem; font-weight: 500; }
.toc-item-h3 .toc-link { font-size: 0.74rem; padding-left: 0.85rem; }
.toc-link {
  display: block; padding: 0.28rem 0.5rem; color: var(--text-muted);
  text-decoration: none; border-left: 2px solid transparent; line-height: 1.4;
  transition: color var(--tx), border-color var(--tx); border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.toc-link:hover { color: var(--text-secondary); border-left-color: var(--border-strong); }
.toc-link.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; background: rgba(37,99,235,0.05); }
.toc-back-top {
  display: block; margin-top: 1.5rem; font-size: 0.72rem; color: var(--text-subtle);
  text-decoration: none; padding: 0.3rem 0.5rem; border-radius: var(--r-sm);
  transition: color var(--tx), background var(--tx);
}
.toc-back-top:hover { color: var(--accent); background: var(--bg-muted); }

/* ── Landing Page Hero ── */
.hero {
  background: linear-gradient(140deg, #0c1526 0%, #0f2044 35%, #0f3460 65%, #0d4a8a 100%);
  color: #fff; padding: 4rem 2.5rem 3.5rem; position: relative; overflow: hidden;
}
.hero::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse 70% 60% at 70% 50%, rgba(96,165,250,0.12) 0%, transparent 70%);
}
.hero-inner { max-width: 680px; position: relative; z-index: 1; }
.hero-badges { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.hero-badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.25rem 0.7rem; border-radius: 99px; font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.04em; border: 1px solid rgba(255,255,255,0.2);
}
.hero-badge-version { background: rgba(37,99,235,0.35); color: #93c5fd; }
.hero-badge-edition { background: rgba(16,185,129,0.25); color: #6ee7b7; }
.hero h1 {
  font-size: 2.6rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.15;
  margin-bottom: 0.85rem; color: #fff !important; border: none !important; padding: 0 !important;
}
.hero-subtitle { font-size: 1rem; opacity: 0.8; line-height: 1.6; margin-bottom: 1rem; max-width: 580px; }
.hero-description { font-size: 0.83rem; opacity: 0.55; line-height: 1.6; max-width: 560px; }
.hero-actions { display: flex; gap: 0.75rem; margin-top: 2rem; flex-wrap: wrap; }
.hero-btn {
  display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.7rem 1.35rem;
  border-radius: var(--r-lg); font-size: 0.85rem; font-weight: 600; font-family: var(--font);
  text-decoration: none; cursor: pointer; border: none; transition: all var(--tx);
}
.hero-btn-primary { background: #2563eb; color: #fff; box-shadow: 0 1px 3px rgba(37,99,235,0.4); }
.hero-btn-primary:hover { background: #1d4ed8; box-shadow: 0 4px 12px rgba(37,99,235,0.4); transform: translateY(-1px); }
.hero-btn-secondary { background: rgba(255,255,255,0.1); color: #fff; border: 1px solid rgba(255,255,255,0.2); }
.hero-btn-secondary:hover { background: rgba(255,255,255,0.18); transform: translateY(-1px); }

/* ── Stats Bar ── */
.stats-bar {
  background: var(--bg-subtle); border-bottom: 1px solid var(--border);
  padding: 1.25rem 2.5rem; display: flex; justify-content: center;
  gap: 2.5rem; flex-wrap: wrap;
}
.stat { text-align: center; }
.stat-value { display: block; font-size: 1.65rem; font-weight: 800; color: var(--primary); line-height: 1; }
[data-theme="dark"] .stat-value { color: #93c5fd; }
.stat-label { display: block; font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--text-muted); margin-top: 0.3rem; }

/* ── Publication Cards ── */
.pub-cards-section { max-width: 940px; margin: 0 auto; padding: 2.5rem 2rem 0; }
.pub-cards-heading { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 1rem; }
.pub-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.pub-card {
  display: flex; flex-direction: column; padding: 1.35rem;
  border: 1px solid var(--border); border-radius: var(--r-xl);
  background: var(--bg); text-decoration: none; color: var(--text);
  transition: border-color var(--tx), box-shadow var(--tx), transform var(--tx);
  box-shadow: var(--shadow-sm);
}
.pub-card:hover { border-color: var(--accent); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.pub-card.current { border-color: var(--accent); background: rgba(37,99,235,0.03); }
.pub-card-icon { font-size: 1.5rem; margin-bottom: 0.75rem; }
.pub-card-title { font-size: 0.9rem; font-weight: 700; color: var(--text); margin-bottom: 0.35rem; line-height: 1.3; }
.pub-card-subtitle { font-size: 0.78rem; color: var(--text-secondary); line-height: 1.5; margin-bottom: 0.85rem; flex: 1; }
.pub-card-meta { display: flex; gap: 0.75rem; font-size: 0.7rem; color: var(--text-muted); margin-bottom: 0.85rem; flex-wrap: wrap; }
.pub-card-meta span { display: flex; align-items: center; gap: 0.2rem; }
.pub-card-cta {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.78rem; font-weight: 600; color: var(--accent);
  padding: 0.4rem 0.85rem; border: 1px solid rgba(37,99,235,0.25);
  border-radius: var(--r); background: rgba(37,99,235,0.05);
  transition: all var(--tx); align-self: flex-start;
}
.pub-card:hover .pub-card-cta { background: var(--accent); color: #fff; border-color: var(--accent); }
.pub-card.current .pub-card-cta::after { content: ' (current)'; font-weight: 400; opacity: 0.65; }

/* ── Chapter Listing (Index) ── */
.chapters-section { max-width: 940px; margin: 0 auto; padding: 2.5rem 2rem 5rem; }
.part-divider {
  display: flex; align-items: center; gap: 0.75rem; margin: 2.25rem 0 0.85rem;
}
.part-divider-badge {
  font-size: 0.65rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: #fff; background: var(--primary); padding: 0.22rem 0.6rem; border-radius: var(--r-sm);
  white-space: nowrap;
}
[data-theme="dark"] .part-divider-badge { background: #1a3764; color: #93c5fd; }
.part-divider-title { font-size: 0.92rem; font-weight: 700; color: var(--text); }
.part-divider-line { flex: 1; height: 1px; background: var(--border); }
.chapter-grid { display: flex; flex-direction: column; gap: 0.55rem; }
.chapter-card {
  display: flex; align-items: flex-start; gap: 1rem; padding: 0.95rem 1.1rem;
  border: 1px solid var(--border); border-radius: var(--r-lg); text-decoration: none;
  color: var(--text); background: var(--bg);
  transition: border-color var(--tx), background var(--tx), box-shadow var(--tx), transform var(--tx);
  box-shadow: var(--shadow-sm);
}
.chapter-card:hover { border-color: var(--accent); background: var(--bg-subtle); box-shadow: var(--shadow-md); transform: translateX(3px); }
.chapter-num {
  font-family: var(--mono); font-size: 0.68rem; font-weight: 700; color: var(--accent);
  background: rgba(37,99,235,0.08); padding: 0.2rem 0.45rem; border-radius: var(--r-sm);
  flex-shrink: 0; margin-top: 0.15rem; min-width: 2.2rem; text-align: center;
}
.chapter-info { flex: 1; min-width: 0; }
.chapter-card-title { font-size: 0.925rem; font-weight: 700; margin-bottom: 0.2rem; line-height: 1.3; }
.chapter-card-desc { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.5; margin-bottom: 0.3rem; }
.chapter-card-meta { font-size: 0.68rem; color: var(--text-muted); font-family: var(--mono); }
.chapter-card-arrow { color: var(--border-strong); font-size: 0.9rem; flex-shrink: 0; margin-top: 0.3rem; transition: color var(--tx); }
.chapter-card:hover .chapter-card-arrow { color: var(--accent); }

/* ── Index Topbar (no breadcrumb section) ── */
.index-topbar-spacer { flex: 1; }

/* ── Search Modal ── */
.search-modal {
  position: fixed; inset: 0; z-index: 500; display: flex; align-items: flex-start;
  justify-content: center; padding-top: 10vh;
}
.search-modal[hidden] { display: none; }
.search-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(4px); }
.search-box {
  position: relative; z-index: 1; width: 100%; max-width: 580px; margin: 0 1rem;
  background: var(--bg); border-radius: var(--r-xl); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.search-input-row {
  display: flex; align-items: center; gap: 0.65rem; padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}
.search-input-row svg { color: var(--text-muted); flex-shrink: 0; }
#search-input {
  flex: 1; background: none; border: none; outline: none; font-size: 1rem;
  color: var(--text); font-family: var(--font); caret-color: var(--accent);
}
#search-input::placeholder { color: var(--text-subtle); }
.search-esc-badge {
  font-size: 0.68rem; background: var(--bg-muted); border: 1px solid var(--border-strong);
  border-radius: 4px; padding: 0.1rem 0.35rem; color: var(--text-muted); font-family: var(--font);
  flex-shrink: 0;
}
.search-results { max-height: 380px; overflow-y: auto; }
.search-no-results { padding: 2rem; text-align: center; color: var(--text-muted); font-size: 0.875rem; }
.search-result-item {
  display: block; padding: 0.85rem 1rem; text-decoration: none; color: var(--text);
  border-bottom: 1px solid var(--border); transition: background var(--tx); cursor: pointer;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover, .search-result-item.selected { background: var(--bg-muted); }
.search-result-item.selected { border-left: 3px solid var(--accent); padding-left: calc(1rem - 3px); }
.search-result-section { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 0.2rem; }
.search-result-title { font-size: 0.875rem; font-weight: 600; margin-bottom: 0.2rem; line-height: 1.3; }
.search-result-excerpt { font-size: 0.78rem; color: var(--text-secondary); line-height: 1.5; }
mark { background: rgba(250,204,21,0.35); color: inherit; border-radius: 2px; }
.search-footer {
  padding: 0.55rem 1rem; border-top: 1px solid var(--border);
  font-size: 0.68rem; color: var(--text-muted); display: flex; gap: 1rem;
}
.search-footer kbd {
  background: var(--bg-muted); border: 1px solid var(--border-strong);
  border-radius: 3px; padding: 0.08rem 0.28rem; font-size: 0.65rem; font-family: var(--font);
}

/* ── Mermaid Fullscreen Modal ── */
.diagram-modal {
  position: fixed; inset: 0; z-index: 600; display: flex; align-items: center; justify-content: center;
}
.diagram-modal[hidden] { display: none; }
.diagram-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.8); }
.diagram-modal-box {
  position: relative; z-index: 1; background: var(--bg-subtle); border-radius: var(--r-xl);
  max-width: 95vw; max-height: 90vh; overflow: auto; padding: 1.5rem;
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.diagram-modal-close {
  position: absolute; top: 0.75rem; right: 0.75rem; background: var(--bg-muted);
  border: 1px solid var(--border); border-radius: var(--r-sm); width: 2rem; height: 2rem;
  cursor: pointer; color: var(--text-secondary); font-size: 1rem; display: flex;
  align-items: center; justify-content: center; transition: all var(--tx); z-index: 2;
}
.diagram-modal-close:hover { background: var(--bg-inset); color: var(--text); }
.diagram-modal-content { min-width: 320px; text-align: center; }
.diagram-modal-content svg { max-width: 100%; height: auto; }

/* ── Back to Top ── */
.back-to-top {
  position: fixed; bottom: 2rem; right: 2rem; width: 2.5rem; height: 2.5rem;
  background: var(--primary); color: #fff; border: none; border-radius: 50%;
  cursor: pointer; font-size: 1rem; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md); transition: all var(--tx); z-index: 80;
  opacity: 0; pointer-events: none;
}
.back-to-top.visible { opacity: 1; pointer-events: auto; }
.back-to-top:hover { background: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
body.has-toc .back-to-top { right: calc(var(--toc-width) + 1.5rem); }

/* ── Index Footer ── */
.index-footer {
  max-width: 940px; margin: 0 auto; padding: 1.5rem 2rem;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 0.6rem;
}
.index-footer-main { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.index-footer-brand { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); }
.index-footer-meta { font-size: 0.72rem; color: var(--text-muted); }
.index-footer-disclaimer { font-size: 0.7rem; color: var(--text-subtle); line-height: 1.6; }

/* ── Accessibility ── */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── Print ── */
@media print {
  .sidebar, .topbar, .toc-sidebar, .chapter-nav, .page-footer, #reading-progress,
  .search-modal, .diagram-modal, .back-to-top { display: none !important; }
  .content-wrapper { margin: 0 !important; }
  .article-wrap { max-width: 100%; padding: 0; }
  body.has-toc .content-wrapper { margin-right: 0 !important; }
}

/* ── Responsive ── */
@media (max-width: 1200px) {
  body.has-toc .content-wrapper { margin-right: 0; }
  body.has-toc .toc-sidebar { display: none; }
  .back-to-top { right: 1.5rem; }
}
@media (max-width: 900px) {
  .pub-cards { grid-template-columns: 1fr; gap: 0.75rem; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; transition: transform 200ms ease, box-shadow 200ms ease; }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 30px rgba(0,0,0,0.35); }
  .content-wrapper { margin-left: 0 !important; }
  .menu-toggle { display: flex; }
  .hero h1 { font-size: 1.85rem; }
  .hero { padding: 2.5rem 1.25rem 2rem; }
  .stats-bar { gap: 1.25rem; padding: 1rem 1.25rem; }
  .article-wrap { padding: 1.5rem 1rem 3rem; }
  .chapter-nav { flex-direction: column; }
  .chapter-nav a { max-width: 100%; }
  .page-footer { flex-direction: column; gap: 0.35rem; text-align: center; }
  .chapters-section, .pub-cards-section { padding-left: 1rem; padding-right: 1rem; }
  .hero-actions { flex-direction: column; }
  .hero-btn { justify-content: center; }
  .topbar-reading-time { display: none; }
}
