/* ================= 全局 ================= */
:root {
    --primary: #d4380d;
    --primary-dark: #ad2c08;
    --bg: #f6f4ef;
    --card: #ffffff;
    --text: #262626;
    --text-2: #595959;
    --text-3: #8c8c8c;
    --line: #e8e4da;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .04);
    --serif: "Songti SC", "Noto Serif SC", "SimSun", "STSong", serif;
    --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
}

input, textarea, select {
    font-family: inherit;
    font-size: inherit;
}

.container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ================= 顶栏 ================= */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}

.topbar-inner {
    display: flex;
    align-items: center;
    gap: 24px;
    height: 60px;
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 20px;
}

.logo {
    font-family: var(--serif);
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 2px;
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-shrink: 0;
}

.logo small {
    font-size: 11px;
    color: var(--text-3);
    letter-spacing: 1px;
    font-family: var(--sans);
    font-weight: 400;
}

.nav-tabs {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.nav-tabs a {
    padding: 6px 14px;
    border-radius: 18px;
    color: var(--text-2);
    font-size: 15px;
}

.nav-tabs a.active {
    color: var(--primary);
    background: #fdf0eb;
    font-weight: 600;
}

.search-box {
    flex: 1;
    max-width: 380px;
    margin-left: auto;
    display: flex;
    align-items: center;
    background: #f2f0ea;
    border: 1px solid transparent;
    border-radius: 20px;
    padding: 7px 16px;
    transition: all .2s;
}

.search-box:focus-within {
    background: #fff;
    border-color: var(--primary);
}

.search-box svg {
    flex-shrink: 0;
    color: var(--text-3);
}

.search-box input {
    border: none;
    outline: none;
    background: transparent;
    padding-left: 8px;
    width: 100%;
    color: var(--text);
}

/* ================= 首页 ================= */
.category-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 20px 0 4px;
}

.chip {
    padding: 5px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text-2);
    font-size: 13px;
    transition: all .15s;
}

.chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
    padding: 20px 0 48px;
}

.book-card {
    display: flex;
    gap: 14px;
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
    transition: transform .18s, box-shadow .18s;
    border: 1px solid transparent;
}

.book-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .09);
    border-color: #f0e4dc;
}

