/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --c1: #FF4D6D; --c2: #FFB703; --c3: #06D6A0; --c4: #4CC9F0; --c5: #7B2FBE;
  --c6: #F72585; --c7: #3A86FF; --c8: #FB5607;
  --bg-dark: #0D0B1E;
  --bg-mid: #1A1040;
  --gold: #FFD700;
  --radius: 20px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Nunito', sans-serif;
  background: var(--bg-dark);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== SCREENS ===== */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.4s ease;
  z-index: 10;
}
.screen.active { opacity: 1; pointer-events: all; }

/* ===== SPLASH ===== */
#splash-screen {
  background: linear-gradient(135deg, #1A1040 0%, #6C3CE1 50%, #FF4D6D 100%);
  z-index: 100;
  flex-direction: column;
}
.splash-bg {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 30%, rgba(108,60,225,0.6) 0%, transparent 70%);
  animation: pulseBg 2s ease-in-out infinite;
}
@keyframes pulseBg { 0%,100%{opacity:0.6} 50%{opacity:1} }

.splash-content {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  text-align: center;
}
.splash-img {
  width: 140px; height: 140px;
  object-fit: contain;
  filter: drop-shadow(0 8px 24px rgba(255,77,109,0.6));
  animation: floatIcon 2s ease-in-out infinite;
}
@keyframes floatIcon { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-12px)} }

.splash-title {
  font-family: 'Fredoka One', cursive;
  font-size: 2.4rem; color: #fff;
  text-shadow: 0 4px 12px rgba(0,0,0,0.4);
  line-height: 1.1;
}
.splash-title span { color: var(--gold); }

.loading-bar-wrap {
  width: 240px; height: 10px;
  background: rgba(255,255,255,0.15);
  border-radius: 99px; overflow: hidden;
  margin-top: 8px;
}
.loading-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--c2), var(--c1));
  border-radius: 99px;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px var(--c1);
}
.loading-text { color: rgba(255,255,255,0.6); font-size: 0.85rem; letter-spacing: 2px; }

.splash-particles {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden;
}
.spark {
  position: absolute;
  width: 6px; height: 6px;
  border-radius: 50%;
  animation: sparkFly linear infinite;
}
@keyframes sparkFly {
  0%   { transform: translateY(110vh) scale(0); opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 0.8; }
  100% { transform: translateY(-10vh) scale(1.5); opacity: 0; }
}

/* ===== MENU ===== */
#menu-screen {
  background: linear-gradient(160deg, #0D0B1E 0%, #1A1040 40%, #2D1B69 100%);
  flex-direction: column;
}
.menu-bg-anim {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(123,47,190,0.3) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(255,77,109,0.2) 0%, transparent 50%);
  animation: bgShift 5s ease-in-out infinite alternate;
}
@keyframes bgShift { 0%{filter:hue-rotate(0deg)} 100%{filter:hue-rotate(30deg)} }

.floating-blocks {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden;
}
.float-block {
  position: absolute;
  border-radius: 10px;
  animation: floatBlock linear infinite;
  opacity: 0.25;
}
@keyframes floatBlock {
  0%   { transform: translateY(110%) rotate(0deg); opacity: 0; }
  10%  { opacity: 0.25; }
  90%  { opacity: 0.15; }
  100% { transform: translateY(-10%) rotate(360deg); opacity: 0; }
}

.menu-content {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  padding: 20px;
  width: 100%; max-width: 420px;
}

