/* ============================================================
   云阅电子书 - 仿真翻页阅读器样式 v2
   仿照 yunzhan365：封面单页 → 双页展开
   ============================================================ */

/* ---------- 重置 ---------- */
#flipStage * { box-sizing: border-box; }
#flipStage { margin: 0; padding: 0; }

:root {
    --fb-blue: #2e71a9;
    --fb-blue-light: rgba(46, 113, 169, 0.5);
    --fb-bar-bg: #f4f9fb;
    --fb-font: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    --fb-pink: #d23a9c;
}

/* ---------- 整体舞台 ---------- */
#flipStage {
    position: fixed;
    inset: 0;
    z-index: 9999;
    overflow: hidden;
    font-family: var(--fb-font);
    -webkit-user-select: none;
    user-select: none;
    /* 天空蓝渐变背景 */
    background: linear-gradient(180deg,
        #a8cee5 0%,
        #b8d8ea 15%,
        #c8e0f0 30%,
        #d8e8f2 50%,
        #e8f0f5 70%,
        #f0f5f8 85%,
        #f5f8fa 100%);
}

/* 背景云层装饰 */
#flipStage::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 60% 35% at 15% 75%, rgba(255,255,255,0.6), transparent 70%),
        radial-gradient(ellipse 50% 30% at 85% 80%, rgba(255,255,255,0.5), transparent 70%),
        radial-gradient(ellipse 70% 40% at 50% 90%, rgba(255,255,255,0.4), transparent 70%);
    pointer-events: none;
    z-index: 0;
}

/* ---------- 书本区域容器 ---------- */
.fb-book-area {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    perspective: 2500px;
}

/* ---------- 书本 ---------- */
.fb-book {
    position: relative;
    transform-style: preserve-3d;
}

/* 封面状态：单页宽度 */
.fb-book.cover-mode {
    width: min(520px, 92vw);
    height: min(82vh, 720px);
}

/* 双页展开状态：双页宽度 */
.fb-book.spread-mode {
    width: min(1040px, 95vw);
    height: min(82vh, 720px);
}

/* ---------- 书脊（双页中间折痕） ---------- */
.fb-book.spread-mode::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 0; bottom: 0;
    width: 24px;
    transform: translateX(-50%);
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(80,80,80,0.06) 20%,
        rgba(80,80,80,0.15) 45%,
        rgba(80,80,80,0.2) 50%,
        rgba(80,80,80,0.15) 55%,
        rgba(80,80,80,0.06) 80%,
        transparent 100%);
    z-index: 5;
    pointer-events: none;
}

/* 书本投影 */
.fb-book::after {
    content: "";
    position: absolute;
    left: 2%; right: 2%;
    bottom: -8px;
    height: 20px;
    background: radial-gradient(ellipse 50% 100% at center, rgba(0,0,0,0.15), transparent 70%);
    z-index: -1;
    pointer-events: none;
}

/* ---------- 页面容器 ---------- */
.fb-pages {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

/* ---------- 单个页面 ---------- */
.fb-page {
    position: absolute;
    top: 0;
    height: 100%;
    background: #fffdf8;
    box-shadow:
        0 4px 20px rgba(0,0,0,0.12),
        0 1px 6px rgba(0,0,0,0.08);
    overflow: hidden;
    transform-origin: left center;
    backface-visibility: hidden;
}

/* 封面模式：单页占满 */
.fb-book.cover-mode .fb-page {
    left: 0;
    width: 100%;
}

/* 双页模式：左页在左半，右页在右半 */
.fb-book.spread-mode .fb-page.fb-left-page {
    left: 0;
    width: 50%;
    border-radius: 4px 0 0 4px;
    box-shadow:
        -2px 4px 20px rgba(0,0,0,0.12),
        0 1px 6px rgba(0,0,0,0.08);
}
.fb-book.spread-mode .fb-page.fb-right-page {
    left: 50%;
    width: 50%;
    border-radius: 0 4px 4px 0;
    box-shadow:
        2px 4px 20px rgba(0,0,0,0.12),
        0 1px 6px rgba(0,0,0,0.08);
}

/* 页面可见性 */
.fb-page { opacity: 0; visibility: hidden; z-index: 1; transition: opacity .15s; }
.fb-page.active { opacity: 1; visibility: visible; z-index: 2; }

/* ---------- 3D 翻页层 ---------- */
.fb-flip-layer {
    position: absolute;
    top: 0;
    height: 100%;
    transform-style: preserve-3d;
    z-index: 20;
    pointer-events: none;
}

/* 向前翻：右页向左翻转 */
.fb-flip-layer.flip-fwd {
    left: 50%;
    width: 50%;
    transform-origin: left center;
    animation: fbFlipFwd 0.8s cubic-bezier(0.3, 0.05, 0.2, 1) forwards;
}

/* 向后翻：左页向右翻转 */
.fb-flip-layer.flip-bwd {
    left: 0;
    width: 50%;
    transform-origin: right center;
    animation: fbFlipBwd 0.8s cubic-bezier(0.3, 0.05, 0.2, 1) forwards;
}

@keyframes fbFlipFwd {
    from { transform: rotateY(0deg); }
    to   { transform: rotateY(-180deg); }
}
@keyframes fbFlipBwd {
    from { transform: rotateY(0deg); }
    to   { transform: rotateY(180deg); }
}

/* 翻页正反面 */
.fb-flip-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background: #fffdf8;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
}
.fb-flip-face.fb-flip-back {
    transform: rotateY(180deg);
}

