/* ==========================================================================
   电子书翻页阅读器（参照人教版电子教材阅读器的翻书体验）
   全屏覆盖层 + 3D 真实翻页（perspective / preserve-3d / rotateY）
   ========================================================================== */

.reader-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    flex-direction: column;
    background: #23262b;
    color: #e9ebee;
    font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
    -webkit-user-select: none;
    user-select: none;
    overflow: hidden;
}

.reader-overlay.open {
    display: flex;
}

.reader-overlay * {
    box-sizing: border-box;
}

/* ---------------------------------------------------------------- 顶部工具栏 */
.reader-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    background: linear-gradient(#2c3037, #1e2126);
    border-bottom: 1px solid #101216;
    box-shadow: 0 2px 12px rgba(0, 0, 0, .45);
    z-index: 30;
    flex-wrap: wrap;
}

.reader-toolbar .rt-title {
    flex: 1 1 160px;
    min-width: 0;
    font-size: 15px;
    font-weight: 600;
    color: #f2f4f7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 6px;
}

.reader-toolbar .rt-spacer {
    flex: 0 0 auto;
}

.rt-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    min-width: 34px;
    padding: 0 11px;
    background: rgba(255, 255, 255, .08);
    color: #dfe3e8;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: background .2s, color .2s, border-color .2s, transform .15s;
    white-space: nowrap;
}

.rt-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, .18);
    border-color: rgba(255, 255, 255, .3);
    color: #fff;
}

.rt-btn:active:not(:disabled) {
    transform: scale(.95);
}

.rt-btn:disabled {
    opacity: .35;
    cursor: not-allowed;
}

.rt-btn.active {
    background: #c62828;
    border-color: #c62828;
    color: #fff;
}

.rt-btn i {
    font-size: 13px;
}

.rt-zoom-val {
    min-width: 52px;
    text-align: center;
    font-size: 13px;
    color: #b9c0c8;
    font-variant-numeric: tabular-nums;
}

.rt-pager {
    font-size: 13px;
    color: #cfd5db;
    font-variant-numeric: tabular-nums;
    padding: 0 8px;
    white-space: nowrap;
}

.rt-pager b {
    color: #fff;
    font-size: 14px;
}

/* ------------------------------------------------------------------ 书本舞台 */
.reader-stage {
    position: relative;
    flex: 1 1 auto;
    overflow: hidden;
    background:
        radial-gradient(ellipse 70% 60% at 50% 45%, rgba(120, 132, 148, .22) 0%, rgba(0, 0, 0, 0) 70%),
        linear-gradient(#2a2e34, #1b1e22);
}

/* 书本视口：放大后可滚动查看，未放大时居中 */
.reader-viewport {
    position: absolute;
    inset: 0;
    display: flex;
    overflow: auto;
    scrollbar-width: thin;
}

.reader-viewport::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.reader-viewport::-webkit-scrollbar-thumb {
    background: #454b54;
    border-radius: 5px;
}

.reader-viewport.grabbing {
    cursor: grabbing;
}

.reader-viewport.grab {
    cursor: grab;
}

.reader-stage.grabbing {
    cursor: grabbing;
}

.reader-stage.grab {
    cursor: grab;
}

/* -------------------------------------------------------------- 3D 翻页书本 */
.reader-book {
    position: relative;
    flex: 0 0 auto;
    margin: auto;
    perspective: 2800px;
    perspective-origin: 50% 50%;
    touch-action: none;
}

/* 单页与双页的几何差异 */
.reader-book.spread .reader-leaf {
    left: 50%;
    width: 50%;
}

.reader-book.single .reader-leaf {
    left: 0;
    width: 100%;
}

.reader-leaf {
    position: absolute;
    top: 0;
    height: 100%;
    transform-origin: left center;
    transform-style: preserve-3d;
    transform: rotateY(0deg);
    transition: transform .72s cubic-bezier(.25, .72, .34, 1);
    will-change: transform;
    backface-visibility: visible;
}

.reader-leaf.flipped {
    transform: rotateY(-180deg);
}

/* 空白页（封面内侧 / 末页补白） */
.reader-leaf.flipped,
.reader-leaf:not(.flipped) {
    backface-visibility: visible;
}

.reader-book.no-anim .reader-leaf {
    transition: none !important;
}

.reader-book.single .reader-leaf {
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .25);
}

/* 单页模式下翻走的页会转到书本左侧（舞台内），保持可拖回 */

/* ------------------------------------------------------------------ 书页正反 */
.reader-face {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: #fff;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    box-shadow: 0 14px 34px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .3);
}

.reader-face.back {
    transform: rotateY(180deg);
}

.reader-face img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
    pointer-events: none;
    -webkit-user-drag: none;
    user-select: none;
}

/* 页面加载中的骨架 */
.reader-face.pending {
    background: linear-gradient(100deg, #f2f2f2 30%, #fafafa 50%, #f2f2f2 70%);
    background-size: 220% 100%;
    animation: reader-shimmer 1.2s linear infinite;
}

@keyframes reader-shimmer {
    from {
        background-position: 140% 0;
    }

    to {
        background-position: -40% 0;
    }
}

/* 空白页 */
.reader-face.blank {
    background: #f7f7f5;
    animation: none;
}

.reader-face.blank::after {
    content: '';
    position: absolute;
    inset: 14px;
    border: 1px dashed rgba(0, 0, 0, .07);
    border-radius: 2px;
}

/* 内边距处的纸张阴影，让书页有厚度感（书脊在左边缘） */
.reader-face.front::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    background: linear-gradient(to right, rgba(0, 0, 0, .22), rgba(0, 0, 0, 0) 9%);
}

