:root {
    --ink: #2c2416;
    --muted: #6f5b45;
    --paper: #fffaf2;
    --honey: #f0a202;
    --honey-deep: #c47d00;
    --leaf: #2f9e6b;
    --line: #f0e2cc;
    --shadow: 0 10px 28px rgba(80, 50, 20, 0.08);
    --radius: 28px;
}

* { box-sizing: border-box; }

html { touch-action: manipulation; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    font-family: "Nunito", "Trebuchet MS", "Segoe UI", sans-serif;
    font-size: 1.125rem;
    line-height: 1.45;
    background: #fff6e8;
}

body.page-map {
    background: linear-gradient(#8fd3f4 0%, #e7f7ff 24%, #fff8ea 52%, #d7f0b8 100%);
    background-attachment: fixed;
}

body.theme-meadow { background: linear-gradient(#b9ebff 0%, #fff8ea 46%, #c6eb9a 100%); background-attachment: fixed; }
body.theme-home { background: linear-gradient(#ffd8c4 0%, #fff7f1 46%, #ffd0e2 100%); background-attachment: fixed; }
body.theme-forest { background: linear-gradient(#c9ecb8 0%, #f3ffea 42%, #8fbf78 100%); background-attachment: fixed; }
body.theme-space { background: linear-gradient(#1c2a5a 0%, #3d4d86 46%, #d9e2ff 100%); background-attachment: fixed; color: #fffaf2; }
body.theme-pirate { background: linear-gradient(#8fd0ea 0%, #fff4dd 48%, #f2c98a 100%); background-attachment: fixed; }
body.theme-dino { background: linear-gradient(#d7ef9a 0%, #fff8e4 46%, #b7d48a 100%); background-attachment: fixed; }
body.theme-farm { background: linear-gradient(#c7ebff 0%, #fff6d8 48%, #d2ea9a 100%); background-attachment: fixed; }
body.theme-sea { background: linear-gradient(#7fd4f2 0%, #e5f8ff 42%, #9fd0ea 100%); background-attachment: fixed; }
body.theme-magic { background: linear-gradient(#e7d4ff 0%, #fff4fb 46%, #ffd0ea 100%); background-attachment: fixed; }
body.theme-rescue { background: linear-gradient(#ffd0c4 0%, #fff6f2 48%, #d5e6ff 100%); background-attachment: fixed; }

body.theme-space .prompt,
body.theme-space h1,
body.theme-space .back-link a,
body.theme-space .hint,
body.theme-space .eyebrow { color: #fffaf2; }

h1, h2, .brand, .praise, .world-title, .choice.number, .countdown {
    font-family: "Fredoka", "Trebuchet MS", "Segoe UI", sans-serif;
    font-weight: 700;
}

h1 { font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.05; margin: 0 0 .4rem; }
h2 { font-size: 1.45rem; margin: 0 0 .7rem; }
p { margin: .4rem 0; }

a { color: inherit; }

button, input { font: inherit; color: var(--ink); }

.wrap {
    width: min(760px, calc(100% - 1.4rem));
    margin: 0 auto;
}

main.wrap { position: relative; padding-bottom: 3rem; }

.skip {
    position: absolute;
    left: -999px;
    top: .5rem;
    background: white;
    padding: .4rem .7rem;
    z-index: 30;
}

.skip:focus { left: .6rem; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 15;
    background: rgba(255, 250, 242, .92);
    color: var(--ink);
    backdrop-filter: blur(10px);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .6rem;
    padding: .7rem 0;
}

.brand {
    text-decoration: none;
    font-size: 1.25rem;
    white-space: nowrap;
}

.top-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: .4rem;
}

.pill, .text-btn, .icon-btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    min-height: 42px;
    border: 0;
    border-radius: 999px;
    background: white;
    padding: .25rem .7rem;
    font-weight: 800;
    box-shadow: 0 4px 0 rgba(80, 50, 20, .05);
}

.text-btn, .icon-btn { cursor: pointer; }
.icon-btn { width: 44px; justify-content: center; padding: 0; }
form { margin: 0; }

.avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: white;
    font-weight: 800;
    flex: none;
}

.pill .avatar { width: 28px; height: 28px; font-size: .85rem; }

.hero { padding: 1.2rem 0 .4rem; position: relative; z-index: 1; }
.eyebrow { font-weight: 800; color: #b86b00; letter-spacing: .02em; }
.lead { font-size: 1.15rem; max-width: 38rem; }

.floaters { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.floaters span { position: absolute; font-size: 1.7rem; opacity: .85; animation: drift 7s ease-in-out infinite; }
.floaters span:nth-child(1) { top: 8px; left: 2%; }
.floaters span:nth-child(2) { top: 70px; right: 6%; animation-delay: .4s; }
.floaters span:nth-child(3) { top: 150px; left: 8%; animation-delay: .8s; }
.floaters span:nth-child(4) { top: 18px; right: 28%; animation-delay: 1s; }
.floaters span:nth-child(5) { top: 190px; right: 4%; animation-delay: .2s; }

@keyframes drift {
    50% { transform: translateY(-8px); }
}

.medal-board, .world-path, .panel, .task-path, .stage { position: relative; z-index: 1; }

.medals {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
    gap: .5rem;
    padding: 0;
    margin: 0 0 1.2rem;
}

.medal {
    background: white;
    border-radius: 18px;
    text-align: center;
    padding: .4rem .15rem .3rem;
    font-size: 1.5rem;
    box-shadow: var(--shadow);
}

.medal small { display: block; font-size: .8rem; }
.medal.locked { opacity: .55; }

.sr {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.world-path, .task-path, .player-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .85rem; }

.world-card, .task-card, .player-pick, .panel {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.world-card {
    display: flex;
    align-items: center;
    gap: .75rem;
    min-height: 112px;
    padding: .9rem 1rem;
    text-decoration: none;
    color: var(--ink);
}

.world-card.theme-meadow { background: linear-gradient(160deg, #fff4c4, #d9f5c8); }
.world-card.theme-home { background: linear-gradient(160deg, #ffe3d2, #ffd4e4); }
.world-card.theme-forest { background: linear-gradient(160deg, #d9f2cf, #b7e0c2); }
.world-card.theme-space { background: linear-gradient(160deg, #d9e4ff, #c9d4f5); }
.world-card.theme-pirate { background: linear-gradient(160deg, #d8f3ff, #ffe7b8); }
.world-card.theme-dino { background: linear-gradient(160deg, #e5f6c8, #cfe7a4); }
.world-card.theme-farm { background: linear-gradient(160deg, #fff0c8, #d9f0b0); }
.world-card.theme-sea { background: linear-gradient(160deg, #d5f4ff, #c9e7ff); }
.world-card.theme-magic { background: linear-gradient(160deg, #f3e1ff, #ffe3f2); }
.world-card.theme-rescue { background: linear-gradient(160deg, #ffe1d6, #d9ecff); }

.world-card.is-locked { background: #f4f0ea; color: #7d7368; }
.world-card.is-current { box-shadow: 0 0 0 4px var(--honey), var(--shadow); }

.world-emoji { font-size: 2.5rem; line-height: 1; }
.world-copy, .task-copy { display: grid; flex: 1; min-width: 0; }
.world-kicker, .world-progress, .task-kicker, .hint, .replay-note { color: var(--muted); font-weight: 800; font-size: .92rem; }
.world-title { font-size: 1.35rem; }
.world-state { font-weight: 800; white-space: nowrap; }

@media (min-width: 700px) {
    .world-path li:nth-child(even) .world-card { margin-left: 9%; }
    .world-path li:nth-child(odd) .world-card { margin-right: 9%; }
}

.task-card {
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .7rem;
    text-decoration: none;
    color: inherit;
}

.task-node {
    width: 64px;
    height: 64px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #fff4d2;
    font-size: 1.6rem;
}

.state-done .task-node { background: #ffe08a; }
.state-current .task-node { background: white; box-shadow: 0 0 0 4px var(--honey); }
.state-locked { opacity: .62; }
.task-title { font-weight: 800; }

.panel { padding: 1.1rem 1.15rem 1.2rem; }
.center-card, .world-hero { text-align: center; }
.big-emoji, .medal-hero { font-size: 4.2rem; line-height: 1; margin: .2rem 0; }
.medal-banner {
    display: inline-block;
    background: white;
    border-radius: 999px;
    padding: .45rem .9rem;
    font-weight: 800;
}

.back-link { font-weight: 800; margin-top: .8rem; }
.back-link a { text-decoration: none; }
.prompt { font-size: 1.4rem; font-weight: 800; }

.player-pick {
    width: 100%;
    display: flex;
    align-items: center;
    gap: .8rem;
    text-align: left;
    border: 0;
    border-radius: 22px;
    padding: .75rem;
    cursor: pointer;
}

.player-pick strong, .player-pick small { display: block; }
.player-pick small { color: var(--muted); font-weight: 800; }

.name-form, .stage { display: grid; gap: .85rem; }
.name-form label { font-weight: 800; }
.name-form input {
    width: 100%;
    border: 3px solid #f0d7a2;
    border-radius: 16px;
    padding: .9rem 1rem;
    font-size: 1.3rem;
    background: white;
}

.flash {
    background: white;
    border-radius: 16px;
    padding: .75rem 1rem;
    font-weight: 800;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    min-height: 56px;
    padding: .75rem 1.3rem;
    border: 0;
    border-radius: 999px;
    background: var(--honey);
    color: var(--ink);
    font-weight: 800;
    text-decoration: none;
    box-shadow: 0 5px 0 var(--honey-deep);
    cursor: pointer;
}

.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--honey-deep); }
.btn-ghost { background: white; box-shadow: 0 5px 0 #ead9bf; }
.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: center; }
.btn-row .btn { flex: 1; }

.choice-grid, .compare, .hive-row, .pairs, .math-groups {
    display: grid;
    gap: .75rem;
}

.choice-grid { grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); }
.numbers { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
.compare, .math-groups { grid-template-columns: 1fr 1fr; }
.pairs { grid-template-columns: repeat(3, minmax(0, 1fr)); justify-items: center; }
.hive-row { grid-template-columns: repeat(3, minmax(0, 1fr)); justify-items: center; align-items: end; }

.choice, .compare-side, .dropzone, .pad-btn {
    border: 4px solid white;
    background: white;
    border-radius: 24px;
    box-shadow: 0 8px 0 rgba(80, 50, 20, .08);
    cursor: pointer;
}

.choice, .compare-side {
    min-height: 124px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .15rem;
    padding: .6rem;
}

.choice .emoji, .compare-side .emoji, .dropzone .emoji { font-size: 3rem; line-height: 1.1; }
.choice .label, .compare-side .label, .dropzone .label, .math-label { font-weight: 800; color: var(--muted); }
.choice.number { font-size: 2.5rem; }
.choice.is-right, .compare-side.is-right, .hive.is-right .hive-body { border-color: var(--leaf); background: #e7f8ef; }
.choice.is-wrong, .compare-side.is-wrong, .hive.is-wrong, .slot.is-wrong { animation: nudge .35s; }

@keyframes nudge {
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.crowd, .memory-row, .seq {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    justify-content: center;
    align-items: center;
    font-size: 2.3rem;
}

.crowd, .math-group {
    background: white;
    border-radius: 24px;
    padding: .8rem;
}

.math-label { text-align: center; margin: 0; }
.countdown { font-size: 3rem; text-align: center; margin: 0; }

.maze-grid {
    --cols: 5;
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--cols), clamp(46px, 14vw, 68px));
    gap: 6px;
    justify-content: center;
    touch-action: none;
    margin: 0 auto;
}

.cell {
    width: clamp(46px, 14vw, 68px);
    height: clamp(46px, 14vw, 68px);
    border-radius: 14px;
    background: rgba(255, 255, 255, .88);
    display: grid;
    place-items: center;
    font-size: 1.7rem;
}

.cell.wall { background: #7dba62; box-shadow: inset 0 -6px 0 rgba(40, 90, 30, .18); }
.cell.goal { background: #fff3c4; }
.actor {
    position: absolute;
    left: 0;
    top: 0;
    width: clamp(46px, 14vw, 68px);
    height: clamp(46px, 14vw, 68px);
    display: grid;
    place-items: center;
    font-size: 1.8rem;
    transition: left .16s ease, top .16s ease;
    pointer-events: none;
    z-index: 2;
}

.arrow-pad {
    display: grid;
    width: max-content;
    margin: .2rem auto 0;
    grid-template-columns: 74px 74px 74px;
    grid-template-areas: ". up ." "left down right";
    gap: .45rem;
}

.arrow-pad .up { grid-area: up; }
.arrow-pad .left { grid-area: left; }
.arrow-pad .down { grid-area: down; }
.arrow-pad .right { grid-area: right; }

.pad { display: flex; justify-content: center; gap: .8rem; }
.pad-btn {
    min-width: 74px;
    min-height: 64px;
    font-size: 1.8rem;
    padding: 0;
}

.hive { width: 100%; max-width: 130px; border: 0; background: transparent; padding: 0; cursor: pointer; font: inherit; }
.hive-top { display: block; height: 26px; margin: 0 12px -6px; border-radius: 40px 40px 8px 8px; background: #d36b4a; position: relative; z-index: 1; }
.hive-body {
    display: block;
    height: 132px;
    border-radius: 18px 18px 40px 40px;
    border: 4px solid #c47d00;
    background: repeating-linear-gradient(#f6c445, #f6c445 16px, #e39b12 16px, #e39b12 22px);
    position: relative;
}
.hive-door {
    position: absolute;
    width: 34px;
    height: 26px;
    left: 50%;
    bottom: 8px;
    transform: translateX(-50%);
    background: #5a3718;
    border-radius: 16px 16px 6px 6px;
}
.hive-bees { position: absolute; left: 0; right: 0; bottom: 36px; text-align: center; font-size: 1.25rem; }

.puzzle-layout { display: grid; gap: .8rem; justify-items: center; }
.puzzle-ref {
    width: 140px;
    height: 140px;
    border-radius: 24px;
    border: 4px solid white;
    background-size: cover;
    box-shadow: var(--shadow);
}
.puzzle-board { display: grid; grid-template-columns: repeat(2, clamp(84px, 22vw, 120px)); gap: 8px; }
.tray { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 96px; }
.slot, .piece {
    width: clamp(84px, 22vw, 120px);
    height: clamp(84px, 22vw, 120px);
    border-radius: 18px;
}
.slot {
    border: 3px dashed #e0a106;
    background: rgba(255, 255, 255, .55);
    display: grid;
    place-items: center;
    position: relative;
}
.piece {
    border: 3px solid #f0d7a2;
    background-color: #fffaf2;
    padding: 0;
    font-size: 2.4rem;
    touch-action: none;
    cursor: grab;
}
.slot .piece { width: 100%; height: 100%; border: 0; border-radius: 14px; }
.piece.is-selected { outline: 4px solid var(--leaf); }
.piece.is-dragging { cursor: grabbing; }
.ghost { position: absolute; font-size: 2rem; opacity: .28; }
.draggable { touch-action: none; }

.dropzone {
    width: min(100%, 240px);
    min-height: 180px;
    margin: 0 auto;
    justify-content: center;
}
.dropzone .emoji { font-size: 4.2rem; }

.card {
    width: 100%;
    max-width: 130px;
    aspect-ratio: 3 / 4;
    border: 0;
    padding: 0;
    background: transparent;
    perspective: 700px;
    cursor: pointer;
}
.card-inner {
    display: block;
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform .35s ease;
}
.card.is-up .card-inner, .card.is-matched .card-inner { transform: rotateY(180deg); }
.card-face {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    border-radius: 18px;
    backface-visibility: hidden;
    font-size: 2.5rem;
}
.card-back { background: var(--honey); color: white; box-shadow: 0 8px 0 var(--honey-deep); }
.card-front { background: white; transform: rotateY(180deg); border: 4px solid #ffe08a; }
.card.is-matched .card-front { background: #e7f8ef; border-color: var(--leaf); }

.seq .q, .memory-row .q {
    width: 1.15em;
    height: 1.15em;
    border: 3px dashed #e0a106;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, .7);
}
.loot { font-size: 1.7rem; letter-spacing: .08em; min-height: 2.4em; }

.hud {
    display: flex;
    justify-content: space-between;
    gap: .6rem;
    background: white;
    border-radius: 16px;
    padding: .65rem .85rem;
    font-weight: 800;
}
.timebar { height: 12px; background: rgba(255, 255, 255, .7); border-radius: 99px; overflow: hidden; }
.timebar span { display: block; height: 100%; width: 100%; background: var(--honey); }

.pop-field, .catcher-field {
    position: relative;
    height: min(58vh, 430px);
    border-radius: 28px;
    overflow: hidden;
    background: linear-gradient(#d7f3ff, #f7fff2 58%, #b7e39a 58%);
    box-shadow: var(--shadow);
}
.catcher-field { touch-action: none; }
.pop {
    position: absolute;
    width: 76px;
    height: 76px;
    border: 0;
    border-radius: 22px;
    background: white;
    font-size: 2.2rem;
    box-shadow: 0 6px 0 rgba(80, 50, 20, .1);
    cursor: pointer;
    animation: pop .18s ease;
}
.catcher-player {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 3.2rem;
    line-height: 1;
    z-index: 2;
}
.falling {
    position: absolute;
    font-size: 2.3rem;
    line-height: 1;
    pointer-events: none;
}

@keyframes pop {
    from { transform: scale(.6); }
    to { transform: scale(1); }
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 1rem;
    transform: translateX(-50%);
    z-index: 40;
    max-width: min(92vw, 440px);
    background: white;
    color: var(--ink);
    border-radius: 999px;
    padding: .8rem 1.1rem;
    font-weight: 800;
    text-align: center;
    box-shadow: 0 12px 30px rgba(0, 0, 0, .14);
}

.modal-back[hidden],
.toast[hidden] { display: none !important; }

.modal-back {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(44, 36, 22, .46);
}

.modal-card {
    width: min(100%, 440px);
    background: white;
    color: var(--ink);
    border-radius: 32px;
    padding: 1.3rem 1.15rem 1.15rem;
    text-align: center;
    position: relative;
    z-index: 1;
}

.praise { font-size: clamp(1.8rem, 5vw, 2.35rem); margin: .15rem 0 .35rem; }
.star-burst { font-size: 1.7rem; margin: .2rem 0 .4rem; }
.medal-hero { animation: medal-pop .45s ease; }

@keyframes medal-pop {
    0% { transform: scale(.45); }
    70% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.confetti span {
    position: absolute;
    top: -8%;
    font-size: 1.5rem;
    animation: fall 1.15s ease-in forwards;
}

@keyframes fall {
    to { transform: translateY(105vh) rotate(18deg); opacity: .15; }
}

.sql {
    white-space: pre-wrap;
    background: #2c2416;
    color: #fff6e4;
    border-radius: 16px;
    padding: 1rem;
    overflow: auto;
}

.stage, .choice, .maze-grid, .piece, .card, .hive, .pop, .pad-btn {
    user-select: none;
    -webkit-user-select: none;
}

:focus-visible {
    outline: 3px solid #2c2416;
    outline-offset: 3px;
}

@media (max-width: 560px) {
    .compare, .math-groups, .hive-row { grid-template-columns: 1fr; }
    .hive { max-width: 180px; }
    .topbar-inner { align-items: flex-start; }
    .world-card { align-items: flex-start; }
    .world-state { padding-top: .35rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}
