:root {
    /* ---- Tema merah marun + blush (ngikut warna undangan) ---- */
    --blush: #f7e6e2;
    --blush-light: #fdf3f0;
    --cream: #f3f1e8;
    --rose: #e2a1a8;
    --red: #9a1515;              /* warna amplop & garis oval kartu */
    --maroon: #6a0a0a;           /* warna teks di undangan */
    --ink: #5a1a1f;
    --muted: #8f5f64;
    --accent: #9a1515;
    --glass: rgba(255, 255, 255, .62);
    --line: rgba(122, 28, 36, .24);
    --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
    --sans: "Jost", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;

    /* ---- Titik penting di kanvas (persen dari kanvas 1080 x 1640) ---- */
    --hinge-y: 38.4%;            /* engsel tutup = tepi atas img 3 */
    --flap-open-scale: 1;        /* tutup terbuka diperbesar sedikit (1 = ukuran asli) */
    --flap-open-y: -4%;          /* tutup terbuka digeser naik (negatif = naik, positif = turun) */
    --card-ox: 51.3%;            /* pusat oval kartu (img 5) */
    --card-oy: 51%;
    --card-inside-y: 6%;         /* kartu tersembunyi di dalam amplop */
    --card-inside-scale: .8;
    --card-out-y: -16%;          /* kartu naik keluar dari amplop */
    --card-out-scale: .95;       /* ukuran kartu sampul (5.png) saat keluar amplop; makin kecil = makin kecil kartunya */
    --card-dx: -1.3%;            /* pusat kartu disejajarkan ke pusat amplop */
    --body-dx: 0%;
    --closed-shift: -5.5%;       /* amplop tertutup dinaikkan ke tengah layar */
    --inv-s: .42;                /* ukuran img 6/7/8 saat kecil di dalam amplop */
    --inv-rise: -23%;            /* tinggi naik sebelum membesar ke depan */
    --page-zoom: 1.3;            /* ukuran akhir halaman 6/7/8, naikin kalau mau lebih besar */
    --pocket-top: 38.4%;         /* ujung kantong di atas garis ini dipotong */
    --env-end-opacity: 1;        /* BARU: 1 = amplop tetap kelihatan di langkah 2-4, 0 = hilang seperti dulu */
    --ease: cubic-bezier(.4, .1, .2, 1);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--blush);
}

body {
    color: var(--ink);
    font-family: var(--sans);
    background:
        radial-gradient(circle at 10% 8%,  rgba(226, 161, 168, .45), transparent 42%),
        radial-gradient(circle at 92% 90%, rgba(154, 21, 21, .16), transparent 46%),
        radial-gradient(circle at 90% 10%, rgba(243, 241, 232, .95), transparent 40%),
        radial-gradient(circle at 8% 92%,  rgba(226, 161, 168, .35), transparent 40%),
        radial-gradient(ellipse 80% 70% at 50% 45%, var(--blush-light) 0%, var(--blush) 75%);
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- Layout ---------- */
.invitation-shell {
    height: 100vh;
    height: 100dvh;
    padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    text-align: center;
}

.intro { flex: none; line-height: 1.15; max-width: 100%; }
.brand { margin: 0 0 6px; font: italic 500 17px var(--serif); letter-spacing: .06em; color: var(--accent); }
h1 { margin: 0; font: 600 clamp(22px, 4vw, 44px) var(--serif); letter-spacing: .01em; color: var(--maroon); }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 13px; letter-spacing: .04em; }

