/* ==========================================================================
   Pastel Birthday Surprise — Stylesheet
   Tweak the :root CSS variables below to customize the palette & typography.
   ========================================================================== */

:root {
  /* Palette: Cute & Pastel */
  --bg-cream: #fff7fa;
  --bg-blush: #ffe3ee;
  --bg-lavender: #ede2ff;
  --bg-peach: #ffe8d6;
  --bg-mint: #e4f7f1;

  --surface-card: rgba(255, 255, 255, 0.84);
  --surface-card-strong: rgba(255, 255, 255, 0.94);
  --surface-border: rgba(255, 175, 204, 0.45);

  --ink-primary: #4a2c3a;
  --ink-secondary: #7e586a;
  --ink-muted: #a68494;

  --accent-pink: #ff8fab;
  --accent-pink-deep: #fb6f92;
  --accent-rose: #ffc2d4;
  --accent-gold: #ffd166;
  --accent-lavender: #cdb4db;

  --shadow-soft: 0 18px 45px rgba(214, 128, 160, 0.18);
  --shadow-btn: 0 10px 24px rgba(251, 111, 146, 0.28);
  --glow-pink: 0 0 28px rgba(255, 143, 171, 0.4);

  /* Typography */
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Nunito', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Motion */
  --ease-out-soft: cubic-bezier(0.22, 1, 0.36, 1);
  --transition-screen: 0.65s;
}

/* Reset & Base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: var(--font-body);
  color: var(--ink-primary);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: relative;
  background: linear-gradient(
    135deg,
    var(--bg-cream) 0%,
    var(--bg-blush) 28%,
    var(--bg-lavender) 58%,
    var(--bg-peach) 85%,
    var(--bg-mint) 100%
  );
  background-size: 260% 260%;
  animation: driftGradient 18s ease-in-out infinite;
}

@keyframes driftGradient {
  0% {
    background-position: 0% 30%;
  }
  50% {
    background-position: 100% 70%;
  }
  100% {
    background-position: 0% 30%;
  }
}

/* Background & Confetti Canvases */
#bg-canvas,
#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#bg-canvas {
  z-index: 0;
}

#confetti-canvas {
  z-index: 40;
}

/* Music Toggle Button */
.music-toggle {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  border: 1px solid var(--surface-border);
  border-radius: 999px;
  background: var(--surface-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--ink-secondary);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(180, 110, 140, 0.12);
  transition: transform 0.2s var(--ease-out-soft), background-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

.music-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(180, 110, 140, 0.2);
}

.music-toggle:active {
  transform: scale(0.95);
}

.music-toggle[aria-pressed='true'] {
  background: linear-gradient(135deg, var(--accent-pink), var(--accent-pink-deep));
  color: #fff;
  border-color: transparent;
  box-shadow: var(--glow-pink);
}

.music-toggle[aria-pressed='true'] .music-icon {
  animation: musicBounce 1.4s ease-in-out infinite;
}

@keyframes musicBounce {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-2px) rotate(-8deg);
  }
}

/* App Shell & Screen Transitions */
.app {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100dvh;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
    max(22px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(18px) scale(0.985);
  transition:
    opacity 0.22s ease-out,
    transform 0.22s ease-out,
    visibility 0s linear 0.22s;
}

.screen.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition:
    opacity 0.45s var(--ease-out-soft) 0.18s,
    transform 0.45s var(--ease-out-soft) 0.18s,
    visibility 0s linear 0.18s;
}

.screen.is-leaving {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-14px) scale(0.985);
  transition:
    opacity 0.22s ease-out,
    transform 0.22s ease-out,
    visibility 0s linear 0.22s;
}

.screen-inner {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Shared Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  font-family: var(--font-body);
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  user-select: none;
  transition:
    transform 0.22s var(--ease-out-soft),
    box-shadow 0.25s var(--ease-out-soft),
    background-color 0.25s ease,
    opacity 0.35s ease;
}

.btn:focus-visible,
.music-toggle:focus-visible {
  outline: 3px solid rgba(251, 111, 146, 0.45);
  outline-offset: 3px;
}

.btn-primary {
  padding: 14px 32px;
  font-size: 1rem;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-pink), var(--accent-pink-deep));
  box-shadow: var(--shadow-btn);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(251, 111, 146, 0.36), var(--glow-pink);
}

.btn-primary:active {
  transform: translateY(1px) scale(0.97);
}

.btn-soft {
  padding: 12px 24px;
  font-size: 0.96rem;
  color: var(--ink-primary);
  background: var(--surface-card-strong);
  border: 1.5px solid var(--surface-border);
  box-shadow: 0 10px 26px rgba(214, 128, 160, 0.18);
}

.btn-soft:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(214, 128, 160, 0.26), var(--glow-pink);
}

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

/* ==========================================================================
   Screen 1: Cover
   ========================================================================== */

.cover-card {
  width: 100%;
  max-width: 400px;
  padding: 44px 28px 38px;
  border-radius: 32px;
  background: var(--surface-card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  box-shadow: var(--shadow-soft);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.cover-emblem {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: linear-gradient(145deg, #fff0f5, #ffe2ed);
  display: grid;
  place-items: center;
  box-shadow: 0 10px 24px rgba(255, 143, 171, 0.22);
  animation: gentleFloat 3.6s ease-in-out infinite;
}

@keyframes gentleFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.cover-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.9rem, 6vw, 2.55rem);
  line-height: 1.2;
  color: var(--ink-primary);
}

.cover-hint-btn {
  margin-top: 4px;
  animation: softPulse 2.6s ease-in-out infinite;
}

.sparkle-dot {
  color: var(--accent-pink-deep);
}

@keyframes softPulse {
  0%,
  100% {
    box-shadow: 0 10px 26px rgba(214, 128, 160, 0.18);
  }
  50% {
    box-shadow: 0 12px 30px rgba(255, 143, 171, 0.36);
  }
}

/* ==========================================================================
   Screen 2: Scratch Card
   ========================================================================== */

.scratch-layout {
  gap: 18px;
}

.eyebrow {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-secondary);
}

