/* --- UI 层 (悬浮) --- */
#ui-layer { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 100; }

#theme-stage {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 0;
}

.typography-area {
    position: absolute; right: 8%; top: 25%; 
    text-align: right; pointer-events: none;
    transition: all 0.5s ease;
    z-index: 10; /* 确保在背景之上 */
}
.big-title {
    font-size: 10vw; font-weight: 900; line-height: 0.9; 
    color: var(--main-title-color);
    letter-spacing: -4px; text-transform: uppercase;
}
.sub-title {
    font-size: 1.2rem; color: var(--sub-title-color); 
    letter-spacing: 6px; margin-top: 10px; text-transform: uppercase; font-weight: 300;
}

.scroll-hint {
    position: absolute; left: 40px; bottom: 40px; 
    color: var(--text-secondary); font-size: 12px; 
    writing-mode: vertical-rl; letter-spacing: 2px;
    text-transform: uppercase;
    display: flex; align-items: center; gap: 10px;
}
.scroll-hint::after { content: ''; width: 1px; height: 40px; background: #cbd5e1; }

#fab-upload {
    position: absolute; bottom: 40px; right: 40px; pointer-events: auto;
    width: 64px; height: 64px; border-radius: 50%;
    background: var(--btn-bg); color: var(--btn-text); 
    display: flex; justify-content: center; align-items: center;
    font-size: 32px; box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    cursor: pointer; transition: 0.3s; z-index: 110;
}
#fab-upload:hover { transform: scale(1.1) rotate(90deg); background: #000; }

/* 打包按钮 */
#btn-export {
    position: absolute; top: 40px; right: 40px; pointer-events: auto;
    width: 116px; height: 41px;
    background: var(--btn-bg); color: var(--btn-text);
    border-radius: 30px; border: none;
    display: flex; justify-content: center; align-items: center;
    font-size: 14px; font-weight: 700;
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
    cursor: pointer; transition: 0.3s; z-index: 110;
}
#btn-export:hover { transform: translateY(-2px); box-shadow: 0 15px 30px rgba(0,0,0,0.2); background: var(--btn-hover-bg); }

/* =========================================
   阅读模式状态 (Reading Mode)
   ========================================= */
body.reading-mode #global-ui-controls,
body.reading-mode #theme-toggle-btn {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s;
}

/* =========================================
   VIEW 1: 平面扇形首页 (HOME)
   ========================================= */
#home-view {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: block; 
    opacity: 1; transition: opacity 0.6s, transform 0.6s;
    z-index: 30; /* 确保位于背景之上，但低于 UI 层 */
}

body[data-theme]:not([data-theme="default"]) #home-view {
    --fan-area-width: min(520px, 45vw);
    clip-path: inset(0 calc(100% - var(--fan-area-width)) 0 0);
}

@media (max-width: 768px) {
    body[data-theme]:not([data-theme="default"]) #home-view {
        --fan-area-width: 100vw;
        clip-path: none;
    }
}
#home-view.hidden-view {
    opacity: 0; pointer-events: none; 
    transform: scale(1.1) translateX(-50px); 
    filter: blur(10px);
}

.fan-card {
    position: absolute;
    left: 0; top: 50%; 
    width: 280px; height: 400px;
    margin-left: -140px; margin-top: -200px; 
    
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: var(--card-border);
    border-radius: 20px;
    box-shadow: var(--card-shadow);
    
    display: flex; flex-direction: column; padding: 15px;
    cursor: pointer;
    
    transform-origin: center center;
    will-change: transform;
    transition: background 0.3s, left 0.5s ease; /* 增加位置过渡 */
}

.fan-card:hover {
    background: var(--card-hover-bg);
    border-color: var(--card-hover-border);
    box-shadow: var(--card-hover-shadow);
    z-index: 9999 !important;
}

.card-img-box {
    flex: 1; width: 100%; 
    border-radius: 12px; overflow: hidden; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    background: #f1f5f9;
    position: relative;
}
.card-img-box img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s; }
.fan-card:hover .card-img-box img { transform: scale(1.05); }