/* 背面被自身 rotateY(180deg) 镜像，本地左边缘显示为右侧书脊 */
.reader-face.back::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    background: linear-gradient(to right, rgba(0, 0, 0, .22), rgba(0, 0, 0, 0) 9%);
}

/* 翻动过程中的动态高光 */
.reader-leaf.flipping .reader-face::before {
    background: linear-gradient(to right, rgba(0, 0, 0, .36), rgba(0, 0, 0, .05) 24%, rgba(0, 0, 0, 0) 46%);
}

/* 书脊阴影（需盖在书页之上） */
.reader-spine {
    position: absolute;
    top: 0;
    left: 50%;
    width: 44px;
    height: 100%;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 1200;
    opacity: 0;
    transition: opacity .35s;
    background: linear-gradient(to right,
            rgba(0, 0, 0, 0) 0%,
            rgba(0, 0, 0, .10) 32%,
            rgba(0, 0, 0, .26) 50%,
            rgba(0, 0, 0, .10) 68%,
            rgba(0, 0, 0, 0) 100%);
}

.reader-book.show-spine .reader-spine {
    opacity: 1;
}

/* ------------------------------------------------------------- 左右翻页箭头 */
.reader-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 46px;
    height: 92px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .32);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 20px;
    cursor: pointer;
    z-index: 45;
    transition: background .2s, opacity .2s, transform .2s;
    backdrop-filter: blur(2px);
}

.reader-nav:hover:not(:disabled) {
    background: rgba(198, 40, 40, .82);
}

.reader-nav:disabled {
    opacity: .12;
    cursor: not-allowed;
}

.reader-nav.prev {
    left: 14px;
}

.reader-nav.next {
    right: 14px;
}

/* ------------------------------------------------------------- 缩略图 / 目录 */
.reader-thumbs {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 264px;
    background: #191c20;
    border-right: 1px solid #0d0f12;
    box-shadow: 6px 0 22px rgba(0, 0, 0, .5);
    transform: translateX(-102%);
    transition: transform .3s cubic-bezier(.3, .7, .3, 1);
    z-index: 50;
    display: flex;
    flex-direction: column;
}

.reader-thumbs.open {
    transform: translateX(0);
}

.reader-thumbs-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 11px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #dfe3e8;
    border-bottom: 1px solid #262a30;
    flex: 0 0 auto;
}

.reader-thumbs-grid {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    align-content: start;
    scrollbar-width: thin;
}

.reader-thumbs-grid::-webkit-scrollbar,
.reader-thumbs::-webkit-scrollbar {
    width: 8px;
}

.reader-thumbs-grid::-webkit-scrollbar-thumb {
    background: #3a3f46;
    border-radius: 4px;
}

.reader-thumb {
    position: relative;
    width: 100%;
    height: 100%;
    background: #fff;
    border: 2px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color .2s, transform .2s;
}

.reader-thumb:hover {
    transform: translateY(-2px);
    border-color: rgba(198, 40, 40, .55);
}

.reader-thumb.active {
    border-color: #e53935;
    box-shadow: 0 0 0 2px rgba(229, 57, 53, .3);
}

.reader-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
}

.reader-thumb .reader-thumb-no {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 2px 0;
    text-align: center;
    font-size: 10px;
    line-height: 1.4;
    color: #fff;
    background: rgba(0, 0, 0, .55);
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- 底部状态栏 */
.reader-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 16px;
    background: linear-gradient(#22262b, #1a1d21);
    border-top: 1px solid #101216;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, .4);
    z-index: 30;
    flex-wrap: wrap;
}

.reader-progress {
    flex: 1 1 200px;
    min-width: 120px;
    height: 6px;
    border-radius: 3px;
    background: #40454d;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    cursor: pointer;
}

.reader-progress::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #e53935;
    border: 2px solid #fff;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .5);
}

.reader-progress::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #e53935;
    border: 2px solid #fff;
    cursor: pointer;
}

.reader-footer .rt-label {
    font-size: 12px;
    color: #a8b0b8;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ------------------------------------------------------------------ 加载遮罩 */
.reader-loading {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(24, 27, 31, .78);
    color: #dfe3e8;
    font-size: 14px;
    z-index: 60;
}

.reader-loading.show {
    display: flex;
}

.reader-loading i {
    font-size: 30px;
    color: #e53935;
    animation: reader-spin 1.4s linear infinite;
}

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

/* 轻提示 */
.reader-toast {
    position: absolute;
    left: 50%;
    bottom: 84px;
    transform: translate(-50%, 12px);
    padding: 8px 16px;
    background: rgba(0, 0, 0, .78);
    color: #fff;
    font-size: 13px;
    border-radius: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s, transform .25s;
    z-index: 70;
    white-space: nowrap;
}

.reader-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* -------------------------------------------------------------------- 响应式 */
@media (max-width: 900px) {
    .reader-toolbar {
        padding: 8px 10px;
        gap: 7px;
    }

    .rt-btn {
        height: 32px;
        padding: 0 9px;
        font-size: 12px;
    }

    .reader-nav {
        width: 36px;
        height: 70px;
        font-size: 16px;
    }

    .reader-nav.prev {
        left: 6px;
    }

    .reader-nav.next {
        right: 6px;
    }

    .reader-thumbs {
        width: 210px;
    }

    .reader-footer {
        padding: 8px 10px;
        gap: 8px;
    }

    .reader-toolbar .rt-title {
        order: 10;
        flex-basis: 100%;
        font-size: 13px;
    }
}

@media print {
    .reader-overlay {
        display: none !important;
    }
}
