:root {
    --mp-ink: #2d3436;
    --mp-muted: #636e72;
    --mp-border: #d7e0ea;
    --mp-paper-outline: #2d3436;
    --mp-paper-shadow: #d0d0d0;
    --mp-paper-bg: #fafaf8;
    --mp-paper-warm: #fffaf0;
    --mp-grid-line: #cfdae8;
    --mp-primary: #b94f35;
    --mp-primary-hover: #9f412a;
    --mp-blue: var(--mp-primary);
    --mp-teal: var(--mp-primary);
    --mp-green: #166534;
    --mp-red: #991b1b;
    --mp-yellow: #facc15;
    --mp-accent-yellow: #ffeaa7;
    --mp-accent-pink: #ffd6d6;
    --mp-accent-green: #d4edda;
    --mp-accent-blue: #d6e9ff;
    --mp-bg: var(--mp-paper-bg);
    --mp-surface: #fff;
    --mp-raised: #fff;
    --mp-cell: clamp(42px, 5.7vw, 62px);
    --mp-workspace-height: 480px;
    --mp-page-width: min(1180px, calc(100vw - 28px));
    --mp-radius: 12px;
    --mp-radius-sm: 10px;
    --mp-cutout-shadow: 3px 3px 0 var(--mp-paper-shadow);
    --mp-font-display: "Fredoka", var(--cs-font-display, 'Atkinson Hyperlegible', 'Segoe UI', system-ui, sans-serif);
}

* {
    box-sizing: border-box;
}

html,
body {
    overscroll-behavior-y: none;
}

body {
    margin: 0;
    background: var(--mp-bg);
    color: var(--mp-ink);
    font-family: var(--cs-font-sans, 'Atkinson Hyperlegible', 'Segoe UI', system-ui, sans-serif);
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    min-height: 44px;
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius-sm);
    background: var(--mp-surface);
    color: var(--mp-ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

/* The shared pupil pages' reset (.cla-pupil :where(button, input) { font: inherit }) loads before this
   file and is as strong as a single class: give Maths' buttons back their weight here, before the rules
   that set each control's own size and weight. */
.maths-app :where(button) {
    font-weight: 600;
}

/* No hover lift and no ClassSlate press here (identity 9): every lifted control sinks by its own lift,
   from controls.css (the standard, shared/css/classlings-controls.css). */
button:focus-visible,
a:focus-visible {
    outline: var(--ctl-focus, 4px solid #1e1b3a);
    outline-offset: var(--ctl-focus-gap, 4px);
}

.app-header {
    width: var(--mp-page-width);
    display: grid;
    gap: 10px;
    margin: 14px auto 0;
    padding: 9px 22px 10px;
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius);
    background: var(--mp-surface);
    box-shadow: var(--mp-cutout-shadow);
}

.header-primary {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    min-width: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.header-title {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 12px;
    min-width: 0;
}

.header-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-left: auto;
    min-width: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-left: 0;
    flex: 0 0 auto;
}

.eyebrow {
    display: none;
}

.app-header h1,
.tool-panel h2 {
    margin: 0;
    line-height: 1.05;
}

.app-header h1 {
    font-family: var(--mp-font-display);
    font-size: clamp(1.35rem, 1.65vw, 1.68rem);
    font-weight: 700;
    letter-spacing: 0;
}

.app-header h1 span {
    display: inline-block;
    margin-left: 0.14em;
    color: var(--mp-primary);
    font-weight: 700;
}

.home-link {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius-sm);
    background: var(--mp-surface);
    color: var(--mp-ink);
    font-size: 0.96rem;
    font-weight: 800;
    text-decoration: none;
}

.practice-options-link {
    white-space: nowrap;
}

.maths-practice {
    width: var(--mp-page-width);
    margin: 12px auto 8px;
    display: grid;
    gap: 12px;
}

.maths-practice-hub {
    margin-top: 16px;
}

.maths-practice-hub.has-access-gate,
.access-gate-screen {
    min-height: calc(100svh - 24px);
    align-content: center;
}

.access-gate-screen {
    width: min(1040px, calc(100vw - 28px));
    margin-top: 0;
}

.phone-landscape-lock {
    display: none;
}

.phone-landscape-card {
    width: min(100%, 420px);
    display: grid;
    gap: 10px;
    justify-items: center;
    padding: 22px;
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius);
    background: var(--mp-surface);
    box-shadow: var(--mp-cutout-shadow);
    text-align: center;
}

.phone-landscape-card .eyebrow {
    margin: 0;
    color: var(--mp-primary);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.phone-landscape-card h2 {
    margin: 0;
    font-size: clamp(1.8rem, 8vw, 2.6rem);
    line-height: 1;
}

.phone-landscape-card p:last-child {
    margin: 0;
    max-width: 24rem;
    color: var(--mp-muted);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
}

.entry-loading-panel {
    min-height: 260px;
    align-content: center;
}

.maths-entry-loading-card {
    display: grid;
    grid-template-columns: auto minmax(220px, 1fr);
    align-items: center;
    gap: 18px;
    width: min(760px, 100%);
    padding: clamp(16px, 2.8vw, 24px);
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius-sm);
    background:
        linear-gradient(135deg, rgba(238, 246, 255, 0.84), rgba(255, 248, 229, 0.72)),
        var(--mp-surface);
}

.maths-entry-loading-card .eyebrow {
    display: block;
    margin: 0;
    color: var(--mp-primary);
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.maths-entry-loading-card h2 {
    margin: 0;
    color: var(--mp-ink);
    font-size: clamp(1.55rem, 3vw, 2.35rem);
    line-height: 1;
}

.maths-entry-loading-card p:last-child {
    margin: 0;
    color: var(--mp-muted);
    font-size: 1rem;
    font-weight: 900;
    line-height: 1.25;
}

.practice-option-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 12px;
}

.topic-badge-progress {
    display: grid;
    gap: 7px;
}

.topic-badge {
    --badge-image: none;
    --badge-fallback: #eef2f7;
    width: 34px;
    aspect-ratio: 1;
    display: inline-block;
    border: 2px solid #cfd5d5;
    border-radius: 9px;
    background-color: #fafbfb;
    background-image: var(--badge-image), var(--badge-fallback);
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
    box-shadow: none;
    opacity: 0.62;
}

.topic-badge.is-earned {
    border-color: transparent;
    background-color: transparent;
    background-image: var(--badge-image);
    box-shadow: none;
    opacity: 1;
}

.topic-badge-progress.is-loading .topic-badge-label {
    color: #566466;
}

.topic-badge.is-loading {
    --badge-fallback: linear-gradient(100deg, #eef2f7 0%, #fff2bf 38%, #c7e8e4 62%, #eef2f7 100%);
    border-color: #9db0b0;
    background-color: #eef2f7;
    background-size: 220% 100%;
    opacity: 1;
}

.topic-badge.is-bronze.is-earned {
    --badge-fallback: linear-gradient(135deg, #8d5524, #d89a55 48%, #6b3f1f);
}

.topic-badge.is-silver.is-earned {
    --badge-fallback: linear-gradient(135deg, #7d8791, #f1f5f9 48%, #9aa4b2);
}

.topic-badge.is-gold.is-earned {
    --badge-fallback: linear-gradient(135deg, #b7791f, #facc15 48%, #92400e);
}

.topic-badge.is-platinum.is-earned {
    --badge-fallback: linear-gradient(135deg, #cbd5e1, #ffffff 38%, #9ca3af 72%, #e0f2fe);
}

.topic-badge.is-iridescent.is-earned {
    --badge-fallback: linear-gradient(135deg, #34d399, #60a5fa 28%, #c084fc 54%, #f472b6 76%, #fde68a);
}

.topic-badge-label {
    color: var(--mp-muted);
    font-size: 0.88rem;
    font-weight: 800;
    line-height: 1.15;
}

.practice-option-stage,
.practice-option-status {
    width: max-content;
    max-width: 100%;
    padding: 4px 8px;
    border: 2px solid var(--mp-paper-outline);
    border-radius: 999px;
    background: var(--mp-paper-warm);
    font-size: 0.76rem;
    font-weight: 800;
    line-height: 1;
}

.practice-option-status {
    align-self: end;
    margin-top: auto;
    background: var(--mp-accent-yellow);
}

.practice-option-sync {
    width: max-content;
    max-width: 100%;
    padding: 4px 8px;
    border: 2px solid var(--mp-paper-outline);
    border-radius: 999px;
    background: #fffaf0;
    color: var(--mp-primary);
    font-size: 0.76rem;
    font-weight: 900;
    line-height: 1;
}

.maths-sync-notice {
    position: fixed;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    z-index: 30;
    max-width: calc(100vw - 24px);
    margin: 0;
    padding: 6px 10px;
    line-height: 1.3;
    pointer-events: none;
}

.teacher-action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 12px;
}

.teacher-action-card {
    min-height: 170px;
    display: grid;
    align-content: start;
    gap: 10px;
    padding: 16px;
    text-align: left;
}

.teacher-action-card strong {
    font-size: 1.35rem;
    line-height: 1.05;
}

.access-gate-panel {
    width: min(100%, 820px);
    margin-inline: auto;
    display: grid;
    overflow: hidden;
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius);
    background: var(--mp-surface);
    box-shadow: var(--mp-cutout-shadow);
}

.auth-prompt-panel {
    background: var(--mp-surface);
}

.access-gate-brand-row {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    padding: clamp(16px, 2.2vw, 22px) clamp(18px, 3vw, 28px);
    border-bottom: 1px solid rgba(45, 52, 54, 0.12);
    background: #fffdf7;
}

.access-gate-app-name {
    margin: 0;
    color: var(--mp-ink);
    font-family: var(--mp-font-display);
    font-size: clamp(1.35rem, 2.7vw, 1.9rem);
    font-weight: 800;
    line-height: 1;
}

.access-gate-app-name strong {
    color: var(--mp-primary);
}

.access-gate-main {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(190px, 240px);
    gap: clamp(18px, 4vw, 42px);
    align-items: center;
    padding: clamp(22px, 3.8vw, 38px) clamp(18px, 3vw, 28px);
    background:
        linear-gradient(135deg, rgba(255, 250, 240, 0.9), rgba(255, 255, 255, 0.96) 52%, rgba(238, 246, 255, 0.7)),
        var(--mp-surface);
}

.access-gate-copy {
    display: grid;
    gap: 8px;
    max-width: 30rem;
    padding-left: 14px;
    border-left: 5px solid rgba(185, 79, 53, 0.88);
}

.access-gate-copy .eyebrow {
    display: block;
    margin: 0;
    color: var(--mp-primary);
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.access-gate-copy h2 {
    margin: 0;
    color: var(--mp-ink);
    font-size: clamp(1.75rem, 3.6vw, 2.65rem);
    line-height: 0.98;
}

.auth-prompt-actions,
.access-gate-actions {
    display: grid;
    gap: 10px;
    align-content: center;
    padding: 12px;
    border-radius: var(--mp-radius);
    background: rgba(255, 253, 247, 0.78);
}

.auth-prompt-action,
.access-gate-action {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 10px 18px;
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius-sm);
    font-size: 1rem;
    font-weight: 900;
    line-height: 1;
    text-decoration: none;
}

.auth-prompt-action.secondary-action,
.auth-prompt-action.secondary-action:visited,
.access-gate-action.secondary-action,
.access-gate-action.secondary-action:visited {
    color: var(--mp-ink);
}

.auth-prompt-action.secondary-action:hover,
.access-gate-action.secondary-action:hover {
    color: var(--mp-ink);
    background: var(--mp-paper-warm);
}

.access-gate-pupil-route {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: center;
    padding: 15px clamp(18px, 3vw, 28px);
    border-top: 1px solid rgba(45, 52, 54, 0.12);
    background: #fafaf8;
    color: var(--mp-muted);
    font-size: 0.96rem;
    font-weight: 900;
}

.access-gate-pupil-link,
.access-gate-pupil-link:visited {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 5px 10px;
    border: 2px solid var(--mp-paper-outline);
    border-radius: 999px;
    background: var(--mp-surface);
    color: var(--mp-ink);
    font-weight: 900;
    line-height: 1;
    text-decoration: none;
}

.access-gate-pupil-link:hover {
    color: var(--mp-primary);
    background: var(--mp-paper-warm);
}

.access-gate-dashboard-link,
.access-gate-dashboard-link:visited {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 8px 14px;
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius-sm);
    background: var(--mp-surface);
    color: var(--mp-ink);
    font-size: 0.9rem;
    font-weight: 900;
    line-height: 1;
    text-decoration: none;
}

.access-gate-dashboard-link:hover {
    color: var(--mp-ink);
    background: var(--mp-paper-warm);
}

.teacher-action-detail {
    margin: 0;
    color: var(--mp-muted);
    font-size: 0.94rem;
    font-weight: 700;
    line-height: 1.35;
}

.level-progress-pill {
    color: var(--mp-ink);
    font-size: 0.96rem;
    font-weight: 800;
}

@media (max-width: 760px) {
    .maths-entry-loading-card {
        grid-template-columns: 1fr;
    }
}

.setup-panel {
    display: grid;
    gap: 8px;
    position: relative;
    padding-top: 8px;
    border-top: 1px solid rgba(83, 97, 115, 0.18);
}

.header-controls > .setup-panel {
    flex: 0 1 auto;
    padding-top: 0;
    border-top: 0;
}

.setup-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 0;
}

.setup-context {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}

.topic-title {
    margin: 0;
    color: var(--mp-muted);
    font-size: 0.84rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}

.level-pill,
.level-progress-pill {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    border: 2px solid #cfd8dd;
    border-radius: var(--mp-radius-sm);
    background: #f8fbfb;
    box-shadow: none;
    white-space: nowrap;
}

.level-pill {
    padding: 0 11px;
    color: var(--mp-ink);
    font-size: 0.96rem;
    font-weight: 800;
}

.level-progress-pill {
    padding: 0 11px;
    color: var(--mp-ink);
}

.level-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    margin-left: 4px;
    padding: 4px 12px;
    background: var(--mp-surface);
    font-size: 0.96rem;
    text-align: left;
    white-space: nowrap;
    color: var(--mp-primary);
    font-weight: 800;
}

.new-question-action {
    min-height: 44px;
    margin-left: clamp(2px, 1.4vw, 16px);
    padding: 0 12px;
    white-space: nowrap;
}

.level-panel {
    display: grid;
    gap: 8px;
    position: static;
    z-index: 20;
    padding: 10px;
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius);
    background: var(--mp-surface);
    box-shadow: var(--mp-cutout-shadow);
}

