/* =============================================================================
   Epub Reader — Kindle-style component
   Trade paperback proportions (2:3) on desktop · Full-screen on mobile
   ============================================================================= */

/* ── Reset inside the component ─────────────────────────────────────────────── */
.epub-reader-wrapper,
.epub-reader-wrapper * {
    box-sizing: border-box;
}

/* ── Outer wrapper ───────────────────────────────────────────────────────────── */
.epub-reader-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 2.5rem 1rem;
    width: 100%;
}

/* ── Row: prev arrow + device + next arrow ───────────────────────────────────── */
.epub-reader-layout {
    display: flex;
    align-items: center;
    gap: 1.125rem;
}

/* ── The device frame (Kindle bezel) ─────────────────────────────────────────── */
.epub-device {
    display: flex;
    flex-direction: column;

    background: linear-gradient(160deg, #232323 0%, #141414 100%);
    border-radius: 14px;
    padding: 22px 20px 0;

    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.06),
        0 4px 8px  rgba(0, 0, 0, 0.45),
        0 24px 64px rgba(0, 0, 0, 0.55),
        inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

/* ── The e-ink screen area ───────────────────────────────────────────────────── */
/*    6 × 9 trade paperback = 2:3 ratio.
      360 × 540 px gives comfortable desktop reading.                            */
.epub-screen {
    width:  360px;
    height: 540px;
    background: #f4f1e8;
    border-radius: 3px;
    position: relative;
    overflow: hidden;
    box-shadow:
        inset 0 0 0 1px rgba(0, 0, 0, 0.12),
        inset 0 2px 10px rgba(0, 0, 0, 0.06);
}

/* epub.js renders an iframe into this element */
.epub-viewer {
    width:  100%;
    height: 100%;
    position: relative;
}

/* ── Small base bar below the screen (Kindle detail) ────────────────────────── */
.epub-device-base {
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.epub-device-base::after {
    content: '';
    display: block;
    width: 60px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.12);
}

/* ── Loading overlay ─────────────────────────────────────────────────────────── */
.epub-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f4f1e8;
    transition: opacity 0.3s ease;
    z-index: 10;
}

.epub-loading.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ── Spinner ─────────────────────────────────────────────────────────────────── */
.epub-spinner {
    width:  34px;
    height: 34px;
    border: 3px solid rgba(30, 30, 30, 0.12);
    border-top-color: #3a3a3a;
    border-radius: 50%;
    animation: epub-spin 0.75s linear infinite;
}

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

/* ── Navigation arrows ───────────────────────────────────────────────────────── */
.epub-nav {
    all: unset;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;

    width:  50px;
    height: 50px;
    border-radius: 50%;

    background: rgba(25, 25, 25, 0.78);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.10);

    transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.epub-nav:hover  { background: rgba(45, 45, 45, 0.92); }
.epub-nav:active { transform: scale(0.91); }

