/* ==========================================================================
   ENVELOPE.CSS - HIỆU ỨNG 3D MỞ BAO THƯ VÀ TỜ THƯ TÌNH CẢM
   ========================================================================== */

#scene-envelope {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

.envelope-prompt {
  margin-bottom: 25px;
  font-family: var(--font-heading);
  font-size: clamp(20px, 4vw, 28px);
  color: #ffeaa7;
  text-shadow: 0 0 12px rgba(248, 194, 145, 0.6);
  animation: promptGlow 2s ease-in-out infinite alternate;
}

@keyframes promptGlow {
  0% { opacity: 0.8; transform: translateY(0); }
  100% { opacity: 1; transform: translateY(-4px); }
}

/* 3D Envelope Stage */
.envelope-stage {
  perspective: 1200px;
  width: 100%;
  max-width: 420px;
  height: 280px;
  position: relative;
  cursor: pointer;
  margin: 0 auto;
}

.envelope-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: #92223e;
  border-radius: 12px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.65), 0 0 30px rgba(255, 107, 139, 0.35);
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.envelope-stage:hover .envelope-wrapper {
  transform: translateY(-6px) scale(1.02);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.75), 0 0 45px rgba(255, 107, 139, 0.5);
}

/* Envelope Internal Back */
.envelope-back {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #7a162f;
  border-radius: 12px;
  overflow: hidden;
  z-index: 1;
}

/* Envelope Paper Preview Inside */
.envelope-preview-paper {
  position: absolute;
  top: 15px;
  left: 5%;
  width: 90%;
  height: 85%;
  background: #fffdf9;
  border-radius: 8px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
  z-index: 2;
  transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s, z-index 0.05s 0.2s;
  display: flex;
  flex-direction: column;
  padding: 15px 20px;
  opacity: 0.95;
  border: 1px dashed rgba(224, 49, 107, 0.3);
}

.envelope-preview-paper .paper-line {
  height: 8px;
  background: #f1dfdf;
  border-radius: 4px;
  margin-bottom: 10px;
}

.envelope-preview-paper .paper-line:nth-child(1) { width: 55%; background: #ff8e9e; height: 10px; }
.envelope-preview-paper .paper-line:nth-child(2) { width: 85%; }
.envelope-preview-paper .paper-line:nth-child(3) { width: 70%; }
.envelope-preview-paper .paper-line:nth-child(4) { width: 60%; }

/* Envelope Fold Flaps */
.envelope-folds {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
}

/* Left & Right Side Triangles */
.flap-left {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 140px 0 140px 210px;
  border-color: transparent transparent transparent #841b36;
  border-top-left-radius: 12px;
  border-bottom-left-radius: 12px;
}

.flap-right {
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 140px 210px 140px 0;
  border-color: transparent #8b1e39 transparent transparent;
  border-top-right-radius: 12px;
  border-bottom-right-radius: 12px;
}

/* Bottom Flap */
.flap-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 210px 155px 210px;
  border-color: transparent transparent #a32746 transparent;
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
  filter: drop-shadow(0 -3px 6px rgba(0, 0, 0, 0.15));
}

/* Top Triangle Flap (Opens up) */
.flap-top {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 160px 210px 0 210px;
  border-color: #b72f51 transparent transparent transparent;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  transform-origin: top center;
  transition: transform 0.65s cubic-bezier(0.4, 0, 0.2, 1), z-index 0.05s 0.2s;
  z-index: 5;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.25));
  backface-visibility: hidden;
}

/* Wax Seal Stamp */
.wax-seal {
  position: absolute;
  top: 135px;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffd27d 0%, #d49339 55%, #8c5311 100%);
  border: 3px solid #f9d892;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.6), 0 0 15px rgba(248, 194, 145, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  z-index: 6;
  transition: all 0.5s ease;
  cursor: pointer;
  animation: sealPulse 2.5s infinite;
}

@keyframes sealPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5), 0 0 15px rgba(248, 194, 145, 0.4); }
  50% { transform: translate(-50%, -50%) scale(1.08); box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6), 0 0 25px rgba(248, 194, 145, 0.7); }
}

.wax-seal i {
  font-size: 26px;
  color: #fff;
  filter: drop-shadow(0 2px 4px rgba(70, 35, 5, 0.6));
}

.seal-text {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #fff;
  margin-top: 2px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* State when envelope is opened:
   - Nắp phong bì mở ra sau và lập tức lùi xuống z-index 0
   - Tờ thư trồi lên trên cùng (z-index: 20) che phủ hoàn toàn nắp và các mép gấp */
.envelope-stage.opened .flap-top {
  transform: rotateX(180deg);
  z-index: 0;
}

.envelope-stage.opened .wax-seal {
  opacity: 0;
  transform: translate(-50%, -80px) scale(0.6);
  pointer-events: none;
}

.envelope-stage.opened .envelope-preview-paper {
  transform: translateY(-135px);
  z-index: 20;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 107, 139, 0.3);
}

