:root {
    --mwg-row-gap: 3.2mm;
    --mwg-column-gap: 3.5mm;
    --mwg-cell-gap: var(--mwg-column-gap);
    --mwg-cell-padding-block: 2.5mm;
    --mwg-cell-padding-inline: 2.2mm;
    --mwg-border-color: #4b5563;
    --mwg-soft-border-color: #c8d4e4;
    --mwg-border-width: 1px;
    --mwg-answer-line-width: 2px;
    --mwg-cell-min-height: 31mm;
    --mwg-text-cell-min-height: 24mm;
    --mwg-compare-cell-min-height: 22mm;
    --mwg-fraction-cell-min-height: 26mm;
    --mwg-inline-cell-min-height: 22mm;
    --mwg-division-cell-min-height: 33mm;
    --mwg-rhythm-cell-min-height: 7.4mm;
    --mwg-prevnext-cell-min-height: 7.4mm;
    --mwg-item-number-width: 8mm;
}

.mwg-grid {
    display: flex;
    flex-direction: column;
    gap: var(--mwg-row-gap);
}

.mwg-grid-row {
    display: grid;
    grid-template-columns: repeat(var(--mwg-print-cols, 4), minmax(0, 1fr));
    gap: var(--mwg-cell-gap);
}

.mwg-grid-cell {
    border: var(--mwg-border-width) solid var(--mwg-soft-border-color);
    border-radius: 10px;
    background: #ffffff;
    min-height: var(--mwg-cell-min-height);
    padding: var(--mwg-cell-padding-block) var(--mwg-cell-padding-inline);
    display: flex;
    align-items: flex-start;
    gap: 2.2mm;
    break-inside: avoid;
    page-break-inside: avoid;
}

.mwg-grid-cell-empty {
    border: none;
    background: transparent;
}

.mwg-item-number {
    min-width: var(--mwg-item-number-width);
    font-weight: 800;
    color: #0f172a;
    font-size: 10.2pt;
    line-height: 1.2;
    padding-top: 0.2mm;
}

.mwg-grid-cell--operation {
    align-items: flex-start;
}

.mwg-grid-cell--operation .mwg-op-block {
    margin-top: 2mm;
}

.mwg-grid-cell--multiplication {
    min-height: 26mm;
}

.mwg-grid-cell--division {
    border: none;
    background: transparent;
    min-height: var(--mwg-division-cell-min-height);
    padding-inline: 1.2mm;
}

.mwg-grid-cell--inline-op {
    min-height: var(--mwg-inline-cell-min-height);
    align-items: center;
}

.mwg-op-block {
    --mwg-digit-width: 4ch;
    width: calc(var(--mwg-digit-width) + 2ch);
    font-family: "Courier New", Courier, monospace;
    font-size: 12pt;
    font-weight: 700;
    line-height: 1.12;
    font-variant-numeric: tabular-nums lining-nums;
}

.mwg-op-row {
    display: grid;
    grid-template-columns: 1.2ch var(--mwg-digit-width);
    align-items: baseline;
    justify-content: end;
    column-gap: 0.15ch;
}

.mwg-op-sign {
    text-align: center;
}

.mwg-op-value {
    text-align: right;
    white-space: nowrap;
}

.mwg-op-answer-line {
    border-top: var(--mwg-answer-line-width) solid #1f2937;
    margin-top: 1px;
    height: 10px;
}

.mwg-op-remainder {
    margin-top: 1px;
    font-size: 8.4pt;
    font-weight: 700;
    color: #334155;
    white-space: nowrap;
}

.mwg-op-remainder-blank {
    display: inline-block;
    width: 11mm;
    border-bottom: var(--mwg-border-width) solid #1f2937;
    transform: translateY(-1px);
}

.mwg-inline-op-block {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.4mm;
    justify-content: center;
}

.mwg-inline-op-expression {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.2mm;
    font-family: "Courier New", Courier, monospace;
    font-size: 11.2pt;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums lining-nums;
}

.mwg-inline-op-sign,
.mwg-inline-op-equals {
    color: #0f172a;
}

.mwg-inline-blank {
    display: inline-block;
    min-width: 6ch;
    border-bottom: var(--mwg-answer-line-width) solid #1f2937;
    height: 0.95em;
}

.mwg-inline-remainder {
    display: flex;
    align-items: center;
    gap: 1.4mm;
    font-size: 8.5pt;
    font-weight: 700;
    color: #334155;
}

.mwg-division-block {
    margin-top: 1mm;
    font-family: "Courier New", Courier, monospace;
    color: #0f172a;
}

.mwg-division-layout {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-areas:
        "dividend divisor"
        ". workspace";
    align-items: start;
    column-gap: 2px;
}

.mwg-division-dividend {
    grid-area: dividend;
    align-self: center;
    justify-self: end;
    padding-top: 1.4mm;
    font-size: 12pt;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums lining-nums;
}

