/* ==========================================================================
   majalah-book.css — Pembaca "Buku Digital" Majalah UDI
   Tampilan menyerupai buku sungguhan: sampul keras, buku terjadilah,
   bayangan tulang (gutter), tepi tumpukan kertas, dan animasi balik
   halaman 3D yang bisa digeser (drag) pengguna.
   ========================================================================== */

.book-reader {
    --book-paper: #fbf9f4;
    --book-paper-edge: #e8e2d5;
    --book-ink: #1c1c1e;
    --book-cover-1: #0b1e4b;
    --book-cover-2: #16306e;
    --book-gold: #caa22e;
    --book-ambient-1: #efe9dd;
    --book-ambient-2: #ded4c3;
    --book-ambient-3: #cfc3ae;
    --book-shadow: rgba(28, 22, 12, .34);

    position: relative;
    max-width: 1180px;
    margin: 0 auto;
    padding: 1.5rem .75rem 2.25rem;
    border-radius: 18px;
    background:
        radial-gradient(120% 80% at 50% -10%, rgba(255, 255, 255, .75), rgba(255, 255, 255, 0) 60%),
        linear-gradient(180deg, var(--book-ambient-1) 0%, var(--book-ambient-2) 62%, var(--book-ambient-3) 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 18px 44px rgba(60, 45, 25, .16);
    overflow: hidden;
    min-height: 540px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    touch-action: pan-y;
    -webkit-tap-highlight-color: transparent;
}

/* Ambient vignette supaya buku terasa "berdiri" di meja */
.book-reader::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(70% 55% at 50% 45%, rgba(0, 0, 0, 0) 40%, rgba(60, 45, 25, .16) 100%);
}

/* Saat diperbesar melebihi layar, panggung boleh digulir. */
.book-reader.is-zoomed {
    overflow: auto;
    align-items: flex-start;
    justify-content: flex-start;
}
.book-reader.is-zoomed .book,
.book-reader.is-zoomed .book-cover {
    margin: auto;
}

/* ---------------------------------------------------------------- status */
.book-status {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .85rem;
    color: #4a3f2c;
    z-index: 40;
    text-align: center;
    padding: 2rem;
}
.book-status .spinner-border { color: var(--book-cover-1); }
.book-status-err { color: #8a2b1f; }

/* ================================================================ SAMPUL */
.book-cover {
    position: relative;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
    perspective: 1600px;
}

.book-cover-body {
    position: relative;
    border-radius: 4px 14px 14px 4px;
    overflow: hidden;
    background: linear-gradient(135deg, var(--book-cover-1) 0%, var(--book-cover-2) 100%);
    box-shadow:
        0 26px 60px rgba(20, 15, 5, .42),
        0 3px 10px rgba(20, 15, 5, .3),
        inset 0 0 0 1px rgba(255, 255, 255, .12);
    transform-origin: left center;
    transition: transform .75s cubic-bezier(.2, .7, .2, 1), opacity .45s ease;
    cursor: pointer;
}

/* Punggung buku (spine) */
.book-cover-body::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 26px;
    z-index: 3;
    background: linear-gradient(90deg, rgba(0, 0, 0, .55), rgba(0, 0, 0, .12) 55%, rgba(255, 255, 255, .16));
    pointer-events: none;
}
/* Garis emas tipis tepi sampul */
.book-cover-body::after {
    content: "";
    position: absolute;
    inset: 12px;
    z-index: 3;
    border: 1px solid rgba(202, 162, 46, .55);
    border-radius: 2px 8px 8px 2px;
    pointer-events: none;
}

.book-cover canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-cover-open .book-cover-body {
    transform: rotateY(-155deg) translateX(-6%);
    opacity: 0;
    pointer-events: none;
}

.book-cover-hint {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    border: 0;
    border-radius: 999px;
    padding: .65rem 1.5rem;
    font-size: .9rem;
    font-weight: 700;
    letter-spacing: .02em;
    color: #fff;
    background: linear-gradient(135deg, var(--book-cover-1), var(--book-cover-2));
    box-shadow: 0 10px 24px rgba(11, 30, 75, .32);
    cursor: pointer;
    transition: transform .18s ease, box-shadow .18s ease;
}
.book-cover-hint:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(11, 30, 75, .4); }
.book-cover-hint:active { transform: translateY(0); }
.book-cover-hint[disabled] { opacity: .55; cursor: progress; }

