.epub-reader-page {
    margin: 0;
    background: var(--bg);
}

.epub-reader {
    position: relative;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg);
}

/* ===== TOC Drawer ===== */
.epub-toc-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .35);
    z-index: 1010;
}

.epub-toc-overlay.open {
    display: block;
}

.epub-toc-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    max-width: 80vw;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    z-index: 1020;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4, 0, .2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.epub-toc-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 15px;
    flex-shrink: 0;
}

.epub-toc-drawer-close {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
}

.epub-toc-drawer-close:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.epub-toc-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.epub-toc-list::-webkit-scrollbar { width: 3px; }
.epub-toc-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.epub-toc-item {
    display: block;
    padding: 10px 20px;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.5;
    text-decoration: none;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.epub-toc-item:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.epub-toc-item.active {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 600;
}

.epub-toc-item.sub {
    padding-left: 36px;
    font-size: 13px;
}

.epub-toc-empty {
    padding: 24px 20px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
}

/* ===== Toolbar (frosted glass, auto-hide) ===== */
.epub-reader-toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 16px;
    background: color-mix(in srgb, var(--bg-card) 85%, transparent);
    backdrop-filter: blur(12px) saturate(1.4);
    -webkit-backdrop-filter: blur(12px) saturate(1.4);
    border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
    box-sizing: border-box;
    z-index: 100;
    transform: translateY(-100%);
    opacity: 0;
    transition: transform .3s cubic-bezier(.4, 0, .2, 1), opacity .3s ease;
}

.epub-reader.ui-visible .epub-reader-toolbar {
    transform: translateY(0);
    opacity: 1;
}

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

.epub-reader-title strong {
    max-width: 30vw;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 15px;
    font-weight: 500;
}

.epub-reader-back,
.epub-reader-btn {
    height: 32px;
    border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--bg-card) 60%, transparent);
    color: var(--text);
    font-size: 13px;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    transition: border-color .15s, color .15s, background .15s;
}

.epub-reader-back {
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
}

.epub-reader-btn {
    padding: 0 10px;
    cursor: pointer;
}

.epub-reader-btn:hover,
.epub-reader-back:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.epub-reader-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* ===== Status (centered overlay for loading) ===== */
.epub-reader-status {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 50;
    padding: 12px 28px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 14px;
    background: var(--bg-card);
    box-shadow: var(--shadow);
}

.epub-reader-status.error {
    color: #b42318;
    background: #fff1f0;
}

/* ===== Viewer (full viewport, fade transition) ===== */
.epub-viewer {
    width: 100%;
    height: 100dvh;
    max-width: 960px;
    margin: 0 auto;
    background: var(--bg-card);
    overflow: hidden;
    transition: opacity .18s ease;
}

.epub-viewer.page-fade {
    opacity: 0;
}

.epub-touch-overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
}

/* ===== Bottom Bar (frosted glass, auto-hide) ===== */
.epub-bottombar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 20px 14px;
    background: color-mix(in srgb, var(--bg-card) 85%, transparent);
    backdrop-filter: blur(12px) saturate(1.4);
    -webkit-backdrop-filter: blur(12px) saturate(1.4);
    border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
    z-index: 100;
    transform: translateY(100%);
    opacity: 0;
    transition: transform .3s cubic-bezier(.4, 0, .2, 1), opacity .3s ease;
}

.epub-reader.ui-visible .epub-bottombar {
    transform: translateY(0);
    opacity: 1;
}

.epub-bottombar-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.epub-progress-chapter {
    color: var(--text-secondary);
    font-size: 12px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    max-width: 65%;
}

.epub-progress-page {
    color: var(--text-muted);
    font-size: 12px;
    flex-shrink: 0;
}

.epub-bottombar-slider {
    display: flex;
    align-items: center;
    gap: 12px;
}

.epub-slider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.epub-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-card);
    box-shadow: 0 1px 4px rgba(0,0,0,.2);
    cursor: pointer;
    transition: transform .15s;
}

.epub-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.epub-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-card);
    box-shadow: 0 1px 4px rgba(0,0,0,.2);
    cursor: pointer;
}

.epub-slider::-moz-range-track {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
}

.epub-progress-pct {
    color: var(--text-muted);
    font-size: 12px;
    min-width: 36px;
    text-align: right;
    flex-shrink: 0;
}

/* ===== Error Page ===== */
.epub-reader-error {
    min-height: 70dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text);
}

.epub-reader-error a {
    color: var(--accent);
}

/* ===== Mobile ===== */
@media (max-width: 760px) {
    .epub-reader-toolbar {
        height: auto;
        min-height: 46px;
        flex-wrap: wrap;
        gap: 6px;
        padding: 8px 10px;
    }

    .epub-reader-title {
        flex: 1 1 100%;
    }

    .epub-reader-title strong {
        max-width: calc(100vw - 120px);
        font-size: 14px;
    }

    .epub-reader-controls {
        flex: 1 1 100%;
        justify-content: space-between;
    }

    .epub-viewer { max-width: 100%; }

    .epub-toc-drawer { width: 260px; }

    .epub-bottombar { padding: 8px 12px 12px; gap: 4px; }
    .epub-progress-chapter { font-size: 11px; }
    .epub-progress-page { font-size: 11px; }
    .epub-progress-pct { font-size: 11px; }
    .epub-slider::-webkit-slider-thumb { width: 14px; height: 14px; }

    #epub-prev, #epub-next { display: none; }
}

.epub-slider:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.epub-slider:disabled::-webkit-slider-thumb {
    background: var(--text-muted);
}