.mwg-division-divisor-wrap {
    grid-area: divisor;
    min-width: 11mm;
    min-height: 8mm;
    padding: 0 0 0.8mm 1.4mm;
    border-left: var(--mwg-border-width) solid #1f2937;
    border-bottom: var(--mwg-border-width) solid #1f2937;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
}

.mwg-division-divisor {
    font-size: 12pt;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums lining-nums;
}

.mwg-division-workspace {
    grid-area: workspace;
    min-height: 8mm;
    border-left: var(--mwg-border-width) solid #1f2937;
}

.mwg-division-remainder {
    margin-top: 2mm;
    margin-left: calc(100% - 9mm);
    width: 8mm;
    font-family: "Nunito", sans-serif;
    font-size: 7.4pt;
    font-weight: 700;
    color: #64748b;
    text-transform: lowercase;
}

.mwg-grid-cell--text {
    min-height: var(--mwg-text-cell-min-height);
}

.mwg-grid-cell--comparison {
    min-height: var(--mwg-compare-cell-min-height);
    align-items: center;
}

.mwg-compare-block {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 2mm;
    align-items: center;
}

.mwg-compare-value {
    text-align: center;
    font-size: 12pt;
    font-weight: 800;
    color: #0f172a;
    font-variant-numeric: tabular-nums lining-nums;
}

.mwg-compare-box {
    width: 10mm;
    height: 8mm;
    border: var(--mwg-border-width) dashed var(--mwg-border-color);
    border-radius: 6px;
}

.mwg-grid-cell--fraction {
    min-height: var(--mwg-fraction-cell-min-height);
    align-items: center;
}

.mwg-fraction-block {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 3mm;
    align-items: center;
}

.mwg-fraction-problem {
    display: inline-flex;
    align-items: center;
    gap: 1.6mm;
    justify-content: center;
    min-width: 0;
}

.mwg-fraction-whole {
    font-size: 12pt;
    font-weight: 800;
}

.mwg-fraction-stack {
    display: inline-grid;
    grid-template-rows: auto auto;
    justify-items: center;
    min-width: 16mm;
    font-size: 10.5pt;
    font-weight: 800;
    line-height: 1.1;
}

.mwg-fraction-top {
    width: 100%;
    padding-bottom: 0.6mm;
    border-bottom: var(--mwg-border-width) solid #0f172a;
    text-align: center;
}

.mwg-fraction-bottom {
    padding-top: 0.6mm;
    text-align: center;
}

.mwg-fraction-write-line {
    width: 100%;
    border-bottom: var(--mwg-answer-line-width) solid #1f2937;
    min-height: 10mm;
}

.mwg-text-wrap {
    flex: 1;
    min-width: 0;
}

.mwg-text-question {
    font-size: 10pt;
    font-weight: 700;
    line-height: 1.35;
    color: #0f172a;
    word-break: break-word;
}

.mwg-rhythm-sheet {
    display: flex;
    flex-direction: column;
    gap: var(--mwg-row-gap);
}

.mwg-rhythm-row {
    display: grid;
    grid-template-columns: var(--mwg-item-number-width) minmax(0, 1fr);
    gap: 2.2mm;
    align-items: stretch;
    break-inside: avoid;
    page-break-inside: avoid;
}

.mwg-rhythm-track {
    border: var(--mwg-border-width) solid var(--mwg-border-color);
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
}

.mwg-rhythm-cell {
    min-height: var(--mwg-rhythm-cell-min-height);
    border-left: var(--mwg-border-width) solid var(--mwg-border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10.2pt;
    line-height: 1;
}

.mwg-rhythm-cell:first-child {
    border-left: none;
}

.mwg-rhythm-cell--filled {
    font-weight: 700;
    color: #0f172a;
}

.mwg-prevnext-sheet {
    display: flex;
    flex-direction: column;
    gap: var(--mwg-row-gap);
}

.mwg-prevnext-row {
    display: grid;
    grid-template-columns: repeat(var(--mwg-print-cols, 3), minmax(0, 1fr));
    gap: 4mm;
}

.mwg-prevnext-item {
    display: grid;
    grid-template-columns: var(--mwg-item-number-width) minmax(0, 1fr);
    gap: 2mm;
    align-items: stretch;
    break-inside: avoid;
    page-break-inside: avoid;
}

.mwg-prevnext-item-empty {
    visibility: hidden;
}

.mwg-prevnext-track {
    border: var(--mwg-border-width) solid var(--mwg-border-color);
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mwg-prevnext-box {
    min-height: var(--mwg-prevnext-cell-min-height);
    border-left: var(--mwg-border-width) solid var(--mwg-border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10pt;
    line-height: 1;
}

.mwg-prevnext-box:first-child {
    border-left: none;
}

.mwg-prevnext-box--middle,
.mwg-prevnext-box--filled {
    font-weight: 700;
    color: #0f172a;
}
