:root {
  --bg: #071211;
  --bg-elevated: #0c1d1b;
  --bg-subtle: #112724;
  --border: #1e3d38;
  --text: #e6f4f1;
  --text-muted: #93b7b0;
  --accent: #10b981;
  --accent-strong: #34d399;
  --accent-soft: rgba(16, 185, 129, 0.14);
  --code-bg: #0a1917;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --warning-border: #d97706;
  --note-bg: rgba(56, 189, 248, 0.12);
  --note-border: #0284c7;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f8fbfa;
    --bg-elevated: #ffffff;
    --bg-subtle: #eef5f3;
    --border: #d4e3df;
    --text: #0f2421;
    --text-muted: #4b6a64;
    --accent: #047857;
    --accent-strong: #065f46;
    --accent-soft: rgba(4, 120, 87, 0.1);
    --code-bg: #f1f6f5;
    --warning-bg: #fffbeb;
    --warning-border: #d97706;
    --note-bg: #f0f9ff;
    --note-border: #0284c7;
    --shadow: 0 18px 48px rgba(15, 36, 33, 0.12);
  }
}

:root[data-theme="light"] {
  --bg: #f8fbfa;
  --bg-elevated: #ffffff;
  --bg-subtle: #eef5f3;
  --border: #d4e3df;
  --text: #0f2421;
  --text-muted: #4b6a64;
  --accent: #047857;
  --accent-strong: #065f46;
  --accent-soft: rgba(4, 120, 87, 0.1);
  --code-bg: #f1f6f5;
  --warning-bg: #fffbeb;
  --warning-border: #d97706;
  --note-bg: #f0f9ff;
  --note-border: #0284c7;
  --shadow: 0 18px 48px rgba(15, 36, 33, 0.12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 76px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 60px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1440px;
  height: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 750;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); font-size: 18px; }
.topbar-link { color: var(--text-muted); font-size: 14px; font-weight: 600; }
.topbar-link:hover { color: var(--text); text-decoration: none; }

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { border-color: var(--accent); }
.mobile-menu-btn { display: none; }

.search-trigger {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  border-radius: 9px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 18px;
}
.search-trigger:hover { border-color: var(--accent); color: var(--text); }
.search-trigger kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-subtle);
}

.layout {
  max-width: 1440px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr) 232px;
  gap: 0;
}

.sidebar {
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 24px 16px 40px 20px;
  border-right: 1px solid var(--border);
}
.nav-group { margin-bottom: 22px; }
.nav-group h2 {
  margin: 0 0 8px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.nav-group ul { list-style: none; margin: 0; padding: 0; }
.nav-group a {
  display: block;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 14px;
  color: var(--text-muted);
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-group a:hover { background: var(--bg-subtle); color: var(--text); text-decoration: none; }
.nav-group a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 650;
}

.content {
  min-width: 0;
  padding: 32px 44px 72px;
}

.hero {
  margin-bottom: 36px;
  padding: 32px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--bg-elevated), var(--bg-subtle));
  border: 1px solid var(--border);
}
.hero-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 14px;
}
.hero h1 {
  margin: 0 0 12px;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.15;
  letter-spacing: -0.03em;
}
.hero-lead {
  margin: 0 0 22px;
  max-width: 68ch;
  font-size: 17px;
  color: var(--text-muted);
}
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
  display: inline-flex;
  align-items: center;
  padding: 10px 18px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 650;
  border: 1px solid transparent;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #031510; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--bg-elevated); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-ghost { color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 40px;
}
.feature-card {
  padding: 18px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}
.feature-card h3 { margin: 0 0 6px; font-size: 15px; }
.feature-card p { margin: 0; font-size: 13.5px; color: var(--text-muted); line-height: 1.55; }

.prose h1 { font-size: 32px; line-height: 1.2; letter-spacing: -0.025em; margin: 0 0 18px; }
.prose h2 {
  font-size: 22px;
  line-height: 1.3;
  letter-spacing: -0.015em;
  margin: 36px 0 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.prose h3 { font-size: 17px; margin: 24px 0 8px; }
.prose h4 { font-size: 15px; margin: 18px 0 6px; }
.heading-anchor {
  margin-left: 8px;
  color: var(--text-muted);
  opacity: 0;
  font-weight: 500;
  transition: opacity 0.12s ease;
}
.prose h2:hover .heading-anchor,
.prose h3:hover .heading-anchor,
.prose h4:hover .heading-anchor { opacity: 1; }
.prose p { margin: 0 0 16px; }
.prose ul, .prose ol { margin: 0 0 16px; padding-left: 24px; }
.prose li { margin: 5px 0; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 28px 0; }
.prose blockquote {
  margin: 18px 0;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: var(--bg-subtle);
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.88em;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
}

.code-block {
  margin: 18px 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--code-bg);
}
.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  font-size: 12px;
  color: var(--text-muted);
}
.copy-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.copy-btn:hover { color: var(--text); border-color: var(--accent); }
.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.55;
}
.code-block code { background: none; border: 0; padding: 0; font-size: inherit; }

.table-wrap { overflow-x: auto; margin: 18px 0; }
.prose table { width: 100%; border-collapse: collapse; font-size: 14px; }
.prose th, .prose td {
  border: 1px solid var(--border);
  padding: 9px 12px;
  text-align: left;
  vertical-align: top;
}
.prose th { background: var(--bg-subtle); font-weight: 650; }

.callout {
  margin: 18px 0;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  background: var(--note-bg);
  border-left-color: var(--note-border);
}
.callout-warning, .callout-caution {
  background: var(--warning-bg);
  border-left-color: var(--warning-border);
}
.callout-tip, .callout-important {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}
.callout-title {
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.callout-body p:last-child { margin-bottom: 0; }

.toc {
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 28px 18px 40px 16px;
  border-left: 1px solid var(--border);
  font-size: 13px;
}
.toc-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 5px 0; }
.toc-l3 { padding-left: 12px; }
.toc a { color: var(--text-muted); }
.toc a:hover { color: var(--text); text-decoration: none; }

.pager {
  margin-top: 44px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.pager-link {
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}
.pager-link:hover { border-color: var(--accent); text-decoration: none; }
.pager-link.next { text-align: right; }
.pager-dir { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.pager-label { font-size: 15px; font-weight: 650; color: var(--text); }

.doc-footer {
  margin-top: 26px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.search-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 10vh 16px 16px;
}
.search-modal[hidden] { display: none; }
.search-panel {
  width: min(640px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.search-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.search-input-row input {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.search-results {
  max-height: 55vh;
  overflow-y: auto;
  padding: 8px;
}
.search-item {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
}
.search-item:hover { background: var(--bg-subtle); text-decoration: none; }
.search-item-title { font-weight: 650; font-size: 14px; }
.search-item-meta { font-size: 12px; color: var(--accent-strong); margin-left: 8px; }
.search-item-excerpt { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.search-empty { padding: 18px; text-align: center; color: var(--text-muted); font-size: 14px; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 248px minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .mobile-menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 45;
    background: var(--bg);
    transform: translateX(-100%);
    transition: transform 0.18s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed;
    inset: 60px 0 0 0;
    z-index: 40;
    background: rgba(0, 0, 0, 0.45);
  }
  .content { padding: 22px 18px 56px; }
  .hero { padding: 22px; }
  .search-trigger span { display: none; }
}
