/**
 * ====================================================================
 * GIAO DIỆN PHONG BÌ & BỨC THƯ 20/10 GỬI MỸ LINH (LETTER.CSS)
 * Phong cách: Modern Dreamy Aesthetic
 * ====================================================================
 * - Tông màu: Pastel lavender, hồng phấn, trắng ngọc trai, ánh sáng nhẹ.
 * - Hiện đại, lãng mạn, tinh tế và có chiều sâu.
 * - Loại bỏ hoàn toàn cảm giác vintage, giấy cũ hay phong thư sáp cổ điển.
 * - Tối ưu 100% khả năng đọc, chữ rõ nét và bố cục thoáng đãng.
 * - Responsive hoàn hảo cho cả máy tính lẫn điện thoại.
 */

/* --------------------------------------------------------------------
   1. NÚT CHUYỂN TỪ QUẢ CẦU 3D SANG MÓN QUÀ (SPHERE ACTION BAR)
   -------------------------------------------------------------------- */
.sphere-action-bar {
  position: fixed;
  bottom: clamp(24px, 5vh, 44px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  z-index: 38;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.8s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.8s cubic-bezier(0.22, 1, 0.36, 1),
              visibility 0.8s;
}

.sphere-action-bar.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.sphere-to-letter-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  background: linear-gradient(135deg, rgba(255, 182, 218, 0.92) 0%, rgba(216, 180, 254, 0.9) 100%);
  color: #311847;
  font-family: var(--font-body, 'Montserrat', sans-serif);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.4px;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 0 25px rgba(232, 180, 254, 0.65),
              0 8px 24px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
              box-shadow 0.35s ease,
              background 0.35s ease;
  user-select: none;
  -webkit-user-select: none;
  animation: modernBtnGlow 2.8s ease-in-out infinite alternate;
}

.sphere-to-letter-btn:hover {
  transform: scale(1.04) translateY(-2px);
  box-shadow: 0 0 35px rgba(255, 192, 230, 0.85),
              0 12px 30px rgba(0, 0, 0, 0.4);
  background: linear-gradient(135deg, rgba(255, 200, 230, 0.98) 0%, rgba(228, 198, 255, 0.95) 100%);
}

.sphere-to-letter-btn:active {
  transform: scale(0.98);
}

@keyframes modernBtnGlow {
  0% {
    box-shadow: 0 0 20px rgba(232, 180, 254, 0.5), 0 6px 18px rgba(0, 0, 0, 0.25);
  }
  100% {
    box-shadow: 0 0 32px rgba(255, 175, 215, 0.8), 0 10px 26px rgba(181, 23, 158, 0.35);
  }
}

/* --------------------------------------------------------------------
   2. KHAI BÁO BIẾN MÀU SẮC & THIẾT KẾ CHO GIAI ĐOẠN CUỐI
   - Nền: Tím đêm và xanh tím vũ trụ.
   - Phong bì: Đỏ rượu vang, đỏ mận (Wine Red / Plum).
   - Ánh sáng: Lavender, hồng pastel dịu êm.
   - Viền: Vàng champagne / rose gold.
   - Giấy thư: Trắng kem (Ivory paper).
   -------------------------------------------------------------------- */
:root {
  --env-wine-deep: #47081a;
  --env-wine-base: #6b1129;
  --env-wine-mid: #7e1634;
  --env-wine-bright: #981f42;
  --env-wine-sheen: #b82a52;
  --env-gold-foil: #e2ba78;
  --env-gold-light: #fff2ce;
  --env-gold-border: rgba(226, 186, 120, 0.55);
  --env-rose-glow: rgba(244, 114, 182, 0.35);
  --env-lavender-glow: rgba(192, 132, 252, 0.25);

  --paper-ivory-start: #ffffff;
  --paper-ivory-mid: #fffaf4;
  --paper-ivory-end: #fff4ea;
  --paper-border: rgba(218, 168, 142, 0.65);
  --paper-inner-line: rgba(225, 182, 162, 0.35);

  --font-cursive: 'Dancing Script', 'Caveat', cursive;
  --font-serif: 'Playfair Display', serif;
  --font-body: 'Montserrat', sans-serif;
  --text-dark-wine: #380816;
  --text-body-wine: #441021;
}

