:root {
  --wine: #4a0e1c;
  --deep-rose: #8c1d40;
  --blush: #d4a0a0;
  --gold: #c9a96e;
  --gold-light: #e8d5a3;
  --cream: #f5efe6;
  --warm-white: #fdf8f0;
  --petal: #e8c4c4;
}

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

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--wine);
  overflow: hidden;
  font-family: 'Cormorant Garamond', serif;
  cursor: default;
}

/* ── Ambient Background ── */
.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(140, 29, 64, 0.6) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 30%, rgba(100, 20, 50, 0.4) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(74, 14, 28, 0.8) 0%, transparent 60%),
    linear-gradient(160deg, #2a0a14 0%, #4a0e1c 40%, #3a0c18 100%);
}

.ambient::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  opacity: 0.5;
  pointer-events: none;
}

/* ── Floating Petals ── */
.petals-container {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

.petal {
  position: absolute;
  width: 12px;
  height: 14px;
  background: radial-gradient(ellipse at 30% 30%, var(--blush), var(--petal));
  border-radius: 50% 0 50% 50%;
  opacity: 0;
  animation: petalFall linear infinite;
  filter: blur(0.5px);
}

@keyframes petalFall {
  0% {
    opacity: 0;
    transform: translateY(-20px) rotate(0deg) scale(0.8);
  }
  10% { opacity: 0.6; }
  90% { opacity: 0.3; }
  100% {
    opacity: 0;
    transform: translateY(100vh) rotate(720deg) scale(0.4);
  }
}

/* ── Envelope ── */
.scene {
  position: relative;
  z-index: 10;
  perspective: 1200px;
}

.envelope-wrapper {
  position: relative;
  width: 380px;
  height: 260px;
  cursor: pointer;
  transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.envelope-wrapper:hover {
  transform: scale(1.02);
}

.envelope-wrapper.opened {
  pointer-events: none;
}

.envelope {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

.envelope-back {
  position: absolute;
  inset: 0;
  background: linear-gradient(145deg, #d4a373, #c8956d);
  border-radius: 4px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.4),
    0 2px 8px rgba(0,0,0,0.2),
    inset 0 1px 0 rgba(255,255,255,0.15);
}

.envelope-back::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 2px;
}

.envelope-back::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.5' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23n)' opacity='0.06'/%3E%3C/svg%3E");
  border-radius: 4px;
}

.envelope-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 55%;
  background: linear-gradient(170deg, #c8956d, #b8845f);
  clip-path: polygon(0 0, 50% 100%, 100% 0);
  transform-origin: top center;
  transition: transform 0.8s cubic-bezier(0.23, 1, 0.32, 1);
  z-index: 3;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.envelope-flap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(170deg, rgba(255,255,255,0.08), transparent 60%);
  clip-path: polygon(0 0, 50% 100%, 100% 0);
}

.envelope-wrapper.opened .envelope-flap {
  transform: rotateX(-180deg);
  z-index: 0;
}

.envelope-front {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 65%;
  background: linear-gradient(to bottom, #d4a878, #c89468);
  border-radius: 0 0 4px 4px;
  z-index: 2;
}

.envelope-front::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  background: linear-gradient(135deg, transparent 0%, transparent 50%, #c89060 50.5%, #d4a070 100%);
  clip-path: polygon(0 0, 100% 100%, 0 100%);
  opacity: 0.3;
}

.envelope-front::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 50%;
  height: 100%;
  background: linear-gradient(-135deg, transparent 0%, transparent 50%, #c89060 50.5%, #d4a070 100%);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  opacity: 0.3;
}

/* Wax Seal */
.seal {
  position: absolute;
  bottom: 52%;
  left: 50%;
  transform: translate(-50%, 50%);
  width: 52px;
  height: 52px;
  background: radial-gradient(circle at 35% 35%, #c0354a, #8c1d40, #6b1530);
  border-radius: 50%;
  z-index: 5;
  box-shadow:
    0 2px 8px rgba(0,0,0,0.3),
    inset 0 -2px 4px rgba(0,0,0,0.2),
    inset 0 2px 4px rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.seal::after {
  content: '\2665';
  font-size: 22px;
  color: rgba(255,255,255,0.25);
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.envelope-wrapper.opened .seal {
  opacity: 0;
  transform: translate(-50%, 50%) scale(0.5);
}

/* Prompt text */
.open-prompt {
  position: absolute;
  bottom: -40px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Caveat', cursive;
  font-size: 18px;
  color: var(--blush);
  opacity: 0.7;
  animation: promptPulse 2s ease-in-out infinite;
  white-space: nowrap;
  transition: opacity 0.4s ease;
}

.envelope-wrapper.opened .open-prompt {
  opacity: 0;
}

@keyframes promptPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

/* ── Letter / Card ── */
.letter {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
}

.letter.visible {
  pointer-events: auto;
  opacity: 1;
}

.letter-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 5, 10, 0);
  transition: background 1s ease;
}

.letter.visible .letter-backdrop {
  background: rgba(20, 5, 10, 0.85);
}

.letter-card {
  position: relative;
  width: min(720px, 90vw);
  max-height: 92vh;
  background: var(--warm-white);
  border-radius: 3px;
  padding: 28px 50px 24px;
  box-shadow:
    0 25px 80px rgba(0,0,0,0.5),
    0 8px 24px rgba(0,0,0,0.3);
  transform: translateY(60px) scale(0.9);
  opacity: 0;
  transition: all 1s cubic-bezier(0.23, 1, 0.32, 1) 0.3s;
  overflow-x: hidden;
  overflow-y: auto;
}

.letter.visible .letter-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.letter-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
}

.letter-card::after {
  content: '';
  position: absolute;
  inset: 16px;
  border: 1px solid var(--gold-light);
  border-radius: 1px;
  opacity: 0.4;
  pointer-events: none;
}

/* Decorative corner flourishes */
.flourish {
  position: absolute;
  width: 60px;
  height: 60px;
  opacity: 0.2;
  pointer-events: none;
}

.flourish svg { width: 100%; height: 100%; }

.flourish.tl { top: 22px; left: 22px; }
.flourish.tr { top: 22px; right: 22px; transform: scaleX(-1); }
.flourish.bl { bottom: 22px; left: 22px; transform: scaleY(-1); }
.flourish.br { bottom: 22px; right: 22px; transform: scale(-1); }

/* Content */
.letter-date {
  font-family: 'Cormorant Garamond', serif;
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--gold);
  text-align: center;
  margin-bottom: 10px;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.8s ease 0.8s;
}

.letter.visible .letter-date {
  opacity: 0.7;
  transform: translateY(0);
}

.letter-greeting {
  font-family: 'Petit Formal Script', cursive;
  font-size: 28px;
  color: var(--deep-rose);
  text-align: center;
  margin-bottom: 14px;
  opacity: 0;
  transform: translateY(15px);
  transition: all 0.8s ease 1s;
}

.letter.visible .letter-greeting {
  opacity: 1;
  transform: translateY(0);
}

.letter-divider {
  width: 80px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  margin: 0 auto 14px;
  opacity: 0;
  transition: all 0.8s ease 1.2s;
}

.letter.visible .letter-divider {
  opacity: 0.6;
  width: 120px;
}

.letter-body {
  font-family: 'Caveat', cursive;
  font-size: 22px;
  line-height: 1.6;
  color: #3a2028;
  text-align: center;
  max-width: 480px;
  margin: 0 auto 12px;
}

.letter-body .line {
  display: block;
  opacity: 0;
  transform: translateY(12px);
  transition: all 0.6s ease;
}

.letter.visible .letter-body .line:nth-child(1) { opacity: 1; transform: translateY(0); transition-delay: 1.4s; }
.letter.visible .letter-body .line:nth-child(2) { opacity: 1; transform: translateY(0); transition-delay: 1.7s; }
.letter.visible .letter-body .line:nth-child(3) { opacity: 1; transform: translateY(0); transition-delay: 2.0s; }
.letter.visible .letter-body .line:nth-child(4) { opacity: 1; transform: translateY(0); transition-delay: 2.3s; }
.letter.visible .letter-body .line:nth-child(5) { opacity: 1; transform: translateY(0); transition-delay: 2.6s; }
.letter.visible .letter-body .line:nth-child(6) { opacity: 1; transform: translateY(0); transition-delay: 2.9s; }
.letter.visible .letter-body .line:nth-child(7) { opacity: 1; transform: translateY(0); transition-delay: 3.2s; }

/* ── Family Photo ── */
.letter-photo {
  text-align: center;
  margin: 4px auto 10px;
  opacity: 0;
  transform: translateY(15px) rotate(-1.5deg);
  transition: all 1s cubic-bezier(0.23, 1, 0.32, 1) 2.8s;
}

.letter.visible .letter-photo {
  opacity: 1;
  transform: translateY(0) rotate(-1.5deg);
}

.photo-frame {
  display: inline-block;
  padding: 8px 8px 28px 8px;
  background: white;
  box-shadow:
    0 4px 16px rgba(0,0,0,0.1),
    0 1px 4px rgba(0,0,0,0.08);
  transform: rotate(1.5deg);
  transition: transform 0.4s ease;
}

.photo-frame:hover {
  transform: rotate(0deg) scale(1.02);
}

.photo-frame img {
  display: block;
  width: 280px;
  height: 190px;
  object-fit: cover;
  object-position: center 20%;
  filter: saturate(1.05) contrast(1.02);
}

.photo-caption {
  font-family: 'Caveat', cursive;
  font-size: 15px;
  color: var(--deep-rose);
  margin-top: 8px;
  opacity: 0.7;
}

.letter-heart {
  text-align: center;
  margin: 10px 0;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) 3.4s;
}

