:root {
  --bg: #090d16;
  --bg-elev: #0f1624;
  --bg-card: #131c2e;
  --bg-code: #0c1220;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #e2e8f0;
  --text-strong: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --accent-bg: rgba(56, 189, 248, 0.1);
  --emerald: #34d399;
  --amber: #fbbf24;
  --rose: #fb7185;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  --header-h: 64px;
  --sidebar-w: 272px;
  --toc-w: 230px;
}

html[data-theme="light"] {
  --bg: #f8fafc;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-code: #0f172a;
  --border: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.22);
  --text: #334155;
  --text-strong: #0f172a;
  --text-muted: #64748b;
  --accent: #0284c7;
  --accent-2: #4f46e5;
  --accent-bg: rgba(2, 132, 199, 0.08);
  --shadow: 0 12px 35px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 24px); }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
}
code, pre {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  backdrop-filter: blur(14px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem; gap: 1rem;
}
.brand { display: flex; align-items: center; gap: 0.7rem; color: var(--text-strong); font-weight: 700; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(56, 189, 248, 0.3);
}
.ver-pill {
  font-size: 0.72rem; font-weight: 600; padding: 0.15rem 0.5rem;
  border-radius: 999px; background: var(--accent-bg); color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.top-right { display: flex; align-items: center; gap: 0.65rem; }
.search-trigger {
  display: flex; align-items: center; gap: 0.65rem;
  background: var(--bg-elev); border: 1px solid var(--border);
  color: var(--text-muted); border-radius: 9px; padding: 0.4rem 0.75rem;
  cursor: pointer; font-size: 0.86rem; min-width: 210px; justify-content: space-between;
  transition: border-color 0.15s;
}
.search-trigger:hover { border-color: var(--accent); color: var(--text-strong); }
.kbd {
  font-size: 0.72rem; padding: 0.1rem 0.4rem; border-radius: 5px;
  border: 1px solid var(--border-strong); color: var(--text-muted);
}
.icon-btn {
  background: var(--bg-elev); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 0.42rem 0.65rem;
  cursor: pointer; font-size: 0.85rem; display: inline-flex; align-items: center; gap: 0.35rem;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.menu-btn { display: none; }

/* Layout */
.layout {
  max-width: 1440px; margin: 0 auto;
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: 2rem; padding: 1.5rem 1.25rem 4rem;
}
.sidebar {
  position: sticky; top: calc(var(--header-h) + 1.25rem);
  height: calc(100vh - var(--header-h) - 2.5rem);
  overflow-y: auto; padding-right: 0.5rem;
}
.nav-group { margin-bottom: 1.35rem; }
.nav-group-title {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); font-weight: 700; margin: 0 0 0.45rem 0.65rem;
}
.nav-link {
  display: block; padding: 0.38rem 0.65rem; border-radius: 7px;
  font-size: 0.89rem; color: var(--text); margin-bottom: 2px;
  transition: background 0.12s, color 0.12s;
}
.nav-link:hover { background: var(--accent-bg); color: var(--text-strong); text-decoration: none; }
.nav-link.active {
  background: var(--accent-bg); color: var(--accent); font-weight: 600;
  border-left: 2px solid var(--accent);
}

/* Main Content */
.content { min-width: 0; max-width: 820px; }
.page-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
.type-pill {
  font-size: 0.73rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 0.16rem 0.55rem; border-radius: 6px;
  background: color-mix(in srgb, var(--accent-2) 15%, transparent); color: var(--accent-2);
}
.tag-pill {
  font-size: 0.74rem; padding: 0.12rem 0.48rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-muted);
}
.prose h1 { font-size: 2.05rem; line-height: 1.2; color: var(--text-strong); margin: 0.25rem 0 1rem; letter-spacing: -0.02em; }
.prose h2 {
  font-size: 1.38rem; color: var(--text-strong); margin: 2.1rem 0 0.75rem;
  padding-bottom: 0.4rem; border-bottom: 1px solid var(--border); letter-spacing: -0.01em;
}
.prose h3 { font-size: 1.1rem; color: var(--text-strong); margin: 1.5rem 0 0.5rem; }
.heading-anchor { opacity: 0; margin-left: 0.45rem; color: var(--accent); font-weight: 500; transition: opacity 0.12s; }
.prose h2:hover .heading-anchor, .prose h3:hover .heading-anchor { opacity: 1; text-decoration: none; }
.prose p { margin: 0.85rem 0; }
.prose ul, .prose ol { padding-left: 1.35rem; margin: 0.75rem 0; }
.prose li { margin: 0.35rem 0; }
.prose strong { color: var(--text-strong); }
.prose :not(pre) > code {
  background: var(--accent-bg); color: var(--accent);
  padding: 0.12rem 0.38rem; border-radius: 5px; font-size: 0.86em;
}
.prose blockquote {
  margin: 1rem 0; padding: 0.75rem 1rem; border-left: 3px solid var(--accent);
  background: var(--bg-elev); border-radius: 0 8px 8px 0; color: var(--text-muted);
}
.prose table {
  width: 100%; border-collapse: collapse; margin: 1.25rem 0;
  font-size: 0.9rem; border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
.prose th {
  text-align: left; background: var(--bg-elev); color: var(--text-strong);
  padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--border-strong); font-weight: 600;
}
.prose td { padding: 0.6rem 0.85rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.prose tr:last-child td { border-bottom: none; }

/* Code Blocks */
.code-block {
  margin: 1.1rem 0; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border); background: var(--bg-code); box-shadow: 0 6px 20px rgba(0,0,0,0.18);
}
.code-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.38rem 0.85rem; background: rgba(255,255,255,0.03);
  border-bottom: 1px solid rgba(255,255,255,0.08); font-size: 0.75rem; color: #94a3b8;
}
.copy-btn {
  background: rgba(255,255,255,0.07); color: #cbd5e1; border: 1px solid rgba(255,255,255,0.12);
  border-radius: 5px; padding: 0.15rem 0.55rem; font-size: 0.72rem; cursor: pointer;
}
.copy-btn:hover { background: var(--accent); color: #090d16; border-color: var(--accent); }
.code-block pre { margin: 0; padding: 0.95rem 1rem; overflow-x: auto; font-size: 0.86rem; line-height: 1.55; color: #e2e8f0; }

/* Mermaid */
.mermaid-wrap {
  margin: 1.25rem 0; padding: 1rem; border-radius: 10px;
  background: var(--bg-elev); border: 1px solid var(--border); overflow-x: auto; text-align: center;
}

/* Hero Landing */
.hero-card {
  margin-bottom: 2rem; padding: 2rem; border-radius: 16px;
  background: radial-gradient(circle at top right, color-mix(in srgb, var(--accent-2) 16%, transparent), transparent 55%),
              linear-gradient(180deg, var(--bg-elev), var(--bg-card));
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.hero-badge {
  display: inline-block; font-size: 0.76rem; font-weight: 600; color: var(--accent);
  background: var(--accent-bg); padding: 0.25rem 0.7rem; border-radius: 999px; margin-bottom: 0.85rem;
}
.hero-title { font-size: 2.35rem; line-height: 1.15; margin: 0 0 0.85rem; color: var(--text-strong); letter-spacing: -0.03em; }
.hero-sub { font-size: 1.03rem; color: var(--text); max-width: 64ch; margin: 0 0 1.3rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1.5rem; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff; font-weight: 600; padding: 0.58rem 1.15rem; border-radius: 9px;
}
.btn-primary:hover { opacity: 0.92; text-decoration: none; }
.btn-secondary, .btn-ghost {
  padding: 0.58rem 1.05rem; border-radius: 9px; font-weight: 600;
  border: 1px solid var(--border-strong); color: var(--text-strong); background: var(--bg-elev);
}
.btn-secondary:hover, .btn-ghost:hover { border-color: var(--accent); text-decoration: none; }
.hero-terminal {
  border-radius: 12px; overflow: hidden; border: 1px solid rgba(255,255,255,0.12);
  background: #0b101b; margin-bottom: 1.5rem;
}
.term-bar {
  display: flex; align-items: center; gap: 0.45rem; padding: 0.5rem 0.85rem;
  background: rgba(255,255,255,0.04); border-bottom: 1px solid rgba(255,255,255,0.08);
}
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.red { background: #f87171; } .dot.yellow { background: #fbbf24; } .dot.green { background: #34d399; }
.term-title { margin-left: 0.4rem; font-size: 0.75rem; color: #94a3b8; }
.term-body { margin: 0; padding: 1rem; font-size: 0.82rem; line-height: 1.5; color: #cbd5e1; overflow-x: auto; }
.t-prompt { color: #38bdf8; font-weight: 700; }
.t-ok { color: #fb7185; }
.t-cmd { color: #f8fafc; font-weight: 700; }
.t-warn { color: #fbbf24; }
.t-flag { color: #34d399; font-weight: 600; }
.feature-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.9rem; }
.feature-card {
  padding: 1rem; border-radius: 10px; background: var(--bg-elev); border: 1px solid var(--border);
}
.feature-card h3 { margin: 0.4rem 0 0.35rem; font-size: 0.98rem; color: var(--text-strong); }
.feature-card p { margin: 0; font-size: 0.85rem; color: var(--text-muted); }
.f-tag { font-size: 0.72rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; }

/* TOC */
.toc {
  position: sticky; top: calc(var(--header-h) + 1.25rem);
  height: calc(100vh - var(--header-h) - 2.5rem); overflow-y: auto;
  font-size: 0.83rem;
}
.toc-title { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); font-weight: 700; margin-bottom: 0.5rem; }
.toc a { display: block; padding: 0.25rem 0 0.25rem 0.65rem; color: var(--text-muted); border-left: 2px solid var(--border); }
.toc a.lvl-3 { padding-left: 1.25rem; font-size: 0.79rem; }
.toc a:hover, .toc a.active { color: var(--accent); border-left-color: var(--accent); text-decoration: none; }

/* Prev / Next */
.pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
  margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--border);
}
.pager-card {
  padding: 0.85rem 1rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-elev); display: flex; flex-direction: column;
}
.pager-card:hover { border-color: var(--accent); text-decoration: none; }
.pager-card.next { text-align: right; }
.pager-dir { font-size: 0.75rem; color: var(--text-muted); }
.pager-title { font-weight: 600; color: var(--text-strong); }

/* Search Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 80; background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px); display: none; align-items: flex-start; justify-content: center; padding-top: 10vh;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(640px, 92vw); background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
}
.modal-input-row { display: flex; align-items: center; padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); gap: 0.65rem; }
.modal-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text-strong); font-size: 1rem;
}
.modal-results { max-height: 55vh; overflow-y: auto; padding: 0.5rem; }
.search-item {
  display: block; padding: 0.65rem 0.85rem; border-radius: 8px; color: var(--text);
}
.search-item:hover, .search-item.selected { background: var(--accent-bg); text-decoration: none; }
.search-item-title { font-weight: 600; color: var(--text-strong); }
.search-item-desc { font-size: 0.82rem; color: var(--text-muted); }

/* Pygments dark/light friendly overrides */
.highlight .c, .highlight .c1, .highlight .ch, .highlight .cm { color: #64748b; font-style: italic; }
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .kt { color: #c084fc; }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb, .highlight .sc, .highlight .sd, .highlight .si { color: #34d399; }
.highlight .na, .highlight .nb, .highlight .nc, .highlight .nf { color: #38bdf8; }
.highlight .mi, .highlight .mf, .highlight .mh { color: #fbbf24; }
.highlight .o, .highlight .p { color: #94a3b8; }

@media (max-width: 1120px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .menu-btn { display: inline-flex; }
  .search-trigger { min-width: 120px; }
  .feature-grid { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: var(--header-h); bottom: 0; width: 280px;
    background: var(--bg-elev); border-right: 1px solid var(--border);
    padding: 1rem; z-index: 60; transform: translateX(-105%); transition: transform 0.2s;
  }
  .sidebar.open { transform: translateX(0); }
}
