/*
 * area-model activity styles.
 *
 * Layout is a two-column flex: the rectangle grid on the left,
 * the optional column-shorthand panel on the right.
 *
 * The grid itself uses CSS grid-template-rows / columns sized
 * proportionally to the place-value decomposition — so the visual
 * area of each cell genuinely matches its partial product.
 */

.am-mode-chip {
    display: inline-block;
    padding: 0.3rem 0.7rem;
    background: var(--maths-surface-alt);
    color: var(--maths-primary-dark);
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.am-target-panel { /* shape inherited from .maths-target-panel */ }

.am-target-label {
    font-weight: 800;
    color: #8a5a00;
    font-size: 0.95rem;
    margin-right: 0.5rem;
}

.am-target-prompt {
    flex: 1 1 auto;
    color: #6b4500;
    font-weight: 700;
    font-size: 1rem;
}

.am-controls {
    background: var(--maths-surface);
    border: 1px solid var(--maths-border);
    border-radius: 12px;
    padding: 0.9rem 1.1rem;
    margin-bottom: 1rem;
}

.am-factor-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    font-size: 1.05rem;
}

.am-factor-label {
    font-weight: 700;
    color: var(--maths-ink);
    min-width: auto;
}

.am-stepper {
    display: inline-flex;
    align-items: stretch;
    border: 2px solid var(--maths-border);
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}

.am-step-btn {
    min-width: 44px;
    min-height: 44px;
    border: 0;
    background: var(--maths-surface-alt);
    color: var(--maths-primary-dark);
    font-weight: 800;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.4rem;
}

.am-step-btn:hover { background: var(--maths-surface); }
.am-step-btn:active { background: var(--maths-primary); color: #fff; }

.am-step-value {
    min-width: 3.6rem;
    min-height: 44px;
    border: 0;
    border-left: 1px solid var(--maths-border);
    border-right: 1px solid var(--maths-border);
    background: #fff;
    color: var(--maths-primary-dark);
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: 1.4rem;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    padding: 0 0.6rem;
}

.am-step-value:hover { background: var(--maths-surface-alt); }

.am-factor-times,
.am-factor-equals {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--maths-primary);
}

.am-product {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--maths-primary-dark);
    padding: 0.2rem 0.7rem;
    background: var(--maths-surface-alt);
    border-radius: 8px;
    font-variant-numeric: tabular-nums;
}

.am-decomp-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    margin-top: 0.75rem;
}

.am-decomp-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.am-decomp-label {
    font-weight: 700;
    color: var(--maths-ink-muted);
    font-size: 1.05rem;
}

.am-decomp-chips {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.am-decomp-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    background: var(--maths-surface-alt);
    color: var(--maths-primary-dark);
    border: 1px solid var(--maths-border);
    border-radius: 999px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    min-height: 40px;
}

.am-decomp-chip-value {
    font-size: 1.1rem;
}

.am-decomp-chip-x {
    border: none;
    background: transparent;
    color: var(--maths-danger);
    cursor: pointer;
    font-weight: 800;
    padding: 0 0.15rem;
}

.am-decomp-chip-x:hover { color: #7a1f17; }

.am-decomp-add {
    border: 2px dashed var(--maths-border);
    background: transparent;
    color: var(--maths-primary);
    border-radius: 999px;
    padding: 0.3rem 0.7rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}

.am-decomp-add:hover {
    border-color: var(--maths-primary);
    background: var(--maths-surface-alt);
}

.am-stage {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
}

.am-grid-wrap {
    flex: 1 1 auto;
    min-width: 0;
    background: var(--maths-surface);
    border: 1px solid var(--maths-border);
    border-radius: 12px;
    padding: 1rem 1.1rem;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto 1fr;
    gap: 0.4rem;
}

.am-axis-top {
    grid-column: 2;
    grid-row: 1;
    display: grid;
    gap: 0.25rem;
}

.am-axis-left-wrap {
    grid-column: 1 / 3;
    grid-row: 2;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.4rem;
}

.am-axis-left {
    grid-column: 1;
    display: grid;
    gap: 0.25rem;
}

.am-axis-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.3rem 0.6rem;
    font-weight: 800;
    font-size: 1.15rem;
    color: var(--maths-primary-dark);
    background: var(--maths-surface-alt);
    border-radius: 6px;
    min-width: 2.8rem;
    min-height: 2rem;
    font-variant-numeric: tabular-nums;
}

.am-axis-label.am-axis-label-tens   { background: #DDE9F7; }
.am-axis-label.am-axis-label-ones   { background: #FBE9D7; }
.am-axis-label.am-axis-label-hundreds { background: #DCEEDC; }

.am-grid {
    grid-column: 2;
    display: grid;
    gap: 0.25rem;
    min-height: 320px;
}

.am-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    padding: 0.4rem 0.5rem;
    text-align: center;
    color: var(--maths-ink);
    font-weight: 700;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
    transition: background-color 200ms ease;
}

.am-cell-calc {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--maths-ink-muted);
}

.am-cell-value {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--maths-primary-dark);
    font-variant-numeric: tabular-nums;
    margin-top: 0.2rem;
}