.book-wrap {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: 1280px;
    padding-bottom: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---------- Stage ---------- */
.env-stage {
    position: relative;
    flex: none;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .7s ease, transform .7s ease;
    touch-action: pan-y;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}
.env-stage.is-ready { opacity: 1; transform: none; }

.floor-shadow {
    position: absolute;
    left: 50%;
    top: 72.5%;
    width: 52%;
    height: 3%;
    z-index: 0;
    transform: translateX(-50%);
    background: radial-gradient(ellipse at center, rgba(106, 10, 10, .30), transparent 70%);
    filter: blur(10px);
    pointer-events: none;
    transition: opacity .6s ease;
}

.canvas {
    position: absolute;
    inset: 0;
    perspective: 2200px;
    perspective-origin: 50% 50%;
    transition: transform 1s var(--ease);
}
.env-stage[data-step="0"] .canvas { transform: translateY(var(--closed-shift)); }

.layer { position: absolute; inset: 0; pointer-events: none; }
.layer img {
    display: block;
    width: 100%;
    height: 100%;
    -webkit-user-drag: none;
    user-select: none;
}

/* ---------- Urutan tumpukan ---------- */
.inner  { z-index: 1; }
.card   { z-index: 2; }
.pocket { z-index: 3; }
.flap   { z-index: 4; }

.inner  { transform: translateX(var(--body-dx)); }
.inner img, .pocket img { filter: drop-shadow(0 6px 10px rgba(106, 10, 10, .18)); }
.inner, .pocket { transition: opacity .7s ease; }

/* ujung samping kantong dipotong rata di garis engsel */
.pocket { clip-path: inset(var(--pocket-top) 0 0 0); }

/* ---------- Tutup amplop (flip 3D) ----------
   Daftar fungsi transform sengaja SAMA di keadaan tertutup & terbuka
   (translate + rotateX) supaya animasinya diinterpolasi per fungsi,
   bukan per matriks. Dengan begitu tutup naik halus sambil terbalik. */
.flap {
    transform-origin: 50% var(--hinge-y);
    transform: translate(var(--body-dx), 0%) rotateX(0deg) scale(1);
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    will-change: transform;
    transition: transform 1.05s var(--ease) .7s, z-index 0s 1.2s, opacity .3s ease;
}
.flap .face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
.flap .f-back {
    transform: rotateX(180deg);
    transform-origin: 50% var(--hinge-y);
}

/* ---------- Kartu (img 5) ---------- */
.card {
    transform-origin: var(--card-ox) var(--card-oy);
    opacity: 0;
    transform: translate(var(--card-dx), var(--card-inside-y)) scale(var(--card-inside-scale));
    will-change: transform, opacity;
    transition: opacity .4s ease .3s, transform .7s var(--ease);
}
.card img { filter: drop-shadow(0 8px 14px rgba(106, 10, 10, .20)); }

/* ---------- Halaman undangan (img 6, 7, 8) ----------
   .inv (keluar layar + z-index + fade) > .inv-o (membesar ke depan) > .inv-i (naik dari dalam amplop) */
.inv {
    z-index: 2;
    opacity: 0;
    transform: translateY(0) rotate(0deg);
    transform-origin: 50% 50%;
    transition: opacity .3s ease 1.6s, z-index 0s .95s, transform 1.1s var(--ease) 1.2s;
}
.inv-o, .inv-i {
    position: absolute;
    inset: 0;
    transform-origin: 50% 50%;
    will-change: transform;
}
.inv-o {
    transform: scale(1) translateY(0%);
    transition: transform 1.05s var(--ease) 0s;
}
.inv-i {
    transform: translateY(11%) scale(var(--inv-s));
    transition: transform .9s var(--ease) 1s;
}
.inv img { filter: drop-shadow(0 8px 14px rgba(106, 10, 10, .16)); }

/* ================= STATE PER LANGKAH =================
   0 tertutup | 1 tutup terbuka + kartu | 2 img 6 | 3 img 7 | 4 img 8 (RSVP) */

/* tutup terbuka: terbalik 180deg DAN naik sedikit (--flap-open-y) */
.env-stage:not([data-step="0"]) .flap {
    transform: translate(var(--body-dx), var(--flap-open-y)) rotateX(180deg) scale(var(--flap-open-scale));
    z-index: 1;
    transition: transform 1.05s var(--ease), z-index 0s .5s, opacity .3s ease;
}
.env-stage[data-step="1"] .card {
    opacity: 1;
    transform: translate(var(--card-dx), var(--card-out-y)) scale(var(--card-out-scale));
    transition: opacity .4s ease, transform 1.2s var(--ease);
}
.env-stage[data-step="1"][data-from="0"] .card {
    transition: opacity .4s ease 1s, transform 1.2s var(--ease) 1s;
}
.env-stage[data-step="1"][data-from="2"] .card {
    transition: opacity .1s linear 1.4s, transform 1.1s var(--ease) 1.5s;
}

/* kartu sampul meluncur keluar layar (tetap di sana untuk langkah 2-4) */
.env-stage:is([data-step="2"], [data-step="3"], [data-step="4"]) .card {
    opacity: 0;
    transform: translate(var(--card-dx), -150%) rotate(-3deg);
    transition: opacity .1s linear 1s, transform 1.1s cubic-bezier(.55, 0, .85, .45);
}

/* ---- halaman aktif: img 6 (langkah 2), img 7 (langkah 3), img 8 (langkah 4) ---- */
.env-stage[data-step="2"] .inv1,
.env-stage[data-step="3"] .inv2,
.env-stage[data-step="4"] .inv3 {
    z-index: 20;
    opacity: 1;
    transition: opacity .3s ease .55s, z-index 0s 1.45s, transform 1.1s var(--ease) 1.2s;
}
.env-stage:is([data-step="2"], [data-step="3"], [data-step="4"]) .inv1 .inv-i,
.env-stage:is([data-step="3"], [data-step="4"]) .inv2 .inv-i,
.env-stage[data-step="4"] .inv3 .inv-i {
    transform: translateY(var(--inv-rise)) scale(var(--inv-s));
    transition: transform .9s var(--ease) .55s;
}
.env-stage:is([data-step="2"], [data-step="3"], [data-step="4"]) .inv1 .inv-o,
.env-stage:is([data-step="3"], [data-step="4"]) .inv2 .inv-o,
.env-stage[data-step="4"] .inv3 .inv-o {
    /* kebalikan .inv-i, hasil akhirnya membesar sesuai --page-zoom */
    transform: scale(calc(var(--page-zoom) / var(--inv-s))) translateY(calc(-1 * var(--inv-rise)));
    transition: transform 1.05s var(--ease) 1.5s;
}

/* halaman sebelumnya meluncur keluar layar ke atas */
.env-stage:is([data-step="3"], [data-step="4"]) .inv1,
.env-stage[data-step="4"] .inv2 {
    z-index: 20;
    opacity: 0;
    transform: translateY(-150%) rotate(-3deg);
    transition: opacity .1s linear 1s, transform 1.1s cubic-bezier(.55, 0, .85, .45), z-index 0s 0s;
}

/* amplop TIDAK lagi dihilangkan saat halaman undangan keluar.
   Seberapa jelas ia terlihat diatur lewat --env-end-opacity (1 = penuh). */
.env-stage:is([data-step="2"], [data-step="3"], [data-step="4"]) .flap {
    opacity: var(--env-end-opacity);
    transition: transform 1.05s var(--ease), z-index 0s .5s, opacity .6s ease 1.7s;
}
.env-stage:is([data-step="2"], [data-step="3"], [data-step="4"]) :is(.inner, .pocket, .floor-shadow) {
    opacity: var(--env-end-opacity);
    transition: opacity .6s ease 1.7s;
}

.env-stage[data-step="4"] { cursor: default; }

/* ---------- Yth. nama tamu (di bawah tulisan "Yth." pada 5.png) ---------- */
.guest {
    position: absolute;
    left: 51.2%;
    top: 58.6%;
    width: 50%;
    transform: translateX(-50%);
    text-align: center;
    color: var(--maroon);
    pointer-events: none;
}
.guest[hidden] { display: none; }
.guest-name {
    display: block;
    font-family: var(--serif);
    font-weight: 600;
    font-size: calc(var(--pw, 400px) * 0.032);
    line-height: 1.1;
    overflow-wrap: anywhere;
}

/* ---------- RSVP (demo, di ruang kosong 8.png) ---------- */
.rsvp {
    position: absolute;
    left: 30%;                   /* (100% - width) / 2 supaya tepat di tengah */
    top: 34.2%;
    width: 40%;
    height: 43.5%;
    display: flex;
    flex-direction: column;
    gap: calc(var(--pw, 400px) * 0.012);
    padding: 2px 4px 6px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(154, 21, 21, .35) transparent;
    text-align: center;
    color: var(--maroon);
    font-family: var(--serif);
    font-size: max(8px, calc(var(--pw, 400px) * 0.022));
    pointer-events: none;
    user-select: text;
    -webkit-user-select: text;
}
.env-stage[data-step="4"] .rsvp { pointer-events: auto; }

.rsvp form { display: flex; flex-direction: column; align-items: center; gap: .7em; width: 100%; margin: auto 0; }
.rsvp form[hidden], .thanks[hidden] { display: none; }
.rsvp .f-row { display: flex; flex-direction: column; align-items: center; width: 100%; gap: .2em; margin: 0; padding: 0; border: 0; min-width: 0; }
.rsvp .f-label {
    padding: 0;
    font-family: var(--sans);
    font-size: .72em;
    letter-spacing: .04em;
    color: var(--muted);
}
.rsvp input[type="text"],
.rsvp select,
.rsvp textarea {
    width: 100%;
    padding: .35em .1em;
    border: 0;
    border-bottom: 1px solid rgba(154, 21, 21, .45);
    border-radius: 0;
    background: transparent;
    color: var(--maroon);
    font: inherit;
    font-size: 1.05em;
    line-height: 1.3;
    text-align: center;
    resize: none;
    user-select: text;
    -webkit-user-select: text;
}
.rsvp textarea { border: 1px solid rgba(154, 21, 21, .35); border-radius: 8px; padding: .4em .55em; background: rgba(247, 230, 226, .45); }
.rsvp input::placeholder, .rsvp textarea::placeholder { color: rgba(106, 10, 10, .4); }
.rsvp input[type="text"]:focus, .rsvp select:focus, .rsvp textarea:focus { outline: none; border-color: var(--red); }

/* pilihan jumlah tamu (muncul saat "Hadir") */
.rsvp select {
    width: auto;
    min-width: 8em;
    padding: .35em 1.4em .35em .6em;
    text-align: center;
    text-align-last: center;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background: rgba(247, 230, 226, .45)
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239a1515' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
        no-repeat right .5em center;
    border: 1px solid rgba(154, 21, 21, .35);
    border-radius: 8px;
}
.rsvp .f-row[hidden] { display: none; }

.pills { display: flex; flex-wrap: wrap; justify-content: center; gap: .4em; }
.pills label { cursor: pointer; }
.pills input { position: absolute; opacity: 0; pointer-events: none; }
.pills span {
    display: inline-block;
    padding: .25em .85em;
    border: 1px solid rgba(154, 21, 21, .5);
    border-radius: 30px;
    font-family: var(--sans);
    font-size: .78em;
    color: var(--maroon);
    transition: background .2s ease, color .2s ease;
}
.pills input:checked + span { background: var(--red); border-color: var(--red); color: #fff7f3; }
.pills input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.send {
    align-self: center;
    min-height: 2.4em;
    padding: 0 1.6em;
    border: 0;
    border-radius: 30px;
    background: var(--red);
    color: #fff7f3;
    font: 500 .8em var(--sans);
    letter-spacing: .03em;
    cursor: pointer;
    transition: background .2s ease, transform .15s ease, opacity .2s ease;
}
.send:hover:not(:disabled) { background: var(--maroon); }
.send:active:not(:disabled) { transform: scale(.97); }
.send:disabled { opacity: .55; cursor: wait; }

.status { min-height: 1.2em; margin: 0; text-align: center; font-family: var(--sans); font-size: .74em; color: var(--muted); }
.status.is-error { color: var(--red); }

/* ucapan terima kasih setelah kirim */
.thanks { margin: auto 0; text-align: center; }
.thanks-title { margin: 0 0 .3em; font-size: 1.5em; font-weight: 600; font-style: italic; }
.thanks-text { margin: 0; font-family: var(--sans); font-size: .85em; color: var(--muted); line-height: 1.4; }

/* ---------- Loader & hint ---------- */
.loader {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    z-index: 20;
    transition: opacity .4s ease, visibility .4s;
}
.loader span {
    width: 34px; height: 34px;
    border: 2px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .9s linear infinite;
}
.loader.is-hidden { opacity: 0; visibility: hidden; }
@keyframes spin { to { transform: rotate(360deg); } }

.hint {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    padding: 7px 16px;
    border-radius: 30px;
    background: var(--glass);
    border: 1px solid var(--line);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
    max-width: 94%;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity .4s ease;
    z-index: 10;
}
.hint.is-hidden { opacity: 0; pointer-events: none; }

/* ---------- Controls ---------- */
.controls {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 40px;
    background: var(--glass);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 6px 20px rgba(106, 10, 10, .10);
    font-size: 13px;
}
.controls button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 18px;
    border: 1px solid var(--line);
    border-radius: 30px;
    background: transparent;
    color: var(--maroon);
    cursor: pointer;
    font: inherit;
    transition: transform .15s ease, background .2s ease, border-color .2s ease;
}
.controls button:hover:not(:disabled) { background: rgba(255, 255, 255, .9); border-color: var(--accent); }
.controls button:active:not(:disabled) { transform: scale(.96); }
.controls button:disabled { opacity: .35; cursor: not-allowed; }

.progress { display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 120px; }
#pageCounter { color: var(--muted); font-size: 12px; letter-spacing: .03em; }

.dots { display: flex; gap: 6px; }
.dots i {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--line);
    cursor: pointer;
    transition: width .3s ease, background .3s ease;
}
.dots i.is-active { width: 22px; border-radius: 10px; background: var(--accent); }

