/* =====================================================================
   THIỆP CƯỚI – thiệp vuông 3 trang, phong bì mở thiệp, thư viện mẫu, trang khách mời.
   Cỡ chữ theo bề rộng trang thiệp (cqi) → cùng một thiệp hiện đẹp ở mọi kích thước.
   ===================================================================== */

/* ---------- THIỆP ---------- */
.inv { display: grid; gap: 22px; }
.inv-page {
  position: relative; container-type: inline-size; aspect-ratio: 1; overflow: hidden;
  background: var(--inv-bg); color: var(--inv-ink); font-family: 'Cormorant Garamond', 'Palatino Linotype', Cambria, serif;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .22); border-radius: 2px; text-align: left; line-height: 1.3; letter-spacing: normal;
}
.inv-page > * { position: relative; }
.inv-orn { position: absolute !important; pointer-events: none; overflow: visible; }
.inv-script { font-family: var(--inv-script); font-weight: 400; line-height: 1.08; color: var(--inv-accent); }
.inv-caps { text-transform: uppercase; letter-spacing: .12em; font-weight: 700; font-size: max(7.5px, 2.45cqi); line-height: 1.35; }
.inv-light { font-weight: 600; opacity: .78; }
.inv-tiny { font-size: max(7px, 2.15cqi); line-height: 1.35; opacity: .85; }
.inv-amp { font-family: var(--inv-script); color: var(--inv-accent); font-size: 6.5cqi; line-height: .9; }
.inv-when { font-weight: 700; font-size: max(8.5px, 2.95cqi); letter-spacing: .05em; text-transform: uppercase; }
.inv-note { font-size: max(8px, 2.6cqi); font-style: italic; line-height: 1.35; }
.inv-guest {
  min-height: 5.6cqi; border-bottom: 1.5px dotted var(--inv-accent); font-family: var(--inv-script);
  font-size: 5.4cqi; line-height: 1.05; color: var(--inv-accent); padding: 0 1cqi;
}

/* ảnh tròn + viền đôi */
.inv-photo { border-radius: 50%; overflow: hidden; aspect-ratio: 1; background: var(--inv-soft);
  border: .7cqi solid var(--inv-bg); outline: .35cqi solid var(--inv-accent); outline-offset: .6cqi; display: grid; place-items: center; }
.inv-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.inv-monogram { font-family: var(--inv-script); color: var(--inv-accent); font-size: 9cqi; white-space: nowrap; }

/* Trang 1 – bìa */
.inv-orn-cover { top: -2cqi; left: -2cqi; width: 54cqi; }
.inv-orn-cover-small { right: -1cqi; bottom: -1cqi; width: 30cqi; }
.inv-photo-cover { position: absolute !important; top: 13cqi; right: 9cqi; width: 40cqi; }
.inv-photo-cover .inv-monogram { font-size: 10cqi; }
.inv-cover-names { position: absolute !important; left: 9cqi; top: 37cqi; display: flex; flex-direction: column; }
.inv-cover-names .inv-script { font-size: 12.5cqi; }
.inv-cover-names .inv-amp { margin: -1cqi 0 -1cqi 15cqi; }
.inv-cover-names .inv-script:last-child { margin-left: 18cqi; }
.inv-cover-foot { position: absolute !important; left: 10cqi; bottom: 8cqi; width: 50cqi; display: flex; flex-direction: column; gap: 1.6cqi; }

/* Trang 2 – gia đình & hôn lễ */
.inv-orn-side { right: -3cqi; top: 20cqi; height: 82cqi; }
.inv-p2-body { height: 100%; padding: 8cqi 10cqi 7cqi; display: flex; flex-direction: column; justify-content: space-between; }
.inv-families { display: grid; grid-template-columns: 1fr 1fr; gap: 4cqi; font-size: max(7px, 2.2cqi); }
.inv-family-col { display: flex; flex-direction: column; gap: .5cqi; }
.inv-family-col:last-child { text-align: right; }
.inv-family-col .inv-caps { font-size: max(7px, 2.2cqi); opacity: .8; margin-bottom: .6cqi; }
.inv-block { display: flex; flex-direction: column; gap: .8cqi; max-width: 64cqi; }
.inv-fullnames { display: flex; flex-direction: column; max-width: 70cqi; }
.inv-fullnames .inv-script { font-size: 8.6cqi; }
.inv-fullnames .inv-amp { font-size: 5cqi; margin: -.5cqi 0 -.5cqi 4cqi; }

