/*
 * The A4 sheet.
 *
 * One .sheet is exactly one sheet of A4: 210 x 297 mm including the 15 mm side
 * margins and 12 mm top and bottom margins. The printable block is 180 x 273 mm
 * and is split into a 26 mm header, a 235 mm question area and a 12 mm footer.
 */

.sheet {
  --sheet-ink: #111111;
  position: relative;
  width: 210mm;
  height: 297mm;
  padding: 12mm 15mm;
  background: var(--paper, #ffffff);
  color: var(--sheet-ink);
  font-family: var(--font-sheet);
  font-size: var(--fs, 16pt);
  line-height: 1.2;
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  display: grid;
  grid-template-rows: 26mm 235mm 12mm;
  overflow: hidden;
  break-inside: avoid;
  page-break-inside: avoid;
}

.sheet * {
  box-sizing: border-box;
}

/* ------------------------------------------------------------------ header */

.sheet-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 33mm 33mm 33mm;
  column-gap: 4mm;
  align-items: end;
  padding-bottom: 3mm;
  border-bottom: 0.6mm solid var(--sheet-ink);
}

.sheet-title h2 {
  margin: 0;
  font-size: 13.5pt;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sheet-title p {
  margin: 1.2mm 0 0;
  font-size: 7.6pt;
  color: #444a52;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet-title-answer {
  color: var(--answer);
}

.sheet-field {
  display: flex;
  flex-direction: column;
  gap: 1mm;
}

.sheet-field-label {
  font-size: 7.5pt;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #4a5159;
  white-space: nowrap;
}

.sheet-field-label em {
  font-style: normal;
  text-transform: none;
  letter-spacing: 0;
  font-size: 6.7pt;
  color: #7a818a;
}

.sheet-field-line {
  display: block;
  height: 4.5mm;
  border-bottom: 0.3mm solid #6b7178;
}

/* ------------------------------------------------------------- question area */

.sheet-body {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), var(--cell-w, 45mm));
  grid-template-rows: repeat(var(--rows, 6), var(--cell-h, 39mm));
  column-gap: var(--gap, 0mm);
  row-gap: 0;
  align-content: start;
}

.q {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5mm 1mm;
  min-width: 0;
  overflow: hidden;
}

.q-group {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 2.4mm;
  max-width: 100%;
  min-width: 0;
}

.q-n {
  flex: 0 0 auto;
  width: 5.8mm;
  text-align: right;
  padding-top: 0.8mm;
  font-size: 6.8pt;
  line-height: 1;
  font-weight: 600;
  color: #8d949c;
}

/* horizontal equations */

.q--equation {
  justify-content: center;
}

.q-calc {
  display: inline-flex;
  align-items: baseline;
  gap: 1mm;
  white-space: nowrap;
}

.num {
  font-weight: 500;
  letter-spacing: 0.01em;
}

.op,
.eq {
  font-weight: 400;
  color: #1d232a;
}

.slot {
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  width: var(--slot-w, 9mm);
  min-height: 1.25em;
  border-bottom: 0.4mm solid var(--sheet-ink);
  line-height: 1;
}

.slot .ans {
  padding-bottom: 0.4mm;
}

.ans {
  color: var(--answer);
  font-weight: 700;
}

/* equations: the number sits just above the fact, so the fact keeps the full
   cell width in five-column layouts */

.q--equation .q-group {
  padding-top: 4.2mm;
  align-items: center;
}

.q--equation .q-n {
  position: absolute;
  top: 0;
  left: 0;
  width: auto;
  padding-top: 0;
  text-align: left;
}

.q--bond .q-group {
  align-items: center;
}

/* column addition, subtraction and multiplication */

.q--column {
  justify-content: center;
  align-items: center;
}

.colsum {
  display: grid;
  grid-template-columns: 6mm minmax(0, 1fr);
  row-gap: 0.6mm;
  width: 100%;
  max-width: 44mm;
  font-size: 0.94em;
}

.col-op {
  text-align: left;
  font-size: 1.12em;
  line-height: 1;
}

