/* ==========================================================================
   Midicake ARP manual - print / PDF stylesheet
   ==========================================================================

   Everything here is inside @media print, so it has ZERO effect on the
   browsed site. It only applies when Scripts/build-pdf.ps1 renders the
   print page to PDF with headless Edge (--print-to-pdf uses print media).

   Loaded on every page via extra_css, but only the /print_page/ is ever
   printed, so the rules effectively target that one concatenated page.
   ========================================================================== */

@media print {

  /* --- Page geometry ------------------------------------------------------ */
  @page {
    size: A4;
    margin: 20mm 18mm 20mm 18mm;
  }

  /* --- Hide all site chrome ---------------------------------------------- */
  .md-header,
  .md-tabs,
  .md-sidebar,
  .md-footer,
  .md-nav,
  .md-search,
  .md-source,
  .md-content__button,
  [data-md-component="announce"],
  [data-md-component="skip"] {
    display: none !important;
  }

  /* Print page fills the width; kill the theme's max-width and padding. */
  .md-main__inner,
  .md-content,
  .md-content__inner,
  .md-typeset {
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
  }

  /* --- Base type ---------------------------------------------------------- */
  .md-typeset {
    font-size: 10.5pt;
    line-height: 1.5;
    color: #000;
  }

  .md-typeset p,
  .md-typeset li {
    orphans: 3;   /* no single line stranded at the foot of a page */
    widows: 3;    /* no single line carried alone to the next page */
  }

  /* --- Chapter breaks ----------------------------------------------------- */
  /* Each chapter (an <h1>) starts a fresh page. The print plugin wraps each
     source page in .md-typeset; the h1 is the chapter title. */
  .md-typeset h1 {
    break-before: page;
    font-size: 20pt;
    padding-top: 0;
    margin-top: 0;
    color: #000;                            /* black text - prints high-contrast */
    border-bottom: 2px solid #9c1e83;       /* the orange stays as the highlight */
    padding-bottom: 4pt;
  }

  /* The cover and the first real page should not force an extra blank page. */
  .md-typeset > h1:first-child {
    break-before: avoid;
  }

  /* --- Headings stay with their content ----------------------------------- */
  .md-typeset h2,
  .md-typeset h3,
  .md-typeset h4 {
    break-after: avoid;
    break-inside: avoid;
  }

  .md-typeset h2 {
    font-size: 14pt;
    margin-top: 14pt;
    border-bottom: 0.5pt solid #bbb;
    padding-bottom: 2pt;
  }

  .md-typeset h3 { font-size: 12pt; margin-top: 10pt; }

  /* --- Keep these blocks whole across page boundaries --------------------- */
  /* Callouts / worked-recipe boxes (blockquotes), admonitions, the 6-button
     HTML grids, tables, figures - none should be sliced in half. */
  .md-typeset blockquote,
  .md-typeset .admonition,
  .md-typeset details,
  .md-typeset table,
  .md-typeset figure,
  .md-typeset pre {
    break-inside: avoid;
  }

  /* Table rows shouldn't split either. */
  .md-typeset tr,
  .md-typeset img {
    break-inside: avoid;
  }

  /* --- Tables ------------------------------------------------------------- */
  .md-typeset table:not([class]) {
    font-size: 9.5pt;
    width: 100%;
    border: 0.5pt solid #ccc;
  }

  .md-typeset table:not([class]) th {
    background: #f0f0f0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* The hand-rolled 6-button CONTROL grids (centred bordered tables). */
  .md-typeset table[align="center"] {
    margin: 8pt auto;
    font-size: 9.5pt;
  }

  /* --- Blockquote callouts ------------------------------------------------ */
  .md-typeset blockquote {
    border-left: 3pt solid #9c1e83;
    background: #faf6f0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    padding: 6pt 10pt;
    margin: 8pt 0;
    color: #000;
  }

  /* --- Images ------------------------------------------------------------- */
  /* LCD screenshots: keep them crisp (they're 2x pixel art), cap the width. */
  .md-typeset img[src*="lcd_screenshots"] {
    image-rendering: pixelated;
    max-width: 60mm;
    border: 0.5pt solid #ccc;
  }

  /* SVG diagrams: fit the text column, never pixelate. */
  .md-typeset img[src*="diagrams"] {
    image-rendering: auto;
    max-width: 100%;
    height: auto;
  }

  /* Colour swatches must print in colour, not greyscale. */
  .md-typeset span[style*="background"] {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* --- Links -------------------------------------------------------------- */
  /* Render links as plain body text - no blue underline mid-sentence. */
  .md-typeset a,
  .md-typeset a:visited {
    color: #000;
    text-decoration: none;
  }

  /* Spell out external URLs after the link text, so a printed reader can
     follow them. Internal cross-references (relative .md links) are left
     bare - they'd just print a filename. */
  .md-typeset a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 8.5pt;
    color: #666;
    word-break: break-all;
  }

  /* --- print-site plugin cover ------------------------------------------- */
  /* The element is an ID (#print-site-cover-page), not a class. It holds our
     custom docs/assets/print_cover.tpl - no metadata table, no repo URL. */
  /* No `page: cover` named page here - assigning an element to a named page
     forces the browser to isolate it and spawns a phantom blank page before
     it. A plain break-after is all the cover needs. */
  #print-site-cover-page {
    break-after: page;
    text-align: center;
  }

  .una-cover {
    padding-top: 75mm;
  }
  .una-cover-title {
    font-size: 40pt;
    font-weight: 700;
    color: #000;                            /* black - the orange rule below carries the accent */
    letter-spacing: 0.5pt;
  }
  .una-cover-sub {
    font-size: 20pt;
    color: #333;
    margin-top: 2mm;
  }
  .una-cover-rule {
    width: 60mm;
    height: 2pt;
    background: #9c1e83;
    margin: 10mm auto;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .una-cover-tagline {
    font-size: 13pt;
    font-style: italic;
    color: #555;
  }
  .una-cover-meta {
    font-size: 11pt;
    color: #444;
    margin-top: 30mm;
    line-height: 1.6;
  }
  .una-cover-foot {
    font-size: 9.5pt;
    color: #777;
    margin-top: 8mm;
  }

  /* --- print-site plugin TOC --------------------------------------------- */
  .print-site-table-of-contents {
    break-after: page;
  }

  .print-site-table-of-contents .print-page-toc-title {
    font-size: 16pt;
    color: #000;
    border-bottom: 2px solid #9c1e83;
    padding-bottom: 4pt;
  }
}