.scratch-card-wrap {
  position: relative;
  width: min(100%, 400px);
  height: clamp(250px, 44dvh, 330px);
  border-radius: 28px;
  overflow: hidden;
  background: var(--surface-card-strong);
  border: 2px solid rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
  touch-action: none;
  user-select: none;
}

.scratch-card-under {
  position: absolute;
  inset: 0;
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    radial-gradient(circle at top left, rgba(255, 224, 236, 0.55), transparent 55%),
    radial-gradient(circle at bottom right, rgba(237, 226, 255, 0.55), transparent 55%),
    #fffafc;
  overflow-y: auto;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.scratch-card-under.is-ready {
  opacity: 1;
}

.card-corner-hearts {
  margin-bottom: 12px;
  font-size: 0.95rem;
  letter-spacing: 0.35em;
  color: var(--accent-pink);
}

.birthday-message {
  margin: 0;
  white-space: pre-line;
  font-family: var(--font-display);
  font-size: clamp(1.06rem, 3.6vw, 1.24rem);
  line-height: 1.6;
  color: var(--ink-primary);
  max-width: 34ch;
}

.scratch-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
  opacity: 1;
  transition: none;
}

.scratch-canvas:active {
  cursor: grabbing;
}

.scratch-canvas.is-cleared {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.65s var(--ease-out-soft);
}

.scratch-footer {
  min-height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.subtle-hint {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink-secondary);
  transition: opacity 0.35s ease;
}

.subtle-hint.is-hidden {
  display: none;
}

#scratch-next-btn.is-hidden {
  display: none;
}

#scratch-next-btn.is-visible {
  display: inline-flex;
  animation: popUp 0.45s var(--ease-out-soft) both;
}

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

/* ==========================================================================
   Screen 3: Mini-game "Catch the hearts"
   ========================================================================== */

.game-layout {
  height: 100%;
  max-height: 760px;
  gap: 12px;
  padding-top: 28px;
}

.game-header {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.game-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 4.8vw, 1.75rem);
  font-weight: 700;
  color: var(--ink-primary);
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface-card-strong);
  border: 1.5px solid var(--surface-border);
  box-shadow: 0 6px 16px rgba(214, 128, 160, 0.14);
  font-weight: 800;
  font-size: 1rem;
  color: var(--ink-primary);
}

.score-heart {
  color: var(--accent-pink-deep);
}

.score-sep {
  color: var(--ink-muted);
  font-weight: 700;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  overflow: hidden;
  border: 1px solid rgba(255, 194, 212, 0.45);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-pink), var(--accent-gold));
  transition: width 0.25s var(--ease-out-soft);
}

.game-howto {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-secondary);
}

.game-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  border-radius: 28px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.56);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow-soft);
  touch-action: none;
  user-select: none;
}

.game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

.game-canvas:active {
  cursor: grabbing;
}

/* ==========================================================================
   Screen 4: Finale
   ========================================================================== */

.finale-card {
  width: 100%;
  max-width: 440px;
  padding: 46px 28px 40px;
  border-radius: 34px;
  background: var(--surface-card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-soft);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.finale-badge {
  font-size: 2.5rem;
  line-height: 1;
  filter: drop-shadow(0 8px 16px rgba(255, 143, 171, 0.35));
}

.finale-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2rem, 6.8vw, 2.85rem);
  line-height: 1.15;
  color: var(--ink-primary);
}

.finale-closing {
  margin: 0 0 8px;
  font-size: clamp(1rem, 3.6vw, 1.15rem);
  font-weight: 600;
  line-height: 1.55;
  color: var(--ink-secondary);
  max-width: 30ch;
}

/* Entrance animation triggered when Screen 4 becomes active */
.screen.is-active .finale-badge {
  animation: finaleEntrance 0.7s var(--ease-out-soft) 0.05s both;
}

.screen.is-active .finale-title {
  animation: finaleEntrance 0.8s var(--ease-out-soft) 0.16s both;
}

.screen.is-active .finale-closing {
  animation: finaleEntrance 0.8s var(--ease-out-soft) 0.3s both;
}

.screen.is-active #replay-btn {
  animation: finaleEntrance 0.8s var(--ease-out-soft) 0.44s both;
}

@keyframes finaleEntrance {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ==========================================================================
   Accessibility: Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  body {
    animation: none;
  }

  .cover-emblem,
  .cover-hint-btn,
  .music-toggle[aria-pressed='true'] .music-icon {
    animation: none;
  }

  .screen,
  .screen.is-active,
  .screen.is-leaving,
  .scratch-canvas,
  .btn,
  .progress-fill {
    transition-duration: 0.01ms !important;
  }

  .screen.is-active .finale-badge,
  .screen.is-active .finale-title,
  .screen.is-active .finale-closing,
  .screen.is-active #replay-btn,
  #scratch-next-btn.is-visible {
    animation: none !important;
  }
}

/* Desktop polish */
@media (min-width: 640px) {
  .cover-card {
    padding: 52px 40px 44px;
  }

  .finale-card {
    padding: 54px 40px 46px;
  }
}
