/* ============================================================
   Print / A5 PDF (Ctrl+P)
   ============================================================ */

@page {
  size: A5;
  margin: 8mm;
}

@media print {
  :root {
    --bg: #fff;
    --surface: #fff;
    --text: #000;
    --text-secondary: #222;
    --text-muted: #444;
    --navy: #0f2744;
    --blue: #1a5fb4;
    --border: #999;
    --border-light: #ccc;
    --blue-pale: #f0f4f8;
    --blue-muted: #d0dce8;
    --table-header: #e8eef5;
    --table-stripe: #f7f9fb;
    --memory-bg: #fffde8;
    --trap-bg: #fff5f5;
    --tip-bg: #f3faf3;
    --fs-base: 10.5pt;
  }

  html,
  body {
    background: #fff !important;
    color: #000 !important;
    font-size: 10.5pt;
    line-height: 1.45;
  }

  /* Hide chrome */
  .site-header,
  .sidebar,
  .sidebar-overlay,
  .aside-panel,
  .header-actions,
  .menu-toggle,
  .back-to-top,
  .search-panel,
  .read-progress,
  .mark-check,
  .skip-link {
    display: none !important;
  }

  .book-shell {
    display: block;
    max-width: none;
  }

  .main-wrap {
    padding: 0 !important;
    margin: 0 !important;
  }

  .main-content {
    max-width: none;
    margin: 0;
  }

  .cover {
    margin: 0 0 1rem !important;
    padding: 1.5rem 1rem !important;
    border-radius: 0;
    break-after: page;
    page-break-after: always;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .cover h1 {
    color: #fff !important;
  }

  /* Chapter starts on new page (e.g. multi-chapter print) */
  .chapter-title {
    break-before: page;
    page-break-before: always;
  }

  /* Single-chapter HTML files: never force a blank first page */
  body[data-page="chapter"] .chapter-title,
  .main-content > .chapter-title:first-child,
  .main-content > .chapter-title:first-of-type {
    break-before: avoid;
    page-break-before: avoid;
  }

  /* Avoid splitting boxes / cards mid-page */
  .memory-box,
  .trap-box,
  .tip-box,
  .king-card,
  .person-card,
  .artifact-card,
  .summary-card,
  .war-flow,
  .question-list > li,
  .ox-list li,
  .era-card,
  .timeline {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Large comparison tables may span pages; keep rows intact when possible */
  .table-scroll {
    overflow: visible;
    border: none;
    break-inside: auto;
    page-break-inside: auto;
  }

  .comparison-table {
    min-width: 0;
    font-size: 9pt;
    break-inside: auto;
    page-break-inside: auto;
  }

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

  .comparison-table tfoot {
    display: table-footer-group;
  }

  .comparison-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .comparison-table th,
  .comparison-table td {
    padding: 0.25rem 0.35rem;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

  .chapter-nav {
    display: none !important;
  }

  h2,
  h3,
  h4 {
    break-after: avoid;
    page-break-after: avoid;
    orphans: 3;
    widows: 3;
  }

  p {
    orphans: 3;
    widows: 3;
  }

  img {
    max-width: 100% !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .chapter-hero,
  .edu-figure,
  .artifact-card {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .edu-figure-visual,
  .chapter-hero,
  .cover {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Preserve box colors in PDF */
  .memory-box,
  .trap-box,
  .tip-box,
  .frequency,
  .war-flow,
  .summary-card,
  .cover {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
