:root {
    --bg: #ffffff;
    --text: #2c2c2c;
    --sidebar-bg: #f6f4ef;
    --sidebar-text: #555555;
    --sidebar-active: #ffffff;
    --accent: #a67c52;
    --border: #e6e2da;
    --muted: #9a9a9a;
    --read-font: 18px;
    --read-line: 1.9;
    --content-max: 720px;
}

/* 护眼模式：豆沙绿 */
html[data-theme="eye"] {
    --bg: #c7edcc;
    --text: #2f3e2f;
    --sidebar-bg: #b9e3bd;
    --sidebar-text: #33502f;
    --sidebar-active: #d6f0d9;
    --accent: #3f7d44;
    --border: #a9d6ad;
    --muted: #5c7a5e;
}

/* 夜间模式 */
html[data-theme="night"] {
    --bg: #1d1d1d;
    --text: #b6b6b6;
    --sidebar-bg: #242424;
    --sidebar-text: #9a9a9a;
    --sidebar-active: #2f2f2f;
    --accent: #7f7f7f;
    --border: #333333;
    --muted: #777777;
}

/* 科技蓝模式：浅色玻璃拟态 + 科技蓝 */
html[data-theme="tech"] {
    --bg: #eef3fb;
    --text: #1c2c4c;
    --sidebar-bg: rgba(255, 255, 255, .78);
    --sidebar-text: #4a5b7a;
    --sidebar-active: rgba(26, 99, 221, .12);
    --accent: #1a63dd;
    --border: rgba(26, 99, 221, .18);
    --muted: #5f6f8a;
}

