/* ============ 整体 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    /* 全屏背景图 + 半透明压暗层,保证书和 UI 仍然清晰 */
    background:
        linear-gradient(rgba(16, 16, 22, 0.2), rgba(16, 16, 22, 0.2)),
        url('../bg.jpg') center / cover no-repeat,
        #2a2a2f;
    background-attachment: fixed;
    color: #e8e8ea;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

#app {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

/* ============ 顶栏 ============ */
#topbar {
    height: 52px;
    flex: 0 0 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    background: rgba(20, 20, 24, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 30;
}

#topbar .title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 1px;
    color: #f2f2f4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#topbar .book-icon { font-size: 18px; }

#topbar .btns { display: flex; gap: 8px; }

.tbtn {
    width: 38px;
    height: 38px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    color: #d8d8dc;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tbtn:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.tbtn.active {
    background: #3d7eff;
    border-color: #3d7eff;
    color: #fff;
}

/* ============ 舞台 ============ */
#stage {
    position: relative;
    flex: 1 1 auto;
    overflow: hidden;
    min-height: 0;
}

#zoomStage {
    position: absolute;
    inset: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#zoomContent {
    position: absolute;
    inset: 0;
}

#zoomStage.zoomed {
    display: block;
    overflow: auto;
}

#zoomStage.zoomed #zoomContent {
    transform: scale(2);
    transform-origin: center center;
    pointer-events: none; /* 翻页交互交给箭头按钮,拖动交给 panOverlay */
}

#panOverlay {
    position: absolute;
    inset: 0;
    z-index: 25;
    cursor: grab;
    touch-action: none;
}

#panOverlay:active { cursor: grabbing; }

#book {
    position: relative;
    width: 94%;               /* 左右留出深色边距,更像一本摆在桌面上的书 */
    max-width: 1800px;
    height: 100%;
    margin: 0 auto;
    /* 书体投影 */
    filter: drop-shadow(0 22px 44px rgba(0, 0, 0, 0.55));
}

@media (max-width: 900px) {
    #book { width: 100%; }
}

/* ============ 书脊阴影 + 页堆厚度(仅双页模式) ============ */
/* 注意:库会给当前摆好的页加 --left / --right 类,据此区分左右页;
   左页书脊在右、外侧在左;右页相反。
   外侧厚度条画在 .stf__item 上(向外延伸);书脊内阴影必须画在 img 上,
   因为 inset 阴影会画在子元素(img)之下,画在 item 上会被图片盖住。 */
.stf__wrapper.--landscape .stf__item.--left {
    box-shadow:
        /* 外侧:一摞纸的侧面(由浅到深的多层 1px 边) */
        -1px 0 0 #fafafa, -2px 0 0 #f0f0f0, -3px 0 0 #e4e4e4,
        -4px 0 0 #d8d8d8, -5px 0 0 #cdcdcd, -6px 0 0 #c0c0c0,
        -7px 0 0 #b3b3b3, -8px 0 0 #a8a8a8, -9px 0 0 #9d9d9d,
        -10px 0 0 #929292, -11px 0 0 #888888,
        /* 外侧柔投影,增加书的体积感 */
        -16px 0 18px -8px rgba(0, 0, 0, 0.4);
}

.stf__wrapper.--landscape .stf__item.--right {
    box-shadow:
        1px 0 0 #fafafa, 2px 0 0 #f0f0f0, 3px 0 0 #e4e4e4,
        4px 0 0 #d8d8d8, 5px 0 0 #cdcdcd, 6px 0 0 #c0c0c0,
        7px 0 0 #b3b3b3, 8px 0 0 #a8a8a8, 9px 0 0 #9d9d9d,
        10px 0 0 #929292, 11px 0 0 #888888,
        16px 0 18px -8px rgba(0, 0, 0, 0.4);
}

/* 书脊:左右两页各叠一层朝中缝的渐变覆盖层(inset box-shadow 画不到 img 上面,
   所以用 ::after 渐变盖在图片上方),两页拼起来就是明显的中缝阴影 */