/* ── Status bar: font controls + progress ────────────────────────────────────── */
.epub-status {
    min-height: 1.75rem;
    width: 100%;
    max-width: 460px;   /* aligns with device + arrow width */
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.epub-progress {
    flex: 1;
    text-align: center;
    color: #888;
    font-size: 0.78rem;
    letter-spacing: 0.06em;
}

/* ── Font-size buttons ───────────────────────────────────────────────────────── */
.epub-font-btn {
    all: unset;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.55rem;
    height: 1.75rem;
    border-radius: 5px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    background: rgba(0, 0, 0, 0.04);
    color: #555;
    font-family: Georgia, serif;
    line-height: 1;
    white-space: nowrap;
    transition: background 0.12s ease, color 0.12s ease;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}

.epub-font-dec { font-size: 0.78rem; }
.epub-font-inc { font-size: 0.95rem; }

.epub-font-btn:hover  { background: rgba(0, 0, 0, 0.09); color: #1a1a1a; }
.epub-font-btn:active { background: rgba(0, 0, 0, 0.15); }
.epub-font-btn:disabled { opacity: 0.35; cursor: default; }

/* ── Error text ──────────────────────────────────────────────────────────────── */
.epub-setup-error,
p.epub-load-error {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #c00;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
}

/* =============================================================================
   Table of contents
   ============================================================================= */

/* ── Toggle button (top-left of the reading area) ───────────────────────────── */
.epub-toc-btn {
    all: unset;
    position: absolute;
    top:  10px;
    left: 10px;
    z-index: 25;

    display: flex;
    align-items: center;
    justify-content: center;
    width:  30px;
    height: 30px;
    border-radius: 5px;

    background: rgba(30, 30, 30, 0.55);
    color: #fff;
    cursor: pointer;
    opacity: 0.45;
    transition: opacity 0.15s ease, background 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

/* Show at full opacity when device is hovered, or the button itself */
.epub-device:hover .epub-toc-btn,
.epub-toc-btn:hover,
.epub-toc-btn:focus-visible {
    opacity: 1;
}

.epub-toc-btn:active {
    background: rgba(30, 30, 30, 0.85);
}

/* ── Sliding panel ───────────────────────────────────────────────────────────── */
.epub-toc-panel {
    position: absolute;
    top:    0;
    left:   0;
    height: 100%;
    width:  234px;          /* ~65 % of the 360 px screen */
    z-index: 40;

    display: flex;
    flex-direction: column;

    background: #f0ede4;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.18);

    transform: translateX( -100% );
    transition: transform 0.25s ease;
    will-change: transform;
}

.epub-toc-panel.open {
    transform: translateX( 0 );
}

/* ── Panel header ────────────────────────────────────────────────────────────── */
.epub-toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 12px 10px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.10);
    flex-shrink: 0;
}

.epub-toc-title {
    font-family: Georgia, serif;
    font-size: 0.8rem;
    font-weight: bold;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #444;
}

.epub-toc-close {
    all: unset;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width:  26px;
    height: 26px;
    border-radius: 4px;
    color: #666;
    transition: background 0.12s ease, color 0.12s ease;
    -webkit-tap-highlight-color: transparent;
}

.epub-toc-close:hover { background: rgba(0, 0, 0, 0.07); color: #1a1a1a; }

/* ── Chapter list ────────────────────────────────────────────────────────────── */
.epub-toc-list {
    overflow-y: auto;
    flex: 1;
    padding: 6px 0;
    -webkit-overflow-scrolling: touch;
}

.epub-toc-items {
    list-style: none;
    margin:  0;
    padding: 0;
}

.epub-toc-items a {
    display: block;
    padding: 8px 14px;
    font-family: Georgia, serif;
    font-size: 0.82rem;
    line-height: 1.4;
    color: #1a1a1a;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background 0.1s ease, border-color 0.1s ease;
    word-break: break-word;
}

.epub-toc-items a:hover {
    background: rgba(0, 0, 0, 0.06);
}

.epub-toc-items a.epub-toc-active {
    border-left-color: #3a3a3a;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.05);
}

/* Sub-item indent */
.epub-toc-sub a {
    font-size: 0.78rem;
    color: #555;
}

.epub-toc-empty {
    padding: 1rem;
    font-size: 0.82rem;
    color: #888;
    font-family: Georgia, serif;
}

/* ── Backdrop (dims the non-panel area) ──────────────────────────────────────── */
.epub-toc-backdrop {
    position: absolute;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, 0.30);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.epub-toc-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

/* =============================================================================
   Mobile / handheld: full-screen reader, no device chrome
   ============================================================================= */
@media (max-width: 599px) {

    /* Break out of the theme's container and fill the viewport */
    .epub-reader-wrapper {
        width:  100vw;
        height: 100svh; /* small-viewport height; accounts for browser UI chrome */
        height: 100vh;  /* fallback for browsers without svh */
        margin-left: calc(50% - 50vw);
        padding: 0;
        gap: 0;
        position: relative;
        background: #f4f1e8;
    }

    .epub-reader-layout {
        width:  100%;
        height: 100%;
        gap: 0;
        flex: 1;
        position: relative;
    }

    /* Strip all device chrome */
    .epub-device {
        background: transparent;
        border-radius: 0;
        padding: 0;
        box-shadow: none;
        flex: 1;
        height: 100%;
    }

    .epub-device-base { display: none; }

    .epub-screen {
        width:  100%;
        height: 100%;
        border-radius: 0;
        box-shadow: none;
    }

    /* Arrows float over the content at mid-height */
    .epub-nav {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        z-index: 20;
        width:  40px;
        height: 40px;
        background: rgba(0, 0, 0, 0.28);
        border: none;
    }

    .epub-nav:active { transform: translateY(-50%) scale(0.91); }

    .epub-prev { left:  6px; }
    .epub-next { right: 6px; }

    /* Status bar anchored to the bottom */
    .epub-status {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        padding: 6px 56px;   /* inset from the floating nav arrows */
        z-index: 20;
        background: rgba(244, 241, 232, 0.88);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
        border-top: 1px solid rgba(0, 0, 0, 0.07);
    }

    /* TOC button always fully visible on touch screens */
    .epub-toc-btn {
        opacity: 0.75;
        top:  12px;
        left: 12px;
        width:  34px;
        height: 34px;
    }

    /* TOC panel fills more of the screen width on small devices */
    .epub-toc-panel {
        width: min( 260px, 80vw );
    }
}
