:root {
  --wall: #e0e4ff;
  --paper: #f6f5ff;
  --ink: #2a1a55;
  --ink-soft: #5b4d86;
  --plum: #3c1a70;
  --pink: #b5176a;
  --hot: #d8298e;
  --amber: #f5b23e;
  --radius: 14px;
  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --serif: 'Newsreader', Georgia, serif;
  --gutter: clamp(16px, 4vw, 40px);
  /* Ảnh nền của 3 thẻ (assets/cards). Thay file cùng tên là đổi được, không cần sửa ở đây. */
  --card-thanks: url(assets/cards/thanks.webp);
  --card-invite: url(assets/cards/invite.webp);
  --card-ticket: url(assets/cards/ticket.webp);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--wall); -webkit-text-size-adjust: 100%; }
body { margin: 0; color: var(--ink); font-family: var(--display); }
h1, h2, p, dl, dd { margin: 0; }
a { color: inherit; }

/* ---------- Hành lang ---------- */
#scene { position: fixed; inset: 0; overflow: hidden; background: var(--wall); }
#lines, #surfaces { position: absolute; inset: 0; width: 100%; height: 100%; }
#stage { position: absolute; inset: 0; }
#world, .ring { position: absolute; left: 50%; top: 50%; width: 0; height: 0; transform-style: preserve-3d; }
.ring { left: 0; top: 0; display: none; }
.ring.show { display: block; }
.tile {
  position: absolute;
  border-radius: 12px;
  background-size: cover;
  background-position: center 30%;
  backface-visibility: hidden;
  overflow: hidden;
}
.tile b { position: absolute; inset: 0; border-radius: inherit; background-size: cover; background-position: center 30%; }
#glow {
  position: absolute; inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 39% 44% at 50% 50%, #fff 0, rgba(255, 255, 255, .97) 30%, rgba(255, 255, 255, .6) 62%, rgba(255, 255, 255, 0) 100%);
  transform-origin: center;
}