/* ==========================================================================
   EXPANDED LETTER MODAL OVERLAY
   ========================================================================== */
.letter-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 3, 7, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.letter-modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.letter-paper-modal {
  position: relative;
  width: 100%;
  max-width: 680px;
  max-height: 88vh;
  background: #fffdf9 url('data:image/svg+xml;utf8,<svg width="40" height="40" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg"><g fill="%23f7e6e9" fill-opacity="0.35"><circle cx="20" cy="20" r="1"/></g></svg>');
  border-radius: 18px;
  padding: clamp(25px, 5vw, 45px);
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.7), 0 0 50px rgba(255, 107, 139, 0.3);
  border: 1px solid #f3d7df;
  display: flex;
  flex-direction: column;
  transform: scale(0.9) translateY(30px);
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.letter-modal-overlay.active .letter-paper-modal {
  transform: scale(1) translateY(0);
}

/* Vintage Paper Ornaments */
.letter-paper-modal::before {
  content: '';
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  bottom: 10px;
  border: 1px dashed rgba(212, 103, 133, 0.35);
  border-radius: 12px;
  pointer-events: none;
}

.paper-corner-decor {
  position: absolute;
  font-size: 20px;
  color: var(--primary-pink);
  opacity: 0.6;
}
.corner-tl { top: 18px; left: 18px; }
.corner-tr { top: 18px; right: 18px; }
.corner-bl { bottom: 18px; left: 18px; }
.corner-br { bottom: 18px; right: 18px; }

/* Letter Content */
.letter-scroll-body {
  overflow-y: auto;
  padding-right: 10px;
  margin: 15px 0 20px 0;
  text-align: left;
}

.letter-scroll-body::-webkit-scrollbar {
  width: 6px;
}
.letter-scroll-body::-webkit-scrollbar-thumb {
  background: #f1b3c2;
  border-radius: 10px;
}

.letter-header {
  font-family: var(--font-letter);
  font-size: clamp(26px, 4vw, 34px);
  color: #8c1936;
  font-weight: 700;
  margin-bottom: 18px;
  border-bottom: 1px solid rgba(224, 49, 107, 0.2);
  padding-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.letter-date {
  font-family: var(--font-body);
  font-size: 13px;
  color: #9c6877;
  font-weight: 500;
}

.letter-typed-content {
  font-family: var(--font-letter);
  font-size: clamp(20px, 3.2vw, 25px);
  line-height: 1.8;
  color: #3b1720;
  min-height: 140px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Custom Typing Cursor */
.typed-cursor-custom {
  display: inline-block;
  color: var(--primary-pink);
  font-weight: bold;
  animation: blinkCursor 0.8s infinite;
}

@keyframes blinkCursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.letter-signature {
  margin-top: 25px;
  text-align: right;
  font-family: var(--font-letter);
  font-size: clamp(22px, 3.5vw, 28px);
  color: #a32344;
  font-weight: 700;
}

.letter-signature span {
  display: block;
  font-family: var(--font-body);
  font-size: 13px;
  color: #8f6571;
  font-weight: 400;
  margin-top: 4px;
}

/* Letter Footer Actions */
.letter-footer-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  border-top: 1px solid rgba(212, 103, 133, 0.2);
  padding-top: 18px;
  z-index: 10;
}

.btn-skip-typing {
  background: none;
  border: none;
  font-size: 13px;
  color: #8c5061;
  cursor: pointer;
  text-decoration: underline;
  transition: color 0.3s;
}

.btn-skip-typing:hover {
  color: var(--primary-pink);
}

@media (max-width: 500px) {
  .envelope-stage {
    max-width: 320px;
    height: 220px;
  }
  .flap-left {
    border-width: 110px 0 110px 160px;
  }
  .flap-right {
    border-width: 110px 160px 110px 0;
  }
  .flap-bottom {
    border-width: 0 160px 120px 160px;
  }
  .flap-top {
    border-width: 125px 160px 0 160px;
  }
  .wax-seal {
    top: 105px;
    width: 60px;
    height: 60px;
  }
  .wax-seal i {
    font-size: 20px;
  }
  .seal-text {
    font-size: 7px;
  }
  .letter-footer-actions {
    flex-direction: column-reverse;
  }
  .letter-footer-actions .btn-romantic {
    width: 100%;
  }
}
