:root {
    --bg-1: #4a6fa5;
    --bg-2: #2c4a7c;
    --bg-3: #1b2f52;
    --ink: #f4f7fc;
    --muted: #c9d6ea;
    --gold: #dbe6f7;
    --glass: rgba(255, 255, 255, .10);
    --line: rgba(255, 255, 255, .28);
    --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
    --sans: "Jost", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;

    --ease-slide: cubic-bezier(.45, .05, .2, 1);
    --slide-ms: .9s;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg-3); }

body {
    color: var(--ink);
    font-family: var(--sans);
    background: radial-gradient(ellipse 70% 60% at 50% 42%, var(--bg-1) 0%, var(--bg-2) 55%, var(--bg-3) 100%);
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 2px solid var(--gold); 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(--gold); }
h1 { margin: 0; font: 600 clamp(22px, 4vw, 44px) var(--serif); letter-spacing: .01em; }
.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;
    overflow-x: clip;
}

/* ---------- Stage ---------- */
.book-stage {
    position: relative;
    flex: none;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .7s ease, transform .7s ease;
}
.book-stage.is-ready { opacity: 1; transform: none; }

.book-holder { position: relative; width: 100%; height: 100%; }

.floor-shadow {
    position: absolute;
    bottom: -3%;
    height: 6%;
    transform: translateX(-50%);
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, .42), transparent 70%);
    filter: blur(10px);
    pointer-events: none;
    transition: left var(--slide-ms) var(--ease-slide), width var(--slide-ms) var(--ease-slide);
}

#flipbook {
    position: absolute;
    inset: 0;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
    cursor: pointer;
    perspective: calc(var(--pw) * 3);
    perspective-origin: 50% 50%;
}

/* Semua lapisan seukuran 1 halaman, berada di slot tengah */
.layer {
    position: absolute;
    top: 0;
    left: var(--pw);
    width: var(--pw);
    height: var(--ph);
}
.layer img {
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
    -webkit-user-drag: none;
}
/* ---------- Halaman isi: bertumpuk, yang teratas slide ke bawah ---------- */
.page {
    box-shadow: 0 6px 24px rgba(0, 0, 0, .28);
    will-change: transform, opacity;
    transition:
        transform .95s cubic-bezier(.55, 0, .3, 1),
        opacity .5s ease .4s;                 /* memudar di paruh akhir, setelah mulai meluncur */
}
.page.p4 { z-index: 14; }
.page.p5 { z-index: 13; }
.page.p6 { z-index: 12; }
.page.p7 { z-index: 11; }

.page.out {
    transform: translateY(45%);
    opacity: 0;
    pointer-events: none;
}
/* saat kembali (tombol sebelumnya): muncul lebih dulu, lalu naik */
.page:not(.out) {
    transition:
        transform .95s cubic-bezier(.3, 0, .2, 1),
        opacity .3s ease;
}

/* Nama tamu: di tengah area kosong halaman 4 (antara tanggal dan tulisan Wedding Invitation) */
.guest {
    position: absolute;
    left: 0;
    top: 66%;
    width: 100%;
    height: 14%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0 14%;
    text-align: center;
    color: #234a85;
    pointer-events: none;
    z-index: 2;
}
.guest-label {
    font-size: calc(var(--pw) * 0.03);
    letter-spacing: .24em;
    text-transform: uppercase;
    opacity: .8;
    margin-bottom: calc(var(--pw) * 0.012);
}
.guest-name {
    font-family: var(--serif);
    font-size: calc(var(--pw) * 0.055);
    font-weight: 500;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

/* ---------- Alas kertas ---------- */
.backing {
    z-index: 15;
    background: #fff;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .28);
    transition: opacity .6s ease;
    pointer-events: none;
}
.backing.gone { opacity: 0; }

/* ---------- Penutup (di-flip seperti halaman buku) ---------- */
.cover {
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    transition: transform 1.1s var(--ease-slide);
    will-change: transform;
}
.cover.c3 { z-index: 30; transform-origin: right center; }  /* engsel di kanan */
.cover.c2 { z-index: 31; transform-origin: left center; }   /* engsel di kiri */

.cover.c2.out { transform: rotateY(-180deg); }   /* terbuka ke kiri */
.cover.c3.out { transform: rotateY(180deg); }    /* terbuka ke kanan */

.cover .face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
.cover .face.back { transform: rotateY(180deg); }
.cover .face img { filter: drop-shadow(0 6px 12px rgba(0, 0, 0, .28)); }

/* Sisi belakang dicerminkan: bunga berada di sisi engsel,
   jadi saat terbuka bunga 2 dan 3 menyambung ke halaman 4 */
.cover .face.back img { transform: scaleX(-1); }

/* ---------- Stempel ---------- */
.seal {
    z-index: 40;
    pointer-events: none;
    animation: sealPulse 2.4s ease-in-out infinite;
    transform-origin: 62.6% 45.4%;
}
.seal.open { animation: none; }
@keyframes sealPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.045); }
}