.level-panel-title {
    margin: 0;
    color: var(--mp-muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.level-list {
    display: grid;
    grid-template-columns: repeat(5, minmax(120px, 1fr));
    gap: 8px;
}

.level-button {
    display: grid;
    align-content: center;
    justify-items: start;
    min-height: 56px;
    padding: 8px 10px;
    text-align: left;
}

.level-button span {
    color: var(--mp-muted);
    font-size: 0.8rem;
    font-weight: 600;
}

.level-button .level-status {
    margin-top: 4px;
    color: var(--mp-primary);
    font-size: 0.76rem;
    font-weight: 800;
}

.level-button.is-selected {
    background: var(--mp-accent-yellow);
}

.level-button.is-mastered .level-status {
    color: var(--mp-green);
}

.level-button.is-locked {
    background: #f3f4f6;
    color: rgba(45, 52, 54, 0.62);
    box-shadow: none;
    cursor: not-allowed;
}

.level-button.is-locked span,
.level-button.is-locked .level-status {
    color: rgba(99, 110, 114, 0.72);
}

.primary-action {
    border-color: var(--mp-paper-outline);
    background: var(--mp-primary);
    color: #fff;
}

.primary-action:hover:not(:disabled) {
    background: var(--mp-primary-hover);
}

.primary-action.is-ready-action {
    position: relative;
    isolation: isolate;
    font-weight: 800;
}

.primary-action.is-ready-action::after {
    position: absolute;
    z-index: -1;
    inset: -9px;
    border: 3px solid rgba(250, 204, 21, 0.48);
    border-radius: calc(var(--mp-radius-sm) + 9px);
    content: "";
    pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
    .primary-action.is-ready-action {
    }

    .primary-action.is-ready-action::after {
    }
}

.secondary-action {
    background: var(--mp-surface);
    color: var(--mp-ink);
}

.secondary-action:hover:not(:disabled) {
    background: var(--mp-paper-warm);
}

.work-area {
    display: grid;
    gap: 8px;
}

.question-panel {
    display: flex;
    align-items: center;
    justify-self: center;
    max-width: min(100%, 820px);
    padding: 0 2px;
    border: 0;
    background: transparent;
}

.drag-equation {
    --equation-gap: clamp(8px, 1.6vw, 16px);
    --equation-inner-gap: clamp(4px, 0.7vw, 8px);
    --drag-token-size: clamp(44px, 5.2vw, 66px);
    --drag-token-font-size: clamp(1.7rem, 4vw, 2.8rem);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: nowrap;
    gap: var(--equation-gap);
    max-width: 100%;
    width: 100%;
}

.drag-equation.is-long-equation {
    --equation-gap: clamp(4px, 0.75vw, 8px);
    --equation-inner-gap: clamp(2px, 0.45vw, 5px);
    --drag-token-size: clamp(44px, 4.2vw, 52px);
    --drag-token-font-size: clamp(1.3rem, 3.1vw, 2.25rem);
}

.drag-number {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    gap: var(--equation-inner-gap);
}

.drag-token,
.drag-token-ghost {
    display: inline-grid;
    place-items: center;
    width: var(--drag-token-size, clamp(44px, 5.2vw, 66px));
    min-width: var(--drag-token-size, clamp(44px, 5.2vw, 66px));
    height: var(--drag-token-size, clamp(44px, 5.2vw, 66px));
    min-height: var(--drag-token-size, clamp(44px, 5.2vw, 66px));
    padding: 0;
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius-sm);
    background: var(--mp-surface);
    color: var(--mp-ink);
    font-size: var(--drag-token-font-size, clamp(1.7rem, 4vw, 2.8rem));
    font-weight: 800;
    line-height: 1;
    user-select: none;
    touch-action: none;
}

.drag-token {
    cursor: grab;
}

.drag-token:hover:not([aria-disabled="true"]) {
    background: var(--mp-paper-warm);
}

.drag-token:active:not([aria-disabled="true"]) {
    cursor: grabbing;
}

.drag-token.is-used {
    background: var(--mp-paper-warm);
    color: rgba(45, 52, 54, 0.56);
    box-shadow: none;
    cursor: default;
}

.drag-token.is-pending {
    background: var(--mp-accent-yellow);
    box-shadow: inset 0 0 0 3px rgba(185, 79, 53, 0.32), var(--mp-cutout-shadow);
}

.solving-strip {
    display: grid;
    justify-items: center;
    /* 6 px, not 8: the answer row is 48 px, not 46, and the grid below keeps the room it had. */
    gap: 6px;
}

.column-sum {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--mp-ink);
    font-size: clamp(1.25rem, 2.8vw, 2rem);
    font-weight: 800;
    line-height: 1;
}

.column-sum-terms,
.column-sum-equals,
.column-sum-complete,
.column-sum-prep {
    display: inline-block;
}

.column-sum-prep {
    padding: 8px 12px;
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius-sm);
    background: rgba(191, 219, 254, 0.74);
    color: #1e3a8a;
    font-size: clamp(0.88rem, 1.65vw, 1rem);
    font-weight: 900;
    line-height: 1;
}

.solve-input {
    width: clamp(64px, 8vw, 92px);
    min-height: clamp(44px, 5vw, 54px);
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius-sm);
    background: var(--mp-surface);
    color: var(--mp-ink);
    font: inherit;
    font-weight: 800;
    text-align: center;
}

.solve-input:disabled {
    background: var(--mp-accent-green);
    color: var(--mp-green);
    opacity: 1;
}

.solve-inline-check {
    min-height: clamp(44px, 5vw, 54px);
    padding: 0 16px;
    border-radius: var(--mp-radius-sm);
    font-size: clamp(0.9rem, 1.8vw, 1.05rem);
    white-space: nowrap;
}

.result-tray {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.result-tray .drag-token {
    background: var(--mp-paper-warm);
}

.result-tray .drag-token.is-answer-token,
.result-tray .drag-token.is-final-carry-token {
    background: rgba(187, 247, 208, 0.78);
    color: var(--mp-green);
    box-shadow: inset 0 0 0 2px rgba(22, 163, 74, 0.24);
}

.result-tray .drag-token.is-carry-token {
    background: rgba(252, 211, 77, 0.62);
    color: #713f12;
    box-shadow: inset 0 0 0 2px rgba(161, 98, 7, 0.3);
}

.result-tray .drag-token.is-exchange-source-token,
.result-tray .drag-token.is-exchange-through-token,
.result-tray .drag-token.is-exchange-active-token {
    --drag-token-size: clamp(34px, 4vw, 46px);
    --drag-token-font-size: clamp(1.12rem, 2.45vw, 1.55rem);
    background: rgba(191, 219, 254, 0.78);
    color: #1e3a8a;
    box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.26);
}

.result-tray .drag-token.is-answer-token:hover:not([aria-disabled="true"]),
.result-tray .drag-token.is-final-carry-token:hover:not([aria-disabled="true"]) {
    background: rgba(187, 247, 208, 0.88);
}

.result-tray .drag-token.is-carry-token:hover:not([aria-disabled="true"]) {
    background: rgba(252, 211, 77, 0.74);
}

.result-tray .drag-token.is-exchange-source-token:hover:not([aria-disabled="true"]),
.result-tray .drag-token.is-exchange-through-token:hover:not([aria-disabled="true"]),
.result-tray .drag-token.is-exchange-active-token:hover:not([aria-disabled="true"]) {
    background: rgba(191, 219, 254, 0.9);
}

.result-tray .drag-token.is-used {
    display: none;
}

.drag-token-ghost {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 10000;
    pointer-events: none;
    opacity: 0.92;
    background: var(--mp-accent-yellow);
    box-shadow: var(--mp-cutout-shadow);
    will-change: transform;
}

.drag-token-ghost.is-answer,
.drag-token-ghost.is-final-carry {
    background: rgba(187, 247, 208, 0.78);
    color: var(--mp-green);
    box-shadow: inset 0 0 0 2px rgba(22, 163, 74, 0.24), var(--mp-cutout-shadow);
}

.drag-token-ghost.is-carry {
    background: rgba(252, 211, 77, 0.62);
    color: #713f12;
    box-shadow: inset 0 0 0 2px rgba(161, 98, 7, 0.3), var(--mp-cutout-shadow);
}

.drag-token-ghost.is-exchange-source,
.drag-token-ghost.is-exchange-through,
.drag-token-ghost.is-exchange-active {
    background: rgba(191, 219, 254, 0.78);
    color: #1e3a8a;
    box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.26), var(--mp-cutout-shadow);
}

.workspace {
    display: grid;
    grid-template-columns: minmax(420px, 1fr) minmax(300px, 0.42fr);
    align-items: start;
    min-height: var(--mp-workspace-height);
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius);
    background: var(--mp-surface);
    box-shadow: var(--mp-cutout-shadow);
    overflow: hidden;
}

.grid-panel {
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 12px;
    position: relative;
    width: 100%;
    min-height: var(--mp-workspace-height);
    min-width: 0;
    padding: 28px;
    border-right: 2px solid var(--mp-border);
    background: var(--mp-surface);
}

.grid-panel.has-feedback {
    grid-template-rows: auto auto auto;
    align-content: center;
}

.workspace-feedback {
    position: static;
    width: 100%;
    display: grid;
    justify-items: center;
    pointer-events: none;
    z-index: 5;
}

.workspace-feedback .feedback {
    width: min(100%, 720px);
    box-shadow: var(--mp-cutout-shadow);
}

.workspace-feedback .setup-success {
    /* fit-content, not max-content: a long line wraps on a phone instead of widening the panel. */
    width: fit-content;
    max-width: 100%;
}

