@page {
  margin: var(--kpress-print-page-margin);

  @bottom-left {
    color: oklch(44.95% 0 0);
    content: var(--kpress-print-footer);
    font-family: var(--kpress-font-sans);
    font-weight: var(--kpress-font-weight-sans-regular);
    font-size: var(--kpress-font-size-small);
  }

  @bottom-right {
    color: oklch(17.76% 0 0);
    content: counter(page);
    font-family: var(--kpress-font-prose);
    font-weight: var(--_kpress-font-weight-prose);
    font-size: var(--kpress-font-size-small);
  }
}

@media print {
  :root,
  .kpress {
    color-scheme: light;
    /* Re-root the whole type ramp at the print size: every size derives from
       the base (see style-tokens.css SIZING POLICY), so headings, code, and
       bullets keep their designed ratios to the 11pt body on paper. Without
       this re-rooting, rem-derived sizes would track the 16px screen root
       while the body stays pinned, printing h1/body at ~1.85 instead of the
       designed 1.7. */
    --kpress-font-size-base: var(--kpress-print-font-size);
    --kpress-doc-bg: oklch(100.00% 0 0);
    --kpress-doc-text: oklch(17.76% 0 0);
    --kpress-doc-muted: oklch(38.67% 0 0);
    --kpress-doc-border: oklch(78.26% 0 0);
    --kpress-doc-link: oklch(0.00% 0 0);
  }

  /* Print sans: the static instances lead, the variable face stays as the fallback.
     Chromium's PDF writer cannot embed a variable font away from its default position,
     so it draws every glyph as a Type3 outline path, and a viewer that smooths text
     drawn through the font machinery leaves those paths thin -- the sans then reads a
     step lighter than the serif and the mathematics beside it. A static instance embeds
     as a font and is smoothed as one. The faces are declared in print-fonts.css and
     generated by devtools/instance_sans.py, under a family of their own because the
     OFL reserves the name of the one they are derived from. The selector list mirrors
     the one style-tokens.css declares --kpress-font-sans on, so no scope falls back to
     the screen stack, and it includes :root because the @page margin boxes above
     resolve custom properties from the root element.

     Two host hooks, in precedence order. --kpress-host-font-sans-print names the print
     stack outright: a host that ships instances of its own points at them here. A host
     that sets only the screen hook, --kpress-host-font-sans, has named a family for
     both media and gets it in both -- the static set is a default, not an override, and
     a host's own sans is not overruled on paper. That host prints whatever its family
     prints, Type3 outlines included if it is a variable webfont, so the operations
     guide asks it to set the print hook as well. */
  :root,
  .kpress,
  .kpress-page-main,
  .kpress-tooltip {
    --kpress-font-sans: var(
      --kpress-host-font-sans-print,
      var(
        --kpress-host-font-sans,
        "KPress Print Sans",
        "Source Sans 3 Variable",
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif
      )
    );
  }

  body {
    background: oklch(100.00% 0 0);
  }

  /* The document viewport is a 100dvh scroll container on screen; for print it
     must release its height and overflow (and drop containment) so the whole
     document flows across pages instead of clipping to one screen. The frame's
     transform layer must go too: a transformed ancestor breaks print
     fragmentation. (The viewport keeps `transform: none` defensively.) */
  .kpress-viewport {
    block-size: auto;
    container-type: normal;
    overflow: visible;
    transform: none;
  }

  .kpress-frame {
    transform: none;
  }

  .kpress {
    background: oklch(100.00% 0 0);
    color: oklch(17.76% 0 0);
    font-size: var(--kpress-print-font-size);
    line-height: 1.4;
  }

  .kpress-no-print,
  .kpress button,
  .kpress-site-footer,
  .kpress-site-header,
  .kpress-tooltip,
  .kpress-toc,
  .kpress-toc-backdrop,
  .kpress-video-backdrop,
  .kpress-video-popover {
    display: none;
  }

  .kpress-print-only {
    display: block;
  }

  .kpress h1,
  .kpress h2,
  .kpress h3,
  .kpress h4,
  .kpress h5,
  .kpress h6 {
    break-after: avoid;
    page-break-after: avoid;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .kpress p,
  .kpress li,
  .kpress blockquote {
    hyphens: auto;
    orphans: 3;
    text-align: justify;
    widows: 3;
  }

  .kpress p {
    margin-block: 0.65rem;
  }

  .kpress li {
    margin-block-start: 0.6rem;
  }

  .kpress li > p:first-child {
    margin-block-start: 0;
  }

  .kpress li > p:last-child {
    margin-block-end: 0;
  }

  .kpress-long-text {
    /* Card chrome (data-kpress-card) never prints: paper is the sheet. */
    border: none;
    box-shadow: none;
    padding: 0;
  }

  /* The @page margin is the reading margin on paper: the margin boxes
     (@bottom-left footer, @bottom-right page number) sit exactly at it, so
     the shells drop their screen-side gutters to align the text column with
     them. Without this the text sits 1rem (embedded) to 3rem (standalone)
     inside the margin boxes.

     The block axis is dropped for the same reason and was previously missed.
     `.kpress-page-main` carries `padding-block-start` as a screen gutter, and
     it survived into print stacked on top of the @page margin, pushing the
     first page's content down by that much for no reason a reader can see.
     Measured on a 13-page document at Letter with a 1in margin: 40px of it,
     which cost a whole page. Removing it took the document to 12 pages and
     premature whitespace from 25.51in to 17.58in, because a heading and its
     paragraph that no longer fit above a full-page figure now do. No page
     grows and nothing is stranded; on A4, whose taller box never produced the
     shape, the change is a no-op. */
  .kpress-doc,
  .kpress-page-main {
    padding-inline: 0;
    padding-block-start: 0;
  }

  .kpress blockquote,
  .kpress pre,
  .kpress table,
  .kpress figure {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .kpress tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .kpress thead {
    display: table-header-group;
  }

  .kpress sup {
    font-size: 110%;
  }

  .kpress details.metadata {
    display: none;
  }

  .kpress-tabs [role="tablist"] {
    display: none;
  }

  .kpress-tab-panel,
  .kpress-tab-panel[hidden] {
    break-inside: avoid;
    display: block;
    max-block-size: none;
    overflow: visible;
    page-break-inside: avoid;
    padding-block: 0.75rem;
    visibility: visible;
  }

  .kpress-tab-panel::before {
    color: oklch(17.76% 0 0);
    content: attr(data-kpress-tab-title);
    display: block;
    font-family: var(--kpress-font-sans);
    font-feature-settings: var(--kpress-font-features-sans);
    font-size: calc(var(--kpress-font-size-base) * 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-block: 0 0.5rem;
    text-transform: var(--kpress-caps-transform);
  }

  .kpress-table-wrap {
    margin-inline: 0;
    overflow: visible;
  }

  .kpress-code {
    background-color: transparent;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    word-break: break-word;
  }

  .kpress-math,
  .kpress-math math {
    color: oklch(17.76% 0 0);
  }

  .kpress-math-display {
    break-inside: avoid;
    overflow: visible;
    page-break-inside: avoid;
  }

  .kpress-math[data-kpress-math-error="true"] {
    background: transparent;
    border-color: oklch(17.76% 0 0);
    color: oklch(17.76% 0 0);
  }

  .kpress-diagram,
  .kpress-diagram svg {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .kpress-diagram {
    border-color: oklch(17.76% 0 0);
  }

  .kpress-diagram-source {
    overflow: visible;
    white-space: pre-wrap;
  }

  .kpress-diagram-rendered {
    overflow: visible;
  }

  .kpress ol {
    counter-reset: kpress-print-list-item;
    list-style: none;
    margin-left: 1rem;
    padding-left: 0;
  }

  .kpress ol > li {
    align-items: baseline;
    break-inside: avoid;
    counter-increment: kpress-print-list-item;
    display: grid;
    gap: 0 0.5rem;
    grid-template-columns: 2.5rem minmax(0, 1fr);
    margin-block: 0 0.5rem;
    padding-left: 0;
    page-break-inside: avoid;
    position: static;
  }

  .kpress ol > li::before {
    content: counter(kpress-print-list-item) ".";
    font-family: var(--kpress-font-prose);
    grid-column: 1;
    text-align: right;
  }

  .kpress ol > li > * {
    grid-column: 2;
    hyphens: auto;
    overflow-wrap: break-word;
    word-break: break-word;
  }

  .kpress ol > li p,
  .kpress ol > li blockquote {
    text-align: left;
    text-justify: none;
  }

  .kpress ol ol,
  .kpress ol ul {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
  }

  .kpress ol ol {
    counter-reset: none;
    list-style: decimal outside;
  }

  .kpress ol ul {
    list-style: none;
  }

  .kpress ol ol > li,
  .kpress ol ul > li {
    display: list-item;
    margin-top: 0.4rem;
    padding-left: 0.25rem;
    text-align: left;
    text-justify: none;
  }

  .kpress ol ol > li::before {
    content: none;
  }

  /* The drawn square, at this rule's own smaller marker size; document.css
     carries the measurement, and the em offsets there are why one pair of
     numbers serves both sizes. */
  .kpress ol ul > li::before {
    background: currentColor;
    content: "";
    font-size: calc(var(--kpress-font-size-base) * 0.7);
    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;
  }

  /* This selector outranks the shared forced-colors rule in components.css, so
     the nested print marker needs its own copy or it prints as nothing in a
     high-contrast profile. The reasoning is with that rule. */
  @media (forced-colors: active) {
    .kpress ol ul > li::before {
      background: CanvasText;
      forced-color-adjust: none;
    }
  }

  .kpress .kpress-long-list,
  .kpress .kpress-long-list > li {
    break-inside: auto;
    page-break-inside: auto;
  }

  .kpress-footnote-ref a,
  .kpress-footnote-backref,
  .footnote-ref a,
  .footnote {
    background-color: transparent;
    color: oklch(17.76% 0 0);
    font-family: var(--kpress-font-prose);
    font-feature-settings: normal;
    font-variant-caps: all-small-caps;
    font-weight: var(--_kpress-font-weight-prose);
    padding: 0 0.05rem;
  }

  .kpress-footnote-backref,
  a[href^="#fnref"],
  .reversefootnote {
    display: none;
  }

  .kpress .concepts {
    column-count: 2;
  }

  .kpress .video-gallery {
    display: block;
  }

  .kpress .kpress-video-placeholder {
    aspect-ratio: auto;
    background: transparent;
    border: 1px solid oklch(68.30% 0 0);
    color: oklch(17.76% 0 0);
    min-height: 0;
    padding: 0.75rem;
  }

  .kpress .kpress-video-placeholder-action {
    display: none;
  }

  .kpress .video-item,
  .kpress .boxed-text,
  .kpress .frame-capture,
  .kpress .key-claims,
  .kpress .summary,
  .kpress .concepts {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