.card-title {
    margin-top: 15px; text-align: center;
    color: var(--card-title-color); font-size: 14px; font-weight: 700; letter-spacing: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* --- ★★★ 移动端适配核心代码 ★★★ --- */
@media (max-width: 768px) {
    /* 1. 将扇形整体向左移，留出右侧空间 */
    .fan-card {
        left: -42% !important; /* 加大向左偏移量，原为 -15% */
        width: 200px; /* 缩小卡片宽度 */
        height: 280px; /* 缩小卡片高度 */
        margin-top: -140px; /* 调整垂直中心点 */
        margin-left: -80px; /* 微调水平中心点，原为 -100px */
    }
    
    /* 2. 调整右侧文字布局 */
    .typography-area {
        right: 20px;
        top: 15%;
    }
    .big-title {
        font-size: 18vw; /* 放大文字 */
        color: rgba(0,0,0,0.05); /* 稍微加深一点点 */
    }
    .sub-title {
        font-size: 1rem;
        letter-spacing: 3px;
        margin-top: 5px;
    }
    
    /* 3. 调整底部提示语位置 */
    .scroll-hint {
        left: 20px; bottom: 30px;
    }

    /* 4. 缩小返回按钮 */
    .back-btn {
        padding: 0;
        width: 110px; /* 稍微加宽，原为 100px */
        height: 36px;
        justify-content: center;
        font-size: 12px;
        gap: 5px;
        white-space: nowrap; /* 强制不换行 */
    }

    /* 5. 缩小打包按钮 */
    #btn-export {
        top: 20px; right: 20px;
        width: 110px; height: 36px;
        font-size: 12px;
    }
}

/* =========================================
   VIEW 2: 阅读器 (READER)
   ========================================= */
#reader-view {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    opacity: 0; pointer-events: none; transform: scale(0.95);
    z-index: 150; display: flex; flex-direction: column;
    background: var(--reader-bg); 
    transition: all 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
    visibility: hidden;
}
#reader-view.active-view {
    opacity: 1; pointer-events: auto; transform: scale(1); visibility: visible;
}

#top-nav { height: 70px; display: flex; justify-content: space-between; align-items: center; padding: 0 30px; position: relative; z-index: 200; }
.back-btn { 
    cursor: pointer; font-size: 14px; color: var(--back-btn-text); font-weight: 700; 
    display: flex; align-items: center; gap: 8px; 
    padding: 10px 20px; background: var(--back-btn-bg); 
    border-radius: 30px; transition: 0.3s; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.back-btn span {
    display: inline-flex;
    align-items: center;
    height: 100%;
    transform: translateY(-1px); /* 微调垂直对齐 */
}
.back-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,0.1); }

.detail-link { 
    font-size: 14px; color: #4a5568; text-decoration: none; 
    border-bottom: 1px solid #a0aec0; padding-bottom: 2px; 
    opacity: 0; pointer-events: none; transition: 0.3s; 
}
.detail-link.show { opacity: 1; pointer-events: auto; }

.tip-text {
    position: absolute;
    right: 30px;
    top: 35px; /* 垂直居中于 70px 高的导航栏 */
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--text-secondary);
    pointer-events: none;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 200;
    transition: opacity 0.5s;
}
@media (max-width: 768px) {
    .tip-text {
        right: 20px;
        /* 保持垂直居中 */
        font-size: 10px;
    }
}

#stage-area { 
    flex: 1; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    position: relative; 
    z-index: 10;
    overflow: hidden;
    perspective: 1500px; /* 增强 3D 透视感 */
}

#reader-view:not(.active-view) * {
    pointer-events: none !important;
}

#click-layer {
    position: absolute;
    inset: 0;
    z-index: 20;
    background: transparent;
    pointer-events: none;
}

#reader-view.active-view #click-layer {
    pointer-events: auto;
}

#book-wrapper {
    position: relative;
    z-index: 10;
}
#book-wrapper { 
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1); 
    opacity: 0; 
    transform-style: preserve-3d;
    transform-origin: center center;
}
/* 进出场动画状态 */
.book-exit-left {
    transform: translateX(-100px) rotateY(-30deg) scale(0.9);
    opacity: 0 !important;
}
.book-exit-right {
    transform: translateX(100px) rotateY(30deg) scale(0.9);
    opacity: 0 !important;
}
.book-enter {
    transform: scale(0.95);
    opacity: 0;
}
.book-active {
    transform: translateX(0) rotateY(0) scale(1);
    opacity: 1 !important;
}

.stf__wrapper { box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.15) !important; }

#bookshelf-container { 
    height: 160px; 
    background: white; 
    border-top: 1px solid #f1f5f9; 
    display: flex; 
    align-items: center; 
    z-index: 30; 
    position: relative;
    transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: height;
}
#bookshelf-container.collapsed {
    height: 0;
    border-top: none;
    overflow: visible; /* 关键修正：允许按钮溢出显示 */
}

