*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none
}

:root {
  --pink: #F8C8DC;
  --pink-dark: #f0a8c4;
  --lilac: #D8BFD8;
  --cream: #FFF5E1;
  --mint: #A8E6CF;
  --yellow: #FFD700;
  --soft-white: #FFF9F5;
  --text: #4A3F5C;
  --shadow: 0 8px 32px rgba(74, 63, 92, 0.12);
  --radius: 20px;
  --font-head: 'Fredoka One', cursive;
  --font-body: 'Quicksand', sans-serif;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--cream)
}

body {
  position: relative
}

/* ============= LOADING SCREEN ============= */
#loadingScreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: linear-gradient(135deg, var(--cream), #FFE8F0);
  transition: opacity 0.8s ease;
}

#loadingScreen.done {
  opacity: 0;
  pointer-events: none
}

.loader {
  font-size: 3.5rem;
  animation: loaderBounce 0.8s ease infinite
}

@keyframes loaderBounce {

  0%,
  100% {
    transform: translateY(0) scale(1)
  }

  50% {
    transform: translateY(-16px) scale(1.15)
  }
}

.loader-text {
  font-family: var(--font-body);
  font-weight: 600;
  color: #7A6B8A;
  font-size: 1rem;
  transition: opacity 0.4s;
  min-height: 1.5em
}

.loader-bar-wrap {
  position: relative;
  width: 220px;
  height: 8px;
  border-radius: 10px;
  background: rgba(216, 191, 216, 0.25);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.06)
}

.loader-fill {
  height: 100%;
  width: 0%;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--pink), var(--lilac), var(--mint));
  transition: width 0.5s ease;
  position: relative
}

.loader-fill::after {
  content: '✨';
  position: absolute;
  right: -4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  animation: sparklePop 0.6s ease infinite
}

@keyframes sparklePop {

  0%,
  100% {
    opacity: 1;
    transform: translateY(-50%) scale(1)
  }

  50% {
    opacity: 0.6;
    transform: translateY(-50%) scale(1.3)
  }
}

/* ============= SCREENS ============= */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: max(48px, 8vh);
  padding-bottom: 48px;
  padding-left: 24px;
  padding-right: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.7s ease, transform 0.7s ease;
  transform: scale(0.97);
  overflow-y: auto;
  background: linear-gradient(135deg, var(--cream), #FFE8F0, var(--soft-white), #E8F8F0);
  background-size: 400% 400%;
  animation: bgShift 12s ease infinite;
  will-change: opacity, transform;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1)
}

@keyframes bgShift {
  0% {
    background-position: 0% 50%
  }

  50% {
    background-position: 100% 50%
  }

  100% {
    background-position: 0% 50%
  }
}

.screen-content {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 16px 0
}

h1,
h2,
h3 {
  font-family: var(--font-head);
  font-weight: 400;
  letter-spacing: 0.5px
}

h1 {
  font-size: clamp(1.8rem, 6vw, 2.8rem)
}

h2 {
  font-size: clamp(1.4rem, 5vw, 2rem)
}

p,
label {
  font-family: var(--font-body);
  font-weight: 500;
  line-height: 1.7;
  font-size: clamp(0.95rem, 3vw, 1.05rem)
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 36px;
  border: none;
  border-radius: 50px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, var(--pink), var(--pink-dark));
  color: #fff;
  box-shadow: 0 4px 20px rgba(248, 200, 220, 0.5);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(248, 200, 220, 0.6)
}

.btn:active {
  transform: scale(0.96)
}

.btn-secondary {
  background: linear-gradient(135deg, var(--lilac), #C8A8D8);
  box-shadow: 0 4px 20px rgba(216, 191, 216, 0.5)
}

.btn-gold {
  background: linear-gradient(135deg, #FFD700, #FFB800);
  color: #4A3F5C;
  box-shadow: 0 4px 20px rgba(255, 215, 0, 0.4)
}

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

.input-group input {
  width: 100%;
  padding: 14px 20px;
  border: 2px solid rgba(216, 191, 216, 0.4);
  border-radius: 16px;
  font-family: var(--font-body);
  font-size: 1rem;
  background: var(--soft-white);
  color: var(--text);
  outline: none;
  transition: border-color 0.3s;
  text-align: center;
}

.input-group input:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 4px rgba(248, 200, 220, 0.2)
}

.error-shake {
  animation: shake 0.4s ease
}

@keyframes shake {

  0%,
  100% {
    transform: translateX(0)
  }

  20% {
    transform: translateX(-8px)
  }

  40% {
    transform: translateX(8px)
  }

  60% {
    transform: translateX(-6px)
  }

  80% {
    transform: translateX(6px)
  }
}

.card {
  background: rgba(255, 249, 245, 0.85);
  backdrop-filter: blur(12px);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.particle-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  contain: layout style
}

.particle-bg span {
  position: absolute;
  display: block;
  font-size: 20px;
  animation: floatUp linear infinite;
  opacity: 0.4;
  will-change: transform;
}

@keyframes floatUp {
  0% {
    transform: translateY(100vh) rotate(0deg);
    opacity: 0
  }

  10% {
    opacity: 0.4
  }

  90% {
    opacity: 0.4
  }

  100% {
    transform: translateY(-10vh) rotate(360deg);
    opacity: 0
  }
}

#musicToggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 249, 245, 0.85);
  backdrop-filter: blur(8px);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  will-change: transform;
}

