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

:root {
  --pink: #f7a8b8;
  --rose: #e75480;
  --deep-rose: #c44569;
  --blush: #fce4ec;
  --white: #fff;
}

html, body {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  font-family: 'Georgia', 'Times New Roman', serif;
}

body {
  background: var(--blush);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== SCENE ===== */
#scene {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ===== ENVELOPE ===== */
#envelope {
  position: relative;
  width: 280px;
  height: 180px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  z-index: 10;
}

.envelope-body {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--rose), var(--deep-rose));
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

.envelope-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 55%;
  background: linear-gradient(180deg, #d63b6f, var(--rose));
  clip-path: polygon(0 0, 50% 100%, 100% 0);
  transform-origin: top center;
  transition: transform 0.6s ease-in-out;
  z-index: 2;
}

#envelope.open .envelope-flap {
  transform: rotateX(180deg);
}

.tap-text {
  position: absolute;
  bottom: 30%;
  left: 50%;
  transform: translateX(-50%);
  color: var(--white);
  font-size: 1.2rem;
  font-style: italic;
  z-index: 1;
  animation: pulse 1.5s ease-in-out infinite;
  pointer-events: none;
}

#envelope.open .tap-text {
  opacity: 0;
  transition: opacity 0.3s;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; transform: translateX(-50%) scale(1); }
  50% { opacity: 1; transform: translateX(-50%) scale(1.1); }
}

/* ===== PHOTO TILES ===== */
.photo-tile {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 90px;
  height: 90px;
  transform: translate(-50%, -50%) rotate(0deg) scale(0);
  opacity: 0;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.5s ease;
  z-index: 5;
}

.photo-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.photo-tile.scattered {
  opacity: 1;
  transform: translate(
    calc(-50% + var(--tx)),
    calc(-50% + var(--ty))
  ) rotate(var(--rotate)) scale(1);
}

.photo-tile.fade-out {
  opacity: 0 !important;
  transition: opacity 0.8s ease;
}

/* ===== LETTER ===== */
#letter {
  position: absolute;
  bottom: -300px;
  left: 50%;
  transform: translateX(-50%);
  width: 260px;
  background: var(--white);
  border-radius: 10px;
  padding: 30px 20px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  transition: bottom 0.8s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.6s ease;
  z-index: 20;
}

#letter.visible {
  bottom: calc(50% - 100px);
}

#letter.fade-out {
  opacity: 0;
  transition: opacity 0.6s ease;
}

.letter-text {
  font-size: 1.1rem;
  color: var(--deep-rose);
  line-height: 1.5;
  margin-bottom: 24px;
}

.letter-buttons {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: center;
}

.letter-buttons button {
  border: none;
  border-radius: 25px;
  padding: 10px 28px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.3s ease, font-size 0.3s ease, padding 0.3s ease;
}

#btn-yes {
  background: var(--rose);
  color: var(--white);
}

#btn-yes:hover {
  background: var(--deep-rose);
}

#btn-no {
  background: #ccc;
  color: #333;
}

#btn-no:hover {
  background: #bbb;
}

/* ===== NO OVERLAY ===== */
#no-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

#no-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

#no-overlay img {
  max-width: 70%;
  max-height: 60%;
  border-radius: 12px;
}

.sad-fallback {
  color: var(--white);
  font-size: 2rem;
  text-align: center;
  padding: 20px;
}

/* ===== YES OVERLAY ===== */
#yes-overlay {
  position: fixed;
  inset: 0;
  background: var(--blush);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 40px 16px;
}

#yes-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.love-heading {
  text-align: center;
  color: var(--deep-rose);
  font-size: 2rem;
  margin-bottom: 30px;
  animation: heartbeat 1.2s ease-in-out infinite;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  15% { transform: scale(1.15); }
  30% { transform: scale(1); }
  45% { transform: scale(1.1); }
  60% { transform: scale(1); }
}

/* ===== GALLERY ===== */
#gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 700px;
  margin: 0 auto;
  padding-bottom: 40px;
}

#gallery img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 400px) {
  #envelope {
    width: 240px;
    height: 155px;
  }

  .photo-tile {
    width: 70px;
    height: 70px;
  }

  #letter {
    width: 230px;
    padding: 24px 16px;
  }

  .letter-text {
    font-size: 1rem;
  }

  #gallery {
    grid-template-columns: repeat(2, 1fr);
  }

  .love-heading {
    font-size: 1.6rem;
  }
}

@media (min-width: 401px) and (max-width: 768px) {
  #envelope {
    width: 280px;
    height: 180px;
  }

  .photo-tile {
    width: 90px;
    height: 90px;
  }

  #gallery {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 769px) {
  #envelope {
    width: 320px;
    height: 200px;
  }

  .photo-tile {
    width: 110px;
    height: 110px;
  }

  #gallery {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    max-width: 900px;
  }

  .love-heading {
    font-size: 2.5rem;
  }
}
