/* ========== 书阁 · 设计令牌 ========== */
:root {
  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --surface-2: #EDF1F7;
  --ink: #101828;
  --ink-2: #344054;
  --muted: #667085;
  --line: #E4E9F2;
  --accent: #2563EB;
  --accent-ink: #FFFFFF;
  --accent-soft: #EAF0FE;
  --danger: #B42318;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 10px 28px -18px rgba(16, 24, 40, .28);
  --max: 1120px;
  --read-max: 44rem;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
}

[data-theme="dark"] {
  --bg: #0B1220;
  --surface: #121A29;
  --surface-2: #182234;
  --ink: #E6EDF7;
  --ink-2: #C3CFE0;
  --muted: #93A2B8;
  --line: #22304A;
  --accent: #6EA8FF;
  --accent-ink: #08111F;
  --accent-soft: #16243C;
  --danger: #F97066;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
[data-theme="dark"] .bk .a { color: var(--muted); }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* ========== 顶栏 ========== */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.top-in {
  max-width: var(--max); margin: 0 auto; padding: 0 20px;
  height: 60px; display: flex; align-items: center; gap: 22px;
}
.brand { display: flex; align-items: center; gap: 9px; font-size: 17px; font-weight: 700; letter-spacing: .02em; }
.brand .mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 13px; font-weight: 800;
}
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 7px 11px; border-radius: var(--radius-sm); color: var(--ink-2);
  font-size: 14px; transition: background-color 120ms ease, color 120ms ease;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.on { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.search {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 0 12px; height: 36px; min-width: 210px;
}
.search input {
  border: 0; outline: 0; background: transparent; color: var(--ink);
  font-size: 14px; width: 100%; min-width: 0;
}
.search input::placeholder { color: var(--muted); }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; cursor: pointer; padding: 0;
  transition: border-color 120ms ease, color 120ms ease;
}
.icon-btn:hover { border-color: var(--muted); color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; }

