/* ========== MÀN PHONG BÌ NÂU ========== */
.intro {
  position: fixed; inset: 0;
  z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: max(28px, env(safe-area-inset-top)) var(--gutter) max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 80% at 50% 45%, #6E1519 0%, #4A0A0D 55%, #2B0507 100%);
  color: var(--cream);
  text-align: center;
  overflow: hidden;
}
.intro::before {
  content: ""; position: absolute; inset: 0;
  background-image: var(--grain); opacity: .18; mix-blend-mode: soft-light; pointer-events: none;
}
.intro::after { /* hoa văn gấm chìm như mẫu Etsy */
  content: ""; position: absolute; inset: 0;
  background: var(--damask) center / 44px 44px;
  opacity: .1; pointer-events: none;
}
.intro > * { position: relative; z-index: 1; }

/* Ren viền mép nắp (SVG do JS tạo) */
.flap-lace { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.35)); }
.intro__top, .intro__bottom { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.intro__eyebrow { font-size: 11.5px; font-weight: 500; letter-spacing: .34em; text-transform: uppercase; color: var(--beige); }
.intro__names { font-size: clamp(42px, 12vw, 60px); color: var(--cream); }
.intro__guest { display: flex; flex-direction: column; align-items: center; }
.intro__guest-prefix { font-size: 11.5px; letter-spacing: .26em; text-transform: uppercase; color: var(--beige); }
.intro__guest-name { font-size: 34px; color: var(--cream); max-width: 92vw; overflow-wrap: anywhere; }
.intro__cta { margin-top: 10px; font-size: 11.5px; font-weight: 500; letter-spacing: .3em; text-transform: uppercase; color: var(--beige); animation: pulse 2.2s ease-in-out infinite; }
.intro__skip { margin-top: 4px; padding: 6px 12px; border: 0; background: none; cursor: pointer; font-size: 12.5px; color: var(--beige); text-decoration: underline; text-underline-offset: 3px; }
@keyframes pulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }

/* ========== PHONG BÌ ========== */
.env-stage { perspective: 1600px; width: 100%; display: flex; justify-content: center; }

.envelope {
  --w: min(88vw, 400px);
  position: relative;
  width: var(--w); height: calc(var(--w) * .68);
  padding: 0; border: 0; background: none;
  cursor: pointer;
  transform-style: preserve-3d;
  -webkit-tap-highlight-color: transparent;
}
.envelope > span { position: absolute; display: block; }
.envelope::after { /* bóng đổ dưới phong bì */
  content: ""; position: absolute; left: 6%; right: 6%; bottom: -16px; height: 30px;
  background: radial-gradient(closest-side, rgba(0,0,0,.45), transparent);
  filter: blur(6px); z-index: -1;
}

.envelope__back {
  inset: 0; border-radius: 4px;
  background: linear-gradient(#5A1014, #4A0C0F);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04);
}

/* Lá thư bên trong */
.letter {
  left: 5%; right: 5%; top: 5%; height: 90%;
  z-index: 2;
  background: var(--ivory);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(166,132,95,.35), 0 -6px 16px rgba(0,0,0,.18);
  overflow: hidden;
  will-change: transform;
}
.letter__lace { position: absolute; inset: 6px; background: var(--lace-brown) 0 0 / 16px 16px; padding: 9px;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
          mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0); opacity: .8; }
.letter__inner { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 16px; }
.letter__inner .bow { margin-bottom: 2px; width: 48px; height: 38px; }
.letter__eyebrow { font-size: 9px; font-weight: 500; letter-spacing: .32em; text-transform: uppercase; color: var(--brown); }
.letter__names { font-size: calc(var(--w) * .085); color: var(--brown); }
.letter__date { font-size: 11px; letter-spacing: .34em; color: var(--brown); }

