/* A4 has its own 6 mm inset; the printer must not add a second margin. */
@page { size: A4 portrait; margin: 0; }
.dp-paper-frame {
    --dp-preview-scale: 1;
    position: relative;
    width: 100%;
    max-width: 210mm;
    height: calc(297mm * var(--dp-preview-scale));
    margin: 0 auto 24px;
}
.dp-paper-page, .dp-paper-page * { box-sizing: border-box; }
.dp-paper-page {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 210mm;
    height: 297mm;
    padding: 6mm;
    margin: 0;
    overflow: hidden;
    background: #fff;
    color: #000;
    font: 14px/1.5 Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    text-align: left;
    box-shadow: 0 3px 20px #0002;
    transform: scale(var(--dp-preview-scale, 1));
    transform-origin: top left;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
/* Keep the paper chrome small; writing space belongs to each question. */
.dp-paper-header { flex: 0 0 10mm; display: flex; align-items: center; justify-content: space-between; gap: 5mm; border-bottom: 0.25mm solid #000; }
.dp-sheet-title { margin: 0; color: #000; font-size: 18px; line-height: 1.3; font-weight: 700; white-space: nowrap; }
.dp-paper-info { display: flex; justify-content: space-between; gap: 8mm; font-size: 12px; white-space: nowrap; }
.dp-paper-body { flex: 1 1 auto; min-height: 0; padding-top: 2mm; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 8mm; row-gap: 3mm; align-content: start; align-items: start; }
.dp-question { min-width: 0; margin: 0; break-inside: avoid; }
.dp-question-wide { grid-column: 1 / -1; }
.dp-question-label { min-height: 4.5mm; font-size: 11px; line-height: 1.4; }
.dp-problem { display: flex; align-items: center; gap: 0.6mm; min-height: 9mm; font-size: 18px; line-height: 1.5; white-space: nowrap; }
/* Contents lets a full-width expression wrap between tokens, including nested
   parentheses, without shrinking its numerals or splitting a fraction. */
.dp-expression { display: contents; }
.dp-question-wide .dp-problem { flex-wrap: wrap; }
.dp-operator { display: inline-block; margin: 0 0.5mm; }
.dp-number, .dp-bracket { display: inline-block; }
.dp-fraction { display: inline-flex; flex-direction: column; vertical-align: middle; align-items: stretch; text-align: center; font-size: 0.9em; line-height: 1.12; margin: 0 0.5mm; min-width: 3mm; }
.dp-numerator { border-bottom: 0.3mm solid #000; padding: 0 0.7mm 0.5mm; }
.dp-denominator { padding: 0.5mm 0.7mm 0; }
.dp-work-area { height: 12mm; margin-top: 1mm; }
.dp-work-area-grid {
    background-image: linear-gradient(to right, #ddd 0.2mm, transparent 0.2mm), linear-gradient(to bottom, #ddd 0.2mm, transparent 0.2mm);
    background-size: 7mm 7mm;
    border: 0.2mm solid #ddd;
}
.dp-answer-steps { margin: 1mm 0 0; padding-left: 6mm; font-size: 13px; line-height: 1.65; }
.dp-answer-steps li { white-space: pre-wrap; overflow-wrap: anywhere; }
.dp-paper-footer { flex: 0 0 4mm; display: flex; justify-content: flex-end; align-items: end; font-size: 10px; }
.dp-export-stage { position: absolute; top: 0; left: -10000px; width: 210mm; pointer-events: none; }
.dp-export-stage .dp-paper-page { transform: none !important; box-shadow: none; --dp-preview-scale: 1; }
.dp-print-root { display: none; }
@media print {
    html, body { width: 210mm !important; height: auto !important; margin: 0 !important; padding: 0 !important; background: white !important; }
    body > :not(.dp-print-root) { display: none !important; }
    body > .dp-print-root { display: block !important; margin: 0 !important; padding: 0 !important; }
    .dp-print-root .dp-paper-page {
        display: flex !important;
        transform: none !important;
        width: 210mm !important;
        height: 297mm !important;
        margin: 0 !important;
        box-shadow: none !important;
        break-inside: avoid;
        page-break-inside: avoid;
        break-after: page;
        page-break-after: always;
    }
    .dp-print-root .dp-paper-page:last-child { break-after: auto; page-break-after: auto; }
}

.dp-layout-stage { visibility: hidden; }
