/* ============================================================
   BOOK.os — print.css
   Activates only under @media print (PDF export).
   Letter-size, portrait, two physical pages per logical spread.
   Page-break logic + outer-margin cartouches + color preservation.
   ============================================================ */

@media print {

  /* Page geometry — letter portrait, generous margins for binding */
  @page {
    size: letter portrait;
    margin: 0.6in 0.55in 0.7in 0.55in;
  }

  /* Left-hand page (verso) — extra binding margin on the right */
  @page :left {
    margin-right: 0.7in;
    margin-left: 0.5in;
  }

  /* Right-hand page (recto) — extra binding margin on the left */
  @page :right {
    margin-left: 0.7in;
    margin-right: 0.5in;
  }

  /* First page = cover, no margins (full bleed) */
  @page :first {
    margin: 0;
  }

  /* ---------- Color preservation ---------- */
  html, body {
    background: white !important;
    color: var(--ink) !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    color-adjust: exact;
  }

  /* Drop the dark substrate + flex centering for print pagination */
  body {
    background: none !important;
    display: block !important;
    min-height: 0 !important;
  }

  /* Hide the viewport-pinned decorative frame brackets — print pages
     have their own page margins, no need for the screen frame. */
  body::before,
  body::after {
    display: none !important;
  }

  /* ---------- Spread → two physical pages ---------- */
  .spread {
    display: block;
    width: auto;
    margin: 0;
    filter: none;
    page-break-before: always;
    page-break-after: always;
    break-inside: avoid;
  }

  .spread .page {
    width: 100%;
    height: 9.5in;
    page-break-after: always;
    break-after: page;
    box-shadow: none;
    overflow: visible;
  }

  .spread .page--right {
    page-break-after: avoid;
  }

  /* Prevent orphaned page breaks inside elements that should stay together.
     Covers both old-pattern blocks (data-plate / dialogue-card / pull-quote)
     and revised Spread 3 blocks (mem-capsule / voice-sample / habitat /
     ref-strip / sig-caption / aliases-line) promoted to spread.css
     2026-05-25. */
  .data-plate,
  .dialogue-card,
  .margin-note,
  .pull-quote,
  .daemon-frame,
  .thread,
  .mem-capsule,
  .mem-capsule .row,
  .voice-samples,
  .voice-sample,
  .sensory-field,
  .habitat-block,
  .ref-strip,
  .sig-caption,
  .aliases-line {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Keep heads with following content */
  h1, h2, h3, .section-head {
    page-break-after: avoid;
    break-after: avoid;
  }

  /* ---------- Hide screen-only chrome ----------
     The closed-book 3D hardcover stage owns the viewport on first
     visit; on print, start at the underlying cover spread, not the
     landing animation. Edit-mode chrome (toolbar / actionbar /
     onboard / toast) and ambient overlays (gutter / watermark /
     mtime stamp) already carry `.no-print` and are hidden via the
     first selector. */
  .no-print,
  nav,
  .book-nav,
  .book-warp-curtain,
  .book-turn-page,
  .book-turn-preview,
  .preview-toggle,
  .book-stage,
  #book-closed-stage {
    display: none !important;
  }

  /* ---------- Link styling — show URLs after links (optional) ---------- */
  /* Disabled by default; uncomment if you want printed link refs */
  /* a::after {
    content: " (" attr(href) ")";
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7em;
    color: var(--ink-faint);
  } */

  /* Internal anchors and same-page hrefs shouldn't get the URL postfix */
  a[href^="#"]::after,
  a[href^="javascript:"]::after {
    content: "";
  }

  /* ---------- Image scaling for print fidelity ---------- */
  img {
    max-width: 100%;
    height: auto;
    page-break-inside: avoid;
  }

  /* ---------- Bleeker stamps stay visible in print ---------- */
  .bleeker-stamp,
  .page-corner,
  .margin-note {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
