:root {
  --pink: #f99abd;
  --pink-dark: #e46f9d;
  --yellow: #ffe995;
  --ink: #2c2a35;
  --cloud: #c4f1f6;
  --cloud-dark: #8fd6e0;
  --cream: #fff7e6;
  --accent: #ff7fb0;
  --gold: #f5b700;
  --muted: #7a6f7f;
  --hand: 'Neucha', 'Comic Sans MS', cursive;
  --ui: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  /* поля вокруг сцены продолжают фон: розовая стена, жёлтый пол */
  background: linear-gradient(to bottom, var(--pink) 0 60%, var(--yellow) 60% 100%);
  color: var(--ink);
  font-family: var(--ui);
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* фон комнаты в масштабе высоты экрана: на широких экранах продолжает сцену без шва */
#app { position: fixed; inset: 0; background: url(../assets/bg.webp) center / auto 100% repeat-x; }

/* ---------- сцена 1080x1920 ---------- */

#stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1080px;
  height: 1920px;
  transform-origin: center;
  overflow: hidden;
}

.layer { position: absolute; display: block; pointer-events: none; }
.btn { pointer-events: auto; cursor: pointer; transition: transform .12s; }
.btn:active { transform: scale(.94); }
.btn.disabled { filter: saturate(.6); }
.hidden { display: none !important; }

.monkey, .helmet { transform-origin: 50% 100%; }
.monkey:not(.hidden) { animation: breathe 3.2s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.012, .99); } }

.blink i {
  position: absolute;
  display: block;
  background: #ffd8a7;
  border-bottom: 4px solid #211c16;
  border-radius: 0 0 50% 50%;
  transform: scaleY(0);
  transform-origin: top;
  transition: transform .07s;
}
.blink.on i { transform: scaleY(1); }

.zzz span {
  position: absolute;
  font: 64px var(--hand);
  color: #6b5ca5;
  -webkit-text-stroke: 3px #fff;
  paint-order: stroke;
  animation: zfloat 3.2s ease-out forwards;
}
@keyframes zfloat {
  0% { transform: translate(0, 0) scale(.5) rotate(-10deg); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translate(-190px, -200px) scale(1.5) rotate(-15deg); opacity: 0; }
}

