/* ============================================================
   MÀN HÌNH PHONG BÌ MỞ ĐẦU (CHUNGDÔI 60FPS SMOOTH CINEMATIC OPENING)
   ============================================================ */

.envelope-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--color-wine-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: opacity;
}

.envelope-overlay.is-fading {
  opacity: 0;
  pointer-events: none;
}

.envelope-overlay.is-hidden {
  display: none !important;
}

/* 1. MƯA HẠT TRÁI TIM BAY LƯỢN TRẦM MẶC (AMBIENT PARTICLES) */
.ambient-particles-box {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.ambient-heart {
  position: absolute;
  top: -40px;
  opacity: 0.75;
  will-change: transform;
  backface-visibility: hidden;
  animation: ambientFall 22s linear infinite;
}

@keyframes ambientFall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 0.8;
  }
  90% {
    opacity: 0.7;
  }
  100% {
    transform: translate3d(var(--sway, 25px), 110vh, 0) rotate(360deg);
    opacity: 0;
  }
}

/* 2. CHÙM HẠT PHÁO HOA BUNG TỎA TỪ TÂM (PARTICLE BURST) */
.particles-burst-box {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate3d(-50%, -50%, 0);
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 100;
  overflow: visible;
}

.burst-particle {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  transform: translate3d(-50%, -50%, 0) scale(0);
  animation: particleBurst 1.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  will-change: transform, opacity;
  backface-visibility: hidden;
}

@keyframes particleBurst {
  0% {
    opacity: 0;
    transform: translate3d(-50%, -50%, 0) scale(0) rotate(0deg);
  }
  15% {
    opacity: 1;
    transform: translate3d(-50%, -50%, 0) scale(1.2) rotate(var(--rot-start, 15deg));
  }
  100% {
    opacity: 0;
    transform: translate3d(calc(-50% + var(--dx, 60px)), calc(-50% + var(--dy, -60px)), 0) scale(0.35) rotate(var(--rot-end, 180deg));
  }
}

/* 3. KHỐI KHUNG PHONG BÌ CHÍNH GIỮA (ENVELOPE WRAP) */
.envelope-wrap {
  position: relative;
  z-index: 10;
  width: 90%;
  max-width: 340px;
  margin: 0 auto;
  transform: translate3d(0, 0, 0);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform, opacity;
  backface-visibility: hidden;
}

@media (min-width: 640px) {
  .envelope-wrap {
    max-width: 420px;
  }
}

@media (min-width: 768px) {
  .envelope-wrap {
    max-width: 520px;
  }
}

@media (min-width: 1024px) {
  .envelope-wrap {
    max-width: 600px;
  }
}

/* Phản hồi tức thì mốc 0ms khi chạm mở (micro-scale nhẹ nhàng) */
.envelope-wrap.is-opening {
  transform: translate3d(0, -4px, 0) scale(1.015);
}

