:root {
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

html { height: 100%; }

* { -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top, #ffb6c1, #ff69b4, #e91e63);
  overflow: hidden;
  font-family: 'Poppins', sans-serif;
  color: #fff;
  text-align: center;
  height: 100vh;
  height: 100dvh;
  touch-action: manipulation;
}

.game-container {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 10px) calc(var(--safe-l) + 12px);
  box-sizing: border-box;
}

.game-title {
  font-family: 'Dancing Script', cursive;
  font-size: clamp(1.9rem, 8vw, 3rem);
  margin: 0 0 0.2rem;
  text-shadow: 0 0 20px #fff, 0 0 40px #ff69b4;
  animation: glow 2.5s infinite alternate;
}

.subtitle {
  font-family: 'Dancing Script', cursive;
  font-size: clamp(1.05rem, 4vw, 1.4rem);
  color: #fff9f9;
  margin-bottom: 1rem;
}

@keyframes glow {
  from { text-shadow: 0 0 10px #fff, 0 0 20px #ff69b4; }
  to { text-shadow: 0 0 25px #fff, 0 0 60px #e91e63; }
}

#score-board, #timer {
  font-size: clamp(0.95rem, 3.4vw, 1.2rem);
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50px;
  padding: 0.5rem 1.2rem;
  margin: 0.3rem;
  backdrop-filter: blur(10px);
  box-shadow: 0 0 10px rgba(255, 64, 129, 0.4);
  transition: box-shadow 0.3s ease, background 0.3s ease;
}

#score-board.bump { animation: score-bump 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes score-bump {
  0% { transform: scale(1); }
  45% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

#timer.timer-warning {
  background: rgba(255, 64, 64, 0.28);
  animation: timer-pulse 0.9s ease-in-out infinite;
}
@keyframes timer-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(255, 64, 129, 0.4); }
  50% { box-shadow: 0 0 22px rgba(255, 40, 40, 0.85); }
}

