/* =====================================================================
   BOOK READER — paginated PDF reader + audiobook bar
   Additive stylesheet. Reuses design tokens from style.css :root so it
   matches book-detail-* / books.css exactly. Load AFTER books.css.
   ===================================================================== */

/* ---------------------------------------------------------------------
   READER SHELL
--------------------------------------------------------------------- */
.book-reader {
    background: var(--bg-charcoal);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-gold);
    margin: 0 0 24px;
}

.reader-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 18px;
    background: var(--bg-black);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.reader-toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    color: var(--text-gold);
}

.reader-toolbar-title {
    color: var(--text-white);
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.reader-toolbar-nav,
.reader-toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.reader-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-white);
    font-size: 13px;
    border: 1px solid transparent;
    transition: var(--transition-fast);
}

.reader-btn:hover:not(:disabled) {
    background: var(--brand-primary);
    border-color: var(--brand-primary);
    color: var(--text-white);
}

.reader-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.reader-page-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 6px;
    color: var(--text-white);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.reader-page-input {
    width: 42px;
    text-align: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: var(--text-white);
    font-size: 13px;
    font-weight: 600;
    padding: 4px 2px;
}

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

.reader-page-sep,
.reader-page-total {
    color: rgba(255, 255, 255, 0.55);
}

/* ---------------------------------------------------------------------
   READER STAGE (page canvas)
--------------------------------------------------------------------- */
.reader-stage {
    position: relative;
    min-height: 420px;
    max-height: 78vh;
    overflow-y: auto;
    overflow-x: auto;      /* zoomed-in pages scroll sideways instead of being clipped */
    padding: 28px 16px;
    background:
        repeating-linear-gradient(45deg, rgba(255,255,255,0.02) 0 2px, transparent 2px 40px),
        var(--bg-charcoal);
    touch-action: pan-y;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch; /* momentum scroll on iOS Safari */
}

/* Continuous, feed-style vertical stack of rasterised pages (Page/canvas mode). */
.reader-pages-scroll {
    display: flex;
    flex-direction: column;
    align-items: flex-start;   /* items centre themselves with auto margins, which stay scrollable when zoomed */
    gap: 22px;
    width: 100%;
}

/* [hidden] alone can't win against an author rule that sets display on the
   same element — the browser's [hidden]{display:none} lives in the UA
   stylesheet, which author CSS always overrides regardless of specificity.
   Re-declare it here so `pagesScroll.hidden = true` (set in setMode() when
   switching to Text view) actually hides the page stack instead of leaving
   it visually on top of the text view. */
.reader-pages-scroll[hidden] {
    display: none;
}

.reader-page-item {
    position: relative;
    flex: none;
    margin-left: auto;
    margin-right: auto;
    max-width: none;    /* width/height are set per page by book-reader.js (fit-to-width x zoom) */
    min-height: 200px;  /* stable footprint before its canvas has rendered, so the
                            feed doesn't jump around as pages lazily fill in */
    background: var(--bg-white);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    border-radius: 3px;
    line-height: 0;
}

.reader-page-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-gold);
    font-size: 20px;
    background: rgba(43, 43, 43, 0.06);
}

.reader-canvas {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 3px;
}

.reader-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-gold);
    font-size: 13px;
    font-weight: 600;
    background: rgba(43, 43, 43, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.book-reader.is-loading .reader-loading {
    opacity: 1;
}

.reader-error {
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 10px;
    min-height: 300px;
    color: var(--text-white);
    text-align: center;
    padding: 20px;
}

.reader-error i {
    font-size: 26px;
    color: var(--brand-primary);
}

.book-reader.has-error .reader-stage,
.book-reader.has-error .reader-toolbar-nav {
    display: none;
}

.book-reader.has-error .reader-error {
    display: flex;
}

/* Swipe-turn feedback edges */
.reader-swipe-hint {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 40px;
    display: none;
}

@media (max-width: 640px) {
    .reader-toolbar-title { max-width: 110px; font-size: 12px; }
    .reader-btn { width: 30px; height: 30px; }
    .reader-toolbar { padding: 10px 10px; gap: 6px; }
    .reader-stage { min-height: 320px; padding: 16px 8px; }
}

/* ---------------------------------------------------------------------
   MODE SWITCH — Page (original layout) vs Text (reflowable, adjustable)
--------------------------------------------------------------------- */
.reader-mode-switch {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.06);
    margin-right: 4px;
}

