/* The document viewport: the one element a KPress document scrolls inside.
   It is the `@container kpress-doc` query container. The standalone page shell
   sets it on `kpress-page-main`; an embedding host sets the same class/attribute
   on its own scroll pane. This is what lets the TOC react to the document's real
   width.

   CRITICAL: the viewport must NOT be a containing block for `position: fixed`
   descendants — no transform/filter/perspective/backdrop-filter here. A
   transformed ancestor makes fixed descendants behave like `position: absolute`,
   and absolutely-positioned children of a scroller move with the scrolled
   content: every piece of floating UI (TOC toggle/drawer/backdrop, settings
   menu) would sit at the top of the *document* and scroll away exactly when it
   should appear. The fixed containing block lives one level up, on the
   non-scrolling `.kpress-frame`. */
.kpress-viewport {
  block-size: 100dvh;
  overflow-y: auto;
  container: kpress-doc / inline-size;
  /* The containing block for the popover layer: footnote and link previews are
     appended here and placed with `position: absolute` in PAGE coordinates, so
     they scroll with the paragraph they belong to (tooltips.js,
     `tooltipParent`). `position: relative` is not one of the properties the
     warning above names: it does NOT make this a containing block for
     `position: fixed` descendants, so that rule stands unchanged. */
  position: relative;
  /* In-document hash navigation (TOC and section links) is native browser
     navigation; the glide lives here so it also honors the reduced-motion
     override below. */
  scroll-behavior: smooth;
}

/* A drawer lock hides the scrollbar. Keep its space so the lock cannot change
   the container width and switch the drawer into a rail. */
.kpress-viewport:has(.kpress-toc.kpress-mobile-visible) {
  scrollbar-gutter: stable;
}

/* The document frame: a non-scrolling wrapper of the viewport that pins the
   floating UI. `transform` is the universally-honored trigger that makes it the
   containing block for `position: fixed` descendants; because the frame does not
   scroll, the floating UI stays pinned to its box while the viewport's content
   scrolls beneath it. Standalone, the page shell marks `<body>` (whose box is
   exactly the window). An embedding host puts this class/attribute on a
   non-scrolling wrapper of its scroll pane so the floating UI pins to the pane
   instead of escaping over the host's own chrome; a host that omits it gets
   window-pinned floating UI. */
.kpress-frame {
  transform: translateZ(0);
}

/* The standalone page scroller carries the document background/text so the
   whole window is themed (the embedded host owns its own pane background, so
   this targets the standalone-only `.kpress-page-main`, not `.kpress-viewport`). */
.kpress-page-main {
  background: var(--kpress-doc-bg);
  color: var(--kpress-doc-text);
  padding-inline: var(--kpress-page-margin-inline);
  padding-block-start: var(--kpress-page-margin-block-start);
}

/* Standalone pages on phones: the 2rem gutter is a third of the padding stack;
   narrow it so the reading column keeps its width. */
@media (max-width: 767px) {
  .kpress-page-main {
    --kpress-page-margin-inline: 0.5rem;
  }
}

/* ─────────────────────────────────────────────────────────────────
   Document layout + Table of Contents: the responsive system.

   READ THIS BEFORE TOUCHING THE TOC OR TABLE WIDTHS — the pieces are
   coupled and the failure modes are non-obvious.

   DOM (emitted by format/render.py):
     article.kpress-doc                       reading-measure cap #1
       div.kpress-doc-layout.kpress-content-with-toc   cap #2 + TOC grid
         nav.kpress-toc                        the TOC (sidebar OR drawer)
         div.kpress-prose.kpress-long-text     the article body

   THE RAIL IS A LAYOUT SLOT, NOT A CONSEQUENCE OF THE TOC. Three conditions
   select the wide band's two-column grid, and every wide-band rule that keys
   off the TOC must list all three or the layouts split apart:
     .has-toc                              host-forced (embedding escape hatch)
     :has(.kpress-toc)                     a TOC was rendered
     [data-kpress-toc-rail="reserved"]     rail held open, no TOC rendered
   The third is stamped by render.py when RenderOptions.toc_rail = "reserved"
   and the document fell under toc_min_headings. Without it such a document
   drops out of the grid and back to the centred single column — which moves
   the prose sideways AND narrows it (the unguarded 2.5rem
   `.kpress-content-with-toc .kpress-long-text` inset is sized for the 53rem
   grid track, so against the 48rem cap it eats 5rem of measure). Under
   toc_rail "auto" (the default) nothing is stamped and that fallback stands.

   THE WIDTH CHAIN. `--kpress-measure` is the width of the TEXT, padding
   excluded. Three nested elements bound the column, and each adds back exactly
   the padding that sits between it and the text:

     .kpress-doc         measure + 2x inset + 2x gutter   (document.css)
     .kpress-doc-layout  measure + 2x inset               (document.css)
     .kpress-long-text   measure + 2x inset, padded by the inset

   so the text lands at the measure in every band. `--kpress-column-inset` is
   the band's inline padding inside the column (1.5rem phone / 4rem single
   column / 2.5rem in the wide TOC grid) and `--kpress-doc-gutter` is the page
   margin outside it; the bands reset those two tokens on `.kpress-doc` and the
   caps follow. Nothing in the chain restates a length the tokens already carry.

   Write any new cap the same way. The bug this shape replaced was three caps
   that each added a different subset of the padding: `.kpress-long-text` used a
   literal `48rem` that duplicated the measure and omitted the inset, so the
   same token meant "the text" in the wide band and "the text plus 8rem" in the
   single-column one — a 10rem step in reading width across the wide-band boundary —
   and a host that set the token moved almost nothing, because two of the three
   caps and the grid track never read it.

   All three cap elements centre via margin:auto. Plain single-column reading
   wants all of them. Any layout that needs the full pane must uncap the outer
   two — uncapping only the article leaves `.kpress-doc-layout` centred at the
   measure, which reads as a large left margin with the grid tracks spilling off
   its right edge.

   Everything responsive keys off `@container kpress-doc` — the width of the
   scroll pane (`.kpress-viewport`), NOT the window — so it is correct both
   standalone and embedded in a host pane narrower than the window. Three
   mutually exclusive bands, each defined once below:

     >= 70rem   WIDE     TOC is a sticky left sidebar. Uncaps the outer two
                         caps; grid is `15rem <column box>`, left-aligned
                         (justify-content: start) so the reading text is a
                         constant measure and all extra width is one right-hand
                         margin. Column inset 2.5rem.
     48-70rem   TABLET   Single column; TOC is a fixed drawer + toggle.
                         Column inset 4rem.
     < 48rem    MOBILE   Single column; drawer; tighter type. Column inset
                         1.5rem.

   The band conditions are literal lengths because a container query cannot read
   var(). They are therefore the one part of this system that does NOT follow
   the measure: a host that changes the measure changes the reading width, not
   where the bands switch. The wide band's track carries a `min()` guard so an
   over-large measure degrades instead of overflowing the pane at the floor.

   TABLE INVARIANT: only tables marked `data-kpress-table-scale="wide"`
   (stamped by the renderer / tables.js past the TABLE_WIDE_MIN_* cutoff)
   ever leave the reading column; unmarked tables cap at the column in
   every band. The base wide rule (further down) is a column-centred
   full-bleed — left:50% + translateX(-50%), width keyed off 100cqw so it
   caps at the kpress-doc pane, never the window. That centred bleed is
   only right for a centred single column (with or without a pane
   narrower than the window). Bands that left-align the column (the
   wide-band TOC grid) or want internal scrolling instead MUST neutralise
   it (left:0; transform:none; a left-anchored width) AT OR ABOVE THE
   ATTRIBUTE SELECTOR'S SPECIFICITY (list the
   [data-kpress-table-scale="wide"] variant in the reset) or wide tables
   centre on the column and overhang the layout. All three bands carry
   that reset today; if you add a band, add the reset too.
   ───────────────────────────────────────────────────────────────── */
.kpress-content-with-toc {
  position: relative;
}

.kpress-content-with-toc.has-toc,
.kpress-content-with-toc:has(.kpress-toc) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

/* Cap #3 of the width chain: the column itself. max-width is a border box, so
   it is the measure PLUS the inset; the padding then gives the measure back as
   text. The two must be written from the same token or they drift -- this rule
   previously capped at a literal `48rem` that duplicated the measure and did
   not add the inset, so the text came out one inset-pair narrower than the
   measure asked for, and the literal ignored a host that set the token. */
.kpress-long-text {
  background: var(--kpress-doc-bg);
  margin-inline: auto;
  max-width: min(100%, calc(var(--kpress-measure) + 2 * var(--kpress-column-inset)));
  padding: 1rem var(--kpress-column-inset);
}

/* Container, not viewport: the phone band that undoes this
   (`@container kpress-doc (max-width: 47.99rem)`, far below) keys off the
   scroll pane, so a viewport query here disagrees with it whenever the two
   differ — which is every embedded host. 48rem is the same boundary from the
   other side. */
@container kpress-doc (min-width: 48rem) {
  /* Set on .kpress-doc, not on the column: all three caps in the chain read the
     inset, so a band that changed only the column's padding would move the text
     inside a box the outer two still sized for 1.5rem. */
  .kpress-doc {
    --kpress-column-inset: 4rem;
  }
}

/* Content card: the reading column rendered as a bordered sheet floating
   over the page — textpress's long-text card (hairline + soft shadow at md+;
   narrow screens stay full-bleed, same as textpress). The geometry is
   ALREADY the card's (.kpress-long-text's 48rem cap and md 4rem inline
   padding above are kash's max-w-3xl + md:px-16), so this adds chrome only —
   no layout-affecting properties, which keeps the coupled TOC/table width
   system untouched. Render-time switch: RenderOptions.content_card /
   `format.content_card` stamps data-kpress-card on the article ("on" is the
   default); embedding hosts stamp the same attribute on the fragment wrapper
   themselves. Chrome tokens: --kpress-card-border / --kpress-card-shadow
   (style-tokens.css).

   Container-queried at the same 48rem boundary as the inline padding above,
   and for the same reason: the card's whole premise is that the geometry is
   already the card's. Keyed to the viewport instead, a host pane narrower
   than 48rem inside a window wider than 768px drew the border around the
   phone band's 0.75rem gutter — a hairline pressed against the text and
   through the disclosure chevrons. Narrow stays full-bleed, as textpress
   does; "narrow" just has to mean the pane, not the window. */
@container kpress-doc (min-width: 48rem) {
  .kpress[data-kpress-card="on"] .kpress-long-text {
    border: var(--kpress-card-border);
    box-shadow: var(--kpress-card-shadow);
    /* Breathing room around the text: vertical only here (inline padding is
       the band system's business — 4rem single-column, 2.5rem in the wide
       TOC track — so the card never touches the coupled width math). */
    padding-block: 2.5rem 3rem;
  }

  /* Breathing room below the card before the page (or footer) ends. On the
     article so it composes with .kpress-doc's own padding; vertical only. */
  .kpress-doc[data-kpress-card="on"] {
    padding-block-end: 6rem;
  }
}

.kpress-header-row {
  align-items: center;
  display: flex;
}

.kpress-header-grow {
  flex: 1 1 auto;
  margin-inline-start: 0.5rem;
}

.kpress-header-actions {
  align-items: center;
  display: flex;
  gap: 0.5rem;
  margin-inline-start: auto;
}

