/* ==========================================================================
   Handbook — a documentation theme.

   Ships its own shell (header/footer with a sidebar) and loads the core
   main.css first, then these rules. Mobile-first: the sidebar stacks above
   the content and becomes a sticky column from 60rem up. Three reader
   controls, each stored in localStorage and applied as a data- attribute
   on <html> before first paint:

       data-theme        light | dark      (day / night, via main.js)
       data-doc-layout   sidebar | wide
       data-doc-density  cozy | compact
   ========================================================================== */

:root {
  --font-body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: var(--font-body);
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --accent: #2563eb;
  --bg: #fbfbfa; --bg-soft: #f1f2f4; --surface: #ffffff;
  --line: #e4e7eb; --text: #1f2328; --muted: #656d76;
  --radius: 4px; --measure: 44rem;
  --docs-nav-w: 15rem; --docs-top-h: 3.6rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --bg-soft: #161b22; --surface: #161b22;
    --line: #2a323c; --text: #e6edf3; --muted: #9aa4af; --accent: #4b8dff;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --bg-soft: #161b22; --surface: #161b22;
  --line: #2a323c; --text: #e6edf3; --muted: #9aa4af; --accent: #4b8dff;
}
:root[data-theme="light"] {
  --bg: #fbfbfa; --bg-soft: #f1f2f4; --surface: #ffffff;
  --line: #e4e7eb; --text: #1f2328; --muted: #656d76; --accent: #2563eb;
}

/* ---- top bar ----------------------------------------------------------- */
.docs-top { position: sticky; top: 0; z-index: 40; background: var(--bg); border-bottom: 1px solid var(--line); }
.docs-top__inner { display: flex; align-items: center; gap: 1rem; width: min(100% - 2rem, 84rem); margin-inline: auto; min-height: var(--docs-top-h); }
.docs-ctl { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { padding: 0.3rem 0.62rem; font-size: var(--step--1); color: var(--muted); background: none; border: 0; line-height: 1.6; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { color: var(--text); }
.seg button.is-active { background: var(--accent); color: #fff; }

/* ---- body layout ------------------------------------------------------- */
.docs-body {
  display: grid; grid-template-columns: 1fr; gap: clamp(1.5rem, 4vw, 2.5rem);
  width: min(100% - 2rem, 84rem); margin-inline: auto;
  padding-block: clamp(1.5rem, 4vw, 2.5rem);
}

.docs-nav { font-size: var(--step--1); }
.docs-nav__group + .docs-nav__group { margin-top: 1.1rem; }
.docs-nav__title { display: block; font-weight: 640; color: var(--text); text-decoration: none; letter-spacing: -0.01em; }
.docs-nav__title:hover { color: var(--accent); }
.docs-nav ul { list-style: none; padding: 0; margin: 0.4rem 0 0; display: grid; gap: 0.15rem; border-left: 1px solid var(--line); }
.docs-nav li a { display: block; padding: 0.2rem 0 0.2rem 0.85rem; margin-left: -1px; color: var(--muted); text-decoration: none; border-left: 2px solid transparent; }
.docs-nav li a:hover { color: var(--text); }
.docs-nav a.is-current { color: var(--accent); border-left-color: var(--accent); font-weight: 560; }

.docs-main { min-width: 0; }
.docs-main .container, .docs-main .container--narrow { width: 100%; max-width: var(--measure); margin-inline: 0; }
.docs-main .hero { padding-block: clamp(1.5rem, 4vw, 3rem); }
.docs-main .article-head { padding-block: clamp(1rem, 3vw, 2rem) clamp(1rem, 3vw, 1.5rem); }

@media (min-width: 60rem) {
  .docs-body { grid-template-columns: var(--docs-nav-w) minmax(0, 1fr); }
  .docs-nav {
    position: sticky; top: calc(var(--docs-top-h) + 1rem); align-self: start;
    max-height: calc(100dvh - var(--docs-top-h) - 2rem); overflow: auto;
    padding-right: 0.5rem;
  }
}

/* ---- layout switch: "wide" drops the sidebar and re-centres the text ---- */
[data-doc-layout="wide"] .docs-nav { display: none; }
[data-doc-layout="wide"] .docs-main .container,
[data-doc-layout="wide"] .docs-main .container--narrow { max-width: 60rem; margin-inline: auto; }
@media (min-width: 60rem) {
  [data-doc-layout="wide"] .docs-body { grid-template-columns: minmax(0, 1fr); }
}

/* ---- density switch ---------------------------------------------------- */
[data-doc-density="compact"] body { line-height: 1.5; }
[data-doc-density="compact"] .docs-main .prose { font-size: var(--step--1); }
[data-doc-density="compact"] .docs-main .prose > * + * { margin-top: 0.95em; }
[data-doc-density="compact"] .docs-nav li a { padding-block: 0.12rem; }

/* ---- documentation-flavoured prose ------------------------------------- */
.prose h2 { padding-top: 0.5em; border-top: 1px solid var(--line); }
.prose pre { border: 1px solid var(--line); border-radius: var(--radius); }
.prose code { border-radius: 3px; }
.button { border-radius: var(--radius); }
.tag { border-radius: var(--radius); }

/* ---- footer ------------------------------------------------------------ */
.docs-foot { border-top: 1px solid var(--line); margin-top: 2rem; }
.docs-foot .docs-top__inner { min-height: 0; padding-block: 1.25rem; gap: 1rem; flex-wrap: wrap; }
.docs-foot a { color: var(--muted); text-decoration: none; }
.docs-foot a:hover { color: var(--text); }