/* 翻页动态阴影 */
.fb-flip-shadow {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}
.fb-flip-layer.flip-fwd .fb-flip-shadow {
    background: linear-gradient(90deg,
        rgba(0,0,0,0.28) 0%,
        rgba(0,0,0,0.12) 35%,
        rgba(0,0,0,0.03) 65%,
        transparent 100%);
}
.fb-flip-layer.flip-bwd .fb-flip-shadow {
    background: linear-gradient(270deg,
        rgba(0,0,0,0.28) 0%,
        rgba(0,0,0,0.12) 35%,
        rgba(0,0,0,0.03) 65%,
        transparent 100%);
}

/* 封面过渡动画 */
.fb-page.fb-cover-page.cover-fade-out {
    animation: fbCoverFadeOut 0.5s ease-in forwards;
}
.fb-page.cover-fade-in {
    animation: fbCoverFadeIn 0.5s ease-out forwards;
}
@keyframes fbCoverFadeOut {
    from { opacity: 1; transform: scale(1) rotateY(0deg); }
    to   { opacity: 0; transform: scale(0.92) rotateY(-25deg); }
}
@keyframes fbCoverFadeIn {
    from { opacity: 0; transform: scale(0.92) rotateY(25deg); }
    to   { opacity: 1; transform: scale(1) rotateY(0deg); }
}

/* ---------- 页面内容 ---------- */
.fb-inner {
    position: absolute;
    inset: 0;
    padding: 50px 44px 60px;
    overflow: hidden;
    line-height: 1.9;
    color: #333;
    font-size: 17px;
    text-align: justify;
    word-break: break-word;
    display: flex;
    flex-direction: column;
}

/* 封面内容 */
.fb-inner.fb-cover-inner {
    padding: 0;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbfd 100%);
}

/* PDF 页面 canvas */
.fb-inner.fb-pdf-inner {
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
}
.fb-inner.fb-pdf-inner canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.fb-inner h2 {
    font-size: 1.35em;
    color: #2c3e50;
    margin: .15em 0 .55em;
    line-height: 1.4;
    border-left: 4px solid var(--fb-blue);
    padding-left: .6em;
    flex-shrink: 0;
}
.fb-inner h3 {
    font-size: 1.1em;
    color: #34495e;
    margin: .3em 0 .25em;
    flex-shrink: 0;
}
.fb-inner p {
    margin: 0 0 .6em;
    text-indent: 2em;
}
.fb-inner hr {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: .8em 0;
    flex-shrink: 0;
}
.fb-inner blockquote {
    margin: .4em 1em;
    padding: .3em .9em;
    border-left: 3px solid var(--fb-blue);
    background: rgba(46, 113, 169, 0.05);
    color: #555;
    font-size: .95em;
}

/* 页码（书页底部） */
.fb-pagenum {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: #999;
    letter-spacing: 1px;
    z-index: 10;
}

