/* The code viewer (/code/, web-server-guide § The code viewer) — its only stylesheet.
   The story deck's type and palette, so the two same-origin pages of the bookmarks menu
   read as one family: Newsreader for the headline a file opens with, Atkinson Hyperlegible
   for everything around it, JetBrains Mono for the code. Light is the deck's paper and
   navy ink; dark is its developer section. One accent, the deck's orange, marks the line
   a link points at — nothing else on the page is coloured but the code. */

/* The deck's bundled fonts (docs/presentation/fonts/, SIL OFL), from the deck's own route:
   the CSP's default-src 'self' refuses a font CDN, and one copy beats two. */
@font-face { font-family: "Newsreader"; font-style: normal; font-weight: 400 500; font-display: swap;
  src: url("/story/fonts/newsreader.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("/story/fonts/atkinson-hyperlegible-400.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("/story/fonts/atkinson-hyperlegible-700.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-style: normal; font-weight: 400 600; font-display: swap;
  src: url("/story/fonts/jetbrains-mono.woff2") format("woff2"); }

:root {
  --paper: #F2F4F6;
  --panel: #E9EDF1;
  --well: #FFFFFF;
  --rule: #E3E7EC;
  --edge: #D3D9E0;
  --ink: #16233B;
  --ink-soft: #4A5870;
  --ln: #6B778A;
  --accent: #E8701A;
  --target: #FDF1E6;
  --selected-bg: #16233B;
  --selected-fg: #F2F4F6;
  --mark: #FBD38D;
  --scrim: rgba(22, 35, 59, 0.45);
  /* the code */
  --t-keyword: #2B3F96;
  --t-string: #8A4510;
  --t-doc: #4A5870;
  --t-comment: #5E6B80;
  --t-name: #16233B;
  --t-number: #7A2E59;
  --t-decorator: #3D6B4A;
  --t-variable: #6A3D9A;

  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  color-scheme: light;
}

/* Dark: the system's choice unless the toggle said light; or the toggle's. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #18181B; --panel: #202024; --well: #1F1F23; --rule: #3F3F46; --edge: #52525B;
    --ink: #E5E7EB; --ink-soft: #A1A1AA; --ln: #8B929D; --accent: #F97316; --target: #3A2A12;
    --selected-bg: #E5E7EB; --selected-fg: #18181B; --mark: #FBBF24; --scrim: rgba(0, 0, 0, 0.55);
    --t-keyword: #7DB3F7; --t-string: #FBBF24; --t-doc: #A1A1AA; --t-comment: #A1A1AA;
    --t-name: #F4F4F5; --t-number: #F9A8D4; --t-decorator: #86EFAC; --t-variable: #C4B5FD;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #18181B; --panel: #202024; --well: #1F1F23; --rule: #3F3F46; --edge: #52525B;
  --ink: #E5E7EB; --ink-soft: #A1A1AA; --ln: #8B929D; --accent: #F97316; --target: #3A2A12;
  --selected-bg: #E5E7EB; --selected-fg: #18181B; --mark: #FBBF24; --scrim: rgba(0, 0, 0, 0.55);
  --t-keyword: #7DB3F7; --t-string: #FBBF24; --t-doc: #A1A1AA; --t-comment: #A1A1AA;
  --t-name: #F4F4F5; --t-number: #F9A8D4; --t-decorator: #86EFAC; --t-variable: #C4B5FD;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.5 var(--sans);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}
a { color: var(--ink); }
a:hover { color: var(--ink-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }
.grow { flex-grow: 1; }
[hidden] { display: none !important; }

/* ── the bar ─────────────────────────────────────────────────────────────────────── */
.bar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 12px 28px; border-bottom: 1px solid var(--rule);
}
.brand { font: 500 1.5rem/1.2 var(--serif); text-decoration: none; letter-spacing: -0.01em; }
.tagline { color: var(--ink-soft); font-size: 0.95rem; }
.github { display: inline-flex; align-items: center; gap: 6px; font-size: 0.95rem; }
button { font: inherit; color: inherit; cursor: pointer; }
.icon {
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--rule); background: var(--well); border-radius: 8px;
}
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
html:not(.js) .theme-toggle, html:not(.js) .files-toggle, html:not(.js) .files-close { display: none; }
.files-toggle {
  display: none; align-items: center; gap: 8px; height: 44px; padding: 0 14px;
  border: 1px solid var(--selected-bg); background: var(--selected-bg); color: var(--selected-fg);
  border-radius: 8px; font-weight: 700;
}

/* ── the two columns ─────────────────────────────────────────────────────────────── */
.body { flex: 1; min-height: 0; display: flex; }
main { flex: 1; min-width: 0; overflow: auto; padding: 32px 40px 48px; }
.files {
  width: 340px; flex: none; overflow: auto; background: var(--panel);
  border-left: 1px solid var(--rule); padding: 20px 12px 20px 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.files > * { flex-shrink: 0; }   /* a scrolling column: its rows keep their height */

/* ── the file ────────────────────────────────────────────────────────────────────── */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; color: var(--ink-soft); font-size: 0.95rem; }
.crumbs a { color: var(--ink-soft); }
.crumbs [aria-current] { color: var(--ink); font-weight: 700; }
h1 {
  font: 400 2.25rem/1.2 var(--serif); letter-spacing: -0.01em;
  max-width: 26em; margin: 16px 0 18px; text-wrap: pretty;
}
h1 code { font: 0.8em var(--mono); }
.meta { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin: 0 0 20px; color: var(--ink-soft); }
.button {
  height: 36px; padding: 0 14px; display: inline-flex; align-items: center;
  border: 1px solid var(--edge); background: var(--well); border-radius: 6px;
  color: var(--ink); text-decoration: none; font-size: 0.95rem;
}
.button:hover { border-color: var(--ink-soft); color: var(--ink); }
.notice { background: var(--panel); border-radius: 6px; padding: 10px 14px; color: var(--ink-soft); max-width: 72ch; }