.kpress-page-spacer {
  margin-top: 1.5rem;
}

/* Settings menu: a gear button that opens a popover of segmented icon
   choosers (theme today; more can be added). Ported from the original host
   app's settings control, re-tokenized onto KPress document tokens so it
   themes with the document. The wrapper's `aria-expanded` drives menu visibility. */
.kpress-settings {
  inset-block-start: var(--kpress-settings-inset-block);
  inset-inline-end: var(--kpress-settings-inset-inline);
  position: fixed;
  z-index: 250;
}

.kpress-settings-btn {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--kpress-radius-sm);
  color: var(--kpress-doc-muted);
  cursor: pointer;
  display: inline-flex;
  height: 28px;
  justify-content: center;
  padding: 4px;
  transition:
    color var(--kpress-transition-fast),
    background var(--kpress-transition-fast);
  width: 28px;
}

.kpress-settings-btn:hover,
.kpress-settings[aria-expanded="true"] .kpress-settings-btn {
  background: var(--color-hover-bg);
  color: var(--kpress-doc-text);
}

.kpress-settings-btn:focus-visible {
  outline: 3px solid var(--color-primary-light);
  outline-offset: 2px;
}

.kpress-settings-btn svg {
  height: 16px;
  width: 16px;
}

.kpress-settings-menu {
  display: none;
  inset-block-start: calc(100% + 4px);
  inset-inline-end: 0;
  position: absolute;
}

/* Document actions (doc-actions widget; off by default, opted in via
   `format.widgets: {doc-actions: on}`): "PDF" exports via the browser print
   dialog, "MD" opens the Markdown twin. Two-layer anatomy, mirroring the
   other chrome controls:

   - The BUTTON is the interaction layer only — the settings gear's quiet
     28px hit target and color states (muted -> text on the shared hover
     surface), no typography of its own.
   - The BADGE is the "icon" — the format letters, hand-drawn from type: the
     caps-label idiom one notch below the TOC "Contents" label, inside a
     tight 1px currentColor frame so the frame always matches the letter
     color through every state. Size and corner are the
     --kpress-doc-actions-badge-* tokens (square by default).

   Placement: on card documents the widget relocates its mount into
   .kpress-long-text and these rules pin it to the card's upper-right corner
   (the placement embedding hosts use for their own document actions);
   without a card it stays fixed at the inset tokens (host-overridable, see
   style-tokens.css). */
.kpress-doc-actions {
  display: flex;
  gap: 0.25rem;
  inset-block-start: var(--kpress-doc-actions-inset-block);
  inset-inline-end: var(--kpress-doc-actions-inset-inline);
  position: fixed;
  z-index: 250;
}

.kpress-long-text:has(.kpress-doc-actions) {
  position: relative;
}

/* A body without a leading in-card H1 has no heading margin to clear the
   absolute action row. Reserve that row before paragraph-first content. */
.kpress-long-text:has(.kpress-doc-actions):not(:has(> h1:first-child)) {
  padding-block-start: 3rem;
}

.kpress-long-text .kpress-doc-actions {
  inset-block-start: 1rem;
  inset-inline-end: 1rem;
  position: absolute;
}

.kpress-doc-actions-btn {
  align-items: center;
  background: transparent;
  border: none;
  border-radius: var(--kpress-radius-sm);
  color: var(--kpress-doc-muted);
  cursor: pointer;
  display: inline-flex;
  height: 28px;
  justify-content: center;
  min-width: 28px;
  padding: 0 4px;
  text-decoration: none;
  transition:
    color var(--kpress-transition-fast),
    background var(--kpress-transition-fast);
}

.kpress-doc-actions-btn:hover {
  background: var(--color-hover-bg);
  color: var(--kpress-doc-text);
}

.kpress-doc-actions-badge {
  border: 1px solid currentColor;
  border-radius: var(--kpress-doc-actions-badge-radius);
  font-family: var(--kpress-font-sans);
  font-size: var(--kpress-doc-actions-badge-size);
  font-weight: var(--kpress-font-weight-sans-medium);
  letter-spacing: var(--kpress-caps-spacing);
  line-height: 1;
  padding: 2px 3px;
}

/* The MD badge is an <a>: when the cluster relocates into the card it falls
   under `.kpress a` link styling, which out-specifies the bare class — keep
   the badge quiet (muted, never underlined) at higher specificity. */
.kpress a.kpress-doc-actions-btn {
  color: var(--kpress-doc-muted);
  text-decoration: none;
}

.kpress a.kpress-doc-actions-btn:hover {
  color: var(--kpress-doc-text);
  text-decoration: none;
}

.kpress-doc-actions-btn:focus-visible {
  outline: 3px solid var(--color-primary-light);
  outline-offset: 2px;
}

.kpress-settings[aria-expanded="true"] .kpress-settings-menu {
  display: flex;
}

.kpress-menu {
  background: var(--kpress-doc-bg);
  border: 1px solid var(--kpress-doc-border);
  border-radius: var(--kpress-radius-sm);
  box-shadow:
    0 4px 6px -1px oklch(0.00% 0 0 / 0.1),
    0 2px 4px -1px oklch(0.00% 0 0 / 0.06);
  flex-direction: column;
  min-width: 124px;
  padding: 4px;
  z-index: 300;
}

.kpress-menu-chooser {
  display: flex;
  gap: 2px;
}

.kpress-menu-select {
  background: var(--kpress-doc-bg);
  border: 1px solid var(--kpress-doc-border);
  border-radius: var(--kpress-radius-sm);
  color: var(--kpress-doc-text);
  font-family: var(--kpress-font-sans);
  font-weight: var(--kpress-font-weight-sans-regular);
  font-size: var(--kpress-font-size-tiny);
  padding: 4px 6px;
  width: 100%;
}

/* Stacked chooser groups read as one menu; give successive groups a little
   separation. The native select (font-set chooser) inherits document tokens.
   These adjacency selectors come after the base `.kpress-menu-select` above so
   specificity ascends in source order (biome noDescendingSpecificity). */
.kpress-menu-chooser + .kpress-menu-chooser,
.kpress-menu-chooser + .kpress-menu-select,
.kpress-menu-select + .kpress-menu-chooser {
  margin-top: 4px;
}

.kpress-menu-seg {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: var(--kpress-radius-sm);
  color: var(--kpress-doc-muted);
  cursor: pointer;
  display: flex;
  flex: 1;
  height: 30px;
  justify-content: center;
  min-width: 34px;
  padding: 0;
  transition:
    color var(--kpress-transition-fast),
    background var(--kpress-transition-fast);
}

.kpress-menu-seg:hover,
.kpress-menu-seg:focus-visible {
  background: var(--color-hover-bg);
  color: var(--kpress-doc-text);
  outline: none;
}

.kpress-menu-seg[aria-checked="true"] {
  background: var(--color-bg-selected);
  color: var(--kpress-doc-link);
}

.kpress-menu-seg svg {
  height: 16px;
  width: 16px;
}

.kpress-toc {
  border: 1px solid var(--kpress-doc-border);
  color: var(--kpress-doc-muted);
  font-family: var(--kpress-font-sans);
  font-weight: var(--kpress-font-weight-sans-regular);
  font-feature-settings: var(--kpress-font-features-sans);
  font-size: var(--kpress-font-size-smaller);
  font-variant-numeric: tabular-nums;
  margin: 0 0 1.5rem;
  padding: 0.5rem 0.7rem 1rem 1.2rem;
}

.kpress-toc ol {
  line-height: 1.2;
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}

.kpress-toc a {
  border-inline-start: 2px solid transparent;
  color: inherit;
  display: block;
  padding-block: 0.2rem;
  text-decoration: none;
  /* Only the hover/active properties. Never `all`: a late-applied stylesheet
     (slow or failed sheet, host style injection) must snap into place, not
     visibly animate every property. */
  transition:
    color var(--kpress-transition-fast),
    background-color var(--kpress-transition-fast),
    border-color var(--kpress-transition-fast);
}

/* Hover and active both shift the text to the secondary tone; the colored
   inline-start indicator (plus the selected background) marks the active
   section. The 2px transparent border above keeps text from shifting when
   active. */
.kpress-toc a:hover {
  background-color: var(--color-hover-bg);
  color: var(--color-secondary);
  text-decoration: none;
}

.kpress-toc a[data-active="true"],
.kpress-toc a.active {
  background-color: var(--color-bg-selected);
  border-inline-start-color: var(--kpress-doc-link);
  color: var(--color-secondary);
  text-decoration: none;
}

/* Each entry indents by heading level. The padding sits on the link (the
   element carrying the active inline-start bar) so the bar pins to the
   container edge while every wrapped line shares one text edge. Deeper
   levels indent further and lighten in weight, echoing the document's
   heading hierarchy. Logical properties preserve the same hierarchy in RTL. */

/* Two-level weight hierarchy, matching textpress (toc-h2=550 medium, toc-h3=370
   light). kpress normalizes TOC levels to structural tree depths, so the top
   content level is level-1 (typically the document's h2): it gets medium;
   everything deeper gets light. (textpress keys the same two weights off raw
   h2/h3.) */
.kpress-toc-level-1 > a {
  font-weight: var(--kpress-font-weight-sans-medium);
  letter-spacing: 0.007em;
}

.kpress-toc-level-2 > a,
.kpress-toc-level-3 > a,
.kpress-toc-level-4 > a,
.kpress-toc-level-5 > a,
.kpress-toc-level-6 > a {
  font-weight: var(--kpress-font-weight-sans-light);
}

.kpress-toc-level-1 > a {
  padding-inline-start: 0.75rem;
}

.kpress-toc-level-2 > a {
  padding-inline-start: 1.45rem;
}

.kpress-toc-level-3 > a {
  padding-inline-start: 2.15rem;
}

.kpress-toc-level-4 > a {
  padding-inline-start: 2.85rem;
}

.kpress-toc-level-5 > a {
  padding-inline-start: 3.55rem;
}

.kpress-toc-level-6 > a {
  padding-inline-start: 4.25rem;
}

/* Floating TOC control (32px button, 20px icon — a step larger than the
   settings gear so it reads as the document's primary navigation affordance).
   It floats over the narrow band's tightened text gutter, so instead of the
   gear's transparent-until-hover chrome it always carries a translucent
   document-background fill: where it slightly overlaps a long line, both the
   icon and the text beneath stay readable, in light and dark themes alike
   (the fill follows --kpress-doc-bg). */
.kpress-toc-toggle {
  align-items: center;
  background: color-mix(in srgb, var(--kpress-doc-bg) 80%, transparent);
  border: 1px solid transparent;
  border-radius: var(--kpress-radius-sm);
  color: var(--kpress-doc-muted);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  height: 32px;
  justify-content: center;
  padding: 4px;
  transition:
    color var(--kpress-transition-fast),
    background-color var(--kpress-transition-fast);
  width: 32px;
}

.kpress-toc-toggle:hover {
  background-color: var(--color-hover-bg);
  color: var(--kpress-doc-text);
}

.kpress-toc-toggle-icon {
  display: block;
  height: 20px;
  width: 20px;
}