#musicToggle.show {
  opacity: 1;
  pointer-events: auto
}

#musicToggle:hover {
  transform: scale(1.1)
}

#screen-lock .lock-icon {
  font-size: 4rem;
  margin-bottom: 8px;
  animation: bounce 2s infinite;
  will-change: transform
}

@keyframes bounce {

  0%,
  100% {
    transform: translateY(0)
  }

  50% {
    transform: translateY(-12px)
  }
}

#screen-lock .hint-text {
  font-size: 0.85rem;
  color: #B8A9C9;
  margin-top: 4px
}

.cake-container {
  position: relative;
  width: 200px;
  height: 240px;
  margin: 8px 0 16px
}

.cake-plate {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 180px;
  height: 14px;
  background: linear-gradient(135deg, #E8D5C4, #D4C0B0);
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1)
}

.cake-layer-1 {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: 160px;
  height: 60px;
  background: linear-gradient(135deg, #FFB5C2, #FF9EB0);
  border-radius: 8px 8px 0 0
}

.cake-layer-2 {
  position: absolute;
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%);
  width: 130px;
  height: 50px;
  background: linear-gradient(135deg, #FFC8D6, #FFB0C4);
  border-radius: 8px 8px 0 0
}

.cake-layer-3 {
  position: absolute;
  bottom: 124px;
  left: 50%;
  transform: translateX(-50%);
  width: 100px;
  height: 40px;
  background: linear-gradient(135deg, #FFD6E0, #FFC0D0);
  border-radius: 8px 8px 0 0
}

.cake-frosting {
  position: absolute;
  bottom: 124px;
  left: 50%;
  transform: translateX(-50%);
  width: 110px;
  height: 12px;
  background: linear-gradient(135deg, #FFF5E1, #FFE8C0);
  border-radius: 6px
}

.cake-cherry {
  position: absolute;
  bottom: 158px;
  left: 50%;
  transform: translateX(-50%);
  width: 18px;
  height: 18px;
  background: radial-gradient(circle at 35% 35%, #FF6B8A, #E8456B);
  border-radius: 50%;
  z-index: 2
}

.cake-cherry::after {
  content: '';
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 8px;
  background: #8B7355
}

.candle {
  position: absolute;
  bottom: 164px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 32px;
  background: linear-gradient(180deg, #FFB0C4, #FF8FA3);
  border-radius: 4px;
  z-index: 3
}

.flame {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 20px;
  background: radial-gradient(ellipse at center, #FFF5A0, #FFD700, #FF8C00);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  animation: flicker 0.5s ease-in-out infinite alternate;
  z-index: 4;
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.4), 0 0 24px rgba(255, 200, 0, 0.2);
  cursor: pointer;
  transition: all 0.3s;
  will-change: transform, opacity;
}

.flame:hover {
  transform: translateX(-50%) scale(1.2)
}

.flame.blown {
  transform: translateX(-50%) scale(0);
  opacity: 0;
  box-shadow: none
}

.candle-smoke {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  transition: all 0.8s
}

.candle-smoke.show {
  opacity: 0.6;
  transform: translateX(-50%) translateY(-20px)
}

.candle-smoke span {
  display: block;
  font-size: 1.5rem;
  animation: smokeRise 1s ease-out forwards;
  opacity: 0
}

@keyframes smokeRise {
  0% {
    opacity: 0.6;
    transform: translateY(0) scale(1)
  }

  100% {
    opacity: 0;
    transform: translateY(-30px) scale(1.5)
  }
}

.blow-hint {
  font-size: 0.85rem;
  color: #B8A9C9;
  margin-top: 4px;
  transition: opacity 0.5s
}

@keyframes flicker {
  0% {
    transform: translateX(-50%) scale(1) rotate(-2deg)
  }

  100% {
    transform: translateX(-50%) scale(1.1) rotate(2deg)
  }
}

.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
  contain: layout style
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -10px;
  animation: confettiFall linear forwards;
  will-change: transform;
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1
  }

  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0
  }
}

.gallery-stack {
  position: relative;
  width: 280px;
  height: 360px;
  margin: 8px 0
}

.gallery-card {
  position: absolute;
  inset: 0;
  background: var(--soft-white);
  border-radius: 12px;
  padding: 12px 12px 40px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  transition: transform 0.4s ease, opacity 0.4s ease;
  cursor: grab;
  user-select: none;
  touch-action: none;
  border: 1px solid rgba(255, 255, 255, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  will-change: transform, opacity;
}

.gallery-card .photo-placeholder {
  width: 100%;
  height: 220px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.5rem;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #FFE0EC, #FFC8D8);
}

.gallery-card .photo-placeholder img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
}

.gallery-card .photo-placeholder .fallback-emoji {
  z-index: 1
}

.gallery-card .caption {
  font-size: 0.85rem;
  color: #7A6B8A;
  padding: 4px 8px;
  text-align: center;
  line-height: 1.6;
  flex: 1;
  display: flex;
  align-items: center;
}

.gallery-card .card-number {
  position: absolute;
  bottom: 12px;
  right: 16px;
  font-size: 0.75rem;
  color: #C8B8D8;
  font-weight: 600;
}

.gallery-indicator {
  font-size: 0.85rem;
  color: #B8A9C9;
  margin-top: 8px
}

.gallery-card.dragging {
  cursor: grabbing;
  transition: none !important
}

.gallery-card.removed {
  transform: translateX(120%) rotate(12deg);
  opacity: 0;
  pointer-events: none
}

.scratch-container {
  position: relative;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1;
  margin: 8px 0;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow)
}

.scratch-reveal {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: linear-gradient(135deg, #FFF5E1, #FFE8F0);
  color: var(--text);
}

.scratch-reveal h3 {
  font-size: 1.3rem;
  margin-bottom: 8px;
  color: #E8456B
}

.scratch-reveal p {
  font-size: 0.95rem
}

.scratch-canvas {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  touch-action: none
}

.scratch-percent {
  font-size: 0.8rem;
  color: #B8A9C9;
  margin-top: 8px
}

.letter-card {
  background: rgba(255, 249, 245, 0.9);
  backdrop-filter: blur(12px);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 420px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.letter-text {
  font-size: clamp(0.95rem, 3vw, 1.05rem);
  line-height: 2;
  white-space: pre-wrap;
  text-align: center;
}

.letter-text .cursor {
  display: inline-block;
  width: 2px;
  height: 1.2em;
  background: var(--pink);
  animation: blink 0.8s infinite;
  vertical-align: text-bottom;
  margin-left: 2px
}

@keyframes blink {

  0%,
  100% {
    opacity: 1
  }

  50% {
    opacity: 0
  }
}

@keyframes fadeOut {
  0% {
    opacity: 1
  }

  100% {
    opacity: 0
  }
}

.letter-done {
  opacity: 0;
  transition: opacity 0.6s;
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px
}

.letter-done.show {
  opacity: 1
}

.heart-rain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden
}

.heart-rain span {
  position: absolute;
  top: -40px;
  font-size: 1.5rem;
  animation: heartFall linear forwards;
  will-change: transform;
}

@keyframes heartFall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1
  }

  100% {
    transform: translateY(105vh) rotate(360deg);
    opacity: 0
  }
}

