/* Basic reset */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 16px/1.6 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

:root {
  color-scheme: light dark;

  /* Spacing */
  --topbar-h: 56px;
  --sidebar-w: 280px;
  --toc-w: 260px;

  /* Light palette */
  --bg: #ffffff;
  --bg-elev: #f6f7f9;
  --fg: #1c1e21;
  --muted: #606770;
  --border: #e3e6ea;
  --link: #2458d6;
  --code-bg: #f2f4f8;

  --shadow: 0 1px 10px rgba(0, 0, 0, 0.06);
}

html[data-theme="dark"] {
  --bg: #0f1115;
  --bg-elev: #151a21;
  --fg: #e7e9ee;
  --muted: #a3aab6;
  --border: #262c36;
  --link: #7aa2ff;
  --code-bg: #111723;

  --shadow: 0 1px 10px rgba(0, 0, 0, 0.35);
}

body {
  background: var(--bg);
  color: var(--fg);
}

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

.skip-link {
  position: absolute;
  left: 8px;
  top: 8px;
  padding: 8px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
}

.brand {
  font-weight: 650;
  letter-spacing: 0.2px;
}

.topbar-spacer { flex: 1; }

.icon-btn, .pill {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  height: 36px;
  border-radius: 12px;
  padding: 0 10px;
  cursor: pointer;
  box-shadow: none;
}

.icon-btn {
  width: 40px;
  padding: 0;
}

.icon-btn.subtle {
  border-color: transparent;
  background: transparent;
}

.icon-btn:hover, .pill:hover {
  filter: brightness(1.02);
}

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow: auto;
}

.sidebar-toc {
  border-right: 0;
  border-left: 1px solid var(--border);
}

.sidebar-inner { padding: 14px; }
.sidebar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.sidebar-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.nav-caption {
  margin-top: 16px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav-tree ul {
  list-style: none;
  padding: 0;
  margin: 8px 0;
}

.nav-tree a {
  display: block;
  padding: 8px 10px;
  border-radius: 12px;
  color: var(--fg);
}

.nav-tree a.active {
  background: color-mix(in srgb, var(--link) 12%, var(--bg-elev));
  border: 1px solid color-mix(in srgb, var(--link) 25%, var(--border));
}

.content {
  min-width: 0;
  padding: 28px 22px 60px;
}

.content-inner {
  max-width: 900px;
  margin: 0 auto;
}

.breadcrumbs ol {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
  display: flex;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.breadcrumbs li::after {
  content: "/";
  margin-left: 8px;
  color: var(--border);
}

.breadcrumbs li:last-child::after { content: ""; }

h1 { font-size: 2rem; line-height: 1.2; margin: 0 0 14px; }
h2 { margin-top: 28px; }
h3 { margin-top: 18px; }

.callout {
  padding: 12px 14px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: 14px;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  overflow: auto;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

.footer { color: var(--muted); font-size: 14px; }

.toc {
  font-size: 14px;
}

.toc a {
  color: var(--fg);
  display: block;
  padding: 6px 8px;
  border-radius: 10px;
}

.toc a:hover {
  background: color-mix(in srgb, var(--fg) 6%, transparent);
  text-decoration: none;
}

.toc .toc-h3 { padding-left: 18px; color: var(--muted); }

.back-to-top {
  position: fixed;
  right: 16px;
  bottom: 16px;
  height: 44px;
  width: 44px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 60;
}

/* Desktop collapse toggles */
body.nav-collapsed .layout { grid-template-columns: 64px minmax(0, 1fr) var(--toc-w); }
body.nav-collapsed .sidebar-nav .nav-tree a { padding: 8px; text-align: center; }
body.nav-collapsed .sidebar-nav .nav-caption,
body.nav-collapsed .sidebar-nav .sidebar-title { display: none; }

body.toc-collapsed .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) 0; }
body.toc-collapsed .sidebar-toc { display: none; }

/* Mobile overlays */
.overlay {
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: rgba(0,0,0,0.35);
  z-index: 40;
}

@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h));
    width: min(92vw, 340px);
    z-index: 45;
    transform: translateX(-110%);
    transition: transform 160ms ease;
    box-shadow: var(--shadow);
  }

  .sidebar-toc {
    right: 0;
    left: auto;
    transform: translateX(110%);
    border-left: 1px solid var(--border);
    border-right: 0;
  }

  body.nav-open .sidebar-nav { transform: translateX(0); }
  body.toc-open .sidebar-toc { transform: translateX(0); }

  .content { padding: 18px 14px 70px; }
}

