:root {
    --bg-1: #a67590;
    --bg-2: #7c4f68;
    --bg-3: #4f2f43;
    --paper-edge: #ffffff;
    --ink: #fbf5f7;
    --muted: #e3cfd9;
    --gold: #f3dce7;                 /* aksen blush, menggantikan emas */
    --plum: #90617b;                 /* warna ungu undangan */
    --glass: rgba(255, 255, 255, .10);
    --line: rgba(255, 255, 255, .28);
    --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
    --script: "Allura", "Cormorant Garamond", cursive;
    --sans: "Jost", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}

* { 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;
}

/* ---------- Book ---------- */
.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%;
    transition: transform .7s cubic-bezier(.4, .1, .2, 1);
}

/* Penggulung horizontal untuk buku (dipakai di HP) */
.book-scroll {
    width: 100%;
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 12px 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}
.book-scroll::-webkit-scrollbar { display: none; }

/* Lebar clip = area halaman yang sedang terbuka; auto margin = rata tengah aman */
.book-clip {
    position: relative;
    flex: none;
    margin: 0 auto;
    overflow-x: clip;
}
.book-clip .book-stage {
    position: absolute;
    top: 0;
}

/* Posisi & lebar diatur JS (mengikuti area yang terbuka) */
.floor-shadow {
    position: absolute;
    left: 50%;
    bottom: -3%;
    width: 30%;
    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 .7s ease, width .7s ease;
}

/* Halaman 3: diam di tengah, paling bawah tumpukan */
.base {
    position: absolute;
    top: 0;
    height: 100%;
    z-index: 1;
    background-color: var(--paper-edge);
    background-repeat: no-repeat;
}

/* Bayangan lipatan di engsel: lembut, tanpa garis/kilau putih.
   Posisi (left) & lebar diatur JS; muncul lewat class .on */
.spine {
    position: absolute;
    top: 0; bottom: 0;
    transform: translateX(-50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity .4s ease;
    z-index: 5;
}
.spine.on { opacity: 1; }
.spine::before,
.spine::after {
    content: "";
    position: absolute;
    top: 0; bottom: 0;
    width: 50%;
}
.spine::before {
    left: 0;
    background: linear-gradient(to right,
        rgba(40, 25, 10, 0) 0%,
        rgba(40, 25, 10, .02) 35%,
        rgba(40, 25, 10, .06) 65%,
        rgba(40, 25, 10, .13) 100%);
}
.spine::after {
    right: 0;
    background: linear-gradient(to left,
        rgba(40, 25, 10, 0) 0%,
        rgba(40, 25, 10, .02) 35%,
        rgba(40, 25, 10, .06) 65%,
        rgba(40, 25, 10, .13) 100%);
}

#flipbook {
    position: absolute;
    inset: 0;
    touch-action: none;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}
#flipbook:active { cursor: grabbing; }

.leaf, .strip {
    position: absolute;
    top: 0;
    height: 100%;
    transform-origin: left center;   /* daun page2 menimpa ini lewat inline style (right center) */
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
}
.leaf { will-change: transform; }

.face {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    overflow: hidden;
    background-color: var(--paper-edge);   /* hanya cadangan; JS membuatnya transparan jika ada gambar */
    background-repeat: no-repeat;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
.face.back { transform: rotateY(180deg); }

/* kilau & bayangan hanya menempel pada bagian gambar yang tidak transparan
   (supaya potongan bergelombang di PNG tidak berubah jadi kotak) */
.face::before,
.face::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    -webkit-mask-image: var(--img);
    mask-image: var(--img);
    -webkit-mask-size: var(--msize);
    mask-size: var(--msize);
    -webkit-mask-position: var(--mpos);
    mask-position: var(--mpos);
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
}
/* kilau tipis (hangat, bukan putih murni) */
.face::before {
    background: #fff3dc;
    opacity: var(--h, 0);
    z-index: 1;
}
/* bayangan permukaan kertas */
.face::after {
    background: #2b1b0c;
    opacity: var(--s, 0);
    z-index: 3;
}

/* bayangan jatuh ke halaman di bawah kertas yang terangkat (mask diatur JS) */
.cast {
    position: absolute;
    top: 0;
    height: 100%;
    z-index: 150;
    opacity: 0;
    pointer-events: none;
}
.cast.right { background: linear-gradient(to right, rgba(40, 25, 10, .5), transparent 70%); }
.cast.left  { background: linear-gradient(to left,  rgba(40, 25, 10, .5), transparent 70%); }

/* ---------- 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 (tombol play / pause) ---------- */
#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; }
/* ---------- Yth. tamu undangan (sampul / page1 depan) ---------- */
/* Rata kiri sejajar nama mempelai, di area putih bawah, jauh dari bunga */
.guest {
    --guest-color: #8a5a72;
    position: absolute;
    top: 90%;
    bottom: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    text-align: left;
    color: var(--guest-color);
    pointer-events: none;
    padding-left: calc(var(--pw) * 0.10);
    padding-right: calc(var(--pw) * 0.50);   /* sisakan ruang untuk bunga di kanan */
    z-index: 2;
}
.guest-label {
    font-family: var(--sans);
    font-size: calc(var(--pw) * 0.03);
    font-weight: 400;
    letter-spacing: .22em;
    text-transform: uppercase;
    opacity: .8;
    margin-bottom: calc(var(--pw) * 0.01);
}
.guest-name {
    font-family: var(--serif);
    font-size: calc(var(--pw) * 0.04);
    font-weight: 400;
    line-height: 1.1;
    overflow-wrap: anywhere;
}

/* ---------- Responsive ---------- */
@media (max-width: 700px) {
    .invitation-shell { gap: 10px; padding-left: 10px; padding-right: 10px; }
    .intro { padding: 0 54px; }            /* beri ruang untuk tombol musik */
    .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; }
}

