/* ===================================================
   SOBRE ELEGANTE Y REALISTA
   1. Al inicio: Solo se ve el sobre cerrado.
   2. Al tocar: La carta sale del sobre HACIA ARRIBA.
   3. El sobre se va HACIA ABAJO y se desvanece.
=================================================== */

#envelope-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 50%, #2f1c20 0%, #140a0d 100%);
  transition: opacity 0.6s ease, visibility 0.6s ease;
  overflow: hidden;
  user-select: none;
  padding: 20px;
}

#envelope-overlay.opened {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Polvo dorado flotante de fondo */
#envelope-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* Letrero arriba del sobre */
.envelope-instruction {
  position: relative;
  z-index: 20;
  margin-bottom: 25px;
  text-align: center;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#envelope-overlay.opening .envelope-instruction,
.envelope-wrapper.open ~ .envelope-instruction {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transform: translateY(-15px);
}

.envelope-instruction span {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 28px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(196, 123, 133, 0.6);
  backdrop-filter: blur(10px);
  border-radius: 50px;
  color: #fcebee;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.9rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.5);
  animation: floatSimple 2.5s infinite ease-in-out;
}

.envelope-instruction i {
  color: #fad1d7;
}

/* ===================================================
   CONTENEDOR DEL SOBRE Y LA CARTA
=================================================== */
.envelope-wrapper {
  position: relative;
  width: 340px;
  height: 230px;
  perspective: 1200px;
  cursor: pointer;
  z-index: 10;
  max-width: 100%;
}

@media (min-width: 600px) {
  .envelope-wrapper {
    width: 440px;
    height: 280px;
  }
}

@media (max-width: 380px) {
  #envelope-overlay {
    padding: 12px;
  }
  .envelope-wrapper {
    transform: scale(calc((100vw - 28px) / 340));
    transform-origin: center center;
  }
  .envelope-instruction {
    margin-bottom: 16px;
  }
  .envelope-instruction span {
    font-size: 0.76rem;
    padding: 10px 18px;
    letter-spacing: 1px;
  }
}

@media (max-height: 640px) {
  .envelope-instruction {
    margin-bottom: 10px;
  }
  .envelope-instruction span {
    padding: 7px 16px;
    font-size: 0.75rem;
  }
  .envelope-wrapper.open .env-letter-card {
    transform: translateY(-95px) scale(1.02);
  }
  .envelope-wrapper.open .envelope-shell {
    transform: translateY(125px);
  }
}

/* ===================================================
   1. EL SOBRE COMPLETO (Se desliza hacia ABAJO y se desvanece)
=================================================== */
.envelope-shell {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  transition: transform 0.85s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.85s ease;
  z-index: 5;
}

/* Cuando se abre: El sobre se desliza hacia ABAJO y se va DESVANECIENDO */
.envelope-wrapper.open .envelope-shell {
  transform: translateY(170px);
  opacity: 0;
  pointer-events: none;
}

/* Fondo trasero del sobre */
.env-back {
  position: absolute;
  inset: 0;
  background: #f0d5d9;
  border-radius: 14px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
  border: 1px solid #c47b85;
  z-index: 1;
}

/* Solapa superior que se abre hacia arriba */
.env-top-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-left: 170px solid transparent;
  border-right: 170px solid transparent;
  border-top: 135px solid #e8c7cd;
  transform-origin: top center;
  transform: rotateX(0deg);
  transition: transform 0.4s ease, border-top-color 0.4s ease;
  z-index: 6;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.2));
}

@media (min-width: 600px) {
  .env-top-flap {
    border-left-width: 220px;
    border-right-width: 220px;
    border-top-width: 165px;
  }
}

/* Al tocar: La solapa se levanta */
.envelope-wrapper.open .env-top-flap {
  transform: rotateX(180deg);
  border-top-color: #dfb8bf;
  z-index: 1;
}