/* --------------------------------------------------------------------
   3. MÀN HÌNH CHÍNH GIAI ĐOẠN CUỐI (#letter-screen)
   -------------------------------------------------------------------- */
.letter-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 46;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  perspective: 1400px;
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
  padding: 40px 16px 60px;
  transition: opacity 0.8s cubic-bezier(0.22, 1, 0.36, 1),
              visibility 0.8s;
  -webkit-overflow-scrolling: touch;
}

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

.letter-screen.fade-out {
  opacity: 0 !important;
  pointer-events: none !important;
  transition: opacity 0.6s ease;
}

/* Nền hào quang lavender & hồng pastel dịu êm phía sau phong bì */
.letter-ambient-backdrop {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(90vw, 750px);
  height: min(90vh, 750px);
  background: radial-gradient(
    circle,
    rgba(236, 72, 153, 0.18) 0%,
    rgba(168, 85, 247, 0.14) 35%,
    rgba(99, 102, 241, 0.08) 60%,
    transparent 78%
  );
  filter: blur(65px);
  pointer-events: none;
  z-index: 1;
  animation: ambientAuraBreath 7.5s ease-in-out infinite alternate;
}

@keyframes ambientAuraBreath {
  0% { transform: translate(-50%, -50%) scale(0.92); opacity: 0.7; }
  100% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
}

/* --------------------------------------------------------------------
   4. VÒNG QUỸ ĐẠO ÁNH SÁNG DƯỚI SÀN KHÔNG GIAN (COSMIC ORBIT GROUND)
   - Tái hiện quầng sáng elip ma thuật dưới chân phong thư theo ảnh mẫu
   -------------------------------------------------------------------- */
.letter-cosmic-orbit {
  position: absolute;
  bottom: clamp(10px, 9vh, 75px);
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 720px);
  height: 180px;
  pointer-events: none;
  z-index: 2;
}

.cosmic-ring-outer {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(244, 114, 182, 0.45);
  box-shadow: 0 0 35px rgba(236, 72, 153, 0.45),
              inset 0 0 25px rgba(192, 132, 252, 0.35);
  transform: rotateX(74deg);
  animation: cosmicRingPulse 5s ease-in-out infinite alternate;
}

.cosmic-ring-inner {
  position: absolute;
  top: 25px; bottom: 25px; left: 80px; right: 80px;
  border-radius: 50%;
  border: 1px dashed rgba(255, 200, 225, 0.4);
  transform: rotateX(74deg);
  animation: cosmicRingRotate 50s linear infinite;
}

.cosmic-ring-flare {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotateX(74deg);
  width: 60%;
  height: 60%;
  background: radial-gradient(circle, rgba(255, 182, 218, 0.28) 0%, rgba(192, 132, 252, 0.15) 50%, transparent 80%);
  filter: blur(14px);
}

@keyframes cosmicRingPulse {
  0% { opacity: 0.55; box-shadow: 0 0 25px rgba(236, 72, 153, 0.35); }
  100% { opacity: 0.95; box-shadow: 0 0 45px rgba(244, 114, 182, 0.65), 0 0 20px rgba(255, 255, 255, 0.5); }
}

@keyframes cosmicRingRotate {
  0% { transform: rotateX(74deg) rotateZ(0deg); }
  100% { transform: rotateX(74deg) rotateZ(360deg); }
}

/* --------------------------------------------------------------------
   5. CÁC HẠT SÁNG & CÁNH HOA BAY TRONG KHÔNG GIAN
   -------------------------------------------------------------------- */
.letter-particles-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
  overflow: hidden;
}

.letter-floating-item {
  position: absolute;
  opacity: 0;
  user-select: none;
  pointer-events: none;
  animation: floatCosmicItem 9.5s ease-in-out infinite;
}