/* Khung ký ức: treo lơ lửng, quay mặt về phía người xem */
.memory {
  position: absolute;
  margin: 0;
  padding: 10px 10px 12px;
  background: var(--paper);
  border-radius: 10px;
  box-shadow: 0 18px 40px -18px rgba(42, 26, 85, .55);
  font-family: var(--display);
}
.memory::before {
  content: '';
  position: absolute; left: 50%; bottom: 100%;
  width: 1px; height: 200vh;
  background: rgba(60, 26, 112, .28);
}
.memory-pic { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; }
div.memory-pic { background: linear-gradient(135deg, #6736c9, #d8298e); } /* khung ký ức chưa có ảnh */
.memory figcaption { padding: 10px 4px 0; }
.memory b { display: block; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--pink); }
.memory span { display: block; margin-top: 2px; font: italic 400 19px/1.25 var(--serif); }

/* ---------- Các phòng ---------- */
.room {
  position: relative;
  min-height: 100vh; min-height: 100svh;
  display: grid; place-items: center;
  padding: max(var(--gutter), env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) max(var(--gutter), env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
}
.immersive .room {
  position: fixed; inset: 0;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr); /* giữ thẻ cao hơn màn hình ở chính giữa để thu nhỏ không bị lệch */
  opacity: 0;
  pointer-events: none;
  z-index: 2;
}
.immersive .room.on { pointer-events: auto; }
.immersive .card { will-change: transform; }

.eyebrow { font-size: 13px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }

/* Lối vào */
.hero-card { text-align: center; max-width: min(860px, 100%); }
.hero-card .eyebrow { color: var(--pink); }
h1 {
  margin: 14px 0 12px;
  font-size: clamp(44px, min(10vw, 17vh), 112px);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -.02em;
  color: var(--plum);
  text-wrap: balance;
}
.cue { display: inline-flex; flex-direction: column; align-items: center; gap: 10px; margin-top: clamp(24px, 6vh, 56px); font-size: 14px; font-weight: 500; color: var(--ink-soft); }
.cue i { width: 1px; height: 44px; background: linear-gradient(var(--hot), transparent); animation: cue 1.9s ease-in-out infinite; transform-origin: top; }
@keyframes cue { 0% { transform: scaleY(0); } 55% { transform: scaleY(1); } 100% { transform: scaleY(1); opacity: 0; } }

/* Phòng 01 */
.thanks-card {
  display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  width: min(960px, 100%);
  background: var(--paper);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 40px 80px -40px rgba(42, 26, 85, .6);
}
.thanks-art {
  display: flex; flex-direction: column; justify-content: space-between;
  min-height: 400px;
  padding: 24px;
  color: #fff;
  /* Ảnh nền + lớp tối dần xuống dưới để chữ trắng luôn đọc được, dù ảnh sáng hay tối */
  background: linear-gradient(rgba(60, 26, 112, .12), rgba(60, 26, 112, .55)), var(--card-thanks) center / cover, #4a2183;
}
.thanks-art h2 { font-size: clamp(44px, 6vw, 72px); font-weight: 800; line-height: 1; letter-spacing: -.02em; }
.letter { align-self: center; padding: clamp(24px, 4vw, 48px); font: 400 clamp(17px, 1.6vw, 20px)/1.55 var(--serif); }
.letter p + p { margin-top: .8em; }
.salute { font-family: var(--display); font-weight: 700; font-size: 18px; color: var(--pink); margin-bottom: .8em; }
.sign { margin-top: .8em; font-style: italic; color: var(--ink-soft); }

/* Phòng 02 */
.poster {
  display: flex; flex-direction: column; justify-content: flex-end;
  width: min(1000px, 100%);
  min-height: min(640px, calc(100vh - 2 * var(--gutter)));
  padding: clamp(24px, 4vw, 48px);
  border-radius: var(--radius);
  color: #fff;
  /* Ảnh nền + lớp tím đậm ở nửa dưới, nơi có chữ */
  background: linear-gradient(rgba(60, 26, 112, 0) 18%, rgba(46, 18, 92, .94) 62%), var(--card-invite) center / cover, #4f1f8a;
  box-shadow: 0 40px 80px -40px rgba(42, 26, 85, .75);
}
.poster .eyebrow { margin-bottom: auto; }
.poster h2 { font-size: clamp(36px, min(6.4vw, 11vh), 76px); font-weight: 800; line-height: 1.05; letter-spacing: -.02em; text-wrap: balance; }
.poster-line { margin-top: 14px; max-width: 40em; font: italic 400 clamp(18px, 2vw, 22px)/1.4 var(--serif); }
.poster-date { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; margin-top: 20px; padding-top: 16px; border-top: 1px solid rgba(255, 255, 255, .35); font-size: clamp(16px, 1.8vw, 20px); }
.poster-date span { color: var(--amber); font-weight: 700; }

/* Phòng 03: vé */
.ticket {
  display: grid; grid-template-columns: minmax(0, 1fr) 248px;
  width: min(960px, 100%);
  filter: drop-shadow(0 24px 34px rgba(42, 26, 85, .32));
}
/* Hai lỗ khuyết nửa tròn ở đường xé của vé. Mỗi phần chỉ cần khai báo vị trí hai lỗ
   (--notch-a, --notch-b) và cách chia đôi mặt nạ: trên/dưới hay trái/phải. */
.ticket-main, .kept, .stub {
  --n: 13px;
  --notch-mask:
    radial-gradient(circle var(--n) at var(--notch-a), #0000 98%, #000) var(--notch-a-side) / var(--notch-half) no-repeat,
    radial-gradient(circle var(--n) at var(--notch-b), #0000 98%, #000) var(--notch-b-side) / var(--notch-half) no-repeat;
  -webkit-mask: var(--notch-mask);
  mask: var(--notch-mask);
}
/* Lỗ nằm ở hai góc của một cạnh dọc: chia mặt nạ thành nửa trên, nửa dưới. */
.ticket-main, .kept, .stub { --notch-a-side: top; --notch-b-side: bottom; --notch-half: 100% 51%; }
.ticket-main { --notch-a: 100% 0; --notch-b: 100% 100%; }
.kept, .stub { --notch-a: 0 0; --notch-b: 0 100%; }

.ticket-main {
  padding: clamp(20px, 3.4vw, 40px);
  background: var(--paper);
  border-radius: var(--radius);
}
.ticket-main .eyebrow { color: var(--pink); }
.ticket h2 { margin-top: 8px; font-size: clamp(30px, min(4.6vw, 8vh), 50px); font-weight: 800; line-height: 1.05; letter-spacing: -.02em; }
.ticket-sub { margin-top: 4px; font: italic 400 18px/1.35 var(--serif); color: var(--ink-soft); }
dl { margin-top: clamp(12px, 2.4vh, 22px); }
dl div { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; padding: 7px 0; border-top: 1px solid #d9d8ef; }
dt { font-size: 13px; font-weight: 700; color: var(--ink-soft); line-height: 1.5; }
dd { font-size: 16px; font-weight: 500; line-height: 1.35; }
dd small { display: block; font-size: 14px; font-weight: 500; color: var(--ink-soft); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px;
  border: 1.5px solid var(--plum); border-radius: 10px;
  font-size: 15px; font-weight: 700; color: var(--plum); text-decoration: none;
  transition: background .15s, color .15s;
}
.btn:hover { background: var(--plum); color: #fff; }
.btn-solid { background: var(--amber); border-color: var(--amber); color: var(--ink); }
.btn-solid:hover { background: #fff; border-color: #fff; color: var(--ink); }
#d-phone { display: inline-block; padding: 7px 0; margin: -7px 0; }
:focus-visible { outline: 3px solid var(--hot); outline-offset: 2px; }

.stub-slot { position: relative; display: grid; }
.kept, .stub { grid-area: 1 / 1; border-radius: var(--radius); }
.kept {
  display: flex; flex-direction: column; justify-content: center; align-items: stretch; gap: 10px;
  padding: 20px;
  color: #fff; background: var(--plum);
  visibility: hidden; /* hiện ra khi cuống vé đã xé */
}
.is-kept .kept { visibility: visible; }
.kept-title { font-size: 24px; font-weight: 800; line-height: 1.15; }
.undo { align-self: center; padding: 8px; border: 0; background: none; color: #d9cff5; font: 500 14px var(--display); text-decoration: underline; cursor: pointer; }
.stub {
  position: relative;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 8px;
  padding: 20px 16px 24px;
  border: 0; border-left: 2px dashed rgba(255, 255, 255, .7);
  color: #fff; text-align: center;
  font-family: var(--display);
  /* Ảnh ở nửa trên, chuyển dần sang tím đậm ở nửa dưới, nơi có chữ và nút */
  background: linear-gradient(rgba(46, 26, 92, 0) 30%, rgba(46, 26, 92, .85) 52%, #2e1a5c 64%), var(--card-ticket) center top / cover, #2e1a5c;
  cursor: grab;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  transform-origin: 0 100%;
  transition: transform .35s cubic-bezier(.3, 1.4, .5, 1);
}
.stub:active { cursor: grabbing; }
.stub.dragging { transition: none; }
.stub-label { font-size: 13px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.stub-date { font-size: 46px; font-weight: 800; line-height: 1; letter-spacing: -.02em; }
.stub-cta { margin-top: 6px; padding: 10px 16px; border-radius: 10px; background: #fff; color: var(--ink); font-size: 16px; font-weight: 800; }
.stub-hint { font-size: 13px; font-weight: 500; }
.stub.torn { pointer-events: none; visibility: hidden; transition: transform .6s cubic-bezier(.5, 0, .9, .5), visibility 0s .6s; transform: translate(70px, 120vh) rotate(38deg); }

/* ---------- Biển chỉ dẫn ---------- */
#wayfinder {
  position: fixed; z-index: 3;
  right: env(safe-area-inset-right); top: 50%; transform: translateY(-50%);
  display: none; flex-direction: column;
  background: rgba(246, 245, 255, .86);
  border-radius: 10px 0 0 10px;
}
.immersive #wayfinder { display: flex; }
#wayfinder button {
  position: relative;
  display: flex; align-items: center; justify-content: flex-end;
  width: 44px; min-height: 44px; padding: 0 8px;
  border: 0; background: none;
  color: var(--ink); font: 700 13px var(--display);
  cursor: pointer;
}
#wayfinder i { width: 14px; height: 2px; background: var(--ink); opacity: .4; transition: width .25s, opacity .25s, background .25s; }
#wayfinder span { position: absolute; right: 100%; margin-right: 6px; white-space: nowrap; pointer-events: none; opacity: 0; transform: translateX(6px); transition: opacity .2s, transform .2s; padding: 4px 8px; border-radius: 6px; background: var(--paper); }
#wayfinder button:hover span, #wayfinder button:focus-visible span { opacity: 1; transform: none; }
#wayfinder [aria-current] i { width: 26px; opacity: 1; background: var(--hot); }

#track { display: none; }
.immersive #track { display: block; height: 1000vh; height: 1000lvh; }
#confetti { position: fixed; inset: 0; z-index: 4; width: 100%; height: 100%; pointer-events: none; }

/* ---------- Màn hình hẹp ---------- */
@media (max-width: 720px), (max-height: 480px) {
  #wayfinder { background: none; pointer-events: none; }
  #wayfinder button { width: 14px; min-height: 24px; padding: 0 1px; }
  #wayfinder span { display: none; }
  #wayfinder i { width: 7px; opacity: .75; background: #fff; box-shadow: 0 0 0 1px rgba(42, 26, 85, .5); }
  #wayfinder [aria-current] i { width: 12px; }
}

/* Bố cục xếp chồng. Giữ khớp với App.STACKED_LAYOUT trong js/core.js */
@media (max-width: 720px) and (min-height: 481px), (max-width: 480px) {
  #glow { background: radial-gradient(ellipse 72% 34% at 50% 50%, #fff 0, rgba(255, 255, 255, .97) 40%, rgba(255, 255, 255, .6) 68%, rgba(255, 255, 255, 0) 100%); }

  .thanks-card { grid-template-columns: 1fr; }
  .thanks-art { min-height: 0; gap: 28px; padding: 18px 20px; }
  .thanks-art h2 { font-size: 44px; }
  .letter { padding: 18px 20px 20px; font-size: 17px; line-height: 1.45; }
  .salute { font-size: 16px; }
  .poster { min-height: min(600px, calc(100vh - 2 * var(--gutter))); }

  .ticket { grid-template-columns: 1fr; }
  /* Cuống vé nằm dưới: lỗ ở hai góc của cạnh ngang, chia mặt nạ thành nửa trái, nửa phải. */
  .ticket-main, .kept, .stub { --notch-a-side: left; --notch-b-side: right; --notch-half: 51% 100%; }
  .ticket-main { --notch-a: 0 100%; --notch-b: 100% 100%; padding: 16px 18px; }
  .kept, .stub { --notch-a: 0 0; --notch-b: 100% 0; }
  .ticket h2 { font-size: 28px; }
  .ticket-sub { font-size: 16px; }
  dl { margin-top: 8px; }
  dl div { grid-template-columns: 76px minmax(0, 1fr); gap: 8px; padding: 5px 0; }
  dt { font-size: 12px; }
  dd { font-size: 14px; }
  dd small { font-size: 13px; }
  .actions { margin-top: 8px; }
  .actions .btn { flex: 1; padding: 0 8px; }
  .stub { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; padding: 12px 18px; background: linear-gradient(100deg, rgba(122, 31, 110, .55), rgba(46, 26, 92, .9) 65%), var(--card-ticket) center / cover, #2e1a5c; border-left: 0; border-top: 2px dashed rgba(255, 255, 255, .7); text-align: left; transform-origin: 100% 0; }
  .stub-label { grid-column: 1; font-size: 11px; }
  .stub-date { grid-column: 1; grid-row: 2; font-size: 30px; }
  .stub-cta { grid-column: 2; grid-row: 1 / 3; align-self: center; justify-self: end; margin: 0; }
  .stub-hint { grid-column: 1 / -1; font-size: 12px; }
  .kept { padding: 12px 18px; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
  .kept-title { width: 100%; font-size: 19px; }
  .kept .btn { flex: 1; }
}

/* Điện thoại đứng nhưng thấp, nhất là khi thanh địa chỉ đang hiện */
@media (max-height: 600px) and (max-width: 480px) {
  .thanks-art { gap: 12px; padding: 12px 18px; }
  .thanks-art h2 { font-size: 34px; }
  .letter { padding: 12px 18px 14px; font-size: 16px; line-height: 1.4; }
  .ticket-main { padding: 12px 16px; }
  .ticket h2 { font-size: 24px; }
  .ticket-sub { font-size: 14px; }
  dl div { padding: 3px 0; }
  .stub-hint { display: none; }
  .stub { padding: 8px 16px; }
  .stub-date { font-size: 24px; }
}

@media (max-height: 640px) and (min-width: 721px) {
  .thanks-art { min-height: 280px; }
  .letter { font-size: 16px; line-height: 1.4; padding: 20px 28px; }
  dl div { padding: 4px 0; }
}

/* Điện thoại xoay ngang: giữ hai cột, thu gọn để vừa chiều cao thấp */
@media (max-height: 480px) and (min-width: 481px) {
  :root { --gutter: 12px; }
  .eyebrow { font-size: 11px; }
  h1 { margin: 6px 0; font-size: clamp(36px, 17vh, 64px); }
  .cue { margin-top: 10px; gap: 4px; font-size: 13px; }
  .cue i { height: 22px; }

  .thanks-card { grid-template-columns: minmax(0, 3fr) minmax(0, 8fr); }
  .thanks-art { min-height: 0; padding: 14px; }
  .thanks-art h2 { font-size: clamp(26px, 5vw, 38px); }
  .letter { padding: 12px 18px; font-size: 15px; line-height: 1.35; }
  .salute { font-size: 14px; margin-bottom: .4em; }
  .letter p + p, .sign { margin-top: .45em; }

  .poster { min-height: calc(100vh - 2 * var(--gutter)); padding: 14px 20px; }
  .poster h2 { font-size: clamp(24px, 9vh, 36px); }
  .poster-line { margin-top: 6px; font-size: 15px; line-height: 1.3; }
  .poster-date { margin-top: 8px; padding-top: 8px; font-size: 14px; }

  .ticket { grid-template-columns: minmax(0, 1fr) 150px; }
  .ticket-main { padding: 10px 16px; }
  .ticket h2 { margin-top: 2px; font-size: 22px; }
  .ticket-sub { margin-top: 0; font-size: 14px; }
  dl { margin-top: 5px; }
  dl div { grid-template-columns: 64px minmax(0, 1fr); gap: 8px; padding: 2px 0; }
  dt { font-size: 11px; }
  dd { font-size: 13px; line-height: 1.25; }
  dd small { display: inline; margin-left: 6px; font-size: 12px; }
  .actions { margin-top: 5px; }
  .btn { min-height: 36px; padding: 0 12px; font-size: 13px; }
  .kept, .stub { padding: 10px; }
  .stub { justify-content: center; gap: 4px; background: linear-gradient(160deg, rgba(122, 31, 110, .55), rgba(46, 26, 92, .9) 70%), var(--card-ticket) center / cover, #2e1a5c; }
  .stub-label { font-size: 10px; }
  .stub-date { font-size: 26px; }
  .stub-cta { margin-top: 2px; padding: 7px 10px; font-size: 13px; }
  .stub-hint { font-size: 11px; line-height: 1.2; }
  .kept-title { font-size: 16px; }
  .undo { padding: 4px; font-size: 13px; }
}

/* Giảm chuyển động: bỏ bay camera, các phòng xếp thành trang bình thường */
html.static #glow { background: rgba(255, 255, 255, .6); }
@media (prefers-reduced-motion: reduce) {
  .cue i { animation: none; }
  .stub, .stub.torn { transition: none; }
}
