:root {
    --bg: #fff4dc;
    --ink: #4a3b2a;
    --wood: #e9b77a;
    --wood-dark: #c98b4d;
    --hole: #6b4423;
    --s: 22vmin;              /* размер фигуры в раунде — задаётся из JS */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    background: var(--bg);
    color: var(--ink);
    font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
}

#app { position: fixed; inset: 0; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

/* ---------- главное меню ---------- */
.home { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: safe center; gap: 2.5vmin; padding: 3vmin; overflow-y: auto; touch-action: pan-y; }
.home h1 { margin: 0; font-size: 6.5vmin; letter-spacing: .02em; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2.4vmin; width: min(100%, 150vmin); }
@media (orientation: portrait) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
    border: 0; border-radius: 5vmin; padding: 2.4vmin 1.5vmin 2vmin;
    background: #fff; box-shadow: 0 1.2vmin 0 rgba(0,0,0,.08), 0 2vmin 5vmin rgba(160,110,40,.15);
    display: flex; flex-direction: column; align-items: center; gap: 1.5vmin;
    font: inherit; color: inherit; cursor: pointer; transition: transform .15s;
}
.tile:active { transform: scale(.94); }
.tile .ico { font-size: 11vmin; line-height: 1; height: 12vmin; display: flex; align-items: center; justify-content: center; }
.tile .ico svg { width: 11vmin; height: 11vmin; }
.tile > span { font-size: 3vmin; font-weight: 800; opacity: .75; white-space: nowrap; }
.tile:nth-child(6n+1) { background: #ffe1e1; } .tile:nth-child(6n+2) { background: #e0f2ff; } .tile:nth-child(6n+3) { background: #fff1c4; }
.tile:nth-child(6n+4) { background: #e2f8e5; } .tile:nth-child(6n+5) { background: #efe5ff; } .tile:nth-child(6n) { background: #ffe6f2; }
.ico-half { display: inline-block; clip-path: inset(0 50% 0 0); position: relative; }
.install-hint { font-size: 2.6vmin; opacity: .55; text-align: center; max-width: 90vmin; }

/* ---------- экран игры ---------- */
.game { flex: 1; display: flex; flex-direction: column; position: relative; min-height: 0; overflow: hidden; }
.home-btn {
    position: absolute; top: 2vmin; left: 2vmin; z-index: 50;
    width: 11vmin; height: 11vmin; border-radius: 50%; border: 0; padding: 0;
    background: rgba(255,255,255,.7); font-size: 5.5vmin; cursor: pointer;
    display: grid; place-items: center;
}
.home-btn svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.home-btn circle { fill: none; stroke: #ff8a3c; stroke-width: 6; stroke-dasharray: 289; stroke-dashoffset: 289; }
.home-btn.hold circle { transition: stroke-dashoffset .8s linear; stroke-dashoffset: 0; }
.hold-tip { position: absolute; top: 4.5vmin; left: 15vmin; z-index: 50; font-size: 2.8vmin; background: #fff; padding: 1vmin 2vmin; border-radius: 3vmin; opacity: 0; transition: opacity .3s; pointer-events: none; }
.hold-tip.show { opacity: .9; }

.board { flex: 1; display: flex; flex-direction: column; justify-content: space-evenly; align-items: center; padding: 12vmin 2vmin 3vmin; gap: 3vmin; }
.row { display: flex; justify-content: center; align-items: center; gap: calc(var(--s) * .28); flex-wrap: wrap; max-width: min(100%, var(--row-w, 100vw)); }

/* ---------- фигуры ---------- */
.sorter { background: var(--wood); border-radius: 5vmin; padding: calc(var(--s) * .25) calc(var(--s) * .3); box-shadow: inset 0 -1.5vmin 0 var(--wood-dark), 0 2vmin 4vmin rgba(120,70,20,.25); }
.slot { position: relative; width: var(--s); height: var(--s); }
.slot > svg.hole { width: 100%; height: 100%; fill: var(--hole); filter: drop-shadow(0 .6vmin 0 rgba(255,255,255,.35)); }
.piece { width: var(--s); height: var(--s); touch-action: none; cursor: grab; position: relative; z-index: 2; will-change: transform; }
.piece svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 1vmin 0 rgba(0,0,0,.18)); overflow: visible; }
.piece.dragging { z-index: 40; cursor: grabbing; }
.piece.dragging svg { filter: drop-shadow(0 2.5vmin 1.5vmin rgba(0,0,0,.25)); }
.piece.back { transition: transform .35s cubic-bezier(.3,1.5,.5,1); }
.piece.fly { transition: transform .22s ease-out; }
.slot > .piece.placed { position: absolute; inset: 0; animation: settle .35s ease-out; }
.slot > .piece.placed svg { filter: none; }

/* ---------- тени ---------- */
.emoji { font-size: calc(var(--s) * .8); line-height: 1; width: var(--s); height: var(--s); display: grid; place-items: center; }
.shadow { border-radius: 50%; background: rgba(255,255,255,.55); }
.shadow > .sil { filter: brightness(0); opacity: .22; font-size: calc(var(--s) * .8); line-height: 1; }
.shadow.filled > .sil { display: none; }
.shadow > .piece.placed { position: absolute; inset: 0; }
.slot.shadow { display: grid; place-items: center; }

/* ---------- цвета ---------- */
.bucket { position: relative; width: calc(var(--s) * 1.15); height: calc(var(--s) * 1.15); display: flex; align-items: flex-end; justify-content: center; }
.bucket > svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.bucket .inside { position: relative; z-index: 3; display: flex; flex-wrap: wrap-reverse; justify-content: center; width: 70%; margin-bottom: 22%; gap: 1%; }
.bucket .inside .piece { width: calc(var(--s) * .38); height: calc(var(--s) * .38); }
.ball { width: calc(var(--s) * .7); height: calc(var(--s) * .7); }

/* ---------- кто как говорит ---------- */
.zoo { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); gap: 2vmin; padding: 14vmin 4vmin 4vmin; align-items: center; justify-items: center; }
@media (orientation: portrait) { .zoo { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(3, 1fr); } }
.critter { position: relative; font-size: 22vmin; line-height: 1; border: 0; background: none; padding: 0; cursor: pointer; }
.critter.talk { animation: talk .6s ease-in-out; }
.bubble { position: absolute; left: 50%; top: -2vmin; transform: translate(-50%, -100%); background: #fff; border-radius: 4vmin; padding: 1.2vmin 3vmin; font-size: 5vmin; font-weight: 900; white-space: nowrap; box-shadow: 0 1vmin 3vmin rgba(0,0,0,.12); animation: bubble 1.4s ease-out forwards; pointer-events: none; z-index: 5; }
.next-btn { position: absolute; right: 3vmin; bottom: 3vmin; width: 14vmin; height: 14vmin; border-radius: 50%; border: 0; background: #ffd23f; font-size: 7vmin; box-shadow: 0 1vmin 0 #d9a800; cursor: pointer; }
.next-btn:active { transform: translateY(1vmin); box-shadow: none; }

/* ---------- шарики ---------- */
.sky { flex: 1; position: relative; overflow: hidden; background: linear-gradient(#bfe6ff, #fff4dc); }
.balloon { position: absolute; bottom: -30vmin; width: 18vmin; height: 22vmin; animation: rise linear forwards; touch-action: none; cursor: pointer; }
.balloon svg { width: 100%; height: 130%; overflow: visible; }
.score { position: absolute; top: 3vmin; right: 4vmin; font-size: 6vmin; font-weight: 900; z-index: 10; }

/* ---------- праздник ---------- */
.burst { position: fixed; left: 50%; top: 50%; pointer-events: none; z-index: 100; }
.burst i { position: absolute; font-style: normal; font-size: 7vmin; animation: fly 1.3s ease-out forwards; }
.cheer { position: fixed; left: 50%; top: 45%; transform: translate(-50%,-50%); font-size: 14vmin; font-weight: 900; color: #ff7a2f; text-shadow: 0 1vmin 0 #fff; pointer-events: none; z-index: 101; animation: cheer 1.6s ease-out forwards; white-space: nowrap; }
.pop i { position: absolute; width: 3vmin; height: 3vmin; border-radius: 50%; animation: fly .6s ease-out forwards; }

.shake { animation: shake .4s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-2vmin); } 75% { transform: translateX(2vmin); } }
@keyframes settle { 0% { transform: scale(1.15); } 60% { transform: scale(.94); } 100% { transform: scale(1); } }
@keyframes talk { 0%,100% { transform: scale(1) rotate(0); } 25% { transform: scale(1.18) rotate(-8deg); } 50% { transform: scale(1.1) rotate(6deg); } 75% { transform: scale(1.15) rotate(-4deg); } }
@keyframes bubble { 0% { opacity: 0; transform: translate(-50%,-80%) scale(.6); } 15% { opacity: 1; transform: translate(-50%,-100%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%,-140%); } }
@keyframes fly { to { transform: translate(var(--x), var(--y)) rotate(var(--r)) scale(.4); opacity: 0; } }
@keyframes cheer { 0% { opacity: 0; transform: translate(-50%,-50%) scale(.3); } 20% { opacity: 1; transform: translate(-50%,-50%) scale(1.1); } 30% { transform: translate(-50%,-50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%,-70%) scale(1); } }
@keyframes rise { to { transform: translateY(calc(-100dvh - 40vmin)) translateX(var(--sway, 0)); } }
@keyframes appear { from { opacity: 0; transform: scale(.5); } to { opacity: 1; transform: scale(1); } }
.appear { animation: appear .35s ease-out backwards; }

@media (prefers-reduced-motion: reduce) { * { animation-duration: .01s !important; transition-duration: .01s !important; } }

/* ---------- половинки ---------- */
.half-slot { border-radius: 4vmin; background: rgba(255,255,255,.6); }
.half-slot::after { content: ''; position: absolute; top: 8%; right: 6%; width: 42%; height: 84%; border: max(3px, .6vmin) dashed rgba(74,59,42,.25); border-radius: 0 3vmin 3vmin 0; border-left: 0; pointer-events: none; }
.half-slot.full::after { display: none; }
.half-l { clip-path: inset(0 50% 0 0); }
.half-r { clip-path: inset(-10% -10% -10% 50%); }
.half-slot.full .half-r { clip-path: inset(0 0 0 50%); }
.half-slot.whole { animation: settle .45s ease-out; background: rgba(255,255,255,.9); }

/* ---------- покорми ---------- */
.eater { display: grid; place-items: center; }
.eater .emoji.chomp { animation: chomp .9s ease-in-out; }
.eater.fed::before { content: '💛'; position: absolute; top: -6%; right: -4%; font-size: calc(var(--s) * .28); animation: appear .4s ease-out; }
.food { font-size: calc(var(--s) * .62); }
@keyframes chomp { 0%,100% { transform: scale(1); } 15%,45%,75% { transform: scale(1.15, .9); } 30%,60%,90% { transform: scale(.95, 1.08); } }

/* ---------- раскраска ---------- */
.paint { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2vmin; padding: 12vmin 3vmin 3vmin; min-height: 0; }
@media (orientation: landscape) { .paint { padding: 3vmin 18vmin; } .paint .picture { width: auto; height: min(calc(100dvh - 8vmin), calc(100vw - 38vmin)); } }
.picture { flex: 0 0 auto; aspect-ratio: 1; width: min(100%, calc(100dvh - 32vmin)); height: auto; touch-action: none; background: #fff; border-radius: 5vmin; box-shadow: 0 1.5vmin 4vmin rgba(160,110,40,.15); }
.picture .rg { fill: #fff; stroke: #4a3b2a; stroke-width: 3; stroke-linejoin: round; cursor: pointer; transition: fill .35s ease-out; }
.picture path:not(.rg), .picture .rays path { fill: none; stroke: #4a3b2a; stroke-width: 3; stroke-linecap: round; }
.picture .rg.splash { animation: splash .3s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes splash { 0% { transform: scale(.92); } 60% { transform: scale(1.04); } 100% { transform: scale(1); } }
.palette { display: grid; grid-template-columns: repeat(9, 1fr); gap: 1.6vmin; width: 100%; max-width: 110vmin; }
@media (orientation: landscape) { .palette { grid-template-columns: repeat(3, 1fr); width: auto; max-width: none; } }
@media (orientation: portrait) and (max-aspect-ratio: 3/5) { .palette { grid-template-columns: repeat(5, 1fr); } }
.paint-dot { aspect-ratio: 1; width: 100%; min-width: 9vmin; max-width: 14vmin; border-radius: 50%; border: max(3px, .7vmin) solid #fff; box-shadow: 0 .8vmin 0 rgba(0,0,0,.12); cursor: pointer; padding: 0; transition: transform .15s; justify-self: center; }
.paint-dot.on { transform: scale(1.18); box-shadow: 0 0 0 max(3px, .7vmin) #4a3b2a, 0 .8vmin 0 rgba(0,0,0,.12); }

/* ---------- ку-ку ---------- */
.meadow { align-items: flex-end; }
.bush { position: relative; width: calc(var(--s) * 1.1); height: var(--s); border: 0; background: none; padding: 0; cursor: pointer; }
.bush > svg { position: absolute; inset: auto 0 0 0; width: 100%; height: 82%; z-index: 2; transform-origin: 50% 100%; }
.bush .hider { position: absolute; left: 50%; bottom: 10%; width: auto; height: auto; font-size: calc(var(--s) * .62); transform: translate(-50%, 0) scale(.5); opacity: 0; transition: transform .45s cubic-bezier(.3,1.6,.5,1), opacity .2s; z-index: 1; }
.bush.found .hider { transform: translate(-50%, -62%) scale(1); opacity: 1; }
.bush.wiggle > svg { animation: wiggle .45s ease-in-out; }
.bush .bubble { z-index: 5; top: -40%; }
@keyframes wiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-5deg) scaleY(.94); } 75% { transform: rotate(5deg) scaleY(1.04); } }

/* ---------- ксилофон ---------- */
.music { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding: 10vmin 4vmin 6vmin; gap: 2vmin; min-height: 0; }
.dancer { font-size: 16vmin; line-height: 1; }
.dancer.hop { animation: hop .35s ease-out; }
@keyframes hop { 0%,100% { transform: translateY(0) rotate(0); } 40% { transform: translateY(-4vmin) rotate(-6deg); } 70% { transform: translateY(-1vmin) rotate(4deg); } }
.xylo { width: min(100%, 140vmin); height: 50%; min-height: 34vmin; display: flex; align-items: center; justify-content: center; gap: 2vmin; padding: 3vmin; background: linear-gradient(#c98b4d, #a96d36) center / 100% 12% no-repeat, linear-gradient(#c98b4d, #a96d36) center 85% / 100% 10% no-repeat; touch-action: none; }
.bar { position: relative; flex: 1; border-radius: 2.5vmin; box-shadow: inset 0 -1.5vmin 0 rgba(0,0,0,.15), 0 1vmin 2vmin rgba(0,0,0,.15); cursor: pointer; }
.bar i { position: absolute; left: 50%; width: 2.2vmin; height: 2.2vmin; margin-left: -1.1vmin; border-radius: 50%; background: rgba(255,255,255,.7); }
.bar i:first-child { top: 10%; } .bar i:last-child { bottom: 10%; }
.bar.ding { animation: ding .3s ease-out; }
@keyframes ding { 0% { transform: scale(1); filter: brightness(1.35); } 40% { transform: scale(.94, .97); } 100% { transform: scale(1); filter: none; } }
.note-fly { position: fixed; font-size: 8vmin; font-weight: 900; pointer-events: none; z-index: 60; transform: translate(-50%, 0); animation: notefly 1.2s ease-out forwards; text-shadow: 0 .4vmin 0 #fff; }
@keyframes notefly { to { transform: translate(-50%, -26vmin) rotate(20deg); opacity: 0; } }
.song-btn { background: #ff9ad5; box-shadow: 0 1vmin 0 #e06aa8; }

.next-btn.top { top: 2vmin; bottom: auto; }
.paint .palette { flex: 0 0 auto; }

.spark { position: fixed; z-index: 70; pointer-events: none; font-style: normal; font-size: 5vmin; transform: translate(-50%, -50%); animation: sparkfly .7s ease-out forwards; }
@keyframes sparkfly { to { transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(var(--r)) scale(.4); opacity: 0; } }
