:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --ink: #18211d;
  --muted: #5d6b63;
  --line: #d9dfd6;
  --panel: #ffffff;
  --panel-2: #f0f4ef;
  --accent: #20715b;
  --accent-hover: #185a48;
  --accent-2: #b94d35;
  --code-bg: #14231e;
  --code-fg: #dcebe4;
  --code-kw: #7ecba3;
  --code-str: #f0b97a;
  --code-num: #9dd0ff;
  --code-cmt: #6a9e82;
  --code-fn: #e8d06a;
  --code-type: #c792ea;
  --sidebar-w: 220px;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

/* ── Top nav ──────────────────────────────────────────────── */
.topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.topnav-inner {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 17px;
  color: var(--ink);
  white-space: nowrap;
}

.brand-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  font-size: 15px;
  border-radius: 7px;
}

.topnav-links {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-left: auto;
}

.topnav-links a {
  padding: 5px 11px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.topnav-links a:hover { background: var(--panel-2); color: var(--ink); text-decoration: none; }
.topnav-links a.active { background: var(--panel-2); color: var(--accent); font-weight: 700; }

/* ── Layout ───────────────────────────────────────────────── */
.page-wrap {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 80px;
}

.with-sidebar {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 48px;
  align-items: start;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  font-size: 14px;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-section {
  padding: 8px 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.sidebar a {
  display: block;
  padding: 4px 10px;
  border-radius: 5px;
  color: var(--muted);
  transition: background 0.12s, color 0.12s;
}

.sidebar a:hover { background: var(--line); color: var(--ink); text-decoration: none; }
.sidebar a.active { background: #d7f0e7; color: var(--accent); font-weight: 600; }

/* ── Content ──────────────────────────────────────────────── */
.content h1 { margin: 0 0 8px; font-size: 36px; line-height: 1.1; }
.content h2 { margin: 48px 0 16px; font-size: 24px; padding-top: 8px; border-top: 1px solid var(--line); }
.content h2:first-of-type { margin-top: 32px; border-top: none; }
.content h3 { margin: 28px 0 10px; font-size: 18px; }
.content h4 { margin: 20px 0 8px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.content p { margin: 0 0 14px; }
.content ul, .content ol { margin: 0 0 14px; padding-left: 22px; }
.content li { margin-bottom: 4px; }

.lead { font-size: 18px; color: var(--muted); margin: 0 0 28px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  background: var(--panel-2);
  color: var(--muted);
  vertical-align: middle;
}

.badge.green { background: #d7f0e7; color: #1a6645; }
.badge.red   { background: #fde8e3; color: #9b3622; }

/* ── Code blocks ──────────────────────────────────────────── */
pre {
  margin: 0 0 20px;
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: 10px;
  overflow-x: auto;
  font: 14px/1.6 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

pre code {
  display: block;
  padding: 18px 22px;
}

.terminal-wrap {
  margin: 0 0 20px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 4px 20px rgba(24, 33, 29, 0.10);
}

.terminal-bar {
  height: 34px;
  background: #1e2e28;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.terminal-bar .dot { width: 10px; height: 10px; border-radius: 999px; background: #d66b53; }
.terminal-bar .dot:nth-child(2) { background: #d9b34c; }
.terminal-bar .dot:nth-child(3) { background: #57a86f; }
.terminal-bar .label { margin-left: 8px; font-size: 12px; color: rgba(255,255,255,0.4); font-family: ui-monospace, monospace; }

.terminal-wrap pre { border-radius: 0; margin: 0; border: none; box-shadow: none; }

code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.88em;
}

p code, li code, td code {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--accent-2);
}

/* ── Syntax highlighting ──────────────────────────────────── */
.kw  { color: var(--code-kw); }
.str { color: var(--code-str); }
.num { color: var(--code-num); }
.cmt { color: var(--code-cmt); font-style: italic; }
.fn  { color: var(--code-fn); }
.tp  { color: var(--code-type); }
.op  { color: #89c4e1; }
.pn  { color: var(--code-fg); }

/* ── Tables ───────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin: 0 0 20px;
}

th, td {
  text-align: left;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
}

th {
  background: var(--panel-2);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }

/* ── Cards & grids ────────────────────────────────────────── */
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 0 0 20px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 0 0 20px;
}

.card {
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.card h3 { margin: 0 0 8px; font-size: 16px; }
.card p  { margin: 0; color: var(--muted); font-size: 14px; }
.card ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; }

/* ── Callouts ─────────────────────────────────────────────── */
.callout {
  padding: 14px 18px;
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  background: #e8f5ee;
  margin: 0 0 20px;
  font-size: 15px;
}

.callout.warn { border-color: var(--accent-2); background: #fef0ec; }

/* ── Hero (index) ─────────────────────────────────────────── */
.hero {
  padding: 64px 0 40px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 40px;
  align-items: center;
}

.hero h1 {
  margin: 0 0 16px;
  font-size: clamp(52px, 10vw, 96px);
  line-height: 0.92;
}

.hero .lead { font-size: 20px; }

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 28px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 18px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 15px;
  transition: background 0.15s, color 0.15s;
}

.btn-primary { background: var(--accent); color: #fff; border: 1px solid var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
.btn-outline { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-outline:hover { background: var(--accent); color: #fff; text-decoration: none; }

/* ── Feature section (index) ──────────────────────────────── */
.features-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.feature-card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.feature-card .icon {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: #d7f0e7;
  color: var(--accent);
  font-size: 20px;
  margin-bottom: 14px;
}

.feature-card h3 { margin: 0 0 8px; font-size: 17px; }
.feature-card p  { margin: 0; color: var(--muted); font-size: 14px; }

/* ── Quick start (index) ──────────────────────────────────── */
.steps { display: flex; flex-direction: column; gap: 16px; margin: 0 0 20px; }

.step {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 16px;
  align-items: start;
}

.step-num {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  font-weight: 800;
  font-size: 15px;
  flex-shrink: 0;
}

.step-body h4 { margin: 6px 0 6px; font-size: 15px; }
.step-body p  { margin: 0; color: var(--muted); font-size: 14px; }

/* ── Function reference (stdlib) ──────────────────────────── */
.fn-group { margin-bottom: 40px; }
.fn-group h3 { margin-bottom: 12px; }

.fn-entry {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  margin-bottom: 10px;
  overflow: hidden;
}

.fn-sig {
  padding: 10px 16px;
  background: var(--code-bg);
  color: var(--code-fg);
  font: 14px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.fn-body { padding: 12px 16px; font-size: 14px; }
.fn-body p { margin: 0 0 6px; }
.fn-body p:last-child { margin: 0; }
.fn-body .example { margin-top: 8px; }
.fn-body .example pre { margin: 0; font-size: 13px; }

/* ── Footer ───────────────────────────────────────────────── */
footer {
  border-top: 1px solid var(--line);
  background: var(--panel);
}

footer .footer-inner {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 14px;
  color: var(--muted);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .with-sidebar { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .hero { grid-template-columns: 1fr; padding-top: 40px; }
  .features-grid, .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .topnav-links { display: none; }
}
