/* MASTERCHOO / General Chemistry — shared A4 print system
   Textbook pages flow naturally; worksheet sheets preserve their A4 canvas.
   Apply to every chapter, including future content. */
@page { size: A4 portrait; margin: 0; }
@page textbook {
  size: A4 portrait;
  margin: 16mm 16mm 18mm 16mm;
  @top-right {
    content: "MASTERCHOO  ·  GENERAL CHEMISTRY";
    font-family: Arial, sans-serif;
    font-size: 7pt;
    color: #777;
  }
  @bottom-right {
    content: counter(page);
    font-family: Arial, sans-serif;
    font-size: 8pt;
    color: #777;
  }
}
@media print {
  html, body { background: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  /* Preserve A4 proportions even when box-sizing defaults change elsewhere. */
  #worksheetPrint .printPage {
    box-sizing: border-box !important;
    display: block !important;
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 12mm 15mm 17mm !important;
    border: 0 !important;
    box-shadow: none !important;
    break-after: page;
    page-break-after: always;
  }
  #worksheetPrint .printPage:last-child { break-after: auto; page-break-after: auto; }
  #worksheetPrint .pBrand,
  #worksheetPrint .pTitle,
  #worksheetPrint .pSec h2,
  #worksheetPrint .pSec h3 { break-after: avoid-page; page-break-after: avoid; }
  #worksheetPrint .gasQuestion,
  #worksheetPrint .shortQ,
  #worksheetPrint .blankRow,
  #worksheetPrint .mcq,
  #worksheetPrint .answerLines,
  #worksheetPrint .gasAnswerLine { break-inside: avoid-page; page-break-inside: avoid; }
  #worksheetPrint .pFooter { left: 15mm; right: 15mm; bottom: 8mm; }

  /* Continuous textbook printing: do not force a fresh page per section. */
  body.textbookPrinting .textbookPrintPage {
    page: textbook;
    display: block !important;
    box-sizing: border-box !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    break-after: auto !important;
    page-break-after: auto !important;
  }
  body.textbookPrinting .chapterNote,
  body.textbookPrinting .bookPrintBody,
  body.textbookPrinting .continuousPrint,
  body.textbookPrinting .chapterLesson { overflow: visible !important; }
  body.textbookPrinting .bookPrintBrand,
  body.textbookPrinting .bookPrintHead,
  body.textbookPrinting .chapterLessonHeading,
  body.textbookPrinting .chapterLessonOverview,
  body.textbookPrinting .topicTitle,
  body.textbookPrinting .subtopicTitle {
    break-after: avoid-page !important;
    page-break-after: avoid !important;
  }
  body.textbookPrinting .chapterLesson {
    break-before: auto !important;
    break-inside: auto !important;
    page-break-inside: auto !important;
    padding-top: 4mm !important;
    padding-bottom: 3mm !important;
  }
  body.textbookPrinting .chapterLessonHeading {
    margin-top: 0 !important;
    padding-top: 0 !important;
    font-size: 12pt !important;
  }
  body.textbookPrinting .chapterLessonOverview { margin-bottom: 3mm !important; }
  body.textbookPrinting .bookPrintBody .topic,
  body.textbookPrinting .bookPrintBody .subtopic {
    break-inside: avoid-page !important;
    page-break-inside: avoid !important;
  }
  body.textbookPrinting .bookPrintBody .details li,
  body.textbookPrinting .bookPrintBody .relation,
  body.textbookPrinting .gasExampleStep,
  body.textbookPrinting .gasEquation,
  body.textbookPrinting .gasFormula,
  body.textbookPrinting .bookPrintBody .lessonFigure,
  body.textbookPrinting .bookPrintBody .dataTable tr {
    break-inside: avoid-page !important;
    page-break-inside: avoid !important;
  }
  body.textbookPrinting .gasExample {
    break-inside: avoid-page !important;
    page-break-inside: avoid !important;
    max-width: 100% !important;
    margin: 3mm 0 4mm !important;
  }
  body.textbookPrinting .gasExampleWork,
  body.textbookPrinting .gasExampleStep,
  body.textbookPrinting .gasExampleStep math,
  body.textbookPrinting .gasEquation math {
    overflow: visible !important;
  }
  body.textbookPrinting .bookPrintBody p,
  body.textbookPrinting .bookPrintBody li,
  body.textbookPrinting .bookPrintBody .summary,
  body.textbookPrinting .bookPrintBody .chapterLessonOverview {
    orphans: 3;
    widows: 3;
  }
  body.textbookPrinting .bookPrintBody math[display="inline"] {
    display: inline-block !important;
    vertical-align: -0.16em !important;
    font-size: 1em !important;
    white-space: nowrap !important;
    overflow: visible !important;
  }
  body.textbookPrinting .bookPrintBody math[display="block"] {
    break-inside: avoid-page !important;
    page-break-inside: avoid !important;
  }
  /* Avoid isolated footer-only pages; fixed running header and page numbers remain. */
  body.textbookPrinting .bookPrintFooter { display:none!important; }
}