/* Túi trước (3 nếp gấp) */
.envelope__pocket {
  inset: 0; z-index: 3;
  clip-path: polygon(0 0, 50% 52%, 100% 0, 100% 100%, 0 100%);
  background:
    linear-gradient(to top right, transparent 49.7%, rgba(0,0,0,.28) 50%, rgba(255,255,255,.05) 50.4%, transparent 51.5%) left bottom / 50% 100% no-repeat,
    linear-gradient(to top left, transparent 49.7%, rgba(0,0,0,.28) 50%, rgba(255,255,255,.05) 50.4%, transparent 51.5%) right bottom / 50% 100% no-repeat,
    var(--grain),
    linear-gradient(160deg, #7E1C21 0%, #66141A 55%, #570F13 100%);
  background-size: 50% 100%, 50% 100%, 160px 160px, auto;
}

/* Nắp phong bì (lật 3D) */
.envelope__flap {
  left: 0; right: 0; top: 0; height: 56%;
  z-index: 4;
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  will-change: transform;
}
.envelope__flap-face {
  position: absolute; inset: 0;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background:
    linear-gradient(to bottom, rgba(255,255,255,.06), transparent 30%, rgba(0,0,0,.2)),
    var(--grain),
    linear-gradient(180deg, #8A2228, #6C161B);
  background-size: auto, 160px 160px, auto;
}
.envelope__flap::before { /* bóng nắp đổ lên túi */
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 100%;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform: translateY(5px); background: rgba(0,0,0,.22); filter: blur(3px); z-index: -1;
}

/* ========== CON DẤU SÁP MÀU KEM ========== */
/* Sáp trắng ngọc, mép gợn sóng, vòng nổi, logo dập chìm (vẽ bằng SVG #seal-wax) */
.seal {
  position: absolute;
  left: 50%; top: 56%;
  z-index: 5;
  width: calc(var(--w, 330px) * .34); aspect-ratio: 1; height: auto;
  min-width: 84px;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 6px 6px rgba(0,0,0,.38)) drop-shadow(0 1px 1px rgba(0,0,0,.25));
  will-change: transform, opacity;
}
.envelope > .seal, .reply > .seal { display: block; }
.seal__wax { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
/* Logo dập chìm: lớp sáng lệch xuống + lớp tối lệch lên = hiệu ứng khắc */
.seal__logo, .seal__logo::before {
  --logo: url("/assets/img/logo-mark-bold.png");
  position: absolute; inset: 25%;
  -webkit-mask: var(--logo) center / contain no-repeat;
          mask: var(--logo) center / contain no-repeat;
}
.seal__logo { background: #957953; }
.seal__logo::before { content: ""; inset: 0; transform: translateY(1px); background: rgba(255,255,255,.9); z-index: -1; }
.seal__logo { isolation: isolate; }
.seal__text {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--font-script);
  font-size: calc(var(--w, 330px) * .062);
  line-height: 1.05;
  color: #B49B78;
  text-shadow: 0 1px 0 rgba(255,255,255,.9), 0 -1px 0 rgba(120, 92, 56, .35);
}
.has-logo .seal__text { display: none; }
body:not(.has-logo) .seal__logo { display: none; }

/* Trạng thái */
.intro.is-opening .intro__cta, .intro.is-opening .intro__skip { opacity: 0; transition: opacity .3s; animation: none; }
.intro.is-opening .envelope { cursor: default; }
.intro.flap-behind .envelope__flap { z-index: 1; }

/* Thiệp được "phóng to" qua lớp cắt hình */
.invite.is-zooming {
  position: fixed; inset: 0; z-index: 70;
  overflow: hidden;
  opacity: 1;
  will-change: clip-path, transform;
}

@media (max-height: 640px) {
  .intro__names { font-size: 38px; }
  .envelope { --w: min(80vw, 340px); }
}
@media (prefers-reduced-motion: reduce) {
  .intro__cta { animation: none; opacity: 1; }
}

/* ===================== PHONG BÌ PHẲNG 2D (2026-12-01) ===================== */
.intro { background: var(--ivory); color: var(--brown); }
.intro::before { opacity: .06; mix-blend-mode: normal; }
.intro::after { display: none; }
.intro__eyebrow, .intro__guest-prefix, .intro__cta, .intro__skip { color: var(--brown); }
.intro__names, .intro__guest-name { color: var(--brown-dark); }

.envelope svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.envelope__back { background: none; box-shadow: none; border-radius: 0; }
.envelope__pocket { clip-path: none; background: none; }
.envelope::after { background: radial-gradient(closest-side, rgba(94, 13, 16, .28), transparent); }

/* nắp: mặt ngoài đỏ rượu, mặt trong lót kem (hiện ra khi lật mở) */
.envelope__flap { height: 56%; }
.envelope__flap::before { display: none; }
.envelope__flap-face { position: absolute; inset: 0; clip-path: none; background: none; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.envelope__flap-face--in { transform: rotateX(180deg); }
.flap-lace { display: none; }
.letter { box-shadow: 0 0 0 1px rgba(94, 13, 16, .12), 0 -4px 10px rgba(60, 10, 14, .12); }
.envelope .flap-lace { display: none; }

/* Gắn lại ren vỏ sò ở mép nắp (chỉ mặt ngoài, khi lật mở sẽ ẩn cùng mặt ngoài) */
.envelope .flap-lace { display: block; position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 1.5px 1.5px rgba(40, 5, 8, .4)); }
.envelope .flap-lace--in { transform: scaleY(-1); }

/* ===== Sửa lỗi Safari / Messenger / Zalo trên iPhone =====
   Trong khối 3D (preserve-3d) Safari bỏ qua z-index và tự xếp lớp → lá thư bị vẽ đè lên túi trước.
   Chỉ giữ 3D cho riêng nắp; phần còn lại xếp lớp phẳng theo z-index như bình thường. */
.envelope { transform-style: flat; -webkit-transform-style: flat; perspective: 1600px; -webkit-perspective: 1600px; }
.envelope__flap { -webkit-transform-style: preserve-3d; }
.envelope__flap-face { -webkit-backface-visibility: hidden; backface-visibility: hidden; }
.envelope__back { z-index: 0; }
.letter { z-index: 2; }
.envelope__pocket { z-index: 3; transform: translateZ(0); }
.intro.flap-behind .envelope__flap { z-index: 1; }
.intro[hidden] { display: none !important; }
