/* ==================== 阅读页主题变量 ==================== */

:root {
    --reader-font-size: 19px;
    --reader-line-height: 2;
    --reader-width: 760px;
    --reader-serif: 'Noto Serif CJK SC', 'Source Han Serif SC', 'Songti SC', SimSun, serif;
    --reader-sans: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', system-ui, sans-serif;
    --reader-family: var(--reader-serif);
}

body[data-theme='dark'] {
    --bg: #10141d;
    --bg-soft: #161c28;
    --panel: #1b2231;
    --line: #2a3348;
    --text: #cdd6e6;
    --text-dim: #7e8aa3;
    --accent: #5b8cff;
    --accent-soft: rgba(91, 140, 255, 0.14);
    --shadow: rgba(0, 0, 0, 0.5);
}

body[data-theme='paper'] {
    --bg: #f7f5f0;
    --bg-soft: #fffdf8;
    --panel: #fffdf8;
    --line: #e2ddd2;
    --text: #33302a;
    --text-dim: #8d8779;
    --accent: #3a6ee0;
    --accent-soft: rgba(58, 110, 224, 0.1);
    --shadow: rgba(80, 70, 50, 0.15);
}

body[data-theme='sepia'] {
    --bg: #ede3cf;
    --bg-soft: #f5ecda;
    --panel: #f5ecda;
    --line: #ddd0b4;
    --text: #46381f;
    --text-dim: #97865f;
    --accent: #a0652c;
    --accent-soft: rgba(160, 101, 44, 0.12);
    --shadow: rgba(100, 80, 40, 0.2);
}

body[data-theme='green'] {
    --bg: #e0ebe0;
    --bg-soft: #ebf3eb;
    --panel: #ebf3eb;
    --line: #c9dbc9;
    --text: #2c3a2c;
    --text-dim: #74886f;
    --accent: #2f7d4f;
    --accent-soft: rgba(47, 125, 79, 0.12);
    --shadow: rgba(40, 80, 40, 0.15);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--reader-sans);
    transition: background 0.25s ease, color 0.25s ease;
}

button { font-family: inherit; }

.hidden { display: none !important; }

/* ==================== 顶部进度条 ==================== */

.progress-bar {
    position: fixed;
    top: 0; left: 0;
    height: 2px;
    width: 0;
    background: var(--accent);
    z-index: 60;
    transition: width 0.15s linear;
}

/* ==================== 顶栏 ==================== */

.reader-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 14px;
    padding-top: env(safe-area-inset-top);
    height: calc(52px + env(safe-area-inset-top));
    background: color-mix(in srgb, var(--bg-soft) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    z-index: 50;
    transition: transform 0.25s ease;
}

.reader-topbar.tucked { transform: translateY(-100%); }

.topbar-left, .topbar-right { display: flex; gap: 6px; align-items: center; }

.topbar-title {
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-dim);
}
.topbar-title #topbarBook { color: var(--text); font-weight: 600; }
.topbar-title #topbarChapter::before { content: ' · '; }
.topbar-title #topbarChapter:empty::before { content: ''; }

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 36px; height: 36px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel);
    color: var(--text);
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease;
}
.icon-button:hover { background: var(--accent-soft); border-color: var(--accent); }

/* ==================== 书架 ==================== */

.shelf-view {
    min-height: 100vh;
    min-height: 100dvh;
    padding: 84px 20px 60px;
    padding-top: calc(84px + env(safe-area-inset-top));
    padding-bottom: max(60px, env(safe-area-inset-bottom));
}

.shelf-inner { max-width: 1000px; margin: 0 auto; }

.shelf-title { margin: 0; font-size: 1.6rem; }
.shelf-subtitle { margin: 6px 0 26px; color: var(--text-dim); font-size: 0.9rem; }

.shelf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 16px;
}

.book-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 18px 16px 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    cursor: pointer;
    text-align: left;
    color: var(--text);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.book-card:hover {
    transform: translateY(-3px);
    border-color: var(--accent);
    box-shadow: 0 10px 26px var(--shadow);
}

.book-spine {
    width: 44px; height: 58px;
    display: grid;
    place-items: center;
    border-radius: 6px 10px 10px 6px;
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #9b6bff));
    color: #fff;
    font-weight: 700;
    font-size: 1.25rem;
    box-shadow: inset 3px 0 0 rgba(255, 255, 255, 0.25);
}

.book-name { font-size: 1.02rem; font-weight: 600; margin-top: 2px; }
.book-meta { color: var(--text-dim); font-size: 0.78rem; line-height: 1.6; }

.book-progress {
    margin-top: 4px;
    font-size: 0.78rem;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 6px;
    padding: 5px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shelf-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-dim);
    padding: 60px 0;
}
.shelf-empty a { color: var(--accent); }

/* ==================== 阅读布局 ==================== */

.read-layout { display: block; }

.toc-panel {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 290px;
    background: var(--bg-soft);
    border-right: 1px solid var(--line);
    padding: 68px 0 20px;
    overflow-y: auto;
    z-index: 45;
    transition: transform 0.25s ease;
}
.toc-panel.collapsed { transform: translateX(-100%); }