pre.code {
  margin: 0; padding: 16px 0; overflow-x: auto;
  background: var(--well); border: 1px solid var(--rule); border-radius: 8px;
  font: 400 0.84rem/1.65 var(--mono); tab-size: 4;
}
pre.code code { display: inline-block; min-width: 100%; font: inherit; }
.line { display: block; padding-right: 24px; scroll-margin-block: 30vh; }
.ln {
  display: inline-block; min-width: 6ch; padding: 0 2ch 0 1ch; text-align: right;
  color: var(--ln); text-decoration: none; user-select: none;
}
.ln::before { content: attr(data-n); }
.ln:hover { color: var(--ink); }
.line:target { background: var(--target); box-shadow: inset 3px 0 0 var(--accent); }
.line:target .ln { color: var(--ink); font-weight: 600; }

/* Pygments' short token classes (HtmlFormatter), on the palette above. */
.k, .kc, .kd, .kn, .kp, .kr, .ow, .nt { color: var(--t-keyword); font-weight: 600; }
.kt, .nb, .bp, .fm { color: var(--t-keyword); }
.s, .sa, .sb, .sc, .dl, .s1, .s2, .se, .sh, .si, .sx, .sr, .ss { color: var(--t-string); }
.sd { color: var(--t-doc); font-style: italic; }
.c, .ch, .cm, .c1, .cs, .cpf { color: var(--t-comment); font-style: italic; }
.nf, .nc, .ne { color: var(--t-name); font-weight: 600; }
.m, .mb, .mf, .mh, .mi, .il, .mo, .cp, .no { color: var(--t-number); }
.nd, .na { color: var(--t-decorator); }
.nv, .vc, .vg, .vi, .vm { color: var(--t-variable); }
.gh, .gu, .gs { font-weight: 600; }
.ge { font-style: italic; }

/* ── a folder ────────────────────────────────────────────────────────────────────── */
.contents { list-style: none; margin: 0; padding: 0; max-width: 76ch; border-top: 1px solid var(--rule); }
.contents li { padding: 12px 0; border-bottom: 1px solid var(--rule); }
.contents a { font-weight: 700; font-size: 1.05rem; }
.contents p { margin: 4px 0 0; color: var(--ink-soft); }

/* ── the tree ────────────────────────────────────────────────────────────────────── */
.files-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }
.files-head label { font-weight: 700; }
.files-close { display: none; }
#filter {
  height: 40px; border: 1px solid var(--edge); border-radius: 6px; padding: 0 12px;
  font: inherit; font-size: 0.95rem; background: var(--well); color: var(--ink);
}
.filter-count { margin: 0; padding: 0 4px; color: var(--ink-soft); font-size: 0.875rem; }
.tree { font-size: 0.94rem; line-height: 1.35; }
.tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul ul { padding-left: 18px; }
.tree summary, .tree a {
  display: flex; align-items: center; gap: 6px; min-height: 28px; padding: 2px 10px;
  border-radius: 4px; white-space: nowrap; text-decoration: none; cursor: pointer;
}
.tree summary { color: var(--ink-soft); list-style: none; }
.tree summary::-webkit-details-marker { display: none; }
.tree summary::before {
  content: ''; width: 6px; height: 6px; flex: none; margin: 0 4px 0 2px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform 120ms ease;
}
.tree details[open] > summary::before { transform: rotate(45deg); }
.tree a { padding-left: 28px; }
.tree summary:hover, .tree a:hover { background: var(--rule); color: var(--ink); }
.tree a[aria-current="page"] { background: var(--selected-bg); color: var(--selected-fg); font-weight: 700; }
.tree mark { background: var(--mark); color: #18181B; border-radius: 2px; }
.files-foot { margin: auto 0 0; padding: 12px 4px 0; border-top: 1px solid var(--edge); color: var(--ink-soft); font-size: 0.875rem; }

.scrim { display: none; }

/* ── a phone: the tree becomes a drawer from the right ───────────────────────────── */
@media (max-width: 820px) {
  body { height: auto; }
  .bar { padding: 10px 16px; gap: 12px; }
  .tagline, .github { display: none; }
  .icon { width: 44px; height: 44px; }
  .files-toggle { display: inline-flex; }
  .body { display: block; }
  main { overflow: visible; padding: 20px 16px 32px; }
  h1 { font-size: 1.7rem; margin: 12px 0 14px; }
  .button { height: 44px; }
  pre.code { font-size: 0.78rem; }
  .files { width: auto; border-left: 0; border-top: 1px solid var(--rule); }
  .tree summary, .tree a { min-height: 44px; }
  html.js .files {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 2; width: min(340px, 88vw);
    border-top: 0; box-shadow: -12px 0 32px rgba(0, 0, 0, 0.25);
    transform: translateX(100%); visibility: hidden;
    transition: transform 180ms ease, visibility 0s linear 180ms;
  }
  html.js body.files-open .files { transform: none; visibility: visible; transition: transform 180ms ease; }
  html.js .files-close { display: inline-flex; }
  html.js body.files-open .scrim { display: block; position: fixed; inset: 0; z-index: 1; background: var(--scrim); }
  html.js body.files-open { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
