:root {
  --bg: #0a0e16;
  --bg-surface: #161b22;
  --bg-card: #1c2128;
  --text: #f0f3f6;
  --text-dim: #bcc5d0;
  --accent: #50b86c;
  --accent-hover: #3da85a;
  --border: #30363d;
  --topbar-bg: rgba(10, 14, 22, 0.92);
  --layout-max: 1180px;
  --sidebar-width: 220px;
  color-scheme: dark;
}

/* Light mode — honored when the OS / browser asks for it. Same variable
   shape as the dark default; accent green is darkened so links and headings
   hit AA contrast on white. Mirrors the landing palette in site/index.html. */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --bg-surface: #ffffff;
    --bg-card: #eef1f5;
    --text: #1a2030;
    --text-dim: #5a6a80;
    --accent: #1f9550;
    --accent-hover: #16803f;
    --border: #d8dde6;
    --topbar-bg: rgba(244, 246, 249, 0.92);
    color-scheme: light;
  }
}

/* Explicit user override via the theme toggle (site/theme-toggle.js) or
   the wall moon/sun inside the app — both write the same localStorage key
   and the early script in <head> sets data-theme-mode before paint. The
   data-theme-mode blocks beat :root inside @media on specificity, so the
   user pick wins regardless of OS preference. */
:root[data-theme-mode="dark"] {
  --bg: #0a0e16;
  --bg-surface: #161b22;
  --bg-card: #1c2128;
  --text: #f0f3f6;
  --text-dim: #bcc5d0;
  --accent: #50b86c;
  --accent-hover: #3da85a;
  --border: #30363d;
  --topbar-bg: rgba(10, 14, 22, 0.92);
  color-scheme: dark;
}
:root[data-theme-mode="light"] {
  --bg: #f4f6f9;
  --bg-surface: #ffffff;
  --bg-card: #eef1f5;
  --text: #1a2030;
  --text-dim: #5a6a80;
  --accent: #1f9550;
  --accent-hover: #16803f;
  --border: #d8dde6;
  --topbar-bg: rgba(244, 246, 249, 0.92);
  color-scheme: light;
}

/* Theme toggle button. Mounted by site/theme-toggle.js inside .topbar-inner
   on docs pages (gets .theme-toggle--inline). The base style is also used
   on the landing where the script mounts the button fixed top-right. */
.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 90;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.15s, background 0.15s, border-color 0.15s, transform 0.15s;
}
.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
  transform: scale(1.06);
}
.theme-toggle svg {
  width: 18px;
  height: 18px;
}
.theme-toggle--inline {
  position: static;
  width: 32px;
  height: 32px;
}
.theme-toggle--inline svg {
  width: 16px;
  height: 16px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-family: "Space Grotesk", -apple-system, sans-serif; }

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--layout-max);
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 18px;
}
.topbar-brand {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  transition: color 0.15s;
}
.topbar-brand:hover { color: var(--accent); text-decoration: none; }
.topbar-crumb {
  color: var(--text-dim);
  font-size: 0.95rem;
  text-decoration: none;
  transition: color 0.15s;
}
a.topbar-crumb:hover { color: var(--accent); text-decoration: none; }
.topbar-crumb::before { content: "/ "; margin-right: 4px; color: var(--border); }
.topbar-spacer { flex: 1; }
.topbar-links { display: flex; gap: 16px; font-size: 0.9rem; }
.topbar-links a { color: var(--text-dim); transition: color 0.15s; }
.topbar-links a:hover { color: var(--accent); text-decoration: none; }