/* Trang 3 – tiệc cưới */
.inv-orn-corner { top: -2cqi; left: -2cqi; width: 34cqi; }
.inv-mirror { position: absolute !important; inset: 0; transform: scaleX(-1); pointer-events: none; }
.inv-p3 { display: flex; flex-direction: column; align-items: center; }
.inv-p3-body { flex: none; padding: 10cqi 15cqi 0; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 1.2cqi; }
.inv-p3-body .inv-guest { width: 62cqi; margin-bottom: 1cqi; }
.inv-p3-body .inv-note { max-width: 50cqi; margin-bottom: 1cqi; }
.inv-venue { font-size: 10.5cqi; margin: -.5cqi 0; text-wrap: balance; }
.inv-venue.is-long { font-size: 7cqi; }
.inv-venue.is-xlong { font-size: 5.8cqi; }
/* Ảnh tròn chiếm phần còn lại của trang (co lại khi chữ phía trên dài) – luôn nằm trọn trong trang */
.inv-arc { flex: 1 1 0; min-height: 18cqi; max-height: 40cqi; aspect-ratio: 1; margin: 3cqi 0 4.5cqi; }
.inv-arc svg { position: absolute; inset: -8%; width: 116%; height: 116%; }
.inv-photo-arc { position: absolute !important; inset: 14%; }

/* Khung viền cho các mẫu nền đậm / sang trọng */
.inv-song-hy .inv-page::before, .inv-deco .inv-page::before, .inv-stars .inv-page::before {
  content: ''; position: absolute; inset: 2.6cqi; border: 1px solid var(--inv-accent); opacity: .7; pointer-events: none; z-index: 0;
}
.inv-song-hy .inv-page::after { content: ''; position: absolute; inset: 3.6cqi; border: 1px solid var(--inv-accent); opacity: .35; pointer-events: none; }
.inv-song-hy .inv-photo, .inv-stars .inv-photo { border-color: var(--inv-bg); }

