:root {
  --bg: #0b0f17;
  --bg-elev: #111827;
  --bg-card: #161f31;
  --bg-code: #090d14;
  --border: #25324a;
  --text: #e6edf7;
  --muted: #8ea0bc;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --purple: #c084fc;
  --hl-line: rgba(56, 189, 248, 0.22);
  --radius: 10px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --bg-elev: #ffffff;
  --bg-card: #f1f5f9;
  --bg-code: #0f172a;
  --border: #d8e1ec;
  --text: #0f172a;
  --muted: #475569;
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --accent-soft: rgba(2, 132, 199, 0.1);
  --hl-line: rgba(2, 132, 199, 0.18);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--font-mono); font-size: 0.88em; background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
pre code { background: none; padding: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.flex-1 { flex: 1; }

/* ── Top Navbar ── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 15px; text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: #fff; font-weight: 800; font-family: var(--font-mono);
}
.badge {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(56,189,248,0.3);
}
.nav-tabs { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 9px; border: 1px solid var(--border); }
.nav-tab {
  border: none; background: transparent; color: var(--muted); font-weight: 600; font-size: 13px;
  padding: 6px 14px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; gap: 7px;
}
.nav-tab.active { background: var(--accent-strong); color: #fff; }
.dot-live { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
.nav-right { display: flex; align-items: center; gap: 10px; }

.search-wrap { position: relative; }
.search-wrap input {
  width: 240px; padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 13px;
}
.search-dropdown {
  position: absolute; top: 38px; right: 0; width: 340px; max-height: 360px; overflow-y: auto;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.45); padding: 6px;
}
.search-item {
  display: block; padding: 8px 10px; border-radius: 6px; color: var(--text); cursor: pointer;
}
.search-item:hover { background: var(--accent-soft); text-decoration: none; }
.search-item small { display: block; color: var(--muted); font-size: 11.5px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); cursor: pointer; font-size: 16px;
}

/* ── Docs Shell ── */
.docs-shell {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  min-height: calc(100vh - 58px);
}
.docs-sidebar {
  position: sticky;
  top: 58px;
  height: calc(100vh - 58px);
  overflow-y: auto;
  padding: 20px 14px;
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
}
.side-group { margin-bottom: 18px; }
.side-heading {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 700; padding: 4px 10px; margin-bottom: 4px;
}
.side-link {
  display: block; padding: 6px 10px; border-radius: 6px; color: var(--muted); font-size: 13px;
}
.side-link:hover, .side-link.active { background: var(--accent-soft); color: var(--accent); text-decoration: none; font-weight: 600; }

.docs-main {
  max-width: 1040px;
  width: 100%;
  margin: 0 auto;
  padding: 36px 40px 80px;
}
.hero {
  padding: 28px 30px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(14,165,233,0.14), rgba(99,102,241,0.12));
  border: 1px solid var(--border);
  margin-bottom: 32px;
}
.hero h1 { margin: 0 0 10px; font-size: 30px; line-height: 1.2; letter-spacing: -0.02em; }
.hero p { margin: 0 0 18px; color: var(--muted); font-size: 15px; max-width: 780px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-top: 20px; }
.stat-card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
}
.stat-card span { display: block; font-size: 11.5px; color: var(--muted); }
.stat-card strong { font-size: 20px; color: var(--accent); font-family: var(--font-mono); }

.doc-section { margin-bottom: 48px; scroll-margin-top: 76px; }
.doc-section h2 {
  font-size: 22px; margin: 0 0 12px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border); letter-spacing: -0.01em;
}
.doc-section h3 { font-size: 16px; margin: 22px 0 8px; color: var(--accent); }
.callout {
  padding: 14px 16px; border-radius: 10px; border-left: 3px solid var(--accent);
  background: var(--accent-soft); margin: 14px 0; font-size: 13.5px;
}
.code-block {
  position: relative; background: var(--bg-code); color: #e2e8f0;
  border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px;
  overflow-x: auto; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; margin: 12px 0;
}
.copy-btn {
  position: absolute; top: 8px; right: 8px; padding: 3px 9px; font-size: 11px;
  border-radius: 6px; border: 1px solid #334155; background: #1e293b; color: #cbd5e1; cursor: pointer;
}
.copy-btn:hover { background: #334155; }

.doc-table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 13px; }
.doc-table th, .doc-table td {
  text-align: left; padding: 9px 11px; border-bottom: 1px solid var(--border); vertical-align: top;
}
.doc-table th { background: var(--bg-card); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.doc-table tr:hover td { background: var(--accent-soft); }
.pill { display: inline-block; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; font-family: var(--font-mono); }
.pill-green { background: rgba(52,211,153,0.16); color: var(--green); }
.pill-blue { background: var(--accent-soft); color: var(--accent); }
.pill-amber { background: rgba(251,191,36,0.16); color: var(--amber); }

/* ── Buttons & Inputs ── */
.btn {
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text); font-weight: 600; font-size: 12.5px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; }
.btn-xs { padding: 4px 10px; font-size: 12px; }
.select-input, .select-compact, .text-input {
  padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 12.5px;
}
.select-compact { padding: 4px 8px; font-size: 12px; }

