/* --- Premium Envelope Entry (Slide Out Scene) --- */
#envelope-scene {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate3d(-50%, -50%, 0);
  width: 100%;
  max-width: 460px;
  height: 280px;
  z-index: 900;
  perspective: 1200px;
  transition: opacity 0.8s ease;
  animation: levitate 3.5s ease-in-out infinite;
  will-change: transform;
}

@keyframes levitate {
  0%, 100% { transform: translate3d(-50%, -50%, 0); }
  50% { transform: translate3d(-50%, calc(-50% - 12px), 0); }
}

/* Optimize shadows on mobile to reduce repaint cost */
@media (max-width: 768px) {
  .env-back {
    box-shadow: 0 10px 30px rgba(0,0,0,0.1) !important;
  }
  .wax-seal {
    box-shadow: 0 4px 8px rgba(198, 40, 40, 0.4) !important;
  }
}

.env-pocket {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  clip-path: inset(-150vh -100vw 0 -100vw);
  z-index: 2;
}

.env-back {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #fce4ec, #f8bbd0);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.15);
  transition: transform 0.8s ease, opacity 0.8s ease;
  will-change: transform, opacity;
}

.env-front {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to right, #f48fb1, #f8bbd0);
  clip-path: polygon(0 0, 50% 35%, 100% 0, 100% 100%, 0 100%);
  border-radius: 12px;
  z-index: 3;
  transition: transform 0.8s ease, opacity 0.8s ease;
  will-change: transform, opacity;
}

.env-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 65%;
  background: linear-gradient(135deg, #f8bbd0, #f48fb1);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top;
  z-index: 4;
  transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.8s ease;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  will-change: transform, opacity;
}

.wax-seal {
  position: absolute;
  top: 65%;
  left: 50%;
  transform: translate3d(-50%, -50%, 0);
  width: 60px;
  height: 60px;
  background: radial-gradient(circle at 30% 30%, #ff5252, #c62828);
  border-radius: 50%;
  z-index: 5;
  box-shadow: 0 4px 10px rgba(198, 40, 40, 0.5), inset 0 2px 4px rgba(255,255,255,0.4);
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.5s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  animation: sealPulse 2s infinite ease-in-out;
  overflow: hidden;
  will-change: transform, box-shadow;
}

@keyframes sealPulse {
  0%, 100% { box-shadow: 0 4px 10px rgba(198, 40, 40, 0.5), 0 0 0 0px rgba(192, 57, 43, 0); }
  50% { box-shadow: 0 4px 15px rgba(198, 40, 40, 0.6), 0 0 15px 5px rgba(192, 57, 43, 0.4); }
}

.wax-seal::after {
  content: '';
  position: absolute;
  top: -100%;
  left: -100%;
  width: 300%;
  height: 300%;
  background: linear-gradient(135deg, transparent 45%, rgba(255, 255, 255, 0.3) 50%, transparent 55%);
  transform: rotate(15deg);
  animation: sealShine 3s infinite;
  pointer-events: none;
}

@keyframes sealShine {
  0%, 80% { transform: translate3d(-100%, -100%, 0) rotate(15deg); }
  86%, 100% { transform: translate3d(100%, 100%, 0) rotate(15deg); }
}

.whisper-prompt {
  position: absolute;
  bottom: -60px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 300;
  color: #8A5060;
  opacity: 0;
  animation: whisperFadeIn 1.5s ease forwards;
  animation-delay: 3s;
  pointer-events: none;
  letter-spacing: 0.5px;
}

@keyframes whisperFadeIn {
  from { opacity: 0; transform: translate3d(0, 5px, 0); }
  to { opacity: 0.7; transform: translate3d(0, 0, 0); }
}

.wax-seal svg {
  width: 40px;
  height: 40px;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.3));
}

.wax-seal:hover {
  transform: translate3d(-50%, -50%, 0) scale(1.1);
  box-shadow: 0 6px 15px rgba(198, 40, 40, 0.6), inset 0 2px 5px rgba(255,255,255,0.5);
}

/* Animations Triggered via JS Classes */
#envelope-scene.is-open .env-flap {
  transform: rotateX(180deg);
}

#envelope-scene.is-open .wax-seal {
  opacity: 0;
  transform: translate3d(-50%, 50%, 0) scale(0.5);
  pointer-events: none;
}

#envelope-scene.is-card-out #mainCard {
  transform: translate3d(-50%, -50%, 0) translateY(0); /* Perfectly centered on screen! */
}

#envelope-scene.is-done .env-back,
#envelope-scene.is-done .env-front,
#envelope-scene.is-done .env-flap {
  opacity: 0;
  transform: translate3d(0, 120px, 0);
  pointer-events: none;
}

#envelope-scene.is-done .env-pocket {
  clip-path: none; /* Allow the bottom of the card and its buttons to be fully visible once envelope fades out */
}
