/* ==========================================
   SalmasFlix — Gallery · Book reader modal
   Extracted from gallery.css in Phase 7 CSS refactor.

   Covers the full-screen EPUB / PDF reader shell opened from
   a book card: outer .book-reader-modal (fixed vs. absolute
   depending on whether it was re-parented into a sync-tab
   fullscreen host), .book-reader-header (close + title +
   chapter + progress), the scrollable reading area, and the
   bottom nav bar (prev/next + progress tracker + jump-to-
   page input + .book-page-num).

   Scoped entirely to .book-reader-* and .book-nav-btn /
   .book-tracker-* / .book-jump-* / .book-page-num — zero
   overlap with card chrome or detail modal styles.

   Uses theme tokens throughout so progress fill + focus
   borders retint with the active theme. Keeps the existing
   Fullscreen API + iOS fake-FS re-parenting selectors so the
   modal stays on top of the sync player's <video>.
   ========================================== */

@layer features {

/* Book Reader Modal */
.book-reader-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100vh;
    height: 100dvh;
    background: #0f0e17;
    display: flex;
    flex-direction: column;
    z-index: var(--z-modal);
    animation: fadeIn 0.3s ease;
    overscroll-behavior: none;
    overflow: hidden;
    touch-action: pinch-zoom;
}

/* When the book-reader modal is re-parented INTO a sync-fullscreen host
   (see openBookReader in gallery.js), `position: fixed` on a descendant of
   another fixed element can establish a stacking context scoped inside
   that host — on iOS Safari the <video> sibling then paints ABOVE the
   modal. Switching to `position: absolute` + `inset: 0` + max z-index
   makes the reader a direct sibling layer at the top of the FS host's
   stacking context. Covers both iOS fake-FS (.media-room.media-fs) and
   real Fullscreen API (:fullscreen). */
.media-room.media-fs .book-reader-modal:not(.hidden),
:fullscreen .book-reader-modal:not(.hidden),
:-webkit-full-screen .book-reader-modal:not(.hidden) {
    position: absolute;
    inset: 0;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    z-index: 2147483647;
}

.book-reader-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-lg);
    background: linear-gradient(180deg, #151321 0%, #0f0e17 100%);
    border-bottom: 1px solid rgba(var(--secondary-rgb),0.15);
    flex-shrink: 0;
    min-height: 52px;
}

.book-reader-header .book-reader-close {
    background: rgba(var(--secondary-rgb),0.12);
    border: 1px solid rgba(var(--secondary-rgb),0.25);
    color: var(--text-primary);
    font-size: 1.1rem;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-normal), background-color var(--transition-normal), border-color var(--transition-normal), box-shadow var(--transition-normal), color var(--transition-normal), filter var(--transition-normal), opacity var(--transition-normal), transform var(--transition-normal);
    flex-shrink: 0;
}

.book-reader-header .book-reader-close:hover {
    background: rgba(231, 76, 60, 0.3);
    border-color: rgba(231, 76, 60, 0.5);
}

.book-reader-header .book-reader-title {
    font-size: clamp(0.85rem, 2.5vw, 1rem);
    font-weight: 600;
    color: #e8e0f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.book-reader-header .book-reader-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    flex-shrink: 0;
}

.book-reader-header .book-reader-chapter {
    font-size: 0.75rem;
    color: rgba(var(--secondary-rgb),0.7);
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-reader-header .book-reader-progress {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent-primary);
    white-space: nowrap;
    min-width: 36px;
    text-align: right;
}

.book-reader-area {
    flex: 1;
    width: 100%;
    overflow: hidden;
    position: relative;
    background: #141220;
    min-height: 0; /* critical for flex children */
    touch-action: pinch-zoom;
    overscroll-behavior: none;
}

/* Book Reader Bottom Nav Bar */
.book-reader-nav {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-lg);
    background: linear-gradient(180deg, #0f0e17 0%, #151321 100%);
    border-top: 1px solid rgba(var(--secondary-rgb),0.15);
    flex-shrink: 0;
    min-height: 52px;
}

.book-nav-btn {
    background: rgba(var(--secondary-rgb),0.12);
    border: 1px solid rgba(var(--secondary-rgb),0.25);
    color: var(--text-primary);
    font-size: 1.1rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, background-color 0.2s, border-color 0.2s, box-shadow 0.2s, color 0.2s, filter 0.2s, opacity 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.book-nav-btn:hover {
    background: rgba(var(--secondary-rgb),0.3);
    border-color: var(--accent-primary);
    transform: scale(1.05);
}

.book-nav-btn:active {
    transform: scale(0.95);
}

.book-reader-tracker {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.book-tracker-bar {
    flex: 1;
    height: 6px;
    background: rgba(var(--secondary-rgb),0.12);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.book-tracker-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 3px;
    width: 0%;
    transition: width 0.4s ease;
    box-shadow: 0 0 8px rgba(var(--secondary-rgb),0.4);
}

.book-tracker-text {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent-primary);
    min-width: 40px;
    text-align: center;
    white-space: nowrap;
}

.book-jump-form {
    display: flex;
    align-items: center;
    background: rgba(var(--secondary-rgb),0.12);
    border: 1px solid rgba(var(--secondary-rgb),0.25);
    border-radius: 20px;
    padding: 4px 14px;
    min-width: 80px;
    justify-content: center;
}

.book-page-num {
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
}

.book-page-num:hover { color: var(--secondary-soft); }

.book-jump-input {
    background: transparent;
    border: none;
    outline: none;
    color: #e8e0f0;
    font-size: 0.85rem;
    font-weight: 700;
    width: 80px;
    text-align: center;
    font-family: inherit;
    letter-spacing: 0.02em;
}

.book-jump-input::-webkit-inner-spin-button,
.book-jump-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Mobile adjustments for reader */
@media (max-width: 768px) {
    .book-reader-header {
        padding: 8px 14px;
        min-height: 48px;
        gap: 10px;
    }
    .book-reader-header .book-reader-title {
        font-size: 0.9rem;
    }
    .book-reader-header .book-reader-chapter {
        display: none;
    }
    .book-reader-nav {
        padding: 8px 14px;
        min-height: 56px;
        gap: 10px;
    }
    .book-nav-btn {
        width: 44px;
        height: 44px;
        font-size: 1.2rem;
    }
    .book-reader-area {
        max-width: 100%;
        background: #141220;
    }
    .book-jump-input {
        width: 48px;
        font-size: 0.75rem;
    }
    .book-jump-form {
        padding: 3px 8px;
        gap: 6px;
    }
}

} /* end @layer features */
