/* ===========================================================
   book.css — eBook viewer (golden cream theme, reads book.pdf)
   =========================================================== */

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
    background:
        radial-gradient(ellipse at 50% 38%, #fffcf2 0%, rgba(255,252,242,0) 62%),
        radial-gradient(circle at 6% 8%, rgba(243,214,122,0.35) 0, rgba(243,214,122,0) 40%),
        radial-gradient(circle at 96% 94%, rgba(243,214,122,0.38) 0, rgba(243,214,122,0) 42%),
        #fdf4dc;
    font-family: sans-serif;
    touch-action: none; /* let our custom pinch handler control gestures */
}

#stage {
    position: relative;
    width: 100%;
    height: calc(100% - 90px); /* leave room for bottom bar */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#zoomWrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: center center;
    transition: transform 0.05s linear;
}

#book {
    box-shadow: 0 0 30px rgba(120,85,15,0.4);
    flex: 0 0 auto;
}

.my-page {
    background: #fffaf0;
    position: relative;
    overflow: hidden;
    /* subtle paper-like inner edge so interior pages read as thin paper */
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.04);
}
.my-page img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    opacity: 0;
    transition: opacity 0.35s ease;
    -webkit-user-select: none;
    user-select: none;
    cursor: zoom-in;
}
.my-page img.ready { opacity: 1; }

/* gold shimmer while a page is still being rendered from the PDF */
.my-page.is-loading::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, transparent 30%, rgba(243,214,122,0.4) 50%, transparent 70%);
    background-size: 220% 100%;
    animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer {
    from { background-position: 120% 0; }
    to   { background-position: -120% 0; }
}

/* ---------- Front cover (first PDF page only) ---------- */
.my-page.cover-page {
    background: linear-gradient(150deg, #2b2b2b 0%, #1a1a1a 55%, #262626 100%);
    border-radius: 6px;
    position: relative;
    /* layered inset shadows fake a thick board edge + slight sheen */
    box-shadow:
        inset 0 0 0 2px rgba(255,255,255,0.06),
        inset 0 0 55px rgba(0,0,0,0.55),
        inset 0 2px 0 rgba(255,255,255,0.08),
        0 0 25px rgba(0,0,0,0.5);
}
.my-page.cover-page img {
    border-radius: 6px;
    filter: contrast(1.08) saturate(1.05);
}
/* faint printed-cardboard grain, purely decorative */
.my-page.cover-page::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: 6px;
    background: repeating-linear-gradient(115deg, rgba(255,255,255,0.025) 0 2px, transparent 2px 4px);
    mix-blend-mode: overlay;
}

/* ---------- Bottom control bar ---------- */
#controls {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(253,240,200,0.92);
    backdrop-filter: blur(6px);
    box-shadow: 0 -2px 10px rgba(138,97,24,0.18);
    border-top: 2px solid rgba(217,169,58,0.6);
}

.btn-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

button {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    border: none;
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 15px;
    font-weight: bold;
    color: white;
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

button.pressed {
    transform: translateY(2px) scale(0.97);
}

#prevBtn {
    background: linear-gradient(180deg, #ff8a80 0%, #e53935 55%, #b71c1c 100%);
    box-shadow: 0 4px 0 #7f0000, 0 6px 10px rgba(0,0,0,0.35);
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
#prevBtn.pressed {
    box-shadow: 0 2px 0 #7f0000, 0 3px 6px rgba(0,0,0,0.35);
}

#nextBtn {
    background: linear-gradient(180deg, #a5f5b3 0%, #43a047 55%, #1b5e20 100%);
    box-shadow: 0 4px 0 #0b3d0e, 0 6px 10px rgba(0,0,0,0.35);
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
#nextBtn.pressed {
    box-shadow: 0 2px 0 #0b3d0e, 0 3px 6px rgba(0,0,0,0.35);
}

#downloadBtn {
    color: white;
    text-decoration: none;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(180deg, #64b5f6 0%, #2196f3 55%, #1565c0 100%);
    box-shadow: 0 3px 0 #0d47a1, 0 5px 10px rgba(21,101,192,0.35);
    text-shadow: 0 1px 2px rgba(0,0,0,0.35);
    padding: 6px 14px;
    font-size: 12px;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    isolation: isolate;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
/* diagonal light sweep across the button on hover */
#downloadBtn::before {
    content: "";
    position: absolute;
    top: 0;
    left: -60%;
    width: 40%;
    height: 100%;
    background: linear-gradient(115deg, transparent, rgba(255,255,255,0.65), transparent);
    transform: skewX(-20deg);
    transition: left 0.55s ease;
    z-index: 1;
}
/* diagonal light sweep across the button on hover (real-hover devices only) */
@media (hover: hover) {
    #downloadBtn:hover::before { left: 130%; }
    #downloadBtn:hover {
        transform: translateY(-2px);
        box-shadow: 0 5px 0 #0d47a1, 0 10px 18px rgba(21,101,192,0.45), 0 0 14px rgba(100,181,246,0.55);
    }
    #downloadBtn:hover .dl-icon { animation: dl-bounce 0.7s ease infinite; }
}
#downloadBtn.pressed {
    background: linear-gradient(180deg, #64b5f6 0%, #1976d2 55%, #0d47a1 100%);
    transform: translateY(1px) scale(0.98);
    box-shadow: 0 2px 0 #0d47a1, 0 3px 6px rgba(21,101,192,0.35);
}
#downloadBtn .dl-icon {
    display: inline-block;
    transition: transform 0.3s ease;
}
@keyframes dl-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(3px); }
}


