:root {
    --bg-color: #d8d8d8;
    --text-main: #5f5f5f;
    --glass-bg: rgba(255, 255, 255, 0.55);
    --glass-border: rgba(255, 255, 255, 0.35);
    --accent: #333;
    --zoom-transition: transform 0.6s cubic-bezier(0.2, 1, 0.3, 1);
}

body {
    background: var(--bg-color);
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#book-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
    overflow: hidden;
    scroll-behavior: auto;
}

#loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#flipbook-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.5s cubic-bezier(0.2, 1, 0.3, 1);
    transform-origin: center center;
    flex-shrink: 0;
    z-index: 10;
    will-change: transform;
}

#book-container.zooming-out #flipbook-wrapper {
    transition: transform 0.25s cubic-bezier(0.4, 0, 1, 1);
}

#zoom-overlay {
    display: none;
    position: fixed;
    inset: 0;
    overflow: auto;
    overscroll-behavior: none;
    background: var(--bg-color);
    z-index: 50;
}

#zoom-overlay.active {
    display: block;
    cursor: grab;
}

#zoom-overlay.active #flipbook-wrapper,
#zoom-overlay.active #flipbook-wrapper * {
    pointer-events: none !important;
}



#zoom-stage {
    position: relative;
}

#zoom-overlay #flipbook-wrapper {
    position: absolute;
    transition: transform 0.5s cubic-bezier(0.2, 1, 0.3, 1);
}

#flipbook {
    visibility: hidden;
    border: none;
}

.page {
    background-color: #fff;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

canvas {
    width: 100%;
    height: auto;
    display: block;
    -webkit-user-select: none;
    user-select: none;
    pointer-events: none;
}

/* ── Shared glass style ──────────────────────────────────────── */

#scrubber-wrap, .nav-btn, #page-info-wrap, #zoom-level-bubble, #keyboard-hints {
    background: var(--glass-bg);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid var(--glass-border);
}

/* ── Scrubber ────────────────────────────────────────────────── */

#scrubber-wrap {
    position: fixed;
    z-index: 9999;
    width: 0px;
    /* set dynamically by JS */
    height: 32px;
    padding: 0 12px;

    display: flex;
    align-items: center;
    gap: 6px;

    border-radius: 40px;
    box-sizing: border-box;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);

    opacity: 0;
    pointer-events: none;
    /* Clip from center outward — collapsed to arrow-pill width */
    clip-path: inset(0 calc(50% - 55px) 0 calc(50% - 55px) round 40px);
    transform: translateY(6px);
    transition: opacity 0.2s ease,
        transform 0.25s cubic-bezier(0.2, 1, 0.3, 1),
        clip-path 0.3s cubic-bezier(0.2, 1, 0.3, 1);
}

/* Preview state — collapsed pill showing just the arrows */
#scrubber-wrap.scrubber-preview {
    opacity: 1;
    pointer-events: none;
    transform: translateY(0);
}

/* Full state — fully expanded, no clipping */
#scrubber-wrap.scrubber-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    clip-path: inset(0 0% 0 0% round 40px);
}

#scrubber-label {
    position: absolute;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    color: #555;
    white-space: nowrap;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

#scrubber-wrap.scrubber-visible #scrubber-label,
#scrubber-wrap.scrubber-closing #scrubber-label {
    display: none;
}

#scrubber {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    min-width: 0;
    height: 2px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease 0.15s;
}

#scrubber-wrap.scrubber-visible #scrubber {
    opacity: 1;
}

#scrubber::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #555;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

#scrubber::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: none;
    background: #555;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

#scrubber::-webkit-slider-thumb:hover {
    transform: scale(1.4);
    background: #333;
}

#scrubber::-moz-range-thumb:hover {
    transform: scale(1.4);
    background: #333;
}


#controls {
    position: fixed;
    z-index: 9999;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);

    display: flex;
    align-items: center;
    gap: 8px;

    /* No background — each child is its own pill */
    background: none;
    border: none;
    box-shadow: none;
    padding: 0;

    opacity: 0.2;
    transition: opacity 0.4s ease;
}

#controls:hover,
#controls.ui-active,
#controls.scrubber-open {
    opacity: 1;
}