.reader-mode-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 28px;
    border: 0;
    background: transparent;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 12.5px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    transition: var(--transition-fast);
}

.reader-mode-btn.is-active {
    background: var(--brand-primary);
    color: var(--text-white);
}

.reader-mode-btn:hover:not(.is-active) { color: var(--text-white); }

/* ---------------------------------------------------------------------
   READING SETTINGS PANEL
--------------------------------------------------------------------- */
.reader-settings-toggle.is-active,
.reader-settings-toggle[aria-expanded="true"] {
    background: var(--brand-primary);
    border-color: var(--brand-primary);
}

.reader-settings-panel {
    position: relative;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    gap: 22px;
    padding: 18px 20px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-light);
}

.reader-settings-hint {
    flex-basis: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border-radius: var(--radius-md);
    background: var(--bg-gold-light);
    color: var(--text-secondary);
    font-size: 12.5px;
    line-height: 1.5;
}

.reader-settings-hint i { color: var(--brand-primary); flex-shrink: 0; }

.reader-settings-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.reader-settings-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.reader-settings-options {
    display: flex;
    gap: 6px;
}

.reader-settings-options button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 38px;
    height: 36px;
    padding: 0 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-white);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    transition: var(--transition-fast);
}

.reader-settings-options button:hover { border-color: var(--border-gold); background: var(--bg-gold-light); }

.reader-settings-options button.is-active {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: var(--text-white);
}

.reader-settings-options-aa button {
    flex-direction: column;
    gap: 2px;
    height: 52px;
    min-width: 56px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-muted);
}

.reader-settings-options-aa button.is-active { color: var(--text-white); }

.reader-settings-options-aa .reader-aa {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.reader-settings-options-aa button.is-active .reader-aa { color: var(--text-white); }

.reader-settings-swatches {
    display: flex;
    gap: 10px;
}

.reader-settings-swatches button {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    padding: 3px;
    border: 2px solid transparent;
    transition: var(--transition-fast);
}

.reader-settings-swatches button span {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
}

.reader-settings-swatches button.is-active { border-color: var(--brand-primary); }

@media (max-width: 640px) {
    .reader-settings-panel { gap: 16px; padding: 14px 14px; }
}

/* ---------------------------------------------------------------------
   TEXT MODE — reflowable, theme-able reading surface
--------------------------------------------------------------------- */
.reader-text-shell {
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    min-height: 100%;
}

.reader-text-content {
    padding: 8px 6px 40px;
    color: inherit;
    line-height: 1.85;
}

.reader-text-content p {
    margin: 0 0 1.2em;
    text-indent: 0;
}

.reader-text-content .reader-text-page:first-of-type .reader-text-page-body p:first-child::first-letter {
    font-family: "Playfair Display", serif;
    font-size: 2.6em;
    font-weight: 700;
    float: left;
    line-height: 0.85;
    padding: 0.05em 0.08em 0 0;
    color: var(--brand-primary);
}

/* One section per PDF page, stitched into a single continuous scroll. */
.reader-text-page {
    padding-top: 6px;
}

.reader-text-page + .reader-text-page {
    margin-top: 34px;
    padding-top: 28px;
    border-top: 1px dashed rgba(120, 108, 78, 0.22);
}

.reader-text-page-label {
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    opacity: 0.6;
    margin-bottom: 16px;
}

.reader-text-page-body.reader-text-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 120px;
    color: var(--text-muted);
    font-size: 14px;
}