.seal-half {
    position: absolute;
    inset: 0;
    filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .35));
    transition:
        transform .95s cubic-bezier(.5, -.25, .4, 1),
        opacity .6s ease .3s;
    will-change: transform;
}
/* garis retakan bergerigi tepat di tengah stempel */
.seal-half.l {
    clip-path: polygon(0 0, 62.6% 0, 62.6% 41%, 61.6% 42.8%, 63.4% 44.4%, 61.8% 46%, 63.2% 47.6%, 62.2% 49.4%, 62.6% 51%, 62.6% 100%, 0 100%);
    transform-origin: 62.6% 45.4%;
}
.seal-half.r {
    clip-path: polygon(62.6% 0, 100% 0, 100% 100%, 62.6% 100%, 62.6% 51%, 62.2% 49.4%, 63.2% 47.6%, 61.8% 46%, 63.4% 44.4%, 61.6% 42.8%, 62.6% 41%);
    transform-origin: 62.6% 45.4%;
}
.seal.open .seal-half.l { transform: translate(-5%, 7%) rotate(-20deg); opacity: 0; }
.seal.open .seal-half.r { transform: translate(5%, 9%) rotate(22deg);  opacity: 0; }

/* ---------- 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(--gold);
    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);
    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(--ink);
    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, .18); border-color: var(--gold); }
.controls button:active:not(:disabled) { transform: scale(.96); }
.controls button:disabled { opacity: .3; 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(--gold); }

/* ---------- 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);
    color: var(--gold);
    cursor: pointer;
    transition: border-color .2s ease, transform .15s ease, background .2s ease;
}
#musicBtn:hover { border-color: var(--gold); background: rgba(255, 255, 255, .18); }
#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-duration: .01ms !important; }
}

/* ---------- Form RSVP di halaman 7 ---------- */
.frsvp {
    --navy: #234a85;
    --line: rgba(35, 74, 133, .55);
    --script: "Mea Culpa", "Cormorant Garamond", cursive;
    position: absolute;
    left: 21%;
    right: 21%;
    top: 20%;
    bottom: 11%;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;          /* isi form rata tengah secara vertikal */
    gap: calc(var(--pw) * 0.02);
    padding: 2px;
    overflow-x: hidden;
    overflow-y: auto;
    text-align: center;
    color: var(--navy);
    font-family: var(--serif);
    cursor: auto;
    user-select: text;
    -webkit-user-select: text;
    scrollbar-width: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s ease, visibility 0s .25s;
}
.frsvp::-webkit-scrollbar { display: none; }

.frsvp.show {
    opacity: 1;
    visibility: visible;
    transition: opacity .4s ease .55s, visibility 0s .55s;   /* muncul setelah kartu selesai berputar */
}

.frsvp > * { flex: none; width: 100%; }

/* ---------- Label: tulisan tangan ---------- */
.frsvp-lbl {
    display: block;
    margin: 0;
    font: 400 calc(var(--pw) * 0.062) / 1.05 var(--script);
    text-align: center;
    color: var(--navy);
}