/* Base floating button */
.nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;

    height: 48px;
    width: 48px;
    padding: 0;

    border-radius: 48px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);

    color: #bbb;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;

    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, color 0.4s ease;
}

#controls:hover .nav-btn,
#controls.ui-active .nav-btn {
    color: #555;
}

.nav-btn:hover, #page-info-wrap:hover {
    background: rgba(255, 255, 255, 0.75);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.07);
}

.nav-btn:active, #page-info-wrap:active {
    transform: translateY(0px) scale(0.96);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.nav-btn.nav-disabled {
    pointer-events: none;
    opacity: 0.3 !important;
}

#controls:hover .nav-btn.nav-disabled,
#controls.ui-active .nav-btn.nav-disabled {
    color: #bbb;
}

/* SVG icon buttons — square pill */
.nav-btn svg {
    display: block;
    flex-shrink: 0;
}

/* Page-info badge — same size as buttons, reduced opacity to distinguish */
#page-info-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;

    height: 48px;
    padding: 0 18px;
    overflow: visible;
    cursor: pointer;

    border-radius: 40px;
    box-sizing: border-box;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
    user-select: none;
    opacity: 0.7;
    transition: opacity 0.4s ease, transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}



#controls:hover #page-info-wrap,
#controls.ui-active #page-info-wrap,
#page-info-wrap.scrubber-active {
    opacity: 1;
}

#page-info {
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    color: #bbb;
    letter-spacing: 0.03em;
    pointer-events: none;
    white-space: nowrap;
    transition: color 0.4s ease, opacity 0.15s ease;
}

#controls:hover #page-info,
#controls.ui-active #page-info {
    color: #555;
}


/* ── Zoom level bubble ───────────────────────────────────────── */

#zoom-level-bubble {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    white-space: nowrap;
    border-radius: 40px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
    padding: 0 12px;
    height: 28px;
    display: flex;
    align-items: center;
    font-size: 12px;
    font-weight: 500;
    color: #555;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 10000;
}

#zoom-btn:hover+#zoom-level-bubble,
div:hover>#zoom-level-bubble {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#book-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#book-container::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

/* ── Keyboard hints panel ────────────────────────────────────── */

#keyboard-hints {
    position: fixed;
    z-index: 9999;

    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    padding: 14px 20px;

    font-size: 13px;
    color: var(--text-main);
    white-space: nowrap;

    /* positioned by JS — start off-screen to avoid flash */
    bottom: auto;
    left: auto;
    transform: none;

    transition: opacity 0.2s ease, transform 0.2s ease;
    opacity: 1;
}

#keyboard-hints.hints-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px);
}

#keyboard-hints strong {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #888;
}

#keyboard-hints ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#keyboard-hints li {
    display: flex;
    align-items: center;
    gap: 6px;
}

kbd {
    display: inline-block;
    padding: 2px 7px;
    background: rgba(0, 0, 0, 0.07);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 6px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
}

/* ── iOS simulated fullscreen ────────────────────────────────── */

html.simulated-fs body {
    height: 100dvh;
}

html.simulated-fs #controls {
    opacity: 0 !important;
    pointer-events: none !important;
}

html.simulated-fs #controls.ui-active {
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* ── Mobile mode ─────────────────────────────────────────────── */
@media (max-width: 767px) {
    #book-container {
        overflow: hidden;
        align-items: center;
    }

    #controls {
        left: 0;
        right: 0;
        transform: none;
        justify-content: center;
        gap: 10px;
        bottom: 16px;
        opacity: 1 !important;
    }

    .nav-btn {
        height: 44px;
        width: 44px;
        flex-shrink: 0;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .nav-btn:active {
        transform: translateY(0px) scale(0.92);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    }

    #page-info-wrap {
        position: fixed;
        bottom: 94px;
        left: 50%;
        transform: translateX(-50%) !important;
        height: 32px;
        padding: 0 16px;
        width: max-content;
        white-space: nowrap;
        opacity: 1 !important;
        flex: 0 0 0px;
        min-width: 0;
        overflow: visible;
        margin: 0;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    #page-info-wrap:hover {
        transform: translateX(-50%) !important;
    }

    #page-info-wrap:active {
        transform: translateX(-50%) scale(0.96) !important;
    }

    #page-info {
        font-size: 12px;
    }

    #help-btn {
        display: none;
    }
}