@font-face {
  font-family: "Bungee";
  src: url("../assets/fonts/Bungee-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #1e181c;
  color: #fff;
}

#app {
  position: relative;
  width: 100%; height: 100%;
  height: 100dvh;
  overflow: hidden;
}

#bg-canvas, #game-canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  display: block;
  background: #1e181c;
}

#game-canvas { z-index: 1; }

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  pointer-events: none;
}

.screen.active { display: block; pointer-events: auto; }
.screen.overlay {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(28, 22, 26, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.screen.overlay .panel-glass {
  width: min(92vw, 360px);
  max-width: 100%;
  max-height: none;
  overflow: hidden;
  flex-shrink: 1;
  margin: auto;
  transform-origin: center center;
}

html.in-iframe .screen.overlay {
  padding-bottom: max(72px, calc(env(safe-area-inset-bottom) + 64px));
}

html.overlay-compact .screen.overlay .panel-glass {
  padding: 16px 14px 12px;
}

html.overlay-compact .screen.overlay .panel-glass h2 {
  font-size: 1.35rem;
  margin-bottom: 8px;
}

html.overlay-compact .screen.overlay .final-score {
  margin-bottom: 4px;
}

html.overlay-compact .screen.overlay .final-score strong {
  font-size: 1.85rem;
}

html.overlay-compact .screen.overlay .new-best {
  font-size: 0.85rem;
  margin-bottom: 8px;
}

html.overlay-compact .screen.overlay .reward-hint {
  font-size: 0.66rem;
  margin: 2px 0;
}

html.overlay-compact .screen.overlay .panel-glass .btn {
  padding: 11px 12px;
  font-size: 0.88rem;
  margin-top: 6px;
}

html.overlay-compact .screen.overlay .brand-logo-panel {
  width: min(52vw, 160px);
  margin-top: 8px;
}

html.overlay-tight .screen.overlay .brand-logo-panel {
  display: none;
}

html.overlay-tight .screen.overlay .reward-hint {
  display: none;
}

@media (max-height: 640px) {
  .screen.overlay .panel-glass {
    padding: 14px 12px 10px;
  }
  .screen.overlay .panel-glass .btn {
    padding: 10px 10px;
    font-size: 0.84rem;
    margin-top: 5px;
  }
  .screen.overlay .panel-glass h2 {
    font-size: 1.25rem;
    margin-bottom: 6px;
  }
  .screen.overlay .final-score strong {
    font-size: 1.65rem;
  }
  .screen.overlay .brand-logo-panel {
    display: none;
  }
}

@media (min-height: 900px) {
  .screen.overlay .panel-glass {
    width: min(92vw, 380px);
  }
}

.screen.overlay.active {
  display: flex;
}

/* ── Splash / branding (GD) ── */
.screen.splash {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(20, 16, 18, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}

.screen.splash.active {
  display: flex;
  pointer-events: auto;
}

.splash-inner {
  text-align: center;
  width: min(92vw, 380px);
  max-height: calc(100dvh - max(40px, env(safe-area-inset-top)) - max(40px, env(safe-area-inset-bottom)));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-height: 640px) {
  .game-title--hero .game-title__line--main { font-size: clamp(2.4rem, 14vw, 3.2rem); }
  .game-title--hero .game-title__line--top { font-size: clamp(0.95rem, 4vw, 1.2rem); }
  .brand-logo-splash { width: min(62vw, 220px); margin-top: 14px; }
  .splash-btn { margin-top: 16px; }
  .screen.splash { padding: max(12px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom)); }
}

.brand-logo {
  display: block;
  margin-left: auto;
  margin-right: auto;
  height: auto;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.brand-wordmark {
  color: #ffffff;
  font-family: "Bungee", Impact, sans-serif;
  font-size: clamp(1.15rem, 5vw, 1.75rem);
  letter-spacing: -0.06em;
  line-height: 1;
  text-decoration: none;
  pointer-events: auto;
}

.brand-wordmark span {
  color: #b7ff58;
}

.brand-wordmark small {
  margin-left: 3px;
  color: rgba(255, 255, 255, 0.5);
  font-family: system-ui, sans-serif;
  font-size: 0.36em;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.ad-free-note {
  margin-top: 14px;
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-logo-splash {
  width: min(72vw, 280px);
  margin-top: 20px;
  opacity: 1;
  filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.45));
  animation: logoIn 0.7s 0.18s ease-out both;
}

.brand-logo-menu {
  width: min(72vw, 240px);
  margin-top: 14px;
  opacity: 0.95;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.35));
}

.brand-logo-panel {
  width: min(68vw, 220px);
  margin: 16px auto 0;
  opacity: 0.9;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
}

.splash-btn {
  margin-top: 24px;
  animation: logoIn 0.7s 0.28s ease-out both;
}

@keyframes logoIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

#screen-splash.active .sound-btn { pointer-events: auto; }

.credit-in-panel { display: none; }

html.in-iframe .screen.splash {
  padding-bottom: max(56px, calc(env(safe-area-inset-bottom) + 48px));
}

/* ── Menu floating lights ── */
.menu-lights {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  animation: orbFloat 8s ease-in-out infinite;
}

.orb-a {
  width: 220px; height: 220px;
  top: 8%; left: -5%;
  background: rgba(255, 170, 120, 0.32);
  animation-delay: 0s;
}

.orb-b {
  width: 180px; height: 180px;
  top: 15%; right: -8%;
  background: rgba(255, 130, 160, 0.28);
  animation-delay: -3s;
}

.orb-c {
  width: 140px; height: 140px;
  bottom: 35%; left: 30%;
  background: rgba(255, 200, 140, 0.22);
  animation-delay: -5s;
}

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(12px, -18px) scale(1.08); }
}

