/* ============ 基础 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: #f5f6fa;
    color: #333;
    min-height: 100vh;
}
a { text-decoration: none; color: inherit; }
button { font-family: inherit; }

.btn-primary {
    display: inline-block;
    padding: 10px 28px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: opacity .2s, transform .2s;
}
.btn-primary:hover { opacity: .92; transform: translateY(-1px); }
.btn-ghost {
    display: inline-block;
    padding: 10px 24px;
    border: 1px solid #ddd;
    border-radius: 8px;
    color: #666;
    font-size: 14px;
    background: #fff;
}
.btn-ghost:hover { border-color: #667eea; color: #667eea; }
.btn-danger {
    padding: 5px 14px;
    background: #fff;
    border: 1px solid #ffcdd2;
    color: #e53935;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}
.btn-danger:hover { background: #e53935; color: #fff; }

.alert-error {
    background: #fff0f0; border: 1px solid #ffcdd2; color: #c62828;
    border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px;
}
.alert-success {
    background: #f0faf1; border: 1px solid #b9e6c2; color: #2e7d32;
    border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px;
}

/* ============ 顶部导航 ============ */
.site-header {
    position: sticky; top: 0; z-index: 50;
    background: rgba(255,255,255,.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid #eee;
}
.header-inner {
    max-width: 1100px; margin: 0 auto; padding: 0 20px;
    height: 56px; display: flex; align-items: center; justify-content: space-between;
}
.logo { font-size: 17px; font-weight: 700; color: #333; }
.nav { display: flex; gap: 8px; }
.nav a {
    padding: 6px 14px; border-radius: 8px; font-size: 14px; color: #666;
    transition: background .2s, color .2s;
}
.nav a:hover { background: #f0f1f7; color: #333; }
.nav a.active { background: linear-gradient(135deg, #667eea, #764ba2); color: #fff; }
.nav a.logout:hover { color: #e53935; }

/* ============ 登录页 ============ */
.page-login {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
    background: #fff; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
    width: 100%; max-width: 380px; padding: 44px 36px; text-align: center;
}
.login-logo { font-size: 48px; margin-bottom: 10px; }
.login-card h1 { font-size: 20px; margin-bottom: 6px; }
.login-sub { color: #999; font-size: 13px; margin-bottom: 26px; }
.login-card .form-item { margin-bottom: 14px; }
.login-card input {
    width: 100%; padding: 12px 14px; border: 1px solid #ddd; border-radius: 8px;
    font-size: 14px; transition: border .2s;
}
.login-card input:focus { outline: none; border-color: #667eea; }
.login-card .btn-primary { width: 100%; padding: 12px; font-size: 15px; }

/* ============ 书架 ============ */
.shelf-main { max-width: 1100px; margin: 0 auto; padding: 30px 20px 60px; }
.shelf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 26px 20px;
}
.book-card { transition: transform .25s; }
.book-card:hover { transform: translateY(-4px); }
.book-cover {
    position: relative; display: flex; align-items: center; justify-content: center;
    aspect-ratio: 3/4; border-radius: 10px; overflow: hidden;
    box-shadow: 0 6px 18px rgba(0,0,0,.18);
}
.book-cover .cover-title {
    color: rgba(255,255,255,.96); font-size: 17px; font-weight: 700;
    font-family: "Songti SC", "STSong", serif;
    writing-mode: vertical-rl; letter-spacing: 4px; max-height: 78%;
    text-shadow: 0 1px 4px rgba(0,0,0,.3);
    overflow: hidden;
}
.book-cover .cover-deco {
    position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
    background: rgba(255,255,255,.28);
}
.book-info { padding-top: 10px; text-align: center; }
.book-title {
    display: block; font-size: 14px; font-weight: 600; color: #333;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.book-title:hover { color: #667eea; }
.book-meta { font-size: 12px; color: #999; margin: 4px 0 8px; }
.btn-continue {
    display: inline-block; padding: 5px 16px; font-size: 12px;
    border: 1px solid #667eea; color: #667eea; border-radius: 20px;
    transition: all .2s;
}
.btn-continue:hover { background: #667eea; color: #fff; }
.empty-state { text-align: center; padding: 100px 0; color: #999; }
.empty-icon { font-size: 64px; margin-bottom: 16px; }
.empty-state p { margin-bottom: 20px; font-size: 15px; }

/* ============ 目录页 ============ */
.catalog-main { max-width: 1000px; margin: 0 auto; padding: 30px 20px 60px; }
.book-head {
    display: flex; gap: 26px; background: #fff; border-radius: 14px;
    padding: 26px; box-shadow: 0 4px 16px rgba(0,0,0,.06);
}
.book-cover.big { width: 130px; flex-shrink: 0; aspect-ratio: 3/4; border-radius: 10px; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.book-cover.big .cover-title { font-size: 18px; }
.book-head-info { display: flex; flex-direction: column; justify-content: center; }
.book-head-info h1 { font-size: 24px; margin-bottom: 10px; }
.book-stats { color: #999; font-size: 13px; margin-bottom: 20px; }
.book-actions { display: flex; gap: 12px; }
.catalog-title { font-size: 17px; margin: 30px 0 14px; padding-left: 10px; border-left: 3px solid #667eea; }
.chapter-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0 24px; background: #fff; border-radius: 14px; padding: 16px 22px;
    box-shadow: 0 4px 16px rgba(0,0,0,.06);
}
.chapter-item {
    display: block; padding: 11px 8px; font-size: 14px; color: #555;
    border-bottom: 1px solid #f2f2f2;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    transition: color .15s, padding-left .15s;
}
.chapter-item:hover { color: #667eea; padding-left: 14px; }
.chapter-item.last-read { color: #667eea; font-weight: 600; }

/* ============ 阅读器主题变量 ============ */
:root {
    --reader-font-size: 18px;
}
:root[data-theme="default"] {
    --reader-bg: #fafafa; --reader-color: #333333; --reader-title: #222;
    --reader-bar-bg: rgba(255,255,255,.92); --reader-bar-color: #555;
    --reader-panel-bg: #fff; --reader-border: #e8e8e8;
}
:root[data-theme="eye"] {
    --reader-bg: #c7edcc; --reader-color: #3a4a3b; --reader-title: #2c3a2d;
    --reader-bar-bg: rgba(199,237,204,.94); --reader-bar-color: #4a5d4b;
    --reader-panel-bg: #d8f2dc; --reader-border: #a9d8ae;
}
:root[data-theme="paper"] {
    --reader-bg: #f3e9d2; --reader-color: #5b4a32; --reader-title: #4a3a26;
    --reader-bar-bg: rgba(243,233,210,.94); --reader-bar-color: #7a6547;
    --reader-panel-bg: #f8f0dd; --reader-border: #ddcda8;
}
:root[data-theme="night"] {
    --reader-bg: #1b1f24; --reader-color: #9aa4b0; --reader-title: #c8d0da;
    --reader-bar-bg: rgba(27,31,36,.94); --reader-bar-color: #8a94a0;
    --reader-panel-bg: #242a31; --reader-border: #333b44;
}
:root[data-theme="blue"] {
    --reader-bg: #0f2027; --reader-color: #8fb3c9; --reader-title: #b8d4e8;
    --reader-bar-bg: rgba(15,32,39,.94); --reader-bar-color: #7fa3b9;
    --reader-panel-bg: #173038; --reader-border: #274550;
}

/* ============ 阅读页 ============ */
.page-reader { background: var(--reader-bg); color: var(--reader-color); }
.reader-topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 40;
    display: flex; align-items: center; justify-content: space-between;
    height: 50px; padding: 0 16px;
    background: var(--reader-bar-bg); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--reader-border);
}
.topbar-btn { font-size: 14px; color: var(--reader-bar-color); padding: 6px 10px; border-radius: 6px; }
.topbar-btn:hover { opacity: .75; }
.topbar-title { font-size: 14px; color: var(--reader-bar-color); max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-main {
    max-width: 760px; margin: 0 auto;
    padding: 80px 24px 120px;
}
.reader-chapter-title {
    font-size: 22px; font-weight: 700; color: var(--reader-title);
    margin-bottom: 30px; line-height: 1.5;
}
.reader-content {
    font-size: var(--reader-font-size);
    line-height: 2.05;
    letter-spacing: .03em;
    word-wrap: break-word;
    font-family: "PingFang SC", "Microsoft YaHei", "Songti SC", serif;
}
.reader-pager {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; margin-top: 50px;
}
.pager-btn {
    flex: 1; text-align: center; padding: 13px 0; font-size: 15px;
    border: 1px solid var(--reader-border); border-radius: 10px;
    color: var(--reader-color); background: var(--reader-panel-bg);
    transition: opacity .2s;
}
.pager-btn:hover { opacity: .75; }
.pager-btn.disabled { opacity: .35; pointer-events: none; }
.pager-catalog { max-width: 110px; }

/* 底部工具栏 */
.reader-toolbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    display: flex; justify-content: center; gap: 6px;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: var(--reader-bar-bg); backdrop-filter: blur(10px);
    border-top: 1px solid var(--reader-border);
}
.tool-btn {
    padding: 8px 20px; font-size: 14px; border: none; border-radius: 8px;
    background: transparent; color: var(--reader-bar-color); cursor: pointer;
    transition: background .2s;
}
.tool-btn:hover { background: rgba(127,127,127,.15); }
.tool-btn:disabled { opacity: .35; cursor: default; }

/* 目录抽屉 */
.drawer-mask {
    position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.45);
    opacity: 0; pointer-events: none; transition: opacity .25s;
}
.drawer-mask.show { opacity: 1; pointer-events: auto; }
.reader-drawer {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 61;
    width: min(340px, 86vw);
    background: var(--reader-panel-bg);
    border-right: 1px solid var(--reader-border);
    transform: translateX(-100%); transition: transform .28s ease;
    display: flex; flex-direction: column;
}
.reader-drawer.show { transform: translateX(0); }
.drawer-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 18px; font-size: 15px; font-weight: 600; color: var(--reader-title);
    border-bottom: 1px solid var(--reader-border);
}
.drawer-close {
    border: none; background: none; font-size: 22px; cursor: pointer;
    color: var(--reader-bar-color); line-height: 1;
}
.drawer-list { flex: 1; overflow-y: auto; padding: 6px 0; }
.drawer-item {
    display: block; padding: 11px 18px; font-size: 14px; color: var(--reader-color);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.drawer-item:hover { background: rgba(127,127,127,.1); }
.drawer-item.active { color: #667eea; font-weight: 600; background: rgba(102,126,234,.1); }

/* 设置面板 */
.setting-panel {
    position: fixed; bottom: 64px; left: 50%; transform: translateX(-50%) translateY(16px);
    z-index: 55; width: min(480px, 92vw);
    background: var(--reader-panel-bg); border: 1px solid var(--reader-border);
    border-radius: 14px; padding: 18px 22px;
    opacity: 0; pointer-events: none; transition: opacity .22s, transform .22s;
    box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.setting-panel.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
.setting-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.setting-row + .setting-row { border-top: 1px solid var(--reader-border); }
.setting-label { font-size: 14px; color: var(--reader-bar-color); width: 36px; }
.setting-btn {
    padding: 6px 16px; font-size: 14px; border-radius: 8px; cursor: pointer;
    border: 1px solid var(--reader-border); background: transparent; color: var(--reader-color);
}
.setting-btn:hover { background: rgba(127,127,127,.12); }
.font-size-val { font-size: 14px; color: var(--reader-bar-color); min-width: 24px; text-align: center; }
.theme-list { display: flex; gap: 12px; }
.theme-dot {
    width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
    border: 2px solid var(--reader-border); transition: transform .15s, border-color .15s;
}
.theme-dot:hover { transform: scale(1.1); }
.theme-dot.active { border-color: #667eea; box-shadow: 0 0 0 3px rgba(102,126,234,.35); }

/* ============ 管理后台 ============ */
.admin-main { max-width: 1000px; margin: 0 auto; padding: 30px 20px 60px; }
.admin-card {
    background: #fff; border-radius: 14px; padding: 24px 26px;
    box-shadow: 0 4px 16px rgba(0,0,0,.06); margin-bottom: 24px;
}
.admin-card h2 { font-size: 16px; margin-bottom: 18px; padding-left: 10px; border-left: 3px solid #667eea; }
.upload-row { display: flex; gap: 12px; flex-wrap: wrap; }
.upload-row input[type="file"] { flex: 1 1 200px; font-size: 13px; }
.upload-row input[type="text"] {
    flex: 1 1 200px; padding: 9px 14px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px;
}
.upload-row input[type="text"]:focus { outline: none; border-color: #667eea; }
.upload-tip { margin-top: 12px; font-size: 12px; color: #999; line-height: 1.8; }
.admin-empty { color: #999; font-size: 14px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td { padding: 12px 10px; text-align: left; border-bottom: 1px solid #f0f0f0; }
.admin-table th { color: #999; font-weight: 500; font-size: 13px; }
.admin-table td a { color: #333; font-weight: 600; }
.admin-table td a:hover { color: #667eea; }
.inline-form { display: inline; }

/* ============ 响应式 ============ */
@media (max-width: 640px) {
    .shelf-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 18px 12px; }
    .book-cover .cover-title { font-size: 14px; letter-spacing: 3px; }
    .book-head { flex-direction: column; align-items: center; text-align: center; }
    .book-actions { justify-content: center; }
    .chapter-grid { grid-template-columns: 1fr; }
    .reader-main { padding: 70px 18px 110px; }
    .tool-btn { padding: 8px 12px; font-size: 13px; }
    .topbar-title { display: none; }
    .reader-chapter-title { font-size: 19px; }
}