.game-logo { text-align: center; }
.menu-icon {
  width: 90px; height: 90px; object-fit: contain;
  filter: drop-shadow(0 6px 20px rgba(255,183,3,0.5));
  animation: floatIcon 2.5s ease-in-out infinite;
}
.game-title {
  font-family: 'Fredoka One', cursive;
  font-size: 2.2rem; color: #fff; line-height: 1.1; margin-top: 8px;
  text-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.game-title span { color: var(--gold); }

.menu-stats {
  display: flex; gap: 12px; width: 100%; justify-content: center;
}
.stat-card {
  flex: 1; max-width: 110px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px; padding: 12px 8px;
  text-align: center;
  backdrop-filter: blur(10px);
  display: flex; flex-direction: column; gap: 3px;
}
.stat-icon { font-size: 1.4rem; }
.stat-label { font-size: 0.7rem; color: rgba(255,255,255,0.5); letter-spacing: 1px; text-transform: uppercase; }
.stat-val { font-family: 'Fredoka One', cursive; font-size: 1.4rem; color: #fff; }

.btn-play {
  width: 100%; max-width: 280px;
  padding: 18px 32px;
  border: none; border-radius: 99px; cursor: pointer;
  background: linear-gradient(135deg, var(--c1), var(--c5));
  color: #fff; font-family: 'Fredoka One', cursive; font-size: 1.5rem;
  letter-spacing: 2px;
  box-shadow: 0 6px 24px rgba(255,77,109,0.5), 0 0 0 0 rgba(255,77,109,0.4);
  transition: all 0.2s;
  position: relative; overflow: hidden;
  animation: pulsePlay 2s ease-in-out infinite;
}
@keyframes pulsePlay {
  0%,100%{box-shadow:0 6px 24px rgba(255,77,109,0.5),0 0 0 0 rgba(255,77,109,0.4)}
  50%{box-shadow:0 6px 32px rgba(255,77,109,0.7),0 0 0 12px rgba(255,77,109,0)}
}
.btn-play:hover { transform: scale(1.05); }
.btn-play:active { transform: scale(0.97); }
.btn-play-inner { position: relative; z-index: 1; }

.menu-buttons { display: flex; gap: 12px; width: 100%; max-width: 280px; }
.btn-menu {
  flex: 1; padding: 12px 8px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 14px; cursor: pointer;
  background: rgba(255,255,255,0.07);
  color: #fff; font-family: 'Nunito', sans-serif; font-size: 0.9rem; font-weight: 700;
  backdrop-filter: blur(8px);
  transition: all 0.2s;
}
.btn-menu:hover { background: rgba(255,255,255,0.14); transform: translateY(-2px); }

.btn-mute {
  position: absolute; top: 20px; right: 20px;
  width: 44px; height: 44px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%; background: rgba(255,255,255,0.07);
  backdrop-filter: blur(8px); color: #fff; font-size: 1.2rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* ===== TUTORIAL ===== */
#tutorial-screen {
  background: linear-gradient(160deg, #0D0B1E 0%, #2D1B69 100%);
}
.tutorial-bg {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(76,201,240,0.1) 0%, transparent 70%);
}
.tutorial-content {
  position: relative; z-index: 2;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 24px; padding: 28px 24px;
  width: 100%; max-width: 400px; backdrop-filter: blur(12px);
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.tutorial-title {
  font-family: 'Fredoka One', cursive; font-size: 1.8rem; color: var(--gold);
}
.tutorial-steps { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.tutorial-step {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,0.05); border-radius: 12px; padding: 10px 14px;
}
.step-icon { font-size: 1.5rem; flex-shrink: 0; }
.step-text { color: rgba(255,255,255,0.85); font-size: 0.9rem; }
.step-text strong { color: #fff; }

.tutorial-preview {
  background: rgba(0,0,0,0.3); border-radius: 16px; overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
}
#tutorial-canvas { display: block; }

/* ===== LEVELS ===== */
#levels-screen {
  background: linear-gradient(160deg, #0D0B1E 0%, #2D1B69 100%);
}
.levels-bg {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(123,47,190,0.3) 0%, transparent 60%);
}
.levels-content {
  position: relative; z-index: 2;
  width: 100%; max-width: 440px; padding: 20px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  max-height: 100vh; overflow-y: auto;
}
.levels-title {
  font-family: 'Fredoka One', cursive; font-size: 1.8rem; color: var(--gold);
}
.levels-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px;
  width: 100%;
}
.level-btn {
  aspect-ratio: 1; border-radius: 14px; border: none; cursor: pointer;
  font-family: 'Fredoka One', cursive; font-size: 1.1rem; color: #fff;
  position: relative; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  transition: all 0.2s;
}
.level-btn.unlocked {
  background: linear-gradient(135deg, var(--c5), var(--c7));
  box-shadow: 0 4px 12px rgba(123,47,190,0.4);
}
.level-btn.current {
  background: linear-gradient(135deg, var(--c1), var(--c2));
  box-shadow: 0 4px 12px rgba(255,77,109,0.5);
  animation: pulseCurrent 1.5s ease-in-out infinite;
}
@keyframes pulseCurrent {
  0%,100%{transform:scale(1)} 50%{transform:scale(1.06)}
}
.level-btn.locked {
  background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.25); cursor: default;
}
.level-btn .level-stars { font-size: 0.5rem; letter-spacing: 1px; }
.level-btn:hover:not(.locked) { transform: scale(1.08); }

/* ===== GAME SCREEN ===== */
#game-screen {
  flex-direction: column;
  background: linear-gradient(180deg, #060417 0%, #1a0a3e 60%, #0a1a2e 100%);
}
.game-hud {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px 6px;
  z-index: 20;
}
.hud-left, .hud-right {
  display: flex; align-items: center; gap: 8px;
}
.hud-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.07); color: #fff; font-size: 1.1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.hud-level {
  font-family: 'Fredoka One', cursive; font-size: 1rem; color: rgba(255,255,255,0.7);
}
.hud-gems {
  font-family: 'Fredoka One', cursive; font-size: 1rem; color: var(--gold);
}
.hud-center { display: flex; flex-direction: column; align-items: center; }
.score-display { display: flex; flex-direction: column; align-items: center; }
.score-label { font-size: 0.65rem; color: rgba(255,255,255,0.5); letter-spacing: 2px; }
.score-val {
  font-family: 'Fredoka One', cursive; font-size: 1.8rem; color: #fff;
  text-shadow: 0 0 20px rgba(255,183,3,0.5);
  transition: transform 0.1s;
}
.score-val.pop { animation: scorePop 0.3s ease; }
@keyframes scorePop { 0%{transform:scale(1)} 50%{transform:scale(1.3)} 100%{transform:scale(1)} }

