/* ==================================================================== *
 * base.css — reset, page material, typography, the document frame.
 * ==================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--bar-h) + 1.5rem);
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-text);
  font-size: var(--t-base);
  line-height: var(--lh-body);
  font-weight: 400;
  /* Inter ships a real italic, so nothing needs synthesising. Brutal
     Milk does not — but it only sets headings now, which are never
     italic. */
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---- typography ---------------------------------------------------- */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--f-display);
  line-height: var(--lh-tight);
  letter-spacing: -0.014em;
  margin: 0 0 var(--sp-3);
  text-wrap: balance;
}
h1 { font-size: var(--t-3xl); font-weight: 700; letter-spacing: -0.028em; }

/* A chapter heading is a section break, so it gets a rule above it and
   real air. On a long page these are the landmarks you scroll to. */
h2 {
  font-size: var(--t-xl); font-weight: 650;
  margin-top: var(--sp-8); padding-top: var(--sp-5);
  border-top: 1px solid var(--rule);
}
h3 { font-size: var(--t-lg); font-weight: 620; margin-top: var(--sp-7); }
h4 { font-size: var(--t-md); font-weight: 620; margin-top: var(--sp-5); }
/* The small all-caps headings are labels, not display type — they belong
   to the same register as the mono annotations. */
h5, h6 {
  font-family: var(--f-code);
  font-size: var(--t-xs); font-weight: 700; margin-top: var(--sp-5);
  text-transform: uppercase; letter-spacing: .1em; color: var(--ink-sub);
}

p { margin: 0 0 var(--sp-4); }
p, li { text-wrap: pretty; }

a { color: inherit; text-decoration-color: var(--rule-strong); text-underline-offset: .18em; }
a:hover { text-decoration-color: currentColor; }

strong, b { font-weight: 650; }
em, i { font-style: italic; }

ul, ol { margin: 0 0 var(--sp-4); padding-left: 1.4rem; }
li { margin-bottom: var(--sp-2); }
li::marker { color: var(--ink-sub); }

hr { border: 0; height: 1px; margin: var(--sp-7) 0; background: var(--rule); }

code, kbd, samp, pre { font-family: var(--f-code); font-variant-ligatures: none; }

/* Inline code is a term being named — the same job as a definition — so
   it takes the same butter wash. */
:not(pre) > code {
  font-size: .855em;
  padding: .12em .34em;
  border-radius: 3px;
  background: color-mix(in oklab, var(--butter) var(--wash), var(--card));
  color: var(--ink);
  /* NOT nowrap: a long identifier inside a heading or a summary must be
     allowed to break, or it forces the whole line into a narrow column. */
  overflow-wrap: break-word;
}

::selection { background: color-mix(in oklab, var(--butter) 70%, var(--card)); color: var(--ink); }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: var(--radius); }

.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: var(--sp-4); top: -4rem; z-index: 60;
  background: var(--card); border: 1px solid var(--rule-strong);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--radius);
  transition: top .15s var(--ease);
}
.skip:focus { top: calc(var(--bar-h) + .5rem); }

/* ==================================================================== *
 * The bar
 * ==================================================================== */

.bar {
  position: sticky; top: 0; z-index: 40;
  height: var(--bar-h);
  display: flex; align-items: center; gap: var(--sp-4);
  padding: 0 var(--gutter);
  background: color-mix(in oklab, var(--paper) 86%, transparent);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  border-bottom: 1px solid var(--rule);
}
.bar-mark {
  font-family: var(--f-display);
  font-weight: 650; font-size: var(--t-sm); letter-spacing: -.01em;
  text-decoration: none; white-space: nowrap;
  display: flex; align-items: center; gap: .5rem;
}
.bar-mark .dot {
  width: .46rem; height: .46rem; border-radius: 50%;
  background: var(--ink); flex: none;
}
.bar-crumb {
  font-family: var(--f-code); font-size: var(--t-xs);
  color: var(--ink-sub); letter-spacing: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 1px solid var(--rule); padding-left: var(--sp-4);
}
.bar-sp { flex: 1 1 auto; }
.bar-acts { display: flex; align-items: center; gap: var(--sp-2); flex: none; }