/* 书架内容区单独控制透明度 */
#bookshelf { 
    display: flex; 
    gap: 24px; 
    padding: 0 40px; 
    overflow-x: auto; 
    width: 100%; 
    height: 100%; 
    align-items: center; 
    scrollbar-width: none;
    transition: opacity 0.3s; 
}
#bookshelf-container.collapsed #bookshelf {
    opacity: 0;
    pointer-events: none;
}
.shelf-toggle-btn {
    position: absolute;
    right: 40px;
    top: -24px; /* 按钮高度的一半左右，使其浮在边缘 */
    width: 48px;
    height: 24px;
    background: white;
    border-radius: 12px 12px 0 0;
    border: 1px solid #f1f5f9;
    border-bottom: none;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    cursor: pointer;
    z-index: 40;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: bottom 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.shelf-toggle-btn::after {
    content: '';
    width: 0; 
    height: 0; 
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid #94a3b8; /* 向下的箭头，表示收起 */
    transition: transform 0.3s;
}
/* 当书架收起时，按钮需要改变形态或位置 */
#bookshelf-container.collapsed .shelf-toggle-btn {
    border-radius: 12px 12px 0 0; /* 恢复为上半圆角，与展开状态保持一致 */
    border: 1px solid #f1f5f9; /* 恢复边框颜色 */
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05); /* 恢复阴影方向（虽然在底部，但保持样式统一性） */
    top: auto; 
    bottom: 0; /* 紧贴底部边缘 */
    z-index: 100; 
}
#bookshelf-container.collapsed {
    overflow: visible; /* 关键修正：允许按钮溢出显示 */
}
#bookshelf-container.collapsed .shelf-toggle-btn::after {
    transform: rotate(180deg); /* 箭头向上，表示展开 */
}


