* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root { --ui: #3b2a8f; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  overscroll-behavior: none; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  font-family: "Trebuchet MS", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #fff;
}
body { background: linear-gradient(165deg, #7ad7ff 0%, #6f8cff 50%, #8a5cff 100%); transition: background 0.4s; }
button { font-family: inherit; border: none; cursor: pointer; color: inherit; background: none; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; margin: 0 auto; width: min(100vw, 200vh); display: flex; flex-direction: column; }
body.in-menu #hud, body.in-menu #progress, body.in-menu #bar { visibility: hidden; }

/* ---------- HUD ---------- */
#hud {
  flex: 0 0 auto; height: clamp(60px, 10vh, 82px);
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px 0; gap: 8px; padding-top: max(6px, env(safe-area-inset-top));
}
.hud-center { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
#hud-level { font-size: clamp(20px, 3.6vh, 30px); font-weight: 900; line-height: 1; text-shadow: 0 3px 0 rgba(0,0,0,0.22); white-space: nowrap; }
#hud-hearts { display: flex; gap: 4px; }
#hud-hearts svg { width: clamp(20px, 3.2vh, 26px); height: clamp(20px, 3.2vh, 26px); display: block; transition: transform 0.2s; }
#hud-hearts .lost { opacity: 0.3; filter: grayscale(1); }
#hud-hearts .pop { animation: heartPop 0.5s ease-out; }
@keyframes heartPop { 0% { transform: scale(1.6); } 100% { transform: scale(1); } }
.badge-hard {
  background: linear-gradient(180deg, #ff6b6b, #d90429); border-radius: 999px; padding: 2px 10px;
  font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.5px; box-shadow: 0 2px 0 #8d0b1d;
}
.coin-pill {
  display: flex; align-items: center; gap: 5px;
  background: rgba(0,0,0,0.22); border-radius: 999px; padding: 4px 12px 4px 5px;
  font-weight: 900; font-size: clamp(14px, 2.2vh, 18px);
}
.coin-pill.big { font-size: 20px; padding: 6px 16px 6px 6px; }
.coin-ico {
  display: inline-block; width: 1.2em; height: 1.2em; border-radius: 50%; flex: 0 0 auto;
  background: radial-gradient(circle at 35% 35%, #fff6b0 0 15%, #ffd23f 16% 55%, #f0a500 56% 100%);
  box-shadow: inset 0 0 0 2px #e08e00; vertical-align: middle;
}
.icon-btn {
  width: clamp(42px, 6.5vh, 52px); height: clamp(42px, 6.5vh, 52px); border-radius: 14px;
  background: rgba(255,255,255,0.25); box-shadow: 0 4px 0 rgba(0,0,0,0.2);
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto; position: relative;
}
.icon-btn svg { width: 60%; height: 60%; }
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.2); }
.icon-btn.small { width: 38px; height: 38px; border-radius: 12px; }
.icon-btn.toggle.off { opacity: 0.45; }
.icon-btn.toggle.off::after { content: ''; position: absolute; width: 60%; height: 4px; background: #fff; transform: rotate(-45deg); border-radius: 2px; }

#progress {
  flex: 0 0 auto; position: relative; height: 16px; margin: 6px auto 0; width: min(320px, 70vw);
  background: rgba(0,0,0,0.2); border-radius: 8px; overflow: hidden;
}
#progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #ffe066, #ffb703); border-radius: 8px; transition: width 0.25s; }
#progress-text { position: absolute; inset: 0; font-size: 11px; font-weight: 900; display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 1px rgba(0,0,0,0.4); }

/* ---------- Сцена ---------- */
#stage { position: relative; flex: 1 1 auto; min-height: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#guide { position: absolute; left: 0; top: 0; pointer-events: none; transform: translate(-30%, -10%); z-index: 2; }
.guide-hand { width: 64px; height: 64px; animation: tap 1.1s ease-in-out infinite; filter: drop-shadow(0 3px 2px rgba(0,0,0,0.35)); }
.guide-hand svg { width: 100%; height: 100%; }
@keyframes tap { 0%,100% { transform: translate(14px, 18px) scale(1); } 50% { transform: translate(0, 0) scale(0.9); } }
#guide-text {
  position: absolute; left: 50%; top: 4px; transform: translateX(-50%); width: min(92%, 420px); z-index: 2;
  background: rgba(0,0,0,0.55); border-radius: 16px; padding: 10px 14px; text-align: center;
  font-weight: 900; font-size: clamp(15px, 2.4vh, 19px); pointer-events: none; animation: fadein 0.3s;
}
#laser-hint {
  position: absolute; left: 50%; top: 8px; transform: translateX(-50%); z-index: 3;
  display: flex; gap: 10px; align-items: center; white-space: nowrap;
  background: rgba(150,0,20,0.8); padding: 8px 10px 8px 16px; border-radius: 999px; font-weight: 900; font-size: 17px;
}
#flash { position: absolute; inset: 0; pointer-events: none; display: flex; justify-content: center; }
.flash-text {
  position: absolute; top: 6%; font-weight: 900; font-size: clamp(28px, 5.5vh, 46px); color: #ffe14d;
  text-shadow: 0 4px 0 #c2410c, 0 8px 16px rgba(0,0,0,0.3); white-space: nowrap;
  animation: flash 1s ease-out forwards;
}
@keyframes flash {
  0% { transform: scale(0.3); opacity: 0; }
  20% { transform: scale(1.15); opacity: 1; }
  35% { transform: scale(1); }
  80% { opacity: 1; }
  100% { transform: translateY(-30px); opacity: 0; }
}

