/* RTFM public site (CC-032). Self-contained: no external fonts, no CDN, no
   frameworks. System font stack, unicode/inline-SVG icons only. Themed via a
   `data-theme` attribute on <html>, set by an inline script in <head> before
   first paint (see site/_layout.html) so there is no flash of the wrong theme.
   Without JS the page still themes correctly, from `prefers-color-scheme`
   alone — the toggle button is a progressive enhancement on top of that. */

:root {
  color-scheme: light dark;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;

  --bg: #ffffff;
  --bg-raised: #f5f7fa;
  --fg: #14171c;
  --fg-muted: #5b6270;
  --border: #dde1e7;
  --accent: #2a5ea8;
  --accent-fg: #ffffff;
  --code-bg: #f1f3f6;
  --focus: #2a5ea8;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2.25rem;
  --space-7: 3.5rem;
  --space-8: 5rem;

  --measure: 68ch;
  --wrap: 72rem;
  --radius: 0.5rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #101317;
    --bg-raised: #181c22;
    --fg: #e8eaee;
    --fg-muted: #9aa2af;
    --border: #2b3038;
    --accent: #7ba9e0;
    --accent-fg: #101317;
    --code-bg: #181c22;
    --focus: #7ba9e0;
  }
}

:root[data-theme="dark"] {
  --bg: #101317;
  --bg-raised: #181c22;
  --fg: #e8eaee;
  --fg-muted: #9aa2af;
  --border: #2b3038;
  --accent: #7ba9e0;
  --accent-fg: #101317;
  --code-bg: #181c22;
  --focus: #7ba9e0;
}

/* Wins over the media-query dark block even when specificity ties, because it
   is declared later: a person who explicitly picks light while their system
   prefers dark must get light. */
:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-raised: #f5f7fa;
  --fg: #14171c;
  --fg-muted: #5b6270;
  --border: #dde1e7;
  --accent: #2a5ea8;
  --accent-fg: #ffffff;
  --code-bg: #f1f3f6;
  --focus: #2a5ea8;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  line-height: 1.6;
  overflow-x: hidden;
}

h1, h2, h3 { font-weight: 700; line-height: 1.25; }
p { margin: 0 0 var(--space-4); }

a { color: var(--accent); }
a:hover { text-decoration: underline; }

code { font-family: var(--font-mono); font-size: 0.9em; background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 0.3rem; }
pre code { background: none; padding: 0; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 0.2rem; }

.muted { color: var(--fg-muted); }

/* -- skip link ---------------------------------------------------------- */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent);
  color: var(--accent-fg);
  padding: var(--space-2) var(--space-4);
  border-radius: 0 0 var(--radius) 0;
  text-decoration: none;
}
.skip-link:focus { left: 0; }

/* -- header --------------------------------------------------------------- */

.site-header {
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.header-inner {
  max-width: var(--wrap);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-3) var(--space-4);
  flex-wrap: wrap;
}
.brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  color: var(--fg);
  text-decoration: none;
}
.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-nav a {
  color: var(--fg-muted);
  text-decoration: none;
  padding-bottom: 0.2rem;
  border-bottom: 2px solid transparent;
}
.site-nav a:hover { color: var(--fg); }
.site-nav a[aria-current="page"] {
  color: var(--fg);
  font-weight: 600;
  border-bottom-color: var(--accent);
}
.repo-link {
  margin-left: auto;
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}
.repo-link:hover { color: var(--accent); }
.theme-toggle {
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--fg);
  border-radius: 999px;
  width: 2.25rem;
  height: 2.25rem;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-icon.icon-light { display: none; }
:root[data-theme="dark"] .theme-icon.icon-dark { display: none; }
:root[data-theme="dark"] .theme-icon.icon-light { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-icon.icon-dark { display: none; }
  :root:not([data-theme]) .theme-icon.icon-light { display: inline; }
}
:root[data-theme="light"] .theme-icon.icon-dark { display: inline; }
:root[data-theme="light"] .theme-icon.icon-light { display: none; }

/* -- page header ------------------------------------------------------------ */