.workspace-feedback.is-visually-hidden {
    right: auto;
    bottom: auto;
    left: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.workspace.is-setup .workspace-feedback {
    min-height: var(--mp-setup-grid-bottom-gap);
    align-content: center;
    margin: 0;
}

.workspace.is-setup .workspace-feedback .feedback {
    margin: 0;
    padding: 8px 12px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.badge-award-celebration {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 8;
    display: grid;
    justify-items: center;
    gap: 12px;
    width: min(430px, calc(100% - 36px));
    padding: 24px;
    border: 4px solid var(--mp-paper-outline);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 8px 8px 0 rgba(45, 52, 54, 0.18);
    text-align: center;
    pointer-events: auto;
    transform: translate(-50%, -50%);
}

.badge-award-celebration.is-topic-mastered {
    width: min(500px, calc(100% - 36px));
    padding: 26px;
    border: 5px solid transparent;
    background:
        linear-gradient(#fff, #fff) padding-box,
        linear-gradient(135deg, #f8d7ff, #d9fbff, #fff4c8, #e5dcff) border-box;
    box-shadow:
        inset 0 0 0 4px var(--mp-paper-outline),
        inset 0 0 0 9px rgba(184, 234, 255, 0.5),
        9px 9px 0 rgba(45, 52, 54, 0.18);
}

.badge-award-icon {
    width: 142px;
    height: auto;
    display: block;
    border: 0;
    border-radius: 20px;
    background-color: transparent;
    filter: drop-shadow(3px 4px 0 rgba(45, 52, 54, 0.16));
}

.badge-award-copy {
    display: grid;
    justify-items: center;
    gap: 8px;
    color: var(--mp-muted);
    font-size: clamp(1rem, 2.1vw, 1.22rem);
    font-weight: 800;
    line-height: 1.16;
}

.badge-award-kicker {
    color: var(--mp-primary);
    font-family: var(--mp-font-display);
    font-size: clamp(0.88rem, 1.5vw, 1rem);
    font-weight: 800;
    letter-spacing: 0.08em;
    line-height: 1;
    text-transform: uppercase;
}

.badge-award-copy strong {
    color: var(--mp-ink);
    font-family: var(--mp-font-display);
    font-size: clamp(2rem, 4.8vw, 3.45rem);
    line-height: 0.95;
}

.badge-award-strip {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin: 2px 0 0;
}

.badge-award-mini {
    width: 36px;
    border: 0;
    border-radius: 10px;
    background-color: transparent;
    filter: drop-shadow(2px 3px 0 rgba(45, 52, 54, 0.14));
    opacity: 1;
    transform: none;
}

.badge-award-actions {
    display: flex;
    justify-content: center;
}

.badge-award-action {
    min-height: 46px;
    padding: 9px 18px;
    border: 3px solid var(--mp-paper-outline);
    border-radius: 999px;
    background: var(--mp-accent-yellow);
    color: var(--mp-ink);
    font-family: var(--mp-font-display);
    font-size: clamp(1.08rem, 2.1vw, 1.3rem);
    font-weight: 700;
}

@media (prefers-reduced-motion: no-preference) {
    .badge-award-celebration {
    }

    .badge-award-icon {
    }

    .badge-award-celebration.is-topic-mastered .badge-award-icon {
    }

    .badge-award-mini {
    }

    .badge-award-mini:nth-child(1) {
    }

    .badge-award-mini:nth-child(2) {
    }

    .badge-award-mini:nth-child(3) {
    }

    .badge-award-mini:nth-child(4) {
    }

    .badge-award-mini:nth-child(5) {
    }
}

@media (max-width: 720px) {
    .badge-award-celebration {
        gap: 10px;
        padding: 18px;
    }

    .badge-award-icon {
        width: 118px;
    }

    .badge-award-copy strong {
        font-size: clamp(1.75rem, 8vw, 2.45rem);
    }

    .badge-award-mini {
        width: 31px;
    }
}

.student-grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-columns), var(--mp-cell));
    grid-template-rows: repeat(var(--grid-rows), var(--mp-cell));
    position: relative;
    width: calc(var(--grid-columns) * var(--mp-cell));
    height: calc(var(--grid-rows) * var(--mp-cell));
    background: var(--mp-surface);
    overflow: hidden;
    touch-action: none;
}

.student-grid::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    background-image:
        linear-gradient(to right, var(--mp-grid-line) 1px, transparent 1px),
        linear-gradient(to bottom, var(--mp-grid-line) 1px, transparent 1px);
    background-size: var(--mp-cell) var(--mp-cell);
    background-position: 0 0;
}

.grid-square {
    --mp-cell-bg: transparent;
    --mp-cell-hover-bg: rgba(225, 112, 85, 0.06);
    --mp-cell-guide-ring-width: 0px;
    --mp-cell-guide-ring-color: transparent;
    --mp-cell-selected-ring-width: 0px;
    --mp-cell-selected-ring-color: transparent;
    --mp-cell-origin-ring-width: 0px;
    --mp-cell-origin-ring-color: transparent;
    --mp-cell-shadow:
        inset 0 0 0 var(--mp-cell-origin-ring-width) var(--mp-cell-origin-ring-color),
        inset 0 0 0 var(--mp-cell-selected-ring-width) var(--mp-cell-selected-ring-color),
        inset 0 0 0 var(--mp-cell-guide-ring-width) var(--mp-cell-guide-ring-color);
    display: grid;
    place-items: center;
    position: relative;
    z-index: 2;
    width: var(--mp-cell);
    height: var(--mp-cell);
    min-height: var(--mp-cell);
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--mp-cell-bg);
    box-shadow: none;
    color: var(--mp-ink);
    font-size: min(clamp(1.5rem, 4vw, 2.25rem), calc(var(--mp-cell) * .70));
    font-weight: 620;
    line-height: 1;
    transform: none;
}

/* All cell frames share the same clearance from the grid and answer lines. */
.grid-square::after {
    content: "";
    position: absolute;
    inset: 3px;
    box-shadow: var(--mp-cell-shadow);
    pointer-events: none;
}

.grid-square-value {
    position: relative;
    z-index: 1;
    display: inline-block;
}

.grid-square:hover {
    background: var(--mp-cell-hover-bg);
    box-shadow: none;
    transform: none;
}

button.grid-square:hover:not(:disabled),
button.grid-square:active:not(:disabled),
.grid-square:active {
    box-shadow: none;
    transform: none;
}

.student-grid.is-line-placement .grid-square {
    cursor: crosshair;
}

.student-grid.is-line-placement {
    touch-action: none;
}

.student-grid.is-setup-complete {
}

.student-grid.is-solving.is-setup-complete {
}

.student-grid.is-line-placement .grid-square:hover {
    background: var(--mp-cell-bg);
}

.grid-square.is-entry-guide {
    --mp-cell-bg: rgba(20, 184, 166, 0.045);
    --mp-cell-hover-bg: rgba(20, 184, 166, 0.11);
    --mp-cell-guide-ring-width: 0px;
    --mp-cell-guide-ring-color: rgba(20, 184, 166, 0.12);
}

.grid-square.is-operator-guide {
    --mp-cell-bg: rgba(214, 233, 255, 0.45);
    --mp-cell-hover-bg: rgba(214, 233, 255, 0.62);
    --mp-cell-guide-ring-width: 0px;
    --mp-cell-guide-ring-color: rgba(145, 174, 204, 0.2);
}

.grid-square.is-ruler-line-guide {
    --mp-cell-bg: rgba(96, 165, 250, 0.075);
    --mp-cell-hover-bg: rgba(96, 165, 250, 0.12);
    --mp-cell-guide-ring-width: 0px;
}

.grid-square.is-active-column {
    --mp-cell-bg: rgba(255, 214, 102, 0.34);
    --mp-cell-hover-bg: rgba(255, 214, 102, 0.46);
    --mp-cell-guide-ring-width: 0px;
    --mp-cell-guide-ring-color: rgba(185, 79, 53, 0.34);
}

.grid-square.is-active-column.has-value {
    --mp-cell-bg: rgba(255, 214, 102, 0.54);
    --mp-cell-hover-bg: rgba(255, 214, 102, 0.66);
    --mp-cell-guide-ring-width: 2px;
}

.grid-square.is-answer-target,
.grid-square.is-final-carry-target {
    --mp-cell-bg: rgba(220, 252, 231, 0.4);
    --mp-cell-hover-bg: rgba(220, 252, 231, 0.6);
    --mp-cell-guide-ring-width: 0px;
    --mp-cell-guide-ring-color: rgba(22, 163, 74, 0.24);
}

.grid-square.is-carry-target {
    --mp-cell-bg: rgba(252, 211, 77, 0.42);
    --mp-cell-hover-bg: rgba(252, 211, 77, 0.54);
    --mp-cell-guide-ring-width: 2px;
    --mp-cell-guide-ring-color: rgba(161, 98, 7, 0.36);
}

.grid-square.is-exchange-source-target,
.grid-square.is-exchange-through-target,
.grid-square.is-exchange-active-target {
    --mp-cell-bg: rgba(191, 219, 254, 0.42);
    --mp-cell-hover-bg: rgba(191, 219, 254, 0.56);
    --mp-cell-guide-ring-width: 2px;
    --mp-cell-guide-ring-color: rgba(37, 99, 235, 0.32);
}

.grid-square.is-active-column.is-answer-target,
.grid-square.is-active-column.is-final-carry-target {
    --mp-cell-bg: rgba(187, 247, 208, 0.66);
    --mp-cell-hover-bg: rgba(187, 247, 208, 0.78);
    --mp-cell-guide-ring-width: 2px;
    --mp-cell-guide-ring-color: rgba(185, 79, 53, 0.34);
}

.grid-square.is-active-column.is-carry-target {
    --mp-cell-bg: rgba(252, 211, 77, 0.56);
    --mp-cell-hover-bg: rgba(252, 211, 77, 0.68);
    --mp-cell-guide-ring-color: rgba(161, 98, 7, 0.44);
}

.grid-square.is-active-column.is-exchange-source-target,
.grid-square.is-active-column.is-exchange-through-target,
.grid-square.is-active-column.is-exchange-active-target {
    --mp-cell-bg: rgba(191, 219, 254, 0.58);
    --mp-cell-hover-bg: rgba(191, 219, 254, 0.72);
}

.student-grid.is-preparing-exchange .grid-square.is-exchange-source-target,
.student-grid.is-preparing-exchange .grid-square.is-exchange-through-target,
.student-grid.is-preparing-exchange .grid-square.is-exchange-active-target {
    --mp-cell-bg: rgba(219, 234, 254, 0.68);
    --mp-cell-hover-bg: rgba(219, 234, 254, 0.84);
    --mp-cell-guide-ring-width: 3px;
    --mp-cell-guide-ring-color: rgba(37, 99, 235, 0.44);
}

.student-grid.is-preparing-exchange .grid-square.is-exchange-source-target.is-selected,
.student-grid.is-preparing-exchange .grid-square.is-exchange-through-target.is-selected,
.student-grid.is-preparing-exchange .grid-square.is-exchange-active-target.is-selected {
    --mp-cell-bg: rgba(191, 219, 254, 0.9);
    --mp-cell-guide-ring-color: rgba(30, 64, 175, 0.68);
}

.student-grid.is-preparing-exchange .grid-square.is-exchange-corner-target {
    --mp-cell-bg: transparent;
    --mp-cell-hover-bg: transparent;
    --mp-cell-guide-ring-width: 0px;
}

.student-grid.is-preparing-exchange .grid-square.is-exchange-corner-target::before {
    content: "";
    position: absolute;
    left: 7%;
    top: 7%;
    width: 46%;
    height: 42%;
    border-radius: 0 0 8px 0;
    background: rgba(219, 234, 254, 0.86);
    box-shadow: inset 0 0 0 3px rgba(37, 99, 235, 0.38);
    pointer-events: none;
}

.student-grid.is-preparing-exchange .grid-square.is-exchange-corner-target.is-selected {
    --mp-cell-bg: transparent;
    --mp-cell-selected-ring-width: 0px;
}

.student-grid.is-preparing-exchange .grid-square.is-exchange-corner-target.is-selected::before {
    background: rgba(191, 219, 254, 0.92);
    box-shadow: inset 0 0 0 3px rgba(30, 64, 175, 0.66);
}

.grid-square.is-exchange-mark {
    --mp-cell-bg: transparent;
    --mp-cell-hover-bg: rgba(191, 219, 254, 0.2);
    align-items: end;
    padding-bottom: 10%;
    color: #1e3a8a;
    font-size: min(clamp(1.05rem, 2.55vw, 1.45rem), calc(var(--mp-cell) * .40));
    font-weight: 760;
}

.grid-square.is-exchange-mark.is-exchange-active-symbol {
    font-size: min(clamp(1rem, 2.35vw, 1.36rem), calc(var(--mp-cell) * .38));
}

.grid-square.is-exchange-mark.is-exchange-stack {
    align-items: center;
    padding-bottom: 0;
}

.grid-square-exchange-stack {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.06em;
    line-height: 0.82;
    transform: translateY(-0.03em);
}

.grid-square-exchange-stack-new {
    font-size: 0.92em;
    font-weight: 820;
    transform: translateX(-0.58em);
}