/* 纯 CSS 占位封面:渐变 + 竖排书名 */
.cover {
    position: relative;
    width: 86px;
    height: 116px;
    border-radius: 6px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px 8px;
    color: #fff;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}

.cover::before {
    content: "";
    position: absolute;
    inset: 4px;
    border: 1px solid rgba(255, 255, 255, .35);
    border-radius: 3px;
    pointer-events: none;
}

.cover .cover-title {
    writing-mode: vertical-rl;
    font-family: var(--serif);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 2px;
    line-height: 1.25;
    max-height: 100%;
    overflow: hidden;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}

.cover .cover-author {
    font-size: 10px;
    opacity: .85;
    align-self: flex-end;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.book-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.book-title {
    font-family: var(--serif);
    font-size: 17px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-meta {
    font-size: 12px;
    color: var(--text-3);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.book-meta .tag {
    color: var(--primary);
    background: #fdf0eb;
    border-radius: 4px;
    padding: 0 6px;
    line-height: 18px;
}

.book-desc {
    font-size: 13px;
    color: var(--text-2);
    margin-top: 8px;
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-info .book-meta.bottom {
    margin-top: auto;
    padding-top: 8px;
}

/* 空状态 / 加载 */
.empty, .loading {
    text-align: center;
    color: var(--text-3);
    padding: 80px 0;
    font-size: 14px;
}

.empty .empty-icon {
    font-size: 44px;
    margin-bottom: 12px;
    opacity: .5;
}

/* ================= 详情页 ================= */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-3);
    font-size: 13px;
    padding: 18px 0 0;
}

.back-link:hover {
    color: var(--primary);
}

.book-detail {
    display: flex;
    gap: 28px;
    background: var(--card);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 28px;
    margin-top: 14px;
}

.book-detail .cover {
    width: 130px;
    height: 176px;
    border-radius: 8px;
}

.book-detail .cover .cover-title {
    font-size: 20px;
    letter-spacing: 3px;
}

.detail-info {
    flex: 1;
    min-width: 0;
}

.detail-title {
    font-family: var(--serif);
    font-size: 26px;
    font-weight: 700;
    line-height: 1.3;
}

.detail-author {
    margin-top: 8px;
    color: var(--text-2);
    font-size: 14px;
}

.detail-author .tag {
    color: var(--primary);
    background: #fdf0eb;
    border-radius: 4px;
    padding: 1px 8px;
    font-size: 12px;
    margin-right: 10px;
}

.detail-stats {
    margin-top: 10px;
    display: flex;
    gap: 28px;
    color: var(--text-3);
    font-size: 13px;
}

.detail-stats b {
    display: block;
    font-size: 18px;
    color: var(--text);
    font-family: var(--serif);
}

.detail-desc {
    margin-top: 14px;
    color: var(--text-2);
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-wrap;
}

.detail-actions {
    margin-top: 18px;
    display: flex;
    gap: 12px;
    align-items: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 8px;
    padding: 9px 22px;
    font-size: 14px;
    transition: all .15s;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-ghost {
    border: 1px solid var(--line);
    color: var(--text-2);
    background: #fff;
}

.btn-ghost:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-ghost.on {
    border-color: var(--primary);
    color: var(--primary);
    background: #fdf0eb;
}

.chapter-section {
    background: var(--card);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 22px 28px;
    margin-top: 20px;
    margin-bottom: 48px;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    padding-bottom: 12px;
}

.section-head h2 {
    font-size: 17px;
    font-family: var(--serif);
}

.section-head .toggle-btn {
    color: var(--text-3);
    font-size: 13px;
}

.section-head .toggle-btn:hover {
    color: var(--primary);
}

.chapter-list {
    list-style: none;
    columns: 2;
    column-gap: 40px;
}

.chapter-list li a {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 6px;
    border-bottom: 1px dashed #f0ece2;
    font-size: 14px;
    color: var(--text-2);
    break-inside: avoid;
}

.chapter-list .wc {
    color: var(--text-3);
    font-size: 12px;
    flex-shrink: 0;
}

.chapter-list li a:hover {
    color: var(--primary);
    background: #fdfaf7;
}

.chapter-list li a.current {
    color: var(--primary);
    font-weight: 600;
}

.chapter-list li a.current {
    color: var(--primary);
    font-weight: 600;
}

.chapter-list .vol-head {
    column-span: all;
    list-style: none;
    margin: 16px 0 2px;
    padding: 4px 6px 8px;
    color: var(--primary);
    font-family: var(--serif);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--line);
}

.chapter-list li:first-child .vol-head:first-child {
    margin-top: 4px;
}

.catalog-empty {
    color: var(--text-3);
    font-size: 13px;
    padding: 16px 0 4px;
    text-align: center;
}

.no-chapter-hint {
    color: var(--text-3);
    font-size: 13px;
}

/* ================= 阅读页 ================= */
.reader-body {
    transition: background .25s, color .25s;
}

.reader-body.theme-white {
    --r-bg: #ffffff;
    --r-text: #2c2c2e;
    --r-text-2: #6e6e73;
    --r-bar: rgba(255, 255, 255, .96);
    --r-line: #ebedf0;
}

.reader-body.theme-paper {
    --r-bg: #f8f1e0;
    --r-text: #3b3428;
    --r-text-2: #8a7f68;
    --r-bar: rgba(248, 241, 224, .96);
    --r-line: #e6dcc4;
}

.reader-body.theme-green {
    --r-bg: #cbe6cb;
    --r-text: #2b3c2b;
    --r-text-2: #5f7a5f;
    --r-bar: rgba(203, 230, 203, .96);
    --r-line: #b1d4b1;
}

.reader-body.theme-dark {
    --r-bg: #17171a;
    --r-text: #a8a8ad;
    --r-text-2: #6b6b70;
    --r-bar: rgba(28, 28, 32, .96);
    --r-line: #2c2c31;
}

.reader-body {
    background: var(--r-bg);
    color: var(--r-text);
    min-height: 100vh;
}

.reader-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    height: 48px;
    padding: 0 14px;
    gap: 6px;
    background: var(--r-bar);
    border-bottom: 1px solid var(--r-line);
    backdrop-filter: blur(8px);
    transition: background .25s;
}

.reader-topbar .rt-title {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: var(--r-text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rt-btn {
    padding: 7px 12px;
    border-radius: 8px;
    color: var(--r-text-2);
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.rt-btn:hover {
    background: rgba(128, 128, 128, .12);
    color: var(--r-text);
}

.reader-main {
    max-width: 760px;
    margin: 0 auto;
    padding: 76px 22px 60px;
}

.reader-chapter-title {
    font-family: var(--serif);
    font-size: 22px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 6px;
}

.reader-chapter-meta {
    text-align: center;
    color: var(--r-text-2);
    font-size: 12px;
    margin-bottom: 30px;
}

.reader-content p {
    font-size: var(--fs, 18px);
    line-height: var(--lh, 1.9);
    text-indent: 2em;
    margin-bottom: 1em;
    letter-spacing: .3px;
}

.reader-end {
    margin-top: 44px;
    padding: 18px 0 6px;
    border-top: 1px solid var(--r-line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.reader-end .chapter-pos {
    color: var(--r-text-2);
    font-size: 13px;
}

.nav-btn {
    min-width: 108px;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    border: 1px solid var(--r-line);
    color: var(--r-text-2);
    background: transparent;
    transition: all .15s;
}

.nav-btn:hover:not(:disabled) {
    color: var(--primary);
    border-color: var(--primary);
}

.nav-btn:disabled {
    opacity: .35;
    cursor: not-allowed;
}

.nav-btn.next {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.nav-btn.next:hover:not(:disabled) {
    background: var(--primary-dark);
}

/* 目录抽屉 */
.drawer-mask {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .4);
    z-index: 60;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s;
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 430px;
    max-width: 88vw;
    background: var(--r-bar);
    z-index: 61;
    transform: translateX(100%);
    transition: transform .25s ease;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(8px);
}

body.drawer-open .drawer-mask {
    opacity: 1;
    pointer-events: auto;
}

body.drawer-open .drawer {
    transform: translateX(0);
}

.drawer-head {
    padding: 16px 18px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.drawer-head b {
    font-family: var(--serif);
    font-size: 15px;
}

.drawer-head .close-btn {
    color: var(--r-text-2);
    font-size: 20px;
    line-height: 1;
    padding: 4px;
}

/* 工具行:搜索 + 正/倒序 */
.drawer-tools {
    display: flex;
    gap: 8px;
    padding: 0 14px 10px;
    border-bottom: 1px solid var(--r-line);
}

.drawer-search {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(128, 128, 128, .1);
    border-radius: 8px;
    padding: 6px 10px;
    color: var(--r-text-2);
}

.drawer-search input {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    font-size: 13px;
    color: var(--r-text);
}

.order-btn {
    flex-shrink: 0;
    border: 1px solid var(--r-line);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 13px;
    color: var(--r-text-2);
    transition: all .15s;
}

.order-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.order-btn.on {
    color: var(--primary);
    border-color: var(--primary);
    background: rgba(212, 56, 13, .06);
}

/* 章节两列网格,卷名跨双列 */
.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px 20px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 10px;
    align-content: start;
}

.drawer-body li {
    list-style: none;
    min-width: 0;
}

.drawer-body li a {
    display: block;
    padding: 8px 10px;
    font-size: 13px;
    color: var(--r-text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-radius: 6px;
}

.drawer-body li a:hover {
    color: var(--primary);
}

.drawer-body li a.current {
    color: var(--primary);
    font-weight: 600;
    background: rgba(212, 56, 13, .07);
}

.drawer-body .vol-head {
    grid-column: 1 / -1;
    margin: 12px 0 2px;
    padding: 2px 10px 6px;
    color: var(--primary);
    font-family: var(--serif);
    font-weight: 700;
    font-size: 14px;
    border-bottom: 1px solid var(--r-line);
}

.drawer-body .vol-head:first-child {
    margin-top: 4px;
}

.drawer-body .toc-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--r-text-2);
    padding: 40px 0;
    font-size: 13px;
}

/* 设置面板 */
.settings-pop {
    position: fixed;
    top: 56px;
    right: 14px;
    z-index: 45;
    width: 264px;
    background: var(--r-bar);
    border: 1px solid var(--r-line);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .18);
    padding: 16px;
    display: none;
}

.settings-pop.open {
    display: block;
}

.setting-row {
    margin-bottom: 14px;
}

.setting-row:last-child {
    margin-bottom: 0;
}

.setting-row .label {
    font-size: 12px;
    color: var(--r-text-2);
    margin-bottom: 8px;
}

.font-stepper {
    display: flex;
    align-items: center;
    border: 1px solid var(--r-line);
    border-radius: 8px;
    overflow: hidden;
}

.font-stepper button {
    flex: 1;
    padding: 8px 0;
    font-size: 15px;
    color: var(--r-text);
}

.font-stepper button:hover {
    background: rgba(128, 128, 128, .12);
}

.font-stepper span {
    flex: 1;
    text-align: center;
    font-size: 13px;
    border-left: 1px solid var(--r-line);
    border-right: 1px solid var(--r-line);
    color: var(--r-text-2);
}

.theme-dots {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.theme-dot {
    height: 38px;
    border-radius: 8px;
    border: 2px solid transparent;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-dot.active {
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}

.theme-dot.d-white {
    background: #fff;
    color: #555;
    border-color: #e0e0e0;
}

.theme-dot.d-white.active {
    border-color: var(--primary);
}

.theme-dot.d-paper {
    background: #f8f1e0;
    color: #7a6c4f;
}

.theme-dot.d-green {
    background: #cbe6cb;
    color: #3e5c3e;
}

.theme-dot.d-dark {
    background: #17171a;
    color: #999;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 12%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, .78);
    color: #fff;
    padding: 10px 22px;
    border-radius: 22px;
    font-size: 14px;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
}

.toast.show {
    opacity: 1;
}

/* ================= 响应式 ================= */
@media (max-width: 640px) {
    .topbar-inner {
        gap: 10px;
    }

    .nav-tabs {
        display: none;
    }

    .book-grid {
        grid-template-columns: 1fr;
    }

    .book-detail {
        flex-direction: column;
        padding: 20px;
    }

    .chapter-list {
        columns: 1;
    }

    .detail-stats {
        gap: 18px;
    }

    /* 小屏目录抽屉回退单列 */
    .drawer-body {
        grid-template-columns: 1fr;
    }
}

/* 宽屏详情页目录三列 */
@media (min-width: 1000px) {
    .chapter-list {
        columns: 3;
    }
}