/* ---------- PHONG BÌ ---------- */
.envelope { position: relative; width: min(88vw, 500px); aspect-ratio: 1.22; perspective: 1400px; margin: 0 auto; }
.envelope > * { position: absolute; }
.envelope-back { inset: 0; background: var(--inv-soft); border-radius: 12px; box-shadow: 0 30px 60px rgba(0, 0, 0, .35); }
.envelope-letter {
  left: 7%; right: 7%; top: 7%; height: 82%; z-index: 1; display: grid; place-items: center;
  background: var(--inv-bg); border-radius: 6px; box-shadow: 0 4px 14px rgba(0, 0, 0, .15);
  transition: transform 1s .55s cubic-bezier(.2, .8, .2, 1);
}
.envelope-letter .inv-script { font-size: clamp(30px, 9vw, 52px); }
.envelope-front {
  inset: 0; z-index: 2; border-radius: 12px; clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%);
  background: linear-gradient(170deg, var(--inv-bg) 0%, var(--inv-soft) 100%);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6%; color: var(--inv-ink);
  font-family: 'Cormorant Garamond', 'Palatino Linotype', Cambria, serif;
}
.envelope-to { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.envelope-to .inv-caps { font-size: 12px; opacity: .75; }
.envelope-name { font-family: var(--inv-script); color: var(--inv-accent); font-size: clamp(24px, 7vw, 38px); line-height: 1.1; text-align: center; padding: 0 16px; }
.envelope-flap {
  left: 0; right: 0; top: 0; height: 56%; z-index: 3; transform-origin: top center;
  background: linear-gradient(180deg, var(--inv-accent), color-mix(in srgb, var(--inv-accent) 70%, #000));
  clip-path: polygon(0 0, 100% 0, 50% 100%); transition: transform .8s cubic-bezier(.5, 0, .3, 1), z-index 0s .4s;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .2));
}
.envelope-seal {
  left: 50%; top: 56%; z-index: 4; width: 16%; aspect-ratio: 1; transform: translate(-50%, -50%); border: 0; border-radius: 50%; cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #c94848, #7d1515 70%); color: #f7e2b0; box-shadow: 0 6px 16px rgba(0, 0, 0, .35), inset 0 0 0 4px rgba(255, 255, 255, .12);
  font: 700 clamp(18px, 5vw, 28px) 'Cormorant Garamond', serif; letter-spacing: .02em;
  transition: transform .4s, opacity .4s; animation: seal-pulse 2.4s ease-in-out infinite;
}
.envelope-seal:hover { transform: translate(-50%, -50%) scale(1.06); }
.envelope-seal:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
.envelope.is-open .envelope-flap { transform: rotateX(180deg); z-index: 0; }
.envelope.is-open .envelope-seal { opacity: 0; transform: translate(-50%, -50%) scale(.5); pointer-events: none; animation: none; }
.envelope.is-open .envelope-letter { transform: translateY(-46%); }
@keyframes seal-pulse { 0%, 100% { box-shadow: 0 6px 16px rgba(0, 0, 0, .35), 0 0 0 0 rgba(255, 255, 255, .45); } 50% { box-shadow: 0 6px 16px rgba(0, 0, 0, .35), 0 0 0 12px rgba(255, 255, 255, 0); } }

/* ---------- TRANG KHÁCH MỜI ---------- */
body.invite-mode #invitation-page { width: 100%; max-width: none; padding: 0; }
.inv-stage { background: var(--stage); min-height: calc(100vh - 64px); padding: 28px 16px 120px; color: #fff; }
.inv-stage-inner { max-width: 1240px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }
.inv-intro { min-height: calc(100vh - 160px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; text-align: center; }
.inv-intro-hint { font-size: 14px; opacity: .8; letter-spacing: .04em; }
.inv-intro.is-leaving { animation: fade-away .6s 1.4s forwards; }
@keyframes fade-away { to { opacity: 0; transform: scale(.96); } }
.inv-guest-pages .inv { grid-template-columns: 1fr; max-width: 560px; margin: 0 auto; }
@media (min-width: 1100px) { .inv-guest-pages .inv { grid-template-columns: repeat(3, 1fr); max-width: none; } }
.inv-guest-pages .inv-page { opacity: 0; transform: translateY(24px); animation: page-in .8s cubic-bezier(.2, .8, .2, 1) forwards; }
.inv-guest-pages .inv-page:nth-child(2) { animation-delay: .18s; }
.inv-guest-pages .inv-page:nth-child(3) { animation-delay: .36s; }
@keyframes page-in { to { opacity: 1; transform: none; } }

.inv-section { max-width: 760px; width: 100%; margin: 0 auto; background: rgba(255, 255, 255, .96); color: var(--ink); border-radius: 18px; padding: 24px; }
.inv-section h2 { font-family: var(--font-title); margin: 0 0 6px; }
.countdown { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; text-align: center; max-width: 520px; margin: 0 auto; }
.countdown div { background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .25); border-radius: 14px; padding: 14px 4px; }
.countdown strong { display: block; font-size: clamp(24px, 6vw, 38px); font-family: var(--font-title); }
.countdown span { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; opacity: .8; }
.inv-countdown-title { text-align: center; font-family: 'Cormorant Garamond', 'Palatino Linotype', Cambria, serif; font-size: 22px; margin: 0 0 12px; }
.inv-info-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.inv-info-row .btn { background: rgba(255, 255, 255, .12); color: #fff; border: 1px solid rgba(255, 255, 255, .35); }
.inv-info-row .btn:hover { background: rgba(255, 255, 255, .22); }
.inv-actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; justify-content: center; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(20, 18, 26, .78); backdrop-filter: blur(10px);
}
.inv-actions .btn { min-width: 0; flex: 0 1 240px; background: #26222e; color: #fff; border: 1px solid rgba(255, 255, 255, .18); }
.inv-actions .btn:hover { background: #3a3445; }
body.invite-mode .tabbar, body.invite-mode #app-footer { display: none; }
body.invite-mode { padding-bottom: 0; }
.gift-qr { width: 200px; height: 200px; background: #fff; border-radius: 12px; padding: 8px; margin: 8px auto; display: block; }

/* ---------- THƯ VIỆN MẪU ---------- */
.tpl-hero { text-align: center; max-width: 720px; margin: 0 auto 22px; }
.tpl-hero h1 { margin-bottom: 8px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 20px; }
.tpl-card { display: flex; flex-direction: column; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px; transition: transform .2s, box-shadow .2s; }
.tpl-card:hover { transform: translateY(-4px); box-shadow: 0 16px 34px rgba(80, 30, 30, .12); }
.tpl-card.active { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.tpl-thumb { border-radius: 10px; padding: 14px; background: var(--stage); cursor: zoom-in; border: 0; }
.tpl-thumb .inv-page { box-shadow: 0 8px 20px rgba(0, 0, 0, .3); }
.tpl-meta { display: flex; align-items: center; gap: 8px; }
.tpl-meta strong { flex: 1; min-width: 0; }
.tpl-actions { display: flex; gap: 8px; }
.tpl-actions .btn { flex: 1; }
.tpl-preview-dialog .inv { grid-template-columns: 1fr; }
.tpl-preview-stage { background: var(--stage); padding: 16px; border-radius: 14px; max-height: 70vh; overflow-y: auto; }

/* Trình soạn: chọn mẫu dạng dải ngang */
.tpl-strip { display: grid; grid-auto-flow: column; grid-auto-columns: 112px; gap: 10px; overflow-x: auto; padding: 2px 2px 8px; scroll-snap-type: x mandatory; }
.tpl-pick { border: 2px solid transparent; border-radius: 12px; padding: 6px; background: var(--stage); cursor: pointer; scroll-snap-align: start; display: flex; flex-direction: column; gap: 6px; }
.tpl-pick > span { color: #fff; font: 600 11px var(--font-body); text-align: center; line-height: 1.2; }
.tpl-pick.active { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.tpl-pick .inv-page { box-shadow: none; }
.inv-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.inv-editor-preview { position: sticky; top: 84px; background: var(--stage); border-radius: 18px; padding: 18px; max-height: calc(100vh - 100px); overflow-y: auto; }
.inv-editor-preview .inv { max-width: 460px; margin: 0 auto; }
.inv-form-section { display: flex; flex-direction: column; gap: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
.inv-form-section:first-of-type { border-top: 0; padding-top: 0; }
.inv-form-section h3 { margin: 0; font-size: 17px; }
.host-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.host-picker label { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 14px; }
.host-picker label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.photo-picker { display: flex; align-items: center; gap: 14px; }
.photo-picker .stack { align-items: flex-start; }
.photo-picker img, .photo-picker .photo-empty { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; background: var(--bg); border: 1px dashed var(--line); display: grid; place-items: center; font-size: 26px; flex: none; }

@media (max-width: 900px) {
  .inv-editor { grid-template-columns: 1fr; }
  .inv-editor-preview { position: static; max-height: none; }
}
@media (max-width: 640px) {
  .inv-section { padding: 18px; }
  .inv-actions .btn { padding-left: 10px; padding-right: 10px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .envelope-flap, .envelope-letter, .envelope-seal { transition: none; animation: none; }
  .inv-guest-pages .inv-page { animation: none; opacity: 1; transform: none; }
  .inv-intro.is-leaving { animation-duration: .01s; animation-delay: 0s; }
}

/* ---------- ĐỢT 2b: chuyện tình yêu, album, sổ lời chúc, nhạc ---------- */
/* Khách mời */
.inv-story h2, .inv-album h2, #guestbook-section h2 { font-family: var(--inv-script); color: var(--inv-accent); font-weight: 400; font-size: clamp(34px, 7vw, 46px); line-height: 1.1; }
.story-timeline { list-style: none; margin: 18px 0 0; padding: 0; position: relative; display: flex; flex-direction: column; gap: 18px; }
.story-timeline::before { content: ''; position: absolute; left: 15px; top: 6px; bottom: 6px; width: 2px; background: color-mix(in srgb, var(--inv-accent) 35%, transparent); }
.story-timeline li { display: grid; grid-template-columns: 32px 1fr; gap: 12px; align-items: start; }
.story-dot { width: 32px; height: 32px; border-radius: 50%; background: var(--inv-accent); color: #fff; display: grid; place-items: center; font-size: 14px; position: relative; }
.story-card { background: color-mix(in srgb, var(--inv-accent) 8%, #fff); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; }
.story-when { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--inv-accent); font-weight: 700; }
.story-card p { margin: 2px 0 0; color: var(--muted); line-height: 1.55; }
@media (min-width: 720px) {
  .story-timeline::before { left: 50%; transform: translateX(-1px); }
  .story-timeline li { grid-template-columns: 1fr 32px 1fr; }
  .story-timeline li .story-dot { grid-column: 2; grid-row: 1; }
  .story-timeline li:nth-child(odd) .story-card { grid-column: 1; grid-row: 1; text-align: right; align-items: flex-end; }
  .story-timeline li:nth-child(even) .story-card { grid-column: 3; grid-row: 1; }
}
.album-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.album-cell { border: 0; padding: 0; border-radius: 10px; overflow: hidden; aspect-ratio: 1; cursor: zoom-in; background: var(--bg); }
.album-cell:first-child { grid-column: span 2; grid-row: span 2; }
.album-cell img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s; }
.album-cell:hover img { transform: scale(1.05); }
.wish-wall { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 16px 0 18px; max-height: 460px; overflow-y: auto; padding: 2px; }
.wish-card { margin: 0; background: color-mix(in srgb, var(--inv-accent) 7%, #fff); border-radius: 14px; padding: 14px 16px; border: 1px solid color-mix(in srgb, var(--inv-accent) 18%, transparent); }
.wish-card blockquote { margin: 0; white-space: pre-line; line-height: 1.55; }
.wish-card figcaption { margin-top: 8px; font-weight: 700; color: var(--inv-accent); font-size: 14px; }
.music-toggle {
  position: fixed; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 41; width: 48px; height: 48px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .35); background: rgba(20, 18, 26, .7); color: #fff; font-size: 22px; cursor: pointer; backdrop-filter: blur(8px);
}
.music-toggle.is-playing { animation: disc-spin 4s linear infinite; box-shadow: 0 0 0 4px color-mix(in srgb, var(--inv-accent) 45%, transparent); }
.music-toggle:not(.is-playing)::after { content: ''; position: absolute; left: 10px; right: 10px; top: 50%; height: 2px; background: #fff; transform: rotate(-45deg); }
@keyframes disc-spin { to { transform: rotate(360deg); } }
.music-frame { position: fixed; width: 1px; height: 1px; left: -10px; bottom: 0; opacity: 0; pointer-events: none; border: 0; }

/* Trình soạn */
.album-edit { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.album-thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--bg); touch-action: none; }
.album-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: grab; }
.album-remove { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .6); color: #fff; cursor: pointer; }
.story-edit-item { border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.story-edit-item .btn-link { align-self: flex-start; }
.music-picker { display: flex; flex-direction: column; gap: 6px; }
.music-option { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; }
.music-option label, label.music-option { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.music-option:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.wish-item { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.wish-item.is-new { animation: drop-flash 1.2s ease; border-color: var(--brand); }
@media (prefers-reduced-motion: reduce) { .music-toggle.is-playing { animation: none; } }
label.music-option { justify-content: flex-start; }
.inv-editor-side { align-self: stretch; }   /* cột cao bằng form → khung xem trước bám theo suốt lúc soạn */
.inv-owner-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 24px; align-items: start; }
@media (max-width: 900px) { .inv-owner-panels { grid-template-columns: 1fr; } }

/* ---------- Trình soạn: mục gập / mở + giao diện điện thoại ---------- */
.inv, .inv-page { width: 100%; }   /* Safari: khung thiệp trong nút bấm không tự giãn → mất ảnh thu nhỏ */
details.inv-form-section { display: block; padding: 0; scroll-margin-top: 76px; }
.inv-form-section > summary {
  list-style: none; display: flex; align-items: center; gap: 10px; padding: 14px 0; cursor: pointer; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.inv-form-section > summary::-webkit-details-marker { display: none; }
.inv-form-section > summary::after { content: '⌄'; font-size: 20px; line-height: 1; color: var(--muted); transition: transform .2s; margin-top: -6px; }
.inv-form-section[open] > summary::after { transform: rotate(180deg); margin-top: 6px; }
.step-num { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-dark); font: 700 13px var(--font-body); transition: background .2s, color .2s; }
.inv-form-section.is-done .step-num { background: #1f7a4d; color: #fff; }
.step-title { flex: 1; min-width: 0; font: 700 17px var(--font-title); }
.step-title .small { font-family: var(--font-body); font-weight: 500; }
.step-done { color: #1f7a4d; font-weight: 800; opacity: 0; transition: opacity .2s; }
.inv-form-section.is-done .step-done { opacity: 1; }
.inv-form-body { display: flex; flex-direction: column; gap: 12px; padding-bottom: 18px; }
.same-photo { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; padding: 6px 0; }
.same-photo input { width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
.inv-mobile-bar { display: none; }

@media (max-width: 900px) {
  .inv-editor { grid-template-columns: minmax(0, 1fr); }   /* dải mẫu thiệp không còn kéo rộng cả trang */
  .inv-editor > form { min-width: 0; }
  .inv-editor-side, .inv-save-main { display: none; }    /* xem thiệp + lưu chuyển xuống thanh dưới đáy */
  .inv-mobile-bar {
    display: flex; gap: 10px; position: fixed; left: 0; right: 0; z-index: 44;
    bottom: calc(58px + env(safe-area-inset-bottom, 0px)); padding: 10px 16px;
    background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(42, 36, 33, .08);
  }
  .inv-mobile-bar .btn { flex: 1; min-height: 46px; }
  body:has(.inv-mobile-bar) { padding-bottom: calc(136px + env(safe-area-inset-bottom, 0px)); }
  body:has(.inv-mobile-bar) .toast-host { bottom: calc(144px + env(safe-area-inset-bottom, 0px)); }
  .tpl-strip { grid-auto-columns: 100px; margin: 0 -2px; }
  .photo-picker img, .photo-picker .photo-empty { width: 72px; height: 72px; }
  .music-option { flex-wrap: wrap; }
  .story-edit-item .form-grid, .inv-form-body .form-grid { grid-template-columns: 1fr; }
  .inv-owner-panels { margin-top: 16px; }
}
/* Ảnh thu nhỏ (dải chọn mẫu): bỏ cỡ chữ tối thiểu – chữ co đúng tỷ lệ như thiệp thật */
.tpl-pick .inv-caps, .tpl-pick .inv-family-col .inv-caps { font-size: 2.45cqi; }
.tpl-pick .inv-tiny, .tpl-pick .inv-families { font-size: 2.15cqi; }
.tpl-pick .inv-when { font-size: 2.95cqi; }
.tpl-pick .inv-note { font-size: 2.6cqi; }
.tpl-pick .inv-guest { border-bottom-width: 1px; }
/* Mũi tên mở / đóng mục */
.inv-form-section > summary::after {
  content: ''; width: 9px; height: 9px; margin: -4px 4px 0 2px; font-size: 0;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg);
}
.inv-form-section[open] > summary::after { transform: rotate(-135deg); margin-top: 4px; }

/* ---------- Nâng cấp thiệp: nhiều sự kiện, câu hỏi, mừng cưới 2 bên, video, phù dâu phù rể, hiệu ứng, khóa ---------- */
/* Trình soạn */
.event-edit { border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--card); }
.event-edit.is-main { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.event-edit-head { display: flex; align-items: center; gap: 8px; }
.event-badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark); }
.gift-edit { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px 12px; margin: 0; }
.gift-edit legend { font-weight: 700; padding: 0 6px; }
.effect-picker .chip { cursor: pointer; }
.effect-picker .chip.active, .rsvp-choice.active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); }
.share-box { background: var(--brand-soft); padding: 14px; }
.share-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.share-qr { display: flex; gap: 14px; align-items: center; padding: 10px; border-radius: 12px; background: #fff; }
.share-qr img { width: 132px; height: auto; flex: none; image-rendering: pixelated; }
.rsvp-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.rsvp-stats div { background: var(--bg); border-radius: 12px; padding: 10px; text-align: center; display: flex; flex-direction: column; }
.rsvp-stats strong { font-size: 22px; }
.rsvp-stats span { font-size: 12px; color: var(--muted); }
.rsvp-breakdown { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.rsvp-breakdown li { display: flex; gap: 8px; align-items: baseline; padding: 6px 10px; border-radius: 10px; background: var(--bg); }
.rsvp-breakdown li span:first-child { flex: 1; }
.rsvp-question { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; border-top: 1px dashed var(--line); }
.rsvp-question .chip { cursor: default; }
.wish-reply-box { margin-top: 8px; }
.wish-reply-box summary { cursor: pointer; color: var(--brand-dark); font-weight: 600; }
.wish-reply-box textarea { margin: 6px 0; min-height: 60px; }

/* Khách mời */
.inv-lock { max-width: 440px; }
.inv-lock-icon { font-size: 40px; }
.inv-events h2, .inv-crew h2, .inv-video h2 { font-family: var(--inv-script); color: var(--inv-accent); font-weight: 400; font-size: clamp(34px, 7vw, 46px); line-height: 1.1; }
.event-list { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.event-card { display: grid; grid-template-columns: 86px 1fr; gap: 14px; padding: 14px; border-radius: 16px; border: 1px solid color-mix(in srgb, var(--inv-accent) 22%, transparent); background: color-mix(in srgb, var(--inv-accent) 5%, #fff); }
.event-card.is-main { border-color: var(--inv-accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--inv-accent) 25%, transparent); }
.event-date { display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 12px; background: var(--inv-accent); color: #fff; padding: 8px 4px; text-align: center; }
.event-date strong { font-size: 22px; line-height: 1.1; }
.event-date span { font-size: 13px; opacity: .9; }
.event-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.event-kind { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; color: var(--inv-accent); }
.event-name { font-size: 17px; }
.event-links { display: flex; gap: 14px; margin-top: 4px; font-size: 14px; font-weight: 600; }
.event-links a { color: var(--inv-accent); }
.crew-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-top: 14px; }
.crew-col { background: color-mix(in srgb, var(--inv-accent) 7%, #fff); border-radius: 14px; padding: 12px 16px; text-align: center; }
.crew-col ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.video-box { margin-top: 14px; aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden; background: #000; }
.video-box iframe { width: 100%; height: 100%; border: 0; display: block; }
.video-poster { width: 100%; height: 100%; border: 0; cursor: pointer; background: #222 center / cover no-repeat; display: grid; place-items: center; }
.video-play { width: 68px; height: 68px; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff; font-size: 26px; display: grid; place-items: center; padding-left: 5px; transition: transform .2s, background .2s; }
.video-poster:hover .video-play { transform: scale(1.08); background: var(--inv-accent); }
.gift-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 14px; }
.gift-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px; border-radius: 16px; background: color-mix(in srgb, var(--inv-accent) 6%, #fff); }
.gift-card .gift-qr { margin: 6px auto; }
.gift-account { font-size: 18px; font-weight: 800; letter-spacing: .04em; }
.rsvp-events { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.rsvp-events legend { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.rsvp-event { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.rsvp-event:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.rsvp-event input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--brand); flex: none; }
.rsvp-event > span { display: flex; flex-direction: column; }
.rsvp-q fieldset { border: 0; padding: 0; margin: 0; }
.rsvp-q legend { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.rsvp-choice { cursor: pointer; }
.rsvp-choice input { position: absolute; opacity: 0; pointer-events: none; }
.rsvp-choice:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }
.wish-reply { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: #fff; font-size: 14px; border-left: 3px solid var(--inv-accent); }

/* Hiệu ứng rơi */
.wedding-effect { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
.wedding-effect span { position: absolute; top: -40px; color: var(--fx-accent); animation-name: fx-fall; animation-timing-function: linear; animation-iteration-count: infinite; will-change: transform; }
.effect-snow span { color: #fff; text-shadow: 0 0 6px rgba(255, 255, 255, .7); }
.effect-sparkles span { color: #f3d27a; text-shadow: 0 0 8px rgba(243, 210, 122, .8); }
.effect-petals span { color: #f4a7b9; }
.effect-hearts span { animation-name: fx-rise; top: auto; bottom: -40px; }
@keyframes fx-fall { to { transform: translate(var(--fx-drift), 110vh) rotate(var(--fx-spin)); } }
@keyframes fx-rise { to { transform: translate(var(--fx-drift), -110vh) rotate(calc(var(--fx-spin) / 4)); } }

@media (max-width: 640px) {
  .event-card { grid-template-columns: 70px 1fr; gap: 10px; padding: 12px; }
  .share-qr img { width: 104px; }
  .rsvp-stats strong { font-size: 18px; }
}

/* ---------- Trình soạn: thanh mục cố định (mỗi lần 1 mục) + Lưu / Xem thử ---------- */
.inv-toolbar {
  position: sticky; top: 64px; z-index: 6; display: flex; align-items: center; gap: 10px;
  margin: -6px -8px 4px; padding: 8px; border-radius: 14px;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(8px); box-shadow: 0 6px 18px rgba(42, 36, 33, .06);
}
.inv-steps { flex: 1; min-width: 0; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; padding: 2px; scroll-behavior: smooth; }
.inv-step {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px 6px 6px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); font: 600 13px var(--font-body); color: var(--muted); cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.inv-step .step-num { width: 22px; height: 22px; font-size: 11px; }
.inv-step .step-check { display: none; color: #1f7a4d; font-weight: 800; }
.inv-step.is-done .step-check { display: inline; }
.inv-step.is-done .step-num { background: #1f7a4d; color: #fff; }
.inv-step:hover { border-color: var(--brand); color: var(--ink); }
.inv-step.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.inv-step.active .step-num { background: #fff; color: var(--brand-dark); }
.inv-step.active .step-check { color: #fff; }
.inv-toolbar-actions { flex: none; display: flex; gap: 6px; }
.inv-save-main { display: none; }
/* Tiêu đề mục chỉ là tiêu đề (không gập / mở) */
#editor .inv-form-section > summary { cursor: default; padding-top: 6px; }
#editor .inv-form-section > summary::after { display: none; }
#editor details.inv-form-section { border-top: 0; }
.inv-step-nav { display: flex; justify-content: space-between; gap: 8px; padding-top: 12px; margin-top: 4px; border-top: 1px dashed var(--line); }
/* Bản xem thử */
.preview-banner {
  position: sticky; top: 0; z-index: 60; padding: 8px 16px; text-align: center; font: 600 13px var(--font-body);
  background: #fff7d6; color: #6b5200; border-bottom: 1px solid #f0dc8f;
}

@media (max-width: 900px) {
  .inv-toolbar { top: 60px; margin: -4px -4px 4px; }
  .inv-toolbar-actions { display: none; }        /* điện thoại: Lưu / Xem thử nằm ở thanh dưới đáy */
}
/* Máy tính: hiện đủ 12 mục (xếp nhiều dòng), Lưu / Xem thử ở góc phải */
.inv-toolbar-title { display: none; }
@media (min-width: 901px) {
  .inv-toolbar { display: grid; grid-template-columns: 1fr auto; align-items: center; row-gap: 8px; }
  .inv-toolbar-title { display: block; font: 700 15px var(--font-title); padding-left: 4px; }
  .inv-steps { grid-column: 1 / -1; grid-row: 2; flex-wrap: wrap; overflow: visible; gap: 6px; }
  .inv-step { padding: 4px 9px 4px 4px; font-size: 12.5px; }
}

/* Trình phát YouTube mini (nhạc nền từ link YouTube) – hiện hẳn để iPhone phát tại chỗ, không bật video toàn màn hình */
.music-mini {
  position: fixed; left: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 42; width: 200px;
  border-radius: 12px; overflow: hidden; background: #111; box-shadow: 0 10px 28px rgba(0, 0, 0, .4);
  opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .25s, transform .25s;
}
.music-mini.is-on { opacity: 1; transform: none; pointer-events: auto; }
.music-mini-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 4px 10px; color: #fff; font: 600 12px var(--font-body); }
.music-mini-close { width: 26px; height: 26px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .15); color: #fff; cursor: pointer; }
.music-mini iframe { display: block; width: 200px; height: 113px; border: 0; }
/* Cột trái: form + gửi thiệp + phản hồi + sổ lời chúc; cột phải: xem trước bám theo màn hình */
.inv-editor-main { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.inv-editor-main .inv-owner-panels { grid-template-columns: 1fr; margin-top: 0; gap: 20px; }
.inv-form-section.is-entering { animation: section-in .22s ease; }
@keyframes section-in { from { opacity: .35; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .inv-form-section.is-entering { animation: none; } }

/* Nhạc nền YouTube: chỉ phát tiếng – trình phát có kích thước thật, nằm trong màn hình nhưng trong suốt, không bấm được */
.music-yt { position: fixed; left: 0; bottom: 0; width: 200px; height: 113px; opacity: 0; pointer-events: none; z-index: 1; overflow: hidden; }
.music-yt iframe { width: 200px; height: 113px; border: 0; display: block; }
/* Mục 8: video tải từ máy */
.video-upload { display: flex; flex-direction: column; gap: 8px; }
.video-preview { width: 100%; max-height: 260px; border-radius: 12px; background: #000; }
.video-box video { width: 100%; height: 100%; display: block; background: #000; }