.letter.visible .letter-heart {
  opacity: 1;
  transform: scale(1);
}

.heart-icon {
  display: inline-block;
  color: var(--deep-rose);
  font-size: 32px;
  animation: heartbeat 1.2s ease-in-out infinite;
  animation-delay: 3.5s;
  opacity: 0.8;
}

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

.letter-sign {
  font-family: 'Petit Formal Script', cursive;
  font-size: 20px;
  color: var(--deep-rose);
  text-align: center;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.8s ease 3.6s;
}

.letter.visible .letter-sign {
  opacity: 0.9;
  transform: translateY(0);
}

/* ── Sparkle Particles on Card ── */
.sparkles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.sparkle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--gold-light);
  border-radius: 50%;
  opacity: 0;
  animation: sparkleAnim 3s ease-in-out infinite;
}

@keyframes sparkleAnim {
  0%, 100% { opacity: 0; transform: scale(0); }
  50% { opacity: 0.8; transform: scale(1); }
}

/* ── Responsive ── */
@media (max-width: 540px) {
  .envelope-wrapper {
    width: 300px;
    height: 210px;
  }
  .letter-card {
    padding: 45px 32px;
    min-height: 500px;
  }
  .letter-greeting { font-size: 24px; }
  .letter-body { font-size: 19px; }
  .flourish { width: 40px; height: 40px; }
}