.progress-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(216, 191, 216, 0.3);
  z-index: 100;
  border-radius: 2px;
  overflow: hidden
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--pink), var(--lilac), var(--mint));
  transition: width 0.8s ease;
  border-radius: 2px
}

.step-indicator {
  display: flex;
  gap: 8px;
  margin-bottom: 16px
}

.step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #E0D6EC;
  transition: all 0.4s
}

.step-dot.active {
  background: var(--pink);
  transform: scale(1.3);
  box-shadow: 0 0 8px rgba(248, 200, 220, 0.5)
}

.step-dot.done {
  background: var(--mint);
  transform: scale(1)
}

@media(max-width:480px) {
  .screen {
    padding-top: max(32px, 6vh);
    padding-bottom: 32px;
    padding-left: 16px;
    padding-right: 16px
  }

  .screen-content {
    max-width: 100%
  }

  .card {
    padding: 20px 16px
  }

  .gallery-stack {
    width: 240px;
    height: 310px
  }

  .gallery-card .photo-placeholder {
    height: 180px;
    font-size: 2.8rem
  }

  .cake-container {
    transform: scale(0.85)
  }

  #musicToggle {
    top: 12px;
    right: 12px;
    width: 38px;
    height: 38px;
    font-size: 1rem
  }

  .letter-card {
    padding: 20px 16px
  }
}

.hidden {
  display: none !important
}