/* ---------- 封面内容 ---------- */
.fb-cover-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 40px 30px;
}
.fb-cover-content .cv-logo {
    display: inline-block;
    font-size: 12px;
    color: var(--fb-blue);
    letter-spacing: 3px;
    border: 1px solid rgba(46,113,169,0.3);
    border-radius: 20px;
    padding: 4px 16px;
    margin-bottom: 28px;
}
.fb-cover-content .cv-title {
    font-size: 2em;
    font-weight: 700;
    color: #1a3a5c;
    line-height: 1.35;
    letter-spacing: 2px;
    margin: 0 0 12px;
}
.fb-cover-content .cv-author {
    font-size: 15px;
    color: #667;
    margin-bottom: 20px;
}
.fb-cover-content .cv-desc {
    font-size: 14px;
    color: #888;
    line-height: 1.8;
    max-width: 80%;
    margin: 0 auto 24px;
    text-indent: 0;
}
.fb-cover-content .cv-hr {
    width: 50px;
    height: 2px;
    background: var(--fb-blue);
    border: none;
    border-radius: 2px;
    margin: 0 0 20px;
    opacity: 0.6;
}
.fb-cover-content .cv-tip {
    font-size: 12px;
    color: #aaa;
    letter-spacing: 1px;
}

/* ---------- 左侧"打开目录"标签 ---------- */
.fb-toc-toggle {
    position: absolute;
    background: var(--fb-pink);
    color: #fff;
    font-size: 13px;
    letter-spacing: 3px;
    padding: 14px 8px;
    border-radius: 6px;
    cursor: pointer;
    z-index: 50;
    box-shadow: 2px 2px 10px rgba(0,0,0,0.2);
    transition: opacity .3s, transform .3s;
    white-space: nowrap;
    line-height: 1.5;
    font-weight: 500;
    border: none;
    font-family: var(--fb-font);
    writing-mode: vertical-rl;
    text-orientation: upright;
}

/* 封面模式：标签在书本右侧上方 */
.fb-book.cover-mode .fb-toc-toggle {
    right: -10px;
    top: 30px;
    transform: translateX(100%);
}

/* 双页模式：标签在左页左侧上方 */
.fb-book.spread-mode .fb-toc-toggle {
    left: -10px;
    top: 30px;
    transform: translateX(-100%);
}

.fb-toc-toggle:hover { opacity: 0.85; }
.fb-toc-toggle.hidden { opacity: 0; pointer-events: none; }

/* ---------- 翻页箭头 ---------- */
.fb-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 98px;
    height: 101px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.4);
    border-radius: 50%;
    cursor: pointer;
    z-index: 30;
    opacity: 0.5;
    transition: opacity .3s, background .3s;
    border: none;
}
.fb-nav-btn:hover {
    opacity: 0.85;
    background: rgba(255,255,255,0.6);
}
.fb-nav-btn svg { width: 32px; height: 32px; fill: var(--fb-blue); }
.fb-nav-btn.disabled { opacity: 0; pointer-events: none; }
.fb-nav-left { left: 10px; }
.fb-nav-right { right: 10px; }

/* ---------- 底部工具栏 ---------- */
.fb-toolbar {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 45px;
    background: var(--fb-bar-bg);
    box-shadow: 0 0 15px rgba(40,40,40,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    z-index: 40;
    padding: 0 10px;
}

.fb-logo {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--fb-blue);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 0 8px;
    white-space: nowrap;
}
.fb-logo svg { width: 20px; height: 20px; fill: var(--fb-blue); }

.fb-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 38px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--fb-blue);
    font-size: 11px;
    gap: 1px;
    padding: 0 4px;
    border-radius: 4px;
    transition: background .2s;
    font-family: var(--fb-font);
    line-height: 1;
}
.fb-btn:hover { background: rgba(46,113,169,0.08); }
.fb-btn:active { background: rgba(46,113,169,0.15); }
.fb-btn svg { width: 18px; height: 18px; fill: var(--fb-blue); }
.fb-btn span { font-size: 10px; color: var(--fb-blue); white-space: nowrap; }
.fb-btn.disabled { opacity: 0.35; pointer-events: none; }
.fb-btn.playing { background: rgba(46,113,169,0.15); }

.fb-sep {
    width: 1px;
    height: 20px;
    background: rgba(46,113,169,0.15);
    margin: 0 2px;
    flex-shrink: 0;
}

/* 页码输入框 */
.fb-page-input {
    display: flex;
    align-items: center;
    gap: 2px;
    margin: 0 4px;
}
.fb-page-input input {
    width: 50px;
    height: 24px;
    border: 1px solid #ccc;
    border-radius: 3px;
    text-align: center;
    font-size: 12px;
    color: #333;
    outline: none;
    font-family: var(--fb-font);
}
.fb-page-input input:focus { border-color: var(--fb-blue); }
.fb-page-input .total {
    font-size: 12px;
    color: #666;
}

