/*
 * The documentation site's stylesheet — Nocturne, the same system the app is
 * built to, so a reader moving between the two does not cross a seam.
 *
 * Deliberately a separate file from `src/styles.css` rather than an import of
 * it: the app's sheet is 3 000 lines about tables, popovers and a stacked bar,
 * none of which a page of prose has. What the two share is the token block
 * below, copied — a documentation page must render from one request without a
 * bundler, and the alternative to copying eight colours is shipping the app's
 * entire sheet to read a paragraph. If a token changes in the app, it changes
 * here; there is nothing else to keep in step.
 */

:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101114;
  --surface: #1c1d21;
  --surface-alt: #2a2b31;
  --surface-sunken: #0b0c0e;
  --border: #52545d;
  --border-strong: #666973;
  --rule: rgba(255, 255, 255, 0.28);

  --text: #e8e8eb;
  --text-2: #e8e8eb;
  --text-3: #cfd1d7;
  --muted: #b8bbc4;
  --faint: #b8bbc4;

  --accent: #b8aeff;
  --accent-hover: #d0c9ff;
  --accent-pale: #d8d2ff;
  --accent-tint: rgba(184, 174, 255, 0.2);
  --accent-tint-2: rgba(184, 174, 255, 0.1);
  --accent-border: rgba(184, 174, 255, 0.5);

  --error: #f4a49b;
  --error-tint: rgba(244, 164, 155, 0.13);
  --error-border: rgba(244, 164, 155, 0.45);

  --warn: #f0e2b0;
  --warn-bar: #d8bb62;
  --warn-border: rgba(216, 187, 98, 0.55);
  --warn-tint: rgba(216, 187, 98, 0.14);

  --font-ui: "Inter", "Geist Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, Menlo, monospace;

  --r-xs: 5px;
  --r-sm: 8px;
  --r-md: 12px;

  --topbar-h: 52px;
  --sidebar-w: 258px;
  --toc-w: 210px;
  /* The measure. Prose wider than this stops being readable — the eye loses
     the start of the next line — and the app's own `--measure` is about tables,
     which is a different problem with a different answer. */
  --prose: 74ch;
}

/* The light ground, from the app's own light block — same reason the dark one is
   copied, and the same rule for it: the accent gets louder by going darker, so
   `--accent-hover` and `--accent-pale` are steps *down* in lightness here. */
[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-alt: #e8ebf3;
  --surface-sunken: #eef0f7;
  --border: #d6dae6;
  --border-strong: #bec3d3;
  --rule: rgba(19, 21, 34, 0.09);

  --text: #262a37;
  --text-2: #343949;
  --text-3: #454b5e;
  --muted: #5c6278;
  --faint: #6e7589;

  --accent: #5a4ac8;
  --accent-hover: #4636ad;
  --accent-pale: #372a8e;
  --accent-tint: rgba(90, 74, 200, 0.13);
  --accent-tint-2: rgba(90, 74, 200, 0.06);
  --accent-border: rgba(90, 74, 200, 0.34);

  --error: #b3261e;
  --error-tint: rgba(179, 38, 30, 0.09);
  --error-border: rgba(179, 38, 30, 0.35);

  --warn: #7a5811;
  --warn-bar: #b98f22;
  --warn-border: rgba(158, 120, 24, 0.42);
  --warn-tint: rgba(185, 143, 34, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  /* anchors land below the sticky bar rather than under it */
  scroll-padding-top: calc(var(--topbar-h) + 16px);
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-2);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent-hover);
  text-decoration-color: var(--accent-tint);
  text-underline-offset: 3px;
}

a:hover {
  color: var(--accent-pale);
  text-decoration-color: currentColor;
}

code,
pre,
.mono {
  font-family: var(--font-mono);
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--surface-alt);
  color: var(--text);
  padding: 10px 16px;
  z-index: 20;
  border-radius: 0 0 var(--r-sm) 0;
}

.skip:focus {
  left: 0;
}

