/* Shared by every page: the explainer (index.html), the docs (docs/*.html), and 404.html. */
:root {
  --bg: #fbfbf9;
  --fg: #1b1b1a;
  --muted: #5b5b56;
  --line: #d6d5cf;
  --control: #85857f; /* borders of things you can press or type in: 3:1 on --bg and --panel */
  --panel: #f1f0ec;
  --accent: #1f5f8b;
  --bar: #7b848c;
  --mark-measured: #1b1b1a;
  --mark-p95: #b3261e;
  --warn-bg: #fbf1dc;
  --warn-fg: #6a4600;
  --ok-bg: #e5f0e8;
  --ok-fg: #1d5230;
  --error: #b3261e;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --header-h: 3.25rem;
  color-scheme: light;
}
/* Dark: the system setting, unless the reader chose light; or the reader's choice. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413;
    --fg: #e7e6e1;
    --muted: #a3a29b;
    --line: #3a3a36;
    --control: #6f6f69;
    --panel: #1e1e1c;
    --accent: #7db4dc;
    --bar: #6f7880;
    --mark-measured: #e7e6e1;
    --mark-p95: #f2b8b5;
    --warn-bg: #3a2c0e;
    --warn-fg: #f1d18f;
    --ok-bg: #173022;
    --ok-fg: #a9dcb8;
    --error: #f2b8b5;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413;
  --fg: #e7e6e1;
  --muted: #a3a29b;
  --line: #3a3a36;
  --control: #6f6f69;
  --panel: #1e1e1c;
  --accent: #7db4dc;
  --bar: #6f7880;
  --mark-measured: #e7e6e1;
  --mark-p95: #f2b8b5;
  --warn-bg: #3a2c0e;
  --warn-fg: #f1d18f;
  --ok-bg: #173022;
  --ok-fg: #a9dcb8;
  --error: #f2b8b5;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.55 var(--sans); }
main, footer { max-width: 46rem; margin: 0 auto; padding: 0 1rem; }
.intro { padding-top: 2.5rem; }
h1 { font-size: 1.65rem; line-height: 1.2; margin: 0 0 0.75rem; }
h2 { font-size: 1.25rem; line-height: 1.3; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 1.5rem 0 0.5rem; }
h1, h2, h3, h4, section { scroll-margin-top: calc(var(--header-h) + 1rem); }
p { margin: 0 0 1rem; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code, .num { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.intro nav ul { list-style: none; padding: 0; margin: 1.25rem 0 2rem; display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; }
.intro nav a { font-size: 0.95rem; }
nav a[aria-current="page"] { color: var(--fg); font-weight: 600; text-decoration: none; }
blockquote { margin: 0 0 1rem; padding: 0.75rem 1rem; border-left: 3px solid var(--line); background: var(--panel); }
blockquote p:last-child { margin: 0; }
footer { padding-bottom: 3rem; border-top: 1px solid var(--line); padding-top: 1.5rem; margin-top: 2rem; font-size: 0.9rem; color: var(--muted); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; background: var(--bg); padding: 0.5rem; z-index: 30; }
.offscreen { position: fixed; left: -9999px; top: 0; }

/* ---- the header on every page ------------------------------------------ */

.site-header { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line); }
.site-header .bar { max-width: 80rem; min-height: var(--header-h); margin: 0 auto; padding: 0.4rem 1rem; display: flex; align-items: center; flex-wrap: wrap; gap: 0.35rem 1.75rem; }
.brand { display: inline-flex; align-items: center; gap: 0.4rem; font: 700 1rem var(--mono); color: var(--fg); text-decoration: none; }
.brand .mark { color: var(--accent); }
.primary ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; }
.primary a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.primary a:hover { color: var(--fg); text-decoration: underline; }
.primary a[aria-current="page"] { color: var(--fg); font-weight: 600; }
.tools { margin-left: auto; display: flex; gap: 0.5rem; }
.tools button { font: 0.85rem var(--sans); color: var(--fg); background: var(--panel); border: 1px solid var(--control); border-radius: 4px; padding: 0.3rem 0.65rem; cursor: pointer; white-space: nowrap; }
.tools button:hover { border-color: var(--fg); }
kbd { font: 0.75rem var(--mono); border: 1px solid var(--control); border-radius: 3px; padding: 0 0.3rem; color: var(--muted); }
/* Narrow screens: the links take their own row, and the header scrolls away
   rather than holding two rows of the screen. */
@media (max-width: 48rem) {
  .site-header { position: static; }
  h1, h2, h3, h4, section { scroll-margin-top: 1rem; }
  .primary { order: 3; flex-basis: 100%; }
  .tools kbd { display: none; }
}

/* ---- a status line for copy and theme changes -------------------------- */

.toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); z-index: 40; background: var(--fg); color: var(--bg); padding: 0.4rem 0.85rem; border-radius: 4px; font-size: 0.9rem; opacity: 0; pointer-events: none; transition: opacity 0.15s; }
.toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

@media print {
  .site-header, .skip, .toast, footer { display: none !important; }
  body { background: #fff; color: #000; }
  a { color: inherit; }
}

/* ---- search: a dialog built by site.js --------------------------------- */

dialog.search { width: min(40rem, calc(100vw - 2rem)); max-height: min(36rem, calc(100vh - 4rem)); margin: 4rem auto auto; padding: 0; color: var(--fg); background: var(--bg); border: 1px solid var(--control); border-radius: 8px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25); overflow: hidden; }
dialog.search[open] { display: flex; flex-direction: column; }
dialog.search::backdrop { background: rgba(0, 0, 0, 0.4); }
.search-bar { display: flex; gap: 0.5rem; padding: 0.75rem; border-bottom: 1px solid var(--line); }
.search-bar input { flex: 1; min-width: 0; font: 1rem var(--sans); padding: 0.5rem 0.6rem; color: var(--fg); background: var(--bg); border: 1px solid var(--control); border-radius: 4px; }
.search-close { font: 0.85rem var(--sans); color: var(--fg); background: var(--panel); border: 1px solid var(--control); border-radius: 4px; padding: 0 0.7rem; cursor: pointer; }
.search-note { margin: 0; padding: 0.5rem 1rem 0; font-size: 0.85rem; color: var(--muted); }
.search-note:empty { display: none; }
.search-results { list-style: none; margin: 0; padding: 0.5rem; overflow-y: auto; flex: 1; }
.search-results a { display: block; padding: 0.55rem 0.7rem; border-radius: 6px; text-decoration: none; color: var(--fg); }
.search-results a:hover, .search-results a:focus-visible { background: var(--panel); outline-offset: -2px; }
.search-results .where { display: block; font-weight: 600; color: var(--accent); font-size: 0.95rem; }
.search-results .quote { display: block; font-size: 0.85rem; color: var(--muted); line-height: 1.45; margin-top: 0.15rem; }
.search-results mark { background: var(--warn-bg); color: var(--warn-fg); border-radius: 2px; padding: 0 0.1rem; }
.search-hint { margin: 0; padding: 0.45rem 1rem; border-top: 1px solid var(--line); font-size: 0.78rem; color: var(--muted); }
@media (hover: none) { .search-hint { display: none; } }
@media print { dialog.search { display: none !important; } }