.kpress-toc-title {
  border-bottom: 1px solid var(--kpress-doc-border);
  border-inline-start: none;
  font-size: var(--kpress-caps-label-size);
  font-variant-caps: var(--kpress-caps-variant);
  font-weight: var(--kpress-font-weight-sans-medium);
  letter-spacing: var(--kpress-caps-spacing);
  line-height: var(--kpress-caps-heading-line-height);
  padding-inline-start: 0.75rem;
  text-transform: var(--kpress-caps-transform);
}

/* Collapsible-TOC chrome (server-rendered only when toc_collapse_depth is
   set and the document has deeper entries; toc.js owns the state). The
   header row moves the title's underline onto the full row so the TOC reads
   the same with and without the expand-all button flush right of
   "Contents". */
.kpress-toc-header {
  align-items: center;
  border-bottom: 1px solid var(--kpress-doc-border);
  display: flex;
  gap: 0.3rem;
  justify-content: space-between;
}

.kpress-toc-header .kpress-toc-title {
  border-bottom: none;
  flex: 1 1 auto;
}

/* Deliberately quiet control: no border or fill, colored like the Contents
   label it sits beside (the muted TOC tone), darkening slightly on hover.
   The chevrons glyph pair keeps it minimal — a small disclosure hint, not a
   chrome button. */
.kpress-toc-expand-all {
  align-items: center;
  background: transparent;
  border: none;
  border-radius: var(--kpress-radius-sm);
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  flex: none;
  height: 18px;
  justify-content: center;
  opacity: 0.55;
  padding: 2px;
  transition:
    color var(--kpress-transition-fast),
    opacity var(--kpress-transition-fast);
  width: 18px;
}

.kpress-toc-expand-all:hover {
  background-color: var(--color-hover-bg);
  color: var(--kpress-doc-text);
  opacity: 1;
}

.kpress-toc-expand-all-icon {
  display: block;
  height: 12px;
  width: 12px;
}

/* Both state icons are server-rendered; aria-expanded picks the visible one
   (unfold while collapsed, fold while expanded) so the behavior only flips
   the attribute, never the markup. */
.kpress-toc-expand-all[aria-expanded="true"] .kpress-toc-expand-all-icon:first-of-type,
.kpress-toc-expand-all[aria-expanded="false"] .kpress-toc-expand-all-icon:last-of-type {
  display: none;
}

/* Collapsed entries animate closed rather than display:none (which cannot
   transition): each row eases its block-size and opacity to zero with the
   standard motion tokens, and visibility drops the hidden links from the
   tab order when the transition ends. Scoped to collapse-enabled navs so
   documents without the feature keep today's exact row styling. The
   :where() keeps the ancestor scope at zero specificity so the global
   prefers-reduced-motion block (`.kpress [class]`, later in this file) still
   outranks the transition and suppresses the motion. */
:where(.kpress-toc[data-kpress-toc-collapse-depth]) .toc-list > li {
  max-block-size: 5rem;
  overflow: hidden;
  transition:
    max-block-size var(--kpress-transition-med),
    opacity var(--kpress-transition-med),
    visibility var(--kpress-transition-med);
}

:where(.kpress-toc[data-kpress-toc-collapse-depth]) .toc-list > li.kpress-toc-collapsed {
  max-block-size: 0;
  opacity: 0;
  visibility: hidden;
}

/* `position: fixed` resolves against the non-scrolling `.kpress-frame` (the
   containing block for fixed descendants), so `inset: 0` covers the document
   frame — the whole window standalone, just the pane when embedded. */
.kpress-toc-backdrop {
  background-color: oklch(0.00% 0 0 / 0.5);
  display: none;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  transition:
    opacity var(--kpress-transition-fade),
    visibility var(--kpress-transition-fade);
  visibility: hidden;
  z-index: 199;
}