/* Heat-map colouring by magnitude — bigger sub-products are deeper. */
.am-cell.am-cell-mag-1 { background: #F4F8FD; }
.am-cell.am-cell-mag-2 { background: #E5EFFA; }
.am-cell.am-cell-mag-3 { background: #C9DEF1; }
.am-cell.am-cell-mag-4 { background: #A8C7E7; }
.am-cell.am-cell-mag-5 { background: #7FAAD7; color: #fff; }
.am-cell.am-cell-mag-5 .am-cell-value,
.am-cell.am-cell-mag-5 .am-cell-calc { color: #fff; }

.am-shorthand {
    flex: 0 0 220px;
    background: var(--maths-surface);
    border: 1px solid var(--maths-border);
    border-radius: 12px;
    padding: 0.9rem 1rem;
    font-variant-numeric: tabular-nums;
}

.am-shorthand[hidden] { display: none; }

.am-shorthand-title {
    font-weight: 800;
    color: var(--maths-primary-dark);
    font-size: 0.95rem;
    margin-bottom: 0.6rem;
    padding-bottom: 0.45rem;
    border-bottom: 1px solid var(--maths-border);
}

.am-shorthand-body {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.am-shorthand-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0.55rem;
    border-radius: 6px;
    font-weight: 700;
}

.am-shorthand-row-total {
    border-top: 2px solid var(--maths-ink);
    margin-top: 0.4rem;
    padding-top: 0.55rem;
    font-size: 1.05rem;
    color: var(--maths-primary-dark);
}

.am-your-turn {
    background: #FFF7DE;
    border: 1px solid #F0C14B;
    border-radius: 12px;
    padding: 0.9rem 1.1rem;
    margin-top: 1rem;
}

.am-your-turn-label {
    font-weight: 800;
    color: #8a5a00;
    margin-bottom: 0.4rem;
}

.am-your-turn-list {
    margin: 0;
    padding-left: 1.2rem;
    color: #5e3c00;
    font-weight: 600;
}

body.display-mode .am-decomp-add,
body.display-mode .am-decomp-chip-x {
    display: none;
}

body.display-mode .am-controls {
    pointer-events: none;
}

/* In display mode the steppers become bare text so "Across × Down = product"
 * reads as a static equation, not interactive chrome. */
body.display-mode .am-stepper {
    border: 2px solid transparent;
    background: transparent;
}

body.display-mode .am-step-btn { display: none; }

body.display-mode .am-step-value {
    background: transparent;
    border: 0;
    color: var(--maths-primary-dark);
    min-width: 2.5rem;
    padding: 0;
    font-size: 1.5rem;
    cursor: default;
}

/* Keypad popover — primary-friendly digit grid for fine-grained entry
 * (e.g. setting a 3-digit factor like 235). Steppers handle the common
 * cases; this opens when the value pill is tapped. */
.am-keypad {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: #fff;
    border: 2px solid var(--maths-primary);
    border-radius: 14px;
    box-shadow: 0 10px 32px rgba(15, 23, 42, 0.18);
    padding: 0.8rem;
    width: min(360px, 92vw);
}

.am-keypad[hidden] { display: none; }

.am-keypad-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.am-keypad-prompt {
    font-weight: 800;
    color: var(--maths-primary-dark);
    font-size: 1rem;
}

.am-keypad-close {
    border: 0;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--maths-ink-muted);
    padding: 0 0.4rem;
}

.am-keypad-display {
    text-align: center;
    background: var(--maths-surface-alt);
    border-radius: 10px;
    padding: 0.6rem;
    font-size: 2rem;
    font-weight: 800;
    color: var(--maths-primary-dark);
    font-variant-numeric: tabular-nums;
    margin-bottom: 0.6rem;
}

.am-keypad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
}

.am-key {
    min-height: 54px;
    border: 2px solid var(--maths-border);
    border-radius: 10px;
    background: #fff;
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: 1.4rem;
    color: var(--maths-primary-dark);
    cursor: pointer;
    transition: background-color 120ms ease, transform 60ms ease;
}

.am-key:hover { background: var(--maths-surface-alt); }
.am-key:active { transform: scale(0.96); background: var(--maths-primary); color: #fff; }

.am-key-back {
    color: var(--maths-danger);
    border-color: var(--maths-danger);
}

.am-key-ok {
    color: #fff;
    background: var(--maths-primary);
    border-color: var(--maths-primary-dark);
}

.am-key-ok:hover { background: var(--maths-primary-dark); }

/* Split chooser — pops up when "+ split" is tapped on a decomp chip.
 * Shows place-value-driven candidate splits as tappable chips. */
.am-split-chooser {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: #fff;
    border: 2px solid var(--maths-primary);
    border-radius: 14px;
    box-shadow: 0 10px 32px rgba(15, 23, 42, 0.18);
    padding: 0.9rem 1rem;
    width: min(480px, 94vw);
}

.am-split-chooser[hidden] { display: none; }

.am-split-chooser-prompt {
    font-weight: 800;
    color: var(--maths-primary-dark);
    font-size: 1.05rem;
    margin-bottom: 0.6rem;
}

.am-split-chooser-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.6rem;
}

.am-split-chip {
    border: 2px solid var(--maths-border);
    background: #fff;
    border-radius: 10px;
    padding: 0.5rem 0.8rem;
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    color: var(--maths-primary-dark);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-height: 44px;
}

.am-split-chip:hover { background: var(--maths-surface-alt); border-color: var(--maths-primary); }
.am-split-chip-pair { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.am-split-chip-plus { color: var(--maths-ink-muted); font-weight: 700; }

.am-split-chooser-close {
    border: 0;
    background: transparent;
    color: var(--maths-ink-muted);
    cursor: pointer;
    font-weight: 700;
    padding: 0.3rem 0.6rem;
}

@media (max-width: 720px) {
    .am-stage { flex-direction: column; }
    .am-shorthand { flex: 0 0 auto; width: 100%; }
}