.col-num {
  text-align: right;
  font-weight: 500;
  line-height: 1.12;
  white-space: nowrap;
}

.col-rule {
  grid-column: 1 / -1;
  border-top: 0.5mm solid var(--sheet-ink);
  margin: 0.5mm 0;
}

.col-total {
  min-height: 1.2em;
}

/* bus stop short division */

.q--busstop,
.q--long {
  justify-content: center;
  padding: 2.5mm 1mm 0.5mm;
}

.bs,
.ld {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  max-width: 100%;
}

.bs-quot,
.ld-quot {
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  min-height: 1.1em;
  line-height: 1.05;
}

.bs-quot i,
.ld-quot i {
  width: var(--dg, 6.6mm);
  text-align: center;
  font-style: normal;
  font-weight: 700;
}

.bs-main,
.ld-main {
  display: inline-flex;
  align-items: stretch;
}

.bs-divisor,
.ld-divisor {
  width: 9mm;
  text-align: right;
  padding-right: 1.2mm;
  align-self: flex-end;
  line-height: 1.15;
  font-weight: 500;
}

.bs-dividend,
.ld-dividend {
  display: inline-flex;
  border-top: 0.5mm solid var(--sheet-ink);
  border-left: 0.5mm solid var(--sheet-ink);
  padding-left: 0.4mm;
  line-height: 1.15;
}

.bs-dividend i,
.ld-dividend i {
  width: var(--dg, 6.6mm);
  text-align: center;
  font-style: normal;
  font-weight: 500;
}

.bs-rem {
  align-self: flex-end;
  margin-left: 2mm;
  font-size: 0.92em;
  white-space: nowrap;
}

.ld-work {
  align-self: stretch;
  margin-left: 9mm;
}

.ld-work span {
  display: block;
  height: 0.85em;
  border-bottom: 0.25mm dotted #9aa3ad;
}

/* grid method */

.q--grid {
  padding: 2mm 1mm 0.5mm;
}

.gm {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6mm;
  font-size: 0.72em;
}

.gm-table {
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.gm-table th,
.gm-table td {
  border: 0.35mm solid var(--sheet-ink);
  width: 14mm;
  height: 5.2mm;
  line-height: 1.05;
  text-align: center;
  vertical-align: middle;
  font-weight: 500;
  padding: 0;
}

.gm-table .gm-corner {
  width: 8mm;
  background: #f1f1ee;
  font-weight: 600;
}

.gm-part {
  color: #4a5159;
  font-weight: 500;
}

.gm-total {
  display: flex;
  align-items: center;
  gap: 2mm;
  font-size: 0.95em;
}

.gm-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72em;
  color: #5b626a;
}

.gm-ans {
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  min-width: 18mm;
  min-height: 1.15em;
  border-bottom: 0.35mm solid var(--sheet-ink);
}

/* number bonds */

.bond {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.6mm;
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--bond-fs, 0.82em);
}

.bond .slot {
  width: calc(var(--slot-w, 9mm) - 1mm);
}

.bond-eq {
  display: inline-flex;
  align-items: baseline;
  gap: 1.2mm;
  white-space: nowrap;
}

.bond-bar {
  display: flex;
  width: 100%;
  height: 7mm;
  border: 0.4mm solid var(--sheet-ink);
}

.bond-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 0.4mm solid var(--sheet-ink);
  font-size: 0.8em;
  font-weight: 500;
}

.bond-seg:last-child {
  border-right: 0;
}

.bond-seg--blank {
  background: #fafaf8;
}

/* ------------------------------------------------------------------ footer */

.sheet-foot {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-top: 0.3mm solid #8b929a;
  padding-top: 1.5mm;
  font-size: 7.5pt;
  color: #3f464d;
}

.sheet-foot-left {
  text-align: left;
  letter-spacing: 0.02em;
}

.sheet-foot-mid {
  text-align: center;
  color: #2b3238;
}

.sheet-foot-right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------- on-screen preview */

.preview-stage .sheet {
  box-shadow: var(--shadow-md);
  border: 1px solid #d7d3cb;
}

.preview-stage .sheet + .sheet {
  margin-top: 10mm;
}
