:root {
  --c-lang: #7f9a72; --c-nha: #b8902f; --c-hen: #6f86a3; --c-bien: #c4735c;
  --season: var(--c-lang);
  --ink: #3b2f2b;
  --hud: #2e2924;
  --cream: #f7f0e3;
  --paper: url("../assets/paper.png");
  --f-ui: "Baloo 2", "Nunito", system-ui, sans-serif;
  --f-body: "Baloo 2", "Nunito", system-ui, sans-serif;
  --f-script: "Dancing Script", cursive;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: #2a2622; color: var(--ink); font-family: var(--f-body); }
body { overscroll-behavior: none; touch-action: none; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

#scene {
  position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none;
  transform-origin: 20px 50%;
  transition: transform .8s cubic-bezier(.65, 0, .35, 1), border-radius .8s cubic-bezier(.65, 0, .35, 1);
  z-index: 1;
}
.frame {
  position: fixed; inset: 0; pointer-events: none; z-index: 5;
  border: 4px dashed rgba(247, 240, 227, .82);
  background: radial-gradient(circle, transparent 68%, rgba(20, 14, 10, .42) 170%);
  transform-origin: 20px 50%;
  transition: transform .8s cubic-bezier(.65, 0, .35, 1), border-radius .8s cubic-bezier(.65, 0, .35, 1), opacity .4s;
}

/* ---------- HUD ---------- */
.hud {
  position: fixed; z-index: 10; left: 0; right: 0; top: 0;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  padding: calc(26px + var(--safe-t)) 34px 0;
  pointer-events: none;
}
.brand { color: var(--hud); text-shadow: 0 1px 0 rgba(255, 252, 245, .55), 0 0 16px rgba(255, 250, 240, .55); font-family: var(--f-ui); }
.brand b { display: block; font-size: 27px; font-weight: 700; letter-spacing: .01em; }
.brand span { display: block; font-family: var(--f-body); font-style: italic; font-size: 15px; font-weight: 500; margin-top: 2px; transition: opacity .35s; }
.pbtn {
  pointer-events: auto; font-family: var(--f-ui); font-weight: 700; font-size: 17px; color: var(--hud);
  padding: 10px 22px; border: 2px solid rgba(46, 41, 36, .55); border-radius: 999px;
  background: rgba(255, 250, 240, .55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  transition: border-color .2s, background .2s;
}
.pbtn:hover, .pbtn:focus-visible { border: 2px dashed var(--hud); background: rgba(255, 250, 240, .8); outline: none; }
.pbtn.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { background: rgba(242, 201, 76, .55); border-color: rgba(46, 41, 36, .9); } }

/* ---------- dock ---------- */
.dock {
  position: fixed; z-index: 10; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 18px; color: #fff; font-family: var(--f-ui);
  padding: 6px 14px; border-radius: 16px;
  background: rgba(46, 30, 20, .34); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 6px 18px -8px rgba(30, 18, 10, .5);
  transition: opacity .3s;
}
.dk-play { display: flex; align-items: center; gap: 6px; white-space: nowrap; font-weight: 700; font-size: 15px; padding: 6px 10px; border-radius: 10px; text-shadow: 0 1px 2px rgba(40, 25, 15, .5); }
.dk-play svg { width: 18px; height: 18px; fill: #fff; filter: drop-shadow(0 1px 1px rgba(40, 25, 15, .4)); }
.dk-play .pa { display: none; }
.dk-play[aria-pressed="true"] .pa { display: block; }
.dk-play[aria-pressed="true"] .pl { display: none; }
.dk-play:hover, .dk-play:focus-visible { outline: 2px dashed #fff; }
.zoom { display: flex; align-items: center; gap: 6px; }
.zoom button { width: 30px; height: 30px; display: grid; place-items: center; }
.zoom svg { width: 22px; height: 22px; stroke: #fff; stroke-width: 1.8; fill: none; stroke-linecap: round; filter: drop-shadow(0 1px 1px rgba(40, 25, 15, .45)); }
.zoom input { -webkit-appearance: none; appearance: none; width: 170px; height: 4px; background: #fff; outline: none; cursor: pointer; box-shadow: 0 1px 2px rgba(40, 25, 15, .35); }
.zoom input::-webkit-slider-thumb { -webkit-appearance: none; width: 8px; height: 20px; background: #fff; box-shadow: 0 1px 2px rgba(40, 25, 15, .4); }
.zoom input::-moz-range-thumb { width: 8px; height: 20px; background: #fff; border: 0; border-radius: 0; }
.dots { display: flex; gap: 4px; }
.dots button { font-weight: 700; font-size: 14px; padding: 5px 9px; border-radius: 10px; border: 2px solid transparent; text-shadow: 0 1px 2px rgba(40, 25, 15, .5); opacity: .78; }
.dots button.on { border: 2px dashed #fff; opacity: 1; }
.dots button:hover, .dots button:focus-visible { opacity: 1; outline: none; border-color: rgba(255, 255, 255, .6); }

.hint {
  position: fixed; z-index: 10; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%);
  color: #fff; font-family: var(--f-ui); font-weight: 600; font-size: 15px; white-space: nowrap;
  text-shadow: 0 1px 2px rgba(40, 25, 15, .55); pointer-events: none;
  padding: 5px 14px; border-radius: 12px; background: rgba(46, 30, 20, .3); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: hint 2.4s ease-in-out infinite; transition: opacity .6s;
}
.hint.off { opacity: 0; animation: none; }
@keyframes hint { 50% { transform: translate(-50%, -5px); } }

/* ---------- ghi chú chương (màn hình dọc) ---------- */
.note {
  position: fixed; z-index: 9; left: 50%; bottom: calc(70px + var(--safe-b));
  width: min(92vw, 420px); padding: 14px 18px 16px;
  background-color: var(--cream); background-image: var(--paper); background-blend-mode: multiply; background-size: 360px;
  border-radius: 6px; box-shadow: 0 10px 24px -10px rgba(40, 25, 15, .55), 0 2px 0 rgba(40, 25, 15, .08);
  transform: translate(-50%, 24px) rotate(-.6deg); opacity: 0; pointer-events: none;
  transition: opacity .45s, transform .45s cubic-bezier(.3, 1.4, .5, 1);
  display: none;
}
.note.on { opacity: 1; transform: translate(-50%, 0) rotate(-.6deg); pointer-events: auto; }
.note::before { content: ""; position: absolute; top: -9px; left: 50%; width: 70px; height: 20px; margin-left: -35px; background: rgba(240, 222, 180, .75); transform: rotate(2deg); box-shadow: 0 1px 2px rgba(40, 25, 15, .15); }
.note-photo { float: right; width: 96px; height: 96px; object-fit: cover; margin: -2px -4px 6px 12px; border: 5px solid #fbf8f1; border-bottom-width: 14px; box-shadow: 0 4px 10px -4px rgba(40, 25, 15, .5); transform: rotate(3deg); }
.note small { font-family: var(--f-body); font-style: italic; font-weight: 600; font-size: 13px; color: #8e3a32; letter-spacing: .02em; }
.note h2 { font-family: var(--f-ui); font-weight: 700; font-size: 21px; line-height: 1.2; margin: 2px 0 6px; }
.note p { font-size: 14.5px; line-height: 1.55; }
.note-btn { margin-top: 10px; font-family: var(--f-ui); font-weight: 700; font-size: 15px; padding: 9px 16px; border-radius: 10px; background: #b8403a; color: #fff; }

/* ---------- thiệp mời ---------- */
/* nền giấy nằm dưới cảnh 3D; hộp thiệp nằm trên (hai lớp tách nhau, cảnh thu nhỏ ở giữa) */
.panel-bg {
  position: fixed; inset: 0; z-index: 0;
  background-color: var(--season); background-image: var(--paper); background-blend-mode: multiply; background-size: 420px;
  transition: background-color .6s;
}
body.panel-open #scene { transform: scale(.6); border-radius: 32px; box-shadow: 0 30px 60px -20px rgba(30, 18, 10, .55); }
body.panel-open .frame { transform: scale(.6); border-radius: 32px; }
body.panel-open .dock, body.panel-open .hint, body.panel-open .note { opacity: 0 !important; pointer-events: none !important; }
.pn-box {
  position: fixed; z-index: 8; right: 5%; top: 50%; width: min(440px, 36vw); max-height: 92vh; overflow-y: auto;
  transform: translate(40px, -50%); opacity: 0; visibility: hidden;
  transition: transform .7s cubic-bezier(.3, 1, .4, 1) .15s, opacity .5s .15s, visibility 0s .8s;
  padding: 26px 28px 24px; color: #fff; font-family: var(--f-body);
  scrollbar-width: thin; touch-action: pan-y; overscroll-behavior: contain;
}
body.panel-open .pn-box { transform: translate(0, -50%); opacity: 1; visibility: visible; transition: transform .7s cubic-bezier(.3, 1, .4, 1) .2s, opacity .5s .2s, visibility 0s; }
.pn-photos { display: flex; gap: 10px; margin: 0 0 14px; }
.pn-photos figure { flex: 1; aspect-ratio: 1 / 1.12; background: #fbf8f1; padding: 6px 6px 18px; box-shadow: 0 8px 16px -8px rgba(30, 18, 10, .55); transform: rotate(var(--r, 0deg)); }
.pn-photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pn-kicker { font-family: var(--f-ui); font-weight: 700; font-size: 15px; letter-spacing: .14em; text-transform: uppercase; opacity: .9; }
.pn-names { font-family: var(--f-script); font-weight: 700; font-size: clamp(38px, 4.2vw, 56px); line-height: 1.02; margin: 6px 0 10px; text-shadow: 0 2px 0 rgba(40, 25, 15, .12); }
.pn-names span { display: block; }
.pn-names i { display: block; font-style: normal; font-size: .55em; opacity: .85; margin: -2px 0 -4px 1.2em; }
.pn-lead { font-size: 16px; line-height: 1.55; margin-bottom: 16px; }
.pn-date, .pn-venue { border-top: 2px dashed rgba(255, 255, 255, .55); padding: 12px 0; display: grid; gap: 3px; }
.pn-date b { font-family: var(--f-ui); font-size: 24px; font-weight: 700; }
.pn-venue b { font-family: var(--f-ui); font-size: 19px; font-weight: 700; }
.pn-count { font-family: var(--f-ui); font-weight: 600; opacity: .92; }
.pn-btns { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.pn-btn { font-family: var(--f-ui); font-weight: 700; font-size: 15px; color: #fff; text-decoration: none; padding: 8px 16px; border: 2.5px dashed rgba(255, 255, 255, .9); border-radius: 12px; }
.pn-btn:hover, .pn-btn:focus-visible { background: rgba(255, 255, 255, .16); outline: none; }
.pn-fam { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; border-top: 2px dashed rgba(255, 255, 255, .55); padding: 12px 0; font-size: 14.5px; line-height: 1.45; }
.pn-fam h3 { font-family: var(--f-ui); font-size: 15px; font-weight: 700; }
.rsvp { background-color: var(--cream); background-image: var(--paper); background-blend-mode: multiply; background-size: 360px; color: var(--ink); border-radius: 8px; padding: 16px 18px 18px; margin-top: 8px; box-shadow: 0 12px 26px -14px rgba(30, 18, 10, .6); display: grid; gap: 10px; }
.rsvp h2 { font-family: var(--f-ui); font-size: 21px; font-weight: 700; }
.f { display: grid; gap: 4px; font-size: 14px; font-weight: 600; }
.f input, .f select, .f textarea { font: 500 16px var(--f-body); color: var(--ink); background: rgba(255, 255, 255, .6); border: 2px dashed rgba(59, 47, 43, .35); border-radius: 8px; padding: 8px 10px; outline: none; resize: vertical; }
.f input:focus, .f select:focus, .f textarea:focus { border-color: #b8403a; border-style: solid; }
.f.small { max-width: 140px; }
.seg { display: grid; gap: 6px; }
.seg label { display: flex; align-items: center; gap: 8px; font-size: 15px; cursor: pointer; }
.seg input { accent-color: #b8403a; width: 18px; height: 18px; }
.pn-send { font-family: var(--f-ui); font-weight: 700; font-size: 16px; padding: 11px 18px; border-radius: 10px; background: #b8403a; color: #fff; justify-self: start; }
.pn-send:hover { background: #a3342f; }
.rsvp-ok { font-family: var(--f-ui); font-weight: 600; color: #3f6b3a; }

/* ---------- màn chờ ---------- */
.loader { position: fixed; inset: 0; z-index: 50; overflow: hidden; }
.q {
  position: absolute; width: calc(50% + 34px); height: calc(50% + 34px); filter: url(#torn);
  background-image: var(--paper); background-blend-mode: multiply; background-size: 420px;
  box-shadow: 0 2px 10px rgba(30, 18, 10, .35);
  transition: transform 1.05s cubic-bezier(.65, 0, .35, 1);
}
.q-tl { top: -22px; left: -22px; background-color: var(--c-lang); }
.q-tr { top: -22px; right: -22px; background-color: var(--c-nha); }
.q-bl { bottom: -22px; left: -22px; background-color: var(--c-bien); }
.q-br { bottom: -22px; right: -22px; background-color: var(--c-hen); }
.loader.open .q-tl { transform: translate(-105%, -105%); }
.loader.open .q-tr { transform: translate(105%, -105%); }
.loader.open .q-bl { transform: translate(-105%, 105%); }
.loader.open .q-br { transform: translate(105%, 105%); }
.loader.open .ld-mid { opacity: 0; transform: scale(.9); }
.ld-mid { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, 90vw); text-align: center; color: #fff; transition: opacity .4s, transform .5s; }
.ld-mid { transform: translate(-50%, -50%); }
.loader.open .ld-mid { transform: translate(-50%, -50%) scale(.9); }
.ld-for { font-family: var(--f-ui); font-weight: 600; font-size: 16px; margin-bottom: 6px; text-shadow: 0 1px 2px rgba(40, 25, 15, .4); min-height: 1.2em; }
.ld-title { font-family: var(--f-ui); font-weight: 700; font-style: italic; font-size: clamp(36px, 8vw, 64px); line-height: 1.05; text-shadow: 0 2px 0 rgba(40, 25, 15, .18), 0 6px 20px rgba(40, 25, 15, .25); margin-bottom: 8px; }
.ld-names { font-family: var(--f-script); font-weight: 700; font-size: clamp(24px, 4.4vw, 34px); margin-bottom: 24px; text-shadow: 0 1px 2px rgba(40, 25, 15, .35); }
.ld-bar { position: relative; height: 10px; margin: 0 auto; width: min(380px, 78vw); background: rgba(255, 255, 255, .35); border-radius: 6px; }
.ld-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 6px; transition: width .3s;
  background: repeating-linear-gradient(-45deg, #f2c94c 0 9px, #2e2924 9px 18px); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .5); }
.ld-bar b { position: absolute; top: 50%; left: 0; width: 34px; height: 34px; margin: -17px 0 0 -17px; display: grid; place-items: center; background: #fff8e8; color: #8e3a32; border-radius: 50%; font-size: 18px; box-shadow: 0 3px 8px rgba(40, 25, 15, .3); transition: left .3s; }
.ld-sub { font-family: var(--f-ui); font-weight: 600; font-size: 15px; margin-top: 18px; text-shadow: 0 1px 2px rgba(40, 25, 15, .4); }
.ld-go {
  margin-top: 18px; font-family: var(--f-ui); font-weight: 700; font-size: 20px; color: #fff;
  padding: 12px 34px; border: 3px dashed #fff; border-radius: 14px; text-shadow: 0 1px 2px rgba(40, 25, 15, .4);
  animation: pulse 1.8s ease-in-out infinite;
}
.ld-fail { position: absolute; left: 50%; bottom: 10%; transform: translateX(-50%); width: min(520px, 90vw); text-align: center; color: #fff; font-family: var(--f-ui); background: rgba(40, 25, 15, .45); padding: 12px 16px; border-radius: 10px; }

/* ---------- màn hình nhỏ ---------- */
@media (orientation: portrait) and (max-width: 1100px), (max-width: 560px) {
  .hud { padding: calc(20px + var(--safe-t)) 18px 0; }
  .brand b { font-size: 21px; }
  .brand span { font-size: 13px; }
  .pbtn { font-size: 15px; padding: 8px 14px; }
  .dock { gap: 8px; bottom: calc(12px + var(--safe-b)); width: calc(100% - 24px); justify-content: center; flex-wrap: wrap; }
  .zoom { display: none; }
  .dk-play span { display: none; }
  .note { display: block; top: calc(80px + var(--safe-t)); bottom: auto; transform: translate(-50%, -18px) rotate(-.6deg); }
  .note.on { transform: translate(-50%, 0) rotate(-.6deg); }
  .note::before { top: auto; bottom: -9px; }
  .hint { bottom: calc(64px + var(--safe-b)); font-size: 14px; }
  #scene, .frame { transform-origin: 50% 104px; }
  body.panel-open #scene, body.panel-open .frame { transform: scale(.36); }
  .pn-box { left: 0; right: 0; top: calc(118px + .36 * (100vh - 104px)); bottom: 0; width: auto; max-height: none; transform: translateY(40px); padding: 6px 20px calc(24px + var(--safe-b)); }
  body.panel-open .pn-box { transform: none; }
  .pn-names { font-size: 40px; }
  .pn-photos figure { padding: 4px 4px 12px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .hud { padding: calc(12px + var(--safe-t)) 22px 0; }
  .brand b { font-size: 19px; } .brand span { font-size: 12px; }
  .dock { bottom: calc(8px + var(--safe-b)); gap: 10px; }
  .zoom input { width: 110px; }
  .hint { bottom: 52px; }
  .pn-box { max-height: 96vh; width: min(420px, 44vw); right: 3%; }
  body.panel-open #scene, body.panel-open .frame { transform: scale(.52); }
  .note { display: block; left: auto; right: 16px; bottom: auto; top: calc(58px + var(--safe-t)); width: 300px; padding: 10px 14px 12px; transform: translateY(-14px) rotate(.5deg); }
  .note.on { transform: none; }
  .note h2 { font-size: 16px; margin-bottom: 3px; }
  .note p { font-size: 12.5px; line-height: 1.45; }
}
@media (pointer: coarse) {
  .dots button, .dk-play, .pbtn, .note-btn { min-height: 44px; min-width: 44px; }
  .zoom button { width: 44px; height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  .hint, .pbtn.pulse, .ld-go { animation: none; }
}