.page-header {
  max-width: var(--wrap);
  margin: 0 auto;
  padding: var(--space-7) var(--space-4) var(--space-5);
}
.page-header h1 { font-size: 2.15rem; margin: 0 0 var(--space-3); }
.page-lead { color: var(--fg-muted); max-width: var(--measure); font-size: 1.1rem; margin: 0; }

/* -- hero (home only) -------------------------------------------------------- */

.hero { padding: var(--space-8) var(--space-4) var(--space-6); border-bottom: 1px solid var(--border); }
.hero-inner { max-width: var(--wrap); margin: 0 auto; }
.hero-headline { font-size: clamp(2rem, 1.2rem + 3vw, 3.25rem); max-width: 22ch; margin: 0 0 var(--space-3); }
.hero-subhead { font-size: 1.15rem; color: var(--fg-muted); max-width: var(--measure); margin: 0 0 var(--space-5); }
.hero-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-bottom: var(--space-4); }
.hero-note { margin: 0 0 var(--space-6); }

.hero-search { max-width: 30rem; padding-top: var(--space-5); border-top: 1px solid var(--border); }
.hero-search-label { display: block; font-size: 0.85rem; color: var(--fg-muted); margin-bottom: var(--space-2); }
.hero-search-row { display: flex; gap: var(--space-2); }
.hero-search-row input {
  flex: 1;
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--fg);
  font: inherit;
}
.hero-search-row button {
  flex-shrink: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-fg);
  padding: var(--space-2) var(--space-4);
  font-weight: 600;
  font: inherit;
  cursor: pointer;
}
.hero-search-note { font-size: 0.8rem; max-width: var(--measure); margin: var(--space-2) 0 0; }

/* -- buttons ----------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 85%, black); text-decoration: none; }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--fg); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

/* -- sections ------------------------------------------------------------------ */

.section { padding: var(--space-7) var(--space-4); border-bottom: 1px solid var(--border); }
.section:last-of-type { border-bottom: none; }
.section-title, .section-lead, .section-content {
  max-width: var(--wrap);
  margin-left: auto;
  margin-right: auto;
}
.section-title { font-size: 1.5rem; margin-bottom: var(--space-3); scroll-margin-top: 4.5rem; }
.section-title .anchor { color: inherit; text-decoration: none; }
.section-title .anchor:hover { text-decoration: underline; }
.section-lead { color: var(--fg-muted); font-size: 1.05rem; margin-bottom: var(--space-5); }
.section-lead, .section-content > p { max-width: var(--measure); }
.section-content > p:last-child { margin-bottom: 0; }

/* -- cards (Section.items) ------------------------------------------------------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: var(--space-4);
}
.cards + p, p + .cards { margin-top: var(--space-4); }
.card { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); background: var(--bg-raised); }
.card-kicker {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 700;
  margin: 0 0 var(--space-2);
}
.card-title { font-size: 1.05rem; margin: 0 0 var(--space-2); }
.card-body { color: var(--fg-muted); margin: 0; }

/* -- snippets (Section.snippets) -------------------------------------------------- */

.snippet {
  margin: var(--space-4) 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  overflow: hidden;
}
.snippet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}
.snippet-label { font-family: var(--font-mono); font-size: 0.8rem; color: var(--fg-muted); }
.snippet-code { margin: 0; padding: var(--space-3); overflow-x: auto; }
.snippet-code code { font-size: 0.85rem; white-space: pre; }

/* Hidden until JS marks <html class="js"> — a copy button that does nothing
   without JS is worse than no button at all. */
.copy-btn {
  display: none;
  font-size: 0.78rem;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  flex-shrink: 0;
}
.js .copy-btn { display: inline-flex; }
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.copy-feedback { margin: 0; padding: 0; font-size: 0.78rem; color: var(--accent); min-height: 0; }
.copy-feedback:not(:empty) { padding: var(--space-1) var(--space-3) 0; }
.snippet-note {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  font-size: 0.82rem;
  color: var(--fg-muted);
  border-top: 1px solid var(--border);
}

/* -- tables (fields, tools' body kept as list below, compare, benchmark) -------- */