/* ── Playground Shell ── */
.pg-shell {
  display: flex; flex-direction: column;
  height: calc(100vh - 58px);
}
.pg-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 16px; background: var(--bg-elev); border-bottom: 1px solid var(--border);
}
.pg-toolbar-left, .pg-toolbar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.drop-pill {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 8px;
  border: 1.5px dashed var(--accent); background: var(--accent-soft); cursor: pointer; font-size: 12px;
}
.drop-pill.drag-over { background: rgba(56,189,248,0.28); }

.pg-metrics {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.metric-chip {
  display: flex; align-items: baseline; gap: 6px; padding: 3px 10px;
  border-radius: 6px; background: var(--bg-elev); border: 1px solid var(--border); font-size: 12px;
}
.metric-chip span { color: var(--muted); }
.metric-chip strong { font-family: var(--font-mono); color: var(--accent); }
.file-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.file-pill {
  padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-family: var(--font-mono);
  background: var(--bg-card); border: 1px solid var(--border); cursor: pointer;
}
.file-pill.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.pg-workspace {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 44% 56%;
}
.pg-pane { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.pg-source-pane { border-right: 1px solid var(--border); background: var(--bg-code); color: #e2e8f0; }
.pg-ast-pane { background: var(--bg-elev); }

.pane-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; background: var(--bg-elev); border-bottom: 1px solid var(--border); color: var(--text);
}
.pane-title, .pane-actions { display: flex; align-items: center; gap: 8px; }
.span-badge { font-family: var(--font-mono); font-size: 11px; color: var(--accent); }

.code-viewer {
  flex: 1; overflow: auto; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; padding: 8px 0;
}
.code-line { display: flex; padding: 0 12px; white-space: pre; }
.code-line.hl { background: var(--hl-line); border-left: 3px solid var(--accent); padding-left: 9px; }
.line-num {
  width: 44px; flex-shrink: 0; text-align: right; padding-right: 14px;
  color: #64748b; user-select: none;
}
.code-editor {
  flex: 1; width: 100%; resize: none; border: none; outline: none;
  background: var(--bg-code); color: #e2e8f0; padding: 12px 16px;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55;
}

.pane-tabs {
  display: flex; gap: 4px; padding: 6px 10px 0; border-bottom: 1px solid var(--border); background: var(--bg);
}
.ptab {
  padding: 7px 12px; border: none; border-bottom: 2px solid transparent;
  background: transparent; color: var(--muted); font-weight: 600; font-size: 12.5px; cursor: pointer;
}
.ptab.active { color: var(--accent); border-bottom-color: var(--accent); }
.ptab-body { display: none; flex: 1; min-height: 0; flex-direction: column; overflow: hidden; }
.ptab-body.active { display: flex; }

.tree-controls {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.tree-split {
  flex: 1; min-height: 0; display: grid; grid-template-columns: 58% 42%;
}
.ast-tree { overflow: auto; padding: 8px; border-right: 1px solid var(--border); font-family: var(--font-mono); font-size: 12px; }
.node-inspector { overflow: auto; padding: 12px; font-size: 12.5px; }
.tree-row {
  display: flex; align-items: center; gap: 5px; padding: 3px 6px; border-radius: 5px; cursor: pointer; white-space: nowrap;
}
.tree-row:hover { background: var(--accent-soft); }
.tree-row.selected { background: var(--accent-strong); color: #fff; }
.tree-row.selected .t-meta, .tree-row.selected .t-span { color: #e0f2fe; }
.t-toggle { width: 14px; display: inline-block; text-align: center; color: var(--muted); }
.t-key { color: var(--accent); font-weight: 600; }
.t-kind { color: var(--purple); font-weight: 600; }
.t-meta { color: var(--muted); font-size: 11px; }
.t-span { margin-left: auto; font-size: 10.5px; color: var(--green); }
.tree-children { padding-left: 16px; border-left: 1px dashed var(--border); margin-left: 8px; }

.json-pre {
  flex: 1; overflow: auto; margin: 0; padding: 12px 14px;
  background: var(--bg-code); color: #cbd5e1; font-family: var(--font-mono); font-size: 12px;
}
.audit-wrap, .emit-wrap, .formula-box {
  flex: 1; overflow: auto; padding: 14px;
}
.formula-box textarea {
  width: 100%; margin: 8px 0; padding: 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-code); color: #e2e8f0; font-family: var(--font-mono); font-size: 12.5px;
}
.card-box {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px;
}
.empty-hint { color: var(--muted); padding: 20px 10px; text-align: center; }

@media (max-width: 980px) {
  .docs-shell { grid-template-columns: 1fr; }
  .docs-sidebar { display: none; }
  .docs-main { padding: 20px 16px 60px; }
  .pg-workspace { grid-template-columns: 1fr; grid-template-rows: 42% 58%; }
  .tree-split { grid-template-columns: 1fr; }
  .search-wrap { display: none; }
}