.combo-display {
  background: linear-gradient(135deg, var(--c1), var(--c2));
  border-radius: 99px; padding: 2px 12px; margin-top: 2px;
  animation: comboPop 0.4s ease;
}
@keyframes comboPop {
  0%{transform:scale(0) rotate(-10deg)} 60%{transform:scale(1.2) rotate(3deg)} 100%{transform:scale(1) rotate(0)}
}
#combo-text { font-family: 'Fredoka One', cursive; font-size: 0.85rem; color: #fff; }

.game-area {
  flex: 1; width: 100%; position: relative; overflow: hidden;
}
#game-canvas { width: 100%; height: 100%; display: block; }

.tap-hint {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  font-family: 'Fredoka One', cursive; font-size: 1.4rem; color: rgba(255,255,255,0.7);
  pointer-events: none;
  animation: tapPulse 1s ease-in-out infinite;
}
@keyframes tapPulse { 0%,100%{opacity:0.7;transform:translate(-50%,-50%) scale(1)} 50%{opacity:1;transform:translate(-50%,-50%) scale(1.1)} }

.game-bottom-bar {
  width: 100%; padding: 8px 16px 12px;
  z-index: 20;
}
.tower-height-bar { display: flex; align-items: center; gap: 8px; }
.height-label { font-size: 0.7rem; color: rgba(255,255,255,0.5); white-space: nowrap; }
.height-bar-wrap {
  flex: 1; height: 8px;
  background: rgba(255,255,255,0.1); border-radius: 99px; overflow: visible;
  position: relative;
}
.height-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--c3), var(--c2));
  border-radius: 99px;
  transition: width 0.3s ease;
  box-shadow: 0 0 8px var(--c3);
}
.height-star {
  position: absolute; right: 0; top: 50%; transform: translate(50%,-50%);
  font-size: 1rem;
  transition: right 0.3s ease;
}
.height-val { font-family: 'Fredoka One', cursive; font-size: 0.85rem; color: var(--gold); white-space: nowrap; }

