/* ============ шрифты (локально) ============ */
@font-face { font-family: 'Montserrat'; font-weight: 600; font-display: swap; src: url('../fonts/montserrat-cyrillic-600.woff2') format('woff2'); unicode-range: U+0400-04FF, U+2116; }
@font-face { font-family: 'Montserrat'; font-weight: 600; font-display: swap; src: url('../fonts/montserrat-latin-600.woff2') format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: 'Montserrat'; font-weight: 800; font-display: swap; src: url('../fonts/montserrat-cyrillic-800.woff2') format('woff2'); unicode-range: U+0400-04FF, U+2116; }
@font-face { font-family: 'Montserrat'; font-weight: 800; font-display: swap; src: url('../fonts/montserrat-latin-800.woff2') format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: 'Montserrat'; font-weight: 900; font-display: swap; src: url('../fonts/montserrat-cyrillic-900.woff2') format('woff2'); unicode-range: U+0400-04FF, U+2116; }
@font-face { font-family: 'Montserrat'; font-weight: 900; font-display: swap; src: url('../fonts/montserrat-latin-900.woff2') format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }

/* ============ база ============ */
:root {
  --pink: #ff2e93;
  --pink-hot: #ff0f7b;
  --pink-soft: #ff8cc6;
  --ink: #1b0f1f;
  --purple: #2a0f33;
  --ease: cubic-bezier(.62, 0, .2, 1);
  /* ширина автомата: влезает и по высоте, и по ширине экрана */
  --mw: min(calc((100vh - 190px) * 0.6555), 94vw, 540px);
  --tx: 0px; --ty: 0px; --sc: 1;
}
@supports (height: 100dvh) {
  :root { --mw: min(calc((100dvh - 190px) * 0.6555), 94vw, 540px); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #ff9fce; }
body {
  font-family: 'Montserrat', 'Helvetica Neue', Arial, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}
img { display: block; -webkit-user-drag: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }

#app { position: fixed; inset: 0; overflow: hidden; }

.bg {
  position: absolute; inset: 0;
  background: #ff9fce url('../assets/bg_v.jpg') center bottom / cover no-repeat;
}
@media (orientation: landscape) {
  .bg { background-image: url('../assets/bg_h.jpg'); }
}
.bg::after {   /* мягкая виньетка для глубины */
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(120% 80% at 50% 45%, rgba(255,255,255,.18), rgba(255,255,255,0) 45%, rgba(190,10,110,.28) 100%);
}

/* ============ парящие сердца ============ */
.floaters { position: absolute; inset: 0; pointer-events: none; }
.fl { position: absolute; height: auto; animation: float 7s ease-in-out infinite; filter: drop-shadow(0 12px 18px rgba(200, 20, 110, .35)); }
.fl1 { width: clamp(54px, 9vw, 110px); left: 4%;  top: 20%; animation-duration: 8s; }
.fl2 { width: clamp(44px, 7vw, 90px);  right: 5%; top: 46%; animation-duration: 9.5s; animation-delay: -3s; }
.fl3 { width: clamp(30px, 4.5vw, 60px); right: 12%; top: 14%; animation-duration: 6.5s; animation-delay: -2s; }
.fl4 { width: clamp(24px, 3.5vw, 46px); left: 12%; top: 62%; animation-duration: 7.5s; animation-delay: -4s; }
.fl5 { width: clamp(36px, 5.5vw, 70px); left: 22%; top: 6%; animation-duration: 10s; animation-delay: -6s; opacity: .85; }
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-22px) rotate(6deg); }
}

/* ============ шапка ============ */
.top {
  position: absolute; z-index: 30; left: 0; right: 0; top: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(14px, env(safe-area-inset-top)) clamp(14px, 4vw, 44px) 0;
  pointer-events: none;
}
.logo { width: clamp(96px, 13vw, 170px); height: auto; transform: rotate(-4deg); filter: drop-shadow(0 4px 8px rgba(120, 0, 60, .3)); }
.sound {
  pointer-events: auto;
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; background: rgba(42, 15, 51, .62);
  transition: transform .15s, background .2s;
}
.sound:active { transform: scale(.9); }
.sound .mute { display: none; }
.sound[aria-pressed="false"] .waves { display: none; }
.sound[aria-pressed="false"] .mute { display: block; }