.stf__wrapper.--landscape .stf__item.--left::after,
.stf__wrapper.--landscape .stf__item.--right::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.stf__wrapper.--landscape .stf__item.--left::after {
    background: linear-gradient(to left,
        rgba(0, 0, 0, 0.3) 0%,
        rgba(0, 0, 0, 0.16) 3%,
        rgba(0, 0, 0, 0.05) 12%,
        rgba(0, 0, 0, 0) 22%);
}

.stf__wrapper.--landscape .stf__item.--right::after {
    background: linear-gradient(to right,
        rgba(0, 0, 0, 0.3) 0%,
        rgba(0, 0, 0, 0.16) 3%,
        rgba(0, 0, 0, 0.05) 12%,
        rgba(0, 0, 0, 0) 22%);
}

.page, .page > img {
    width: 100%;
    height: 100%;
    display: block;
}

.page > img {
    object-fit: fill;
    background: #fff;
}

/* ============ 左右翻页箭头 ============ */
.arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 72px;
    border: none;
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.28);
    color: rgba(255, 255, 255, 0.85);
    font-size: 44px;
    line-height: 1;
    cursor: pointer;
    z-index: 35; /* 高于缩放平移层(25),保证缩放状态下仍可点击翻页 */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, opacity 0.15s;
    opacity: 0.55;
}

.arrow:hover { background: rgba(0, 0, 0, 0.5); opacity: 1; }

.arrow.left  { left: 16px; }
.arrow.right { right: 16px; }

.arrow:disabled { opacity: 0.15; cursor: default; background: rgba(0,0,0,0.28); }

/* ============ 底栏 ============ */
#bottombar {
    position: relative;
    z-index: 30;
    display: flex;
    flex-direction: column;
}

#pageInfo {
    text-align: center;
    font-size: 13px;
    color: #b9b9c0;
    padding: 8px 0 10px;
    letter-spacing: 1px;
    font-variant-numeric: tabular-nums;
}

/* 缩略图栏 */
#thumbs {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 10px 14px 12px;
    background: rgba(16, 16, 20, 0.62);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    scrollbar-width: thin;
}

#thumbs::-webkit-scrollbar { height: 6px; }
#thumbs::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.22); border-radius: 3px; }

.thumb {
    flex: 0 0 auto;
    width: 92px;
    border: 2px solid rgba(255, 255, 255, 0.16);
    border-radius: 6px;
    background: #fff;
    padding: 0;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: border-color 0.15s, transform 0.15s;
}

.thumb:hover { border-color: rgba(255, 255, 255, 0.5); transform: translateY(-2px); }

.thumb.current { border-color: #3d7eff; }

.thumb img {
    width: 100%;
    display: block;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    pointer-events: none;
}

.thumb span {
    position: absolute;
    right: 3px;
    bottom: 2px;
    font-size: 10px;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    border-radius: 3px;
    padding: 1px 4px;
    pointer-events: none;
}

/* ============ 加载遮罩 ============ */
#loading {
    position: fixed;
    inset: 0;
    z-index: 100;
    /* 与 body 相同的背景,淡出时和主界面无缝衔接 */
    background:
        linear-gradient(rgba(16, 16, 22, 0.2), rgba(16, 16, 22, 0.2)),
        url('../bg.jpg') center / cover no-repeat,
        #2a2a2f;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    transition: opacity 0.35s;
}

#loading.fade { opacity: 0; pointer-events: none; }

.spinner {
    width: 44px;
    height: 44px;
    border: 4px solid rgba(255, 255, 255, 0.15);
    border-top-color: #3d7eff;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#loadText { font-size: 14px; color: #ececf0; letter-spacing: 2px; text-shadow: 0 1px 10px rgba(0, 0, 0, 0.7); }

.spinner { box-shadow: 0 1px 14px rgba(0, 0, 0, 0.45); }

/* ============ 全屏 ============ */
#app:fullscreen #stage { height: calc(100vh - 52px); }

/* ============ 移动端 ============ */
@media (max-width: 900px) {
    .arrow {
        width: 44px;
        height: 60px;
        font-size: 36px;
    }
    .arrow.left  { left: 6px; }
    .arrow.right { right: 6px; }
    #topbar { height: 46px; flex-basis: 46px; }
    #topbar .title { font-size: 14px; }
}