/* ===== OVERLAY SCREENS ===== */
.overlay-screen {
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  z-index: 50;
}
.overlay-panel {
  background: linear-gradient(135deg, #1A1040, #2D1B69);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 28px; padding: 30px 24px;
  width: 100%; max-width: 340px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  position: relative; overflow: hidden;
}
.overlay-panel h2 {
  font-family: 'Fredoka One', cursive; font-size: 1.8rem; color: #fff;
}
.pause-score { font-size: 1rem; color: rgba(255,255,255,0.7); }

.btn-overlay {
  width: 100%; padding: 14px;
  border: none; border-radius: 14px; cursor: pointer;
  background: linear-gradient(135deg, var(--c1), var(--c5));
  color: #fff; font-family: 'Fredoka One', cursive; font-size: 1.1rem;
  transition: all 0.2s;
}
.btn-overlay.secondary {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
}
.btn-overlay:hover { transform: scale(1.03); }
.btn-overlay:active { transform: scale(0.97); }

/* ===== GAME OVER ===== */
.gameover-panel { gap: 12px; }
.gameover-emoji { font-size: 3rem; animation: emojiPop 0.5s cubic-bezier(0.36,0.07,0.19,0.97); }
@keyframes emojiPop {
  0%{transform:scale(0) rotate(-20deg)} 60%{transform:scale(1.3) rotate(5deg)} 100%{transform:scale(1) rotate(0)}
}
.gameover-title { font-family: 'Fredoka One', cursive; font-size: 2rem; color: var(--gold); }
.go-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%;
}
.go-stat {
  background: rgba(255,255,255,0.06); border-radius: 12px; padding: 10px 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.go-stat-label { font-size: 0.65rem; color: rgba(255,255,255,0.5); letter-spacing: 1px; text-transform: uppercase; }
.go-stat-val { font-family: 'Fredoka One', cursive; font-size: 1.4rem; color: #fff; }
.stars-display { font-size: 2rem; letter-spacing: 4px; }
.new-best-badge {
  background: linear-gradient(135deg, var(--gold), #FF8C00);
  border-radius: 99px; padding: 4px 16px;
  font-family: 'Fredoka One', cursive; font-size: 0.95rem; color: #fff;
  animation: badgePop 0.5s cubic-bezier(0.36,0.07,0.19,0.97);
}
@keyframes badgePop {
  0%{transform:scale(0)} 70%{transform:scale(1.2)} 100%{transform:scale(1)}
}
.go-btns { display: flex; gap: 10px; width: 100%; }
.go-btns .btn-overlay { flex: 1; }
.confetti-container { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti-piece {
  position: absolute; width: 8px; height: 8px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(400px) rotate(720deg); opacity: 0; }
}

.btn-back {
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 14px; padding: 10px 24px;
  color: #fff; font-family: 'Nunito', sans-serif; font-size: 0.95rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s;
}
.btn-back:hover { background: rgba(255,255,255,0.14); }

/* ===== FLOATING SCORE TEXT ===== */
.float-score {
  position: fixed; pointer-events: none;
  font-family: 'Fredoka One', cursive; font-size: 1.4rem; color: var(--gold);
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  z-index: 200;
  animation: floatUp 1s ease forwards;
}
@keyframes floatUp {
  0%   { transform: translateY(0) scale(0.5); opacity: 0; }
  20%  { transform: translateY(-10px) scale(1.2); opacity: 1; }
  100% { transform: translateY(-70px) scale(1); opacity: 0; }
}

/* ===== RESPONSIVE ===== */
@media (max-height: 600px) {
  .menu-content { gap: 12px; }
  .game-title { font-size: 1.6rem; }
  .menu-icon { width: 60px; height: 60px; }
  .btn-play { padding: 14px 28px; font-size: 1.2rem; }
}
@media (min-width: 600px) {
  .game-area canvas { max-width: 500px; margin: 0 auto; }
}