.kpress-toc-backdrop.kpress-visible {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

/* Footnotes take the small rung of the ramp, not a bare ratio. `0.9em` scaled
   whatever font-size it happened to inherit and compounded with it -- the prose
   size in a standalone page, but a card, a table cell or an embedding host can
   hand the block something else. It also named no rung: against an 18px base it
   resolved to 16.2px, while `--kpress-font-size-small`, the size every other
   small surface uses, is 17.1px. */
.kpress-footnotes {
  border-top: 1px solid var(--kpress-doc-border);
  color: var(--kpress-doc-muted);
  font-family: var(--kpress-font-footnote);
  font-weight: var(--kpress-font-weight-sans-regular);
  font-size: var(--kpress-font-size-small);
  margin-top: 2rem;
  padding-top: 1rem;
}

/* Footnote controls. The reference in the text, the ↑ after its footnote and the ↓
   in its hover preview are one family: each takes the reader to or from a footnote,
   so they look alike at rest and answer a hover the same way the document's other
   small controls do -- the link colour on the glyph, a link-coloured border, and the
   link wash behind it. The border is present at rest, transparent, so nothing moves
   on hover; the wash is the same `--kpress-doc-surface-hover` every hover here uses.

   `.kpress a.…backref` and `.kpress-tooltip …nav-link` carry a class beyond the bare
   one: the generic `.kpress a:hover` underline is (0,2,1) and a bare
   `.kpress-footnote-backref:hover` (0,2,0) would lose to it and underline. */
.kpress-footnote-ref a,
.kpress a.kpress-footnote-backref,
.kpress-tooltip .kpress-footnote-nav-link {
  background-color: var(--color-bg-meta-solid);
  border: 1px solid transparent;
  border-radius: var(--kpress-radius-md);
  color: var(--color-hint-strong);
  font-family: var(--kpress-font-sans);
  font-feature-settings: var(--kpress-font-features-sans);
  font-style: normal;
  font-weight: 600;
  padding: 0 0.15rem;
  text-decoration: none;
  /* Hover properties only, never `all` (late-applied styles must not animate). */
  transition:
    color var(--kpress-transition-fast),
    background-color var(--kpress-transition-fast),
    border-color var(--kpress-transition-fast);
}

.kpress-footnote-ref a {
  margin-right: 0.15rem;
}

.kpress-footnote-ref a:hover,
.kpress a.kpress-footnote-backref:hover,
.kpress-tooltip .kpress-footnote-nav-link:hover {
  background-color: var(--color-hover-bg);
  border-color: var(--kpress-doc-link);
  color: var(--kpress-doc-link);
  text-decoration: none;
}

.kpress-tooltip {
  background: var(--color-bg-meta-solid);
  border: 1px solid var(--color-hint-gentle);
  border-radius: var(--kpress-radius-none);
  box-shadow:
    0 4px 6px -1px oklch(0.00% 0 0 / 0.1),
    0 2px 4px -1px oklch(0.00% 0 0 / 0.06);
  color: var(--kpress-doc-text);
  font-family: var(--kpress-font-sans);
  font-feature-settings: var(--kpress-font-features-sans);
  font-size: var(--kpress-font-size-small);
  font-weight: var(--kpress-font-weight-sans-regular);
  hyphens: auto;
  line-height: 1.4;
  max-width: min(20rem, calc(100vw - 2rem));
  min-width: 8rem;
  opacity: 0;
  overflow-wrap: break-word;
  padding: 0.75rem 1rem;
  pointer-events: none;
  /* A callout belongs to a place in the text, not to a place on the screen.
     tooltips.js appends it inside the `.kpress-viewport` scroller and writes
     page coordinates (screen position + the scroller's scroll offset), so it
     stays beside the word that opened it while the reader scrolls. The one
     exception is the mobile sheet below, which goes back to `fixed`. */
  position: absolute;
  transition:
    opacity 0.6s ease-in-out,
    visibility 0.6s ease-in-out;
  visibility: hidden;
  white-space: normal;
  width: max-content;
  word-break: normal;
  z-index: 1000;
}

.kpress-tooltip.kpress-tooltip-visible {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.kpress-tooltip-content {
  min-width: 0;
  padding-inline-end: 1.5rem;
}

.kpress-tooltip-close {
  align-items: center;
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--kpress-doc-muted);
  cursor: pointer;
  display: flex;
  font: inherit;
  font-size: 1.15em;
  height: 1.5rem;
  inset-block-start: 0.35rem;
  inset-inline-end: 0.35rem;
  justify-content: center;
  line-height: 1;
  padding: 0;
  position: absolute;
  width: 1.5rem;
}

.kpress-tooltip-close:hover,
.kpress-tooltip-close:focus-visible {
  background: var(--color-hover-bg);
  color: var(--kpress-doc-link);
}

.kpress-tooltip-close:focus-visible {
  outline: 1px solid var(--kpress-doc-link);
  outline-offset: 1px;
}

/* Section-preview tooltips navigate to their target on tap/click
   (tooltips.js); the pointer signals it. Footnote popovers stay plain — only
   the links inside them navigate. */
.kpress-tooltip:not(.kpress-tooltip-footnote) {
  cursor: pointer;
}

/* No edge arrow on tooltips (textpress has none; the bare popover reads cleaner).
   The per-position `::after` border-color rules below are inert while this is hidden. */
.kpress-tooltip::after {
  display: none;
}

.kpress-tooltip a {
  color: var(--kpress-doc-link);
  cursor: pointer;
  overflow-wrap: break-word;
  pointer-events: auto;
  text-decoration: underline;
  transition: color var(--kpress-transition-med);
}

.kpress-tooltip a:hover {
  color: var(--color-primary-light);
  text-decoration: underline;
}

/* The preview mounts outside every .kpress wrapper, so the document's code rule
   never reaches it: name the shipped mono face here. */
.kpress-tooltip code,
.kpress-tooltip kbd,
.kpress-tooltip pre,
.kpress-tooltip samp {
  font-family: var(--kpress-font-mono);
  font-size: 0.9em;
  overflow-wrap: break-word;
  white-space: normal;
  word-break: break-all;
}

.kpress-tooltip p,
.kpress-tooltip span,
.kpress-tooltip div {
  overflow-wrap: break-word;
  word-break: normal;
}

.kpress-tooltip-footnote {
  font-family: var(--kpress-font-footnote);
  line-height: 1.5;
  max-width: min(25rem, calc(100vw - 2rem));
  min-width: 12rem;
  text-align: left;
}

.kpress-tooltip-bottom::after {
  border-bottom-color: var(--kpress-doc-border);
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
}

.kpress-tooltip-bottom-right::after {
  border-bottom-color: var(--kpress-doc-border);
  bottom: 100%;
  left: 1rem;
}

.kpress-tooltip-bottom-left::after {
  border-bottom-color: var(--kpress-doc-border);
  bottom: 100%;
  right: 1rem;
}

.kpress-tooltip-top::after {
  border-top-color: var(--kpress-doc-border);
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
}

.kpress-tooltip-top-right::after {
  border-top-color: var(--kpress-doc-border);
  left: 1rem;
  top: 100%;
}

.kpress-tooltip-top-left::after {
  border-top-color: var(--kpress-doc-border);
  right: 1rem;
  top: 100%;
}

.kpress-tooltip-left::after {
  border-left-color: var(--kpress-doc-border);
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
}

.kpress-tooltip-right::after {
  border-right-color: var(--kpress-doc-border);
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
}

.kpress-tooltip-wide-right {
  box-shadow:
    0 8px 25px -3px oklch(0.00% 0 0 / 0.15),
    0 4px 6px -2px oklch(0.00% 0 0 / 0.05);
  max-width: 24rem;
}

.kpress-tooltip-wide-right::after {
  border-right-color: var(--kpress-doc-border);
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
}

/* The narrow-screen presentation is a sheet across the bottom of the pane, not
   a callout beside an anchor: it has no anchor to stay beside, and a bar that
   slid up the screen as the reader scrolled would read as broken. So it keeps
   the window-fixed frame (and is appended to the body, outside the scroller, by
   tooltips.js) while every other placement scrolls with the text. This rule
   ties with `.kpress-tooltip` on specificity and wins on source order. */
.kpress-tooltip-mobile-bottom {
  box-shadow: 0 -4px 16px oklch(0.00% 0 0 / 0.18);
  box-sizing: border-box;
  max-width: none;
  min-width: 0;
  padding: 0.75rem 1rem;
  position: fixed;
  text-align: left;
  width: auto;
}

.kpress-tooltip-mobile-bottom::after {
  display: none;
}

.kpress-footnote-nav {
  float: right;
  margin-inline-start: 0.5rem;
}

/* Tables: only tables marked wide (data-kpress-table-scale="wide", stamped by
   the renderer/tables.js when a table is large on both axes — see
   TABLE_WIDE_MIN_* in format/markdown.py) get the wide presentation. Smaller
   tables keep the reading-column width in every band; content wider than the
   wrap still scrolls internally. The base wide rule below is the
   column-centred, pane-capped full bleed for a centred single column;
   container bands neutralise it where the column is not centred or the
   bleed is unwanted (see the layout comment above). */
.kpress-table-wrap {
  background-color: var(--kpress-doc-bg);
  box-sizing: border-box;
  margin: 2rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
  scrollbar-color: var(--color-scrollbar) transparent;
  scrollbar-width: thin;
  width: 100%;
}

.kpress-table-wrap[data-kpress-table-scale="wide"] {
  left: 50%;
  transform: translateX(-50%);
  /* 100cqw, not 100vw: the bleed is capped at the kpress-doc pane, so a
     no-TOC document embedded in a pane narrower than the window stays inside
     the pane (without a query container, cqw falls back to vw — the
     standalone window-width case, where they are equal). */
  width: min(calc(100cqw - 2rem), max(100%, var(--kpress-measure)));
}

.kpress-table {
  border: 1px solid var(--color-border-hint);
  border-collapse: collapse;
  font-family: var(--kpress-font-table);
  font-weight: var(--kpress-font-weight-sans-regular);
  font-feature-settings: var(--kpress-font-features-sans);
  font-size: var(--kpress-font-size-small);
  line-height: 1.3;
  min-width: 100%;
  width: auto;
  word-break: break-word;
}

/* Code inside a table steps down a mono tier, at EVERY width.
   The two ramps in style-tokens.css pair by index — mono/normal, mono-small/smaller,
   mono-tiny/tiny, all three at 0.82 — so code keeps one optical weight against
   whatever text surrounds it. A table is the one surface whose text is reduced
   (`small`) while its code was not, leaving code at 0.863 of its own cell: heavier
   inside a table than the identical span in prose, which mono's larger x-height
   exaggerates further.

   `small` has no mono partner (the text ramp has four tiers, mono has three), so
   neither choice is exact, and neither is even closer: mono-small sits at 0.777 of
   the cell and mono at 0.863, equidistant either side of the ramp's 0.82 — 0.043
   out on each side, and equidistant whatever the ramp ratio, since the cell's 0.95
   is the midpoint of the 1.0 and 0.9 steps the two rungs carry. The tie breaks on
   direction — code that reads as subordinate to the cell rather than competing
   with it.

   This rule was previously scoped inside the narrow band, where it looked
   correct only because that band ALSO drops table text to `smaller` — the
   pairing came from the text side, not from this declaration. Unscoped, the
   narrow band keeps the same result and no longer needs its own copy.
   Load order matters: `.kpress code` (document.css) ties on specificity, and
   components.css is loaded after it. */
.kpress-table code,
.kpress-table pre {
  font-size: var(--kpress-font-size-mono-small);
}

.kpress-table th,
.kpress-table td {
  max-width: 40rem;
  min-width: 6rem;
  padding: 0.3rem 0.6rem;
  text-align: start;
  vertical-align: top;
}

.kpress-table th {
  background-color: var(--color-bg-alt-solid);
  border-bottom: 1px solid var(--color-border-hint);
  font-size: var(--kpress-caps-label-size);
  font-variant-caps: var(--kpress-caps-variant);
  font-weight: var(--kpress-font-weight-sans-bold);
  /* Header labels hyphenate rather than inherit the table's break-word
     letter-level wrapping: a narrow column shows "Capitali-zation" over more
     lines, never an unhyphenated mid-word cut. overflow-wrap stays as the
     last resort for strings hyphenation cannot split (needs a `lang` on the
     document/host root to pick a hyphenation dictionary). */
  hyphens: auto;
  letter-spacing: var(--kpress-caps-spacing);
  line-height: var(--kpress-caps-heading-line-height);
  overflow-wrap: break-word;
  text-align: center;
  text-transform: var(--kpress-caps-transform);
  word-break: normal;
}

.kpress-table tbody tr:nth-child(even) {
  background-color: var(--color-bg-alt-solid);
}

.kpress-table [data-kpress-numeric="true"] {
  font-variant-numeric: tabular-nums;
  text-align: end;
}

/* Task-list checkboxes: one clean box (no extra prose bullet), drawn with the
   shared Lucide `square` / `square-check` glyphs via a mask. Unchecked is a dimmer
   gray empty box; checked is a darker box with a check. The disabled <input> stays
   for its accessible checked/unchecked state.

   Each rule also keys on where the box sits, the first element of its item or of
   the item's first paragraph (a loose list), because a host that sanitizes KPress's
   HTML again can strip every class and keep only `<input type="checkbox" disabled>`:
   Metabrowser's inert hardener does, and there the box drew as the browser's own
   checkbox under a bullet. That is safe in `sanitized` output, where the box is the
   only `<input>` that survives. A structural selector also needs `disabled`, which
   the sanitized box always has and that host keeps, so a checkbox a reader can tick
   in a `trusted` document keeps the browser's look and its bullet, as before these
   rules. CSS cannot see text, so an item whose first element is a checkbox after
   some words also loses its bullet. Only a `ul` item loses its marker that way: an
   ordered item, a footnote among them, keeps its number, which the reader needs, so
   a class-free ordered task list shows the number beside the box, where KPress's
   classed one shows the box alone (`.kpress-task`).

   The structural selectors put `:where()` around their context and around
   `[disabled]` in the box rules, so each ties the class rule beside it on
   specificity, and an element both match is styled exactly as before. The two rules
   that need `:has()` stay apart from the class rules, since a browser without it
   drops a rule that shares its selector list. The bullet rule outranks its class
   rule, which changes nothing: no KPress rule between the two sets `content` on an
   item's `::before`. tests/test_playwright_task_box.py compares a class-free list
   with the classed one in Chromium. */
.kpress-prose ul > li.kpress-task::before {
  content: none;
}

.kpress-prose
  ul
  > li:has(
    > input[type="checkbox"][disabled]:first-child,
    > p:first-child > input[type="checkbox"][disabled]:first-child
  )::before {
  content: none;
}

.kpress-task {
  list-style: none;
}

.kpress-prose
  :where(
    ul
      > li:has(
        > input[type="checkbox"][disabled]:first-child,
        > p:first-child > input[type="checkbox"][disabled]:first-child
      )
  ) {
  list-style: none;
}

.kpress-task input[type="checkbox"],
:where(.kpress-prose li) > input[type="checkbox"]:where([disabled]):first-child,
:where(.kpress-prose li > p:first-child) > input[type="checkbox"]:where([disabled]):first-child {
  appearance: none;
  background-color: var(--kpress-doc-muted);
  block-size: var(--kpress-checkbox-size);
  cursor: default;
  inline-size: var(--kpress-checkbox-size);
  margin-inline-end: 0.4rem;
  mask:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='18' height='18' x='3' y='3' rx='2'/%3E%3C/svg%3E")
    center / contain no-repeat;
  vertical-align: -0.15em;
}

.kpress-task input[type="checkbox"]:checked,
:where(.kpress-prose li) > input[type="checkbox"]:where([disabled]):first-child:checked,
:where(.kpress-prose li > p:first-child)
  > input[type="checkbox"]:where([disabled]):first-child:checked {
  background-color: var(--kpress-doc-text);
  mask:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='18' height='18' x='3' y='3' rx='2' stroke-width='2'/%3E%3Cpath d='m7 12.5 3.5 3.5 6.5-7' stroke-width='2.5'/%3E%3C/svg%3E")
    center / contain no-repeat;
}

.kpress-code-scroll {
  overflow-x: auto;
}

/* Minimal scrollbar on the remaining doc scroll surfaces (the main viewport
   keeps the OS scrollbar; tables/code/tabs set theirs inline). */
.kpress-code-scroll,
.kpress-math-display,
.kpress-diagram-source,
.kpress-diagram-rendered {
  scrollbar-color: var(--color-scrollbar) transparent;
  scrollbar-width: thin;
}

.kpress-code:has(.kpress-code-copy) {
  position: relative;
}

/* Icon-only copy control, revealed on hover/focus of the code block
   (host-app parity). The label lives in aria-label/title, never as text. */
.kpress-code-copy {
  align-items: center;
  background: var(--kpress-doc-bg);
  border: 1px solid var(--kpress-doc-border);
  border-radius: var(--kpress-radius-sm);
  color: var(--kpress-doc-muted);
  cursor: pointer;
  display: flex;
  inset-block-start: 0.4rem;
  inset-inline-end: 0.4rem;
  justify-content: center;
  opacity: 0;
  padding: 0.3rem;
  position: absolute;
  transition:
    background-color var(--kpress-transition-fast),
    border-color var(--kpress-transition-fast),
    color var(--kpress-transition-fast),
    opacity var(--kpress-transition-fast);
  z-index: 1;
}

.kpress-code-copy svg {
  block-size: 15px;
  display: block;
  inline-size: 15px;
}

.kpress-code:hover .kpress-code-copy,
.kpress-code:focus-within .kpress-code-copy,
.kpress-code-copy:focus-visible {
  opacity: 1;
}

.kpress-code-copy:hover {
  background: var(--color-hover-bg);
  color: var(--kpress-doc-text);
}

.kpress-code-copy:focus-visible {
  outline: 3px solid var(--kpress-doc-link);
  outline-offset: 2px;
}

.kpress-code-copy[data-kpress-copy-state="copied"] {
  background: color-mix(in srgb, var(--color-success) 12%, transparent);
  border-color: var(--color-success);
  color: var(--color-success);
  opacity: 1;
}

.kpress-code-copy[data-kpress-copy-state="error"] {
  background: color-mix(in srgb, var(--kpress-doc-danger) 12%, transparent);
  border-color: var(--kpress-doc-danger);
  color: var(--kpress-doc-danger);
  opacity: 1;
}

.kpress-math {
  font-family: var(--kpress-font-prose);
  line-height: 1.4;
}

.kpress-math math {
  color: inherit;
  font-size: 1.02em;
}

.kpress-math-inline {
  display: inline-block;
  max-width: 100%;
  /* Let KaTeX's / the MathML fallback's own baseline seat on the text baseline;
     the previous -0.1em nudge dropped inline math ~half an x-height too low. */
  vertical-align: baseline;
}

.kpress-math-display {
  display: block;
  margin-block: 1rem;
  overflow-x: auto;
  padding-block: 0.25rem;
  scrollbar-color: var(--color-scrollbar) transparent;
  scrollbar-width: thin;
  text-align: center;
}

.kpress-math-display math {
  display: inline-block;
  max-width: 100%;
}

/* KaTeX sizing. The vendored `katex/katex.min.css` is a pinned upstream bundle
   and stays byte-identical through the next KaTeX bump, so the correction lives
   here instead. Upstream sets `.katex { font-size: 1.21em }` to seat KaTeX_Main
   beside a Times-like body face; KPress reads in PT Serif, whose larger x-height
   makes that lift roughly a fifth too much, and worse inside the small Source
   Sans contexts, where the surrounding text is already below prose size. The
   ratios are the `--kpress-katex-size-*` tokens (style-tokens.css); this is the
   KaTeX counterpart of the `1.02em` nudge `.kpress-math math` gives the MathML
   fallback.

   SPECIFICITY: katex.min.css is linked AFTER these stylesheets (KaTeX is a lazy
   per-document asset merged onto the end of the manifest), so a bare `.katex`
   rule here would lose the tie to upstream's own `.katex`. Every selector below
   therefore carries at least one extra class or type. For the same reason the
   sans-context rule comes after the prose and display rules: it ties them at
   (0,3,0) and wins on order, which is what puts math in a caption at caption
   size.

   THE PREVIEW OVERLAY takes the same tokens. A footnote or section preview is a
   clone of already-rendered math that tooltips.js mounts on the viewport pane or
   the body, outside every `.kpress`, so without a scope of its own it would fall
   back to upstream's 1.21em while the document beside it reads at the token. The
   token's value comes from wherever the overlay sits in the cascade: 1em when
   katex-text-face.css matches the overlay's stamped math mode, style-tokens.css's
   1.05em otherwise, which is exactly the document's own rule. */
.kpress .katex,
.kpress-tooltip .katex {
  font-size: var(--kpress-katex-size-prose);
}

.kpress .katex-display .katex,
.kpress-tooltip .katex-display .katex {
  font-size: var(--kpress-katex-size-display);
}

.kpress .kpress-figcaption .katex,
.kpress .sans-text .katex,
.kpress .kpress-toc-title .katex,
.kpress .kpress-table th .katex,
.kpress .tab-button .katex,
.kpress .kpress-tab-button .katex,
.kpress summary .katex {
  font-size: var(--kpress-katex-size-sans);
}

/* KaTeX progressive enhancement: the semantic MathML renders by default and
   as the no-JS fallback; the TeX source node stays hidden until KaTeX
   replaces it. Once rendered, KaTeX is shown and the MathML is kept in the
   accessibility tree only. */
.kpress-math-render {
  display: none;
}

.kpress-math[data-kpress-math-rendered="true"] .kpress-math-render {
  display: inline;
}

.kpress-math-display[data-kpress-math-rendered="true"] .kpress-math-render {
  display: block;
}

.kpress-math[data-kpress-math-rendered="true"] .kpress-math-semantic {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

[data-kpress-math-pending="true"]
  .kpress-math:not([data-kpress-math-rendered="true"])
  .kpress-math-semantic {
  visibility: hidden;
}

.kpress-math[data-kpress-math-error="true"] {
  background: color-mix(in srgb, var(--kpress-doc-danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--kpress-doc-danger) 45%, transparent);
  border-radius: var(--kpress-radius-sm);
  color: var(--kpress-doc-danger);
  font-family: var(--kpress-font-mono);
  font-size: var(--kpress-font-size-mono);
  padding: 0.05rem 0.25rem;
}

.kpress-diagram {
  margin: 1.5rem 0;
}

.kpress-diagram svg {
  display: block;
  height: auto;
  margin-inline: auto;
  max-width: 100%;
}

.kpress-svg-diagram,
.kpress-mermaid {
  background: var(--kpress-doc-bg);
  border: 1px solid var(--kpress-doc-border);
  padding: 1rem;
}

.kpress-diagram-source {
  margin: 0;
  overflow-x: auto;
  scrollbar-color: var(--color-scrollbar) transparent;
  scrollbar-width: thin;
  white-space: pre;
}

.kpress-diagram-rendered {
  overflow-x: auto;
  scrollbar-color: var(--color-scrollbar) transparent;
  scrollbar-width: thin;
}

.kpress-diagram-source[hidden],
.kpress-diagram-rendered[hidden] {
  display: none;
}

.kpress-diagram[data-kpress-diagram-status="error"] {
  border-color: color-mix(in srgb, var(--kpress-doc-danger) 45%, var(--kpress-doc-border));
}

.kpress-mermaid {
  position: relative;
}

/* Image placement (diagrams.js, `placement: "image"`). */
.kpress-diagram-image {
  display: block;
  height: auto;
  margin-inline: auto;
  max-width: 100%;
}

/* A diagram Mermaid could not draw: its message, above the source it failed on. */
.kpress-diagram-error {
  color: var(--kpress-doc-text);
  font-family: var(--kpress-font-sans);
  margin-block-end: 0.5rem;
}

.kpress-diagram-error-detail {
  color: var(--kpress-doc-danger);
  font-family: var(--kpress-font-mono);
  font-size: var(--kpress-font-size-mono);
  margin: 0.25rem 0 0;
  white-space: pre-wrap;
}

/* Opt-in diagram controls (diagram-controls.js). The toolbar shows on hover or focus,
   as a code block's copy button does, and never prints. Show source and expand
   apply only to a drawn diagram. */
.kpress-diagram-toolbar {
  background: var(--kpress-doc-bg);
  border: 1px solid var(--kpress-doc-border);
  border-radius: var(--kpress-radius-sm);
  display: flex;
  gap: 0.15rem;
  inset-block-start: 0.4rem;
  inset-inline-end: 0.4rem;
  opacity: 0;
  padding: 0.1rem;
  position: absolute;
  transition: opacity var(--kpress-transition-fast);
  z-index: 1;
}

.kpress-mermaid:hover > .kpress-diagram-toolbar,
.kpress-diagram-toolbar:focus-within {
  opacity: 1;
}

@media (hover: none) {
  .kpress-diagram-toolbar {
    opacity: 1;
  }
}

.kpress-mermaid:not([data-kpress-diagram-status="rendered"]) .kpress-diagram-expand,
.kpress-mermaid:not([data-kpress-diagram-status="rendered"]) .kpress-diagram-toggle-source {
  display: none;
}

.kpress-diagram-button {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--kpress-radius-sm);
  color: var(--kpress-doc-muted);
  cursor: pointer;
  display: flex;
  justify-content: center;
  padding: 0.3rem;
  transition:
    background-color var(--kpress-transition-fast),
    color var(--kpress-transition-fast);
}

.kpress-diagram .kpress-diagram-button svg {
  block-size: 15px;
  display: block;
  inline-size: 15px;
  margin: 0;
}

.kpress-diagram-button:hover {
  background: var(--color-hover-bg);
  color: var(--kpress-doc-text);
}

.kpress-diagram-button:focus-visible {
  outline: 3px solid var(--kpress-doc-link);
  outline-offset: 2px;
}

.kpress-diagram-copy[data-kpress-copy-state="copied"] {
  color: var(--color-success);
}

.kpress-diagram-copy[data-kpress-copy-state="error"] {
  color: var(--kpress-doc-danger);
}

/* The expand dialog: modal, in the top layer, placed inside the figure so it
   inherits the document's theme tokens. */
.kpress-diagram-dialog {
  background: var(--kpress-doc-bg);
  block-size: calc(100vh - 2rem);
  border: 1px solid var(--kpress-doc-border);
  border-radius: var(--kpress-radius-md);
  color: var(--kpress-doc-text);
  inline-size: calc(100vw - 2rem);
  max-block-size: none;
  max-inline-size: none;
  padding: 0;
}

.kpress-diagram-dialog[open] {
  display: flex;
  flex-direction: column;
}

.kpress-diagram-dialog::backdrop {
  background-color: oklch(0.00% 0 0 / 0.5);
}

.kpress-diagram-dialog-controls {
  border-block-end: 1px solid var(--kpress-doc-border);
  display: flex;
  gap: 0.15rem;
  justify-content: flex-end;
  padding: 0.35rem;
}

.kpress-diagram-dialog-close {
  margin-inline-start: 0.75rem;
}

.kpress-diagram-viewport {
  cursor: grab;
  flex: 1;
  overflow: hidden;
  position: relative;
  touch-action: none;
}

.kpress-diagram-viewport.kpress-diagram-dragging {
  cursor: grabbing;
}

.kpress-diagram-viewport:focus-visible {
  outline: 2px solid var(--kpress-doc-link);
  outline-offset: -2px;
}

.kpress-diagram-stage {
  inline-size: max-content;
  inset-block-start: 0;
  inset-inline-start: 0;
  position: absolute;
  transform-origin: 0 0;
}

.kpress-diagram .kpress-diagram-stage > svg,
.kpress-diagram .kpress-diagram-stage > img {
  display: block;
  max-width: none;
}

.kpress-video-popover[hidden] {
  display: none;
}

/* Tabs: all panels share one grid cell so the container sizes to the TALLEST
   panel and does not jump when switching tabs; capped at ~half a page with
   internal scroll. Inactive panels stay in layout (for sizing) but are hidden
   from view and from the a11y / focus order. */
.kpress-tabs {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  margin: 1.5rem 0;
}

.kpress-tab-list,
.kpress-tabs [role="tablist"] {
  align-items: flex-end;
  border-bottom: 1px solid var(--kpress-doc-border);
  display: flex;
  gap: 0.25rem;
  grid-column: 1;
  grid-row: 1;
  overflow-x: auto;
  scrollbar-color: var(--color-scrollbar) transparent;
  scrollbar-width: thin;
}

.kpress-tab-panel {
  grid-column: 1;
  grid-row: 2;
  max-block-size: 50vh;
  overflow-y: auto;
  padding-block: 1rem;
  scrollbar-color: var(--color-scrollbar) transparent;
  scrollbar-width: thin;
}

.kpress-tab-panel[hidden] {
  display: block;
  visibility: hidden;
}

.kpress .highlight {
  border-radius: var(--kpress-radius-lg);
  padding: 0 0.5rem;
}

.kpress .citation {
  border-radius: var(--kpress-radius-sm);
  color: var(--color-secondary);
  display: inline-block;
  font-family: var(--kpress-font-sans);
  font-weight: var(--kpress-font-weight-sans-regular);
  font-feature-settings: var(--kpress-font-features-sans);
  height: 1.3rem;
  padding: 0 0.4rem;
  transition:
    background-color var(--kpress-transition-med),
    color var(--kpress-transition-med);
}

.kpress .citation::before {
  content: "[";
}

.kpress .citation::after {
  content: "]";
}

.kpress .citation:hover {
  background-color: var(--color-hover-bg);
  color: var(--color-primary);
}

.kpress .debug {
  color: var(--color-hint);
  font-family: var(--kpress-font-sans);
  font-feature-settings: var(--kpress-font-features-sans);
  font-size: var(--kpress-font-size-tiny);
  font-weight: var(--kpress-font-weight-sans-regular);
}

.kpress .hero h1 {
  font-family: var(--kpress-font-sans);
  font-feature-settings: var(--kpress-font-features-sans);
  font-size: calc(var(--kpress-font-size-base) * 1.6);
  font-weight: var(--kpress-font-weight-sans-medium);
  letter-spacing: 0.03em;
  line-height: 1.05;
  margin-block: 1rem 0;
  text-transform: uppercase;
}

.kpress .hero h1 i {
  font-family: var(--kpress-font-prose);
  font-size: calc(var(--kpress-font-size-base) * 1.5);
  font-style: italic;
  letter-spacing: 0;
  text-transform: none;
}

.kpress .subtitle {
  font-family: var(--kpress-font-prose);
  font-size: var(--kpress-font-size-normal);
  font-style: italic;
}

.kpress .boxed-text {
  /* The deliberate ink rule (kash border-hairline), not the faint doc border:
     a box the author drew should read as drawn. */
  border: 1px solid var(--kpress-doc-border-hairline);
  margin: 1rem 0;
  padding: 0 1rem;
}

.kpress .shaded-text {
  background-color: var(--kpress-doc-code-bg);
}

/* A sans-serif region: front matter, hero blocks, and other UI-voiced passages
   switch from the serif reading face to the sans stack. */
.kpress .sans-text {
  font-family: var(--kpress-font-sans);
  font-weight: var(--kpress-font-weight-sans-regular);
  font-feature-settings: var(--kpress-font-features-sans);
}

.kpress .sans-text p {
  margin-block: 0.8rem;
}

.kpress .sans-text h1 {
  font-family: var(--kpress-font-sans);
  font-feature-settings: var(--kpress-font-features-sans);
  font-size: calc(var(--kpress-font-size-base) * 1.75);
  font-weight: 380;
  margin-block: 1rem 1.2rem;
}

.kpress .sans-text h2 {
  font-family: var(--kpress-font-sans);
  font-feature-settings: var(--kpress-font-features-sans);
  font-size: calc(var(--kpress-font-size-base) * 1.25);
  font-weight: 440;
  margin-block: 1rem 0.8rem;
}

.kpress .centered-headers h1,
.kpress .centered-headers h2,
.kpress .centered-headers h3 {
  text-align: center;
}

.kpress .justify p {
  text-align: justify;
  text-align-last: left;
}

.kpress .description {
  color: var(--color-secondary);
  font-family: var(--kpress-font-sans);
  font-weight: var(--kpress-font-weight-sans-regular);
  font-feature-settings: var(--kpress-font-features-sans);
  font-size: var(--kpress-font-size-small);
  margin: 2rem 0;
}

.kpress .key-claims,
.kpress .summary,
.kpress .concepts {
  font-family: var(--kpress-font-sans);
  font-weight: var(--kpress-font-weight-sans-regular);
  font-feature-settings: var(--kpress-font-features-sans);
  font-size: var(--kpress-font-size-small);
  margin: 1rem 0;
  padding: 1rem;
}

.kpress .key-claims,
.kpress .concepts {
  border: 1px solid var(--color-hint-gentle);
}

.kpress .key-claims::before,
.kpress .summary::before,
.kpress .concepts::before {
  display: block;
  font-family: var(--kpress-font-sans);
  font-feature-settings: var(--kpress-font-features-sans);
  font-size: calc(var(--kpress-font-size-base) * 1.2 * var(--kpress-caps-heading-size-multiplier));
  font-variant-caps: var(--kpress-caps-variant);
  font-weight: var(--kpress-font-weight-sans-medium);
  letter-spacing: var(--kpress-caps-spacing);
  line-height: var(--kpress-caps-heading-line-height);
  margin-bottom: 0.5rem;
  text-align: center;
  text-transform: var(--kpress-caps-transform);
}

.kpress .key-claims::before {
  content: "Key Claims";
}

.kpress .summary::before {
  content: "Summary";
}

.kpress .concepts {
  column-count: 3;
  column-gap: 2rem;
  font-weight: var(--kpress-font-weight-sans-bold);
  padding-top: 3.5rem;
  position: relative;
}

.kpress .concepts::before {
  content: "Concepts";
  left: 50%;
  position: absolute;
  top: 1rem;
  transform: translateX(-50%);
  width: 100%;
}

.kpress .claim {
  font-family: var(--kpress-font-sans);
  font-feature-settings: var(--kpress-font-features-sans);
  font-weight: var(--kpress-font-weight-sans-bold);
  margin: 0.7rem 0 0.7rem 1.8rem;
  position: relative;
}

/* The same drawn square as the prose and concepts markers; document.css carries
   the measurement it reproduces. This rule is where the glyph cost most: .claim
   is sans, so U+25AA fell through a different stack than the prose one and came
   out 5.20px against the prose marker's 3.26px at a 16px base -- 60% larger,
   for a token whose whole purpose is that every bulleted list matches. */
.kpress .claim::before {
  background: currentColor;
  content: "";
  font-size: var(--kpress-bullet-size);
  height: 0.226em;
  inset-inline-start: calc(var(--kpress-font-size-base) * -0.85 + 0.064em);
  position: absolute;
  top: calc(var(--kpress-font-size-base) * 0.1 + 0.689em);
  width: 0.226em;
}

/* Every mark KPress paints rather than sets, in forced colors (Windows High
   Contrast and the browser settings that emulate it).

   The UA forces `background-color` to `Canvas` there, so a box filled with
   `currentColor` paints the page background onto the page background and
   disappears: measured in Chromium under `forced_colors: active`, the marker
   painted 0 ink pixels where the U+25AA glyph it replaces painted 196. That is
   the one behaviour a drawn mark does not inherit from a glyph, and it is lost
   for the readers a high-contrast mode exists for. `CanvasText` is the forced
   foreground, and `forced-color-adjust: none` is what lets it through.

   One rule for all four, and it lives here rather than beside each base rule
   because this file loads after document.css and ties it on specificity. The
   nested print marker needs its own copy in print.css, whose selector is more
   specific still. The disclosure chevron is in the same list for the same
   reason: it is a mask filled with `background-color`. */
@media (forced-colors: active) {
  .kpress-prose ul > li::before,
  .kpress .concepts ul > li::before,
  .kpress .claim::before,
  .kpress summary::before {
    background: CanvasText;
    forced-color-adjust: none;
  }
}

/* Every heading inside a sans block takes the sans face, so its mathematics and its
   words are set in the same one.

   WHY THIS RULE IS NEEDED AT ALL: document.css redeclares the prose face directly on
   the heading -- `.kpress-prose h1`, `h2`, `h5` and `h6` each carry their own
   `font-family: var(--kpress-font-prose, ...)` -- and a declaration on the element
   itself beats the sans family a container sets on an ancestor, which reaches the
   heading only by inheritance. So `## Heading` inside one of these blocks drew PT
   Serif while the block around it drew Source Sans.

   WHY THAT MATTERS MORE THAN A FONT SLIP: the sans math composite is scoped by
   CONTAINER, not by the heading's own face. katex-init.js resolves its `SANS_CONTEXT`
   with `closest()` from each node it renders, which climbs straight past the heading
   to `.description`, so mathematics in a heading here is laid out from the sans tables
   and stamped for the sans rules in katex-text-face.css to draw from `KPress Math Text
   Sans`. The heading therefore read as serif words wrapped around a sans formula,
   which is the disagreement that whole mechanism exists to remove. Headings are
   deliberately not sans-math roles of their own (katex-text-face.css records why: a
   heading's sans weight is not the weight the pinned tables were built at), so the
   agreement has to be reached from the text side, here.

   `.sans-text` is in the list too. It already redeclares the sans family on its own
   `h1` and `h2` above -- that pair is where this pattern comes from -- but it stops
   there, so its `h5` and `h6` were on the prose face exactly like the other five
   containers. `h3` and `h4` reach the sans face through the `.kpress-prose h1..h6`
   group rule rather than a rule of their own; they are listed anyway so this states
   the whole invariant and does not quietly depend on that group rule keeping them.

   SPECIFICITY: (0,2,1), which clears `.kpress-prose h1` at (0,1,1). It ties the
   `.sans-text` heading rules above at (0,2,1) and wins on source order, declaring the
   same family they do -- their size, weight and margins are untouched. */
.kpress :is(.sans-text, .description, .key-claims, .summary, .concepts, .claim)
  :is(h1, h2, h3, h4, h5, h6) {
  font-family: var(--kpress-font-sans);
  --_kpress-font-weight-prose: var(--kpress-font-weight-sans-regular);
  font-feature-settings: var(--kpress-font-features-sans);
}

.kpress .full-text {
  margin: 1rem 0;
}

.kpress .annotated-para {
  align-items: flex-start;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.kpress .annotated-para .para-caption {
  align-self: center;
  border-right: 2px solid var(--color-hint);
  color: var(--color-secondary);
  font-family: var(--kpress-font-sans);
  font-weight: var(--kpress-font-weight-sans-regular);
  font-feature-settings: var(--kpress-font-features-sans);
  font-size: var(--kpress-font-size-smaller);
  margin: 0.5rem 1rem 0.5rem 0;
  max-height: 15rem;
  order: 0;
  overflow-y: auto;
  padding-right: 0.5rem;
  scrollbar-color: var(--color-hint-gentle) transparent;
  scrollbar-width: thin;
  width: 20%;
}

.kpress .annotated-para .para {
  order: 1;
  width: 80%;
}

.kpress .frame-capture {
  border: 1px solid var(--color-hint);
  border-radius: var(--kpress-radius-lg);
  display: block;
  margin: 1rem auto;
  max-width: 225px;
}

.kpress .video-gallery {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.kpress .video-item {
  background-color: var(--kpress-doc-bg);
  border: 1px solid var(--kpress-doc-border);
  border-radius: var(--kpress-radius-lg);
  padding: 1rem;
}

/* Inline YouTube player. The server emits a safe placeholder (no iframe, so
   sanitized + hashed output stay network-free); video-popover.js swaps in this
   responsive 16:9 frame on load. */
.kpress-video {
  margin: 1.5rem 0;
}

.kpress-video-embed {
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: var(--kpress-radius-sm);
  display: block;
  width: 100%;
}

.kpress .kpress-video-placeholder {
  align-items: center;
  aspect-ratio: 16 / 9;
  background:
    linear-gradient(135deg, oklch(0.00% 0 0 / 0.72), oklch(0.00% 0 0 / 0.42)), var(--color-primary);
  border: 1px solid var(--kpress-doc-border);
  border-radius: var(--kpress-radius-none);
  color: oklch(100.00% 0 0);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  font-family: var(--kpress-font-sans);
  font-weight: var(--kpress-font-weight-sans-regular);
  font-feature-settings: var(--kpress-font-features-sans);
  gap: 0.75rem;
  justify-content: center;
  min-height: 12rem;
  padding: 1rem;
  text-align: center;
  width: 100%;
}

.kpress .kpress-video-placeholder:focus-visible {
  outline: 3px solid var(--kpress-doc-link);
  outline-offset: 3px;
}

/* One sans bold across the design system: these two carried a literal 700, the
   only sans chrome above the bold token, until 2026-09-07. */
.kpress .kpress-video-placeholder-action {
  align-items: center;
  background: oklch(100.00% 0 0 / 0.92);
  border-radius: var(--kpress-radius-pill);
  color: oklch(17.76% 0 0);
  display: inline-flex;
  font-size: var(--kpress-font-size-small);
  font-weight: var(--kpress-font-weight-sans-bold);
  height: 3rem;
  justify-content: center;
  line-height: 1;
  width: 3rem;
}

.kpress .kpress-video-placeholder-title {
  font-size: var(--kpress-font-size-small);
  font-weight: var(--kpress-font-weight-sans-bold);
}

.kpress-video-popover iframe {
  aspect-ratio: 16 / 9;
  border: 0;
  width: 100%;
}

.kpress .video-item iframe {
  border: 0;
  border-radius: var(--kpress-radius-lg);
  height: 200px;
  width: 100%;
}

/* The caps-label idiom, at the label weight the TOC title, the disclosure
   summaries and the print tab label all use. It asked for a literal 600 until
   2026-09-07, so the same label came out heavier on screen than on paper. */
.kpress .tab-button,
.kpress-tab-button {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--color-secondary);
  cursor: pointer;
  flex: 1 1 auto;
  font-family: var(--kpress-font-sans);
  font-feature-settings: var(--kpress-font-features-sans);
  font-size: var(--kpress-caps-label-size);
  font-variant-caps: var(--kpress-caps-variant);
  font-weight: var(--kpress-font-weight-sans-medium);
  letter-spacing: var(--kpress-caps-spacing);
  line-height: 1.2;
  max-width: 10rem;
  min-width: 5rem;
  outline: none;
  padding: 0 0.5rem;
  text-align: center;
  text-transform: var(--kpress-caps-transform);
}

.kpress-tab-button:focus-visible {
  outline: 3px solid var(--kpress-doc-link);
  outline-offset: 2px;
}

.kpress .tab-button-active,
.kpress-tab-button[aria-selected="true"] {
  border-color: var(--color-primary-light);
  color: var(--color-primary);
}

.kpress .tab-button-inactive,
.kpress-tab-button[aria-selected="false"] {
  border-color: transparent;
  color: var(--color-secondary);
}

.kpress .tab-button-inactive:hover,
.kpress-tab-button[aria-selected="false"]:hover {
  border-color: var(--color-hover);
  color: var(--color-primary);
}

.hidden {
  display: none;
}

.kpress .hidden {
  display: none;
}

.kpress-video-backdrop {
  background-color: oklch(0.00% 0 0 / 0.5);
  inset: 0;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  transition:
    opacity var(--kpress-transition-fade),
    visibility var(--kpress-transition-fade);
  visibility: hidden;
  z-index: 199;
}

.kpress-video-backdrop.kpress-visible {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.kpress-video-popover {
  background: var(--kpress-doc-bg);
  border: 1px solid var(--kpress-doc-border);
  color: var(--kpress-doc-text);
  display: flex;
  flex-direction: column;
  left: 1rem;
  max-height: calc(100dvh - 2rem);
  overflow: hidden;
  position: fixed;
  top: 1rem;
  width: min(44rem, calc(100dvw - 2rem));
  z-index: 200;
}

.kpress-video-popover.kpress-maximized {
  bottom: 1rem;
  right: 1rem;
  width: auto;
}

.kpress-video-header {
  align-items: center;
  display: flex;
  gap: 0.5rem;
  justify-content: space-between;
  padding: 0.5rem 0.6rem 0.5rem 0.85rem;
}

/* Icon-only close (Lucide `x`), not a text button. */
.kpress-video-header [data-kpress-video-close] {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: var(--kpress-radius-sm);
  color: var(--kpress-doc-muted);
  cursor: pointer;
  display: flex;
  justify-content: center;
  padding: 0.25rem;
  transition:
    background var(--kpress-transition-fast),
    color var(--kpress-transition-fast);
}

.kpress-video-header [data-kpress-video-close]:hover,
.kpress-video-header [data-kpress-video-close]:focus-visible {
  background: var(--color-hover-bg);
  color: var(--kpress-doc-text);
}

.kpress-video-header [data-kpress-video-close] svg {
  block-size: 18px;
  display: block;
  inline-size: 18px;
}

/* Heading step-up band: from 64rem the H2-H4 section headings take their
   larger sizes; narrow and medium panes keep the tighter defaults from
   style-tokens.css. Deliberately one notch below the 70rem TOC band so the
   heading step is not swallowed by that layout reflow, and deliberately
   headings ONLY: body text stays 1rem at every width (kash parity — kash
   bumps prose above 1rem only for print). */
@container kpress-doc (min-width: 64rem) {
  .kpress {
    --kpress-font-size-h2: calc(var(--kpress-font-size-base) * 1.4);
    --kpress-font-size-h3: calc(var(--kpress-font-size-base) * 1.2);
    --kpress-font-size-h4: calc(var(--kpress-font-size-base) * 1.2);
  }
}

/* Wide document: TOC is a sticky sidebar. Widths track the document viewport
   via `cqw` (not the window), so this is correct standalone and embedded. */
@container kpress-doc (width >= 70rem) {
  body.kpress-video-open .kpress-toc,
  .kpress-viewport.kpress-video-open .kpress-toc {
    display: none;
  }

  /* The TOC sidebar needs the full document width. Both the article
     (`.kpress-doc`, max-width 76ch+2rem) AND the inner grid wrapper
     (`.kpress-doc-layout`, max-width 76ch) are otherwise capped at the
     single-column reading measure and centred via margin:auto — so left
     in place the two-column grid is crushed into ~600px and shoved toward
     the centre/right (a left margin on the TOC, the fixed tracks spilling
     past the cap to the right). Uncap both so the sidebar + content span
     the pane, left-aligned. */
  .kpress-doc:has(.kpress-toc),
  .kpress-doc:has(> [data-kpress-toc-rail="reserved"]),
  .kpress-doc-layout:has(.kpress-toc),
  .kpress-doc-layout[data-kpress-toc-rail="reserved"] {
    margin-inline: 0;
    max-width: none;
  }

  /* The whole wide band carries a tighter inset than the single-column bands:
     the large outer margin (and, with a TOC, the 3rem rail gap) already holds
     the column off its surroundings, so 2.5rem is enough for the content card's
     chrome to breathe.

     UNCONDITIONAL, and it must stay that way. This is the band's inset, not the
     grid's: 0.3.3 applied it through `.kpress-content-with-toc .kpress-long-text`,
     a selector that matches whether or not a TOC was rendered, because
     `.kpress-content-with-toc` is on the layout wrapper always. 0.3.4 briefly
     gated this on the rail conditions, which quietly moved every TOC-less wide
     document from 2.5rem to 4rem -- the text still landed at the measure, since
     the caps follow the inset, but the card's inner padding changed and a host
     sizing its own surfaces to `measure + 2 x 2.5rem` (the documented wide track)
     no longer matched the document inside them.

     Do not add the rail conditions back here. The neighbouring rules carry them
     because they build the two-column grid, which genuinely needs a rail; the
     inset is the band's and applies to a single column too. */
  .kpress-doc {
    --kpress-column-inset: 2.5rem;
  }

  /* BOTH columns are width-bounded and the pair is left-aligned with
     justify-content, so the content column is a constant at every pane width.
     The earlier `clamp(.., 15cqw, ..)` TOC column grew with the pane and, under
     a fixed 68rem group cap, ate into the 1fr content column -- so the text got
     narrower the wider you dragged. Left-aligning pins the TOC + content to the
     start so all extra pane width becomes a single trailing margin -- no empty
     band to the left of the TOC.

     The content track is the column box, measure + 2x inset, so the TEXT lands
     at exactly the measure. The `min()` against the pane is a guard, not a
     resize. At the 70rem floor it allows the default track exactly: 45rem
     of text plus two 2.5rem insets. A larger host measure shrinks to fit.
     100cqw - 20rem is the pane less the 15rem rail, the 3rem gap and the two
     1rem page gutters. */
  .kpress-content-with-toc.has-toc,
  .kpress-content-with-toc:has(.kpress-toc),
  .kpress-content-with-toc[data-kpress-toc-rail="reserved"] {
    align-items: start;
    column-gap: 3rem;
    /* The two TOC-bearing conditions are already grid from the base rule
       above; the reserved rail is not, and only becomes a grid inside this
       band — narrow bands have no rail to reserve and stay single-column. */
    display: grid;
    grid-template-columns:
      15rem
      min(calc(var(--kpress-measure) + 2 * var(--kpress-column-inset)), calc(100cqw - 20rem));
    justify-content: start;
    min-height: 100dvh;
  }

  /* The site header/footer rows follow the same geometry as the doc grid: with a
     TOC the grid left-anchors inside .kpress-doc (1rem doc pad + 15rem track +
     3rem gap) and .kpress-long-text pads 2.5rem, so the reading text's inline
     start sits at 21.5rem. A centered header would drift off that column as the
     pane widens; align its content instead. Only the inline centering is
     cancelled: the footer keeps its block gap above. */
  .kpress-page-main:has(.kpress-toc) .kpress-site-header,
  .kpress-page-main:has(.kpress-toc) .kpress-site-footer,
  .kpress-page-main:has([data-kpress-toc-rail="reserved"]) .kpress-site-header,
  .kpress-page-main:has([data-kpress-toc-rail="reserved"]) .kpress-site-footer {
    margin-inline: 0;
    max-width: none;
    padding-inline-start: 21.5rem;
  }

  /* The track above is already the column box, so the column fills it and the
     inset comes from the token the article set for this band -- the padding is
     not restated here, or it would be a second place to keep in step with the
     track. */
  .kpress-content-with-toc .kpress-long-text {
    grid-column: 2;
    margin: 0;
    max-width: none;
  }

  /* The optional thumbnail is the layout's third child and the only one with
     no explicit track, so grid auto-placement drops it into whichever cell is
     free — the rail itself once the rail is reserved and empty. Pin it to the
     reading column with the prose it belongs to. Child combinator: an author's
     own .thumbnail inside the prose is not a grid item and must not be
     re-placed. */
  .kpress-content-with-toc > .thumbnail {
    grid-column: 2;
  }

  .kpress-toc {
    align-self: start;
    grid-column: 1;
    margin: 0;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    position: sticky;
    scrollbar-color: var(--kpress-doc-border) transparent;
    scrollbar-width: thin;
    top: 2rem;
    width: auto;
  }

  .kpress-toc::-webkit-scrollbar {
    width: 2px;
  }

  .kpress-toc::-webkit-scrollbar-track {
    background: transparent;
  }

  .kpress-toc::-webkit-scrollbar-thumb {
    background: var(--kpress-doc-border);
    border-radius: var(--kpress-radius-sm);
  }

  .kpress-toc-toggle,
  .kpress-toc-backdrop {
    display: none;
  }

  /* Tables marked wide bleed rightward into the trailing margin instead of
     scrolling inside the reading column. The grid is 15rem TOC + 3rem gap +
     53rem column (left-aligned), and `.kpress-long-text` insets 2.5rem, so the
     table's left edge sits 20.5rem from the pane's left; cap the width at the
     pane's right edge (a matching 2.5rem inset → `100cqw - 23rem`). Unmarked
     tables cap at the reading column (`max-width: 100%`) and scroll internally;
     wide-marked ones grow to their content and scroll internally only once
     they pass the pane edge. `100cqw` is the pane, so the table never centres
     on / spills past the window. */
  .kpress-content-with-toc.has-toc .kpress-table-wrap,
  .kpress-content-with-toc:has(.kpress-toc) .kpress-table-wrap,
  .kpress-content-with-toc[data-kpress-toc-rail="reserved"] .kpress-table-wrap {
    left: 0;
    margin-inline: 0;
    max-width: 100%;
    min-width: 100%;
    transform: none;
    width: max-content;
  }

  .kpress-content-with-toc.has-toc .kpress-table-wrap[data-kpress-table-scale="wide"],
  .kpress-content-with-toc:has(.kpress-toc) .kpress-table-wrap[data-kpress-table-scale="wide"],
  .kpress-content-with-toc[data-kpress-toc-rail="reserved"]
    .kpress-table-wrap[data-kpress-table-scale="wide"] {
    max-width: calc(100cqw - 23rem);
  }

  .kpress-content-with-toc.has-toc .kpress-table,
  .kpress-content-with-toc:has(.kpress-toc) .kpress-table,
  .kpress-content-with-toc[data-kpress-toc-rail="reserved"] .kpress-table {
    max-width: none;
    width: 100%;
  }
}

/* Narrow document: TOC collapses to a floating list-icon button that fades in
   once toc.js detects the reader has scrolled past the first section; clicking
   it slides a fixed drawer (with backdrop) over the prose. Fixed positioning
   resolves against the non-scrolling `.kpress-frame`, so the drawer covers the
   document pane, not the browser window. */
@container kpress-doc (width < 70rem) {
  .kpress-toc-toggle {
    left: 0.75rem;
    opacity: 0;
    position: fixed;
    top: 1rem;
    transition:
      opacity var(--kpress-transition-fade),
      visibility var(--kpress-transition-fade),
      color var(--kpress-transition-fast),
      background-color var(--kpress-transition-fast);
    visibility: hidden;
    z-index: 201;
  }

  .kpress-toc-toggle.show-toggle {
    opacity: 1;
    visibility: visible;
  }

  /* The floating toggle lives in the pane's top-left gutter (fixed against
     the frame), so the document must keep an inline gutter at least as wide
     as the toggle's footprint (0.75rem inset + 32px button + breathing
     room) or prose slides under the control — both at mid widths, where the
     centered column's left edge moves inside the footprint, and on phones,
     where the 1rem base padding leaves the first characters covered. Hosts
     that add their own pane inset shrink the reservation through the
     clearance variable (their inset already contributes to the gutter). */
  /* Set the gutter token, not padding-inline: .kpress-doc's cap adds the gutter
     (box-sizing is border-box), so widening the padding alone would take the
     extra room out of the reading column instead of out of the page margin. */
  .kpress-doc {
    --kpress-doc-gutter: max(1rem, var(--kpress-toc-toggle-clearance));
  }

  .kpress-toc-backdrop {
    display: block;
  }

  .kpress-toc {
    -webkit-overflow-scrolling: touch;
    background: var(--kpress-doc-code-bg);
    color: var(--color-secondary);
    left: 1rem;
    /* dvh, not vh: on phones 100vh includes the area behind the collapsing
       browser chrome, which pushed the drawer's bottom below the visible
       viewport and trapped the last entries. The extra block-end padding
       gives the list scroll room past its final entry so it is always
       comfortably reachable. */
    max-height: calc(100dvh - 6rem);
    opacity: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-block-end: 2.5rem;
    pointer-events: none;
    position: fixed;
    top: 4rem;
    touch-action: pan-y;
    transform: translateY(-0.5rem);
    transition:
      opacity var(--kpress-transition-fade),
      transform var(--kpress-transition-fade),
      visibility var(--kpress-transition-fade);
    visibility: hidden;
    width: calc(100cqw - 2rem);
    z-index: 200;
  }

  .kpress-toc a {
    color: var(--color-secondary);
  }

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

  .kpress-toc a[data-active="true"],
  .kpress-toc a.active {
    color: var(--kpress-doc-text);
  }

  .kpress-toc-title {
    font-size: var(--kpress-caps-label-size);
  }

  /* In the drawer the expand-all control returns to a comfortable touch
     size; the extra-small sizing is for the wide sidebar, where it sits
     beside the small-caps Contents label. */
  .kpress-toc-expand-all {
    height: 20px;
    width: 20px;
  }

  .kpress-toc-expand-all-icon {
    height: 14px;
    width: 14px;
  }

  .kpress-toc ol {
    font-size: var(--kpress-font-size-small);
  }

  .kpress-toc.kpress-mobile-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    visibility: visible;
  }

  .kpress .annotated-para {
    display: block;
  }

  .kpress .annotated-para .para,
  .kpress .annotated-para .para-caption {
    width: auto;
  }

  /* Tablet band (48–70rem): the wide (>=70rem) and mobile (<48rem) blocks
     both neutralize the base wide-table full-bleed (left:50% +
     translateX(-50%) centred on the viewport), but this band did not — so
     the centred bleed leaked through. Embedded in a host pane narrower than
     the window, that centres the table on the window and spills it past the
     pane on both sides. Anchor it to the prose column and scroll internally,
     matching the other two breakpoints. (The attribute variant is listed so
     this reset also out-specifies the base wide-table bleed rule.) */
  .kpress-table-wrap,
  .kpress-table-wrap[data-kpress-table-scale="wide"] {
    left: 0;
    margin-inline: 0;
    max-width: 100%;
    transform: none;
    width: 100%;
  }

  .kpress-table {
    max-width: none;
    width: 100%;
  }
}

@container kpress-doc (max-width: 47.99rem) {
  /* Narrow screens get a tighter frame: the wide-screen gutters stack up to several
     rem per side, which is dead space on a phone (kash used 1.5rem total). The doc
     and long-text pads shrink here; the standalone page gutter shrinks in the
     media rule by .kpress-page-main below. The floating TOC toggle is present in
     this whole band, so the shrink must still respect its clearance reservation
     (this rule ties with the clearance rule above and wins by order). */
  .kpress-doc {
    /* The two phone gutters are held in variables so the wide-table
       edge-bleed below can extend across exactly this inset. The stray-wide-
       content clip guard lives HERE (not on .kpress-long-text): the doc's
       padding box ends at the pane edge, so wide tables may bleed across the
       gutters and are clipped only at the pane, never at the text margin.
       Unlike the mid-width band above, the phone band does NOT reserve the
       floating-toggle clearance: on a phone every rem of gutter is reading
       width, and the toggle's translucent document-background fill keeps the
       control and any text it slightly overlaps legible (design review
       decision — see the toggle's own comment). */
    --kpress-doc-gutter: 0.5rem;
    overflow-x: hidden;
    padding-inline: var(--kpress-doc-gutter);
  }

  .kpress-long-text {
    --kpress-prose-gutter: 0.75rem;
    max-width: 100%;
    padding-inline: var(--kpress-prose-gutter);
  }

  /* The wide 4rem pull-in reads as wasted width on a phone. */
  .kpress blockquote {
    margin-inline: 0.75rem 1rem;
  }

  /* Shallower list indents on narrow screens (kash parity). */
  .kpress-prose ul,
  .kpress-prose ol,
  .kpress .concepts ul {
    margin-left: 1rem;
  }

  /* Three columns are unreadable at phone width. */
  .kpress .concepts {
    column-count: 1;
  }

  /* Any table too wide for the phone column keeps its left edge on the text
     column but bleeds rightward across the phone gutters to the pane edge, so
     the scroll region is cut off at the screen, not at the text's right
     margin (the screen-edge cut also signals scrollability). This
     deliberately ignores the wide mark: on a phone the mark decides nothing —
     `max-content` under the pane-edge cap means small tables sit at the
     column width and only overflowing ones grow. The gutter variables are the
     two inline pads above; the doc-level clip guard keeps any rounding
     overflow at the pane edge. */
  .kpress-table-wrap,
  .kpress-table-wrap[data-kpress-table-scale="wide"] {
    left: 0;
    margin-inline: 0;
    max-width: calc(100% + var(--kpress-doc-gutter, 0.5rem) + var(--kpress-prose-gutter, 0.75rem));
    min-width: 100%;
    transform: none;
    width: max-content;
  }

  .kpress-table {
    font-size: var(--kpress-font-size-smaller);
    max-width: none;
    min-width: 100%;
    width: auto;
  }
}

@media (max-width: 1199px) {
  body.kpress-video-open {
    overflow: hidden;
    position: fixed;
    touch-action: none;
    width: 100%;
  }

  .kpress-viewport.kpress-video-open {
    overflow: hidden;
    touch-action: none;
  }
}

@media (min-width: 1200px) {
  .kpress-tooltip-wide-right {
    max-width: 22rem;
    min-width: 16rem;
  }

  .kpress-tooltip-footnote.kpress-tooltip-wide-right {
    max-width: 24rem;
    min-width: 18rem;
  }
}

@media (min-width: 1600px) {
  .kpress-tooltip-wide-right {
    max-width: 28rem;
    min-width: 20rem;
  }

  .kpress-tooltip-footnote.kpress-tooltip-wide-right {
    max-width: 30rem;
    min-width: 22rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kpress [class],
  .kpress [class]::before,
  .kpress [class]::after,
  .kpress summary,
  .kpress summary::before,
  .kpress details::details-content,
  .kpress-toc-backdrop,
  .kpress-video-backdrop,
  /* The viewport pane sits above .kpress, so the smooth hash-navigation
     glide needs its own reduced-motion opt-out. */
  .kpress-viewport {
    animation-duration: 0.01ms;
    animation-iteration-count: 1;
    scroll-behavior: auto;
    transition-duration: 0.01ms;
  }
}

/* Site chrome slots. The header/footer content is site-owned raw HTML (page
   chrome slots); these wrappers only align it with the document column and
   hand it the document's sans typography and theme tokens. KPress never
   styles the slot's inner markup. */
.kpress-site-header,
.kpress-site-footer {
  box-sizing: border-box;
  color: var(--kpress-doc-text);
  font-family: var(--kpress-font-sans);
  font-weight: var(--kpress-font-weight-sans-regular);
  font-size: var(--kpress-font-size-small);
  margin: 0 auto;
  max-width: var(--kpress-measure);
  padding: 0.75rem 1.5rem;
  width: 100%;
}

.kpress-site-header {
  border-bottom: 1px solid var(--kpress-doc-border);
}

.kpress-site-footer {
  border-top: 1px solid var(--kpress-doc-border);
  color: var(--kpress-doc-muted);
  margin-top: 2rem;
}

/* Slot <-> reading-column alignment in the md single-column state: from 48rem
   container width .kpress-long-text pads 4rem inline (kash's md:px-16), so the
   slot content must pad the same or header/footer chrome sits 2.5rem off the
   text's inline edge. Below 48rem both sides land at 1.5rem (long-text 1rem +
   .kpress-doc 0.5rem); at >=70rem the docked-TOC rule re-anchors
   padding-inline-start at the reading column, overriding this by specificity. */
@container kpress-doc (min-width: 48rem) {
  .kpress-site-header,
  .kpress-site-footer {
    padding-inline: 4rem;
  }
}

.kpress-site-header a,
.kpress-site-footer a {
  color: var(--kpress-doc-link);
  text-decoration: none;
}

.kpress-site-header a:hover,
.kpress-site-footer a:hover {
  text-decoration: underline;
}