.grid-square-exchange-stack-base {
    font-size: 1em;
    font-weight: 760;
}

.grid-square.is-exchange-rewritten .grid-square-value::after {
    content: "";
    position: absolute;
    left: -0.14em;
    right: -0.14em;
    top: 50%;
    height: 3px;
    border-radius: 999px;
    background: currentColor;
    transform: rotate(42deg);
    transform-origin: center;
}

.student-grid.is-line-placement .grid-square.is-ruler-line-guide {
    --mp-cell-bg: rgba(96, 165, 250, 0.13);
    --mp-cell-hover-bg: rgba(96, 165, 250, 0.16);
}

.student-grid.is-ruler-snap .grid-square.is-ruler-line-guide {
    --mp-cell-bg: rgba(96, 165, 250, 0.22);
    --mp-cell-hover-bg: rgba(96, 165, 250, 0.24);
}

.workspace.is-setup .student-grid {
    --mp-grid-line: #aebfd2;
    background: #fbfdff;
    box-shadow: inset 0 0 0 2px rgba(83, 97, 115, 0.16);
}

.workspace.is-setup .student-grid::before {
    background-image:
        linear-gradient(to right, var(--mp-grid-line) 1.5px, transparent 1.5px),
        linear-gradient(to bottom, var(--mp-grid-line) 1.5px, transparent 1.5px);
}

.workspace.is-setup .grid-square.is-entry-guide {
    --mp-cell-bg: rgba(20, 184, 166, 0.12);
    --mp-cell-hover-bg: rgba(20, 184, 166, 0.2);
}

.workspace.is-setup .grid-square.is-operator-guide {
    --mp-cell-bg: rgba(214, 233, 255, 0.72);
    --mp-cell-hover-bg: rgba(214, 233, 255, 0.86);
}

.workspace.is-setup .grid-square.is-ruler-line-guide {
    --mp-cell-bg: rgba(96, 165, 250, 0.14);
    --mp-cell-hover-bg: rgba(96, 165, 250, 0.2);
}

.guide-marker {
    color: rgba(83, 97, 115, 0.35);
    font-size: min(clamp(1.25rem, 3vw, 1.8rem), calc(var(--mp-cell) * .55));
    font-weight: 700;
}

.grid-square.is-selected {
    z-index: 4;
    --mp-cell-selected-ring-width: 3px;
    --mp-cell-selected-ring-color: rgba(45, 52, 54, 0.72);
}

.is-token-dragging .grid-square.is-selected {
    --mp-cell-selected-ring-width: 0px;
    --mp-cell-selected-ring-color: transparent;
}

.grid-square.is-drag-origin {
    --mp-cell-origin-ring-width: 3px;
    --mp-cell-origin-ring-color: rgba(83, 97, 115, 0.42);
    background: transparent;
    color: transparent;
}

.grid-square.is-correct {
    --mp-cell-bg: rgba(220, 252, 231, 0.78);
    --mp-cell-hover-bg: rgba(220, 252, 231, 0.78);
    --mp-cell-guide-ring-width: 0px;
    --mp-cell-selected-ring-width: 0px;
}

.grid-square.is-incorrect {
    --mp-cell-bg: rgba(254, 226, 226, 0.84);
    --mp-cell-hover-bg: rgba(254, 226, 226, 0.84);
    --mp-cell-guide-ring-width: 0px;
    --mp-cell-selected-ring-width: 0px;
}

.student-grid.is-solving .grid-square.is-correct {
    --mp-cell-bg: rgba(220, 252, 231, 0.34);
    --mp-cell-hover-bg: rgba(220, 252, 231, 0.38);
}

.grid-square.is-solving-symbol {
    font-weight: 800;
}

.grid-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 4;
    pointer-events: none;
}

.tool-panel {
    display: grid;
    align-content: start;
    gap: 12px;
    width: 100%;
    max-height: var(--mp-workspace-height);
    overflow-y: auto;
    padding: 20px;
    background: var(--mp-surface);
}

.tool-group {
    display: grid;
    gap: 5px;
}

.tool-group h2 {
    font-size: 1.18rem;
}

.tool-group p {
    margin: 0;
    color: var(--mp-muted);
    font-size: 0.96rem;
    line-height: 1.45;
}

.keypad {
    display: grid;
    grid-template-columns: repeat(3, minmax(64px, 1fr));
    gap: 8px;
}

.solving-keypad button {
    font-size: 1.1rem;
}

.keypad button {
    min-height: 54px;
    background: var(--mp-surface);
    font-size: 1.25rem;
}

.keypad.is-disabled {
    opacity: 0.48;
}

.tool-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.tool-actions > :only-child {
    grid-column: 1 / -1;
}

.exchange-decision {
    display: grid;
    gap: 10px;
}

.exchange-decision p {
    margin: 0;
    color: var(--mp-ink);
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.25;
}

.exchange-decision-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.edit-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
}

.edit-actions .secondary-action {
    min-height: 44px;
    border-color: rgba(45, 52, 54, 0.48);
    background: rgba(255, 255, 255, 0.78);
    color: var(--mp-muted);
    font-size: 0.9rem;
}

.clear-square-action {
    grid-column: 1 / -1;
}

.tool-actions .primary-action {
    min-height: 50px;
    font-size: 1.02rem;
}

.completion-progress {
    display: grid;
    gap: 8px;
    width: 100%;
    margin-top: 4px;
}

.completion-progress-label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    color: var(--mp-muted);
    font-size: 0.9rem;
    font-weight: 700;
}

.completion-progress-label strong {
    color: var(--mp-ink);
}

.completion-progress-track {
    display: block;
    width: 100%;
    height: 16px;
    overflow: hidden;
    border: 2px solid var(--mp-paper-outline);
    border-radius: 999px;
    background: rgba(207, 218, 232, 0.48);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.72);
}

.completion-progress-fill {
    display: block;
    width: var(--progress-to);
    height: 100%;
    border-radius: inherit;
    background: #42c8a5;
    box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, 0.32),
        inset 0 -2px 0 rgba(45, 52, 54, 0.12);
}

.restart-actions {
    display: grid;
    justify-items: center;
}

.restart-action {
    min-height: 44px;
    width: max-content;
    min-width: 0;
    padding: 0 10px;
    border-color: transparent;
    background: transparent;
    color: var(--mp-muted);
    font-size: 0.88rem;
    box-shadow: none;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.36;
    box-shadow: none;
}

.edit-actions button:disabled,
.restart-action:disabled {
    border-color: rgba(45, 52, 54, 0.18);
    background: transparent;
}

.feedback {
    margin: 0;
    padding: 12px;
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius-sm);
    line-height: 1.45;
    font-weight: 700;
}

.feedback.success {
    background: var(--mp-accent-green);
    color: var(--mp-green);
}

.setup-success {
    display: grid;
    gap: 2px;
    padding: 8px 12px;
}

.setup-success-copy {
    display: grid;
    gap: 2px;
}

.feedback.error {
    background: var(--mp-accent-pink);
    color: var(--mp-red);
}

.feedback.info {
    background: var(--mp-accent-blue);
    color: #075985;
}

@media (min-width: 901px) and (min-height: 720px) {
    :root {
        --mp-cell: clamp(66px, 9.2vh, 78px);
        --mp-workspace-height: min(620px, calc(100dvh - 204px));
    }
}

@media (min-width: 901px) and (orientation: landscape) {
    :root {
        --mp-cell: clamp(70px, min(10.2dvh, 5.4vw), 102px);
        --mp-workspace-height: clamp(600px, calc(100dvh - 96px), 1040px);
    }

    body:has(.workspace) {
        overflow: hidden;
    }

    .workspace {
        height: var(--mp-workspace-height);
    }

    .workspace.is-solving {
        grid-template-columns: minmax(520px, 1fr) minmax(340px, 0.44fr);
    }

    .workspace .grid-panel,
    .workspace .tool-panel {
        height: var(--mp-workspace-height);
        min-height: 0;
    }

    .tool-panel.is-setup {
        overflow: hidden;
    }

    .tool-panel.is-solving {
        grid-template-columns: 1fr;
        align-content: center;
        gap: 10px;
        overflow: hidden;
        padding: 18px 18px 14px;
    }

    .tool-panel.is-solving .tool-group {
        grid-column: 1;
    }

    .tool-panel.is-solving .tool-group h2 {
        font-size: 1.08rem;
    }

    .tool-panel.is-solving .tool-group p {
        font-size: 0.88rem;
        line-height: 1.24;
    }

    .tool-panel.is-solving .keypad {
        grid-column: 1;
        grid-template-columns: repeat(3, minmax(52px, 1fr));
        gap: 7px;
    }

    .tool-panel.is-solving .keypad button {
        min-height: 44px;
    }

    .tool-panel.is-solving .edit-actions,
    .tool-panel.is-solving .tool-actions,
    .tool-panel.is-solving .restart-actions {
        grid-column: 1;
    }

    .tool-panel.is-solving .edit-actions {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 7px;
    }

    .tool-panel.is-solving .tool-actions {
        grid-template-columns: 1fr;
    }

    .tool-panel.is-solving .clear-square-action {
        grid-column: auto;
    }

    .tool-panel.is-solving .edit-actions button,
    .tool-panel.is-solving .tool-actions button,
    .tool-panel.is-solving .restart-action {
        min-height: 40px;
        width: 100%;
        padding: 0 8px;
        font-size: 0.86rem;
    }
}

@media (min-width: 1200px) and (max-width: 1500px) and (orientation: landscape) {
    :root {
        --mp-page-width: calc(100vw - 18px);
    }
}

@media (min-width: 901px) and (max-height: 560px) {
    :root {
        --mp-cell: clamp(38px, 8.5vh, 46px);
        --mp-workspace-height: calc(100dvh - 142px);
    }

    .app-header {
        gap: 8px;
        margin-top: 8px;
        padding: 7px 18px;
    }

    .app-header h1 {
        font-size: 1.2rem;
    }

    .maths-practice {
        margin-top: 8px;
    }

    .workspace {
        height: var(--mp-workspace-height);
        min-height: 0;
    }

    .grid-panel {
        height: var(--mp-workspace-height);
        min-height: 0;
        gap: 6px;
        padding: 10px 14px;
    }

    .drag-token,
    .drag-token-ghost {
        width: clamp(38px, 8.5vh, 46px);
        min-height: clamp(38px, 8.5vh, 46px);
        font-size: clamp(1.28rem, 5.4vh, 1.65rem);
    }

    .tool-panel {
        gap: 7px;
        height: var(--mp-workspace-height);
        min-height: 0;
        max-height: var(--mp-workspace-height);
        overflow: hidden;
        padding: 10px 12px;
    }

    .tool-group p {
        font-size: 0.86rem;
        line-height: 1.25;
    }

    .keypad button,
    .tool-actions button,
    .edit-actions button {
        min-height: 32px;
    }
}

@media (max-width: 900px) {
    :root {
        --mp-cell: clamp(54px, 7vw, 62px);
    }

    .level-list {
        grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
    }

    .workspace {
        grid-template-columns: minmax(390px, 1fr) minmax(300px, 0.78fr);
    }

    .grid-panel {
        min-height: 480px;
        padding: 24px 16px;
    }

    .workspace-feedback {
        right: 18px;
        bottom: 18px;
        left: 18px;
    }

    .tool-panel {
        max-height: 480px;
    }
}

@media (min-width: 721px) and (max-width: 900px) and (max-height: 560px) {
    :root {
        --mp-cell: clamp(40px, 10vh, 46px);
        --mp-workspace-height: calc(100dvh - 136px);
    }

    .app-header {
        gap: 8px;
        padding: 4px 16px;
    }

    .eyebrow {
        display: none;
    }

    .app-header h1 {
        font-size: 1.05rem;
    }

    .home-link {
        min-height: 42px;
        padding: 0 8px;
        font-size: 0.78rem;
    }

    .maths-practice {
        margin: 8px auto;
        gap: 8px;
    }

    .setup-panel {
        padding-top: 8px;
    }

    .topic-title {
        font-size: 0.9rem;
    }

    .level-toggle,
    .new-question-action {
        min-height: 42px;
    }

    .workspace {
        grid-template-columns: minmax(360px, 1fr) minmax(300px, 0.78fr);
    }

    .grid-panel {
        min-height: var(--mp-workspace-height);
        gap: 6px;
        padding: 10px 12px;
    }

    .question-panel strong {
        font-size: 1.1rem;
    }

    .drag-token,
    .drag-token-ghost {
        width: clamp(44px, 8.5vh, 46px);
        min-height: clamp(44px, 8.5vh, 46px);
        font-size: clamp(1.25rem, 5.6vh, 1.7rem);
    }

    .tool-panel {
        gap: 6px;
        max-height: var(--mp-workspace-height);
        padding: 8px 10px;
    }

    .tool-group {
        gap: 0;
    }

    .tool-group h2 {
        font-size: 1rem;
    }

    .tool-group p {
        display: none;
    }

    .keypad {
        grid-template-columns: repeat(3, minmax(42px, 1fr));
        gap: 6px;
    }

    .keypad button,
    .tool-actions button,
    .edit-actions button {
        min-height: 44px;
        font-size: 1rem;
    }

    .tool-actions,
    .edit-actions {
        gap: 6px;
    }
}