/* ---------- Musik ---------- */
#musicBtn {
    --size: 46px;
    position: fixed;
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    z-index: 50;
    width: var(--size);
    height: var(--size);
    min-width: var(--size);
    min-height: var(--size);
    aspect-ratio: 1 / 1;
    flex: none;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--glass);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 6px 20px rgba(106, 10, 10, .10);
    color: var(--accent);
    cursor: pointer;
    transition: border-color .2s ease, transform .15s ease, background .2s ease;
}
#musicBtn:hover { border-color: var(--accent); background: rgba(255, 255, 255, .9); }
#musicBtn:active { transform: scale(.94); }
#musicBtn svg { grid-area: 1 / 1; transition: opacity .2s ease, transform .2s ease; }
#musicBtn .icon-pause { opacity: 0; transform: scale(.7); }
#musicBtn.is-playing .icon-play  { opacity: 0; transform: scale(.7); }
#musicBtn.is-playing .icon-pause { opacity: 1; transform: none; }

/* ---------- Responsive ---------- */
@media (max-width: 700px) {
    .invitation-shell { gap: 10px; padding-left: 10px; padding-right: 10px; }
    .intro { padding: 0 54px; }
    .brand { font-size: 15px; margin-bottom: 4px; }
    h1 { font-size: clamp(20px, 6.2vw, 28px); }
    .subtitle { display: none; }
    .controls { gap: 8px; padding: 6px; }
    .controls button span { display: none; }
    .controls button { width: 44px; padding: 0; justify-content: center; }
    .progress { min-width: 100px; }
    #musicBtn { --size: 42px; }
    .hint { font-size: 11px; }
}
@media (min-width: 701px) and (max-width: 1000px) {
    .controls button { padding: 0 14px; }
}
@media (max-height: 620px) {
    .subtitle, .brand { display: none; }
    h1 { font-size: 20px; }
}
@media (max-height: 480px) {
    .intro { display: none; }
    .dots, #pageCounter { display: none; }
    .progress { min-width: 0; }
    .invitation-shell { gap: 6px; padding-top: 8px; padding-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}