.math-page {
    max-width: 920px;
    min-height: 686px;
}

.math-levels {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
}

.math-level,
.math-cat {
    text-align: left;
    background: #fff;
    border: 1px solid #5e8b7a;
    border-radius: 0.5rem;
    padding: 0.25rem 0.85rem;
    color: inherit;
}

.math-cat {
    min-width: 8.5rem;
    text-align: center;
    font-weight: 700;
    color: #2f5d4e;
}

.math-level {
    min-width: 9.5rem;
}

.math-level:hover,
.math-level:focus-visible,
.math-cat:hover,
.math-cat:focus-visible {
    box-shadow: 0 0.35rem 0.8rem rgba(47, 93, 78, 0.16);
    outline: none;
}

.math-cat.is-on,
.math-level.is-on {
    background: #e7f3ee;
    box-shadow: 0 0 0 2px #5e8b7a;
}

.math-top-you {
    background: #e7f3ee;
    font-weight: 700;
}

.math-level.is-locked {
    opacity: 0.55;
    cursor: not-allowed;
    border-color: #c5cdd8;
}

.math-level-name {
    display: block;
    font-weight: 700;
    color: #2f5d4e;
}

.math-level-blurb {
    display: block;
    font-size: 0.8rem;
    color: #6c757d;
}

.math-hud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 0.75rem;
}

.math-lives {
    display: flex;
    gap: 0.3rem;
    font-size: 1.15rem;
}

.math-lives span {
    opacity: 0.28;
}

.math-lives span.is-on {
    opacity: 1;
    color: #c9a227;
}

.math-stat {
    font-size: 0.9rem;
    color: #2f5d4e;
}

.math-stat-label {
    color: #6c757d;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.math-stage {
    position: relative;
    display: grid;
    grid-template-columns: minmax(12rem, 42%) 1fr;
    height: 420px;
    overflow: hidden;
    border-radius: 12px;
    box-shadow: inset 0 0 0 1px rgba(47, 93, 78, 0.12);
}

.math-board {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem 0.75rem 4.5rem;
    background:
        radial-gradient(circle at 12% 18%, rgba(244, 228, 179, 0.12), transparent 42%),
        linear-gradient(180deg, #24463c 0%, #1b332c 100%);
    color: #f4e4b3;
    text-align: center;
}

.math-board-kicker {
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.8;
    margin-bottom: 0.65rem;
}

.math-prompt {
    font-size: clamp(1.6rem, 4vw, 2.4rem);
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
    font-variant-numeric: tabular-nums;
}

.math-typed {
    min-height: 2.1rem;
    margin: 0.85rem 0 0;
    padding: 0.2rem 0.7rem;
    border-radius: 0.45rem;
    background: rgba(244, 228, 179, 0.12);
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    font-variant-numeric: tabular-nums;
}

.math-hint {
    margin: 0.6rem 0 0;
    font-size: 0.85rem;
    color: #ffe082;
}

.math-fall {
    position: relative;
    z-index: 2;
    background: linear-gradient(180deg, #cfe8df 0%, #eef6f1 48%, #f4ead0 78%, #d9c48a 100%);
}

.math-chip {
    position: absolute;
    top: 0;
    left: 0;
    min-width: 3.2rem;
    height: 3.2rem;
    padding: 0 0.55rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #fff;
    color: #2f5d4e;
    font-weight: 700;
    font-size: 1.35rem;
    line-height: 1;
    box-shadow: 0 4px 0 #b7c2d8;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
    will-change: transform;
    font-variant-numeric: tabular-nums;
}

.math-chip.is-blast {
    animation: math-blast 0.32s ease-out forwards;
    pointer-events: none;
}

.math-chip.is-drop {
    animation: math-drop 0.28s ease-in forwards;
    pointer-events: none;
}

.math-ground {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    height: 64px;
    background: linear-gradient(180deg, #c9a36a 0%, #a67c4a 100%);
    box-shadow: inset 0 8px 12px rgba(90, 60, 20, 0.15);
}

.math-over {
    position: absolute;
    inset: 0;
    z-index: 8;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(244, 247, 251, 0.88);
    padding: 1rem;
}

.math-over-card {
    background: #fff;
    border-radius: 12px;
    padding: 1.25rem 1.4rem;
    box-shadow: 0 0.5rem 1.4rem rgba(47, 93, 78, 0.18);
    max-width: 22rem;
    width: 100%;
}

.math-over-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem 0.75rem;
    font-size: 0.9rem;
}

.math-over-stats span {
    color: #6c757d;
}

.math-over-stats strong {
    color: #2f5d4e;
}

.math-board.is-hit .math-prompt {
    color: #b8f0c8;
}

.math-board.is-miss {
    animation: math-shake 0.28s ease-in-out;
}

@keyframes math-blast {
    0% { transform: translate(var(--x, 0), var(--y, 0)) scale(1); opacity: 1; }
    100% { transform: translate(var(--x, 0), var(--y, 0)) scale(1.5); opacity: 0; }
}

@keyframes math-drop {
    0% { transform: translate(var(--x, 0), var(--y, 0)) scale(1); opacity: 1; }
    100% { transform: translate(var(--x, 0), calc(var(--y, 0px) + 18px)) scale(0.7); opacity: 0; }
}

@keyframes math-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

@media (max-width: 700px) {
    .math-stage {
        grid-template-columns: 1fr;
        grid-template-rows: 38% 1fr;
        height: 480px;
    }

    .math-board {
        padding-bottom: 0.75rem;
    }

    .math-prompt {
        font-size: 1.7rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .math-chip.is-blast,
    .math-chip.is-drop,
    .math-board.is-miss {
        animation: none;
    }
}
