:root {
    --primary-color: #1f2937;
    --primary-dark: #111827;
    --bg-color: #f6f5f1;
    --card-bg: #fffefa;
    --text-color: #202124;
    --muted-color: #8a8f98;
    --soft-color: #f0eee8;
    --border-color: #e2dfd7;
    --shadow: 0 16px 40px rgba(31, 41, 55, 0.07);
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--text-color);
    background: var(--bg-color);
    line-height: 1.7;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--primary-color); }
img { max-width: 100%; display: block; }
.container { width: min(1080px, calc(100% - 32px)); margin: 0 auto; }

.site-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
}
.topbar {
    min-height: 78px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}
.logo {
    font-size: clamp(1.75rem, 5vw, 2.55rem);
    line-height: 1;
    font-weight: 900;
    letter-spacing: -0.08em;
    color: var(--primary-dark);
    white-space: nowrap;
}
.top-actions { display: flex; gap: 10px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.top-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 8px 18px;
    border-radius: 14px;
    background: var(--soft-color);
    border: 1px solid rgba(31, 41, 55, 0.06);
    color: var(--primary-dark);
    font-weight: 700;
}
.top-link.ghost { background: transparent; }
.site-tabs {
    min-height: 58px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
    text-align: center;
    border-top: 1px solid var(--border-color);
    font-size: 1.08rem;
    font-weight: 750;
    color: #3f4652;
}
.site-tabs a { padding: 14px 6px; border-radius: 12px; }
.site-tabs a:hover { background: var(--soft-color); color: var(--primary-dark); }

