/* ==========================================================
   The paper
   ========================================================== */
.sheet {
  position: relative;
  width: 210mm;
  min-height: 297mm;
  flex: 0 0 auto;
  padding: 13mm 13mm 15mm;
  background: #fff;
  color: #111;
  box-shadow: 0 10px 30px rgba(61, 64, 91, 0.18);
  transform-origin: top center;
  overflow: hidden;
}

.sheet-wm {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 0;
}
.sheet-wm span {
  font-size: 128px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--accent);
  opacity: 0.08;
  transform: rotate(-32deg);
  white-space: nowrap;
}
/* lift everything above the watermark without disturbing the footer,
   which is pinned to the foot of the page */
.sheet > *:not(.sheet-wm) { position: relative; z-index: 1; }
.sheet > .sh-foot { position: absolute; }

.sh-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent);
}
/* The logo slot and the spacer opposite it are the same fixed width, so
   the title block sits on the true centre of the page whatever shape the
   uploaded logo happens to be. */
.sh-head img {
  flex: 0 0 140px;
  width: 140px;
  max-height: 54px;
  object-fit: contain;
  object-position: left center;
}
.sh-text { flex: 1; min-width: 0; text-align: center; }
.sh-spacer { width: 140px; flex: 0 0 140px; }
.sh-inst { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; color: #1a1c26; }
.sh-title { font-size: 13.5px; font-weight: 600; margin-top: 2px; }
.sh-sub { font-size: 11.5px; font-weight: 600; color: #555; margin-top: 1px; }
.sh-meta { font-size: 10.5px; color: #777; margin-top: 2px; }

.sh-lines { display: flex; gap: 16px; font-size: 11.5px; font-weight: 600; margin: 9px 0 4px; }
.sh-lines span { flex: 1; border-bottom: 1px dotted #999; padding-bottom: 3px; }
.sh-lines span:last-child { flex: 0 0 84px; }

.q-grid { display: grid; gap: 5mm; margin-top: 5mm; }
.q { break-inside: avoid; }
.q-no { font-size: 9.5px; font-weight: 700; color: #888; }
.q-term, .q-body { font-variant-numeric: tabular-nums; }
.q-term { text-align: right; font-weight: 600; line-height: 1.42; }
.q-body { font-weight: 600; margin-top: 3px; }
.q-hint { font-size: 9px; color: #999; margin-top: 2px; }
.q-ans { margin-top: 4px; }
.q-ans.filled { text-align: right; font-weight: 800; }

/* question sizes */
.size-s .q-term, .size-s .q-body { font-size: 13px; }
.size-m .q-term, .size-m .q-body { font-size: 15px; }
.size-l .q-term, .size-l .q-body { font-size: 18px; }
/* answer space — the writing area under every question */
.size-s .q-ans { height: 24px; }
.size-m .q-ans { height: 32px; }
.size-l .q-ans { height: 40px; }
.space-roomy .q-ans { height: 44px; }
.space-tall .q-ans { height: 58px; }
.q-ans.filled { line-height: 1.4; height: auto !important; }

/* single-line sums: 5454 + 545 + 485 = ____ */
.q-oneline .q-body { line-height: 1.5; word-spacing: 0.06em; }

/* ---- templates ---- */
.tpl-classic .q { border: 1px solid #333; border-radius: 3px; padding: 4px 7px; }
.tpl-classic .q-no { border-bottom: 1px solid #ddd; margin-bottom: 3px; }
.tpl-classic .q-ans { border-top: 2px solid #333; }

.tpl-minimal .q { padding: 2px 6px 0; }
.tpl-minimal .q-ans { border-top: 1.5px solid #444; }
.tpl-minimal .q-no { color: var(--accent); }

.tpl-grid .q { border: 1px solid #999; padding: 4px 7px; }
.tpl-grid .q-no { color: #666; margin-bottom: 2px; }
.tpl-grid .q-ans { border-top: 1px solid #999; background: repeating-linear-gradient(to right, #ddd 0 3px, transparent 3px 6px) bottom / 100% 1px no-repeat; }
.tpl-grid .q-grid { gap: 0; }

.tpl-cards .q {
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0 7px 5px;
  overflow: hidden;
}
.tpl-cards .q-no {
  margin: 0 -7px 5px;
  padding: 3px 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}
.tpl-cards .q-ans { border-top: 1.5px dashed var(--accent); }

/* abacus bead-counting question */
.q-abacus { display: flex; justify-content: center; margin: 4px 0 10px; }
.q-abacus svg { width: 100%; height: auto; max-height: 104px; }
.size-s .q-abacus svg { max-height: 78px; }
.size-l .q-abacus svg { max-height: 126px; }
.q-abacusbox .q-ans { border-top: none; }

/* room to actually write the number: two well-spaced ruled lines */
.q-write { display: grid; gap: 30px; padding: 8px 2px 12px; }
.q-write i { display: block; height: 1.1px; background: var(--accent); opacity: 0.85; }
.size-s .q-write { gap: 22px; padding: 6px 2px 9px; }
.size-l .q-write { gap: 38px; padding: 10px 2px 15px; }
.space-roomy .q-write { gap: 40px; padding: 10px 2px 16px; }
.space-tall .q-write { gap: 52px; padding: 12px 2px 20px; }

/* stacked sums need air between the last term and the rule */
.tpl-classic .q-ans, .tpl-cards .q-ans, .tpl-grid .q-ans { margin-top: 5px; }
.q-work { margin-top: 2px; }

.sh-foot {
  position: absolute;
  left: 13mm;
  right: 13mm;
  bottom: 7mm;
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: #999;
  border-top: 1px solid #eee;
  padding-top: 4px;
}

.key-title { font-size: 15px; font-weight: 800; margin-top: 6mm; color: var(--accent); }
.key-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 3px 10px;
  margin-top: 3mm;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.key-grid div { border-bottom: 1px dotted #ccc; padding: 2px 0; }

.ex-empty { padding: 70px 20px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- print ---------- */
@page { size: A4 portrait; margin: 0; }

@media print {
  html, body { height: auto; background: #fff; }
  .no-print, .ex-appbar, .ex-side { display: none !important; }
  .ex-app, .ex-body { display: block; height: auto; }
  .ex-stage { overflow: visible; padding: 0; background: #fff; }
  .ex-paper { display: block; }
  .sheet {
    box-shadow: none;
    transform: none !important;
    width: 210mm;
    height: 297mm;
    min-height: 0;
    page-break-after: always;
    break-after: page;
  }
  .sheet:last-child { page-break-after: auto; break-after: auto; }
  .sheet, .sheet * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}


/* ---------- extra question shapes ---------- */
.q-rule { border-top: 2px solid currentColor; margin-top: 3px; opacity: 0.85; }
.tpl-minimal .q-rule { border-top-width: 1.5px; }
.q-work { border-bottom: 1px dotted #bbb; height: 16px; }
.q-listbox .q-line {
  font-size: 0.86em;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px dotted #ccc;
  padding: 1px 0;
}
.key-grid.key-wide { grid-template-columns: repeat(2, 1fr); font-size: 10.5px; }