/* ================================================================= BUKU */
.book {
    position: relative;
    z-index: 5;
    display: none;
    transform-style: preserve-3d;
    perspective: 2800px;
    perspective-origin: 50% 42%;
}
.book.is-open { display: block; }

.book-pages {
    position: relative;
    display: flex;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.book-leaf {
    position: relative;
    flex: 1 1 50%;
    height: 100%;
    background: var(--book-paper);
    overflow: hidden;
    box-shadow: 0 12px 34px var(--book-shadow);
}
/* Tepi tumpukan kertas di sisi luar */
.book-leaf--left {
    border-radius: 3px 1px 1px 3px;
    background-image: linear-gradient(270deg, rgba(0, 0, 0, .07), rgba(0, 0, 0, 0) 42px);
}
.book-leaf--right {
    border-radius: 1px 3px 3px 1px;
    background-image: linear-gradient(90deg, rgba(0, 0, 0, .07), rgba(0, 0, 0, 0) 42px);
}

.book-leaf canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: var(--book-paper);
}

/* Halaman kosong (mis. sampul berdiri sendiri di sisi kanan) */
.book-leaf--empty {
    background: linear-gradient(90deg, #ece5d6, #e6decd 60%, #ddd4c1);
    box-shadow: inset 0 0 40px rgba(90, 70, 40, .16);
}
.book-leaf--empty::after {
    content: "Halaman Kosong";
    position: absolute;
    inset: auto 0 1.1rem;
    text-align: center;
    font-size: .72rem;
    letter-spacing: .22em;
    text-transform: uppercase;
    color: rgba(90, 70, 40, .45);
}

/* Tulang buku / gutter */
.book-gutter {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 84px;
    transform: translateX(-50%);
    z-index: 6;
    pointer-events: none;
    background: linear-gradient(90deg,
        rgba(0, 0, 0, 0) 0%,
        rgba(70, 55, 30, .10) 32%,
        rgba(50, 38, 18, .26) 47%,
        rgba(30, 22, 8, .38) 50%,
        rgba(50, 38, 18, .26) 53%,
        rgba(70, 55, 30, .10) 68%,
        rgba(0, 0, 0, 0) 100%);
}
.book:not(.book-mode-single) .book-gutter { display: block; }
.book.book-mode-single .book-gutter { display: none; }

/* Mode satu halaman: daun kosong disembunyikan agar halaman memenuhi buku. */
.book-mode-single .book-leaf--left { display: none; }
.book-mode-single .book-leaf--right {
    flex: 1 1 100%;
    border-radius: 3px;
}

/* Bayangan jatuh di bawah buku */
.book-shadow {
    position: absolute;
    left: 6%;
    right: 6%;
    bottom: -26px;
    height: 34px;
    z-index: 1;
    background: radial-gradient(50% 50% at 50% 0%, rgba(40, 30, 12, .42), rgba(40, 30, 12, 0) 72%);
    filter: blur(3px);
    pointer-events: none;
}

/* ==================================================== LEMBAR BALIK HALAMAN */
.book-flip {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 20;
    width: 50%;
    transform-style: preserve-3d;
    will-change: transform;
    pointer-events: none;
}
.book-flip--next {
    left: 50%;
    transform-origin: left center;
    transform: rotateY(0deg);
    box-shadow: -14px 0 30px rgba(30, 22, 8, .28);
}
.book-flip--prev {
    left: 0;
    transform-origin: right center;
    transform: rotateY(0deg);
    box-shadow: 14px 0 30px rgba(30, 22, 8, .28);
}

/* Mode satu halaman: satu lembar menutupi seluruh lebar buku. */
.book-mode-single .book-flip { width: 100%; }
.book-mode-single .book-flip--next { left: 0; }

.book-flip-face {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: var(--book-paper);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
.book-flip-face canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: var(--book-paper);
}
.book-flip-back { transform: rotateY(180deg); }

/* Kertas kosong pada lembar yang dibalik (mis. halaman terakhir) */
.book-flip-face.is-blank,
.book-leaf.is-blank {
    background: linear-gradient(90deg, #ece5d6, #e6decd 60%, #ddd4c1);
}
.book-leaf.is-blank::after {
    content: "Halaman Kosong";
    position: absolute;
    inset: auto 0 1.1rem;
    text-align: center;
    font-size: .72rem;
    letter-spacing: .22em;
    text-transform: uppercase;
    color: rgba(90, 70, 40, .45);
}

/* Bayangan yang menyapu saat halaman dibalik */
.book-flip-shade {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    background: linear-gradient(90deg, rgba(0, 0, 0, 0), rgba(30, 22, 8, .38));
    opacity: 0;
}

/* Sudut lipatan yang muncul saat digeser (drag) */
.book-corner {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 76px;
    height: 76px;
    z-index: 22;
    cursor: grab;
    background: linear-gradient(315deg, rgba(202, 162, 46, .32) 0%, rgba(202, 162, 46, 0) 55%);
    border-bottom-right-radius: 4px;
    transition: opacity .2s ease;
}
.book-corner:active { cursor: grabbing; }
.book-mode-single .book-corner { display: none; }
.book-corner--prev {
    left: 0;
    right: auto;
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 4px;
    background: linear-gradient(45deg, rgba(202, 162, 46, .32) 0%, rgba(202, 162, 46, 0) 55%);
}
.book-corner--prev .book-corner-hint { right: auto; left: 10px; }
.book-corner-hint {
    position: absolute;
    right: 10px;
    bottom: 8px;
    font-size: 1.05rem;
    color: rgba(60, 48, 20, .55);
    pointer-events: none;
}

/* Bayangan lipatan dibalik saat halaman maju vs mundur. */
.book-flip--prev .book-flip-shade {
    background: linear-gradient(270deg, rgba(0, 0, 0, 0), rgba(30, 22, 8, .38));
}

/* ============================================================== KONTROL */
.book-toolbar {
    position: relative;
    z-index: 30;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: .45rem;
    width: 100%;
}

.book-btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    border: 1px solid rgba(11, 30, 75, .2);
    background: #fff;
    color: var(--book-cover-1);
    border-radius: .55rem;
    padding: .45rem .7rem;
    font-size: .8rem;
    font-weight: 600;
    transition: .15s;
    cursor: pointer;
    white-space: nowrap;
}
.book-btn:hover:not(:disabled) { background: #f3f5fa; border-color: rgba(11, 30, 75, .38); }
.book-btn.active { background: var(--book-cover-1); color: #fff; border-color: var(--book-cover-1); }
.book-btn:disabled { opacity: .38; cursor: not-allowed; }

.book-pagenum {
    color: var(--book-cover-1);
    font-weight: 800;
    font-size: .86rem;
    min-width: 92px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.book-zoomval {
    min-width: 48px;
    text-align: center;
    font-size: .78rem;
    font-weight: 700;
    color: #4a3f2c;
}

/* Slider zoom */
.book-zoomer {
    -webkit-appearance: none;
    appearance: none;
    width: 110px;
    height: 4px;
    border-radius: 4px;
    background: rgba(11, 30, 75, .18);
    outline: none;
}
.book-zoomer::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--book-cover-1);
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .28);
    cursor: pointer;
}
.book-zoomer::-moz-range-thumb {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--book-cover-1);
    border: 2px solid #fff;
    cursor: pointer;
}

