:root {
    --ink: #17212b;
    --muted: #5b6572;
    --paper: #fffdf7;
    --panel: rgba(255, 255, 255, 0.94);
    --line: #d9e2ea;
    --pink: #e8507a;
    --teal: #16a6a3;
    --yellow: #ffd166;
    --green: #4caf50;
    --red: #e14d4d;
    --blue: #2777c7;
    --sky: #bde7ff;
    --grass: #70c15b;
    --shadow: 0 12px 28px rgba(23, 33, 43, 0.18);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 8% 8%, rgba(255, 209, 102, 0.45), transparent 26%),
        radial-gradient(circle at 88% 18%, rgba(22, 166, 163, 0.28), transparent 28%),
        linear-gradient(135deg, #fff1f4 0%, #e7f8f5 50%, #fff8dd 100%);
    color: var(--ink);
    font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
    letter-spacing: 0;
}

button {
    touch-action: manipulation;
    font-family: inherit;
}

#app {
    min-height: 100vh;
}

.game-header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 18px;
    border-bottom: 2px solid rgba(23, 33, 43, 0.08);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
}

.player-info,
.game-stats {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border: 3px solid var(--ink);
    border-radius: 8px;
    background: var(--yellow);
    font-size: 30px;
}

.stats {
    display: grid;
    gap: 6px;
}

.level {
    color: var(--pink);
    font-size: 18px;
    font-weight: 800;
}

.xp-bar {
    position: relative;
    width: 160px;
    height: 22px;
    overflow: hidden;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: #ffffff;
}

.xp-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--teal), var(--yellow));
    transition: width 0.35s ease;
}

.xp-text {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 800;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 68px;
    justify-content: center;
    padding: 8px 10px;
    border: 2px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    font-weight: 800;
}

.stat-icon {
    font-size: 20px;
}

.sound-toggle {
    width: 46px;
    height: 46px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: var(--yellow);
    cursor: pointer;
    font-size: 22px;
}

.screen {
    display: none;
    padding: 22px;
    animation: fadeIn 0.25s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.menu-container {
    max-width: 1040px;
    margin: 26px auto;
}

.game-title {
    display: grid;
    gap: 10px;
    margin-bottom: 28px;
    text-align: center;
}

.rainbow-text {
    color: var(--pink);
    font-size: clamp(34px, 7vw, 58px);
    font-weight: 900;
    text-shadow: 3px 3px 0 #fff, 6px 6px 0 rgba(22, 166, 163, 0.22);
}

.subtitle {
    color: var(--ink);
    font-size: 20px;
    font-weight: 700;
}

.menu-buttons,
.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
    max-width: 1040px;
    margin: 0 auto 26px;
}

.menu-btn,
.game-card,
.action-btn,
.back-btn,
.rule-chip {
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
    cursor: pointer;
    font-weight: 850;
    box-shadow: 0 5px 0 rgba(23, 33, 43, 0.18);
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.menu-btn:hover,
.game-card:hover,
.action-btn:hover,
.back-btn:hover,
.rule-chip:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 rgba(23, 33, 43, 0.16);
}

.menu-btn:active,
.game-card:active,
.action-btn:active,
.back-btn:active,
.rule-chip:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 rgba(23, 33, 43, 0.18);
}

.menu-btn {
    min-height: 132px;
    display: grid;
    place-items: center;
    gap: 8px;
    padding: 18px;
}

.btn-icon,
.game-icon {
    font-size: 46px;
}

.btn-text {
    font-size: 19px;
}

.mascot-welcome {
    display: grid;
    grid-template-columns: auto minmax(0, 560px);
    align-items: center;
    justify-content: center;
    gap: 18px;
    margin-top: 20px;
}

.mascot {
    font-size: 64px;
    animation: hop 2.4s infinite;
}