#game-area {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
#game-area.enter {
  animation: gameAreaIn 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes gameAreaIn {
  from { opacity: 0.4; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

/* Hidden class */
.hidden { display: none !important; }

/* Burst sparkles */
.sparkle-burst {
  position: absolute;
  animation: burst 0.9s cubic-bezier(0.22, 1.4, 0.36, 1) forwards;
  pointer-events: none;
  z-index: 11;
}

@keyframes burst {
  0% { transform: scale(0) rotate(0deg); opacity: 1; }
  55% { transform: scale(1.6) rotate(140deg); opacity: 1; }
  100% { transform: scale(2.1) rotate(220deg); opacity: 0; }
}

.heart {
  position: absolute;
  cursor: pointer;
  animation: heartRise linear forwards;
  text-shadow: 0 0 10px #fff;
  user-select: none;
  padding: 22px;
  margin: -22px;
  line-height: 1;
  will-change: transform, opacity;
}

/* Slower, smoother floating with a bit of natural side-to-side drift and
   spin so hearts feel like they're tumbling on a breeze, not sliding on rails */
@keyframes heartRise {
  0% {
    transform: translate(0, 100vh) scale(0.6) rotate(0deg);
    opacity: 0;
  }
  8% { opacity: 1; }
  28% {
    transform: translate(var(--sway-a, 14px), 72vh) scale(1.15) rotate(var(--spin, 10deg));
  }
  52% {
    transform: translate(calc(var(--sway-a, 14px) * -1), 46vh) scale(1.3) rotate(calc(var(--spin, 10deg) * -1));
  }
  76% {
    transform: translate(var(--sway-b, -10px), 20vh) scale(1.38) rotate(var(--spin, 10deg));
  }
  92% { opacity: 1; }
  100% {
    transform: translate(0, -12vh) scale(1.42) rotate(0deg);
    opacity: 0;
  }
}


/* === BACK BUTTON POSITION === */
.back-btn {
  position: fixed;
  bottom: calc(var(--safe-b) + 30px);
  right: calc(var(--safe-r) + 30px);
  z-index: 1000;
  padding: 12px 28px;
  font-size: 1.1rem;
  animation: pulseGlow 2.5s ease-in-out infinite;
}

/* Reuse golden-btn from previous */
.golden-btn {
  position: relative;
  padding: 14px 36px;
  font-family: 'Dancing Script', cursive;
  font-weight: 700;
  font-size: 1.4rem;
  color: #fff;
  background: linear-gradient(45deg, #ffd700, #ffb800, #ff9900, #cc7a00);
  background-size: 300% 300%;
  border: none;
  border-radius: 50px;
  box-shadow: 
    0 8px 20px rgba(255, 215, 0, 0.4),
    0 0 0 4px rgba(255, 215, 0, 0.2),
    inset 0 2px 4px rgba(255, 255, 255, 0.3);
  cursor: pointer;
  overflow: hidden;
  transition: all 0.4s ease;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  letter-spacing: 1px;
  z-index: 1;
}

.golden-btn::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
  transform: skewX(-25deg);
  z-index: -1;
}

.golden-btn:hover::before {
  left: 100%;
  transition: left 0.7s ease;
}

.golden-btn:hover {
  background-position: 100% 0;
  transform: translateY(-3px);
  box-shadow: 0 15px 35px rgba(255, 215, 0, 0.5), 0 0 0 6px rgba(255, 215, 0, 0.3);
}

.golden-btn:active {
  transform: translateY(-1px);
}

@keyframes pulseGlow {
  0%, 100% { 
    box-shadow: 
      0 8px 20px rgba(255, 215, 0, 0.4),
      0 0 0 4px rgba(255, 215, 0, 0.2),
      inset 0 2px 4px rgba(255, 255, 255, 0.3);
  }
  50% { 
    box-shadow: 
      0 12px 30px rgba(255, 215, 0, 0.6),
      0 0 0 8px rgba(255, 215, 0, 0.4),
      inset 0 2px 4px rgba(255, 255, 255, 0.5);
  }
}

/* Mobile Adjustment */
@media (max-width: 480px) {
  .back-btn {
    bottom: calc(var(--safe-b) + 20px);
    right: calc(var(--safe-r) + 20px);
    padding: 10px 20px;
    font-size: 1rem;
  }
  .game-title { margin-top: 0.2rem; }
  .start-btn { font-size: 1.35rem; padding: 0.85rem 2.4rem; }
}



.start-btn {
  background: linear-gradient(45deg, #ff80ab, #e91e63);
  border: none;
  color: #fff;
  font-family: 'Dancing Script', cursive;
  font-size: 1.6rem;
  padding: 1rem 3rem;
  border-radius: 60px;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(233, 30, 99, 0.5);
  animation: bouncePulse 3s infinite ease-in-out;
  margin-top: 1.5rem;
  transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.45s ease;
}

.start-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 18px 50px rgba(255, 64, 129, 0.7);
}

@keyframes bouncePulse {
  0%, 100% {
    transform: translateY(0) scale(1);
    box-shadow: 0 10px 25px rgba(233, 30, 99, 0.5);
  }
  50% {
    transform: translateY(-6px) scale(1.07);
    box-shadow: 0 14px 35px rgba(255, 64, 129, 0.7);
  }
}

/* Stop state: cooler tone so it visually reads as "the game is running,
   tap to end it" rather than a repeat of the same Start action */
.start-btn.is-stop {
  background: linear-gradient(45deg, #6a3fa0, #3d2a78);
  box-shadow: 0 10px 30px rgba(90, 50, 160, 0.5);
  animation: stopPulse 1.6s infinite ease-in-out;
}
.start-btn.is-stop:hover {
  box-shadow: 0 18px 50px rgba(120, 70, 200, 0.6);
}
@keyframes stopPulse {
  0%, 100% { box-shadow: 0 10px 25px rgba(90, 50, 160, 0.5); }
  50% { box-shadow: 0 14px 32px rgba(140, 80, 220, 0.65); }
}


#end-screen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #fff;
  text-align: center;
  animation: fadeIn 1s ease forwards;
  padding: calc(var(--safe-t) + 1.2rem) calc(var(--safe-r) + 1.2rem) calc(var(--safe-b) + 1.2rem) calc(var(--safe-l) + 1.2rem);
  box-sizing: border-box;
  overflow-y: auto;
}

.end-buttons {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 0.4rem;
}


@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.back-home {
  display: inline-block;
  margin-top: 1rem;
  color: #fff;
  text-decoration: none;
  font-family: 'Dancing Script', cursive;
  background: linear-gradient(45deg, #ff69b4, #e91e63);
  padding: 0.6rem 1.4rem;
  border-radius: 50px;
  transition: all 0.3s ease;
}

.back-home:hover {
  transform: scale(1.05);
  box-shadow: 0 10px 30px rgba(255, 64, 129, 0.5);
}

/* === SOUND TOGGLE === */
.icon-btn {
  position: fixed;
  top: calc(var(--safe-t) + 18px);
  right: calc(var(--safe-r) + 18px);
  z-index: 1000;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(6px);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}
.icon-btn:hover { background: rgba(0, 0, 0, 0.4); transform: scale(1.08); }

@media (max-width: 480px) {
  .icon-btn { width: 40px; height: 40px; top: calc(var(--safe-t) + 12px); right: calc(var(--safe-r) + 12px); font-size: 1rem; }
}