:root {
  --bg: #140d0b;
  --ink: #2b1b14;
  --paper: #f4ead7;
  --paper-tex: none;
  --brass: #d3aa5c;
  --brass-hi: #f4dc9e;
  --brass-lo: #8a6524;
  --red: #8c2226;
  --red-hi: #b8302b;
  --cream: #f6eedf;
  --muted: rgba(246, 238, 223, 0.72);
  --script: 'Dancing Script', 'Segoe Script', cursive;
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--cream); font-family: var(--serif); -webkit-text-size-adjust: 100%; }
body { overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------ màn chờ */
.loader {
  position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: radial-gradient(60% 50% at 50% 45%, #2a1a12, var(--bg));
  transition: opacity .8s ease, visibility .8s;
}
.is-ready .loader { opacity: 0; visibility: hidden; }
[data-test] .loader { display: none; }
.ld-key { width: 74px; height: 74px; color: var(--brass); --hole: #22150f; animation: ldspin 2.4s cubic-bezier(.5,0,.5,1) infinite; transform-origin: 50% 40%; }
@keyframes ldspin { to { transform: rotate(360deg); } }
.ld-t { margin: 0; font-family: var(--script); font-size: 26px; color: var(--brass-hi); }
.ld-bar { width: 160px; height: 2px; background: rgba(211,170,92,.2); border-radius: 2px; overflow: hidden; }
.ld-bar i { display: block; height: 100%; width: calc(var(--p, 0) * 100%); background: var(--brass); transition: width .4s ease; }

/* ------------------------------------------------ sân khấu 3D */
.stage { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
.stage canvas:active { cursor: grabbing; }
.vignette {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(10,6,5,.55) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .4 0 0 0 0 .3 0 0 0 .5 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light; opacity: .55;
}
.fail { position: absolute; inset: auto 20px 45%; text-align: center; font-size: 20px; color: var(--cream); }

/* ------------------------------------------------ thanh trên */
.hud {
  position: absolute; z-index: 5; top: calc(14px + var(--safe-t)); left: calc(16px + var(--safe-l)); right: calc(16px + var(--safe-r));
  display: flex; align-items: center; justify-content: space-between; gap: 12px; pointer-events: none;
}
.hud > * { pointer-events: auto; }
.brand { font-family: var(--script); font-weight: 600; font-size: 24px; color: var(--cream); text-decoration: none; line-height: 1; text-shadow: 0 1px 8px rgba(0,0,0,.5); display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.brand i { color: var(--brass); font-style: normal; }
.brand b { font-family: var(--serif); font-weight: 600; font-size: 13px; letter-spacing: .14em; color: var(--muted); margin-left: 6px; }
.hud-btns { display: flex; gap: 8px; }
.hb {
  display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 14px 0 11px; border-radius: 99px; cursor: pointer;
  border: 1px solid rgba(211,170,92,.35); background: rgba(24,15,12,.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  font-size: 15px; font-weight: 600; letter-spacing: .02em; color: var(--cream); transition: background .2s, border-color .2s;
}
.hb svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.hb[data-auto] svg { fill: currentColor; stroke: none; }
.hb[data-sound][aria-pressed="false"] .w { display: none; }
.hb[aria-pressed="true"][data-auto] { background: rgba(211,170,92,.25); border-color: var(--brass); }
.hb:hover { border-color: var(--brass); }
.hb.strong { background: linear-gradient(180deg, #e2bd70, #b58a3e); color: #2a1a10; border-color: #f0d38f; }
.hb:focus-visible, .wind:focus-visible, .btn:focus-visible, .open-card:focus-visible { outline: 2px solid var(--brass-hi); outline-offset: 3px; }

/* ------------------------------------------------ chấm chương */
.dots { position: absolute; z-index: 4; top: calc(66px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; gap: 18px; margin: 0; padding: 0; list-style: none; pointer-events: none; opacity: 0; transition: opacity .6s; }
.lid-open .dots { opacity: 1; }
[data-phase="finale"] .dots, .invite-open .dots { opacity: 0; }
.dots li { position: relative; width: 44px; text-align: center; font-size: 13px; font-weight: 600; letter-spacing: .08em; color: rgba(246,238,223,.5); padding-bottom: 7px; }
.dots li::before, .dots li::after { content: ''; position: absolute; left: 0; bottom: 0; height: 2px; border-radius: 2px; }
.dots li::before { right: 0; background: rgba(246,238,223,.2); }
.dots li::after { width: calc(var(--p, 0) * 100%); background: var(--brass); }
.dots li.on { color: var(--brass-hi); }

/* ------------------------------------------------ nút lên dây */
.dock { position: absolute; z-index: 5; left: 0; right: 0; bottom: calc(18px + var(--safe-b)); display: grid; justify-items: center; gap: 10px; pointer-events: none; }
.dock > * { pointer-events: auto; }
.hint {
  margin: 0; min-height: 30px; padding: 5px 14px; border-radius: 99px; font-size: 17px; font-weight: 600; letter-spacing: .02em;
  background: rgba(24,15,12,.5); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); color: var(--cream);
  opacity: 0; transform: translateY(6px); transition: opacity .4s, transform .4s; pointer-events: none; text-align: center; max-width: calc(100vw - 32px);
}
.hint.show { opacity: 1; transform: none; }
.wind {
  position: relative; width: 84px; height: 84px; border-radius: 50%; border: 0; padding: 0; cursor: pointer; touch-action: none;
  background: radial-gradient(circle at 35% 30%, #f5dc9c, #cfa556 45%, #8a6524 100%);
  box-shadow: 0 8px 24px rgba(0,0,0,.45), inset 0 -3px 6px rgba(80,50,10,.5), inset 0 2px 3px rgba(255,240,200,.6);
  transition: transform .15s ease, box-shadow .2s;
}
.wind.down { transform: scale(.95); }
.wind .ring { position: absolute; inset: -9px; width: calc(100% + 18px); height: calc(100% + 18px); transform: rotate(-90deg); pointer-events: none; }
.wind .ring circle { fill: none; stroke-width: 3.5; }
.wind .ring .trk { stroke: rgba(246,238,223,.18); }
.wind .ring .val { stroke: var(--brass-hi); stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: calc(1 - var(--p, 0)); transition: stroke-dashoffset .1s linear; }
.wind .key { position: absolute; inset: 12px; width: 60px; height: 60px; color: #5a3d14; --hole: #e6c27a; transform: rotate(var(--key, 0rad)); transform-origin: 50% 50%; }
.wind.is-full { animation: full .3s ease; }
@keyframes full { 30% { transform: rotate(-6deg); } 60% { transform: rotate(4deg); } }
[data-phase="intro"] .wind { animation: beckon 2.2s ease-in-out infinite; }
@keyframes beckon { 50% { box-shadow: 0 8px 24px rgba(0,0,0,.45), 0 0 0 10px rgba(211,170,92,.18), inset 0 -3px 6px rgba(80,50,10,.5), inset 0 2px 3px rgba(255,240,200,.6); } }
[data-phase="finale"] .wind { display: none; }
.open-card {
  height: 50px; padding: 0 26px; border-radius: 99px; cursor: pointer; border: 1px solid #f0d38f; font-size: 19px; font-weight: 700; letter-spacing: .02em;
  background: linear-gradient(180deg, #e2bd70, #b58a3e); color: #2a1a10; box-shadow: 0 10px 30px rgba(0,0,0,.45); animation: beckon2 2s ease-in-out infinite;
}
@keyframes beckon2 { 50% { box-shadow: 0 10px 30px rgba(0,0,0,.45), 0 0 0 9px rgba(211,170,92,.2); } }

/* ------------------------------------------------ thiệp mời */
.invite {
  position: fixed; inset: 0; z-index: 20; background: rgba(16,10,8,.58); backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  opacity: 0; transition: opacity .6s ease;
}
.invite.show { opacity: 1; }
.inv-scroll { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; padding: calc(28px + var(--safe-t)) 16px calc(40px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.card {
  position: relative; max-width: 580px; margin: 0 auto; padding: 48px clamp(22px, 6vw, 56px) 36px; color: var(--ink); text-align: center;
  background-color: var(--paper); background-image: var(--paper-tex); background-size: 512px;
  border-radius: 3px; box-shadow: 0 30px 70px rgba(0,0,0,.55), 0 2px 0 rgba(255,255,255,.4) inset;
  transform: translateY(30px) scale(.97); transition: transform .7s cubic-bezier(.2,.8,.2,1);
}
.invite.show .card { transform: none; }
.card::before { content: ''; position: absolute; inset: 12px; border: 1px solid rgba(140,34,38,.35); outline: 1px solid rgba(140,34,38,.18); outline-offset: 4px; pointer-events: none; }
.close { position: absolute; top: 14px; right: 14px; width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; font-size: 30px; line-height: 1; color: var(--ink); cursor: pointer; z-index: 2; }
.kicker { margin: 0; font-size: 19px; font-weight: 500; outline: none; }
.kicker b { font-family: var(--script); font-weight: 700; font-size: 1.45em; color: var(--red); }
.lead { margin: 6px 0 0; font-style: italic; font-size: 18px; }
.names { margin: 10px 0 0; font-family: var(--script); font-weight: 600; font-size: clamp(44px, 11vw, 70px); line-height: 1.02; color: var(--red); display: grid; }
.names i { font-style: normal; font-size: .5em; color: #b08440; margin: 2px 0; }
.xi { font-size: 34px; color: var(--red); margin: 14px 0 0; font-family: serif; }
.when { margin-top: 24px; }
.day { margin: 0; font-size: 15px; letter-spacing: .3em; text-transform: uppercase; font-weight: 600; }
.date { margin: 8px 0 0; display: inline-flex; align-items: center; gap: 14px; }
.date b { font-size: 76px; line-height: .9; font-weight: 600; color: var(--red); }
.date span { text-align: left; font-size: 20px; font-weight: 600; line-height: 1.15; border-left: 1px solid rgba(43,27,20,.35); padding-left: 14px; }
.lunar { margin: 8px 0 0; font-style: italic; font-size: 17px; }
.sched { display: flex; justify-content: center; gap: 0; margin: 18px 0 0; }
.sched div { padding: 0 16px; border-left: 1px solid rgba(43,27,20,.25); }
.sched div:first-child { border: 0; }
.sched dt { font-size: 14px; letter-spacing: .06em; }
.sched dd { margin: 2px 0 0; font-size: 24px; font-weight: 700; }
.where { margin-top: 28px; }
.where h2 { margin: 0; font-size: 24px; font-weight: 700; }
.where p { margin: 4px 0 0; font-size: 18px; }
.btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 0 22px; border-radius: 99px; cursor: pointer; text-decoration: none;
  font-size: 17px; font-weight: 700; letter-spacing: .02em; border: 1px solid var(--red); background: var(--red); color: #fbf3e4;
}
.btn.ghost { background: transparent; color: var(--red); }
.fam { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 30px; }
.fam h3 { margin: 0; font-size: 14px; letter-spacing: .24em; text-transform: uppercase; color: var(--red); }
.fam p { margin: 6px 0 0; font-size: 18px; line-height: 1.35; }
.cd { display: flex; justify-content: center; gap: 8px; margin-top: 28px; flex-wrap: wrap; }
.cd p { margin: 0; width: 70px; padding: 8px 0 6px; border: 1px solid rgba(140,34,38,.3); border-radius: 4px; }
.cd b { display: block; font-size: 28px; font-weight: 700; line-height: 1; }
.cd span { font-size: 14px; }
.cd .cd-done { display: none; width: auto; border: 0; font-family: var(--script); font-size: 30px; color: var(--red); }
.cd.done p { display: none; }
.cd.done .cd-done { display: block; }
.reply { margin-top: 34px; padding-top: 26px; border-top: 1px solid rgba(140,34,38,.25); }
.reply h2 { margin: 0; font-family: var(--script); font-weight: 600; font-size: 40px; color: var(--red); }
.reply .sub { margin: 4px 0 0; font-size: 17px; }
.rsvp { display: grid; gap: 14px; margin-top: 18px; text-align: left; }
.rsvp fieldset { border: 0; margin: 0; padding: 0; }
.rsvp legend { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice label, .chips label { position: relative; }
.choice input, .chips input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choice span { display: grid; place-items: center; min-height: 52px; padding: 6px 10px; border: 1.5px solid rgba(140,34,38,.4); border-radius: 8px; text-align: center; font-size: 17px; font-weight: 700; line-height: 1.15; }
.choice input:checked + span { background: var(--red); color: #fbf3e4; border-color: var(--red); }
.choice input:focus-visible + span, .chips input:focus-visible + span { outline: 2px solid var(--red); outline-offset: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips legend { width: 100%; }
.chips span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border: 1.5px solid rgba(140,34,38,.35); border-radius: 99px; font-size: 16px; font-weight: 600; }
.chips input:checked + span { background: rgba(140,34,38,.12); border-color: var(--red); color: var(--red); }
.field { display: grid; gap: 5px; }
.field > span { font-size: 16px; font-weight: 600; }
.field small { font-weight: 500; opacity: .75; }
.field input, .field textarea, .stepper input {
  width: 100%; font: inherit; font-size: 18px; color: var(--ink); background: rgba(255,252,245,.6); border: 1.5px solid rgba(43,27,20,.25); border-radius: 8px; padding: 10px 12px;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--red); background: #fffaf0; }
.stepper { display: inline-grid; grid-template-columns: 46px 64px 46px; gap: 6px; }
.stepper button { height: 46px; border-radius: 8px; border: 1.5px solid rgba(140,34,38,.4); background: transparent; font-size: 24px; color: var(--red); cursor: pointer; }
.stepper input { text-align: center; padding: 8px 4px; }
.err { margin: 0; color: #a01b1b; font-weight: 700; font-size: 16px; }
.send { justify-self: center; min-width: 200px; margin-top: 4px; }
.demo { margin: 0; font-size: 14px; opacity: .8; text-align: center; }
.thanks { margin-top: 16px; outline: none; }
.thanks h3 { margin: 0; font-family: var(--script); font-size: 38px; color: var(--red); }
.thanks p { font-size: 18px; }
.c-foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 30px; }
.credits { max-width: 560px; margin: 18px auto 0; font-size: 14px; line-height: 1.45; color: var(--muted); text-align: center; }

@media (min-aspect-ratio: 5/4) {
  .dock { left: auto; right: calc(28px + var(--safe-r)); bottom: calc(26px + var(--safe-b)); justify-items: end; }
  .hint { text-align: right; }
  .dots { top: auto; bottom: calc(34px + var(--safe-b)); left: calc(28px + var(--safe-l)); transform: none; }
}

/* ------------------------------------------------ màn hình nhỏ */
@media (max-width: 760px), (orientation: portrait) and (max-width: 1100px) {
  .hb span { display: none; }
  .hb { width: 40px; padding: 0; justify-content: center; }
  .hb.strong { width: auto; padding: 0 14px 0 11px; }
  .hb.strong span { display: inline; }
  .brand b { display: none; }
  .dots { top: calc(62px + var(--safe-t)); gap: 10px; }
  .dots li { width: 40px; font-size: 12px; }
}
@media (max-width: 380px) {
  .brand { font-size: 21px; }
  .hb.strong span { display: none; }
  .hb.strong { width: 40px; padding: 0; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .hud { top: calc(8px + var(--safe-t)); }
  .dots { top: auto; bottom: calc(12px + var(--safe-b)); left: calc(16px + var(--safe-l)); transform: none; gap: 8px; }
  .dots li { width: 36px; font-size: 11px; }
  .dock { bottom: calc(10px + var(--safe-b)); right: calc(16px + var(--safe-r)); left: auto; justify-items: end; }
  .wind { width: 70px; height: 70px; }
  .wind .key { inset: 10px; width: 50px; height: 50px; }
  .hint { font-size: 15px; }
}
@media (pointer: coarse) {
  .hb { height: 44px; }
  .hb, .hb.strong { min-width: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  .ld-key, [data-phase="intro"] .wind, .open-card { animation: none; }
}

/* vở rối: ẩn nút lên dây khi hộp đã chơi */
[data-phase="wind"] .dock, [data-phase="open"] .dock, [data-phase="box"] .dock, [data-phase="stage"] .dock, [data-phase="end"] .dock { opacity: 0; pointer-events: none; transition: opacity .6s; }
[data-phase="intro"] .dots, [data-phase="wind"] .dots, [data-phase="box"] .dots, [data-phase="end"] .dots { opacity: 0; }
[data-phase="stage"] .dots { opacity: 1; }
.dots li { width: 34px; }
.playbill { margin: 0 0 10px; font-size: 13px; letter-spacing: .28em; text-transform: uppercase; font-weight: 700; color: #8c2226; }