.btn {
  font: inherit; font-size: var(--t-xs); font-family: var(--f-code);
  color: var(--ink-dim); background: transparent;
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: .36rem .6rem; cursor: pointer; line-height: 1;
  display: inline-flex; align-items: center; gap: .4rem;
  transition: background .13s var(--ease), border-color .13s var(--ease), color .13s var(--ease);
}
.btn:hover:not(:disabled) { background: var(--recessed); border-color: var(--rule-strong); color: var(--ink); }
.btn:disabled { opacity: .38; cursor: default; }
.btn[aria-pressed="true"], .btn.on {
  background: color-mix(in oklab, var(--butter) var(--wash), var(--card));
  border-color: var(--rule-strong); color: var(--ink);
}
.btn svg { width: 14px; height: 14px; flex: none; }

/* ==================================================================== *
 * The document frame
 *
 * The prose column is centred in the VIEWPORT, not in whatever space the
 * rails leave over. That difference is the whole reason the earlier
 * layout felt shoved to one side: a three-column grid centres the grid,
 * which pushes the text right of centre by half the left rail and then
 * left again by half the right one, and the text never sits where the
 * eye expects it.
 *
 * So: the rails are positioned against the viewport edges and the
 * article is a plain centred column. On a wide screen the reading column
 * is exactly in the middle of the screen; when the window is too narrow
 * to hold rails and a full measure, the rails withdraw and the column
 * stays put.
 * ==================================================================== */

.page { position: relative; }

.prose {
  max-width: var(--wide);
  margin: 0 auto;
  padding: var(--sp-7) var(--gutter) var(--sp-8);
}

/* Words get a reading measure; artifacts — figures, code, tables,
   terminal transcripts — get the full column, because a diagram squeezed
   to a paragraph's width is a diagram you cannot read. Both share a left
   edge, so the page keeps a spine. */
.prose > :where(p, ul, ol, dl, h1, h2, h3, h4, h5, h6, hr, blockquote,
                .lede, .kicker, .plain, .analogy, .warn, .exam, .note,
                .spec, .defn, .recall, .grid2, .pagenav, .split, .ask,
                .q-hd, .ans-hd) {
  max-width: var(--measure);
}
.prose > :where(.fig, .cw, .tw, pre, .term, .bleed, .w, section) { max-width: none; }
.prose > * { margin-inline-start: 0; }
.bleed { max-width: none; }

/* Inside a question or a details panel the same rule has to apply again,
   since those wrap their own paragraphs. */
.q > :where(p, ul, ol, .split, .ask, .exam, .note, .warn, .plain, .spec) {
  max-width: var(--measure);
}

.rail {
  position: fixed;
  top: var(--bar-h);
  max-height: calc(100dvh - var(--bar-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-6) var(--sp-4) var(--sp-8);
  font-size: var(--t-sm);
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
  z-index: 30;
}
.rail::-webkit-scrollbar { width: 7px; }
.rail::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 4px; }

.rail-l { left: 0; width: var(--rail-l); padding-left: var(--gutter); }
.rail-r { right: 0; width: var(--rail-r); padding-right: var(--gutter); }

/* The rails only appear when there is genuinely room for them beside a
   full-width reading column — never by squeezing it. */
@media (max-width: 1500px) { .rail-r { display: none; } }
@media (max-width: 1180px) {
  .rail-l {
    inset: var(--bar-h) auto 0 0;
    width: min(21rem, 86vw);
    background: var(--card);
    border-right: 1px solid var(--rule);
    padding: var(--sp-5) var(--gutter) var(--sp-8);
    transform: translateX(-102%);
    transition: transform .22s var(--ease);
    box-shadow: 8px 0 40px -24px var(--shadow-edge);
  }
  .rail-l.open { transform: none; }
  .rail-scrim {
    position: fixed; inset: var(--bar-h) 0 0; z-index: 29;
    background: color-mix(in oklab, var(--ink) 30%, transparent);
    opacity: 0; pointer-events: none; transition: opacity .22s var(--ease);
  }
  .rail-scrim.on { opacity: 1; pointer-events: auto; }
}
@media (min-width: 1181px) { .rail-toggle, .rail-scrim { display: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