.book-hintline {
    position: relative;
    z-index: 30;
    margin: 0;
    text-align: center;
    font-size: .78rem;
    color: #5c513c;
}

/* ============================================================== THUMBNAIL */
.book-sheet {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: none;
    background: rgba(18, 14, 6, .62);
    backdrop-filter: blur(3px);
    padding: 1.5rem;
}
.book-sheet.is-open { display: block; }

.book-sheet-panel {
    position: relative;
    max-width: 1080px;
    max-height: 84vh;
    margin: 0 auto;
    background: var(--book-paper);
    border-radius: 14px;
    box-shadow: 0 30px 70px rgba(0, 0, 0, .5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.book-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .85rem 1.1rem;
    border-bottom: 1px solid rgba(11, 30, 75, .12);
    background: #fff;
}
.book-sheet-head h3 { margin: 0; font-size: .98rem; font-weight: 800; color: var(--book-cover-1); }
.book-sheet-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
    gap: .75rem;
    padding: 1rem;
    overflow-y: auto;
}
.book-thumb {
    position: relative;
    border: 2px solid transparent;
    border-radius: 5px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .16);
    cursor: pointer;
    padding: 0;
    aspect-ratio: 3 / 4;
    transition: border-color .15s, transform .15s;
}
.book-thumb:hover { transform: translateY(-2px); border-color: var(--book-gold); }
.book-thumb.is-current { border-color: var(--book-cover-1); }
.book-thumb canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.book-thumb span {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    padding: .15rem;
    font-size: .68rem;
    font-weight: 700;
    color: #fff;
    background: rgba(11, 30, 75, .82);
}