/* ============ кнопки ============ */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: .55em;
  min-height: 60px; padding: 0 2.1em;
  font-weight: 800; font-size: clamp(17px, 2.3vh, 22px); letter-spacing: .06em;
  color: #fff; white-space: nowrap;
  border-radius: 999px;
  background: linear-gradient(180deg, #3a2440 0%, #1b0f1f 46%, #0c060e 100%);
  box-shadow:
    inset 0 1.5px 0 rgba(255,255,255,.28),
    inset 0 -3px 6px rgba(0,0,0,.6),
    0 6px 0 #05020a,
    0 10px 22px rgba(60, 0, 40, .45),
    0 0 26px rgba(255, 46, 147, .75),
    0 0 60px rgba(255, 46, 147, .35);
  transition: transform .12s ease, box-shadow .12s ease, opacity .3s, filter .3s;
}
.btn::before {   /* глянцевый блик */
  content: ''; position: absolute; left: 8%; right: 8%; top: 5px; height: 38%;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255,255,255,.22), rgba(255,255,255,0));
  pointer-events: none;
}
.btn:hover { filter: brightness(1.15); }
.btn:active {
  transform: translateY(5px) scale(.98);
  box-shadow:
    inset 0 1.5px 0 rgba(255,255,255,.2), inset 0 -3px 6px rgba(0,0,0,.6),
    0 1px 0 #05020a, 0 3px 10px rgba(60,0,40,.45),
    0 0 18px rgba(255,46,147,.9), 0 0 44px rgba(255,46,147,.45);
}
.btn:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
.btn[disabled] { cursor: default; filter: saturate(.6) brightness(.8); opacity: .8; transform: translateY(4px); }
.btn-grab { min-width: 250px; min-height: 66px; font-weight: 900; font-size: clamp(20px, 2.8vh, 26px); }

/* ============ экран 1: заголовок ============ */
.intro {
  position: absolute; z-index: 20;
  left: clamp(18px, 6vw, 60px); top: calc(max(14px, env(safe-area-inset-top)) + clamp(64px, 11vh, 96px));
  transition: opacity .45s ease, transform .6s var(--ease), visibility 0s;
}
.title {
  margin: 0 0 clamp(16px, 3vh, 30px);
  font-weight: 900; line-height: 1.02; letter-spacing: -.02em;
  font-size: clamp(34px, 10.4vw, 54px);
  transform: rotate(-4deg); transform-origin: left bottom;
  text-shadow: 0 2px 0 rgba(255,255,255,.35);
}
.title span { display: block; }
.title .pink {
  color: var(--pink-hot);
  text-shadow: 0 0 18px rgba(255, 255, 255, .7), 0 2px 0 rgba(255,255,255,.5);
}
#app:not([data-screen="start"]) .intro { opacity: 0; transform: translateX(-40px); visibility: hidden; pointer-events: none; transition: opacity .35s ease, transform .5s var(--ease), visibility 0s .5s; }

/* появление при загрузке */
.intro .title span, .intro .btn { opacity: 0; transform: translateY(18px); }
.ready .intro .title span, .ready .intro .btn { opacity: 1; transform: none; transition: opacity .6s ease, transform .7s cubic-bezier(.2, 1.3, .4, 1); }
.ready .intro .title span:nth-child(2) { transition-delay: .1s; }
.ready .intro .title span:nth-child(3) { transition-delay: .2s; }
.ready .intro .btn { transition-delay: .35s; }
.ready .intro .btn:active { transition-delay: 0s; transform: translateY(5px) scale(.98); }

/* ============ автомат ============ */
.machine-wrap {
  position: absolute; z-index: 10;
  left: 50%; bottom: calc(max(26px, env(safe-area-inset-bottom)) + 92px);
  width: var(--mw);
  font-size: calc(var(--mw) / 100);       /* 1em = 1% ширины автомата */
  transform: translateX(-50%) translate(var(--tx), var(--ty)) scale(var(--sc));
  transform-origin: 50% 100%;
  transition: transform .95s var(--ease);
  will-change: transform;
}
.machine { position: relative; width: 100em; height: 152.56em; }
.machine-img {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4; pointer-events: none;
}
.machine-glow {   /* неоновое свечение за автоматом */
  position: absolute; left: -22%; right: -22%; top: 2%; bottom: -4%;
  background: radial-gradient(closest-side, rgba(255,255,255,.75), rgba(255, 70, 170, .55) 45%, rgba(255, 46, 147, 0) 72%);
  animation: glow 3.2s ease-in-out infinite; pointer-events: none;
}
@keyframes glow { 0%, 100% { opacity: .65; transform: scale(.97); } 50% { opacity: 1; transform: scale(1.03); } }
.machine-logo {
  position: absolute; z-index: 5; left: 50%; top: 3.6em; width: 44em; height: auto;
  transform: translateX(-50%) rotate(-3deg);
  filter: drop-shadow(0 .4em .5em rgba(120, 0, 60, .35));
  pointer-events: none;
}