@media (max-width: 720px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .grid-panel {
        border-right: 0;
        border-bottom: 1px solid var(--mp-border);
        min-height: 0;
        padding: 18px 10px;
        overflow-x: auto;
    }

    .workspace-feedback {
        position: static;
        margin-top: 14px;
        width: 100%;
        pointer-events: auto;
    }

    .tool-panel {
        max-height: none;
        overflow-y: visible;
    }
}

@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    :root {
        --mp-cell: clamp(33px, 9vh, 38px);
        --mp-workspace-height: calc(100dvh - 128px);
    }

    .app-header {
        gap: 8px;
        margin: 6px 8px 0;
        padding: 5px 16px;
        min-height: 0;
    }

    .app-header h1 {
        font-size: 1rem;
    }

    .home-link {
        min-height: 42px;
        padding: 0 8px;
        font-size: 0.78rem;
    }

    .maths-practice {
        width: min(100vw - 16px, 1180px);
        margin: 6px auto 4px;
        gap: 6px;
    }

    .setup-panel {
        padding-top: 7px;
    }

    .setup-toolbar {
        gap: 8px;
    }

    .setup-context {
        gap: 8px;
    }

    .topic-title {
        font-size: 0.82rem;
    }

    .level-toggle,
    .new-question-action {
        min-height: 42px;
        padding: 4px 8px;
        font-size: 0.85rem;
    }

    .level-panel {
        max-height: calc(100dvh - 80px);
        overflow-y: auto;
    }

    .level-list {
        grid-template-columns: repeat(3, minmax(96px, 1fr));
    }

    .level-button {
        min-height: 42px;
        padding: 6px 8px;
    }

    .workspace {
        grid-template-columns: minmax(270px, 1fr) minmax(240px, 0.92fr);
        min-height: var(--mp-workspace-height);
    }

    .grid-panel {
        min-height: var(--mp-workspace-height);
        gap: 5px;
        padding: 8px 10px;
        border-right: 1px solid var(--mp-border);
        border-bottom: 0;
        overflow: hidden;
    }

    .drag-equation {
        gap: 5px;
    }

    .drag-token,
    .drag-token-ghost {
        width: 44px;
        min-height: 44px;
        font-size: 1.22rem;
    }

    .tool-panel {
        gap: 6px;
        max-height: var(--mp-workspace-height);
        padding: 8px 10px;
        overflow-y: auto;
    }

    .tool-group {
        gap: 0;
    }

    .tool-group h2 {
        font-size: 1rem;
    }

    .tool-group p {
        display: none;
    }

    .keypad {
        gap: 6px;
    }

    .keypad button,
    .tool-actions button,
    .edit-actions button {
        min-height: 44px;
        font-size: 0.95rem;
    }

    .tool-actions,
    .edit-actions {
        gap: 6px;
    }

    .workspace-feedback {
        right: 10px;
        bottom: 10px;
        left: 10px;
    }

    .workspace-feedback .feedback {
        padding: 8px 10px;
        font-size: 0.88rem;
    }
}

@media (min-width: 721px) and (max-width: 900px) and (min-height: 900px) and (orientation: portrait) {
    :root {
        --mp-cell: clamp(60px, 8vw, 68px);
    }

    .workspace {
        grid-template-columns: 1fr;
        min-height: 0;
    }

    .grid-panel {
        min-height: 530px;
        gap: 12px;
        padding: 20px 18px;
        border-right: 0;
        border-bottom: 2px solid var(--mp-border);
    }

    .drag-equation {
        gap: 10px;
    }

    .drag-token,
    .drag-token-ghost {
        width: clamp(52px, 7.4vw, 62px);
        min-height: clamp(52px, 7.4vw, 62px);
        font-size: clamp(1.8rem, 4.4vw, 2.35rem);
    }

    .tool-panel {
        max-height: none;
        overflow-y: visible;
        padding: 14px 24px 16px;
    }

    .tool-group {
        grid-template-columns: auto minmax(0, 1fr);
        align-items: baseline;
        column-gap: 14px;
    }

    .tool-group p {
        margin-top: 0;
    }

    .keypad {
        grid-template-columns: repeat(3, minmax(80px, 1fr));
    }

    .keypad button,
    .tool-actions button,
    .edit-actions button {
        min-height: 50px;
    }

    .tool-panel.is-solving {
        grid-template-columns: minmax(0, 1fr) minmax(220px, 0.82fr);
        align-items: start;
    }

    .tool-panel.is-solving .tool-group,
    .tool-panel.is-solving .keypad {
        grid-column: 1;
    }

    .tool-panel.is-solving .edit-actions,
    .tool-panel.is-solving .tool-actions,
    .tool-panel.is-solving .restart-actions {
        grid-column: 2;
    }
}

@media (max-width: 560px) {
    :root {
        --mp-cell: 40px;
    }

    .app-header {
        gap: 10px;
        margin: 8px;
        padding: 10px 14px;
        min-height: 0;
    }

    .app-header h1 {
        font-size: 1.4rem;
    }

    .header-title {
        display: grid;
        gap: 2px;
    }

    .home-link {
        min-height: 42px;
        padding: 0 8px;
        font-size: 0.82rem;
    }

    .maths-practice {
        width: min(100vw - 16px, 1180px);
        gap: 10px;
    }

    .maths-practice-hub {
        margin-top: 8px;
        margin-bottom: 0;
    }

    .maths-practice-hub.has-access-gate,
    .access-gate-screen {
        min-height: calc(100svh - 16px);
        align-content: center;
    }

    .access-gate-panel {
        width: 100%;
    }

    .access-gate-brand-row {
        padding: 14px;
    }

    .access-gate-app-name {
        font-size: clamp(1.2rem, 6vw, 1.55rem);
    }

    .access-gate-dashboard-link,
    .access-gate-dashboard-link:visited {
        min-height: 38px;
        padding: 7px 10px;
        font-size: 0.84rem;
    }

    .access-gate-main {
        grid-template-columns: 1fr;
        gap: 18px;
        padding: 18px 14px;
    }

    .access-gate-copy {
        padding-left: 12px;
        border-left-width: 4px;
    }

    .access-gate-copy h2 {
        font-size: clamp(1.62rem, 8vw, 2.05rem);
    }

    .access-gate-actions,
    .auth-prompt-actions {
        padding: 0;
        background: transparent;
    }

    .access-gate-actions,
    .auth-prompt-actions {
        grid-template-columns: 1fr;
    }

    .access-gate-action,
    .auth-prompt-action {
        width: 100%;
    }

    .access-gate-pupil-route {
        width: 100%;
        justify-content: center;
        text-align: center;
        padding: 13px 14px;
    }

    .practice-option-grid {
        gap: 10px;
    }

    .setup-toolbar,
    .setup-context {
        align-items: stretch;
        flex-direction: column;
    }

    .topic-title {
        white-space: normal;
    }

    .level-toggle {
        justify-content: space-between;
        width: 100%;
    }

    .new-question-action {
        margin-left: 0;
        width: 100%;
    }

    .question-panel {
        align-items: center;
    }

    .drag-equation {
        gap: 8px;
    }

    .drag-token,
    .drag-token-ghost {
        width: 44px;
        min-height: 44px;
        font-size: 1.35rem;
    }

    .tool-panel {
        gap: 10px;
        padding: 14px 20px 16px;
    }

    .tool-group {
        gap: 2px;
    }

    .tool-group h2 {
        font-size: 1.12rem;
    }

    .tool-group p {
        display: block;
        font-size: 0.88rem;
        line-height: 1.28;
    }

    .keypad {
        grid-template-columns: repeat(3, minmax(58px, 1fr));
        gap: 8px;
    }

    .keypad button,
    .tool-actions button,
    .edit-actions button {
        min-height: 44px;
    }

    .tool-actions {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 700px) and (orientation: portrait) {
    #app[data-phone-layout="rotate"] .maths-practice:not(.maths-practice-hub) .work-area {
        display: none;
    }

    #app[data-phone-layout="rotate"] .maths-practice:not(.maths-practice-hub) .phone-landscape-lock {
        min-height: calc(100dvh - 128px);
        display: grid;
        place-items: center;
        padding: 14px;
    }

    #app[data-phone-layout="rotate"] .maths-practice:not(.maths-practice-hub) .phone-landscape-card {
        min-height: min(360px, calc(100dvh - 172px));
    }
}

@media (max-width: 520px) {
    .app-header {
        width: min(100vw - 12px, 1180px);
        gap: 8px;
        margin-top: 6px;
        padding: 8px 10px;
    }

    .header-primary {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto auto;
        grid-template-areas:
            "title level level"
            "change change topics";
        align-items: center;
        gap: 8px;
    }

    .header-left,
    .header-title {
        justify-content: flex-start;
        text-align: left;
    }

    .app-header h1 {
        font-size: clamp(1.05rem, 7vw, 1.32rem);
    }

    .header-left {
        grid-area: title;
    }

    .header-controls {
        display: contents;
    }

    .header-controls > .setup-panel,
    .setup-toolbar,
    .setup-context {
        display: contents;
    }

    .level-pill,
    .level-toggle,
    .header-actions .home-link {
        min-height: 40px;
        justify-content: center;
        width: 100%;
        padding-inline: 8px;
        font-size: 0.86rem;
        text-align: center;
    }

    .level-pill {
        grid-area: level;
        min-width: 54px;
        width: auto;
    }

    .level-pill::before {
        content: attr(data-level-number);
    }

    .level-pill-label,
    .level-progress-pill {
        display: none;
    }

    .level-toggle {
        grid-area: change;
        margin-left: 0;
    }

    .header-actions {
        display: contents;
        margin-left: 0;
    }

    .header-actions .practice-options-link {
        grid-area: topics;
        min-width: 86px;
    }
}

@media (max-width: 380px) {
    .app-header {
        gap: 8px;
        padding: 8px 12px;
    }

    .header-primary {
        flex-wrap: nowrap;
        gap: 8px;
    }

    .app-header h1 {
        font-size: 1.15rem;
    }

    .home-link {
        min-height: 42px;
        padding: 0 8px;
        font-size: 0.82rem;
    }

}

.workspace.is-setup {
    --mp-cell: clamp(60px, 10.5vw, 88px);
    --mp-setup-tool-height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) var(--mp-setup-tool-height);
    align-items: stretch;
}

.workspace.is-setup .grid-panel {
    --mp-setup-grid-bottom-gap: clamp(48px, 7dvh, 84px);
    min-height: 0;
    padding: clamp(18px, 2.4vw, 30px);
    border-right: 0;
    border-bottom: 2px solid var(--mp-border);
}

/* The feedback region reserves the former bottom spacer, so checking does not move the grid. */

/* Each tile is the size of the squares it goes into, so it keeps its size when it lands (the teacher,
   15 October: on the school laptop 72 px tiles went into 52 px squares, and on a board 72 px tiles into
   88 px squares). The grid's fit (appController.js fitStudentGridToPanel) sets --mp-cell, and the tiles
   follow it. Phones and the shortest windows keep their own tiles (the media queries below). */
.workspace.is-setup .drag-equation,
.workspace.is-setup .drag-equation.is-long-equation {
    --drag-token-size: var(--mp-cell);
    --drag-token-font-size: calc(var(--mp-cell) * 0.65);
}

@media (max-width: 720px) {
    .workspace.is-setup .drag-equation {
        --drag-token-size: clamp(52px, 6.2vw, 72px);
        --drag-token-font-size: clamp(1.9rem, 4.35vw, 3rem);
    }

    .workspace.is-setup .drag-equation.is-long-equation {
        --drag-token-size: clamp(44px, 5vw, 62px);
        --drag-token-font-size: clamp(1.5rem, 3.55vw, 2.5rem);
    }
}