.flash-wrap { margin-top: 14px; }
.flash { padding: 12px 14px; border-radius: 14px; margin-bottom: 10px; background: #fff8db; border: 1px solid #eed98d; }
.flash.success { background: #edf8ef; border-color: #a8d8af; }
.flash.error { background: #fff1f0; border-color: #ffa39e; }

.search-strip {
    margin: 22px auto 28px;
    padding: 0;
}
.search-form {
    display: flex;
    gap: 0;
    max-width: 100%;
    border: 2px solid var(--border-color);
    background: var(--card-bg);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 10px 22px rgba(31, 41, 55, 0.04);
}
.search-form input[type="text"] {
    border: 0;
    background: transparent;
    min-height: 52px;
    border-radius: 0;
}
.search-form button { border-radius: 0; min-width: 128px; }

.hero {
    margin: 24px auto;
    padding: clamp(22px, 4vw, 34px);
    border-radius: 26px;
    background: linear-gradient(135deg, #ffffff, #f6f4ee);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}
.hero h1 { margin: 0 0 10px; font-size: clamp(1.8rem, 4vw, 3rem); line-height: 1.2; letter-spacing: -0.04em; }
.hero p { margin: 0 0 18px; color: var(--muted-color); }

input[type="text"], input[type="password"], input[type="email"], input[type="number"], select, textarea {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 12px 14px;
    font: inherit;
    background: white;
    color: var(--text-color);
}
textarea { min-height: 160px; resize: vertical; }
button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 14px;
    padding: 11px 18px;
    background: var(--primary-color);
    color: white;
    font: inherit;
    font-weight: 750;
    cursor: pointer;
    min-height: 44px;
}
button:hover, .btn:hover { background: var(--primary-dark); color: white; }
button:disabled { opacity: 0.65; cursor: not-allowed; }
.btn.secondary, button.secondary { background: var(--soft-color); color: var(--primary-dark); }
.btn.secondary:hover, button.secondary:hover { background: #e6e2d8; color: var(--primary-dark); }
.btn.danger, button.danger { background: #b42318; }
.inline-form { display: inline; }

.grid-layout { display: grid; grid-template-columns: 1fr 300px; gap: 24px; margin-bottom: 30px; }
.section, .sidebar-card, .panel, .form-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 22px;
    padding: clamp(18px, 3vw, 24px);
    box-shadow: var(--shadow);
}
.section.plain { background: transparent; border: 0; box-shadow: none; padding: 0; }
.section + .section, .panel + .panel { margin-top: 22px; }
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}
.section-title { margin: 0; font-size: 1.32rem; line-height: 1.25; letter-spacing: -0.03em; }
.section-more { color: var(--muted-color); font-weight: 700; }

.recommend-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: clamp(14px, 4vw, 32px);
}
.recommend-card { text-align: center; }
.recommend-card img {
    width: min(150px, 100%);
    aspect-ratio: 3 / 4;
    object-fit: cover;
    margin: 0 auto 10px;
    border-radius: 14px;
    background: var(--soft-color);
    box-shadow: 0 12px 24px rgba(31, 41, 55, 0.10);
}
.recommend-card h3 { margin: 0 0 2px; font-size: 1rem; font-weight: 800; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.recommend-card p { margin: 0; color: var(--muted-color); font-size: 0.92rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.book-list { display: grid; gap: 14px; }
.book-card {
    display: grid;
    grid-template-columns: 86px 1fr;
    gap: 15px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 18px;
    background: white;
}
.book-cover img { width: 86px; height: 116px; object-fit: cover; border-radius: 12px; background: #eee; }
.book-info h3 { margin: 0 0 5px; font-size: 1.08rem; line-height: 1.4; }
.book-info p { margin: 4px 0; }
.meta, .muted { color: var(--muted-color); font-size: 0.92rem; }
.stat-row { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted-color); font-size: 0.88rem; }
.stat-pill { padding: 2px 8px; border-radius: 999px; background: var(--soft-color); }
.text-book-list { display: grid; gap: 8px; }
.text-book-row {
    display: grid;
    grid-template-columns: 56px 1fr auto;
    gap: 12px;
    align-items: baseline;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border-color);
}
.text-book-row .cat { color: var(--muted-color); }
.text-book-row .name { font-weight: 760; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.text-book-row .author { color: var(--muted-color); font-size: 0.92rem; white-space: nowrap; }
.category-list, .hot-list { display: grid; gap: 10px; padding: 0; list-style: none; margin: 0; }
.category-list a, .hot-list a { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border-color); }
.category-cloud { display: flex; flex-wrap: wrap; gap: 10px; }
.category-chip { padding: 9px 14px; border-radius: 999px; background: var(--soft-color); font-weight: 700; }

.book-detail { display: grid; grid-template-columns: 180px 1fr; gap: clamp(18px, 4vw, 28px); align-items: start; }
.book-detail .cover { width: 180px; height: 240px; object-fit: cover; border-radius: 16px; box-shadow: var(--shadow); background: var(--soft-color); }
.book-main h1 { margin: 0 0 8px; font-size: clamp(1.6rem, 4vw, 2.25rem); line-height: 1.18; letter-spacing: -0.05em; }
.book-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 18px 0; }
.book-stat { padding: 12px; border-radius: 16px; background: var(--soft-color); text-align: center; }
.book-stat strong { display: block; font-size: 1.12rem; line-height: 1.2; }
.book-stat span { color: var(--muted-color); font-size: 0.84rem; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.book-desc {
    max-height: 7.8em;
    overflow: hidden;
    position: relative;
    margin-top: 14px;
    color: #444b56;
}
.book-desc.collapsed::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3.2em;
    background: linear-gradient(to bottom, rgba(255,254,250,0), var(--card-bg));
}
.book-desc.expanded { max-height: none; }
.collapse-toggle { margin-top: 8px; padding: 7px 0; background: transparent; color: var(--primary-color); min-height: auto; font-weight: 800; }
.collapse-toggle:hover { background: transparent; color: var(--primary-dark); }
.chapter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.chapter-grid a { padding: 10px 12px; border: 1px solid var(--border-color); border-radius: 12px; background: white; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.collapsible-list.collapsed { max-height: 360px; overflow: hidden; position: relative; }
.collapsible-list.collapsed::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 76px; background: linear-gradient(to bottom, rgba(255,254,250,0), var(--card-bg)); pointer-events: none; }

.reader-page {
    --bg-color: #fbfaf6;
    --card-bg: #fbfaf6;
    --border-color: #ebe7dd;
    background: var(--bg-color);
}
.reader-wrap { max-width: 820px; margin: 0 auto; padding: 24px 0 40px; }
.reader-toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    color: var(--muted-color);
}
.reader-toolbar .actions { margin: 0; }
.reader-toolbar button, .reader-toolbar select { min-height: 38px; padding: 7px 11px; border-radius: 12px; }
.reader-card { background: transparent; border: 0; border-radius: 0; padding: clamp(6px, 3vw, 26px); box-shadow: none; }
.reader-card h1 { margin: 0 0 8px; font-size: clamp(1.5rem, 5vw, 2.35rem); line-height: 1.3; letter-spacing: -0.04em; }
.reader-content { font-size: 1.12rem; line-height: 2.1; letter-spacing: 0.02em; color: #242424; }
.reader-end { margin-top: 44px; padding-top: 24px; border-top: 1px solid var(--border-color); }
.reader-progress { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; color: var(--muted-color); margin-bottom: 14px; }
.reader-progress span { font-weight: 800; color: var(--text-color); }
.reader-progress small { color: var(--muted-color); }
.reader-nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 0; }
.reader-nav .btn { width: 100%; text-align: center; justify-content: center; }
.btn.disabled, .btn.disabled:hover { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
body.theme-eye { --bg-color: #eef4e8; --card-bg: #eef4e8; --border-color: #d3dfc8; }
body.theme-night { --bg-color: #111; --card-bg: #111; --text-color: #dedbd3; --muted-color: #918d86; --border-color: #2d2d2d; --shadow: none; }
body.theme-night .reader-content { color: #d8d5cd; }
body.theme-night .book-desc.collapsed::after,
body.theme-night .collapsible-list.collapsed::after { background: linear-gradient(to bottom, rgba(17,17,17,0), var(--card-bg)); }

.form-card { max-width: 560px; margin: 34px auto; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; margin-bottom: 6px; font-weight: 760; }
.counter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.form-help { margin: -4px 0 14px; color: var(--muted-color); font-size: 0.9rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: white; border-radius: 16px; overflow: hidden; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border-color); text-align: left; vertical-align: top; }
th { background: #f7f5ef; }
.admin-nav { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.pagination { display: flex; gap: 8px; flex-wrap: wrap; margin: 20px 0; }
.pagination a { padding: 8px 12px; border-radius: 10px; background: white; border: 1px solid var(--border-color); }
.pagination a.active { background: var(--primary-color); color: white; border-color: var(--primary-color); }
.site-footer { margin-top: 34px; padding: 28px 0; color: var(--muted-color); text-align: center; }

@media (max-width: 760px) {
    .container { width: min(100% - 24px, 1080px); }
    .topbar { min-height: 72px; }
    .top-actions { gap: 8px; }
    .top-link { min-height: 38px; padding: 7px 14px; border-radius: 12px; }
    .site-tabs { font-size: 1rem; min-height: 52px; }
    .search-strip { margin-top: 16px; }
    .search-form { border-radius: 16px; }
    .search-form button { min-width: 100px; padding-left: 14px; padding-right: 14px; }
    .grid-layout { grid-template-columns: 1fr; }
    .recommend-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
    .book-card { grid-template-columns: 76px 1fr; gap: 12px; padding: 10px; }
    .book-cover img { width: 76px; height: 102px; }
    .book-info p:not(.meta):not(.stat-row) { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    .text-book-row { grid-template-columns: 48px 1fr; }
    .text-book-row .author { grid-column: 2; }
    .book-detail { grid-template-columns: 112px 1fr; }
    .book-detail .cover { width: 112px; height: 150px; border-radius: 14px; }
    .book-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .counter-grid { grid-template-columns: 1fr; gap: 0; }
    .chapter-grid { grid-template-columns: 1fr; }
    .reader-wrap { width: min(100% - 28px, 820px); padding-top: 18px; }
    .reader-toolbar { align-items: flex-start; }
    .reader-nav { grid-template-columns: 1fr; }
}