.item-heart {
  color: #ff85a2;
  font-size: 15px;
  filter: drop-shadow(0 0 8px rgba(255, 133, 162, 0.75));
}

.item-sparkle {
  color: #fef08a;
  font-size: 13px;
  filter: drop-shadow(0 0 8px rgba(254, 240, 138, 0.85));
}

.item-petal {
  display: inline-block;
  width: 12px;
  height: 16px;
  background: radial-gradient(circle at 35% 35%, #ffe4ec, #f472b6 65%, #c084fc 100%);
  border-radius: 60% 40% 70% 30% / 60% 30% 70% 40%;
  opacity: 0.75;
  filter: drop-shadow(0 0 6px rgba(244, 114, 182, 0.4));
}

@keyframes floatCosmicItem {
  0% {
    transform: translateY(25px) rotate(0deg) scale(0.85);
    opacity: 0;
  }
  15% {
    opacity: 0.8;
  }
  85% {
    opacity: 0.8;
  }
  100% {
    transform: translateY(-90px) rotate(260deg) scale(1.08);
    opacity: 0;
  }
}

/* --------------------------------------------------------------------
   6. DÒNG CHỮ THƠ MỘNG GÓC PHẢI (HANDWRITING FLOATING QUOTE)
   - "Một bức thư nhỏ / Gửi trọn yêu thương... ♡"
   -------------------------------------------------------------------- */
.letter-floating-quote {
  position: absolute;
  top: clamp(22px, 6vh, 65px);
  right: clamp(16px, 6vw, 100px);
  text-align: right;
  pointer-events: none;
  z-index: 6;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 1.3s cubic-bezier(0.22, 1, 0.36, 1) 0.5s,
              transform 1.3s cubic-bezier(0.22, 1, 0.36, 1) 0.5s;
}

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

.quote-line-top {
  font-family: var(--font-cursive);
  font-size: clamp(1.2rem, 2.3vw, 1.7rem);
  color: #fce7f3;
  margin: 0 0 2px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-shadow: 0 0 16px rgba(244, 114, 182, 0.8),
               0 2px 8px rgba(0, 0, 0, 0.5);
}

.quote-line-bottom {
  font-family: var(--font-cursive);
  font-size: clamp(1.35rem, 2.6vw, 2.05rem);
  color: #fed7e2;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-shadow: 0 0 20px rgba(236, 72, 153, 0.85),
               0 2px 10px rgba(0, 0, 0, 0.5);
}

.quote-heart {
  color: #fb7185;
  display: inline-block;
  margin-left: 4px;
  animation: heartPulse 2.2s ease-in-out infinite alternate;
}

@keyframes heartPulse {
  0% { transform: scale(1); filter: drop-shadow(0 0 3px rgba(251, 113, 133, 0.6)); }
  100% { transform: scale(1.18); filter: drop-shadow(0 0 10px rgba(244, 63, 94, 0.95)); }
}

/* --------------------------------------------------------------------
   7. KHUNG CẢNH TRUNG TÂM CHỨA PHONG BÌ & LÁ THƯ
   -------------------------------------------------------------------- */
.letter-scene-container {
  position: relative;
  width: 100%;
  max-width: 540px;
  min-height: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 5;
  margin: auto;
}

/* --------------------------------------------------------------------
   8. THIẾT KẾ PHONG THƯ MÀU ĐỎ RƯỢU VANG PHA TÍM HỒNG (HTML/CSS THUẦN)
   -------------------------------------------------------------------- */
.envelope-wrapper {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 310px;
  perspective: 1200px;
  transform-style: preserve-3d;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 14px;
  background: linear-gradient(155deg, var(--env-wine-bright) 0%, var(--env-wine-mid) 40%, var(--env-wine-deep) 100%);
  box-shadow: 0 25px 60px rgba(10, 2, 12, 0.8),
              0 0 35px var(--env-rose-glow),
              inset 0 0 35px rgba(25, 3, 10, 0.6);
  border: 1px solid var(--env-gold-border);
  z-index: 10;
  transition: transform 0.95s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.95s cubic-bezier(0.22, 1, 0.36, 1),
              filter 0.95s ease,
              box-shadow 0.45s ease;
}

.envelope-wrapper:hover:not(.is-receded) {
  transform: translateY(-4px) scale(1.015);
  box-shadow: 0 30px 65px rgba(10, 2, 12, 0.85),
              0 0 45px rgba(244, 114, 182, 0.5);
}

/* Khi phong bì lùi ra sau nhường vị trí trung tâm cho chế độ đọc thư */
.envelope-wrapper.is-receded {
  transform: translateY(180px) scale(0.78);
  opacity: 0.35;
  filter: blur(1.5px);
  pointer-events: auto; /* Cho phép chạm lại phong bì để mở/đưa thư ra giữa */
}

.envelope-wrapper.is-receded:hover {
  opacity: 0.55;
  filter: blur(0.5px);
}

/* Ánh hào quang nhẹ quanh phong bì */
.envelope-aura-glow {
  position: absolute;
  inset: -12px;
  border-radius: 24px;
  background: radial-gradient(circle, rgba(244, 114, 182, 0.22) 0%, rgba(168, 85, 247, 0.12) 50%, transparent 75%);
  filter: blur(15px);
  pointer-events: none;
  z-index: -1;
}

/* Thân sau phong bì (Envelope Back Lining) */
.envelope-back {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 13px;
  background: linear-gradient(145deg, #420718 0%, #2e0410 60%, #1e020a 100%);
  box-shadow: inset 0 0 45px rgba(0, 0, 0, 0.8);
  z-index: 1;
  overflow: hidden;
}

.envelope-back-sheen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: linear-gradient(180deg, rgba(226, 186, 120, 0.15) 0%, transparent 100%);
}

/* NẮP PHONG BÌ PHÍA TRÊN (TOP FLAP) - LẬT MỞ 180 ĐỘ BẰNG TRANSFORM & TRANSFORM-ORIGIN */
.envelope-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-origin: top center;
  transform-style: preserve-3d;
  z-index: 5;
  transition: transform 1.05s cubic-bezier(0.34, 1.25, 0.64, 1);
}