/* ── Glass panel ── */
.panel {
  text-align: center;
  min-width: min(92vw, 340px);
  position: relative;
}

.panel-glass {
  background: linear-gradient(145deg, rgba(60, 48, 52, 0.58), rgba(32, 26, 30, 0.75));
  border: 1px solid rgba(255, 220, 190, 0.14);
  border-radius: 24px;
  padding: 28px 28px 24px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.05) inset,
    0 24px 80px rgba(0, 0, 0, 0.45),
    0 0 60px rgba(255, 160, 120, 0.1);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  overflow: hidden;
}

.panel-glass::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 25px;
  padding: 1px;
  background: linear-gradient(135deg, rgba(255,255,255,0.22), rgba(255,180,140,0.18), rgba(255,140,160,0.18));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  animation: borderPulse 4s ease-in-out infinite;
}

@keyframes borderPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

#screen-menu.active {
  display: block;
  pointer-events: none;
  overflow: hidden;
}

#screen-menu.active .menu-panel,
#screen-menu.active .sound-btn { pointer-events: auto; }

.menu-panel {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: var(--panel-top, 50%);
  width: min(92vw, 340px);
  max-width: 380px;
  margin: 0;
  max-height: none;
  overflow: visible;
}

html.in-iframe .sound-btn {
  bottom: max(52px, calc(env(safe-area-inset-bottom) + 44px));
}

html.menu-compact .menu-logo {
  display: none;
}

html.menu-compact .menu-panel .panel-glass {
  padding: 14px 16px 12px;
}

html.menu-compact .game-title--menu .game-title__line--main {
  font-size: clamp(1.85rem, 9.5vw, 2.35rem);
}

html.menu-compact .game-title--menu .game-title__line--top {
  font-size: clamp(0.8rem, 3.2vw, 0.95rem);
}

html.menu-compact .subtitle {
  font-size: 0.68rem;
  margin-top: 2px;
  line-height: 1.25;
}

html.menu-compact .best-box {
  margin: 8px 0 10px;
  padding: 8px 14px;
}

html.menu-compact .best-value {
  font-size: 1.65rem;
}

html.menu-compact .btn {
  padding: 12px 14px;
  font-size: 0.95rem;
  margin-top: 6px;
}

html.menu-compact .game-title__gem {
  width: 9px;
  height: 9px;
}

@media (max-height: 640px) {
  .menu-panel { width: min(94vw, 320px); }
}

@media (min-width: 768px) {
  .menu-panel { width: min(380px, 40vw); }
}

@media (orientation: landscape) and (max-height: 520px) {
  .menu-panel { width: min(320px, 44vw); }
  html.menu-compact .subtitle { display: none; }
}