/* ---------- Nama & jumlah tamu: garis tipis ---------- */
.frsvp input[type="text"],
.frsvp select {
    width: 100%;
    padding: 1px 4px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
    color: var(--navy);
    font: 500 16px/1.2 var(--serif);     /* 16px = batas minimum agar iOS tidak zoom */
    text-align: center;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color .2s ease;
}
.frsvp input[type="text"]:focus,
.frsvp select:focus { border-bottom-color: var(--navy); }
.frsvp ::placeholder { color: var(--navy); opacity: .38; font-style: italic; font-size: 13px; }

/* ---------- Hadir / Tidak hadir ---------- */
.frsvp-choice { display: flex; gap: 6px; margin-top: 2px; }
.frsvp-choice label { flex: 1; position: relative; }
.frsvp-choice input { position: absolute; opacity: 0; pointer-events: none; }
.frsvp-choice span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 0 6px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    color: var(--navy);
    white-space: nowrap;
    font: 500 clamp(11px, calc(var(--pw) * 0.034), 13px) / 1 var(--serif);
    cursor: pointer;
    transition: background .2s ease, color .2s ease, border-color .2s ease;
}
.frsvp-choice label:hover span { border-color: var(--navy); }
.frsvp-choice input:checked + span {
    background: var(--navy);
    border-color: var(--navy);
    color: #fff;
}
.frsvp-choice input:focus-visible + span { outline: 2px solid var(--navy); outline-offset: 2px; }

/* ---------- Jumlah tamu ---------- */
.frsvp-guests { display: flex; flex-direction: column; align-items: center; }
.frsvp-guests[hidden] { display: none; }
.frsvp-guests select {
    width: auto;
    min-width: 84px;
    padding-right: 16px;
    text-align-last: center;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23234a85' stroke-width='1.2'/%3E%3C/svg%3E")
        no-repeat right 3px center;
}

/* ---------- Ucapan ---------- */
.frsvp-wish { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 50px; max-height: 90px; }
.frsvp-wish textarea {
    flex: 1;
    width: 100%;
    height: auto;
    min-height: 36px;
    resize: none;
    padding: 4px 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .4);
    color: var(--navy);
    font: 500 16px/1.25 var(--serif);
    text-align: left;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color .2s ease, background .2s ease;
}
.frsvp-wish textarea:focus { border-color: var(--navy); background: rgba(255, 255, 255, .65); }

/* ---------- Tombol Kirim ---------- */
.frsvp-submit {
    width: auto;
    min-width: 48%;
    min-height: 28px;
    margin-top: 2px;
    padding: 0 18px;
    border: 1px solid var(--navy);
    border-radius: 999px;
    background: var(--navy);
    color: #fff;
    font: 600 clamp(10px, calc(var(--pw) * 0.03), 12px) var(--serif);
    letter-spacing: .24em;
    text-transform: uppercase;
    cursor: pointer;
    transition: opacity .2s ease, transform .15s ease;
}
.frsvp-submit:active:not(:disabled) { transform: scale(.97); }
.frsvp-submit:disabled { opacity: .5; cursor: wait; }

.frsvp-status { margin: 0; font: 500 clamp(11px, calc(var(--pw) * 0.03), 13px) var(--serif); text-align: center; }
.frsvp-status:empty { display: none; }
.frsvp-status.err { color: #b3261e; }

/* ---------- Setelah terkirim ---------- */
.frsvp-thanks { display: none; margin: auto; text-align: center; line-height: 1.3; }
.frsvp-thanks strong { display: block; font: 400 calc(var(--pw) * 0.1) / 1.1 var(--script); margin-bottom: 4px; }
.frsvp-thanks span { font: 500 calc(var(--pw) * 0.034) var(--serif); }
.frsvp.done > :not(.frsvp-thanks) { display: none; }
.frsvp.done .frsvp-thanks { display: block; }

.frsvp-hp { position: absolute; left: -9999px; width: 0; height: 0; opacity: 0; }

