/* ===========================================================================
   v065 - printing a question
   ---------------------------------------------------------------------------
   Layered above v027..v064; nothing here edits an older file.

   Who prints what, from the proposal (TC-037):
     * students print the question to work on paper - IAL work is handwriting on
       paper, so a printable question is the natural companion to the pad;
     * teachers print a set for class, and a teacher's copy WITH the mark scheme.

   So: a question prints on its own - no navigation, no toolbar, no writing
   panel, no buttons - the question image is never cropped, and the answer pane
   is included only when the teacher copy was asked for.

   The workspace is a fixed full-screen panel with its own scroll boxes, which
   is why it needs unwinding here; a naive `@media print` leaves you with one
   screenful and the rest silently cut off.
   =========================================================================== */

/* The answer pane is off by default and back on for the teacher copy. Written
   outside the media query as well, because the class is added just before
   `window.print()` and removed after - the cascade has to hold either way. */
body.print-with-answers [data-device] #workspace #v027MarkSchemePane,
body.print-with-answers #workspace #v027MarkSchemePane { display: block !important; }

@media print {
  /* ---------- 1. everything that is a control, not content ---------- */
  .sidebar,
  .sidebarCollapseBtn,
  .mobileHeader,
  .mobileNav,
  .topbar,
  .task-bar,
  .workspaceTop,
  .workspaceSubmit,
  .heroBtns,
  .filters,
  .phoneRotateHint,
  #gateNotice,
  #mergeAsk,
  .obBackdrop,
  .toast,
  .loginBackdrop,
  .modalBackdrop,
  .workspaceSplitter,
  .paperInkToolbar,
  .inkToolbar,
  .canvasStage,
  .footer,
  .appCopyright,
  /* These three live INSIDE the question pane and were the reason page 1 came
     out blank - they still occupied their height, pushing the paper onto page
     2. The toolbar holds the zoom controls, the badge is the "Read-only source"
     chip, `questionZoom` is the − 100% + control. */
  .question-toolbar,
  .questionZoom,
  .readOnlySourceBadge,
  .paperZoomStatus,
  .paperFitBtn,
  /* the writing side: heading, pad, canvas, submit strip */
  .workHead,
  #inkMethod,
  .inkWorkspace,
  .inkInfo,
  .v027WorkTabs,
  .answerMethod,
  .workspaceDrawing,
  button:not(.print-keep) {
    display: none !important;
  }

  /* ---------- 2. unwrap the fixed full-screen workspace ---------- */
  html, body {
    background: #fff !important;
    height: auto !important;
    overflow: visible !important;
  }

  #workspace,
  .panel.active {
    position: static !important;
    display: block !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    inset: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    border: 0 !important;
  }

  /* one column, full width */
  #workspace #workspaceGrid,
  .workspaceGrid {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
    gap: 0 !important;
    padding: 0 !important;
  }

  #workspace .questionPaper,
  #workspace .workingPanel {
    position: static !important;
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow: visible !important;
    flex: none !important;
    padding: 0 !important;
    margin: 0 0 6mm !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  /* ---------- 3. the question itself ---------- */

  /* Never crop the paper: a cut-off diagram is worse than a slightly smaller
     one, and the student cannot answer what they cannot see. */
  #workspace .questionPaper img,
  #workspace .questionPaper svg,
  #workspace canvas,
  #questionStage img {
    max-width: 100% !important;
    height: auto !important;
    page-break-inside: avoid;
  }

  #questionStage,
  #questionStageInner,
  .questionPaperInner {
    width: auto !important;
    max-width: none !important;
    zoom: 1 !important;
    transform: none !important;
    overflow: visible !important;
    height: auto !important;
  }

  /* long questions flow across pages instead of being clipped */
  #workspace .questionPaper,
  #workspace .v027MarkSchemePane {
    page-break-inside: auto;
  }

  /* ---------- 4. the answer, for the teacher copy ---------- */

  /* A student's sheet must NOT carry the mark scheme. This needs saying because
     v033 makes the pane permanently visible in workspace mode
     (`body.workspace-mode .v027MarkSchemePane{display:block!important}`), so
     without this rule the answers printed on the student copy too.
     The teacher copy is switched on by a class on <body>, declared OUTSIDE this
     media query - and it wins, because `body.print-with-answers #workspace
     #v027MarkSchemePane` is more specific than `#workspace .v027MarkSchemePane`. */
  #workspace .v027MarkSchemePane {
    display: none !important;
  }

  /* No margin, rule or padding above the answer image. It is taller than a page
     and cannot be split, so it starts on a fresh page and anything sitting above
     it is stranded there: with an 8mm margin + rule the teacher copy ran to 5
     sheets and page 2 carried ZERO ink (measured with pdftotext - the page had
     no text at all). The image has its own table header, so it needs no
     decoration - and removing the decoration saves a sheet per copy. */
  #workspace .v027MarkSchemePane,
  #workspace .v027MsContent {
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    min-height: 0 !important;
  }

  /* The pane's own heading sits above the answer image. That image is a single
     very tall picture (the whole official mark scheme), and a replaced element
     cannot be split across pages - so ANY element above it costs a whole extra
     sheet, because the image gets pushed to a fresh page and the heading is left
     alone on a blank one. Measured: 5 sheets with the heading, and the heading's
     own page was 0.12% ink.
     The image carries its own table header ("Question Number / Scheme / Marks"),
     so it is still identifiable without the heading. Dropping it saves a sheet
     per copy - and teachers print these in class sets. */
  #workspace .v027MsHead {
    display: none !important;
  }

  #workspace .v027MarkSchemePane,
  #workspace .v027MarkSchemePane *,
  #workspace #v027MarkSchemePdf img,
  #workspace .v027FullMarkSchemePdf img {
    page-break-inside: auto !important;
  }

  /* ---------- 5. A4 page setup ---------- */

  @page {
    size: A4;
    margin: 14mm 12mm;
  }

  /* a light heading so the printed page is identifiable */
  #workspace .questionPaper::before {
    content: "astarmaths.cn";
    display: block;
    margin: 0 0 4mm;
    font: 700 9pt/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
    letter-spacing: .06em;
    color: #9aa4b4;
    border-bottom: 1px solid #e6eaf1;
    padding-bottom: 2mm;
  }
}