.workspace.is-setup .tool-panel {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 8px;
    align-self: end;
    height: auto;
    max-height: none;
    min-height: 0;
    overflow: visible;
    padding: 10px 14px;
    background: var(--mp-paper-bg);
    z-index: 8;
}

.workspace.is-setup .tool-group {
    display: block;
    min-width: max-content;
}

.workspace.is-setup .tool-group h2 {
    color: var(--mp-muted);
    font-size: 0.92rem;
    line-height: 1;
    white-space: nowrap;
}

.workspace.is-setup .tool-group p,
.workspace.is-setup .keypad {
    display: none;
}

.workspace.is-setup .edit-actions,
.workspace.is-setup .tool-actions,
.workspace.is-setup .restart-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.workspace.is-setup .edit-actions {
    justify-content: center;
    flex-wrap: wrap;
}

.workspace.is-setup .tool-actions,
.workspace.is-setup .restart-actions {
    justify-content: flex-end;
}

.workspace.is-setup .edit-actions button,
.workspace.is-setup .tool-actions button,
.workspace.is-setup .restart-action {
    width: auto;
    min-height: 44px;
    padding: 0 12px;
    font-size: 0.86rem;
}

.workspace.is-setup .tool-actions .primary-action {
    min-width: 128px;
}

.workspace.is-setup .tool-actions .primary-action.is-ready-action {
    min-width: 162px;
}

.workspace.is-setup .restart-action {
    border-color: rgba(45, 52, 54, 0.38);
    background: var(--mp-paper-warm);
}

.workspace.is-setup .edit-actions button:disabled,
.workspace.is-setup .restart-action:disabled,
.workspace.is-setup.is-setup-complete .edit-actions {
    display: none;
}

@media (max-width: 720px) {
    .workspace.is-setup {
        --mp-cell: clamp(44px, 13.6vw, 56px);
        grid-template-rows: auto auto;
    }

    .workspace.is-setup .grid-panel {
        min-height: 0;
        padding: 18px 10px;
        overflow-x: auto;
    }

    .workspace.is-setup .tool-panel {
        grid-template-columns: 1fr;
        justify-items: stretch;
        padding: 10px;
    }

    .workspace.is-setup .tool-group {
        display: none;
    }

    .workspace.is-setup .edit-actions,
    .workspace.is-setup .tool-actions,
    .workspace.is-setup .restart-actions {
        justify-content: stretch;
    }

    .workspace.is-setup .edit-actions button,
    .workspace.is-setup .tool-actions button,
    .workspace.is-setup .restart-action {
        flex: 1 1 auto;
    }
}

@media (max-width: 380px) {
    .workspace.is-setup .grid-panel {
        overflow-x: hidden;
    }

    .workspace.is-setup .drag-equation {
        --equation-gap: 4px;
        --equation-inner-gap: 2px;
        --drag-token-size: clamp(32px, 11vw, 38px);
        --drag-token-font-size: clamp(1.05rem, 6.8vw, 1.45rem);
        transform: scale(0.72);
        transform-origin: center;
    }

    .workspace.is-setup .drag-equation.is-long-equation {
        --equation-gap: 3px;
        --equation-inner-gap: 1px;
        --drag-token-size: clamp(30px, 10vw, 35px);
        --drag-token-font-size: clamp(0.95rem, 6vw, 1.28rem);
    }
}

@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    .workspace.is-setup {
        --mp-cell: clamp(44px, 10vh, 48px);
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .workspace.is-setup .grid-panel {
        min-height: 0;
        padding: 8px 10px;
        border-right: 0;
        border-bottom: 2px solid var(--mp-border);
    }

    .workspace.is-setup .drag-equation {
        --drag-token-size: clamp(44px, 9vh, 46px);
        --drag-token-font-size: clamp(1.2rem, 5.5vh, 1.7rem);
    }

    .workspace.is-setup .tool-panel {
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 6px;
        padding: 7px 10px;
    }

    .workspace.is-setup .tool-group h2 {
        font-size: 0.82rem;
    }

    .workspace.is-setup .edit-actions button,
    .workspace.is-setup .tool-actions button,
    .workspace.is-setup .restart-action {
        min-height: 44px;
        padding: 0 9px;
        font-size: 0.82rem;
    }
}

/* A laptop's height: squares up to a tenth of the window's height (64 px on the school laptop's 640), which
   the grid's fit shrinks only if they would not all fit above the bottom of the window. */
@media (min-width: 901px) and (max-height: 820px) and (orientation: landscape) {
    .workspace.is-setup {
        --mp-cell: clamp(52px, min(7vw, 10dvh), 68px);
        --mp-workspace-height: clamp(400px, calc(100dvh - 176px), 520px);
    }

    .workspace.is-setup .grid-panel {
        padding-top: 18px;
        padding-bottom: 18px;
    }
}

@media (min-width: 901px) and (min-height: 561px) and (max-height: 720px) and (orientation: landscape) {
    :root {
        --mp-cell: clamp(64px, min(10dvh, 5.2vw), 78px);
        --mp-workspace-height: clamp(520px, calc(100dvh - 92px), 640px);
    }

    .app-header {
        grid-template-columns: auto minmax(0, 1fr);
        align-items: center;
        gap: 12px;
        margin-top: 8px;
        padding: 8px 14px;
    }

    .header-primary {
        gap: 10px;
    }

    .header-title {
        align-items: center;
        flex-wrap: nowrap;
        gap: 8px;
    }

    .app-header h1 {
        font-size: 1.25rem;
    }

    .topic-title {
        font-size: 0.86rem;
    }

    .setup-panel {
        gap: 0;
        padding-top: 0;
        border-top: 0;
    }

    .setup-toolbar {
        justify-content: flex-end;
    }

    .level-toggle {
        max-width: min(58vw, 560px);
    }

    .maths-practice {
        margin-top: 8px;
        margin-bottom: 4px;
    }

    .workspace {
        height: var(--mp-workspace-height);
        min-height: 0;
    }

    .grid-panel,
    .tool-panel {
        height: var(--mp-workspace-height);
        min-height: 0;
    }

    .workspace.is-setup .tool-panel {
        min-height: 0;
        overflow: hidden;
    }

    .workspace.is-setup .grid-panel {
        padding-top: 18px;
        padding-bottom: 18px;
    }

    .tool-panel.is-solving {
        grid-template-columns: 1fr;
        align-items: stretch;
        align-content: center;
        gap: 8px;
        max-height: none;
        overflow: visible;
        padding: 14px 14px 12px;
    }

    .tool-panel.is-solving .tool-group {
        grid-column: 1;
    }

    .tool-panel.is-solving .tool-group p {
        line-height: 1.25;
    }

    .tool-panel.is-solving .keypad {
        grid-column: 1;
        grid-template-columns: repeat(3, minmax(52px, 1fr));
        gap: 6px;
    }

    .tool-panel.is-solving .keypad button {
        min-height: 38px;
    }

    .tool-panel.is-solving .edit-actions,
    .tool-panel.is-solving .tool-actions,
    .tool-panel.is-solving .restart-actions {
        grid-column: 1;
    }

    .tool-panel.is-solving .edit-actions {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
    }

    .tool-panel.is-solving .tool-actions {
        grid-template-columns: 1fr;
    }

    .tool-panel.is-solving .clear-square-action {
        grid-column: auto;
    }

    .tool-panel.is-solving .edit-actions button,
    .tool-panel.is-solving .tool-actions button,
    .tool-panel.is-solving .restart-action {
        min-height: 38px;
        width: 100%;
        padding: 0 8px;
        font-size: 0.82rem;
    }
}

@media (min-width: 901px) and (max-height: 640px) and (orientation: landscape) {
    .app-header {
        margin-top: 0;
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .maths-practice {
        margin-top: 6px;
        margin-bottom: 0;
    }

    .workspace.is-setup .grid-panel {
        gap: 8px;
        padding-top: 5px;
        padding-bottom: 18px;
    }

    .workspace.is-setup .tool-panel {
        padding-top: 6px;
        padding-bottom: 6px;
    }

    .workspace.is-setup .tool-actions .primary-action,
    .workspace.is-setup .tool-actions .primary-action.is-ready-action {
        min-width: 136px;
    }
}

@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    .tool-panel.is-solving {
        grid-template-columns: minmax(0, 1fr) minmax(120px, 0.64fr);
        align-items: start;
    }

    .tool-panel.is-solving .tool-group {
        grid-column: 1 / -1;
    }

    .tool-panel.is-solving .keypad {
        grid-column: 1;
        grid-template-columns: repeat(3, minmax(44px, 1fr));
    }

    .tool-panel.is-solving .edit-actions,
    .tool-panel.is-solving .tool-actions,
    .tool-panel.is-solving .restart-actions {
        grid-column: 2;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}

/* Keep setup feedback in normal flow, clear of the action bar at every viewport. */
.workspace.is-setup {
    height: auto;
    min-height: var(--mp-workspace-height);
    grid-template-rows: auto auto;
}

/* Keep the next action beside the work pupils have just checked. */
.workspace.has-workspace-actions {
    height: auto;
}
.workspace:not(.has-solving-keypad):not(.has-persistent-tools) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
}
.workspace:not(.has-solving-keypad):not(.has-persistent-tools) .tool-panel {
    display: none;
}
/* Keep multiplication in the same two-panel arrangement as carrying addition.
   The empty keypad area retains its width while pupils place/check their tiles. */
.workspace.has-persistent-tools:not(.has-solving-keypad) .tool-panel {
    visibility: hidden;
}
.workspace.has-workspace-actions .grid-panel {
    height: auto;
    min-height: 0;
    grid-template-rows: none;
    border-bottom: 0;
}
.workspace:not(.has-solving-keypad):not(.has-persistent-tools) .grid-panel {
    border-right: 0;
}
.maths-step-acknowledgement {
    position: fixed;
    z-index: 100;
    transform: translate(-50%, -50%);
    width: min(330px, calc(100% - 32px));
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 20px 18px;
    border: 2px solid #285d37;
    border-radius: 16px;
    background: #d8eedb;
    color: #285d37;
    box-shadow: 4px 5px 0 rgba(45, 52, 54, 0.16);
    text-align: center;
    pointer-events: none;
}
.maths-step-acknowledgement strong {
    display: block;
    font-weight: 600;
    font-family: var(--mp-font-display);
    font-size: 1.55rem;
    line-height: 1.1;
}
.maths-step-acknowledgement strong + span {
    display: block;
    margin-top: 5px;
    font-size: 0.9rem;
    line-height: 1.4;
}
.maths-step-tick {
    font-size: 2.2rem;
    font-weight: 700;
    line-height: 1;
}
.workspace-actions {
    position: relative;
    z-index: 9;
    width: min(100%, 320px);
    justify-self: center;
}
.workspace .workspace-actions .tool-actions {
    display: grid;
    grid-template-columns: 1fr;
    grid-column: auto;
    justify-self: stretch;
    width: 100%;
    margin: 0;
}
.workspace.has-workspace-actions .workspace-actions button {
    width: 100%;
    min-height: 54px;
    padding: 10px 20px;
    font-size: 1.15rem;
}
.workspace-actions .exchange-decision {
    text-align: center;
}
.grid-panel > .completion-progress {
    width: min(100%, 420px);
}

@media (max-height: 560px) and (orientation: landscape) {
    .workspace.has-workspace-actions {
        --mp-cell: 44px;
        min-height: 0;
    }
    .workspace.has-workspace-actions .grid-panel {
        gap: 6px;
        padding: 8px 10px;
    }
    .workspace.has-workspace-actions .workspace-actions button {
        min-height: 44px;
        padding: 6px 14px;
        font-size: 1rem;
    }
    /* The celebration replaces covered working on short screens, leaving room to continue. */
    .workspace.has-badge-award .student-grid,
    .workspace.has-badge-award .completion-progress,
    .workspace.has-badge-award .workspace-feedback {
        display: none;
    }
    .workspace.has-badge-award .badge-award-celebration {
        position: relative;
        top: auto;
        left: auto;
        width: min(100%, 430px);
        padding: 12px;
        gap: 6px;
        transform: none;
    }
    .workspace.has-badge-award .badge-award-icon {
        width: 64px;
    }
    .workspace.has-badge-award .badge-award-copy {
        gap: 4px;
        font-size: 1rem;
    }
    .workspace.has-badge-award .badge-award-copy strong {
        font-size: 1.5rem;
    }
    .workspace.has-badge-award .badge-award-mini {
        width: 26px;
    }
}
.workspace.is-setup .grid-panel,
.workspace.is-setup .tool-panel {
    height: auto;
}

