/* ================================================= */
/* READER — Full-viewport overlay                    */
/* ================================================= */

body.reader-open {
    overflow: hidden;
}

.reader-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 22, 40, 0.85);
    backdrop-filter: blur(12px) saturate(180%);
    display: flex;
    flex-direction: column;
    z-index: 9999;
    animation: readerFadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes readerFadeIn {
    from { opacity: 0; transform: scale(1.05); }
    to { opacity: 1; transform: scale(1); }
}

/* ================================================= */
/* TOP BAR                                           */
/* ================================================= */

.reader-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    min-height: 56px;
    flex-shrink: 0;
}

.reader-topbar-left {
    flex: 0 0 auto;
}

.reader-page-info {
    font-size: 14px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(255, 255, 255, 0.08);
    padding: 4px 14px;
    border-radius: 20px;
    letter-spacing: 0.5px;
}

.reader-topbar-center {
    flex: 1;
    text-align: center;
    min-width: 0;
    padding: 0 12px;
}

.reader-book-title {
    font-size: 15px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    letter-spacing: 0.3px;
    display: inline-block;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reader-topbar-right {
    flex: 0 0 auto;
}

.reader-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-size: 18px;
    transition: all 0.2s ease;
    background: rgba(255, 255, 255, 0.06);
}

    .reader-close-btn:hover {
        background: rgba(220, 53, 69, 0.7);
        color: #fff;
        transform: scale(1.1);
    }

/* ================================================= */
/* MAIN CONTENT AREA                                 */
/* ================================================= */

.reader-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

.reader-nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 30;
    width: 52px;
    height: 100px;
    border: none;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(6px);
    color: rgba(255, 255, 255, 0.7);
    font-size: 24px;
    cursor: pointer;
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reader-nav-prev {
    left: 0;
    border-radius: 0 8px 8px 0;
}

.reader-nav-next {
    right: 0;
    border-radius: 8px 0 0 8px;
}

.reader-nav-arrow:hover {
    background: rgba(13, 110, 253, 0.45);
    color: #fff;
    width: 60px;
}

.reader-nav-arrow:active {
    transform: translateY(-50%) scale(0.95);
}

.reader-nav-arrow:disabled {
    opacity: 0.25;
    cursor: default;
    pointer-events: none;
}

/* Viewer Container — scrollable for zoom */
.reader-viewer {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    max-height: 100%;
    overflow: auto;
    padding: 8px 60px;
    min-width: 0;
    min-height: 0;
}

    /* Base canvas style */
    .reader-viewer canvas,
    .flip-page canvas {
        display: block;
        border-radius: 4px;
        flex-shrink: 0;
        max-width: 100%;
        height: auto;
        transition: transform 0.1s ease-out;
    }

/* ================================================= */
/* FLIPBOOK LAYOUT                                   */
/* ================================================= */

.canvas-container-flip {
    width: 100%;
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 10px 0;
    box-sizing: border-box;
}

.flip-book-frame {
    background-color: transparent;
    transition: transform 0.2s ease-out;
}

.page {
    background-color: #fff;
    overflow: hidden;
    color: #333;
}

.page-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Hard pages (covers) styling */
.page[data-density="hard"] {
    background-color: #f8f9fa;
}

/* Page shadowing applied by St.PageFlip inside its container */
.stf__block {
    border-radius: 4px; /* Slight rounded corners simulating paper */
}

/* ================================================= */
/* LOADING                                           */
/* ================================================= */

.reader-loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 40px;
    background: rgba(15, 25, 35, 0.95);
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    z-index: 50;
    min-width: 200px;
    min-height: 150px;
}

    .reader-loading.hidden {
        display: none;
    }

/* ================================================= */
/* BOTTOM TOOLBAR                                    */
/* ================================================= */

.reader-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    flex-wrap: wrap;
    position: relative;
    z-index: 100;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 10px;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0 4px;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
}

    .toolbar-btn:hover {
        background: rgba(255, 255, 255, 0.12);
        color: #fff;
        transform: translateY(-1px);
    }

    .toolbar-btn:active {
        transform: scale(0.92);
    }

    .toolbar-btn:disabled {
        opacity: 0.35;
        cursor: default;
        pointer-events: none;
    }

    .toolbar-btn.active {
        background: rgba(13, 110, 253, 0.3);
        color: #6fb3ff;
    }