/* --- поле за стеклом --- */
.field {
  position: absolute; z-index: 1;
  left: 7.37em; top: 32.05em; width: 85.74em; height: 77.56em;
  overflow: hidden;
}
.backwall {
  position: absolute; inset: 0;
  background:
    linear-gradient(90deg, rgba(42,15,51,.55), rgba(42,15,51,0) 13%, rgba(42,15,51,0) 87%, rgba(42,15,51,.55)),
    radial-gradient(90% 70% at 50% 30%, #ff9ad0 0%, #f0399a 55%, #a3126b 100%);
}
.backwall::before {  /* неоновая лампа под потолком */
  content: ''; position: absolute; left: 8%; right: 8%; top: 1.6em; height: 1.1em; border-radius: 1em;
  background: #fff; box-shadow: 0 0 2em .6em rgba(255,255,255,.85), 0 0 6em 2em rgba(255, 120, 200, .8);
  animation: lamp 4s ease-in-out infinite;
}
.backwall::after {  /* задние углы короба */
  content: ''; position: absolute; left: 13%; right: 13%; top: 0; bottom: 0;
  border-left: .25em solid rgba(255,255,255,.22); border-right: .25em solid rgba(255,255,255,.22);
}
@keyframes lamp { 0%, 100% { opacity: 1; } 48% { opacity: 1; } 50% { opacity: .72; } 52% { opacity: 1; } }
.rail {
  position: absolute; left: 0; right: 0; top: 0; height: 2.6em; z-index: 2;
  background: linear-gradient(180deg, #5b2c66, #2a0f33 60%, #14061a);
  box-shadow: 0 .4em .8em rgba(40, 0, 40, .45);
}

/* шары */
.balls { position: absolute; inset: 0; }
.balls-back { z-index: 1; }
.bags { position: absolute; inset: 0; z-index: 3; }
.balls-front { z-index: 6; }
.ball {
  position: absolute; border-radius: 50%;
  background:
    radial-gradient(circle at 32% 26%, rgba(255,255,255,.95) 0 6%, rgba(255,255,255,0) 17%),
    radial-gradient(circle at 36% 30%, #ffb7dc 0%, #ff5cae 38%, #e81f86 72%, #a80e60 100%);
  box-shadow: inset -.5em -.8em 1.2em rgba(120, 0, 70, .35), 0 .4em .7em rgba(90, 0, 50, .35);
}
.ball.b2 { background: radial-gradient(circle at 32% 26%, rgba(255,255,255,.95) 0 6%, rgba(255,255,255,0) 17%), radial-gradient(circle at 36% 30%, #ffd0e8 0%, #ff86c4 40%, #f04a9f 75%, #b81a70 100%); }
.ball.b3 { background: radial-gradient(circle at 32% 26%, rgba(255,255,255,.9) 0 6%, rgba(255,255,255,0) 17%), radial-gradient(circle at 36% 30%, #ff8ec7 0%, #f5308f 40%, #cf106f 75%, #8c0a4f 100%); }
.ball.bob { animation: bob 3.6s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-.55em) rotate(4deg); } }
.playing .ball.bob { animation-duration: 1.1s; }   /* автомат «трясётся», пока едет клешня */

/* пачки */
.bag {
  position: absolute; height: auto; transform-origin: 50% 20%;
  filter: drop-shadow(0 .5em .6em rgba(60, 0, 40, .45));
  will-change: transform;
}

/* лоток выдачи (стеклянный короб слева) */
.chute {
  position: absolute; z-index: 7; left: 1.2em; bottom: 0; width: 26em; height: 21em;
  border: .35em solid rgba(255,255,255,.55); border-bottom: 0;
  border-radius: 1em 1em 0 0;
  background: linear-gradient(180deg, rgba(255,255,255,.14), rgba(42, 15, 51, .55));
  box-shadow: inset 0 0 2em rgba(255,255,255,.18);
}

/* клешня */
.rig { position: absolute; left: 0; top: 0; width: 0; height: 0; z-index: 5; will-change: transform; }
.trolley {
  position: absolute; left: -7em; top: .6em; width: 14em; height: 3.6em; border-radius: .8em;
  background: linear-gradient(180deg, #ff9ad0, #ff2e93 55%, #b8106a);
  box-shadow: inset 0 .25em 0 rgba(255,255,255,.55), 0 .5em .8em rgba(40,0,40,.5);
  z-index: 2;
}
.cable {
  position: absolute; left: -.9em; top: 2em; width: 1.8em; height: 4em; border-radius: .4em;
  background:
    repeating-linear-gradient(180deg, rgba(255,255,255,.28) 0 .25em, rgba(0,0,0,0) .25em 1.1em),
    linear-gradient(90deg, #0c060e, #4a3550 45%, #1b0f1f 70%, #05020a);
  box-shadow: 0 0 .6em rgba(0,0,0,.35);
}
.claw { position: absolute; left: -10em; top: 0; width: 20em; height: 20.87em; will-change: transform; }
.claw-sway { position: absolute; inset: 0; transform-origin: 50% 0; animation: sway 3s ease-in-out infinite; }
@keyframes sway { 0%, 100% { transform: rotate(-1.6deg); } 50% { transform: rotate(1.6deg); } }
.claw-part { position: absolute; inset: 0; width: 100%; height: 100%; }
.claw-l { transform-origin: 25.65% 43.75%; }
.claw-r { transform-origin: 73.48% 43.75%; }

/* стекло поверх поля */
.glass {
  position: absolute; z-index: 5; pointer-events: none;
  left: 7.37em; top: 32.05em; width: 85.74em; height: 77.56em;
  background:
    linear-gradient(112deg, rgba(255,255,255,0) 18%, rgba(255,255,255,.22) 24%, rgba(255,255,255,.04) 31%, rgba(255,255,255,0) 32%, rgba(255,255,255,0) 58%, rgba(255,255,255,.14) 63%, rgba(255,255,255,0) 69%);
  box-shadow: inset 0 0 0 .3em rgba(255,255,255,.45), inset 0 0 3em rgba(255, 120, 200, .45);
}

/* вспышка в окошке выдачи */
.door-glow {
  position: absolute; z-index: 6; left: 11.5em; top: 120.5em; width: 22em; height: 22em; border-radius: 2em;
  background: radial-gradient(closest-side, #fff, rgba(255, 140, 210, .9) 45%, rgba(255, 46, 147, 0) 100%);
  opacity: 0; transform: scale(.6); pointer-events: none;
}
.door-glow.flash { animation: flash 1.2s ease-out forwards; }
@keyframes flash { 0% { opacity: 0; transform: scale(.6); } 25% { opacity: 1; transform: scale(1.5); } 100% { opacity: 0; transform: scale(2.6); } }

/* Честер на стартовом экране */
.chester-lie {
  position: absolute; z-index: 12; left: -40em; bottom: -5em; width: 82em; height: auto;
  filter: drop-shadow(0 1.5em 1.6em rgba(120, 0, 70, .4));
  transition: transform .8s var(--ease), opacity .5s ease;
  pointer-events: none;
}
#app:not([data-screen="start"]) .chester-lie { transform: translate(-70%, 30%) rotate(-8deg); opacity: 0; }

/* ============ экран 2: кнопка игры ============ */
.controls {
  position: absolute; z-index: 40; left: 0; right: 0;
  bottom: max(26px, env(safe-area-inset-bottom));
  display: grid; justify-items: center; pointer-events: none;
}
.controls .btn { grid-area: 1 / 1; pointer-events: auto; opacity: 0; visibility: hidden; transform: translateY(30px); transition: opacity .35s ease, transform .5s cubic-bezier(.2, 1.3, .4, 1), visibility 0s .5s, filter .3s; }
[data-screen="game"] .btn-grab, [data-screen="result"] .btn-again { opacity: 1; visibility: visible; transform: none; transition-delay: .35s, .35s, 0s, 0s; }
[data-screen="game"] .btn-grab[disabled] { opacity: .8; transform: translateY(4px); }
[data-screen="game"] .btn-grab:not([disabled]):active, [data-screen="result"] .btn-again:active { transform: translateY(5px) scale(.98); transition-delay: 0s; }
[data-screen="result"] .btn-again { transition-delay: 1s, 1s, 0s, 0s; }

/* ============ экран 3: результат ============ */
.result { position: absolute; inset: 0; pointer-events: none; }  /* без z-index: конфетти уходит за автомат, Честер — перед ним */
.heart {
  position: absolute; z-index: 20; left: 50%; top: 23em; width: 104em; height: 98.8em; margin-left: -52em;
  opacity: 0; visibility: hidden; transform: translate(-28em, 62em) scale(.08) rotate(-25deg);
  transition: opacity .25s ease, transform .3s ease-in, visibility 0s .3s;
  pointer-events: none;
}
[data-screen="result"] .heart {
  opacity: 1; visibility: visible; transform: none;
  transition: opacity .3s ease, transform .85s cubic-bezier(.2, 1.45, .35, 1), visibility 0s;
}
.heart-shape { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 0 2em rgba(255,255,255,.95)) drop-shadow(0 0 5em rgba(255, 46, 147, .9)); }
[data-screen="result"] .heart-shape { animation: beat 1.5s ease-in-out 1s infinite; }
@keyframes beat { 0%, 100% { transform: scale(1); } 14% { transform: scale(1.035); } 28% { transform: scale(1); } 42% { transform: scale(1.025); } 56% { transform: scale(1); } }
.rays { position: absolute; inset: -9%; width: 118%; height: 118%; opacity: 0; }
[data-screen="result"] .rays { animation: rays 1.8s ease-out .5s infinite; }
@keyframes rays { 0% { opacity: 0; transform: scale(.86); } 30% { opacity: 1; } 100% { opacity: 0; transform: scale(1.06); } }
.heart-text {
  position: absolute; left: 17%; right: 17%; top: 19%; height: 46%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35em;
  text-align: center; color: #fff; font-weight: 800; font-size: 6.6em; line-height: 1.14;
  text-shadow: 0 .06em .12em rgba(150, 0, 80, .55);
  transform: rotate(-3deg);
}
.heart-text p { margin: 0; text-wrap: balance; }
.heart-text svg { flex: none; font-size: 1.25em; }

.chester-thumb {
  position: absolute; z-index: 26; bottom: 0; height: min(40vh, 64vw); width: auto;
  left: max(-10px, calc(50% - var(--mw) * 0.5 - min(40vh, 64vw) * 0.72));
  transform: translateY(105%) rotate(-6deg); transform-origin: 0 100%;
  transition: transform .5s ease-in;
  filter: drop-shadow(0 0 22px rgba(255, 46, 147, .45));
}
[data-screen="result"] .chester-thumb { transform: none; transition: transform .8s cubic-bezier(.2, 1.3, .4, 1) .45s; }

/* конфетти */
.confetti { position: absolute; inset: 0; overflow: hidden; z-index: 9; }
.cf { position: absolute; top: -30px; border-radius: 2px; opacity: 0; animation: fall linear forwards; }
.cf-heart { width: 18px !important; height: 17px !important; border-radius: 0; -webkit-mask: var(--heart-mask) center / contain no-repeat; mask: var(--heart-mask) center / contain no-repeat; }
@keyframes fall {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), 108vh) rotate(var(--rot)); }
}

/* ============ раскладки ============ */
/* телефон, стартовый экран: автомат ниже и правее, заголовок сверху слева */
[data-screen="start"] { --tx: 15vw; --ty: 86px; --sc: .8; }

@media (max-height: 700px) and (orientation: portrait) {
  .title { font-size: clamp(28px, 8.6vw, 40px); }
  [data-screen="start"] { --sc: .74; }
}

/* планшет в портрете */
@media (min-width: 700px) and (orientation: portrait) {
  .title { font-size: clamp(54px, 8vw, 84px); }
  [data-screen="start"] { --tx: 16vw; --sc: .82; }
}

/* десктоп / альбомная ориентация: заголовок слева, автомат справа */
@media (orientation: landscape) and (min-width: 760px) {
  :root { --mw: min(calc((100vh - 170px) * 0.6555), 46vw, 560px); }
  .intro { left: clamp(28px, 9vw, 150px); top: 50%; transform: translateY(-54%); }
  #app:not([data-screen="start"]) .intro { transform: translate(-60px, -54%); }
  .title { font-size: clamp(40px, 5.6vw, 92px); margin-bottom: clamp(20px, 4vh, 40px); }
  .btn-start { min-height: 64px; font-size: clamp(18px, 1.5vw, 24px); }
  [data-screen="start"] { --tx: 21vw; --ty: 84px; --sc: .96; }
}
@supports (height: 100dvh) {
  @media (orientation: landscape) and (min-width: 760px) {
    :root { --mw: min(calc((100dvh - 170px) * 0.6555), 46vw, 560px); }
  }
}

/* высокие телефоны (портрет): в игре автомат не прижат к низу, а стоит по центру свободного места */
@media (orientation: portrait) {
  #app:not([data-screen="start"]) { --ty: calc(max(0px, 100vh - 190px - var(--mw) * 1.5256) * -0.42); }
}
@supports (height: 100dvh) {
  @media (orientation: portrait) {
    #app:not([data-screen="start"]) { --ty: calc(max(0px, 100dvh - 190px - var(--mw) * 1.5256) * -0.42); }
  }
}

/* низкий альбомный экран (телефон боком): автомат на всю высоту, кнопка справа */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --mw: min(calc((100vh - 18px) * 0.6555), 40vw); }
  .machine-wrap { bottom: 8px; }
  .controls { left: auto; right: max(14px, env(safe-area-inset-right)); bottom: 50%; transform: translateY(50%); width: auto; }
  .intro { left: max(5vw, env(safe-area-inset-left)); }
  .title { font-size: clamp(26px, 5vw, 44px); }
  [data-screen="start"] { --tx: 18vw; --ty: 0px; --sc: 1; }
  #app:not([data-screen="start"]) { --tx: -7vw; }
  .btn, .btn-grab { min-height: 50px; min-width: 0; padding: 0 1.5em; font-size: 14px; }
  .chester-thumb { height: 60vh; left: max(0px, env(safe-area-inset-left)); }
  .top { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .logo { width: 84px; }
}
@supports (height: 100dvh) {
  @media (orientation: landscape) and (max-height: 520px) {
    :root { --mw: min(calc((100dvh - 18px) * 0.6555), 40vw); }
  }
}

@media (prefers-reduced-motion: reduce) {
  .fl, .machine-glow, .ball.bob, .claw-sway, .btn-grab, .heart-shape, .rays { animation: none !important; }
}

/* в портрете на игровом экране логотип в шапке прячем: он уже есть на автомате */
.logo { transition: opacity .4s ease; }
@media (orientation: portrait) {
  #app:not([data-screen="start"]) .logo { opacity: 0; }
}

/* ============ мини-интерактив (js/fx.js) ============ */
.fx-layer { position: absolute; inset: 0; z-index: 60; pointer-events: none; overflow: hidden; }
.fx-heart { position: absolute; width: 1em; height: .93em; translate: -50% -50%; background: currentColor; -webkit-mask: var(--heart-mask) center / contain no-repeat; mask: var(--heart-mask) center / contain no-repeat; will-change: translate, opacity; }

.ball, .bag, #claw, .fl, .chester-lie, .chester-thumb, .machine-logo { cursor: pointer; }
.balls, .bags, .rig, .chute { pointer-events: none; }   /* контейнеры не перехватывают клики */
.ball, .bag, #claw { pointer-events: auto; }
.ball { transform-origin: 50% 100%; }
#claw { transform-origin: 50% 0; }
.fl { pointer-events: auto; }
.chester-lie { pointer-events: auto; transform-origin: 50% 100%; }
#app:not([data-screen="start"]) .chester-lie { pointer-events: none; }
.chester-thumb { transform-origin: 30% 100%; }
[data-screen="result"] .chester-thumb { pointer-events: auto; }
.machine-logo { pointer-events: auto; }
[data-screen="result"] .heart-shape #hp { pointer-events: auto; cursor: pointer; }
.field { cursor: pointer; }
.machine { transform-origin: 50% 100%; }

/* параллакс: слои чуть смещаются за мышкой (переменные --px/--py ставит fx.js) */
#app { --px: 0; --py: 0; }
.floaters { translate: calc(var(--px) * -18px) calc(var(--py) * -12px); }
.bg { inset: -14px; translate: calc(var(--px) * 8px) calc(var(--py) * 6px); }
.machine-glow { translate: calc(var(--px) * -10px) calc(var(--py) * -6px); }
.intro { translate: calc(var(--px) * -6px) calc(var(--py) * -4px); }

/* ============ пульт автомата как кнопка ============ */
.panel-hit {
  position: absolute; z-index: 7; left: 52.6em; top: 108.5em; width: 32.4em; height: 23.5em;
  border-radius: 3.2em; cursor: pointer;
  transition: box-shadow .25s ease, background .25s ease, transform .1s ease;
}
.panel-hit:hover { background: rgba(255,255,255,.14); box-shadow: 0 0 2.4em .4em rgba(255,255,255,.75), 0 0 5em 1em rgba(255, 46, 147, .7); }
.panel-hit:active { transform: translateY(.5em) scale(.97); background: rgba(255,255,255,.3); }
.panel-hit:focus-visible { outline: .5em solid #fff; outline-offset: .4em; }
/* в игре пульт мягко мигает, подсказывая, что его можно нажать */
.playing .panel-hit, [data-screen="result"] .panel-hit { cursor: default; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .panel-hit { animation: none !important; } }

/* =====================================================================
   v2: полировка и производительность
   Правило: всё, что анимируется постоянно, меняет только transform и opacity
   (их рисует видеокарта) — никаких анимаций box-shadow / filter.
   ===================================================================== */
:root { --heart-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 21.5C4.5 15.6 1 11.8 1 7.4A5.9 5.9 0 0 1 12 4.3 5.9 5.9 0 0 1 23 7.4c0 4.4-3.5 8.2-11 14.1z'/%3E%3C/svg%3E"); }

/* --- плавное появление страницы, когда картинки загрузились --- */
#app { opacity: 0; transition: opacity .5s ease; }
#app.ready { opacity: 1; }
.ready .machine { animation: riseIn 1s cubic-bezier(.2, 1.15, .35, 1) both; }
@keyframes riseIn { from { transform: translateY(14em) scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
.ready .chester-lie { animation: chesterIn .9s cubic-bezier(.2, 1.2, .4, 1) .45s both, chesterIdle 4.5s ease-in-out 1.6s infinite; }
@keyframes chesterIn { from { translate: -34em 6em; opacity: 0; } to { translate: 0 0; opacity: 1; } }
@keyframes chesterIdle { 0%, 100% { rotate: 0deg; } 50% { rotate: -1.2deg; } }
#app:not([data-screen="start"]) .chester-lie { animation: none; }
.ready .floaters .fl { animation-name: float, flIn; animation-duration: var(--fd, 7s), 1.2s; animation-timing-function: ease-in-out, ease-out; animation-iteration-count: infinite, 1; animation-fill-mode: none, backwards; }
@keyframes flIn { from { opacity: 0; scale: .5; } to { opacity: 1; scale: 1; } }
.fl1 { --fd: 8s; } .fl2 { --fd: 9.5s; } .fl3 { --fd: 6.5s; } .fl4 { --fd: 7.5s; } .fl5 { --fd: 10s; }

/* --- кнопки: свечение и блик отдельными слоями --- */
.btn { isolation: isolate; }
.btn::after {     /* пульсирующий неон: анимируется только прозрачность */
  content: ''; position: absolute; inset: 0; border-radius: inherit; z-index: -1; pointer-events: none;
  box-shadow: 0 0 34px 6px rgba(255, 46, 147, .95), 0 0 80px 18px rgba(255, 46, 147, .5);
  opacity: 0;
}
/* свечение крутится только у кнопки текущего экрана — скрытые кнопки ничего не анимируют */
[data-screen="start"] .btn-start::after, [data-screen="result"] .btn-again::after, [data-screen="game"] .btn-grab:not([disabled])::after { animation: neon 1.7s ease-in-out infinite; }
.shine::after { animation-play-state: paused; }
[data-screen="start"] .btn-start .shine::after, [data-screen="result"] .btn-again .shine::after, [data-screen="game"] .btn-grab .shine::after { animation-play-state: running; }
@keyframes neon { 0%, 100% { opacity: 0; } 50% { opacity: 1; } }
.shine { position: absolute; inset: 0; border-radius: inherit; overflow: hidden; pointer-events: none; }
.shine::after {
  content: ''; position: absolute; top: -20%; bottom: -20%; left: 0; width: 34%;
  background: linear-gradient(100deg, rgba(255,255,255,0), rgba(255,255,255,.34) 50%, rgba(255,255,255,0));
  transform: translateX(-140%) skewX(-18deg);
  animation: shine 3.6s ease-in-out infinite;
}
.btn-again .shine::after { animation-delay: 1.6s; }
.btn[disabled] .shine::after { animation: none; }
@keyframes shine { 0%, 62% { transform: translateX(-140%) skewX(-18deg); } 100% { transform: translateX(440%) skewX(-18deg); } }
.btn .lbl { position: relative; }

/* --- автомат: тень на полу, неоновые рёбра, бегущие лампочки --- */
.machine-shadow {
  position: absolute; left: -6%; right: -6%; bottom: -3.2em; height: 9em; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(120, 0, 70, .5), rgba(120, 0, 70, 0));
  pointer-events: none;
}
.neon {
  position: absolute; z-index: 5; top: 30em; bottom: 5em; width: 1.3em; border-radius: 1em; pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,0), #fff 12%, #fff 88%, rgba(255,255,255,0));
  box-shadow: 0 0 1.6em .5em rgba(255, 120, 200, .95), 0 0 4.5em 1.2em rgba(255, 46, 147, .6);
  opacity: .55; animation: neonEdge 2.6s ease-in-out infinite;
}
.neon-l { left: 2.2em; } .neon-r { right: 2.2em; animation-delay: -1.3s; }
@keyframes neonEdge { 0%, 100% { opacity: .35; } 50% { opacity: .9; } }
.playing .neon { animation-duration: .7s; }

.bulbs { position: absolute; z-index: 5; left: 8em; right: 8em; top: 28.4em; height: 2em; display: flex; justify-content: space-between; align-items: center; pointer-events: none; }
.bulbs i {
  width: 1.7em; height: 1.7em; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #ffe9a8 45%, #ffb400);
  box-shadow: 0 0 1em .25em rgba(255, 220, 120, .95), 0 0 2.4em .6em rgba(255, 46, 147, .55);
  opacity: .28; animation: bulb 1.5s linear infinite;
}
@keyframes bulb { 0%, 100% { opacity: .28; } 12% { opacity: 1; } 34% { opacity: .28; } }
.playing .bulbs i { animation-duration: .5s; }
[data-screen="result"] .bulbs i { animation: bulbWin .45s steps(1) infinite; }
[data-screen="result"] .bulbs i:nth-child(even) { animation-delay: -.225s; }
@keyframes bulbWin { 0% { opacity: 1; } 50% { opacity: .25; } }

/* клешня: одна тень на всю конструкцию вместо трёх */
.claw-sway { filter: drop-shadow(0 .5em .5em rgba(40, 0, 40, .4)); }

/* --- пульт: подсветка-подсказка отдельным слоем --- */
.panel-hit::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  box-shadow: 0 0 2em .3em rgba(255,255,255,.6), 0 0 4.5em .8em rgba(255, 46, 147, .55);
  opacity: 0;
}
[data-screen="game"]:not(.playing) .panel-hit::after { animation: neon 1.8s ease-in-out infinite; }

/* --- результат: затемнение вокруг сердца, появление текста --- */
.spot {
  position: absolute; z-index: 15; left: 50%; top: 72em; width: 300vmax; height: 300vmax; margin: -150vmax 0 0 -150vmax;
  background: radial-gradient(circle, rgba(42, 15, 51, 0) 0, rgba(42, 15, 51, 0) 9%, rgba(42, 15, 51, .5) 20%, rgba(42, 15, 51, .62) 100%);
  opacity: 0; transition: opacity .4s ease; pointer-events: none;
}
[data-screen="result"] .spot { opacity: 1; transition: opacity .7s ease .1s; }
.heart-text p, .heart-text svg { opacity: 0; transform: translateY(.5em) scale(.92); }
[data-screen="result"] .heart-text p { opacity: 1; transform: none; transition: opacity .45s ease .42s, transform .6s cubic-bezier(.2, 1.4, .4, 1) .42s; }
[data-screen="result"] .heart-text svg { opacity: 1; transform: none; transition: opacity .4s ease .7s, transform .6s cubic-bezier(.2, 1.6, .4, 1) .7s; }
[data-screen="result"] .chester-thumb { filter: none; }

/* --- слои, которые двигаются каждый кадр, заранее отдаём видеокарте --- */
.ball.bob, .fl, .machine-glow, .neon, .cf { will-change: transform, opacity; }
.cable { will-change: height; }
.field { contain: layout paint; }
/* (у .result contain ставить нельзя: он создаёт свой слой наложения, и Честер уходит под затемнение) */

@media (prefers-reduced-motion: reduce) {
  .btn::after, .shine::after, .neon, .bulbs i, .panel-hit::after, .ready .machine, .ready .chester-lie, .ready .floaters .fl { animation: none !important; }
  .bulbs i, .neon { opacity: .8; }
}
