/* ========================================
   电子相册/杂志 - 自适应样式 v16
   翻页引擎：StPageFlip（page-flip 2.x）
   桌面端自动双页跨页（封面封底单显），手机端自动单页
   附带：缩略图 / 自动播放 / 全屏 / 滚轮缩放平移
   ======================================== */

/* 基础重置 */
* { margin:0; padding:0; box-sizing:border-box; }
html, body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: #0a0a0f; color: #e0e0e0; 
    overflow-x: hidden; -webkit-font-smoothing: antialiased;
}

/* ========== 列表页样式 ========== */
.album-app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.album-header {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-bottom: 1px solid #2a2a4a;
    padding: 0 20px;
    position: sticky; top: 0; z-index: 100;
}
.header-inner {
    max-width: 1200px; margin: 0 auto;
    display: flex; align-items: center; 
    height: 56px;
}
.logo-link {
    color: #6c63ff; text-decoration: none; font-size: 15px;
    font-weight: 500; white-space: nowrap;
}
.logo-link:hover { color: #8b83ff; }
.header-title {
    flex: 1; text-align: center; font-size: 18px; 
    font-weight: 600; color: #fff; letter-spacing: 2px;
}
.header-spacer { width: 60px; }

.container {
    max-width: 1200px; margin: 0 auto; padding: 30px 20px;
}

/* 相册网格 */
.album-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 24px;
}
.album-card {
    background: #1a1a2e; border-radius: 12px; overflow: hidden;
    text-decoration: none; color: #e0e0e0;
    transition: transform .3s, box-shadow .3s;
    border: 1px solid #2a2a4a;
    display: block;
}
.album-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 40px rgba(108,99,255,.2);
    border-color: #6c63ff;
}
.card-cover {
    position: relative; overflow: hidden;
    aspect-ratio: 4/3; background: #12121f;
}
.card-cover img {
    width: 100%; height: 100%; object-fit: cover;
    transition: transform .4s;
}
.album-card:hover .card-cover img { transform: scale(1.05); }
.card-cover-placeholder {
    width: 100%; height: 100%; display: flex;
    flex-direction: column; align-items: center; justify-content: center;
    font-size: 48px; color: #6c63ff; opacity: .6;
}
.card-cover-placeholder p { font-size: 14px; margin-top: 8px; }
.card-pages-badge {
    position: absolute; top: 10px; right: 10px;
    background: rgba(0,0,0,.7); color: #fff;
    padding: 3px 10px; border-radius: 20px; font-size: 12px;
}
.card-info { padding: 16px; }
.card-title { 
    font-size: 16px; font-weight: 600; margin-bottom: 6px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-desc { 
    font-size: 13px; color: #888; margin-bottom: 10px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; line-height: 1.5; min-height: 39px;
}
.card-meta { font-size: 12px; color: #666; }

/* 空状态 */
.empty-state {
    text-align: center; padding: 80px 20px; color: #666;
}
.empty-icon { font-size: 64px; margin-bottom: 16px; }
.empty-state p { font-size: 16px; }

/* 分页 */
.pagination-wrap { text-align: center; padding: 40px 0; }
.pagination-wrap .pagination { 
    display: inline-flex; gap: 6px; flex-wrap: wrap;
}
.pagination-wrap .pagination li { list-style: none; }
.pagination-wrap .pagination li a,
.pagination-wrap .pagination li span {
    display: inline-block; padding: 8px 14px;
    background: #1a1a2e; border: 1px solid #2a2a4a; border-radius: 6px;
    color: #ccc; text-decoration: none; font-size: 14px; transition: all .2s;
}
.pagination-wrap .pagination li.active span {
    background: #6c63ff; border-color: #6c63ff; color: #fff;
}
.pagination-wrap .pagination li a:hover {
    background: #2a2a4a; border-color: #6c63ff;
}
.pagination-wrap .pagination li.disabled span {
    opacity: .4; cursor: default;
}

/* 底部 */
.album-footer {
    margin-top: auto; padding: 24px; text-align: center;
    color: #555; font-size: 13px; border-top: 1px solid #1a1a2e;
}

/* ========== 阅读器样式 ========== */
.magazine-app {
    width: 100vw; height: 100vh; height: 100dvh;
    overflow: hidden; position: relative;
    background: #0a0a0f;
    display: flex; flex-direction: column;
    user-select: none;
}

/* 工具栏 */
.magazine-toolbar {
    display: flex; align-items: center; padding: 0 12px;
    height: 50px; flex-shrink: 0;
    background: rgba(26,26,46,.95); border-bottom: 1px solid #2a2a4a;
    backdrop-filter: blur(10px); z-index: 50;
    transition: transform .3s;
}
.magazine-toolbar.hidden { transform: translateY(-100%); }
.tool-btn {
    background: transparent; border: none; color: #ccc;
    font-size: 18px; padding: 8px 10px; cursor: pointer;
    text-decoration: none; border-radius: 6px; transition: all .2s;
    white-space: nowrap;
}
.tool-btn:hover { background: #2a2a4a; color: #fff; }
.tool-title {
    flex: 1; text-align: center; font-size: 16px; font-weight: 600;
    color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool-actions { display: flex; gap: 4px; align-items: center; }

.magazine-viewer {
    flex: 1; position: relative; overflow: hidden;
    background: #0a0a0f;
    display: flex; align-items: center; justify-content: center;
    padding: 0 0 28px 0; /* 仅底部留进度条空间，两侧无内边距 */
}

/* ========== 缩放包装层（JS 动态创建，包裹 bookContainer） ========== */
.zoom-wrapper {
    flex-shrink: 0;
    margin: 0 auto;
    transform-origin: center center;
    will-change: transform;
    transition: transform .08s ease-out;
}
.zoom-wrapper.zoomed {
    transition: none; /* 缩放/拖拽过程中禁用过渡 */
    cursor: grab;
}

/* 缩放百分比标签 */
.zoom-label {
    position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,.65); color: #fff; font-size: 12px;
    padding: 2px 10px; border-radius: 10px; z-index: 35;
    opacity: 0; transition: opacity .3s;
    pointer-events: none;
}
.zoom-label.visible { opacity: 1; }

/* ========== 书本容器（StPageFlip 挂载点，JS 动态设置精确宽高） ========== */
.book-container {
    position: relative;
}
/* StPageFlip 创建的 .stf__wrapper 由 JS 自动设样式，此处不覆盖 */
.book-container canvas,
.book-container .stf__wrapper {
    display: block;
}

/* ========== 书页基础样式（StPageFlip 会包裹这些元素） ========== */
.book-page {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    position: relative;
    overflow: hidden;
    background: #1a1a2e;
    width: 100%; height: 100%;
    border-radius: 0; /* 双页拼接时圆角会造成缝隙 */
}

/* 封面：特殊渐变背景，左半暗右半亮 */
.book-page[data-role="cover"] .page-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 40%, #1a2744 100%);
}
/* 封底：深色背景 */
.book-page[data-role="back-cover"] .page-content {
    background: #12121f;
}

/* JS 动态标记：封面当前可见时（landscape 下右侧独显） */
.book-page.as-cover .page-image img {
    border-radius: 8px 8px 0 0;
}
.book-page.as-cover .page-content {
    box-shadow: inset -4px 0 20px rgba(0,0,0,.3);
}

/* 封底当前可见时（landscape 下左侧独显） */
.book-page.as-back .page-image img {
    border-radius: 8px 8px 0 0;
}
.book-page.as-back .page-content {
    box-shadow: inset 4px 0 20px rgba(0,0,0,.3);
}

/* 封面/封底页码隐藏（用文字标示会更好） */
.book-page[data-role="cover"] .page-number,
.book-page[data-role="back-cover"] .page-number {
    opacity: 0;
}

/* ========== 页面内容区 ========== */
.page-content {
    width: 100%; height: 100%;
    display: flex; flex-direction: column;
    overflow: hidden;
}

/* 图片区域 */
.page-image { 
    flex: 1;
    min-height: 0;
    display: flex; align-items: center; justify-content: center;
    background: #0a0a0f;
    overflow: hidden;
    position: relative;
}
.page-image img {
    width: 100%; height: 100%;
    object-fit: contain;
    display: block;
}

/* ===== 桌面双页模式：左右页内容向中缝靠拢 ===== */
/* 左页（nth-child even = data-page 1,3,5...）：图片靠右、文字靠右 */
@media (min-width: 768px) {
    .book-page:nth-child(even) .page-image img {
        object-position: right center;
    }
    .book-page:nth-child(even) .page-text {
        padding-left: 24px;
        padding-right: 14px;
    }
    /* 右页（nth-child odd = data-page 0,2,4...）：图片靠左、文字靠左 */
    .book-page:nth-child(odd) .page-image img {
        object-position: left center;
    }
    .book-page:nth-child(odd) .page-text {
        padding-left: 14px;
        padding-right: 24px;
    }
}

/* 文字内容 */
.page-text { 
    padding: 16px 24px;
    background: #1a1a2e;
    flex-shrink: 0;
    max-height: 35%;
    overflow-y: auto;
    border-top: 1px solid #2a2a3e;
}
.page-text.text-pos-top {
    order: -1;
    border-top: none;
    border-bottom: 1px solid #2a2a3e;
}
.page-text.text-pos-overlay {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,.85));
    max-height: 45%;
    border-top: none;
}
.page-title { 
    font-size: 18px; font-weight: 600; color: #fff; margin-bottom: 6px;
}
.page-desc { 
    font-size: 14px; color: #aaa; line-height: 1.7; white-space: pre-wrap;
}