@media (max-height: 560px) and (orientation: landscape) {
    .workspace.is-setup {
        --mp-cell: clamp(32px, 8dvh, 40px);
        min-height: 0;
    }
    .workspace.is-setup .grid-panel {
        --mp-setup-grid-bottom-gap: 40px;
        gap: 6px;
        padding: 8px 10px;
    }
    .workspace.is-setup .drag-equation,
    .workspace.is-setup .drag-equation.is-long-equation {
        --drag-token-size: 44px;
        --drag-token-font-size: 1.6rem;
    }
    .workspace.is-setup .workspace-feedback .feedback {
        padding: 6px 8px;
        font-size: 0.82rem;
        line-height: 1.2;
    }
}

/* In-place guidance: the real workspace owns all layout and interaction. */
.maths-guide-note {
    position: fixed;
    z-index: 60;
    box-sizing: border-box;
    width: 224px;
    padding: 10px 12px 12px;
    background: var(--mp-paper-warm);
    border: 2px solid var(--mp-paper-outline);
    border-radius: var(--mp-radius-sm);
    box-shadow: var(--mp-cutout-shadow);
    color: var(--mp-ink);
    text-align: left;
}
.maths-guide-note[hidden] { display: none; }
.maths-guide-heading { display: grid; grid-template-columns: 1fr 44px; justify-content: space-between; align-items: center; gap: 6px; }
.maths-guide-heading > span { color: var(--mp-muted); font-size: .7rem; font-weight: 600; }
/* The cross (.cla-x, in controls.css) is the standard's: the pixel cross at three times its art, in a 44 px box in the card's corner. */
.maths-guide-heading strong { grid-column: 1 / -1; display: block; font: 600 1.05rem/1.25 var(--mp-font-display); margin: 7px 0; }
.maths-guide-copy p { margin: 0; font-size: .86rem; line-height: 1.45; }
.maths-guide-note .maths-guide-demo { margin-top: 10px; }
.maths-guide-demo:disabled { display: none; }
.maths-guide-note.is-subtle { background: var(--mp-surface); border-color: var(--mp-border); box-shadow: none; }
.maths-guide-source { outline: 3px solid var(--mp-primary) !important; outline-offset: 4px; }
.maths-guide-target { box-shadow: inset 0 0 0 3px var(--mp-primary) !important; }
/* Grid/ruler lines are painted above the cells. Keep the guide frame inside
   their painted edges so all four sides retain the same visible thickness. */
.grid-square.maths-guide-source { outline: none !important; }
.grid-square.maths-guide-source,
.grid-square.maths-guide-target { box-shadow: none !important; }
.grid-square.maths-guide-source::after,
.grid-square.maths-guide-target::after {
    box-shadow: none;
    border: 3px solid var(--mp-primary);
}
/* Keep the compact guide at the same bottom anchor for every step. */
/* The card along the bottom stays 84 px tall (the room the work is fitted into depends on it): its 44 px cross sits on the
   card's top-right corner, half outside, so the 48 px button at the bottom right never touches it, and a long button
   label goes onto two lines beside the words. */