.flap-side {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* Mặt ngoài nắp khi phong bì đang đóng */
.flap-front {
  z-index: 2;
  transform: rotateX(0deg);
}

.flap-triangle-shape {
  width: 100%;
  height: 100%;
  clip-path: polygon(0 0, 100% 0, 50% 55%);
  background: linear-gradient(180deg, #961d3f 0%, #7d1534 60%, #5e0d24 100%);
  box-shadow: inset 0 2px 4px rgba(255, 200, 220, 0.3);
  filter: drop-shadow(0 6px 12px rgba(12, 1, 5, 0.6));
}

.flap-gold-edge {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  clip-path: polygon(0 0, 100% 0, 50% 55%);
  border-top: 1.5px solid var(--env-gold-border);
  pointer-events: none;
}

/* Mặt trong nắp lộ ra khi lật mở 180 độ */
.flap-back {
  transform: rotateY(180deg) rotateZ(180deg);
  z-index: 1;
}

.flap-inner-lining {
  width: 100%;
  height: 100%;
  clip-path: polygon(0 0, 100% 0, 50% 55%);
  background: linear-gradient(180deg, #4d091c 0%, #630e26 55%, #470716 100%);
  box-shadow: inset 0 0 25px rgba(0, 0, 0, 0.65);
}

.flap-inner-rim {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  clip-path: polygon(0 0, 100% 0, 50% 55%);
  border-top: 1px solid rgba(226, 186, 120, 0.4);
  pointer-events: none;
}

/* HAI NẮP GẤP 2 BÊN (SIDE FLAPS) TẠO BẰNG CSS CLIP-PATH TAM GIÁC */
.envelope-fold {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.fold-left {
  clip-path: polygon(0 0, 52% 51%, 0 100%);
  background: linear-gradient(135deg, #811736 0%, #600f27 60%, #46091a 100%);
  z-index: 3;
  border-bottom-left-radius: 13px;
  border-top-left-radius: 13px;
  filter: drop-shadow(3px 0 8px rgba(10, 1, 4, 0.4));
}

.fold-right {
  clip-path: polygon(100% 0, 48% 51%, 100% 100%);
  background: linear-gradient(225deg, #811736 0%, #600f27 60%, #46091a 100%);
  z-index: 3;
  border-bottom-right-radius: 13px;
  border-top-right-radius: 13px;
  filter: drop-shadow(-3px 0 8px rgba(10, 1, 4, 0.4));
}

/* NẮP GẤP PHÍA DƯỚI TẠO TÚI PHONG BÌ (BOTTOM FOLD) */
.fold-bottom {
  clip-path: polygon(0 100%, 50% 46%, 100% 100%);
  background: linear-gradient(0deg, #640f28 0%, #7b1534 60%, #8e1a3d 100%);
  z-index: 4;
  border-bottom-left-radius: 13px;
  border-bottom-right-radius: 13px;
  box-shadow: inset 0 -2px 6px rgba(255, 180, 200, 0.15);
  filter: drop-shadow(0 -4px 12px rgba(12, 1, 5, 0.55));
}

/* Họa tiết viền vàng kim góc phong thư */
.envelope-corner-filigree {
  position: absolute;
  bottom: 6px;
  width: 44px;
  height: 44px;
  pointer-events: none;
}

.filigree-bl {
  left: 6px;
}

.filigree-br {
  right: 6px;
}

.envelope-corner-filigree svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* --------------------------------------------------------------------
   9. CON DẤU SÁP 3D HÌNH TRÒN CÓ BIỂU TƯỢNG HOA HỒNG (CSS PURE)
   -------------------------------------------------------------------- */
.envelope-wax-seal {
  position: absolute;
  top: 51%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  z-index: 6;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.4s ease,
              box-shadow 0.35s ease;
}

.wax-seal-pulse-glow {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(244, 114, 182, 0.45) 0%, transparent 70%);
  animation: waxGlowBreath 2.6s ease-in-out infinite alternate;
  pointer-events: none;
}

.wax-seal-body {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 49% 51% 52% 48% / 51% 49% 51% 49%;
  background: radial-gradient(circle at 35% 35%, #ca2653 0%, #98153b 55%, #5a0920 100%);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.6),
              0 0 22px rgba(220, 45, 90, 0.5),
              inset 0 2px 4px rgba(255, 255, 255, 0.45),
              inset 0 -3px 6px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 185, 205, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease;
}

.wax-seal-relief-ring {
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 190, 210, 0.32);
  box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.5),
              1px 1px 2px rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

.wax-rose-svg {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
  pointer-events: none;
}

.wax-seal-tag {
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.8px;
  color: #fed7e2;
  background: rgba(56, 8, 22, 0.85);
  padding: 2px 10px;
  border-radius: 999px;
  border: 0.8px solid rgba(244, 114, 182, 0.4);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: opacity 0.3s ease;
}

.envelope-wax-seal:hover {
  transform: translate(-50%, -50%) scale(1.08);
}

.envelope-wax-seal:hover .wax-seal-body {
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.7),
              0 0 30px rgba(244, 114, 182, 0.75),
              inset 0 2px 5px rgba(255, 255, 255, 0.6);
}

@keyframes waxGlowBreath {
  0% { transform: scale(0.92); opacity: 0.5; }
  100% { transform: scale(1.18); opacity: 0.95; }
}

/* Khi con dấu được nhấn */
.envelope-wax-seal.is-clicked {
  transform: translate(-50%, -50%) scale(1.22);
  opacity: 0;
  box-shadow: 0 0 45px rgba(255, 200, 225, 0.95),
              0 0 80px rgba(236, 72, 153, 0.75);
  pointer-events: none;
}

.envelope-wax-seal.is-clicked .wax-seal-tag {
  opacity: 0;
}

/* Trạng thái mở nắp phong bì */
.envelope-wrapper.is-open {
  cursor: default;
}

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

.envelope-wrapper.is-open.flap-behind .envelope-flap {
  z-index: 1;
}

/* --------------------------------------------------------------------
   10. LÁ THƯ CHÚC MỪNG 20/10 (.letter-card)
   - Chế độ đọc tấm thiệp lớn màu trắng kem sang trọng
   - Căn giữa màn hình hoàn toàn (không bị phong bì che, không cắt chữ ký)
   - Tự co giãn theo thiết bị, có thanh cuộn mượt mà nếu tràn màn hình
   -------------------------------------------------------------------- */
.letter-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, calc(-50% + 25px)) scale(0.82);
  width: min(92vw, 490px);
  max-height: min(88vh, 680px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 6; /* Nằm sau phong bì khi đóng */
  border-radius: 24px;
  background: linear-gradient(165deg, var(--paper-ivory-start) 0%, var(--paper-ivory-mid) 45%, var(--paper-ivory-end) 100%);
  border: 1.5px solid var(--paper-border);
  box-shadow: 0 20px 60px rgba(15, 2, 10, 0.4),
              0 0 40px rgba(255, 215, 230, 0.3),
              inset 0 1px 3px rgba(255, 255, 255, 0.98);
  padding: 32px 28px 28px;
  box-sizing: border-box;
  color: var(--text-dark-wine);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  transition: transform 0.85s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.65s cubic-bezier(0.22, 1, 0.36, 1),
              visibility 0.65s,
              box-shadow 0.85s ease;
}

/* Thanh cuộn tinh tế cho lá thư trên màn hình nhỏ */
.letter-card::-webkit-scrollbar {
  width: 5px;
}

.letter-card::-webkit-scrollbar-track {
  background: rgba(255, 235, 245, 0.4);
  border-radius: 999px;
}

.letter-card::-webkit-scrollbar-thumb {
  background: rgba(226, 186, 120, 0.65);
  border-radius: 999px;
}

.letter-card::-webkit-scrollbar-thumb:hover {
  background: rgba(218, 168, 142, 0.9);
}

/* BƯỚC 1: Lá thư trượt lên từ khe phong bì bằng animation mượt */
.letter-card.is-sliding-up {
  visibility: visible;
  opacity: 1;
  z-index: 15;
  transform: translate(-50%, calc(-50% - 150px)) scale(0.92) rotate(-2deg);
}

/* BƯỚC 2: CHẾ ĐỘ ĐỌC THƯ (READING MODE) - NẰM CHÍNH GIỮA MÀN HÌNH HOÀN TOÀN PHÍA TRƯỚC */
.letter-card.is-reading {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  z-index: 50 !important; /* Tuyệt đối nằm ở trên cùng, không gì có thể che khuất! */
  position: fixed; /* Căn giữa viewport theo yêu cầu */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1) rotate(0deg);
  box-shadow: 0 35px 90px rgba(0, 0, 0, 0.8),
              0 0 60px rgba(244, 114, 182, 0.45),
              0 0 100px rgba(168, 85, 247, 0.28),
              inset 0 1px 3px rgba(255, 255, 255, 0.98);
}

/* Nền phản chiếu ánh ngọc trai */
.letter-paper-sheen {
  position: absolute;
  inset: 0;
  border-radius: 23px;
  background: radial-gradient(circle at 80% 20%, rgba(255, 240, 248, 0.65) 0%, transparent 60%);
  pointer-events: none;
}

/* Đường viền chỉ kép thứ hai bên trong lá thư tạo chiều sâu */
.letter-inner-border {
  position: absolute;
  inset: 8px;
  border: 1px solid var(--paper-inner-line);
  border-radius: 17px;
  pointer-events: none;
}

/* NÚT THU NHỎ / ĐÓNG THƯ GÓC TRÊN */
.letter-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 240, 248, 0.85);
  border: 1px solid var(--paper-border);
  color: #881639;
  font-size: 1.3rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: all 0.25s ease;
  box-shadow: 0 2px 8px rgba(136, 22, 57, 0.1);
  padding: 0;
}

.letter-close-btn:hover {
  background: #ffffff;
  color: #e11d48;
  transform: scale(1.1);
  box-shadow: 0 3px 12px rgba(225, 29, 72, 0.25);
}

/* Cụm hoa trang trí ở các góc lá thư */
.letter-corner-flower {
  position: absolute;
  pointer-events: none;
  z-index: 1;
}

.flower-top-left {
  top: 6px;
  left: 6px;
  width: 80px;
  height: 80px;
}

.flower-top-right {
  top: 6px;
  right: 6px;
  width: 80px;
  height: 80px;
}

.flower-bottom-right {
  bottom: 6px;
  right: 6px;
  width: 105px;
  height: 95px;
}

.corner-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* --------------------------------------------------------------------
   11. NỘI DUNG LÁ THƯ (BỐ CỤC THOÁNG, CHỮ RÕ RÀNG, DỄ ĐỌC)
   -------------------------------------------------------------------- */

/* 1. Ảnh đại diện hình tròn ở phía trên */
.letter-avatar-container {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin: 0 auto 12px;
  width: 90px;
  height: 90px;
  z-index: 2;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.8s cubic-bezier(0.22, 1, 0.36, 1) 0.1s,
              transform 0.8s cubic-bezier(0.22, 1, 0.36, 1) 0.1s;
}

.letter-card.is-revealed .letter-avatar-container,
.letter-card.is-reading .letter-avatar-container {
  opacity: 1;
  transform: scale(1);
}

.letter-avatar-ring {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  padding: 3px;
  box-sizing: border-box;
  background: linear-gradient(135deg, #ffffff 0%, var(--env-gold-foil) 50%, #f472b6 100%);
  box-shadow: 0 6px 20px rgba(152, 31, 66, 0.22),
              0 0 16px rgba(255, 200, 225, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.9);
}

.letter-avatar-image {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.letter-avatar-heart-badge {
  position: absolute;
  top: 0;
  right: -4px;
  font-size: 16px;
  color: #e11d48;
  filter: drop-shadow(0 0 6px rgba(244, 114, 182, 0.8));
  animation: miniHeartFloat 2.4s ease-in-out infinite alternate;
}

@keyframes miniHeartFloat {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-4px) scale(1.15); }
}

/* 2. Tiêu đề "Chúc mừng ngày 20/10" viết tay thanh lịch */
.letter-header-group {
  text-align: center;
  margin-bottom: 12px;
  position: relative;
  z-index: 2;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.8s cubic-bezier(0.22, 1, 0.36, 1) 0.25s,
              transform 0.8s cubic-bezier(0.22, 1, 0.36, 1) 0.25s;
}

.letter-card.is-revealed .letter-header-group,
.letter-card.is-reading .letter-header-group {
  opacity: 1;
  transform: translateY(0);
}

.letter-cursive-title {
  font-family: var(--font-cursive);
  font-size: clamp(1.75rem, 3.8vw, 2.3rem);
  font-weight: 700;
  color: #881639;
  margin: 0 0 6px;
  letter-spacing: 0.4px;
  line-height: 1.25;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

.letter-title-heart-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 4px;
  margin-bottom: 4px;
}

.heart-line-bar {
  display: inline-block;
  width: 44px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(218, 168, 142, 0.85), transparent);
}