/* ---------- 侧边目录 ---------- */
.fb-toc-panel {
    position: absolute;
    top: 0; left: 0; bottom: 45px;
    width: min(280px, 80vw);
    background: #1a3a5c;
    transform: translateX(-100%);
    transition: transform .35s cubic-bezier(.4,0,.2,1);
    z-index: 60;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 20px rgba(0,0,0,0.2);
}
.fb-toc-panel.open { transform: translateX(0); }
.fb-toc-head {
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}
.fb-toc-close {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; color: #fff;
    font-size: 20px; cursor: pointer; border-radius: 4px;
}
.fb-toc-close:hover { background: rgba(255,255,255,0.12); }
.fb-toc-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}
.fb-toc-list::-webkit-scrollbar { width: 4px; }
.fb-toc-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }
.fb-toc-item {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    color: rgba(255,255,255,0.85);
    font-size: 14px;
    cursor: pointer;
    transition: background .2s, color .2s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: var(--fb-font);
    line-height: 1.5;
    gap: 8px;
}
.fb-toc-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.fb-toc-item.current { background: rgba(46,113,169,0.3); color: #fff; }
.fb-toc-item .ti-num { font-size: 12px; color: rgba(255,255,255,0.4); min-width: 24px; }
.fb-toc-item.current .ti-num { color: rgba(255,255,255,0.8); }
.fb-toc-item .ti-text {
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fb-toc-item.toc-cover .ti-text { font-weight: 600; color: #7dd3fc; }

/* 目录遮罩 */
.fb-toc-mask {
    position: absolute; inset: 0; bottom: 45px;
    background: rgba(0,0,0,0.3);
    opacity: 0; visibility: hidden;
    transition: opacity .3s; z-index: 55;
}
.fb-toc-mask.show { opacity: 1; visibility: visible; }

/* ---------- 帮助弹窗 ---------- */
.fb-help {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: min(340px, 88vw);
    background: #fff; border-radius: 12px; padding: 20px 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    opacity: 0; visibility: hidden;
    transition: all .25s cubic-bezier(.4,0,.2,1); z-index: 100;
}
.fb-help.show { opacity: 1; visibility: visible; transform: translate(-50%, -50%) scale(1); }
.fb-help h3 { margin: 0 0 12px; color: #1a3a5c; font-size: 16px; }
.fb-help ul { margin: 0; padding-left: 18px; color: #555; font-size: 13.5px; line-height: 2; }
.fb-help .fh-close {
    margin-top: 14px; width: 100%; height: 36px;
    border: none; border-radius: 8px;
    background: var(--fb-blue); color: #fff; font-size: 14px; cursor: pointer;
    font-family: var(--fb-font);
}
.fb-help .fh-close:hover { background: #2563eb; }
.fb-help-mask {
    position: absolute; inset: 0; background: rgba(0,0,0,0.3);
    opacity: 0; visibility: hidden; transition: opacity .3s; z-index: 90;
}
.fb-help-mask.show { opacity: 1; visibility: visible; }

/* ---------- 举报链接 ---------- */
.fb-report {
    position: absolute; right: 8px; bottom: 52px;
    color: rgba(46, 113, 169, 0.5); font-size: 12px;
    z-index: 35; cursor: pointer; font-family: var(--fb-font);
    transition: opacity .2s;
}
.fb-report:hover { opacity: 0.8; }

/* ---------- 放大遮罩 ---------- */
.fb-zoom-overlay {
    position: absolute; inset: 0; background: rgba(0,0,0,0.8);
    z-index: 200; display: none; align-items: center; justify-content: center; cursor: pointer;
}
.fb-zoom-overlay.show { display: flex; }
.fb-zoom-overlay .zo-page {
    width: min(700px, 92vw); height: min(90vh, 900px);
    background: #fffdf8; overflow-y: auto; padding: 50px 50px 60px;
    line-height: 2; font-size: 18px; color: #333;
    border-radius: 4px; box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.fb-zoom-overlay .zo-close {
    position: absolute; top: 20px; right: 20px;
    width: 40px; height: 40px; background: rgba(255,255,255,0.15);
    border: none; border-radius: 50%; color: #fff; font-size: 20px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

/* ---------- 加载提示 ---------- */
.fb-loading {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: var(--fb-blue);
    font-size: 16px;
    z-index: 50;
    text-align: center;
}
.fb-loading .spinner {
    width: 40px; height: 40px;
    border: 3px solid rgba(46,113,169,0.2);
    border-top-color: var(--fb-blue);
    border-radius: 50%;
    animation: fbSpin 0.8s linear infinite;
    margin: 0 auto 12px;
}
@keyframes fbSpin { to { transform: rotate(360deg); } }

/* ---------- 离屏测量 ---------- */
.fb-measure {
    position: absolute !important;
    left: -99999px !important;
    top: 0 !important;
    inset: auto !important;
    visibility: hidden;
    pointer-events: none;
    overflow: visible !important;
    display: block !important;
    opacity: 0;
}

/* ---------- 主题 ---------- */
.fb-book.theme-sepia .fb-page { background: #f5ecd7; }
.fb-book.theme-sepia .fb-inner { color: #4f4638; }
.fb-book.theme-sepia .fb-inner h2 { color: #5a4632; }
.fb-book.theme-dark .fb-page { background: #2c2a28; }
.fb-book.theme-dark .fb-inner { color: #cfc6b8; }
.fb-book.theme-dark .fb-inner h2 { color: #d9c9a8; border-left-color: #7dd3fc; }
.fb-book.theme-dark .fb-inner h3 { color: #b8a588; }
.fb-book.theme-dark .fb-inner hr { border-top-color: #4a443c; }
.fb-book.theme-dark .fb-pagenum { color: #7c7468; }
.fb-book.theme-dark .fb-cover-content { background: linear-gradient(180deg, #2c2a28 0%, #3a3835 100%); }
.fb-book.theme-dark .fb-cover-content .cv-title { color: #e8dcc8; }
.fb-book.theme-dark .fb-cover-content .cv-author { color: #a89888; }
.fb-book.theme-dark .fb-cover-content .cv-desc { color: #998878; }

/* ---------- 移动端适配 ---------- */
@media (max-width: 768px) {
    .fb-book.cover-mode {
        width: 88vw;
        height: 80vh;
    }
    /* 移动端始终单页模式 */
    .fb-book.spread-mode {
        width: 88vw;
        height: 80vh;
    }
    .fb-book.spread-mode .fb-page.fb-left-page,
    .fb-book.spread-mode .fb-page.fb-right-page {
        left: 0;
        width: 100%;
        border-radius: 4px;
    }
    /* 移动端隐藏书脊 */
    .fb-book.spread-mode::before { display: none; }
    
    .fb-inner { padding: 32px 24px 48px; font-size: 16px; line-height: 1.85; }
    .fb-cover-content .cv-title { font-size: 1.6em; }
    .fb-cover-content .cv-desc { max-width: 90%; }
    
    /* 底部工具栏精简 */
    .fb-btn { min-width: 38px; }
    .fb-btn span { display: none; }
    .fb-logo { display: none; }
    .fb-sep { display: none; }
    .fb-btn[data-action="zoom"],
    .fb-btn[data-action="sound"],
    .fb-btn[data-action="share"],
    .fb-btn[data-action="fullscreen"] { display: none; }
    .fb-mobile-more { display: inline-flex !important; }
    
    .fb-mobile-panel {
        position: absolute; bottom: 45px; left: 50%;
        transform: translateX(-50%);
        background: var(--fb-bar-bg); border-radius: 12px 12px 0 0;
        padding: 8px 12px; display: none; gap: 4px; align-items: center;
        z-index: 45; box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    }
    .fb-mobile-panel.show { display: flex; }
    .fb-mobile-panel .fb-btn { display: inline-flex !important; }
    .fb-mobile-panel .fb-btn span { display: inline; }
    
    .fb-toc-toggle {
        font-size: 12px; padding: 12px 6px; letter-spacing: 3px;
    }
    .fb-nav-btn { width: 48px; height: 50px; }
    .fb-nav-btn svg { width: 22px; height: 22px; }
    .fb-nav-left { left: 4px; }
    .fb-nav-right { right: 4px; }
    .fb-report { bottom: 50px; font-size: 11px; }
}
@media (min-width: 769px) {
    .fb-mobile-more { display: none !important; }
    .fb-mobile-panel { display: none !important; }
}