.table-scroll { overflow-x: auto; margin: var(--space-4) 0; }
table { border-collapse: collapse; width: 100%; }
table th, table td { text-align: left; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); vertical-align: top; }
table thead th {
  color: var(--fg-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
table.fields code { white-space: nowrap; }

table.compare { min-width: 58rem; }
table.compare th[scope="row"] { min-width: 7rem; white-space: nowrap; }
table.compare th[scope="col"], table.compare td { min-width: 11rem; }

table.benchmark { min-width: 60rem; }

.benchmark-meta { max-width: var(--wrap); margin: 0 auto var(--space-4); font-size: 0.85rem; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* -- tools (Section.tools, /docs) ------------------------------------------------ */

.tools { display: grid; gap: var(--space-3); }
.tool { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3) var(--space-4); background: var(--bg-raised); }
.tool-signature { font-family: var(--font-mono); font-size: 0.9rem; margin: 0 0 var(--space-1); }
.tool-signature .badge {
  font-family: var(--font-sans);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  margin-left: var(--space-2);
}
.tool-body { color: var(--fg-muted); margin: 0; }

/* -- docs table of contents ------------------------------------------------------ */

.docs-layout { max-width: var(--wrap); margin: 0 auto; padding: 0 var(--space-4) var(--space-7); }
.docs-toc {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
}
.docs-toc-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-muted); margin: 0 0 var(--space-2); }
.docs-toc ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); }
.docs-toc a { color: var(--fg); text-decoration: none; font-size: 0.9rem; }
.docs-toc a:hover { color: var(--accent); }
.docs-body .section:first-child { padding-top: 0; }

@media (min-width: 62rem) {
  .docs-layout { display: grid; grid-template-columns: 14rem minmax(0, 1fr); align-items: start; gap: var(--space-6); }
  .docs-toc { position: sticky; top: 4.5rem; margin-bottom: 0; }
  .docs-toc ul { flex-direction: column; }
}

/* -- footer ----------------------------------------------------------------------- */

.site-footer { border-top: 1px solid var(--border); margin-top: var(--space-7); background: var(--bg-raised); }
.footer-inner {
  max-width: var(--wrap);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4) var(--space-4);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: var(--space-5);
}
.footer-heading { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-muted); margin: 0 0 var(--space-2); }
.footer-tagline { color: var(--fg-muted); margin: 0; }
.footer-col ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); }
.footer-col a { color: var(--fg); text-decoration: none; }
.footer-col a:hover { color: var(--accent); text-decoration: underline; }
.footer-note { max-width: var(--wrap); margin: 0 auto; padding: 0 var(--space-4) var(--space-5); color: var(--fg-muted); font-size: 0.85rem; }

/* -- small screens ------------------------------------------------------------------ */

/* Phones. The header wraps to three rows down here — brand, five nav items,
   GitHub + toggle — and sticky chrome that tall eats a quarter of the screen for
   the whole scroll. So on narrow screens it scrolls away with the page, and the
   nav becomes a single swipeable row instead of a stack. No JS, no disclosure
   widget: one row that scrolls is a control every phone user already knows. */
@media (max-width: 48rem) {
  .site-header { position: static; }
  .header-inner {
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    row-gap: var(--space-2);
  }
  .site-nav {
    order: 3;
    flex-basis: 100%;
    overflow-x: auto;
    /* the scrollbar must not add height to a row this tight */
    scrollbar-width: none;
    -ms-overflow-style: none;
    overscroll-behavior-x: contain;
  }
  .site-nav::-webkit-scrollbar { display: none; }
  .site-nav ul {
    flex-wrap: nowrap;
    gap: var(--space-4);
    padding-bottom: 0.15rem;
  }
  .site-nav a { white-space: nowrap; }
  .brand { margin-right: auto; }
}

@media (max-width: 30rem) {
  .hero { padding: var(--space-6) var(--space-4) var(--space-5); }
  .hero-actions .btn { width: 100%; }
  .hero-search-row { flex-direction: column; }
  .hero-search-row button { width: 100%; }
}