/* ---- Docs layout (sidebar + main) ---- */
.docs-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: 40px;
  max-width: var(--layout-max);
  margin: 0 auto;
  padding: 32px 24px 64px;
}
.docs-layout > main {
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 64px;
  align-self: start;
  font-size: 0.93rem;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 4px 0 8px;
}
.sidebar-label {
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
  padding: 4px 10px;
}
.sidebar ul { list-style: none; }
.sidebar li { margin-bottom: 1px; }
.sidebar a {
  display: block;
  padding: 6px 10px 6px 12px;
  color: var(--text-dim);
  border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sidebar a:hover {
  color: var(--text);
  background: var(--bg-surface);
  text-decoration: none;
}
.sidebar a.active {
  color: var(--accent);
  background: var(--bg-card);
  border-left-color: var(--accent);
}

/* ---- TOC ---- */
.toc {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 20px;
  margin-bottom: 32px;
}
.toc-label {
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.toc ul { list-style: none; }
.toc li { font-size: 0.92rem; padding: 2px 0; }
.toc li.depth-3 { padding-left: 20px; font-size: 0.88rem; }
.toc a { color: var(--text-dim); }
.toc a:hover { color: var(--accent); text-decoration: none; }

/* ---- Content ---- */
.content h1 {
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.content h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 36px 0 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.content h2:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.content h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  margin: 24px 0 8px;
}
.content h4 {
  font-size: 1rem;
  font-weight: 600;
  margin: 20px 0 6px;
}
.content p { margin-bottom: 14px; color: var(--text-dim); }
.content ul, .content ol { margin: 0 0 14px 22px; color: var(--text-dim); }
.content li { margin-bottom: 4px; }
.content li > ul, .content li > ol { margin-top: 4px; margin-bottom: 4px; }
.content strong { color: var(--text); }
.content em { color: var(--text); }
.content blockquote {
  border-left: 3px solid var(--accent);
  background: rgba(80, 184, 108, 0.06);
  padding: 8px 14px;
  margin: 12px 0;
  color: var(--text-dim);
  border-radius: 0 6px 6px 0;
}
.content blockquote p { margin: 0; }
.content code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, monospace;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.86em;
  color: var(--text);
}
.content pre {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  overflow-x: auto;
  margin: 12px 0 18px;
  line-height: 1.55;
}
.content pre code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: 0.86em;
  color: var(--accent);
}
.content table {
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.92rem;
}
.content th, .content td {
  border: 1px solid var(--border);
  padding: 6px 12px;
  text-align: left;
}
.content th { background: var(--bg-surface); }
.content img { max-width: 100%; border-radius: 6px; margin: 12px 0; }
.content hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

.anchor-link {
  margin-left: 8px;
  color: var(--border);
  font-weight: 400;
  font-size: 0.8em;
  opacity: 0;
  transition: opacity 0.15s;
}
.content h2:hover .anchor-link,
.content h3:hover .anchor-link,
.content h4:hover .anchor-link { opacity: 1; }
.anchor-link:hover { color: var(--accent); text-decoration: none; }

/* ---- Prev/next footer ---- */
.doc-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.doc-nav-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  color: var(--text);
  transition: border-color 0.15s;
}
.doc-nav-card:hover {
  border-color: var(--accent);
  text-decoration: none;
}
.doc-nav-card.next { text-align: right; }
.doc-nav-card .doc-nav-dir {
  font-size: 0.78rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}
.doc-nav-card .doc-nav-title {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600;
  font-size: 1rem;
  color: var(--accent);
}

footer.site-footer {
  max-width: var(--layout-max);
  margin: 32px auto 0;
  padding: 24px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.85rem;
}
.footer-feedback {
  text-align: center;
  margin-bottom: 14px;
}
.footer-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
footer.site-footer .footer-links { display: flex; gap: 18px; }

@media (max-width: 900px) {
  .docs-layout {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 24px 16px 48px;
  }
  .sidebar {
    position: static;
    max-height: none;
    overflow-y: visible;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
  }
  .topbar-inner { padding: 10px 16px; gap: 12px; }
  .topbar-links { gap: 12px; }
  .content h1 { font-size: 1.6rem; }
  .content h2 { font-size: 1.2rem; }
  .doc-nav { grid-template-columns: 1fr; }
  .doc-nav-card.next { text-align: left; }
  .footer-bottom { flex-direction: column; gap: 10px; text-align: center; }
}
