/* Shared print rules. Layered important declarations beat unlayered skin
   overrides without repeating selectors. KaTeX keeps its fonts and geometry. */
@media print {
  @font-face {
    font-family: "Theme Computer Modern";
    src: url("../fonts/computer-modern/roman.woff2") format("woff2");
    font-style: normal;
    font-weight: 400;
    font-display: block;
  }

  @layer print {
    @page { margin: 16mm; }

    :where(html, body, body *) {
      color: #000 !important;
      background: transparent !important;
      box-shadow: none !important;
      text-shadow: none !important;
      animation: none !important;
      transition: none !important;
    }
    /* Do not reset formula borders, glyph sizes, or SVG transforms. */
    :where(body, body *):not(:where(.katex, .katex *, svg, svg *)) {
      border: 0 !important;
      border-radius: 0 !important;
      transform: none !important;
      filter: none !important;
      font-family: "Theme Computer Modern", Georgia, "Times New Roman", serif !important;
      font-size: inherit !important;
      line-height: inherit !important;
      letter-spacing: normal !important;
      text-transform: none !important;
    }
    :where(html, body, body *):not(:where(.katex, .katex *))::before,
    :where(html, body, body *):not(:where(.katex, .katex *))::after {
      content: none !important;
    }
    html, body {
      display: block !important;
      width: auto !important;
      min-width: 0 !important;
      height: auto !important;
      margin: 0 !important;
      padding: 0 !important;
      overflow: visible !important;
      background: #fff !important;
      color-scheme: light !important;
      font-size: 11pt !important;
      line-height: 1.5 !important;
    }

    /* Shells become ordinary blocks so long articles can cross pages. */
    :where(main, .home-shell, .archive-shell, .record-page, .page-shell,
      .error-shell, .masthead, .masthead__copy, .index-heading, .page-heading,
      .record-head, .record-grid, .article__content, .page-prose,
      .home-shell > .record-index, .archive-groups, .error-shell__content) {
      display: block !important;
      position: static !important;
      float: none !important;
      width: auto !important;
      min-width: 0 !important;
      max-width: none !important;
      height: auto !important;
      min-height: 0 !important;
      max-height: none !important;
      margin: 0 !important;
      padding: 0 !important;
      overflow: visible !important;
      contain: none !important;
      columns: auto !important;
    }
    .skip-link, .site-header, .site-footer, .site-nav, .skin-menu,
    .skin-dice, .theme-toggle, .site-share, .site-share__popover,
    .record-grid > .record-index, .record-toc, .related-records, .record-end,
    .masthead__actions, .record-actions, .tag-line, .pagination, .archive-tools,
    .index-map, .record-columns, .record-row__arrow, .heading-anchor,
    .code-frame__bar, .code-frame__gutter, .code-frame__status,
    .code-frame__fallback, .qr-share, .cookie-banner, [data-toybox],
    .flag-check, .challenge-practice, [hidden], main > style, main > script {
      display: none !important;
    }

    .record-head { margin-bottom: 16pt !important; }
    .record-head__key, .record-facts { font-size: 9pt !important; }
    .record-facts { display: block !important; margin: 6pt 0 !important; padding: 0 !important; }
    .record-facts > div { display: inline-block !important; margin-right: 12pt !important; }
    .record-facts dd { margin: 0 !important; }
    .prose, .record-head { text-align: left !important; font-weight: 400 !important; }
    .prose :is(p, li, dt, dd) { orphans: 3; widows: 3; }
    .prose :is(p, ul, ol, dl, figure, table) { margin-block: 8pt !important; }
    h1, h2, h3, h4, h5, h6 {
      position: static !important;
      width: auto !important;
      max-width: none !important;
      margin: 14pt 0 6pt !important;
      padding: 0 !important;
      line-height: 1.25 !important;
      text-align: left !important;
      font-weight: 700 !important;
      break-after: avoid-page;
      overflow-wrap: anywhere !important;
    }
    h1 { font-size: 18pt !important; }
    h2 { font-size: 14pt !important; }
    h3 { font-size: 12pt !important; }
    h4, h5, h6 { font-size: 11pt !important; }
    .prose :is(strong, b) { font-weight: 700 !important; }
    .prose :is(em, i) { font-style: italic !important; }
    .prose :is(ul, ol) { padding-left: 18pt !important; list-style-position: outside !important; }
    .prose ul { list-style-type: disc !important; }
    .prose ol { list-style-type: decimal !important; }
    .prose li { display: list-item !important; }
    .prose li::marker { color: #000 !important; }
    .prose blockquote { margin: 8pt 0 !important; padding: 0 0 0 10pt !important; border-left: 1pt solid !important; }
    .prose hr { height: 0 !important; border-top: .5pt solid !important; }
    .prose a { text-decoration: underline !important; }

    /* Wrap both raw and enhanced code; remove scroll/containment clipping. */
    .prose :is(pre, code, kbd, samp, pre *, code *) {
      font-family: ui-monospace, "SFMono-Regular", Consolas, monospace !important;
      font-size: 9pt !important;
      line-height: 1.4 !important;
    }
    .prose :is(.code-frame, .code-frame__viewport, .highlight, pre, pre code) {
      display: block !important;
      width: auto !important;
      min-width: 0 !important;
      max-width: 100% !important;
      height: auto !important;
      max-height: none !important;
      overflow: visible !important;
      contain: none !important;
      container-type: normal !important;
      break-inside: auto !important;
    }
    .prose :is(.code-frame, .highlight, pre code) { margin: 0 !important; padding: 0 !important; }
    .prose pre { margin: 8pt 0 !important; padding: 6pt !important; border: .5pt solid !important; }
    .prose :is(pre, pre code) { white-space: pre-wrap !important; overflow-wrap: anywhere !important; }

    /* math.css owns script-size ratios; never substitute the math fonts. */
    .prose .katex {
      display: inline !important;
      font-size: 1.04em !important;
      min-width: 0 !important;
      max-width: none !important;
      overflow: visible !important;
    }
    .prose .katex-display {
      display: block !important;
      margin: 10pt 0 !important;
      padding: 0 !important;
      overflow: visible !important;
      contain: none !important;
      break-inside: avoid;
    }
    .prose .katex-display > .katex { display: block !important; text-align: center !important; }
    .prose .katex-display > .katex > .katex-html { white-space: normal !important; }
    .prose img:not(.emoji), .prose svg:not(.katex *) {
      max-width: 100% !important;
      height: auto !important;
      break-inside: avoid;
    }
    .prose table { display: table !important; width: 100% !important; overflow: visible !important; border-collapse: collapse !important; }
    .prose :is(th, td) { min-width: 0 !important; padding: 4pt !important; border-bottom: .5pt solid !important; overflow-wrap: anywhere !important; }
    .prose tr { break-inside: avoid; }
  }
}