/* 页码 */
.page-number {
    position: absolute; bottom: 8px; right: 14px;
    font-size: 12px; color: rgba(255,255,255,.35);
    z-index: 5;
    pointer-events: none;
}

/* ========== 翻页按钮 ========== */
.nav-btn {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 48px; height: 48px; border-radius: 50%;
    background: rgba(26,26,46,.7); border: 1px solid #3a3a5a;
    color: #fff; font-size: 28px; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all .3s; z-index: 30;
    backdrop-filter: blur(10px);
}
.nav-btn:hover { background: rgba(108,99,255,.35); border-color: #6c63ff; }
.nav-btn:active { transform: translateY(-50%) scale(.92); }
.nav-prev { left: 16px; }
.nav-next { right: 16px; }

/* ========== 进度 ========== */
.page-indicator {
    position: absolute; bottom: 0; left: 0; right: 0;
    height: 3px; z-index: 30;
}
.indicator-bar {
    width: 100%; height: 100%; background: rgba(255,255,255,.08);
}
.indicator-fill {
    height: 100%; background: linear-gradient(90deg, #6c63ff, #e94560);
    transition: width .3s; border-radius: 0 2px 2px 0;
}

/* 页码文字 */
.page-info {
    position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,.6); padding: 4px 14px; border-radius: 20px;
    font-size: 13px; color: #ccc; z-index: 25;
    transition: opacity .3s;
    pointer-events: none;
}

/* ========== 缩略图面板 ========== */
.thumbnails-panel {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(10,10,15,.98); z-index: 200;
    transform: translateY(100%); transition: transform .4s cubic-bezier(0.4,0,0.2,1);
    display: flex; flex-direction: column;
}
.thumbnails-panel.open { transform: translateY(0); }
.thumbnails-header {
    display: flex; align-items: center; padding: 16px 20px;
    border-bottom: 1px solid #2a2a4a;
}
.thumbnails-header h3 { flex: 1; font-size: 18px; color: #fff; }
.thumbnails-close {
    background: transparent; border: none; color: #ccc;
    font-size: 22px; cursor: pointer; padding: 4px 8px;
}
.thumbnails-close:hover { color: #fff; }
.thumbnails-grid {
    flex: 1; overflow-y: auto; padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px; align-content: start;
}
.thumbnail-item {
    border-radius: 8px; overflow: hidden;
    min-height: 100px; /* 防止横版图片过矮 */
    position: relative; cursor: pointer; border: 2px solid transparent;
    transition: all .3s; background: #0d0d14;
    box-sizing: border-box; /* border 计入尺寸，避免溢出 */
    /* 宽高比由 JS 按图片实际比例动态设置 */
}
.thumbnail-item:hover { border-color: #6c63ff; transform: scale(1.03); }
.thumbnail-item.current { border-color: #e94560; box-shadow: 0 0 16px rgba(233,69,96,.4); }
.thumbnail-item img {
    width: 100%; height: 100%; object-fit: cover;
    display: block;
}

.thumbnail-placeholder {
    width: 100%; height: 100%; display: flex; align-items: center;
    justify-content: center; color: #666; font-size: 12px; padding: 8px;
    text-align: center;
}
.thumbnail-num {
    position: absolute; bottom: 4px; right: 6px;
    background: rgba(0,0,0,.85); color: #ddd;
    padding: 2px 7px; border-radius: 10px; font-size: 11px;
}


/* ========== 响应式适配 ========== */

@media (max-width: 1024px) {
    /* 较小桌面：无需特殊处理，autoSize 自适应 */
}

/* 手机端 */
@media (max-width: 767px) {
    .album-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
    .magazine-viewer { padding: 0 0 24px 0; }
    .page-content { border-radius: 0; }
    .nav-btn { width: 40px; height: 40px; font-size: 24px; }
    .nav-prev { left: 6px; }
    .nav-next { right: 6px; }
    .page-text { padding: 12px 16px; }
    .page-title { font-size: 16px; }
    .page-desc { font-size: 13px; }
    .thumbnails-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
    .page-number { bottom: 6px; right: 10px; }
}

/* 小屏手机 */
@media (max-width: 480px) {
    .album-header { padding: 0 12px; }
    .header-inner { height: 48px; }
    .header-title { font-size: 16px; letter-spacing: 1px; }
    .album-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .card-info { padding: 10px; }
    .card-title { font-size: 14px; }
    .card-desc { font-size: 11px; min-height: 30px; }
    .container { padding: 16px 10px; }
    .magazine-toolbar { height: 44px; padding: 0 8px; }
    .tool-title { font-size: 14px; }
    .tool-btn { font-size: 16px; padding: 6px 8px; }
    .page-text { padding: 10px 12px; max-height: 40%; }
    .page-title { font-size: 15px; }
    .page-desc { font-size: 12px; line-height: 1.6; }
    .nav-btn { width: 36px; height: 36px; font-size: 22px; background: rgba(26,26,46,.5); }
    .nav-prev { left: 2px; }
    .nav-next { right: 2px; }
    .page-info { font-size: 11px; padding: 2px 10px; }
    .thumbnails-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 12px; }
    .logo-link { font-size: 13px; }
    .header-spacer { width: 40px; }
}

/* 大屏幕优化 */
@media (min-width: 1400px) {
    .page-text { padding: 24px 36px; }
    .page-title { font-size: 22px; }
    .page-desc { font-size: 16px; }
}

/* 横屏手机 */
@media (max-width: 767px) and (orientation: landscape) {
    .page-text { max-height: 45%; }
}