/* ---------- Бустеры ---------- */
#bar {
  flex: 0 0 auto; height: clamp(78px, 12vh, 100px);
  display: flex; justify-content: center; align-items: center; gap: clamp(14px, 5vw, 32px);
  padding-bottom: max(6px, env(safe-area-inset-bottom));
}
.booster {
  position: relative; width: clamp(62px, 9.5vh, 80px); height: clamp(62px, 9.5vh, 80px); border-radius: 20px;
  background: linear-gradient(180deg, #fff 0%, #e9e6ff 100%); color: var(--ui);
  box-shadow: 0 5px 0 rgba(0,0,0,0.25), 0 8px 14px rgba(0,0,0,0.15);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
.booster:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,0.25); }
.booster.active { background: linear-gradient(180deg, #ffd0d0, #ff7b7b); color: #fff; }
.b-ico svg { width: clamp(28px, 4.6vh, 38px); height: clamp(28px, 4.6vh, 38px); display: block; }
.b-name { font-size: clamp(10px, 1.5vh, 12px); font-weight: 900; }
.b-cnt {
  position: absolute; right: -6px; top: -6px; min-width: 26px; height: 26px; border-radius: 13px; color: #fff;
  background: #ff3d6e; border: 2px solid #fff; font-weight: 900; font-size: 14px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
.b-cnt.plus { background: #22c55e; }

/* ---------- Экраны ---------- */
.screen {
  position: fixed; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center;
  z-index: 10; padding: 12px; overflow: hidden;
}
.screen.show { display: flex; animation: fadein 0.25s ease-out; }
.screen.dim { background: rgba(15,10,45,0.6); }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

#screen-loading { background: linear-gradient(165deg, #7ad7ff 0%, #6f8cff 50%, #8a5cff 100%); }
.loader { width: 70px; height: 70px; border-radius: 50%; border: 8px solid rgba(255,255,255,0.3); border-top-color: #fff; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#screen-menu { pointer-events: none; justify-content: space-between; padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: max(14px, env(safe-area-inset-bottom)); }
#screen-menu > * { pointer-events: auto; }
#screen-menu .menu-space { pointer-events: none; flex: 1; }
.menu-top { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: center; }
.logo { text-align: center; margin-top: clamp(44px, 7vh, 64px); }
.logo-title {
  display: flex; justify-content: center; align-items: center; gap: 6px;
  font-size: clamp(40px, 8.5vh, 76px); font-weight: 900; line-height: 1; letter-spacing: 1px;
  color: #fff; text-shadow: 0 4px 0 var(--ui), 0 8px 0 rgba(0,0,0,0.25), 0 14px 20px rgba(0,0,0,0.25);
}
.logo-arrow svg { width: clamp(40px, 8vh, 70px); height: clamp(40px, 8vh, 70px); display: block; animation: shoot 1.6s ease-in-out infinite; filter: drop-shadow(0 4px 0 var(--ui)); }
@keyframes shoot { 0%,100% { transform: translateX(0); } 50% { transform: translateX(10px); } }
.logo-sub {
  display: inline-block; margin-top: 6px; font-size: clamp(20px, 3.8vh, 32px); font-weight: 900; color: #fff;
  background: linear-gradient(180deg, #ff6b8b, #e5275a); padding: 2px 20px; border-radius: 12px; transform: rotate(-3deg);
  box-shadow: 0 4px 0 #9b1239; text-transform: uppercase; letter-spacing: 2px;
}
.menu-bottom { display: flex; flex-direction: column; align-items: center; gap: 12px; width: min(420px, 94vw); }
.menu-bottom > .btn { width: 100%; }
.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(8px, 2vw, 14px); width: 100%; }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: rgba(255,255,255,0.25); border-radius: 18px; padding: 10px 4px 8px;
  font-weight: 800; font-size: clamp(12px, 1.8vh, 15px); box-shadow: 0 5px 0 rgba(0,0,0,0.18);
  backdrop-filter: blur(4px);
}
.tile:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,0.18); }
.tile-ico svg { width: clamp(28px, 4.6vh, 40px); height: clamp(28px, 4.6vh, 40px); display: block; }
.badge {
  position: absolute; top: -6px; right: -4px; width: 24px; height: 24px; border-radius: 50%;
  background: #ff2d55; border: 2px solid #fff; font-style: normal; font-weight: 900; font-size: 14px;
  display: flex; align-items: center; justify-content: center; animation: beat 1s infinite;
}
@keyframes beat { 0%,100% { transform: scale(1); } 50% { transform: scale(1.2); } }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 8px 22px; border-radius: 18px;
  font-weight: 900; font-size: 20px; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.2); position: relative;
}
.btn:active { transform: translateY(4px); }
.btn:disabled { filter: grayscale(0.7); opacity: 0.6; }
.btn-ico svg { width: 26px; height: 26px; display: block; }
.btn-green { background: linear-gradient(180deg, #6ee76e, #22b04a); box-shadow: 0 6px 0 #15803d, 0 10px 16px rgba(0,0,0,0.2); }
.btn-green:active { box-shadow: 0 2px 0 #15803d; }
.btn-blue { background: linear-gradient(180deg, #6ec6ff, #2f80ed); box-shadow: 0 6px 0 #1d4ed8; }
.btn-blue:active { box-shadow: 0 2px 0 #1d4ed8; }
.btn-yellow { background: linear-gradient(180deg, #ffe066, #ffb703); box-shadow: 0 6px 0 #d97706; }
.btn-yellow:active { box-shadow: 0 2px 0 #d97706; }
.btn-red { background: linear-gradient(180deg, #ff7b8a, #ef2b4b); box-shadow: 0 4px 0 #b91c1c; }
.btn-purple { background: linear-gradient(180deg, #ff9ad5, #e0458f); box-shadow: 0 6px 0 #9d174d; }
.btn-purple:active { box-shadow: 0 2px 0 #9d174d; }
.btn-purple.done { filter: saturate(0.4); }
.btn-ad { background: linear-gradient(180deg, #c084fc, #7c3aed); box-shadow: 0 6px 0 #5b21b6; }
.btn-ad:active { box-shadow: 0 2px 0 #5b21b6; }
.btn-huge { font-size: clamp(26px, 5vh, 36px); min-height: clamp(64px, 10vh, 84px); padding: 10px 40px; border-radius: 26px; animation: breathe 1.6s ease-in-out infinite; }
.btn-huge .btn-ico svg { width: 36px; height: 36px; }
.btn-big { font-size: 24px; min-height: 60px; }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.04); } }
.btn-small { min-height: 38px; font-size: 16px; padding: 6px 16px; border-radius: 14px; }
.btn-square { padding: 0; width: 56px; min-width: 56px; }
.btn-square svg { width: 28px; height: 28px; }
.ad-col { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.05; }
.ad-col small { font-size: 12px; opacity: 0.9; font-weight: 800; }

/* ---------- Панели ---------- */
.panel {
  width: min(380px, 94vw); max-height: 96%; overflow-y: auto; touch-action: pan-y;
  background: linear-gradient(180deg, #ffffff, #ece9ff); color: #2d2470;
  border-radius: 28px; padding: 20px 18px; text-align: center;
  box-shadow: 0 10px 0 rgba(30,20,90,0.35), 0 20px 40px rgba(0,0,0,0.3);
  display: flex; flex-direction: column; gap: 12px; align-items: stretch;
  animation: panelIn 0.3s cubic-bezier(.2,1.4,.5,1);
}
@keyframes panelIn { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.panel h2 { font-size: 30px; font-weight: 900; }
.panel .btn { width: 100%; }
.panel .row { display: flex; gap: 10px; }
.panel .row .btn:first-child { flex: 1; }
.panel .row .btn-small { flex: 1; }
.panel .row .btn-square { width: 56px; flex: 0 0 56px; }
.toggles { display: flex; gap: 14px; justify-content: center; }
.toggles .icon-btn { background: #8b7bff; box-shadow: 0 4px 0 #5b4bd6; }
.stars { display: flex; justify-content: center; gap: 6px; height: 64px; align-items: flex-end; }
.stars i { width: 54px; height: 54px; display: block; opacity: 0.2; filter: grayscale(1); transform: scale(0.8); }
.stars i:nth-child(2) { width: 64px; height: 64px; }
.stars i.on { opacity: 1; filter: none; animation: starIn 0.45s cubic-bezier(.2,1.6,.5,1) both; }
.stars i:nth-child(2).on { animation-delay: 0.15s; }
.stars i:nth-child(3).on { animation-delay: 0.3s; }
.stars svg { width: 100%; height: 100%; display: block; }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } to { transform: scale(1) rotate(0); } }
.win-praise { font-size: 20px; font-weight: 900; color: #ff3d6e; margin-top: -6px; }
.win-coins { display: flex; justify-content: center; align-items: center; gap: 8px; font-size: 30px; font-weight: 900; color: #d97706; }
.broken-heart { margin: 0 auto; width: 80px; height: 80px; animation: beat 1.2s infinite; }
.broken-heart svg { width: 100%; height: 100%; }
.fail-desc { font-size: 15px; font-weight: 700; opacity: 0.75; margin-top: -6px; }

/* ---------- Модальное окно ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15,10,45,0.6); z-index: 20; display: flex; align-items: center; justify-content: center; padding: 10px; }
.modal {
  width: min(460px, 96vw); max-height: 94%; display: flex; flex-direction: column;
  background: linear-gradient(180deg, #ffffff, #ece9ff); color: #2d2470;
  border-radius: 26px; box-shadow: 0 10px 0 rgba(30,20,90,0.35), 0 20px 40px rgba(0,0,0,0.3);
  animation: panelIn 0.3s cubic-bezier(.2,1.4,.5,1); overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px 20px; }
.modal-head h3 { font-size: 24px; font-weight: 900; }
.modal-head .icon-btn { background: #8b7bff; box-shadow: 0 3px 0 #5b4bd6; }
.modal-body { overflow-y: auto; padding: 4px 14px 16px; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.hint { font-size: 14px; font-weight: 700; opacity: 0.75; text-align: center; margin-bottom: 10px; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab { flex: 1; padding: 9px 4px; border-radius: 14px; background: #dcd7ff; color: #4b3fb0; font-weight: 900; font-size: 15px; }
.tab.on { background: #6f5bff; color: #fff; box-shadow: 0 4px 0 #4433c9; }
.card {
  display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 18px; padding: 10px;
  margin-bottom: 10px; box-shadow: 0 4px 0 rgba(80,60,200,0.18);
}
.card.hl { background: linear-gradient(135deg, #fff6c2, #e8e2ff); box-shadow: 0 4px 0 #f59e0b; }
.card-pic { flex: 0 0 auto; display: flex; align-items: center; justify-content: center; min-width: 64px; }
.card-pic svg { width: 48px; height: 48px; }
.card-pic canvas { border-radius: 12px; display: block; }
.card-info { flex: 1; min-width: 0; text-align: left; }
.card-title { font-weight: 900; font-size: 17px; }
.card-desc { font-size: 13px; font-weight: 700; opacity: 0.75; }
.card .btn { min-height: 42px; font-size: 16px; padding: 6px 12px; border-radius: 14px; flex: 0 0 auto; }
.card .btn-col { display: flex; flex-direction: column; gap: 8px; }
.price { display: inline-flex; align-items: center; gap: 4px; }
.days { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.day {
  background: #fff; border-radius: 14px; padding: 8px 4px; text-align: center; font-weight: 900; font-size: 13px;
  box-shadow: 0 3px 0 rgba(80,60,200,0.18); display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.day.last { grid-column: span 2; background: linear-gradient(135deg, #fff6c2, #e2dcff); }
.day.done { opacity: 0.45; }
.day.cur { background: linear-gradient(180deg, #ffe066, #ffb703); color: #7c2d12; transform: scale(1.06); box-shadow: 0 4px 0 #d97706; }
.day .amt { display: flex; align-items: center; gap: 3px; font-size: 15px; }
.day .bst { font-size: 11px; opacity: 0.8; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }
.modal-actions .btn { width: 100%; }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: #fff; border-radius: 14px; margin-bottom: 6px; font-weight: 800; }
.lb-row.me { background: #fff1a8; }
.lb-rank { width: 34px; text-align: center; font-weight: 900; color: #6f5bff; }
.lb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.lb-score { font-weight: 900; }
.set-row { display: flex; align-items: center; justify-content: space-between; background: #fff; border-radius: 16px; padding: 10px 14px; margin-bottom: 8px; font-weight: 900; font-size: 18px; }
.switch { width: 64px; height: 34px; border-radius: 17px; background: #d6d1f5; position: relative; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #fff; transition: left 0.2s; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
.switch.on { background: #22c55e; }
.switch.on::after { left: 33px; }

#toast {
  position: fixed; left: 50%; bottom: 18%; transform: translateX(-50%); z-index: 40;
  background: rgba(20,10,50,0.9); padding: 12px 20px; border-radius: 16px; font-weight: 800; font-size: 16px;
  max-width: 90vw; text-align: center; pointer-events: none; animation: fadein 0.2s;
}

@media (max-height: 560px) {
  .logo { margin-top: 4px; }
  .logo-title { font-size: 40px; }
  .tile { flex-direction: row; justify-content: center; padding: 6px; }
  .tile-ico svg { width: 24px; height: 24px; }
  .panel { padding: 12px; gap: 8px; }
  .panel h2 { font-size: 22px; }
  .stars { height: 44px; }
  .stars i { width: 38px; height: 38px; }
  .stars i:nth-child(2) { width: 44px; height: 44px; }
  .btn { min-height: 44px; font-size: 17px; }
  .btn-huge { min-height: 54px; font-size: 24px; }
}
@media (orientation: landscape) and (max-height: 640px) {
  #bar {
    position: absolute; right: max(12px, env(safe-area-inset-right)); top: 50%; transform: translateY(-50%);
    flex-direction: column; height: auto; padding: 0; gap: 14px; z-index: 2;
  }
  #hud { height: 54px; }
}
@media (orientation: landscape) {
  #screen-menu { flex-direction: row; flex-wrap: wrap; align-content: space-between; }
  #screen-menu .logo { position: absolute; left: 3vw; top: 50%; transform: translateY(-50%); margin: 0; width: 30vw; }
  #screen-menu .menu-bottom { position: absolute; right: 3vw; top: 50%; transform: translateY(-50%); width: min(360px, 32vw); }
  #screen-menu .menu-space { display: none; }
}