.toolbar-zoom-label {
    color: rgba(255, 255, 255, 0.75);
    font-size: 13px;
    font-weight: 500;
    min-width: 42px;
    text-align: center;
    user-select: none;
}

.toolbar-page-input {
    display: flex;
    align-items: center;
    gap: 6px;
    color: rgba(255, 255, 255, 0.75);
    font-size: 14px;
    font-weight: 500;
}

    .toolbar-page-input input {
        width: 50px;
        height: 32px;
        text-align: center;
        border: 1px solid rgba(255, 255, 255, 0.15);
        border-radius: 6px;
        background: rgba(255, 255, 255, 0.06);
        color: #fff;
        font-size: 14px;
        font-weight: 500;
        outline: none;
        transition: border-color 0.2s ease, background 0.2s ease;
    }

        .toolbar-page-input input:focus {
            border-color: rgba(13, 110, 253, 0.6);
            background: rgba(255, 255, 255, 0.1);
        }

        .toolbar-page-input input::-webkit-outer-spin-button,
        .toolbar-page-input input::-webkit-inner-spin-button {
            -webkit-appearance: none;
            appearance: none;
            margin: 0;
        }

        .toolbar-page-input input[type="number"] {
            -moz-appearance: textfield;
            appearance: textfield;
        }

/* ================================================= */
/* THUMBNAILS PANEL                                  */
/* ================================================= */

/* ================================================= */
/* THUMBNAILS PANEL                                  */
/* ================================================= */

.reader-thumbnails-panel {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(24px) saturate(150%);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    transform: translateX(-100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.3);
}

.reader-thumbnails-panel.open {
    transform: translateX(0);
}

.thumbnails-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.thumbnails-close {
    background: rgba(255, 255, 255, 0.06);
    border: none;
    color: rgba(255, 255, 255, 0.6);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.thumbnails-close:hover {
    color: #fff;
    background: rgba(220, 53, 69, 0.4);
}

.thumbnails-grid {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.thumbnail-item {
    cursor: pointer;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(255, 255, 255, 0.03);
    position: relative;
    padding: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.thumbnail-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: scale(1.02);
}

.thumbnail-item.active {
    border-color: #0d6efd;
    background: rgba(13, 110, 253, 0.1);
    box-shadow: 0 0 20px rgba(13, 110, 253, 0.4);
}

.thumbnail-item canvas {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
}

.thumbnail-label {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    color: #fff;
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 700;
}

/* ================================================= */
/* CUSTOM SCROLLBAR                                  */
/* ================================================= */

.thumbnails-grid::-webkit-scrollbar,
.reader-viewer::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

.thumbnails-grid::-webkit-scrollbar-track,
.reader-viewer::-webkit-scrollbar-track {
    background: transparent;
}

.thumbnails-grid::-webkit-scrollbar-thumb,
.reader-viewer::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
}

    .thumbnails-grid::-webkit-scrollbar-thumb:hover,
    .reader-viewer::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.25);
    }

/* ================================================= */
/* RESPONSIVE                                        */
/* ================================================= */

@media (max-width: 992px) {
    .reader-toolbar {
        gap: 4px;
    }

    .toolbar-divider {
        margin: 0 6px;
    }
}

@media (max-width: 768px) {
    .reader-nav-arrow {
        width: 36px;
        height: 70px;
        font-size: 18px;
    }

    .reader-topbar {
        padding: 8px 12px;
    }

    .reader-book-title {
        font-size: 13px;
    }

    .reader-toolbar {
        padding: 8px 10px;
    }

    .toolbar-divider {
        margin: 0 4px;
    }

    .toolbar-btn {
        width: 34px;
        height: 34px;
        font-size: 15px;
    }

    .toolbar-page-input input {
        width: 44px;
        height: 30px;
        font-size: 13px;
    }

    .reader-thumbnails-panel {
        width: 200px;
    }

    .reader-viewer {
        padding: 8px 44px;
    }
}

@media (max-width: 480px) {
    .reader-topbar-center {
        display: none;
    }

    .reader-nav-arrow {
        width: 30px;
        height: 60px;
        font-size: 16px;
    }

    .reader-viewer {
        padding: 8px 36px;
    }

    .reader-toolbar {
        justify-content: center;
    }

    .toolbar-divider {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .flip-page,
    .flip-book-frame,
    .page-flip-shadow,
    .reader-nav-arrow,
    .toolbar-btn,
    .reader-close-btn,
    .reader-thumbnails-panel,
    .thumbnail-item {
        transition: none !important;
    }
}