/* Hiệu ứng thiệp bay vút lên trên (envelope-away) với gia tốc tự nhiên mượt mà */
.envelope-wrap.is-away {
  animation: envelopeAway 0.85s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes envelopeAway {
  0% {
    transform: translate3d(0, -4px, 0) scale(1.015) rotate(0deg);
    opacity: 1;
  }
  14% {
    transform: translate3d(0, 8px, 0) scale(1.01) rotate(0.4deg);
    opacity: 1;
  }
  100% {
    transform: translate3d(0, -125vh, 0) scale(0.98) rotate(-2.2deg);
    opacity: 0;
  }
}

/* 4. CON DẤU SÁP ĐỎ VÀ VÒNG SÓNG XUNG KÍCH (WAX SEAL & SEAL RING) */
.wax-seal-btn {
  position: absolute;
  top: 48px;
  left: 50%;
  transform: translate3d(-50%, -50%, 0);
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #7a1f26, #32070b);
  box-shadow: 0 4px 20px rgba(81, 20, 25, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  cursor: pointer;
  border: none;
  padding: 0;
  animation: sealPulse 2.2s ease-in-out infinite;
  transition: transform 0.2s ease;
  will-change: transform, opacity;
  backface-visibility: hidden;
}

.wax-seal-btn:hover {
  transform: translate3d(-50%, -50%, 0) scale(1.08);
}

.wax-seal-icon {
  width: 28px;
  height: 28px;
  fill: var(--color-cream);
  pointer-events: none;
}

@keyframes sealPulse {
  0%, 100% {
    transform: translate3d(-50%, -50%, 0) scale(1);
    box-shadow: 0 4px 20px rgba(81, 20, 25, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.3);
  }
  50% {
    transform: translate3d(-50%, -50%, 0) scale(1.06);
    box-shadow: 0 6px 32px rgba(201, 162, 74, 0.65), inset 0 2px 6px rgba(255, 255, 255, 0.5);
  }
}

/* Con dấu sáp vỡ tan mượt mà trong 0.35s */
.is-opening .wax-seal-btn {
  animation: sealBreak 0.38s cubic-bezier(0.4, 0, 0.2, 1) forwards !important;
  pointer-events: none;
}

@keyframes sealBreak {
  0% {
    transform: translate3d(-50%, -50%, 0) scale(1) rotate(0deg);
    opacity: 1;
  }
  30% {
    transform: translate3d(-50%, -50%, 0) scale(1.16) rotate(5deg);
    opacity: 0.95;
  }
  65% {
    transform: translate3d(-50%, -50%, 0) scale(1.02) rotate(-3deg);
    opacity: 0.5;
  }
  100% {
    transform: translate3d(-50%, -50%, 0) scale(0) rotate(16deg);
    opacity: 0;
  }
}

/* Vòng sóng xung kích từ con dấu */
.seal-ring {
  position: absolute;
  top: 48px;
  left: 50%;
  transform: translate3d(-50%, -50%, 0) scale(0.8);
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 2.5px solid var(--color-gold);
  z-index: 29;
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
  backface-visibility: hidden;
}

.is-opening .seal-ring {
  animation: sealRing 0.55s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes sealRing {
  0% {
    transform: translate3d(-50%, -50%, 0) scale(0.8);
    opacity: 0.9;
    border-color: var(--color-gold);
  }
  100% {
    transform: translate3d(-50%, -50%, 0) scale(2.5);
    opacity: 0;
    border-color: rgba(201, 162, 74, 0);
  }
}

/* 5. TẤM THIỆP TRẮNG KEM TRONG PHONG BÌ */
.envelope-card {
  position: relative;
  background: var(--color-card-bg);
  border: 1px solid var(--color-card-border);
  border-radius: 12px;
  box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.45), 0 8px 24px rgba(0, 0, 0, 0.2), 0 0 40px rgba(201, 162, 74, 0.15);
  overflow: hidden;
  text-align: center;
  padding: 85px 24px 38px;
  will-change: transform;
}

/* Ánh sáng vàng dịu bừng sáng trên mặt thiệp khi mở */
.envelope-card-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 12px;
  background: radial-gradient(ellipse at center top, rgba(201, 162, 74, 0.28) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.35s ease;
  z-index: 1;
  will-change: opacity;
}

.is-opening .envelope-card-glow {
  opacity: 1;
}

/* 6. HOA MẪU ĐƠN 2 GÓC & LỚP BAY LAO VỀ MÀN HÌNH (FLY-ON-OPEN) */
.envelope-peony-corner {
  position: absolute;
  pointer-events: none;
  width: 140px;
  height: auto;
  opacity: 0.85;
  z-index: 2;
  filter: drop-shadow(2px 3px 5px rgba(0, 0, 0, 0.15));
}

.peony-top-left {
  top: -12px;
  left: -18px;
  transform: rotate(25deg);
}

.peony-bottom-right {
  bottom: -15px;
  right: -18px;
  transform: scaleX(-1) rotate(-25deg);
}

@media (min-width: 640px) {
  .envelope-peony-corner {
    width: 170px;
  }
}

/* Lớp hoa mẫu đơn bay về phía trước (dragon-fly-forward) - GPU Composited (No filter:blur) */
.flying-peonies-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 25;
  display: none;
}

.is-opening .flying-peonies-layer {
  display: block;
}

.peony-flying {
  position: absolute;
  pointer-events: none;
  width: 150px;
  height: auto;
  opacity: 0.85;
  will-change: transform, opacity;
  backface-visibility: hidden;
}

.peony-flying.fly-top-left {
  top: -12px;
  left: -18px;
  transform-origin: top left;
  --fly-scale-x: 1;
}

.peony-flying.fly-bottom-right {
  bottom: -15px;
  right: -18px;
  transform-origin: bottom right;
  --fly-scale-x: -1;
}

.is-opening .peony-flying.fly-top-left,
.is-opening .peony-flying.fly-bottom-right {
  animation: dragonFlyForward 1.1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes dragonFlyForward {
  0% {
    transform: translate3d(0, 0, 0) scale(var(--fly-scale-x, 1), 1) rotate(0deg);
    opacity: 0.85;
  }
  35% {
    transform: translate3d(0, 0, 0) scale(calc(var(--fly-scale-x, 1) * 1.55), 1.55) rotate(4deg);
    opacity: 0.65;
  }
  100% {
    transform: translate3d(0, 0, 0) scale(calc(var(--fly-scale-x, 1) * 2.85), 2.85) rotate(8deg);
    opacity: 0;
  }
}

@media (min-width: 640px) {
  .peony-flying {
    width: 180px;
  }
}

@media (min-width: 768px) {
  .envelope-card {
    padding: 95px 40px 46px;
  }
  .envelope-peony-corner {
    width: 200px;
  }
  .peony-top-left {
    top: -20px;
    left: -24px;
  }
  .peony-bottom-right {
    bottom: -20px;
    right: -24px;
  }
  .peony-flying {
    width: 210px;
  }
  .peony-flying.fly-top-left {
    top: -20px;
    left: -24px;
  }
  .peony-flying.fly-bottom-right {
    bottom: -20px;
    right: -24px;
  }
}

/* 7. NỘI DUNG CHỮ TRÊN THIỆP */
.envelope-content {
  position: relative;
  z-index: 10;
}

.envelope-couple-names {
  font-family: var(--font-couple);
  color: var(--color-primary);
  font-size: clamp(28px, 6vw, 36px);
  line-height: 1.2;
  margin-bottom: 8px;
}

.envelope-ampersand {
  font-family: var(--font-body);
  display: block;
  font-size: 20px;
  line-height: 1;
  color: var(--color-primary);
  margin: 2px 0;
}

.envelope-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 10px 0 14px;
}

.envelope-divider-line {
  width: 45px;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--color-primary));
}