.book-item { width: 80px; height: 140px; /* 增加高度以容纳文字 */ flex-shrink: 0; cursor: pointer; transition: 0.3s; opacity: 0.5; transform: scale(0.95); filter: grayscale(100%); display: flex; flex-direction: column; align-items: center; position: relative; }
.book-item.active { opacity: 1; transform: scale(1.05); filter: grayscale(0%); }
/* 激活状态下的图片样式调整移到下面单独处理 */
.book-item.active .book-thumb { box-shadow: 0 10px 20px rgba(0,0,0,0.15); border: 2px solid #3b82f6; }

.book-thumb { width: 80px; height: 110px; object-fit: cover; border-radius: 4px; transition: 0.3s; flex-shrink: 0; }

.book-name {
    margin-top: 8px;
    font-size: 10px;
    color: #64748b;
    text-align: center;
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}
.book-item.active .book-name { color: #3b82f6; font-weight: 700; }

/* 删除按钮样式 */
.delete-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    display: none; /* 默认隐藏 */
    justify-content: center;
    align-items: center;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    z-index: 10;
    cursor: pointer;
    transition: transform 0.2s;
}
.delete-btn:hover { transform: scale(1.1); background: #dc2626; }
.book-item.active .delete-btn { display: flex; /* 选中时显示 */ }

@media (max-width: 768px) {
    .book-item { width: 60px; height: 110px; }
    .book-thumb { width: 60px; height: 85px; }
    .book-name { font-size: 9px; margin-top: 5px; }
    /* 移动端调整删除按钮位置 */
    .delete-btn { width: 18px; height: 18px; font-size: 10px; top: -5px; right: -5px; }
}

/* 书页样式 */
.page { background-color: #fdfbf7; border: 1px solid #e2e2e2; overflow: hidden; }
.page.--cover { background-color: #1a202c; color: white; border: none; }
.page-content { padding: 40px; height: 100%; box-sizing: border-box; display: flex; flex-direction: column; }
.cover-img-box { width: 100%; height: 60%; overflow: hidden; margin-bottom: 25px; border: 4px solid #fff; box-shadow: 0 10px 20px rgba(0,0,0,0.3); background: #eee; }
.cover-img-box img { width: 100%; height: 100%; object-fit: cover; }
.book-title { font-size: 24px; line-height: 1.2; text-transform: uppercase; text-align: center; font-weight: bold; letter-spacing: 1px; }
.text-body { font-size: 16px; line-height: 1.8; text-align: justify; color: #334155; }

.page.full-image .page-content { padding: 0; width: 100%; height: 100%; }
.page.full-image img { width: 100%; height: 100%; object-fit: cover; background: #fff; }
.page.--cover.landscape-cover { display: flex; justify-content: center; align-items: center; padding: 0; background: #1a202c; }
.page.--cover.landscape-cover img { width: 100%; height: 100%; object-fit: contain; border: none; box-shadow: none; }

/* --- 弹窗 --- */
#modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--modal-overlay); backdrop-filter: blur(10px); display: none; justify-content: center; align-items: center; z-index: 200; opacity: 0; transition: 0.3s; --btn-bg: #0f172a; --btn-text: #fff; --btn-hover-bg: #1e293b; }
#modal-overlay.show { opacity: 1; }
.modal-card { background: var(--modal-bg); width: 500px; max-width: 90%; border-radius: 24px; padding: 30px; box-shadow: 0 40px 80px rgba(0,0,0,0.2); transform: scale(0.95); transition: 0.3s; color: #0f172a; }
#modal-overlay.show .modal-card { transform: scale(1); }
.tabs { display: flex; background: #f1f5f9; padding: 5px; margin-bottom: 25px; border-radius: 12px; }
.tab { flex: 1; padding: 10px; text-align: center; cursor: pointer; border-radius: 8px; font-size: 14px; font-weight: 600; color: #64748b; transition: 0.2s; }
.tab.active { background: white; color: #0f172a; box-shadow: 0 4px 10px rgba(0,0,0,0.05); }
.input-group { margin-bottom: 20px; }
.input-label { display: block; font-size: 12px; font-weight: 700; color: #94a3b8; margin-bottom: 8px; letter-spacing: 0.5px; }
.input-field { width: 100%; padding: 12px; border: 2px solid #f1f5f9; border-radius: 10px; font-size: 15px; outline: none; transition: 0.2s; background: #f8fafc; }
.input-field:focus { border-color: #cbd5e1; background: white; }
.btn-primary { background: var(--btn-bg); color: var(--btn-text); padding: 12px 24px; border-radius: 10px; border: none; cursor: pointer; font-weight: bold; float: right; transition: 0.2s; }
.btn-primary:hover { background: var(--btn-hover-bg); transform: translateY(-2px); }

#loading-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255,255,255,0.9); z-index: 300; display: none; flex-direction: column; justify-content: center; align-items: center; }
#measure-box { position: fixed; top: -9999px; width: 320px; visibility: hidden; }

/* =========================================
   SIDEBAR & TOGGLE
   ========================================= */
#theme-toggle-btn {
    position: fixed; right: 0; top: 50%; z-index: 9999;
    width: 40px; height: 60px;
    background: #1a202c; color: #fff;
    border-radius: 8px 0 0 8px;
    display: flex; justify-content: center; align-items: center;
    box-shadow: -4px 0 10px rgba(0,0,0,0.1);
    cursor: pointer; transition: 0.3s;
    transform: translateY(-50%);
}
#theme-toggle-btn:hover { padding-right: 5px; width: 45px; background: #000; }

#theme-sidebar {
    position: fixed; top: 0; right: 0; width: 300px; height: 100%;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    box-shadow: -10px 0 30px rgba(0,0,0,0.1);
    z-index: 10000;
    transform: translateX(100%); transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; flex-direction: column;
}
#theme-sidebar.active { transform: translateX(0); }

.sidebar-header {
    padding: 25px;
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}
.sidebar-header h3 { margin: 0; font-size: 18px; font-weight: 800; color: #1a202c; }
.close-btn { font-size: 24px; cursor: pointer; color: #64748b; transition: 0.2s; }
.close-btn:hover { color: #000; transform: rotate(90deg); }

.theme-list { padding: 20px; overflow-y: auto; flex: 1; }
.theme-item {
    display: flex; align-items: center; gap: 15px;
    padding: 15px; margin-bottom: 10px;
    background: rgba(255,255,255,0.5);
    border-radius: 12px; border: 2px solid transparent;
    cursor: pointer; transition: 0.2s;
}
.theme-item:hover { background: rgba(255,255,255,0.8); transform: translateX(-5px); }
.theme-item.active { border-color: #1a202c; background: #fff; }

.theme-preview { width: 30px; height: 30px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.1); box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.theme-item span { font-size: 14px; font-weight: 600; color: #334155; }

#sidebar-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.3); backdrop-filter: blur(2px);
    z-index: 9998; opacity: 0; pointer-events: none; transition: 0.3s;
}
#sidebar-overlay.active { opacity: 1; pointer-events: auto; }
