:root {
  --bg: #0d0f14;
  --bg-alt: #141820;
  --panel: #1a1f2b;
  --border: #242a38;
  --text: #e6e9f0;
  --text-dim: #9aa3b2;
  --accent: #f05a28;
  --accent-dim: #f99470;
  --code-bg: #1e2330;
  --inline-code-bg: rgba(240, 90, 40, 0.1);
  --max: 1200px;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 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.6;
  -webkit-font-smoothing: antialiased;
}

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

code {
  font-family: "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  font-size: 0.9em;
}

:not(pre) > code {
  background: var(--inline-code-bg);
  color: var(--accent-dim);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
}
.skip-link:focus {
  left: 1rem; top: 1rem;
  background: var(--accent); color: #fff;
  padding: 0.5rem 1rem; border-radius: 4px;
}

/* ── Topbar ─────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(13, 15, 20, 0.85);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
}
.brand {
  display: inline-flex; align-items: center; gap: 0.5rem;
  color: var(--text) !important;
  font-weight: 600;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); font-size: 1.2rem; }
.brand-version {
  color: var(--text-dim);
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  margin-left: 0.25rem;
}
.topbar-nav a {
  margin-left: 1.25rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}
.topbar-nav a:hover { color: var(--text); }

/* ── Layout ─────────────────────────────────────────────────────────────── */

.layout {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 3rem;
}

.sidebar {
  position: sticky;
  top: 64px;
  align-self: start;
  padding: 2rem 0;
  height: calc(100vh - 64px);
  overflow-y: auto;
  border-right: 1px solid var(--border);
}
.sidebar nav { padding-right: 1rem; }
.sidebar .nav-group {
  margin: 1.25rem 0 0.35rem;
  color: var(--text-dim);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
}
.sidebar .nav-group:first-child { margin-top: 0; }
.sidebar a {
  display: block;
  padding: 0.3rem 0.75rem;
  color: var(--text-dim);
  border-radius: 5px;
  font-size: 0.9rem;
  border-left: 2px solid transparent;
}
.sidebar a:hover,
.sidebar a.active {
  color: var(--text);
  background: var(--bg-alt);
  border-left-color: var(--accent);
  text-decoration: none;
}

main {
  padding: 2rem 0 6rem;
  min-width: 0; /* allow pre to overflow/scroll within grid */
}

main section {
  padding: 1rem 0 2rem;
  scroll-margin-top: 80px;
}
main section + section {
  border-top: 1px solid var(--border);
  margin-top: 1.5rem;
}

main h1 {
  font-size: 2.25rem;
  line-height: 1.15;
  margin: 0 0 0.75rem;
  letter-spacing: -0.02em;
}
main h2 {
  font-size: 1.6rem;
  margin: 0 0 1rem;
  letter-spacing: -0.01em;
}
main h3 {
  font-size: 1.15rem;
  margin: 1.75rem 0 0.6rem;
  color: var(--text);
}

p.lede {
  font-size: 1.1rem;
  color: var(--text-dim);
  max-width: 60ch;
}

/* ── Pitch grid ─────────────────────────────────────────────────────────── */

.pitch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 2rem 0 0;
}
.pitch-grid > div {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 1.25rem;
  border-radius: 8px;
}
.pitch-grid h3 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
  color: var(--accent-dim);
}
.pitch-grid p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* ── Tables ─────────────────────────────────────────────────────────────── */

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 1rem 0;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
thead {
  background: var(--bg-alt);
}
th, td {
  text-align: left;
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

/* ── Code blocks ────────────────────────────────────────────────────────── */

pre[class*="language-"] {
  background: var(--code-bg) !important;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.15rem;
  font-size: 0.88rem;
  line-height: 1.55;
  overflow-x: auto;
}

/* ── Footer ─────────────────────────────────────────────────────────────── */

footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ── Example sub-pages ──────────────────────────────────────────────────── */

.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0 0 0.75rem;
}
.breadcrumb a { color: var(--text-dim); }
.breadcrumb a:hover { color: var(--accent-dim); }

.callout {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 0.85rem 1rem;
  margin: 1rem 0;
  font-size: 0.9rem;
  color: var(--text-dim);
}
.callout strong { color: var(--text); }
.callout code { font-size: 0.85em; }

.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  margin: 1.25rem 0;
}
.concept-grid > div {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 0.9rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
}
.concept-grid > div strong {
  display: block;
  color: var(--accent-dim);
  margin-bottom: 0.3rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.step-list { list-style: none; padding: 0; margin: 1rem 0; counter-reset: steps; }
.step-list > li {
  counter-increment: steps;
  position: relative;
  padding: 0.6rem 0 0.6rem 3rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.925rem;
}
.step-list > li:last-child { border-bottom: none; }
.step-list > li::before {
  content: counter(steps);
  position: absolute;
  left: 0;
  top: 0.6rem;
  width: 1.75rem;
  height: 1.75rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.example-links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.6rem;
  margin: 0.75rem 0 0;
}
.example-links-grid a {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.9rem;
  font-size: 0.875rem;
  color: var(--text-dim);
  transition: border-color 0.15s, color 0.15s;
}
.example-links-grid a:hover {
  border-color: var(--accent);
  color: var(--text);
  text-decoration: none;
}
.example-links-grid a.current {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(240, 90, 40, 0.06);
}
.example-links-grid a span {
  display: block;
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

.output-block {
  background: #0a0c10;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.15rem;
  font-family: "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  color: #b8c2d4;
  overflow-x: auto;
  white-space: pre;
}
.output-block .dim { color: #5a6478; }
.output-block .accent { color: var(--accent-dim); }

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .sidebar {
    display: none;
  }
  main h1 { font-size: 1.8rem; }
  main h2 { font-size: 1.35rem; }
}