@keyframes hop {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.speech-bubble {
    padding: 18px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: var(--shadow);
    font-size: 18px;
    font-weight: 700;
}

h2 {
    margin: 8px auto 18px;
    max-width: 1040px;
    color: var(--ink);
    font-size: 30px;
}

.game-card {
    min-height: 180px;
    display: grid;
    align-content: center;
    gap: 8px;
    padding: 18px;
    text-align: center;
}

.game-card:nth-child(3n+1) { background: #fff4c7; }
.game-card:nth-child(3n+2) { background: #dff7f2; }
.game-card:nth-child(3n) { background: #ffe7ed; }

.game-card h3 {
    color: var(--pink);
    font-size: 22px;
}

.game-card p {
    color: var(--muted);
    font-weight: 700;
}

.difficulty {
    font-size: 15px;
}

.back-btn {
    margin-bottom: 14px;
    padding: 11px 18px;
    background: #ffffff;
}

.progress-container {
    max-width: 850px;
    margin: 20px auto;
    display: grid;
    gap: 14px;
}

.progress-category,
.stat-box,
.achievement-card {
    border: 2px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 18px;
}

.progress-category h3 {
    margin-bottom: 10px;
    color: var(--pink);
}

.progress-bar {
    position: relative;
    height: 30px;
    overflow: hidden;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: #ffffff;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--teal), var(--yellow));
    transition: width 0.35s ease;
}

.progress-text {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-weight: 900;
}

.stats-summary {
    max-width: 850px;
    margin: 22px auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
}

.stat-box {
    text-align: center;
}

.stat-value {
    color: var(--pink);
    font-size: 34px;
    font-weight: 900;
}

.achievements-grid {
    max-width: 1040px;
    margin: 20px auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
}

.achievement-card {
    text-align: center;
}

.achievement-card.unlocked {
    border-color: var(--yellow);
    background: #fff6cf;
}

.achievement-card.locked {
    filter: grayscale(1);
    opacity: 0.5;
}

.achievement-icon {
    margin-bottom: 8px;
    font-size: 38px;
}

.achievement-name {
    color: var(--pink);
    font-weight: 900;
}

.achievement-desc {
    margin-top: 5px;
    color: var(--muted);
    font-size: 13px;
}

.game-info {
    max-width: 1120px;
    margin: 0 auto 14px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.game-info > div {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: #ffffff;
    font-size: 18px;
    font-weight: 900;
}

.game-info .label {
    color: var(--muted);
}

.game-canvas {
    position: relative;
    min-height: 560px;
    max-width: 1120px;
    margin: 0 auto 14px;
    overflow: hidden;
    border: 3px solid var(--ink);
    border-radius: 8px;
    background: var(--paper);
    box-shadow: var(--shadow);
}

.game-controls {
    max-width: 1120px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.round-pill,
.rule-chip {
    padding: 9px 13px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: #ffffff;
    font-weight: 900;
}

.rule-chip {
    background: var(--yellow);
}

.mini-stage {
    min-height: 560px;
    display: grid;
    grid-template-columns: minmax(270px, 36%) 1fr;
    background: #fffdf7;
}

.lesson-column {
    display: grid;
    align-content: start;
    gap: 12px;
    padding: 18px;
    border-right: 3px solid var(--ink);
    background: #ffffff;
}

.rule-card {
    display: grid;
    gap: 10px;
    padding: 16px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: #fff8dd;
}

.rule-card.compact ul li:nth-child(n+3) {
    display: none;
}

.rule-label {
    width: fit-content;
    padding: 4px 8px;
    border-radius: 8px;
    background: var(--teal);
    color: #ffffff;
    font-size: 13px;
    font-weight: 900;
}

.rule-card h3 {
    color: var(--pink);
    font-size: 22px;
}

.rule-card p,
.rule-card li,
.rule-card strong {
    line-height: 1.35;
    font-size: 16px;
}

.rule-card ul {
    padding-left: 18px;
}

.task-card {
    display: grid;
    gap: 8px;
    padding: 16px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: #dff7f2;
}

.task-card.danger {
    background: #ffe7ed;
}

.task-card span {
    color: var(--muted);
    font-weight: 900;
}

.task-card strong {
    font-size: clamp(20px, 3vw, 29px);
    line-height: 1.18;
    overflow-wrap: anywhere;
}

.play-field {
    position: relative;
    min-height: 560px;
    overflow: hidden;
}

.road {
    background:
        linear-gradient(90deg, transparent 0 48%, rgba(255, 255, 255, 0.5) 48% 52%, transparent 52%),
        linear-gradient(#585f66, #3d444b);
}

.finish-line {
    position: absolute;
    top: 16px;
    right: 18px;
    z-index: 2;
    padding: 8px 12px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: #ffffff;
    font-weight: 900;
}

.car {
    position: absolute;
    top: 448px;
    left: 34px;
    z-index: 3;
    font-size: 54px;
    transition: left 0.55s ease, top 0.35s ease, transform 0.2s ease;
    animation: drive 2s infinite linear;
}

@keyframes drive {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(18px); }
}

.car.crash {
    animation: crashShake 0.2s linear 3;
}

@keyframes crashShake {
    0%, 100% { transform: translateX(0) rotate(0); }
    25% { transform: translateX(-8px) rotate(-10deg); }
    75% { transform: translateX(8px) rotate(10deg); }
}

.race-help {
    position: absolute;
    left: 18px;
    right: 18px;
    top: 14px;
    z-index: 4;
    padding: 9px 12px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    font-size: 14px;
    font-weight: 900;
}

.lane,
.target,
.bubble,
.chest,
.spell,
.platform,
.word-crate,
.memory-card,
.word-piece {
    border: 2px solid var(--ink);
    border-radius: 8px;
    cursor: pointer;
    color: var(--ink);
    font-weight: 900;
    box-shadow: 0 5px 0 rgba(23, 33, 43, 0.18);
}

.lane {
    position: absolute;
    left: 22%;
    right: 9%;
    min-height: 72px;
    padding: 12px;
    background: #ffffff;
    font-size: clamp(15px, 2.1vw, 20px);
    overflow-wrap: anywhere;
}

.lane-0 { top: 84px; }
.lane-1 { top: 184px; }
.lane-2 { top: 284px; }
.lane-3 { top: 384px; }

.galaxy {
    background:
        radial-gradient(circle at 20% 20%, #ffffff 0 2px, transparent 3px),
        radial-gradient(circle at 70% 35%, #ffffff 0 2px, transparent 3px),
        radial-gradient(circle at 40% 70%, #ffffff 0 2px, transparent 3px),
        linear-gradient(145deg, #20324a, #0f1720);
}

.ship {
    position: absolute;
    left: 28px;
    bottom: 42px;
    z-index: 5;
    font-size: 58px;
    transition: left 0.08s linear, top 0.08s linear;
}

.laser {
    position: absolute;
    z-index: 4;
    width: 8px;
    height: 0;
    border-radius: 8px;
    background: var(--yellow);
    opacity: 0;
    transform: translateX(-50%);
}

.laser.fire {
    animation: laserFire 0.22s ease;
}

@keyframes laserFire {
    0% { opacity: 0; }
    20%, 75% { opacity: 1; }
    100% { opacity: 0; }
}

.target {
    position: absolute;
    width: min(230px, 34%);
    min-height: 86px;
    padding: 12px;
    background: #fff4c7;
    font-size: 17px;
    transition: transform 0.3s ease;
}

.target.fall-away {
    animation: fallAway 0.55s ease forwards;
}

@keyframes fallAway {
    to { opacity: 0.35; transform: translateY(70px) rotate(18deg); }
}

.float-0 { top: 62px; left: 10%; }
.float-1 { top: 122px; right: 9%; }
.float-2 { bottom: 162px; left: 24%; }
.float-3 { bottom: 68px; right: 12%; }

.water {
    background: linear-gradient(#bde7ff 0 38%, #76d5e6 38% 100%);
}

.bubble-cannon {
    position: absolute;
    left: 26px;
    bottom: 30px;
    font-size: 58px;
}

.bubble {
    position: absolute;
    width: min(210px, 34%);
    min-height: 92px;
    padding: 12px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    transition: transform 0.3s ease;
}

.bubble.popped {
    animation: popBubble 0.3s ease forwards;
}

@keyframes popBubble {
    to { transform: scale(1.35); opacity: 0.4; }
}

.bubble-0 { top: 48px; left: 12%; }
.bubble-1 { top: 92px; right: 10%; }
.bubble-2 { bottom: 136px; left: 22%; }
.bubble-3 { bottom: 54px; right: 15%; }

.island {
    background:
        radial-gradient(ellipse at 50% 70%, #ffe39a 0 34%, transparent 35%),
        linear-gradient(#a7e8ff 0 54%, #55c9bd 54% 100%);
}

.map-path {
    position: absolute;
    inset: 110px 70px 120px;
    border: 6px dashed rgba(23, 33, 43, 0.28);
    border-radius: 45%;
    transform: rotate(-8deg);
}

.chest {
    position: absolute;
    display: grid;
    gap: 5px;
    width: min(190px, 32%);
    min-height: 110px;
    place-items: center;
    padding: 10px;
    background: #fff4c7;
}

.chest span {
    font-size: 34px;
}

.chest.open-chest {
    transform: translateY(-8px);
}

.chest small {
    color: var(--muted);
}

.chest-0 { top: 44px; left: 12%; }
.chest-1 { top: 78px; right: 10%; }
.chest-2 { bottom: 88px; left: 18%; }
.chest-3 { bottom: 54px; right: 13%; }

.duel {
    background:
        linear-gradient(transparent 0 68%, rgba(112, 193, 91, 0.85) 68% 100%),
        linear-gradient(#ffe7ed, #fff8dd);
}

.wizard,
.monster {
    position: absolute;
    top: 70px;
    font-size: 70px;
}

.wizard { left: 38px; }
.monster { right: 48px; }

.spell-line {
    position: absolute;
    top: 135px;
    left: 120px;
    right: 130px;
    height: 8px;
    border-radius: 8px;
    background: repeating-linear-gradient(90deg, var(--pink) 0 16px, var(--yellow) 16px 32px);
    animation: shimmer 0.9s linear infinite;
}

@keyframes shimmer {
    from { background-position: 0; }
    to { background-position: 32px; }
}

.spell-grid {
    position: absolute;
    left: 24px;
    right: 24px;
    bottom: 28px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.spell {
    min-height: 76px;
    padding: 12px;
    background: #ffffff;
    font-size: 17px;
    overflow-wrap: anywhere;
}

.platform-world {
    background:
        linear-gradient(transparent 0 74%, #694f35 74% 100%),
        linear-gradient(#bde7ff 0%, #f7fdff 58%, #bde7ff 100%);
}

.runner {
    position: absolute;
    left: 28px;
    bottom: 118px;
    z-index: 3;
    font-size: 56px;
    animation: runBounce 0.8s infinite;
    transition: left 0.42s ease, bottom 0.42s ease, transform 0.2s ease;
}

@keyframes runBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}

.runner.jumping {
    transform: translateY(-22px) scale(1.08);
}

.ground {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 120px;
    background: linear-gradient(var(--grass), #4d9c3a);
}

.platform {
    position: absolute;
    min-height: 74px;
    width: min(230px, 36%);
    padding: 10px;
    background: #fff4c7;
    font-size: 16px;
    overflow-wrap: anywhere;
}

.platform-0 { top: 70px; left: 12%; }
.platform-1 { top: 156px; right: 12%; }
.platform-2 { bottom: 176px; left: 24%; }
.platform-3 { bottom: 80px; right: 9%; }

.sorter-stage,
.puzzle-stage {
    background: #ffffff;
}

.factory {
    background:
        linear-gradient(transparent 0 64%, rgba(23, 33, 43, 0.12) 64% 100%),
        linear-gradient(#e9f7ff, #fff8dd);
}

.conveyor {
    position: absolute;
    left: 0;
    right: 0;
    top: 118px;
    height: 382px;
    border-top: 4px solid var(--ink);
    border-bottom: 4px solid var(--ink);
    background:
        linear-gradient(transparent 0 23%, rgba(23, 33, 43, 0.22) 23% 25%, transparent 25% 48%, rgba(23, 33, 43, 0.22) 48% 50%, transparent 50% 73%, rgba(23, 33, 43, 0.22) 73% 75%, transparent 75%),
        repeating-linear-gradient(90deg, #8f9aa4 0 36px, #6d7780 36px 72px);
    animation: beltMove 0.75s linear infinite;
}

@keyframes beltMove {
    from { background-position: 0 0; }
    to { background-position: 72px 0; }
}

.word-crate {
    position: absolute;
    left: -220px;
    width: min(190px, 32%);
    min-height: 78px;
    display: grid;
    gap: 4px;
    place-items: center;
    padding: 10px;
    background: #fff4c7;
    animation: crateRide 7s linear infinite;
}

.word-crate span {
    font-size: 21px;
}

.word-crate small {
    color: var(--muted);
}

.crate-0 { top: 128px; animation-delay: 0s; }
.crate-1 { top: 218px; animation-delay: 0.35s; }
.crate-2 { top: 308px; animation-delay: 0.7s; }
.crate-3 { top: 398px; animation-delay: 1.05s; }

@keyframes crateRide {
    from { transform: translateX(0); }
    to { transform: translateX(calc(100vw + 360px)); }
}

.word-crate.sorted {
    border-color: var(--green);
    background: #c8f3cb;
    animation-play-state: paused;
}

.word-crate.drop-crate {
    animation: crateDrop 0.55s ease forwards;
}

@keyframes crateDrop {
    to { transform: translateY(150px) rotate(18deg); opacity: 0.45; }
}

.memory-board {
    align-self: center;
    justify-self: center;
    width: min(92%, 620px);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.memory-card {
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    padding: 8px;
    background: var(--teal);
    color: #ffffff;
    font-size: 42px;
    overflow: hidden;
}

.memory-card em {
    display: none;
    color: var(--ink);
    font-size: clamp(13px, 2vw, 18px);
    font-style: normal;
    overflow-wrap: anywhere;
}

.memory-card.open,
.memory-card.done {
    background: #fff4c7;
}

.memory-card.open span,
.memory-card.done span {
    display: none;
}

.memory-card.open em,
.memory-card.done em {
    display: block;
}

.memory-card.done {
    border-color: var(--green);
}

.word-lab {
    display: grid;
    align-content: center;
    gap: 14px;
    padding: 24px;
}

.builder-help {
    display: grid;
    gap: 7px;
    padding: 12px 14px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: #fff8dd;
    font-size: 16px;
    line-height: 1.32;
}

.builder-help.needs-help {
    background: #ffe7ed;
}

.sentence-track {
    min-height: 116px;
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    gap: 10px;
    padding: 16px;
    border: 3px dashed var(--teal);
    border-radius: 8px;
    background: #dff7f2;
}

.pieces {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.word-piece {
    min-height: 52px;
    padding: 10px 14px;
    background: #ffffff;
    font-size: 18px;
}

.word-piece.helped-piece {
    border-color: var(--teal);
    background: #dff7f2;
}

.builder-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.action-btn {
    min-height: 48px;
    padding: 10px 18px;
    background: var(--yellow);
    font-size: 16px;
}

.action-btn.ghost {
    background: #ffffff;
}

.tiny-help {
    width: fit-content;
    min-height: 38px;
    padding: 8px 12px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: var(--yellow);
    font-weight: 900;
    cursor: pointer;
}

.correct {
    background: #c8f3cb !important;
    border-color: var(--green) !important;
}

.wrong {
    background: #ffd5d5 !important;
    border-color: var(--red) !important;
}

[data-answer]:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

.success-burst {
    position: absolute;
    left: 50%;
    top: 42%;
    z-index: 8;
    transform: translate(-50%, -50%);
    padding: 16px 24px;
    border: 3px solid var(--ink);
    border-radius: 8px;
    background: var(--yellow);
    font-size: 30px;
    font-weight: 900;
    animation: burst 0.9s ease forwards;
}

@keyframes burst {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
    30% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
    100% { opacity: 0; transform: translate(-50%, -68%) scale(1); }
}

.inline-feedback {
    position: absolute;
    left: 50%;
    bottom: 16px;
    z-index: 9;
    width: min(90%, 760px);
    transform: translateX(-50%);
    padding: 14px 16px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: var(--shadow);
    font-size: 17px;
    font-weight: 850;
}

.rule-overlay {
    position: absolute;
    inset: 18px;
    z-index: 20;
    display: grid;
    place-content: center;
    gap: 14px;
    padding: 18px;
    background: rgba(255, 255, 255, 0.94);
    border: 3px solid var(--ink);
    border-radius: 8px;
}

.end-screen {
    min-height: 560px;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 14px;
    padding: 24px;
    text-align: center;
}

.end-screen .rule-card {
    max-width: 680px;
    text-align: left;
}

.end-badge {
    font-size: 72px;
}

.popup {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    place-items: center;
    padding: 18px;
    background: rgba(23, 33, 43, 0.58);
}

.popup.show {
    display: grid;
}

.popup-content {
    width: min(100%, 430px);
    display: grid;
    gap: 12px;
    padding: 24px;
    border: 3px solid var(--ink);
    border-radius: 8px;
    background: #ffffff;
    text-align: center;
    box-shadow: var(--shadow);
}

.popup h2 {
    margin: 0;
    color: var(--pink);
}

.reward {
    display: flex;
    justify-content: center;
    gap: 18px;
    margin: 8px 0;
}

.reward-xp,
.reward-stars {
    font-size: 24px;
    font-weight: 900;
}

.popup-btn {
    min-height: 48px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: var(--yellow);
    color: var(--ink);
    font-size: 18px;
    font-weight: 900;
    cursor: pointer;
}

@media (max-width: 820px) {
    .game-header {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .game-stats {
        order: 3;
        width: 100%;
        justify-content: space-between;
    }

    .stat-item {
        flex: 1;
        min-width: 0;
    }

    .screen {
        padding: 14px;
    }

    .mascot-welcome {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .game-info {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .game-canvas {
        min-height: 740px;
    }

    .mini-stage {
        min-height: 740px;
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }

    .lesson-column {
        border-right: 0;
        border-bottom: 3px solid var(--ink);
        padding: 12px;
    }

    .rule-card.compact ul {
        display: none;
    }

    .play-field {
        min-height: 440px;
    }

    .lane {
        left: 8%;
        right: 8%;
    }

    .spell-grid {
        grid-template-columns: 1fr;
    }

    .target,
    .bubble,
    .platform,
    .chest,
    .word-crate {
        width: 40%;
        font-size: 14px;
    }

    .memory-board {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        padding: 14px 0;
    }

    .word-lab {
        align-content: start;
    }
}

@media (max-width: 520px) {
    .avatar {
        width: 44px;
        height: 44px;
    }

    .xp-bar {
        width: 128px;
    }

    .rainbow-text {
        font-size: 34px;
    }

    .menu-buttons,
    .game-grid {
        grid-template-columns: 1fr;
    }

    .target,
    .bubble,
    .platform,
    .chest,
    .word-crate {
        width: 45%;
        min-height: 84px;
    }

    .wizard,
    .monster {
        font-size: 52px;
    }

    .spell-line {
        left: 80px;
        right: 88px;
    }
}