/* ---- 科技蓝模式下的额外点缀（不改变结构，只加质感）---- */
html[data-theme="tech"] body {
    background-image:
        radial-gradient(820px 480px at 4% -8%, rgba(30, 111, 245, .16), transparent 62%),
        radial-gradient(720px 460px at 102% -4%, rgba(34, 211, 238, .15), transparent 62%),
        linear-gradient(rgba(30, 111, 245, .05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(30, 111, 245, .05) 1px, transparent 1px);
    background-size: auto, auto, 100% 42px, 42px 100%;
    background-attachment: fixed, fixed, fixed, fixed;
    background-repeat: no-repeat, no-repeat, repeat, repeat;
}
html[data-theme="tech"] .topbar {
    background: rgba(255, 255, 255, .78);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    backdrop-filter: blur(16px) saturate(160%);
    box-shadow: 0 2px 16px rgba(18, 46, 96, .08);
    position: relative;
}
html[data-theme="tech"] .topbar::after {
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: -1px;
    height: 1px;
    background: linear-gradient(90deg, transparent, #22d3ee, transparent);
    box-shadow: 0 0 10px rgba(34, 211, 238, .9);
}
html[data-theme="tech"] .sidebar {
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    backdrop-filter: blur(16px) saturate(160%);
}
html[data-theme="tech"] .icon-btn:hover {
    color: #1a63dd;
    border-color: #1a63dd;
    box-shadow: 0 3px 12px rgba(26, 99, 221, .18);
}
html[data-theme="tech"] .progress-line { background: rgba(26, 99, 221, .14); }
html[data-theme="tech"] .progress-fill {
    background: linear-gradient(90deg, #1a63dd, #22d3ee);
    box-shadow: 0 0 10px rgba(26, 99, 221, .55);
}
html[data-theme="tech"] .chapter-list li.active {
    box-shadow: inset 3px 0 0 0 #1a63dd;
}
html[data-theme="tech"] .chapter-nav button:hover:not(:disabled) {
    color: #1a63dd;
    border-color: #1a63dd;
    box-shadow: 0 4px 14px rgba(26, 99, 221, .16);
}
html[data-theme="tech"] .nick-dialog {
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 18px 50px rgba(18, 46, 96, .22);
}
html[data-theme="tech"] .nick-actions button {
    background: linear-gradient(90deg, #1a63dd, #0d6fd4);
    border-color: transparent;
    box-shadow: 0 6px 18px rgba(26, 99, 221, .3);
}
html[data-theme="tech"] .nick-actions .nick-cancel {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
    box-shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
    -webkit-text-size-adjust: 100%;
}

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.topbar {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.book-title {
    flex: 1; font-weight: 600; font-size: 16px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-select {
    flex: 1; min-width: 0; max-width: 60%;
    border: 1px solid var(--border); background: var(--bg); color: var(--text);
    border-radius: 8px; padding: 6px 8px; font-size: 14px; cursor: pointer;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-select:focus { outline: none; border-color: var(--accent); }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
    border: 1px solid var(--border); background: transparent; color: var(--text);
    border-radius: 8px; padding: 6px 10px; font-size: 14px; cursor: pointer;
    line-height: 1.2;
}
.icon-btn:active { background: var(--sidebar-bg); }

#menuBtn { display: none; }

.progress-line { height: 3px; background: var(--border); }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

.main { flex: 1; display: flex; min-height: 0; position: relative; }

.sidebar {
    width: 280px; border-right: 1px solid var(--border);
    background: var(--sidebar-bg); display: flex; flex-direction: column;
}
.sidebar-head {
    padding: 12px; border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 8px;
}
.sidebar-title { font-weight: 600; font-size: 15px; }
.chapter-filter {
    padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text); font-size: 13px; outline: none;
}
.chapter-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.chapter-list li {
    padding: 11px 14px; border-bottom: 1px solid var(--border);
    cursor: pointer; font-size: 14px; color: var(--sidebar-text);
}
.chapter-list li:hover { background: var(--sidebar-active); }
.chapter-list li.active { background: var(--sidebar-active); color: var(--accent); font-weight: 600; }

.reader { flex: 1; overflow-y: auto; padding: 28px 20px 60px; -webkit-overflow-scrolling: touch; }
.chapter-title { font-size: 22px; text-align: center; margin: 6px 0 26px; font-weight: 700; }
.chapter-content { max-width: var(--content-max); margin: 0 auto; font-size: var(--read-font); line-height: var(--read-line); }
.chapter-content p { margin: 0 0 1.1em; text-indent: 2em; word-break: break-word; }
.chapter-nav {
    max-width: var(--content-max); margin: 40px auto 0;
    display: flex; justify-content: space-between; gap: 12px;
}
.chapter-nav button {
    flex: 1; padding: 11px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text); border-radius: 10px;
    cursor: pointer; font-size: 14px;
}
.chapter-nav button:disabled { opacity: .4; cursor: default; }

.backdrop { display: none; }

.nick-btn {
    max-width: 88px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nick-mask {
    position: fixed; inset: 0; z-index: 60;
    background: rgba(0, 0, 0, .45);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.nick-mask[hidden] { display: none; }
.nick-dialog {
    width: 100%; max-width: 380px;
    background: var(--bg); color: var(--text);
    border-radius: 14px; padding: 22px 20px 18px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .2);
}
.nick-dialog h2 { margin: 0 0 8px; font-size: 18px; text-align: center; }
.nick-desc { margin: 0 0 14px; font-size: 13px; line-height: 1.6; color: var(--muted); }
.nick-dialog input {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--bg); color: var(--text); font-size: 16px; outline: none;
}
.nick-dialog input:focus { border-color: var(--accent); }
.nick-error { min-height: 18px; margin: 8px 0 4px; font-size: 12px; color: #c4503a; }
.nick-actions { display: flex; gap: 10px; margin-top: 8px; }
.nick-actions button {
    flex: 1; padding: 11px; border-radius: 10px; cursor: pointer; font-size: 14px;
    border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
.nick-actions .nick-cancel {
    background: transparent; color: var(--text); border-color: var(--border);
}
.nick-actions .nick-cancel[hidden] { display: none; }

/* ============ 移动端（手机） ============ */
@media (max-width: 768px) {
    #menuBtn { display: inline-block; }
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0;
        width: 78%; max-width: 320px; z-index: 30;
        transform: translateX(-100%); transition: transform .25s ease;
        box-shadow: 2px 0 12px rgba(0, 0, 0, .18);
    }
    .sidebar.open { transform: translateX(0); }
    .backdrop {
        display: block; position: fixed; inset: 0;
        background: rgba(0, 0, 0, .35); z-index: 20;
        opacity: 0; pointer-events: none; transition: opacity .25s;
    }
    .backdrop.show { opacity: 1; pointer-events: auto; }
    .reader { padding: 18px 16px 56px; }
    .chapter-title { font-size: 19px; }
    .icon-btn { padding: 6px 9px; font-size: 13px; }
}