/* --- top bar --------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 22px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 18px;
  height: 18px;
  background: url("/favicon.svg") center / contain no-repeat;
}

.brand-tag {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-pale);
  background: var(--accent-tint-2);
  border: 1px solid var(--accent-border);
  border-radius: 999px;
  padding: 1px 8px;
}

.topbar-links {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 13px;
}

/* The app's chrome-scale segmented control, reproduced — the manual's top bar is
   the same bar, and a reader crossing from the app should not meet a different
   switch. Written by the script that makes it work, like the sidebar filter. */
.themeSwitch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}

.themeSwitch button {
  padding: 1px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.themeSwitch button:hover[aria-pressed="false"] {
  color: var(--text-2);
}

.themeSwitch button[aria-pressed="true"] {
  background: var(--surface-alt);
  color: var(--text);
  font-weight: 500;
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.topbar-links a {
  color: var(--muted);
  text-decoration: none;
}

.topbar-links a:hover {
  color: var(--text);
}

/* --- layout ---------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: 0 40px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 22px;
  align-items: start;
}

/* A page with fewer than two headings prints no rail (the glossary, mostly).
   Reclaim its column instead of leaving a 210px hole beside the prose. */
.layout:not(:has(.toc)) {
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 28px 0 60px;
}

.sidebar-toggle {
  display: none;
}

.nav-filter {
  width: 100%;
  margin-bottom: 18px;
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
}

.nav-filter:focus {
  outline: none;
  border-color: var(--accent-border);
}

.nav-group + .nav-group {
  margin-top: 22px;
}

.nav-title {
  margin: 0 0 7px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--faint);
}

.sidebar ul,
.sidebar-toggle ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--border);
}

.sidebar li a {
  display: block;
  padding: 5px 0 5px 14px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  font-size: 13.5px;
  color: var(--text-3);
  text-decoration: none;
}

.sidebar li a:hover {
  color: var(--text);
}

.sidebar li a.active {
  color: var(--accent-pale);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* --- content --------------------------------------------------------- */

.content {
  min-width: 0;
  padding: 34px 0 80px;
}

.prose {
  max-width: var(--prose);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
}

.prose h1 {
  margin: 0 0 26px;
  font-size: 34px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text);
  font-weight: 600;
}

.prose h2 {
  margin: 44px 0 14px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  font-size: 22px;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--text);
  font-weight: 600;
}

.prose h3 {
  margin: 30px 0 10px;
  font-size: 16.5px;
  color: var(--text);
  font-weight: 600;
}

.prose h4 {
  margin: 24px 0 8px;
  font-size: 14px;
  color: var(--text-2);
  font-weight: 600;
}

.anchor {
  margin-left: 8px;
  color: var(--border-strong);
  text-decoration: none;
  font-weight: 400;
  opacity: 0;
}

h2:hover .anchor,
h3:hover .anchor,
h4:hover .anchor,
.anchor:focus {
  opacity: 1;
}

.prose p {
  margin: 0 0 15px;
}

.prose ul,
.prose ol {
  margin: 0 0 15px;
  padding-left: 22px;
}

.prose li {
  margin-bottom: 7px;
}

.prose li > ul {
  margin: 7px 0 0;
}

.prose strong {
  color: var(--text);
  font-weight: 600;
}

.prose code {
  font-size: 0.875em;
  padding: 1.5px 5px;
  border-radius: var(--r-xs);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
}

.prose pre {
  margin: 0 0 18px;
  padding: 14px 16px;
  overflow-x: auto;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-2);
}

.prose pre code {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
}

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

.prose blockquote {
  margin: 0 0 18px;
  padding: 2px 0 2px 16px;
  border-left: 2px solid var(--border-strong);
  color: var(--text-3);
}

.prose blockquote p:last-child {
  margin-bottom: 0;
}

/* --- callouts (blockquotes with a leading **Note** / **Warning**) ------ */

.callout {
  margin: 0 0 18px;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 14px;
}

.callout p:last-child {
  margin-bottom: 0;
}