/* ── Game title wordmark ── */
.game-title {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 0.9;
  padding: 6px 28px 10px;
  margin: 0 auto 4px;
  animation: titlePop 0.65s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.game-title--hero {
  padding: 10px 36px 14px;
  margin-bottom: 0;
}

.game-title--menu {
  margin-bottom: 2px;
}

.game-title__line {
  display: block;
  font-family: "Bungee", "Arial Black", sans-serif;
  font-style: normal;
  font-weight: 400;
  text-transform: uppercase;
  user-select: none;
}

.game-title__line--top {
  font-size: clamp(1rem, 4.2vw, 1.35rem);
  letter-spacing: 0.42em;
  margin-right: -0.42em;
  color: #fff3e4;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35),
    0 3px 0 #7a5848,
    0 5px 14px rgba(0, 0, 0, 0.45);
  opacity: 0.95;
}

.game-title__line--main {
  margin-top: -2px;
  font-size: clamp(2.6rem, 12vw, 3.75rem);
  letter-spacing: 0.04em;
  background: linear-gradient(
    175deg,
    #fffef8 0%,
    #ffe566 18%,
    #ffb347 42%,
    #ff6b9d 72%,
    #ff4757 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  filter:
    drop-shadow(0 2px 0 #b83a4a)
    drop-shadow(0 5px 0 #7a2535)
    drop-shadow(0 10px 22px rgba(255, 100, 120, 0.45));
  transform: rotate(-2deg) scaleX(1.02);
}

.game-title--hero .game-title__line--top {
  font-size: clamp(1.15rem, 5vw, 1.55rem);
}

.game-title--hero .game-title__line--main {
  font-size: clamp(3.2rem, 16vw, 4.6rem);
  filter:
    drop-shadow(0 3px 0 #b83a4a)
    drop-shadow(0 6px 0 #7a2535)
    drop-shadow(0 14px 28px rgba(255, 100, 120, 0.5));
}

.game-title__gem {
  position: absolute;
  width: 13px;
  height: 13px;
  border-radius: 3px;
  transform: rotate(12deg);
  box-shadow:
    0 2px 0 rgba(0, 0, 0, 0.35),
    0 0 12px rgba(255, 200, 100, 0.35);
  animation: gemBob 2.8s ease-in-out infinite;
}

.game-title__gem--tl {
  top: 2px;
  left: 0;
  background: linear-gradient(145deg, #7bed9f, #1b8a4a);
  animation-delay: 0s;
}

.game-title__gem--tr {
  top: 18%;
  right: -2px;
  width: 10px;
  height: 10px;
  background: linear-gradient(145deg, #82baff, #1565c0);
  animation-delay: -0.9s;
}

.game-title__gem--bl {
  bottom: 8px;
  left: 8%;
  width: 11px;
  height: 11px;
  background: linear-gradient(145deg, #ffc880, #e65100);
  animation-delay: -1.6s;
}

@keyframes titlePop {
  from {
    opacity: 0;
    transform: scale(0.88) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes gemBob {
  0%, 100% { transform: rotate(12deg) translateY(0); }
  50% { transform: rotate(12deg) translateY(-4px); }
}

.subtitle {
  margin-top: 6px;
  font-size: 0.82rem;
  color: rgba(255, 230, 210, 0.58);
  letter-spacing: 0.04em;
}

.best-box {
  margin: 22px 0 20px;
  padding: 14px 20px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3) inset;
}

.best-label {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.4);
}

.best-value {
  display: block;
  font-size: 2.4rem;
  font-weight: 800;
  margin-top: 4px;
  background: linear-gradient(180deg, #ffe566, #ffd166, #f0a500);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 12px rgba(255, 209, 102, 0.45));
}

.panel h2 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 16px;
  text-shadow: 0 0 20px rgba(255, 180, 120, 0.35);
}

.final-score {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.55);
  margin-bottom: 8px;
}

.final-score strong {
  display: block;
  font-size: 2.4rem;
  font-weight: 800;
  color: #fff;
  margin-top: 6px;
  text-shadow: 0 0 24px rgba(255, 255, 255, 0.25);
}

.new-best {
  color: #ffd166;
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 16px;
  text-shadow: 0 0 16px rgba(255, 209, 102, 0.5);
}

/* ── Buttons ── */
.btn {
  display: block;
  width: 100%;
  max-width: 100%;
  padding: 16px 20px;
  border: none;
  border-radius: 16px;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  margin-top: 10px;
  position: relative;
  overflow: hidden;
  transition: transform 0.12s, box-shadow 0.12s;
  letter-spacing: 0.02em;
  white-space: normal;
  line-height: 1.2;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, #ff9a6c 0%, #ff7e8a 50%, #e86aa0 100%);
  color: #fff;
  box-shadow:
    0 6px 28px rgba(255, 140, 100, 0.4),
    0 0 40px rgba(255, 120, 140, 0.18),
    0 2px 0 rgba(255, 255, 255, 0.15) inset;
}

.btn-glow {
  animation: btnPulse 3s ease-in-out infinite;
}

@keyframes btnPulse {
  0%, 100% { box-shadow: 0 6px 28px rgba(255,140,100,0.4), 0 0 40px rgba(255,120,140,0.18), 0 2px 0 rgba(255,255,255,0.15) inset; }
  50% { box-shadow: 0 8px 36px rgba(255,140,100,0.55), 0 0 60px rgba(255,120,140,0.3), 0 2px 0 rgba(255,255,255,0.2) inset; }
}

.btn-shine {
  position: absolute;
  top: 0; left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
  animation: btnShine 3s ease-in-out infinite;
}

@keyframes btnShine {
  0% { left: -100%; }
  40%, 100% { left: 150%; }
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.btn-reward {
  background: linear-gradient(135deg, #ffc857 0%, #ff9f43 45%, #ff7b54 100%);
  color: #2a1810;
  font-weight: 800;
  box-shadow:
    0 6px 24px rgba(255, 170, 60, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.25) inset;
  margin-top: 8px;
}

.btn-reward-alt {
  background: linear-gradient(135deg, #ffe566 0%, #ffd32a 50%, #ffb830 100%);
}

.btn-reward:disabled {
  opacity: 0.35;
  pointer-events: none;
  filter: grayscale(0.4);
}

.btn-reward.hidden-use { display: none; }

.reward-hint {
  font-size: 0.72rem;
  color: rgba(255, 220, 170, 0.55);
  margin: 4px 0 2px;
  letter-spacing: 0.02em;
}

.reward-hint.hidden { display: none; }

#continue-hint { margin-bottom: 6px; }

/* ── HUD ── */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: calc(var(--hud-height, 52px) + max(8px, env(safe-area-inset-top)));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 12px 6px;
  padding-top: max(6px, env(safe-area-inset-top));
  pointer-events: auto;
  z-index: 5;
  gap: 8px;
  box-sizing: border-box;
}

.hud-score {
  flex: 1;
  padding: 8px 14px;
  border-radius: 14px;
  background: rgba(10, 14, 32, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.hud-right { text-align: right; }

.hud-label {
  display: block;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(180, 200, 255, 0.5);
}

.hud-value {
  display: inline-block;
  font-size: 1.4rem;
  font-weight: 800;
  text-shadow: 0 0 12px rgba(255, 180, 120, 0.28);
}

.hud-value.bump {
  animation: hudBump 0.34s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes hudBump {
  0% { transform: scale(1); }
  40% { transform: scale(1.28); text-shadow: 0 0 18px rgba(255, 200, 120, 0.7); }
  100% { transform: scale(1); }
}

.hud-combo {
  display: block;
  margin-top: 2px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: rgba(255, 210, 100, 0.95);
  text-shadow: 0 0 10px rgba(255, 180, 60, 0.45);
}

.icon-btn {
  width: 46px; height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: rgba(10, 14, 32, 0.65);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.icon-btn:active { background: rgba(255, 255, 255, 0.1); }

.sound-btn {
  position: absolute;
  bottom: max(8px, env(safe-area-inset-bottom));
  right: max(8px, env(safe-area-inset-right));
  z-index: 100;
  width: 40px; height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(10, 14, 32, 0.7);
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  backdrop-filter: blur(8px);
}

.credit-in-panel {
  margin-top: 14px;
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.22);
  letter-spacing: 0.06em;
}

.credit { display: none; }

#screen-pause.active ~ .sound-btn,
#screen-over.active ~ .sound-btn { pointer-events: auto; }

#screen-game.active { pointer-events: none; }
#screen-game.active .hud,
#screen-game.active .sound-btn { pointer-events: auto; }

.hidden { display: none !important; }