/* ================================================================ MUSIK */
/* Pemutar YouTube disembunyikan supaya yang terdengar hanya audionya. */
.book-music-yt {
    position: absolute;
    width: 1px;
    height: 1px;
    left: -9999px;
    top: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}
.book-music-yt iframe {
    width: 1px;
    height: 1px;
    border: 0;
}

/* Panel mengambang: putar/jeda, ganti lagu, mode pengulangan, judul lagu. */
.book-musicbar {
    position: absolute;
    top: .85rem;
    right: .85rem;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: .3rem;
    max-width: min(560px, calc(100% - 1.7rem));
    padding: .3rem .5rem .3rem .3rem;
    border-radius: 999px;
    background: rgba(11, 30, 75, .82);
    box-shadow: 0 6px 16px rgba(0, 0, 0, .24);
}
.book-musicbar:empty { display: none; }

.book-music-btn {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: rgba(255, 255, 255, .82);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: .18s;
    font-size: .95rem;
    padding: 0;
}
.book-music-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .16); color: #fff; }
.book-music-btn:disabled { opacity: .3; cursor: default; }
.book-music-btn.is-off { color: rgba(255, 255, 255, .38); }
.book-music-btn.is-one { color: var(--book-gold); }

.book-music-title {
    flex: 0 1 auto;
    min-width: 0;
    margin-left: .25rem;
    padding-right: .4rem;
    color: rgba(255, 255, 255, .92);
    font-size: .76rem;
    letter-spacing: .01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.book-music-title:empty { display: none; }

.book-music {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 0;
    background: var(--book-gold);
    color: #1e2b45;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: .2s;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .3);
    padding: 0;
}
.book-music:hover { transform: scale(1.06); }
.book-music.playing { background: var(--book-gold); }
.book-music .book-eq { display: none; gap: 3px; align-items: flex-end; height: 15px; }
.book-music.playing .book-eq { display: flex; }
.book-music.playing .bi-music-note-beamed { display: none; }
.book-eq span {
    display: block;
    width: 3px;
    background: #1e2b45;
    animation: bookEq 1s ease-in-out infinite;
}
.book-eq span:nth-child(1) { height: 8px; }
.book-eq span:nth-child(2) { height: 15px; animation-delay: .18s; }
.book-eq span:nth-child(3) { height: 11px; animation-delay: .36s; }
@keyframes bookEq {
    0%, 100% { transform: scaleY(.45); }
    50% { transform: scaleY(1); }
}

/* ============================================================= RESPONSIF */
@media (max-width: 992px) {
    .book-reader { padding: 1rem .5rem 1.75rem; border-radius: 14px; }
}

@media (max-width: 640px) {
    .book-reader { min-height: 420px; }
    .book-gutter { width: 44px; }
    .book-corner { width: 58px; height: 58px; }
    .book-btn { padding: .4rem .55rem; font-size: .74rem; }
    .book-zoomer { width: 80px; }
    .book-pagenum { min-width: 74px; font-size: .78rem; }
    .book-leaf--empty::after { font-size: .6rem; }
    .book-hintline { font-size: .72rem; }
}

@media (prefers-reduced-motion: reduce) {
    .book-cover-body, .book-thumb { transition: none; }
    .book-eq span { animation: none; }
}