.maths-guide-note.is-compact { min-height: 84px; height: auto; padding: 5px 12px 7px; }
.maths-guide-note.is-compact .maths-guide-heading { display: flex; gap: 8px; }
.maths-guide-note.is-compact .maths-guide-heading > span { font-size: .7rem; }
.maths-guide-note.is-compact .maths-guide-heading .cla-x { order: 3; }
.maths-guide-note.is-compact .maths-guide-copy { padding-right: 160px; }
.maths-guide-note.is-compact .maths-guide-heading strong { font-size: .92rem; line-height: 1.1; margin: 0; }
.maths-guide-note.is-compact .maths-guide-copy p { font-size: .82rem; line-height: 1.3; }
.maths-guide-note.is-compact .maths-guide-demo { position: absolute; right: 12px; bottom: 12px; margin: 0; }
.maths-guide-caption { display: block; min-height: 32px; margin-top: 5px; color: var(--mp-muted); font-size: .72rem; line-height: 1.25; }
.maths-guide-note.is-your-turn .maths-guide-caption { color: var(--mp-primary); font-weight: 700; }
.maths-guide-note.is-compact .maths-guide-caption { min-height: 14px; margin-top: 3px; padding-right: 160px; }
.maths-guide-copy .is-error { color: var(--mp-danger, #9c302b); font-weight: 600; }
.maths-guide-place, .maths-guide-column { position: fixed; pointer-events: none; z-index: 57; }
.maths-guide-place { display: grid; place-items: center; color: var(--mp-muted); font: 600 .72rem/1 var(--mp-font-display); }
.maths-guide-column { background: color-mix(in srgb, var(--gold) 10%, transparent); border: 1px solid color-mix(in srgb, var(--gold-deep) 25%, transparent); border-radius: 6px; }
/* The Guide's demonstration: a pointer, its contact cue and a ghost of the tile show the move on copies
   laid over the page (levelWalkthrough.js). Nothing on the page itself moves. */
.maths-guide-hand, .maths-guide-ghost, .maths-guide-contact { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 62; }
.maths-guide-hand { width: 32px; height: 40px; margin-left: -4px; margin-top: -3px; transform-origin: 4px 3px; z-index: 64; }
.maths-guide-hand svg { width: 100%; height: 100%; fill: var(--mp-paper-warm); stroke: var(--mp-ink); stroke-width: 1.8; stroke-linejoin: round; filter: drop-shadow(1px 2px 1px color-mix(in srgb, var(--mp-ink) 16%, transparent)); }
.maths-guide-contact { width: 26px; height: 26px; margin-left: -13px; margin-top: -13px; border: 2px solid var(--mp-primary); border-radius: 50%; background: var(--mp-paper-warm); z-index: 63; }
/* The Guide's moving tile shows its digit as the tile does, in the sums' numbers (classlings.css) at the tiles' weight;
   demonstrate() gives it the copied digit's size and colour (the teacher, 24 October: "the fonts are different when getting
   dragged by the guide"). */
.maths-guide-ghost { display: grid; place-items: center; border: 2px dashed var(--mp-primary); border-radius: var(--mp-radius-sm); background: var(--mp-paper-warm); box-shadow: none; color: var(--mp-ink); font-size: 2.5rem; font-weight: 800; line-height: 1; }
@media (prefers-reduced-motion: reduce) { .maths-guide-hand, .maths-guide-ghost, .maths-guide-contact { display: none; } }
[data-maths-guide-dock] .maths-practice { padding-bottom: var(--maths-guide-reserve); }
[data-maths-guide-dock] .workspace-feedback { display: none; }
[data-maths-guide-dock] .grid-panel { --mp-setup-grid-bottom-gap: 0px; }
@media (max-height: 560px) and (orientation: landscape) {
    .maths-guide-note { padding: 6px 8px 8px; }
    .maths-guide-heading > span { font-size: .64rem; }
    .maths-guide-heading strong { grid-column: 1 / -1; font-size: .92rem; margin: 4px 0; }
    .maths-guide-copy p { font-size: .76rem; line-height: 1.35; }
    .maths-guide-note .maths-guide-demo { margin-top: 6px; }
    .maths-guide-ghost { font-size: 1.65rem; }
}

@media (max-height: 560px) and (orientation: landscape) {
    [data-maths-guide-dock] .workspace .grid-panel { padding-top: 4px; padding-bottom: 4px; gap: 4px; }
}
@media (max-height: 560px) and (orientation: landscape) {
    [data-maths-guide-dock] .workspace { min-height: 0; }
    [data-maths-guide-dock] .workspace .grid-panel { min-height: 0; height: auto; align-content: start; }
    [data-maths-guide-dock] .tool-panel.is-solving { padding: 6px 10px; gap: 4px; }
    [data-maths-guide-dock] .tool-panel.is-solving .keypad { gap: 4px; }
}

.maths-guide-place.is-small { font-size: .6rem; }
@media (max-height: 420px) and (orientation: landscape) {
    [data-maths-guide-dock] .app-header { margin-top: 0; padding-top: 0; padding-bottom: 0; }
}
[data-maths-guide-dock] .exchange-decision > p { display: none; }
@media (max-height: 560px) and (orientation: landscape) {
    [data-maths-guide-dock] .workspace:not(.has-solving-keypad):not(.has-persistent-tools) .solving-strip:has(.result-tray) {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 12px;
    }
    [data-maths-guide-dock] .solving-strip .result-tray { margin: 0; }
}

/* Fallbacks are selected from measured space. Preserve the normal desktop skin. */
.workspace[data-maths-layout="compact"] .grid-panel,
.workspace[data-maths-layout="scroll"] .grid-panel {
    padding: 8px 10px;
    gap: 8px;
    --mp-setup-grid-bottom-gap: 0px;
}
body:has(.workspace[data-maths-layout="scroll"]) { overflow: auto; }
.workspace[data-maths-layout="scroll"] {
    height: auto; min-height: 0; max-height: none;
    grid-template-columns: minmax(0, 1fr); grid-template-rows: auto;
}
.workspace[data-maths-layout="scroll"] .grid-panel {
    height: auto; min-height: 0; max-height: none;
    grid-template-rows: none; align-content: start; overflow: auto;
    padding-bottom: 16px; border-right: 0;
}
.workspace[data-maths-layout="scroll"] .student-grid { justify-self: safe center; }
.workspace[data-maths-layout="scroll"] .tool-panel.is-solving {
    height: auto; min-height: 0; max-height: none; overflow: visible;
}
[data-maths-guide-dock] .workspace[data-maths-layout="scroll"] {
    max-height: max(44px, calc(100dvh - var(--maths-workspace-top, 100px) - var(--maths-guide-reserve, 96px) - 24px));
    overflow: auto;
    scrollbar-gutter: stable;
}
[data-maths-guide-dock] .workspace[data-maths-layout="scroll"] .grid-panel { overflow: visible; }
.maths-display-report {
    position: fixed; top: 12px; right: 12px; z-index: 1000;
    margin: 0; padding: 12px; width: min(420px, calc(100% - 24px));
    max-height: calc(100dvh - 24px); overflow: auto;
    background: #fff; border: 2px solid #2d3436; font: 14px/1.4 sans-serif;
}
.maths-display-report:not([open]) { width: auto; }
.maths-display-report textarea { display: block; width: 100%; height: 200px; font: 14px/1.4 monospace; }

/* A pupil's method stays anchored while totals, tiles and feedback change.
   Empty slots retain space, but never contain hidden interactive controls. */
.workspace.is-solving .grid-panel {
    align-content: start;
    padding: 12px 16px;
    gap: 8px;
}
.workspace.is-solving .column-sum {
    /* As tall as the answer box and the Check button beside it (the standard's small size, 48 px), so the grid below never moves. */
    min-height: max(var(--ctl-small-h, 48px), 1.4em);
}
.workspace.is-solving .solve-input { height: 1.4em; }
.workspace.is-solving .result-tray {
    --drag-token-size: clamp(44px, 5.2vw, 66px);
    /* The answer, carry and exchange cards' numbers are sized from the card, as the setting-out cards' are (65%). The short
       pages below make the cards 44 px; their numbers stayed 44.8 px, bigger than the card, so on a Chromebook's 1366 x 635
       or a school laptop's page the 7 of 17 ran into the card's foot (23 October). Exchange cards set their own. */
    --drag-token-font-size: calc(var(--drag-token-size) * 0.65);
    min-height: var(--drag-token-size);
    align-content: center;
}
.workspace-footer {
    display: grid;
    align-content: start;
    justify-items: center;
    gap: 12px;
    width: 100%;
    min-height: 11rem;
}
.workspace-status {
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 8px;
    width: 100%;
    min-height: 6.5rem;
}
.workspace-status > .completion-progress {
    width: min(100%, 420px);
    margin: 0;
}
.workspace-status > .workspace-feedback.is-visually-hidden {
    position: absolute;
}
@media (max-height: 560px) and (orientation: landscape) {
    .workspace.is-solving .result-tray { --drag-token-size: 44px; }
    .workspace.has-badge-award .workspace-status { display: none; }
    .workspace.has-badge-award .workspace-footer { min-height: 0; }
}

/* Docked keypads keep the method centred when the keypad comes and goes. */
.workspace.has-docked-keypad {
    position: relative;
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
}
.workspace.has-docked-keypad .grid-panel {
    height: auto;
    min-height: 0;
    border: 0;
}
.workspace.has-docked-keypad .tool-panel.is-solving {
    width: min(100%, 300px);
    height: auto;
    min-height: 0;
    max-height: none;
    justify-self: center;
}
.workspace.has-docked-keypad[data-keypad-dock="side"] .tool-panel.is-solving {
    position: absolute;
    top: var(--auto-keypad-top);
    right: 12px;
    width: 220px;
    padding: 8px;
}
.maths-step-acknowledgement.is-quiet {
    width: min(280px, calc(100% - 32px));
    grid-template-columns: 28px minmax(0, 1fr);
    padding: 10px 14px;
    gap: 8px;
    box-shadow: 2px 3px 0 rgba(45, 52, 54, .12);
}
.maths-step-acknowledgement.is-quiet strong { font-size: 1.15rem; }
.maths-step-acknowledgement.is-quiet .maths-step-tick { font-size: 1.6rem; }
.maths-step-acknowledgement.is-quiet strong + span { font-size: .85rem; margin-top: 2px; }

/* Multiplication carries stay legible below the line after they are used. A used carry is crossed out in blue (the app's
   sky-deep, short multiplication's Guide colour; the teacher, 25 October), and its digit keeps its own ink. */
.student-grid:is(.is-multiplication, .is-long-multiplication) .grid-square.is-carry-symbol .grid-square-value { font-size: .65em; }
.grid-square.is-used-carry .grid-square-value::after {
    content: ""; position: absolute; left: -.12em; right: -.12em; top: 50%;
    height: 2px; border-radius: 999px; background: var(--sky-deep, #1b6fcf); transform: rotate(-44deg);
}
.maths-guide-note .maths-guide-next { margin-top: 10px; }
.maths-guide-note.is-compact .maths-guide-next { position: absolute; right: 12px; bottom: 12px; margin: 0; }

/* The Yes and No question's own line repeats the line above it ("Can we do 3 − 7 in the ones column?"): on a
   page up to 800 px high, a board's 768 and a Chromebook's 720, it gives way, so the page is not 8 px too tall. */
@media (min-width: 901px) and (max-height: 799px) and (orientation: landscape) {
    .workspace.is-solving .exchange-decision > p { display: none; }
}

/* A short wide page (a school laptop at 1366 x 540 to 690 once the browser's bar is off, a board in a window): the practice
   screen keeps its two columns, the sum and the grid on the left and the keypad on the right, and fits the page. Before,
   from 680 px down it fell back to one long page with the keypad, then the button that goes on, below the screen
   (walk-through of 14 October). The Classlings' sizes are unchanged (44 px squares and keys at the least, 56 px buttons);
   what gives is the room kept for the line under the work, which now stands beside the button that goes on instead of above
   it, and for the tile that appears over the grid. */
@media (min-width: 901px) and (max-height: 690px) and (orientation: landscape) {
    .workspace.is-solving { --mp-workspace-height: calc(100dvh - 84px); }
    .workspace.is-solving .result-tray { --drag-token-size: 44px; }
    .workspace.is-solving .workspace-footer { min-height: 4.5rem; }
    .workspace.is-solving .workspace-footer:has(> .workspace-actions) {
        display: grid;
        grid-template-columns: minmax(0, 520px) 300px;
        align-items: start;
        column-gap: 16px;
        width: min(100%, 836px);
        justify-self: center;
    }
    .workspace.is-solving .workspace-footer:has(> .workspace-actions) .workspace-status { min-height: 0; justify-items: end; }
    .workspace.is-solving .workspace-footer > .workspace-actions { width: 100%; }
    /* Once a sum is finished the medal bar and the line under the work share the same room: the bar's words (the page's
       header says the same, and the bar's label stays for screen readers) and the line's padding give way. */
    .workspace.is-solving .completion-progress { margin-top: 0; gap: 0; }
    .workspace.is-solving .completion-progress-label { display: none; }
    .workspace.is-solving .workspace-feedback .feedback { padding-block: 8px; }
    .tool-panel.is-solving .keypad button { min-height: 44px; }
    /* The medal screen: the celebration takes the place of the grid it used to cover, so the button that goes on
       ("Start Level 4") is on the page (the same as the 560 px rules above, for the laptop's 540 to 690). */
    .workspace.has-badge-award .student-grid,
    .workspace.has-badge-award .completion-progress,
    .workspace.has-badge-award .workspace-feedback { display: none; }
    .workspace.has-badge-award .badge-award-celebration {
        position: relative;
        top: auto;
        left: auto;
        width: min(100%, 430px);
        padding: 12px;
        gap: 6px;
        transform: none;
    }
    .maths-app .workspace.has-badge-award .badge-award-celebration.is-topic-mastered { padding: 12px; gap: 6px; }
    .workspace.has-badge-award .workspace-status { display: none; }
    .workspace.is-solving.has-badge-award .workspace-footer { display: flex; justify-content: center; min-height: 0; }
    .workspace.is-solving.has-badge-award .workspace-footer > .workspace-actions { width: min(100%, 320px); }
    .workspace.has-badge-award .badge-award-icon { width: 64px; }
    .workspace.has-badge-award .badge-award-copy { gap: 4px; font-size: 1rem; }
    .workspace.has-badge-award .badge-award-copy strong { font-size: 1.5rem; }
    .workspace.has-badge-award .badge-award-mini { width: 26px; }
}

/* Long multiplication's build (long-multiplication-designs/METHOD.md and its storyboard, 24 October 2026). The 0 that holds
   the second row's ones is long multiplication's own colour, periwinkle, so it reads as a placeholder. Its tile and its
   square appear once the lines are on, and simply appear. Every zero is the plain one (the board's digits). */
.student-grid.is-long-multiplication { overflow: visible; }
/* Seven rows have little room to spare, so the grid is fitted closely (appController.js fitStudentGridToPanel): the line
   under the grid is measured, and the spare room is the two gaps below the grid and a little more. */
.workspace.is-setup.is-long-multiplication .grid-panel { --mp-grid-fit-safety: 32px; }
.grid-square.is-placeholder-guide,
.workspace.is-setup .grid-square.is-placeholder-guide {
    --mp-cell-bg: rgba(77, 99, 214, 0.07);
    --mp-cell-hover-bg: rgba(77, 99, 214, 0.12);
}
.grid-square.is-placeholder-value { --mp-cell-bg: var(--cla-periwinkle-tint, #e9edff); }
.grid-square.is-placeholder-value .grid-square-value { color: var(--cla-periwinkle-deep, #4d63d6); }
.guide-marker.is-placeholder-marker {
    color: rgba(77, 99, 214, 0.42);
    font-family: 'Maths Numbers', var(--body, 'Atkinson Hyperlegible', system-ui, sans-serif);
}
/* The 0's tile waits beside the second row, away from the sum, the size of the squares it goes into. It rests like the
   other tiles, with only its digit in the placeholder's colour. */
.setup-extra {
    position: absolute;
    z-index: 6;
    left: calc(100% + 20px);
    top: calc((var(--extra-row) + 0.5) * var(--mp-cell));
    display: flex;
    align-items: center;
    gap: 10px;
    transform: translateY(-50%);
}
.setup-extra .drag-token {
    --drag-token-size: var(--mp-cell);
    --drag-token-font-size: calc(var(--mp-cell) * 0.65);
}
.drag-token.is-placeholder-token:not(.is-used) { color: var(--cla-periwinkle-deep, #4d63d6); }
.setup-extra-label { color: rgba(30, 27, 58, 0.62); font: 600 15px / 1.2 var(--ctl-display, var(--display, 'Fredoka', system-ui, sans-serif)); white-space: nowrap; }
/* On a narrower page the grid keeps room on its right for the tile from the start, so nothing moves when it appears, and
   the tile's words go under it. */
@media (max-width: 900px) {
    .workspace.is-setup.is-long-multiplication .student-grid { margin-right: calc(var(--mp-cell) + 16px); }
    .setup-extra { left: calc(100% + 8px); flex-direction: column; gap: 3px; transform: translateY(calc(var(--mp-cell) * -0.5)); }
    .setup-extra-label { width: min-content; font-size: 12px; line-height: 1.1; text-align: center; white-space: normal; }
}
/* The rows the three lines frame aren't tinted while they wait: the dashed lines already show where the lines go. They
   light up while = is being placed, as in the other methods. */
.workspace.is-setup .student-grid.is-long-multiplication:not(.is-line-placement):not(.is-ruler-snap) .grid-square.is-ruler-line-guide {
    --mp-cell-bg: transparent;
    --mp-cell-hover-bg: rgba(96, 165, 250, 0.08);
}
/* The Guide's numbers in the board's digits too: "The 2 in 26 is worth 20". */
body.maths-app:has(.app-header.is-practice.topic-long-multiplication) .maths-guide-copy p {
    font-family: 'Maths Numbers', var(--body, 'Atkinson Hyperlegible', system-ui, sans-serif);
}
/* On a school laptop's short page the build's message line stands beside Check setup, as the working screen's does, so
   seven rows of 44 px squares fit; Check setup keeps its place under the grid. */
@media (min-width: 901px) and (max-height: 690px) and (orientation: landscape) {
    .workspace.is-setup.is-long-multiplication .grid-panel {
        --mp-setup-grid-bottom-gap: 0px;
        /* The grid fit's spare room: the one gap above the button and the message line, which share a row. */
        --mp-grid-fit-safety: 20px;
        grid-template-columns: minmax(0, 1fr) 320px minmax(0, 1fr);
        column-gap: 16px;
    }
    .workspace.is-setup.is-long-multiplication .grid-panel > * { grid-column: 1 / -1; }
    .workspace.is-setup.is-long-multiplication .grid-panel > .workspace-feedback { grid-row: 3; grid-column: 1; justify-items: end; }
    .workspace.is-setup.is-long-multiplication .grid-panel > .workspace-actions { grid-row: 3; grid-column: 2; }
}

/* Long multiplication's working (the storyboard's W1 to D1). A row's carry sits above the top digit it is added to, in the
   square's top-left corner for the first row and its bottom-right for the second, so both can be in one square; the app
   crosses each out once it is used, and it stays readable. */
.grid-square.has-corner-marks { overflow: visible; }
.grid-square-corner {
    position: absolute;
    z-index: 1;
    padding: 1px 3px;
    color: var(--mp-ink);
    font-family: 'Maths Numbers', var(--body, 'Atkinson Hyperlegible', system-ui, sans-serif);
    font-size: calc(var(--mp-cell) * 0.4);
    font-weight: 700;
    line-height: 1;
}
.grid-square-corner.is-tl { left: 3px; top: 3px; }
.grid-square-corner.is-br { right: 3px; bottom: 3px; }
.grid-square-corner.is-used::after {
    content: "";
    position: absolute;
    left: 0.1em;
    right: 0.1em;
    top: 50%;
    height: 2px;
    border-radius: 999px;
    background: var(--sky-deep, #1b6fcf);
    transform: rotate(-44deg);
}
/* The line under the work, Check column and, at the end, the answer and Next question stand beside the seven rows, under
   the keypad (the storyboard's D1). The empty footer left under the grid keeps the grid's fit. */
.workspace.is-solving.has-footer-beside:not(.has-solving-keypad) .tool-panel { visibility: visible; }
.workspace.has-footer-beside .grid-panel > .workspace-footer { min-height: 0; }
.workspace.is-solving .tool-panel .workspace-footer.is-beside {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    width: 100%;
    min-height: 0;
}
.workspace.is-solving .tool-panel .workspace-footer.is-beside .workspace-status { min-height: 0; justify-items: stretch; }
.workspace.is-solving .tool-panel .workspace-footer.is-beside .workspace-actions { width: 100%; }
.workspace.is-solving .tool-panel .workspace-footer.is-beside .setup-success { width: 100%; justify-items: center; text-align: center; }
/* The + that comes in by itself when the rows are added (the teacher, 25 October) looks like the × the child placed: the
   same ink and size, on the same light blue. It simply appears. */
.grid-square.is-fixed-symbol {
    --mp-cell-bg: rgba(214, 233, 255, 0.45);
    --mp-cell-hover-bg: rgba(214, 233, 255, 0.62);
}
/* The tiles to place are the tray's own size, so the grid under them stays put when they appear (on a short page tiles are
   otherwise 8.5% of its height: 45.9 px at 540, in a tray kept 44 px tall). */
.workspace.is-long-multiplication.is-solving .result-tray .drag-token { width: var(--drag-token-size); min-height: var(--drag-token-size); }