.envelope-divider-line.to-left {
  background: linear-gradient(to left, transparent, var(--color-primary));
}

.envelope-divider-glyph {
  color: var(--color-primary);
  opacity: 0.75;
  font-size: 15px;
}

.envelope-date {
  font-family: var(--font-content);
  color: var(--color-text-sub);
  font-size: 16px;
  margin-bottom: 12px;
  letter-spacing: 0.04em;
}

.envelope-subtext {
  font-family: var(--font-content);
  color: var(--color-text-sub);
  font-size: 17px;
  font-weight: 300;
  margin-bottom: 22px;
  letter-spacing: 0.08em;
}

/* 8. NÚT MỞ THIỆP TỎA SÁNG */
.btn-open-envelope {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 36px;
  background-color: var(--color-primary);
  color: #f3e8de;
  font-family: var(--font-content);
  font-size: 17px;
  font-weight: 600;
  border-radius: var(--radius-btn);
  box-shadow: 0 4px 16px rgba(81, 20, 25, 0.4);
  border: none;
  cursor: pointer;
  overflow: hidden;
  text-decoration: none;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  will-change: transform;
}

.btn-open-envelope:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(81, 20, 25, 0.55);
}

.btn-shine-bar {
  position: absolute;
  top: 0;
  left: 0;
  width: 32px;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  pointer-events: none;
  animation: btnShine 2.8s ease-in-out infinite;
}

@keyframes btnShine {
  0% { transform: translateX(-150%); }
  50%, 100% { transform: translateX(450%); }
}

/* 9. TƯƠNG THÍCH PREFERS-REDUCED-MOTION */
@media (prefers-reduced-motion: reduce) {
  .wax-seal-btn,
  .btn-shine-bar,
  .ambient-heart,
  .seal-ring,
  .peony-flying,
  .burst-particle {
    animation: none !important;
  }
  .envelope-wrap.is-away {
    animation: none !important;
    opacity: 0 !important;
  }
  .envelope-overlay.is-fading {
    opacity: 0 !important;
    transition: opacity 0.3s ease !important;
  }
}