.toc-head { padding: 4px 18px 12px; border-bottom: 1px solid var(--line); }
.toc-head h2 { margin: 0; font-size: 1.05rem; }
.toc-meta { margin: 5px 0 0; color: var(--text-dim); font-size: 0.78rem; }

.toc-list { padding: 10px 10px 30px; }

.toc-volume {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 9px 10px;
    margin-top: 6px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    cursor: pointer;
    border-radius: 8px;
}
.toc-volume:hover { background: var(--accent-soft); }
.toc-volume .arrow { transition: transform 0.2s ease; font-size: 0.7rem; }
.toc-volume.open .arrow { transform: rotate(90deg); }

.toc-chapter {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 10px 8px 18px;
    background: transparent;
    border: none;
    border-left: 2px solid transparent;
    border-radius: 0 8px 8px 0;
    color: var(--text);
    font-size: 0.88rem;
    line-height: 1.5;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.toc-chapter:hover { background: var(--accent-soft); }
.toc-chapter.active {
    color: var(--accent);
    border-left-color: var(--accent);
    background: var(--accent-soft);
    font-weight: 600;
}
.toc-chapter.empty { color: var(--text-dim); }
.toc-chapter.empty::after { content: ' ·空'; font-size: 0.72rem; }

/* ==================== 正文 ==================== */

.read-main {
    padding: 84px 24px 40px;
    margin-left: 290px;
    transition: margin-left 0.25s ease;
}
.read-main.full { margin-left: 0; }

.chapter-article {
    max-width: var(--reader-width);
    margin: 0 auto;
}

.chapter-volume {
    margin: 0;
    color: var(--accent);
    font-size: 0.78rem;
    letter-spacing: 0.14em;
}

.chapter-heading {
    margin: 8px 0 6px;
    font-size: 1.55rem;
    font-weight: 700;
    font-family: var(--reader-family);
    line-height: 1.4;
}

.chapter-info {
    margin: 0 0 34px;
    color: var(--text-dim);
    font-size: 0.8rem;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.chapter-body {
    font-family: var(--reader-family);
    font-size: var(--reader-font-size);
    line-height: var(--reader-line-height);
    letter-spacing: 0.02em;
}

.chapter-body p {
    margin: 0 0 0.9em;
    text-indent: 2em;
    text-align: justify;
}

.chapter-body h1, .chapter-body h2, .chapter-body h3, .chapter-body h4 {
    text-indent: 0;
    line-height: 1.5;
    margin: 1.4em 0 0.7em;
}
.chapter-body h1 { font-size: 1.3em; }
.chapter-body h2 { font-size: 1.18em; }
.chapter-body h3, .chapter-body h4 { font-size: 1.05em; }

.chapter-body hr {
    border: none;
    border-top: 1px solid var(--line);
    margin: 2em auto;
    width: 50%;
}

.chapter-body .scene-break {
    text-indent: 0;
    text-align: center;
    color: var(--text-dim);
    letter-spacing: 1em;
    margin: 1.6em 0;
}

.chapter-body .empty-chapter {
    text-indent: 0;
    text-align: center;
    color: var(--text-dim);
    padding: 80px 0;
}

/* ==================== 章节导航 ==================== */

.chapter-nav {
    max-width: var(--reader-width);
    margin: 46px auto 0;
    display: flex;
    gap: 10px;
}

.nav-button {
    flex: 1;
    padding: 13px 10px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    font-size: 0.92rem;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.nav-button.center { flex: 0 0 108px; color: var(--text-dim); }
.nav-button:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }
.nav-button:disabled { opacity: 0.35; cursor: default; }

/* ==================== 设置面板 ==================== */

.settings-panel {
    position: fixed;
    top: 60px;
    right: 14px;
    width: 300px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 14px 40px var(--shadow);
    padding: 16px;
    z-index: 55;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.setting-label { color: var(--text-dim); font-size: 0.82rem; flex: 0 0 34px; }
.setting-controls { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.setting-value { color: var(--text-dim); font-size: 0.8rem; min-width: 38px; text-align: center; }

.chip {
    padding: 6px 12px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.theme-chip { font-size: 0.95rem; padding: 6px 9px; }

/* ==================== 移动端 ==================== */

.toc-mask {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 44;
}

@media (max-width: 900px) {
    .read-main {
        margin-left: 0;
        padding: 76px 16px 32px;
        padding-top: calc(76px + env(safe-area-inset-top));
        padding-bottom: max(32px, env(safe-area-inset-bottom));
    }
    .toc-panel {
        box-shadow: 14px 0 40px var(--shadow);
        width: min(320px, 86vw);
        padding-top: calc(68px + env(safe-area-inset-top));
    }
    .topbar-title #topbarBook { display: none; }
    .topbar-title #topbarChapter::before { content: ''; }
    .settings-panel { right: 8px; left: 8px; width: auto; top: calc(60px + env(safe-area-inset-top)); }
    :root { --reader-font-size: 18px; }
    .chapter-heading { font-size: 1.3rem; }
    .icon-button { width: 42px; height: 42px; }
    .shelf-grid { grid-template-columns: 1fr; }
    .shelf-view { padding-left: 16px; padding-right: 16px; }
    .chapter-nav { flex-wrap: wrap; }
    .nav-button { min-height: 44px; }
    .nav-button.center { flex: 1 1 100%; order: 3; }
}
