:root {
    --bg-1: #4a5a4f;
    --bg-2: #2c3730;
    --bg-3: #1d2520;
    --paper-edge: #d6cdbd;       /* warna cadangan kertas (bukan putih) */
    --ink: #f3eee4;
    --muted: #aeb8ac;
    --gold: #d3b97f;
    --glass: rgba(243, 238, 228, .08);
    --line: rgba(243, 238, 228, .2);
    --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
    --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);
}

.book-stage[data-state="front"] .book-holder { transform: translateX(-25%); }
.book-stage[data-state="back"]  .book-holder { transform: translateX(25%); }

.floor-shadow {
    position: absolute;
    left: 50%;
    bottom: -3%;
    width: 92%;
    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: width .7s ease;
}
.book-stage[data-state="front"] .floor-shadow,
.book-stage[data-state="back"]  .floor-shadow { width: 46%; }
.book-stage[data-state="portrait"] .floor-shadow { width: 84%; }

/* Bayangan lipatan tengah: lembut, tanpa garis/kilau putih */
.spine {
    position: absolute;
    top: 0; bottom: 0; left: 50%;
    width: 12%;
    max-width: 110px;
    transform: translateX(-50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity .4s ease;
    z-index: 5;
}
.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%);
}
.book-stage[data-state="open"] .spine { opacity: 1; }

#flipbook {
    position: absolute;
    inset: 0;
    touch-action: none;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}
#flipbook:active { cursor: grabbing; }

/* Mode HP: hanya sisi kiri dipotong (supaya halaman yang sudah terbuka
   cuma menyisakan sliver tipis). Atas, bawah, dan kanan dibiarkan bebas
   supaya lengkung dan perspektif kertas tidak terpotong. */
#flipbook.single { clip-path: inset(-60% -60% -60% 0); }

.leaf, .strip {
    position: absolute;
    top: 0;
    height: 100%;
    transform-origin: left 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);
    background-repeat: no-repeat;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
.face.back { transform: rotateY(180deg); }

/* kilau tipis (hangat, bukan putih murni) */
.face::before {
    content: "";
    position: absolute;
    inset: 0;
    background: #fff3dc;
    opacity: var(--h, 0);
    pointer-events: none;
    z-index: 1;
}
/* bayangan permukaan kertas */
.face::after {
    content: "";
    position: absolute;
    inset: 0;
    background: #2b1b0c;
    opacity: var(--s, 0);
    pointer-events: none;
    z-index: 3;
}

/* bayangan jatuh ke halaman di bawah kertas yang terangkat */
.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(243, 238, 228, .14); 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(243, 238, 228, .14); }
#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) ---------- */
/* Teks digandakan per strip kertas, jadi ukuran & padding harus dihitung
   dari --pw (lebar halaman), bukan persen dari induknya. */
.guest {
    --guest-color: #3b2a1a;
    position: absolute;
    top: 0;
    bottom: 7%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    text-align: center;
    color: var(--guest-color);
    font-family: var(--serif);
    pointer-events: none;
    padding: 0 calc(var(--pw) * 0.08);
    z-index: 2;
}
.guest-label {
    font-size: calc(var(--pw) * 0.035);
    font-style: italic;
    letter-spacing: .08em;
    opacity: .85;
}
.guest-name {
    font-size: calc(var(--pw) * 0.062);
    font-weight: 600;
    line-height: 1.15;
    word-break: break-word;
}

/* ---------- 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; }
}