.reader-text-page-empty {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    border-radius: var(--radius-md);
    background: rgba(120, 108, 78, 0.06);
    color: var(--text-muted) !important;
    font-size: 13.5px;
}

.reader-text-page-empty i { color: var(--brand-primary); }

/* Reading-progress bar shown only in Text mode, above the stage. */
.reader-text-progress {
    height: 3px;
    background: rgba(120, 108, 78, 0.12);
}

.reader-text-progress span {
    display: block;
    height: 100%;
    width: 0%;
    background: var(--brand-primary);
    transition: width 0.12s linear;
}

/* Reading themes — applied to the whole reader shell so the toolbar/stage
   background shifts together with the text surface in Text mode. */
.book-reader.is-text-mode.reader-theme-sepia .reader-stage,
.book-reader.is-text-mode.reader-theme-sepia .reader-text-content {
    background: #F1E7CF;
    color: #3B2F1C;
}

.book-reader.is-text-mode.reader-theme-white .reader-stage,
.book-reader.is-text-mode.reader-theme-white .reader-text-content {
    background: #FFFFFF;
    color: #1A1A1A;
}

.book-reader.is-text-mode.reader-theme-black .reader-stage,
.book-reader.is-text-mode.reader-theme-black .reader-text-content {
    background: #121212;
    color: #EDEDED;
}

.book-reader.is-text-mode.reader-theme-sepia .reader-stage { background-image: none; }
.book-reader.is-text-mode.reader-theme-white .reader-stage { background-image: none; }
.book-reader.is-text-mode.reader-theme-black .reader-stage { background-image: none; }

/* ---------------------------------------------------------------------
   AUDIOBOOK BAR
--------------------------------------------------------------------- */
.audio-player-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: var(--bg-gold-light);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-lg);
    margin: 0 0 24px;
}

.audio-play-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--brand-primary);
    color: var(--text-white);
    font-size: 15px;
    box-shadow: var(--shadow-button);
    transition: var(--transition-fast);
}

.audio-play-btn:hover { background: var(--brand-primary-dark); }

.audio-play-btn i.fa-pause { display: none; }
.audio-player-bar.is-playing .audio-play-btn i.fa-play { display: none; }
.audio-player-bar.is-playing .audio-play-btn i.fa-pause { display: inline-block; }

.audio-info {
    flex: 1;
    min-width: 0;
}

.audio-title {
    display: block;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.audio-progress-track {
    position: relative;
    height: 6px;
    border-radius: 999px;
    background: rgba(176, 141, 60, 0.18);
    margin-bottom: 6px;
}

.audio-progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0%;
    border-radius: 999px;
    background: var(--brand-primary);
    pointer-events: none;
}

.audio-seek {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.audio-times {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.audio-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.audio-speed-btn,
.audio-download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 34px;
    padding: 0 10px;
    border-radius: 8px;
    background: var(--bg-white);
    border: 1px solid var(--border-gold);
    color: var(--text-primary);
    font-size: 12.5px;
    font-weight: 700;
    transition: var(--transition-fast);
}

.audio-speed-btn:hover,
.audio-download-btn:hover {
    background: var(--brand-primary);
    border-color: var(--brand-primary);
    color: var(--text-white);
}

@media (max-width: 640px) {
    .audio-player-bar { padding: 12px 14px; gap: 10px; }
    .audio-play-btn { width: 40px; height: 40px; }
    .audio-actions .audio-speed-btn span.audio-speed-label { display: none; }
}
/* Placeholder shown while a page is still being drawn */
.reader-page-loading[hidden] { display: none; }
.reader-page-loading {
    flex-direction: column;
    gap: 8px;
    background: linear-gradient(135deg, #FBF9F2, #EAE6D6);
}
.reader-page-loading .reader-page-num {
    font-family: 'Outfit', sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: #7A5B08;
    letter-spacing: .08em;
}