.heart-line-icon {
  color: #e11d48;
  font-size: 14px;
  filter: drop-shadow(0 0 5px rgba(225, 29, 72, 0.55));
}

/* 3. Vùng hiển thị lời chúc 60 chữ - CHỮ LỚN, RÕ NÉT, DỄ ĐỌC */
.letter-body-container {
  position: relative;
  z-index: 2;
  text-align: center;
  min-height: 135px;
  margin-bottom: 16px;
  padding: 0 8px;
}

.letter-text-message {
  font-family: var(--font-body);
  font-size: clamp(0.96rem, 1.55vw, 1.05rem);
  line-height: 1.84;
  color: #3b0918; /* Màu đỏ mận sẫm đậm nét, tương phản tối đa trên nền trắng kem */
  font-weight: 500;
  letter-spacing: 0.25px;
  display: inline;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Con trỏ máy đánh chữ */
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1.2em;
  background-color: #e11d48;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: letterCursorBlink 0.8s infinite;
}

.typing-cursor.done {
  display: none !important;
}

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

/* 4. Chữ ký ở cuối thư */
.letter-signature-container {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid rgba(226, 186, 170, 0.5);
  position: relative;
  z-index: 2;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

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

.letter-signature-content {
  font-family: var(--font-cursive);
  font-size: 1.48rem;
  font-weight: 700;
  color: #881639;
  letter-spacing: 0.5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* 5. Nút đọc lại thư */
.letter-footer-actions {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  position: relative;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.6s ease;
}

.letter-footer-actions.visible {
  opacity: 1;
}

.letter-replay-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 22px;
  background: linear-gradient(135deg, #ffffff 0%, #fff0f5 100%);
  border: 1.5px solid var(--paper-border);
  border-radius: 999px;
  color: #881639;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(136, 22, 57, 0.12);
  transition: all 0.3s ease;
}

.letter-replay-button:hover {
  background: #ffffff;
  color: #e11d48;
  border-color: #f472b6;
  transform: scale(1.05);
  box-shadow: 0 4px 18px rgba(225, 29, 72, 0.25);
}

.replay-arrow {
  font-size: 1rem;
  line-height: 1;
}

/* --------------------------------------------------------------------
   12. TƯƠNG THÍCH MỌI THIẾT BỊ (RESPONSIVE PC / TABLET / MOBILE)
   - Đảm bảo lá thư không bao giờ bị tràn, cắt chữ hay mất góc
   - Hỗ trợ cuộn bên trong lá thư trên thiết bị màn hình thấp
   -------------------------------------------------------------------- */
@media (max-width: 640px) {
  .letter-screen {
    padding: 20px 12px 30px;
    align-items: center;
  }

  .letter-scene-container {
    max-width: 100%;
    min-height: 380px;
  }

  .envelope-wrapper {
    max-width: 350px;
    height: 240px;
  }

  .envelope-wrapper.is-receded {
    transform: translateY(140px) scale(0.72);
    opacity: 0.28;
  }

  .letter-card.is-reading {
    width: min(94vw, 420px);
    max-height: min(88vh, 620px);
    padding: 26px 20px 22px;
  }

  .letter-floating-quote {
    top: 14px;
    right: 14px;
    text-align: right;
  }

  .quote-line-top {
    font-size: 1.15rem;
  }

  .quote-line-bottom {
    font-size: 1.35rem;
  }

  .letter-avatar-container {
    width: 76px;
    height: 76px;
    margin-bottom: 8px;
  }

  .letter-cursive-title {
    font-size: 1.65rem;
  }

  .letter-body-container {
    min-height: 115px;
    margin-bottom: 12px;
    padding: 0 2px;
  }

  .letter-text-message {
    font-size: 0.92rem;
    line-height: 1.72;
  }

  .letter-signature-content {
    font-size: 1.32rem;
  }

  .envelope-wax-seal {
    width: 50px;
    height: 50px;
  }

  .wax-seal-body {
    width: 46px;
    height: 46px;
  }

  .wax-rose-svg {
    width: 26px;
    height: 26px;
  }

  .sphere-action-bar {
    bottom: 20px;
  }

  .sphere-to-letter-btn {
    padding: 10px 22px;
    font-size: 0.86rem;
  }
}

@media (max-width: 380px) {
  .envelope-wrapper {
    max-width: 310px;
    height: 215px;
  }

  .envelope-wrapper.is-receded {
    transform: translateY(120px) scale(0.68);
    opacity: 0.25;
  }

  .letter-card.is-reading {
    width: 96vw;
    max-height: 90vh;
    padding: 20px 14px 18px;
  }

  .letter-avatar-container {
    width: 68px;
    height: 68px;
  }

  .letter-cursive-title {
    font-size: 1.45rem;
  }

  .letter-text-message {
    font-size: 0.86rem;
    line-height: 1.65;
  }
}