/* ========== 布局 ========== */
.wrap { max-width: var(--max); margin: 0 auto; padding: 26px 20px 90px; }
.sec { margin: 0 0 34px; }
.sec-head { display: flex; align-items: baseline; gap: 12px; margin: 0 0 14px; }
.sec-head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: .01em; }
.sec-head .more { margin-left: auto; font-size: 13px; color: var(--muted); }
.sec-head .more:hover { color: var(--accent); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ========== 书籍网格 ========== */
.grid {
  display: grid; gap: 22px 18px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.bk { display: flex; flex-direction: column; gap: 8px; }
.cover {
  position: relative; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line);
}
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover .ph {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; padding: 14px 12px;
  background: var(--surface-2);
  color: var(--ink-2); text-align: center;
}
/* 无封面时用素面书衣：深色布纹 + 竖排书名，不用渐变/光斑 */
.cover .ph.cloth {
  align-items: stretch; justify-content: flex-start; gap: 0; padding: 0;
  color: #F2F5F9; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.16);
}
.cover .ph.cloth::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 7px;
  background: rgba(255,255,255,.2); box-shadow: inset -1px 0 0 rgba(0,0,0,.22), inset 1px 0 0 rgba(255,255,255,.08);
}
.cover .ph.cloth .ph-c {
  display: block; margin: 14px 12px 8px; padding-left: 4px;
  font-size: 30px; font-weight: 700; line-height: 1; color: rgba(255,255,255,.9);
  letter-spacing: .02em;
}
.cover .ph.cloth .ph-t {
  margin: 0 12px auto; padding-left: 4px;
  font-size: 13px; font-weight: 600; line-height: 1.7; letter-spacing: .04em;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden;
}
.cover .ph.cloth em {
  margin: 10px 12px 14px; padding-left: 4px; font-style: normal;
  font-size: 10.5px; color: rgba(242,245,249,.62); letter-spacing: .06em;
  display: flex; align-items: center; gap: 6px;
}
/* 书脊压印线 + 藏书印，让占位读起来像「素面精装」而不是加载失败 */
.cover .ph.cloth em::before {
  content: ""; flex: 0 0 14px; height: 1px; background: rgba(242,245,249,.35);
}
.cover .ph.cloth::after {
  content: "书阁"; position: absolute; right: 10px; bottom: 10px;
  font-size: 9px; letter-spacing: .16em; color: rgba(242,245,249,.34);
  writing-mode: vertical-rl;
}
.cover .ph:not(.cloth) em { font-style: normal; font-size: 10.5px; color: var(--muted); }
.bk .t {
  font-size: 13.5px; font-weight: 600; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.bk .a { font-size: 12.5px; color: #5A6675; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.bk:hover .t { color: var(--accent); }

/* ========== 榜单 ========== */
.rank { display: grid; gap: 0; }
.rank-row {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 16px; border-bottom: 1px solid var(--line);
}
.rank-row:last-child { border-bottom: 0; }
.rank-num {
  width: 24px; text-align: center; font-size: 13px; font-weight: 700;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.rank-row:nth-child(-n+3) .rank-num { color: var(--accent); }
.rank-row .tt { font-size: 14px; font-weight: 600; }
.rank-row .au { font-size: 12.5px; color: var(--muted); }
.rank-row .meta { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ========== 分类条 ========== */
.cats { display: flex; flex-wrap: wrap; gap: 8px; }
.cats a {
  padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 13px; color: var(--ink-2);
  transition: border-color 120ms ease, color 120ms ease;
}
.cats a:hover { border-color: var(--accent); color: var(--accent); }
.cats a.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ========== 详情页 ========== */
.book-head { display: flex; gap: 22px; padding: 22px; }
.book-head .cover { width: 150px; flex: 0 0 150px; }
.book-head h1 { margin: 2px 0 10px; font-size: 22px; line-height: 1.35; letter-spacing: -.01em; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.meta-row b { color: var(--ink-2); font-weight: 600; }
.intro { font-size: 13.5px; color: var(--ink-2); line-height: 1.75; max-width: 62ch; }
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 18px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: opacity 120ms ease;
}
.btn:hover { opacity: .9; }
.btn.ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--muted); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }

.toc { padding: 18px 22px 22px; }
.toc-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.toc-list { columns: 2; column-gap: 26px; }
@media (max-width: 640px) { .toc-list { columns: 1; } }
.toc-list a {
  display: block; padding: 7px 0; font-size: 13.5px; color: var(--ink-2);
  border-bottom: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  break-inside: avoid;
}
.toc-list a:hover { color: var(--accent); }

/* ========== 阅读页 ========== */
.reader { max-width: var(--read-max); margin: 0 auto; }
.reader-bar {
  display: flex; align-items: center; gap: 10px; padding: 12px 0 16px;
  font-size: 13px; color: var(--muted); min-width: 0;
}
.reader-bar > a {
  max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reader-bar > span { flex: 0 0 auto; }
.reader h1 { font-size: 19px; line-height: 1.5; margin: 4px 0 20px; letter-spacing: -.005em; }
.content { font-size: var(--fs, 17px); line-height: var(--lh, 1.95); color: var(--ink); }
.content p { margin: 0 0 .85em; text-indent: 2em; text-align: justify; }
.content p:last-child { margin-bottom: 0; }
.reader-nav { display: flex; gap: 10px; margin: 28px 0 0; }
.reader-nav a, .reader-nav span {
  flex: 1; text-align: center; padding: 11px 8px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface); font-size: 13.5px; color: var(--ink-2);
}
.reader-nav a:hover { border-color: var(--accent); color: var(--accent); }
.reader-nav span { color: var(--muted); border-style: dashed; }
.reader-tools { display: flex; gap: 8px; margin-left: auto; }
.reader-tools button {
  min-width: 38px; height: 38px; padding: 0 8px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  font-size: 12.5px; font-weight: 600;
}
.reader-tools button:active { background: var(--surface-2); }
.reader-tools button:hover { border-color: var(--muted); }
.chap-title-list { max-height: 60vh; overflow: auto; }

/* ========== 空状态 ========== */
.empty {
  padding: 56px 20px; text-align: center; color: var(--muted); font-size: 14px;
  border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface);
}

/* ========== 分页 ========== */
.pager { display: flex; justify-content: center; gap: 8px; margin-top: 22px; }
.pager a, .pager span {
  min-width: 34px; height: 34px; display: grid; place-items: center;
  padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 13px; color: var(--ink-2);
}
.pager a:hover { border-color: var(--accent); color: var(--accent); }
.pager .cur { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ========== 页脚 ========== */
.foot {
  border-top: 1px solid var(--line); margin-top: 40px; padding: 22px 20px 40px;
  font-size: 12.5px; color: var(--muted); text-align: center; line-height: 1.9;
}

/* ========== 手机 ========== */
.tabbar { display: none; }
@media (max-width: 760px) {
  .nav { display: none; }
  .top-in { height: 54px; gap: 12px; padding: 0 14px; }
  .search { min-width: 0; flex: 1; height: 34px; }
  .wrap { padding: 18px 14px 92px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 16px 12px; }
  .book-head { padding: 16px; gap: 14px; }
  .book-head .cover { width: 104px; flex: 0 0 104px; }
  .book-head h1 { font-size: 17px; }
  .intro { font-size: 13px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(3, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    display: grid; place-items: center; gap: 3px; padding: 9px 0 8px;
    font-size: 11px; color: var(--muted);
  }
  .tabbar a.on { color: var(--accent); }
  .tabbar a.on svg { stroke-width: 2.3; }
  .reader-tools button { min-width: 42px; height: 40px; }
  .tabbar svg { width: 20px; height: 20px; }
  .rank-row { padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
