:root {
  --bg: #0b0c10;
  --bg-elevated: #12131a;
  --bg-card: #15161f;
  --border: #23242f;
  --text: #e6e6ef;
  --text-dim: #9a9bab;
  --accent: #818cf8;
  --accent-strong: #6366f1;
  --code-bg: #1a1b24;
  --green: #4ade80;
  --yellow: #fbbf24;
  --radius: 10px;
  --max-width: 880px;
  --hero-grad-start: #ffffff;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-elevated: #f7f7fb;
  --bg-card: #f3f3f9;
  --border: #e3e3ee;
  --text: #1a1b24;
  --text-dim: #5c5d6e;
  --accent: #6366f1;
  --accent-strong: #4f46e5;
  --code-bg: #f0f0f8;
  --green: #16a34a;
  --yellow: #b45309;
  --hero-grad-start: #1a1b24;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.65;
}

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

code, pre, kbd {
  font-family: "JetBrains Mono", "Fira Code", Consolas, Menlo, monospace;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.55;
  position: relative;
}

pre code { background: none; padding: 0; }

p code, li code, td code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 0.88em;
  color: #c7c9ff;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}
pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 20px;
  background: var(--bg);
  opacity: 0.97;
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--text);
  font-size: 15px;
}
.topbar .brand .dot { color: var(--accent); }
.brand-logo {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: block;
}
.hero-logo {
  width: 88px;
  height: 88px;
  border-radius: 18px;
  margin: 0 auto 18px;
  display: block;
  box-shadow: 0 0 40px rgba(129,140,248,0.35);
}
footer .brand-logo { display: inline-block; width: 20px; height: 20px; vertical-align: middle; margin-right: 6px; }

.topbar .links { display: flex; align-items: center; gap: 18px; font-size: 14px; }
.topbar .links a { color: var(--text-dim); }
.topbar .links a:hover { color: var(--text); text-decoration: none; }
.topbar .links .pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  color: var(--text);
}

.menu-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 10px;
  cursor: pointer;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }

/* ---------- Layout ---------- */
.layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
}

.sidebar {
  flex: 0 0 260px;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  padding: 24px 16px 60px;
  border-right: 1px solid var(--border);
}

.sidebar nav .group { margin-bottom: 22px; }
.sidebar nav .group-title {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 8px 10px;
  font-weight: 600;
}
.sidebar nav a {
  display: block;
  color: var(--text-dim);
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 14px;
  margin-bottom: 1px;
}
.sidebar nav a:hover { background: var(--bg-elevated); color: var(--text); text-decoration: none; }
.sidebar nav a.active {
  background: rgba(99,102,241,0.14);
  color: var(--accent);
  font-weight: 600;
}

.toc {
  flex: 0 0 220px;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  padding: 32px 20px 60px 0;
  font-size: 13px;
}
.toc .toc-title {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 10px;
  font-weight: 600;
}
.toc a {
  display: block;
  color: var(--text-dim);
  padding: 5px 0;
  border-left: 2px solid transparent;
  padding-left: 12px;
  margin-left: -1px;
}
.toc a:hover { color: var(--text); text-decoration: none; }
.toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
@media (max-width: 1200px) { .toc { display: none; } }

.content {
  flex: 1;
  min-width: 0;
  padding: 40px 48px 100px;
  max-width: var(--max-width);
  margin: 0 auto;
}

.content h1 { font-size: 32px; margin: 0 0 6px; }
.content h2 { font-size: 23px; margin: 42px 0 14px; border-top: 1px solid var(--border); padding-top: 34px; }
.content h1 + .lead { margin-top: 0; }
.content h3 { font-size: 17px; margin: 28px 0 10px; color: var(--text); }
.content > h2:first-of-type { border-top: none; padding-top: 0; }

.lead { color: var(--text-dim); font-size: 17px; margin-bottom: 28px; }

table { width: 100%; border-collapse: collapse; margin: 18px 0; font-size: 14px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; }

.badge-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 28px; }
.badge {
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--text-dim);
}
.badge.green { color: var(--green); border-color: rgba(74,222,128,.3); }

.callout {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 18px 0;
  font-size: 14.5px;
  color: var(--text-dim);
}
.callout strong { color: var(--text); }

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin: 20px 0;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.card h3 { margin-top: 0; font-size: 15px; }
.card p { color: var(--text-dim); font-size: 14px; margin: 6px 0 0; }
.card a.stretched { color: var(--text); }

.prevnext {
  display: flex;
  justify-content: space-between;
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.prevnext a { color: var(--text-dim); }
.prevnext .next { text-align: right; }
.prevnext small { display: block; color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Home / hero ---------- */
.hero {
  text-align: center;
  padding: 70px 20px 40px;
  max-width: 760px;
  margin: 0 auto;
}
.hero h1 {
  font-size: 44px;
  margin: 18px 0 12px;
  background: linear-gradient(90deg, var(--hero-grad-start), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero p { color: var(--text-dim); font-size: 18px; }
.hero .cta { display: flex; gap: 12px; justify-content: center; margin-top: 26px; }
.btn {
  display: inline-block;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}
.btn.primary { background: var(--accent-strong); color: #fff; }
.btn.primary:hover { background: #5457e6; text-decoration: none; }
.btn.ghost { border: 1px solid var(--border); color: var(--text); }
.btn.ghost:hover { border-color: var(--accent); text-decoration: none; }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  max-width: 1040px;
  margin: 50px auto;
  padding: 0 20px;
}
.feature-grid .card h3 { color: var(--accent); }

.home-section { max-width: 1040px; margin: 0 auto 60px; padding: 0 20px; }

/* ---------- Stat strip ---------- */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  max-width: 1040px;
  margin: 0 auto 60px;
  padding: 0 20px;
}
.stat-strip .stat {
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 14px;
}
.stat-strip .stat .num {
  font-size: 30px;
  font-weight: 700;
  color: var(--accent);
  display: block;
}
.stat-strip .stat .label {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 4px;
}

/* ---------- Bar chart ---------- */
.chart { margin: 22px 0 30px; }
.chart-row {
  display: grid;
  grid-template-columns: 200px 1fr 56px;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 13.5px;
}
.chart-row .chart-label { color: var(--text-dim); }
.chart-row .chart-track {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.chart-row .chart-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
}
.chart-row .chart-value { color: var(--text); font-weight: 600; text-align: right; }

/* ---------- FAQ ---------- */
.faq-item {
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
}
.faq-item summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: "+"; color: var(--text-dim); font-weight: 400; font-size: 18px; }
.faq-item[open] summary::after { content: "\2212"; }
.faq-item p { color: var(--text-dim); margin: 10px 0 0; font-size: 14.5px; }

footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 30px 20px 60px;
}

@media (max-width: 900px) {
  .menu-toggle { display: inline-block; }
  .sidebar {
    position: fixed;
    left: -280px;
    top: 56px;
    z-index: 60;
    width: 260px;
    background: var(--bg);
    transition: left .2s ease;
  }
  .sidebar.open { left: 0; }
  .content { padding: 28px 20px 80px; }
  .feature-grid, .grid, .stat-strip { grid-template-columns: 1fr 1fr; }
  .hero h1 { font-size: 32px; }
  .chart-row { grid-template-columns: 120px 1fr 48px; }
}