.timer {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.timer span, .timer b {
  background: var(--cream);
  border: 5px solid var(--ink);
  border-radius: 999px;
}
.timer span { font: 46px var(--hand); padding: 6px 34px; }
.timer b { font: 800 84px var(--ui); padding: 4px 44px; letter-spacing: 2px; font-variant-numeric: tabular-nums; }

/* ---------- экраны боксов и колеса (внутри сцены) ---------- */

.screen { position: absolute; inset: 0; animation: fadein .25s; }
/* на экранах боксов и колеса прячем обезьянку и кнопки комнаты, затемняем и поля вокруг сцены */
.screen-open #stage > .monkey, .screen-open #stage > .helmet, .screen-open #stage > .blink,
.screen-open #stage > .zzz, .screen-open #stage > .timer, .screen-open #stage > .btn { visibility: hidden; }
.screen-open #app::before { content: ''; position: absolute; inset: 0; background: rgba(60, 10, 40, .5); animation: fadein .25s; }
.dim { position: absolute; inset: 0; background: rgba(60, 10, 40, .5); }
@keyframes fadein { from { opacity: 0; } }

.screen-title {
  position: absolute;
  text-align: center;
  font: 96px var(--hand);
  color: #fff;
  -webkit-text-stroke: 8px var(--ink);
  paint-order: stroke;
}
.screen-title small { display: block; font-size: 52px; -webkit-text-stroke-width: 6px; }

.screen-actions, .bet-row, .bet-chips { display: flex; justify-content: center; gap: 30px; }
.screen-actions { position: absolute; }

.box-group { position: absolute; inset: 0; pointer-events: none; }
.box-group .layer { pointer-events: auto; cursor: pointer; }
.box-group.idle .layer { animation: wobble 1.6s ease-in-out infinite; transform-origin: 50% 100%; }
.box-group.idle:nth-of-type(odd) .layer { animation-delay: -.8s; }
@keyframes wobble { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }

.prize { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.prize img { height: 380px; filter: drop-shadow(0 10px 0 rgba(0,0,0,.15)); }
.prize.other { transform-origin: bottom; }
.prize.other img { height: 280px; filter: grayscale(.3) drop-shadow(0 10px 0 rgba(0,0,0,.15)); }
.prize-card {
  background: var(--cream);
  border: 5px solid var(--ink);
  border-radius: 30px;
  padding: 10px 26px;
  text-align: center;
  white-space: nowrap;
}
.prize-card b { display: block; font: 46px var(--hand); }
.prize-card span { font: 800 40px var(--ui); }
.prize.other .prize-card { transform: scale(.8); opacity: .9; }
.mystery {
  font: 300px/380px var(--hand);
  color: #fff;
  -webkit-text-stroke: 10px var(--ink);
  paint-order: stroke;
  animation: wobble 1.2s ease-in-out infinite;
}
.prize.shine::before {
  content: '';
  position: absolute;
  left: 50%; top: 190px;
  width: 700px; height: 700px;
  margin: -350px 0 0 -350px;
  background: repeating-conic-gradient(rgba(255, 240, 150, .7) 0 10deg, transparent 10deg 20deg);
  border-radius: 50%;
  mask: radial-gradient(circle, #000 20%, transparent 70%);
  -webkit-mask: radial-gradient(circle, #000 20%, transparent 70%);
  animation: spin 8s linear infinite;
  z-index: -1;
}
@keyframes spin { to { transform: rotate(360deg); } }

.wheel { transform-origin: 50% 50%; }
.pointer {
  position: absolute;
  width: 100px; height: 110px;
  background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  filter: drop-shadow(0 6px 0 var(--ink));
}
.pointer::after {
  content: '';
  position: absolute;
  inset: 14px 22px 34px;
  background: #fff;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  opacity: .5;
}
.wheel-result {
  position: absolute;
  text-align: center;
  font: 800 72px var(--ui);
  color: #fff;
  -webkit-text-stroke: 7px var(--ink);
  paint-order: stroke;
}
.wheel-result .win { color: #ffe066; }

.bet { position: absolute; display: flex; flex-direction: column; gap: 34px; }
.bet-value {
  display: flex; align-items: center; gap: 14px;
  background: var(--cream);
  border: 5px solid var(--ink);
  border-radius: 999px;
  padding: 0 34px;
  font: 800 64px var(--ui);
}
.bet-value input {
  width: 220px;
  border: 0; background: none; outline: none;
  font: inherit; text-align: center; color: var(--ink);
}

/* ---------- кнопки в стиле облачков с макета ---------- */

.pill {
  background: var(--cloud);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 6px 16px;
  font-family: var(--hand);
  font-size: 18px;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .1s, box-shadow .1s;
}
.pill:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.pill:disabled { opacity: .6; }
.pill.accent { background: var(--accent); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.25); }
.pill.big { font-size: 22px; padding: 10px 26px; }
.pill.round { width: 48px; height: 48px; padding: 0; font: 800 26px var(--ui); }
#stage .pill { border-width: 6px; box-shadow: 0 8px 0 var(--ink); font-size: 56px; padding: 12px 44px; }
#stage .pill:active { transform: translateY(8px); box-shadow: none; }
#stage .pill.big { font-size: 64px; padding: 16px 60px; }
#stage .pill.round { width: 120px; height: 120px; padding: 0; font-size: 72px; }

.coin {
  display: inline-block;
  width: .9em; height: .9em;
  border-radius: 50%;
  vertical-align: -.1em;
  background: radial-gradient(circle at 35% 30%, #fff3b0 0 15%, #ffd23f 35%, var(--gold) 70%);
  border: .08em solid #a87700;
}

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}
#hud[hidden] { display: none; }
.hud-card {
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 22px;
  padding: 4px 22px 6px;
  text-align: center;
  box-shadow: 0 3px 0 var(--ink);
}
#hud-name { font: 22px var(--hand); max-width: 50vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#hud-balance { font: 800 20px var(--ui); display: flex; gap: 6px; align-items: center; justify-content: center; }
#btn-top { position: absolute; right: 12px; top: 6px; pointer-events: auto; }
#btn-rules { position: absolute; left: 12px; top: 6px; pointer-events: auto; }

.rules { text-align: left; display: flex; flex-direction: column; gap: 10px; font-size: 15px; line-height: 1.35; }
.rules table { border-collapse: collapse; width: 100%; font-size: 14px; }
.rules td { padding: 3px 6px; border-bottom: 1px dashed #d9cbbd; }
.rules td:nth-child(2), .rules td:nth-child(3) { text-align: right; white-space: nowrap; }

#banner {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  top: calc(max(10px, env(safe-area-inset-top)) + 70px);
  background: var(--ink); color: #fff;
  border-radius: 14px;
  padding: 6px 14px;
  font: 600 14px var(--ui);
  z-index: 5;
  white-space: nowrap;
}

/* ---------- панели ---------- */

.panel-wrap {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(60, 10, 40, .45);
  z-index: 10;
  animation: fadein .2s;
}
.panel {
  position: relative;
  width: 100%; max-width: 440px;
  max-height: calc(100% - 20px);
  overflow-y: auto;
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 28px;
  box-shadow: 0 6px 0 var(--ink);
  padding: 22px 18px 18px;
  text-align: center;
  display: flex; flex-direction: column; gap: 12px; align-items: stretch;
  animation: pop .25s ease-out;
  user-select: text;
}
.panel.small { max-width: 340px; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.panel h2 { font: 28px var(--hand); margin: 0; }
.panel p { margin: 0; }
.panel .bet-row { gap: 14px; align-items: center; }
.panel-close {
  position: absolute; right: 10px; top: 8px;
  border: 0; background: none;
  font-size: 22px; color: var(--muted);
}
.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }

.field {
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 12px 14px;
  font: 22px var(--hand);
  text-align: center;
  background: #fff;
  outline: none;
}
.field:focus { border-color: var(--pink-dark); }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 20px;
  padding: 10px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.card img { height: 120px; }
.card b { font: 20px var(--hand); }
.card .muted { font-size: 12px; line-height: 1.2; min-height: 2.4em; }
.card .count { font: 800 15px var(--ui); }
.card .bonus { font: 700 13px var(--ui); color: #2a9d4b; }
.card.locked { background: #f1ebe4; }
.card.locked img { filter: brightness(0) opacity(.25); }
.card .pill { margin-top: 4px; }

.sell-img { height: 140px; align-self: center; }
.qty { min-width: 80px; }
.qty b { display: block; font: 800 34px var(--ui); }
.qty small { color: var(--muted); }
.pill.small-text { align-self: center; font-size: 15px; padding: 3px 14px; }

.lb { display: flex; flex-direction: column; gap: 6px; }
.lb-row {
  display: flex; align-items: center; gap: 10px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 6px 10px;
  text-align: left;
}
.lb-row.me { background: #ffe1ee; border-width: 3px; }
.rank { width: 28px; text-align: center; font: 800 16px var(--ui); }
.ava {
  width: 36px; height: 36px; border-radius: 50%;
  object-fit: cover; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--cloud); border: 2px solid var(--ink);
  font: 800 16px var(--ui);
}
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.lb-val { font: 800 14px var(--ui); white-space: nowrap; }
.lb-sep { font: 16px var(--hand); color: var(--muted); margin-top: 6px; }

/* ---------- уведомления и загрузка ---------- */

#toasts {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 16px);
  display: flex; flex-direction: column-reverse; align-items: center; gap: 6px;
  pointer-events: none;
  z-index: 20;
}
.toast {
  background: var(--ink); color: #fff;
  border-radius: 14px;
  padding: 8px 16px;
  font: 700 15px var(--ui);
  animation: pop .2s ease-out;
  transition: opacity .4s, transform .4s;
}
.toast.good { background: #2a9d4b; }
.toast.bad { background: #d23c5c; }
.toast.out { opacity: 0; transform: translateY(10px); }

#loader {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--pink);
  font: 24px var(--hand);
  z-index: 30;
}
.spinner {
  width: 44px; height: 44px;
  border: 5px solid var(--cream);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 10px auto;
}