.callout-label {
  margin: 0 0 4px !important;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.callout-note {
  border-left-color: var(--accent);
  background: var(--accent-tint-2);
}

.callout-note .callout-label {
  color: var(--accent-pale);
}

.callout-warn {
  border-left-color: var(--warn-bar);
  border-color: var(--warn-border);
  background: var(--warn-tint);
}

.callout-warn .callout-label {
  color: var(--warn);
}

.callout-danger {
  border-left-color: var(--error);
  border-color: var(--error-border);
  background: var(--error-tint);
}

.callout-danger .callout-label {
  color: var(--error);
}

/* --- tables ---------------------------------------------------------- */

.table-scroll {
  margin: 0 0 18px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.prose th {
  text-align: left;
  padding: 9px 14px;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  white-space: nowrap;
}

.prose td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

.prose tr:last-child td {
  border-bottom: 0;
}

.ta-right {
  text-align: right;
}

.ta-center {
  text-align: center;
}

/* --- home page ------------------------------------------------------- */

.home-sections {
  margin-bottom: 34px;
}

.home-section + .home-section {
  margin-top: 30px;
}

.home-h {
  margin: 0 0 4px !important;
  padding-top: 0 !important;
  border-top: 0 !important;
  font-size: 17px !important;
}

.home-blurb {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.home-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
}

.home-list li {
  margin: 0;
  padding: 11px 15px;
  background: var(--surface);
}

.home-list a {
  display: block;
  font-weight: 500;
  text-decoration: none;
  color: var(--accent-pale);
}

.home-list span {
  display: block;
  font-size: 13px;
  color: var(--muted);
}

/* --- on this page ---------------------------------------------------- */

.toc {
  position: sticky;
  top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 40px 0 60px;
  font-size: 13px;
}

.toc-title {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--faint);
}

.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--border);
}

.toc li {
  margin: 0;
}

.toc a {
  display: block;
  padding: 4px 0 4px 13px;
  color: var(--muted);
  text-decoration: none;
  line-height: 1.4;
}

.toc a:hover {
  color: var(--text);
}

.toc-h3 a {
  padding-left: 26px;
  font-size: 12.5px;
}

/* --- pager & footer -------------------------------------------------- */

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  max-width: var(--prose);
  margin-top: 46px;
}

.pager-link {
  display: block;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  text-decoration: none;
}

.pager-link:hover {
  border-color: var(--accent-border);
}

.pager-next {
  text-align: right;
}

.pager-rel {
  display: block;
  font-size: 11.5px;
  color: var(--faint);
}

.pager-title {
  display: block;
  font-weight: 500;
  color: var(--accent-pale);
}

.foot {
  max-width: var(--prose);
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--faint);
}

.foot p {
  margin: 0;
}

/* --- narrow ---------------------------------------------------------- */

@media (max-width: 1180px) {
  .layout,
  .layout:not(:has(.toc)) {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }

  .toc {
    display: none;
  }
}

/* The `:not(:has(...))` selector above outranks a plain `.layout`, so the
   narrow layouts have to repeat it or a rail-less page would keep the wide
   grid on a phone. */
@media (max-width: 860px) {
  .layout,
  .layout:not(:has(.toc)) {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .sidebar {
    display: none;
  }

  .sidebar-toggle {
    display: block;
    margin: 18px 0 0;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface);
  }

  .sidebar-toggle > summary {
    padding: 11px 15px;
    cursor: pointer;
    font-size: 13.5px;
    color: var(--text-2);
  }

  .sidebar-toggle .sidebar-inner {
    padding: 0 15px 15px;
  }

  .sidebar-toggle li a {
    display: block;
    padding: 5px 0 5px 14px;
    font-size: 13.5px;
    color: var(--text-3);
    text-decoration: none;
  }

  .sidebar-toggle li a.active {
    color: var(--accent-pale);
  }

  .prose h1 {
    font-size: 28px;
  }

  .pager {
    grid-template-columns: 1fr;
  }
}