/* Frente del sobre (Cubre la carta al inicio) */
.env-front-cover {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: linear-gradient(180deg, #fdf6f7 0%, #eed2d6 100%);
  clip-path: polygon(0 38%, 50% 65%, 100% 38%, 100% 100%, 0 100%);
  border-radius: 0 0 14px 14px;
  border-bottom: 1px solid #c47b85;
  z-index: 4;
}

/* Filo dorado en el frente del sobre */
.env-front-cover::after {
  content: '';
  position: absolute;
  inset: 0;
  clip-path: polygon(0 38%, 50% 65%, 100% 38%, 100% 39.5%, 50% 66.5%, 0 39.5%);
  background: linear-gradient(90deg, #c87b87, #fce4e8, #b86775);
}

/* Sello de cera dorado sobre la solapa */
.env-wax-seal {
  position: absolute;
  top: 115px;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fcdde2 0%, #c47b85 45%, #883e4a 100%);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5), 0 0 25px rgba(196, 123, 133, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  z-index: 8;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

@media (min-width: 600px) {
  .env-wax-seal {
    top: 140px;
    width: 80px;
    height: 80px;
  }
}

.env-wax-seal i {
  font-size: 0.85rem;
  margin-bottom: 2px;
}

.env-wax-seal span {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 1px;
}

.envelope-wrapper.open .env-wax-seal {
  transform: translate(-50%, -50%) scale(1.3);
  opacity: 0;
  pointer-events: none;
}

/* ===================================================
   2. LA CARTA DE INVITACIÓN (Sale del sobre hacia ARRIBA)
=================================================== */
.env-letter-card {
  position: absolute;
  top: 12px;
  left: 14px;
  right: 14px;
  bottom: 12px;
  background: #ffffff;
  background-image: linear-gradient(145deg, #ffffff 0%, #fdf5f6 100%);
  border-radius: 12px;
  border: 1.5px solid #c47b85;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 22px 18px;
  text-align: center;
  z-index: 2; /* Al inicio está adentro del sobre, detrás del frente */
  transform: translateY(0);
  transition: 
    transform 0.85s cubic-bezier(0.2, 0.8, 0.2, 1),
    box-shadow 0.6s ease,
    z-index 0.01s 0.25s; /* Pasa al frente mientras sale */
}

/* Cuando se abre: La carta sale deslizándose directo hacia ARRIBA */
.envelope-wrapper.open .env-letter-card {
  z-index: 20 !important;
  transform: translateY(-130px) scale(1.05);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.55), 0 0 35px rgba(196, 123, 133, 0.5);
}

@media (min-width: 600px) {
  .envelope-wrapper.open .env-letter-card {
    transform: translateY(-160px) scale(1.08);
  }
}

/* Contenido de la carta */
.letter-border {
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(196, 123, 133, 0.45);
  border-radius: 8px;
  pointer-events: none;
}

.letter-crown {
  color: #c47b85;
  font-size: 1.3rem;
  margin-bottom: 4px;
}

.letter-subtitle {
  font-family: 'Montserrat', sans-serif;
  font-size: 0.68rem;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #9e646d;
  margin-bottom: 4px;
  font-weight: 600;
}

.letter-name {
  font-family: 'Great Vibes', cursive;
  font-size: clamp(2.2rem, 7vw, 3.2rem);
  color: #8c4652;
  line-height: 1.1;
  margin: 0;
  text-shadow: 0 1px 4px rgba(196, 123, 133, 0.2);
}

@media (max-width: 600px) {
  .letter-subtitle {
    font-size: 0.62rem;
    letter-spacing: 3px;
  }
  .letter-tag {
    font-size: 0.78rem;
    letter-spacing: 3px;
  }
  .letter-date {
    font-size: clamp(0.7rem, 2.7vw, 0.8rem);
    letter-spacing: 0.5px;
    white-space: nowrap;
  }
}

.letter-tag {
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  letter-spacing: 4px;
  color: #55343a;
  margin: 6px 0 8px;
  font-weight: 700;
}

.letter-date {
  font-family: 'Montserrat', sans-serif;
  font-size: 0.82rem;
  color: #6d4f54;
  letter-spacing: 1px;
}

/* Botón flotante para volver a ver el sobre */
.btn-reopen-envelope {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 990;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(196, 123, 133, 0.5);
  backdrop-filter: blur(10px);
  border-radius: 30px;
  color: #85444f;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: all 0.3s ease;
}

@media (max-width: 500px) {
  .btn-reopen-envelope {
    top: 12px;
    left: 12px;
    padding: 6px 14px;
    font-size: 0.75rem;
    gap: 6px;
  }
}

.btn-reopen-envelope:hover {
  background: #ffffff;
  box-shadow: 0 6px 20px rgba(196, 123, 133, 0.3);
  transform: translateY(-2px);
}

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

/* ===================================================
   SOBRE EN CELULARES ANGOSTOS
   El sobre mide 340px; en pantallas más chicas se reduce
   completo (solapa, sello y carta) en lugar de cortarse.
=================================================== */
@media (max-width: 380px) {
  .envelope-wrapper {
    width: 340px;
    max-width: none;
    transform: scale(0.94);
    transform-origin: center center;
  }
}

@media (max-width: 345px) {
  .envelope-wrapper { transform: scale(0.86); }
}

@media (max-width: 300px) {
  .envelope-wrapper { transform: scale(0.74); }
}