/* Previous / Next greyed out at the first / last page */
#prevBtn.is-disabled, #nextBtn.is-disabled {
    opacity: 0.4;
    pointer-events: none;
    filter: grayscale(0.5);
}

/* ---------- Loader ---------- */
#loader {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(253,244,220,0.85);
    backdrop-filter: blur(4px);
}
#loader.show { display: flex; }
.loader-card {
    width: min(320px, 86vw);
    padding: 26px 24px;
    text-align: center;
    border-radius: 18px;
    background: linear-gradient(180deg, #fffdf5, #fbefc9);
    border: 2px solid #d9a93a;
    box-shadow: 0 14px 40px rgba(138,97,24,0.35);
    color: #5a4410;
    font-weight: 700;
}
.spinner {
    width: 46px; height: 46px;
    margin: 0 auto 14px;
    border-radius: 50%;
    border: 5px solid rgba(217,169,58,0.3);
    border-top-color: #b8862b;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.bar { margin-top: 14px; height: 8px; border-radius: 8px; overflow: hidden; background: rgba(217,169,58,0.25); }
.bar i { display: block; height: 100%; width: 0; border-radius: 8px; background: linear-gradient(90deg, #d9a93a, #f3d67a); transition: width 0.2s ease; }
.bar.indeterminate i { width: 40% !important; animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { 0% { transform: translateX(-110%); } 100% { transform: translateX(260%); } }

/* ---------- "Choose PDF" panel (only if book.pdf can't load) ---------- */
#openPanel {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(253,244,220,0.94);
}
#openPanel.show { display: flex; }
.open-card {
    width: min(420px, 100%);
    padding: 28px 24px;
    text-align: center;
    border-radius: 20px;
    background: linear-gradient(180deg, #fffdf5, #fbefc9);
    border: 2px solid #d9a93a;
    box-shadow: 0 16px 44px rgba(138,97,24,0.35);
}
.open-title { font-family: Georgia, serif; font-size: 26px; font-weight: 800; color: #1f4a3a; }
.open-card p { margin: 12px 0 18px; line-height: 1.5; color: #5a4a1f; font-size: 14px; }
.open-card small { display: block; margin-top: 14px; color: #8a6d2a; }
#pickBtn {
    background: linear-gradient(180deg, #f3d67a 0%, #d9a93a 55%, #b8862b 100%);
    box-shadow: 0 4px 0 #8a6118, 0 6px 10px rgba(138,97,24,0.4);
    color: #3b2a05;
}

/* ---------- Fullscreen image viewer ---------- */
#imgViewer {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    touch-action: none;
}
#imgViewer.open {
    display: flex;
}
#imgViewer img {
    max-width: 100%;
    max-height: 100%;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    will-change: transform;
}
#viewerClose {
    position: fixed;
    top: 14px;
    right: 16px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 20px;
    line-height: 42px;
    text-align: center;
    padding: 0;
    z-index: 1001;
}
#viewerPrev,
#viewerNext {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.15);
    color: #fff;
    border-radius: 50%;
    width: 46px;
    height: 46px;
    font-size: 20px;
    padding: 0;
    z-index: 1001;
}
#viewerPrev { left: 16px; }
#viewerNext { right: 16px; }

/* ===========================================================
   Desktop / tablet only — everything below is scoped to
   min-width: 769px so the phone UI stays exactly as-is.
   =========================================================== */
@media (min-width: 769px) {

    #stage {
        height: calc(100% - 100px); /* matches the slightly taller controls bar below */
        padding: 30px 60px;
        box-sizing: border-box;
        /* soft radial "table" surface instead of a flat blank void */
        background: radial-gradient(ellipse at center, rgba(184,134,43,0.14) 0%, rgba(184,134,43,0) 65%);
    }

    #zoomWrapper {
        max-width: 1200px; /* 2-page spread (max ~1500px worth of page width) always ends up smaller than this and the viewport */
        margin: 0 auto;
    }

    #book {
        box-shadow: 0 10px 40px rgba(0,0,0,0.4);
    }

    #controls {
        height: 100px;
        gap: 8px;
        max-width: 1200px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 18px 18px 0 0;
        box-shadow: 0 -4px 18px rgba(138,97,24,0.2);
    }

    .btn-row {
        gap: 22px;
    }

    button {
        font-size: 16px;
        padding: 12px 26px;
        border-radius: 12px;
    }

    #downloadBtn {
        font-size: 14px;
        padding: 8px 18px;
    }


    #viewerPrev,
    #viewerNext {
        width: 54px;
        height: 54px;
        font-size: 24px;
    }
}