/* 飞阅 — mobile-first, premium reading UI */
:root {
  --bg: #f6f4ef;
  --bg-elevated: #ffffff;
  --bg-soft: #efebe3;
  --ink: #1a1a1a;
  --ink-secondary: #5c5c5c;
  --ink-muted: #8a8a8a;
  --line: rgba(26,26,26,0.08);
  --accent: #e85d04;
  --accent-soft: rgba(232,93,4,0.12);
  --accent-dark: #c44d03;
  --success: #2a9d8f;
  --ai: #7c3aed;
  --ai-soft: rgba(124,58,237,0.12);
  --shadow-sm: 0 1px 2px rgba(26,26,26,0.04), 0 4px 12px rgba(26,26,26,0.04);
  --shadow-md: 0 8px 24px rgba(26,26,26,0.08);
  --shadow-lg: 0 16px 48px rgba(26,26,26,0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --nav-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font-sans: "PingFang SC", "Noto Sans SC", "HarmonyOS Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", Georgia, serif;
  --max: 1120px;
  --touch: 44px;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #121212;
  --bg-elevated: #1c1c1e;
  --bg-soft: #252528;
  --ink: #f2f2f2;
  --ink-secondary: #b0b0b0;
  --ink-muted: #7a7a7a;
  --line: rgba(255,255,255,0.08);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.35);
  --accent: #ff7a33;
  --accent-soft: rgba(255,122,51,0.15);
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
}
@media (min-width: 900px) {
  body { padding-bottom: 0; }
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
ul, ol { margin: 0; padding: 0; list-style: none; }
h1,h2,h3,h4 { margin: 0; font-weight: 600; letter-spacing: -0.02em; line-height: 1.25; }
p { margin: 0; }

.container { width: min(100% - 32px, var(--max)); margin-inline: auto; }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); border:0; }

/* Top bar — desktop */
.topbar {
  position: sticky; top: 0; z-index: 40;
  backdrop-filter: saturate(160%) blur(14px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex; align-items: center; gap: 16px;
  height: 60px;
  width: min(100% - 32px, var(--max));
  margin-inline: auto;
}
.logo {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 1.2rem; letter-spacing: -0.03em;
  flex-shrink: 0;
}
.logo-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #f4a261);
  display: grid; place-items: center; color: #fff; font-size: 14px;
  box-shadow: 0 4px 12px rgba(232,93,4,0.35);
}
.nav-links { display: none; gap: 4px; margin-left: 12px; }
.nav-links a {
  padding: 8px 14px; border-radius: 999px; font-size: 0.92rem;
  color: var(--ink-secondary); min-height: var(--touch); display: inline-flex; align-items: center;
}
.nav-links a.active, .nav-links a:hover { background: var(--accent-soft); color: var(--accent-dark); }
.search-wrap { flex: 1; max-width: 360px; margin-left: auto; position: relative; }
.search-wrap input {
  width: 100%; height: 40px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg-elevated); padding: 0 16px 0 40px; outline: none;
}
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-wrap svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); opacity: .45; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: var(--touch); height: var(--touch); border-radius: 12px;
  display: grid; place-items: center; background: var(--bg-elevated); border: 1px solid var(--line);
}
@media (min-width: 900px) {
  .nav-links { display: flex; }
  body.has-bottom-nav { padding-bottom: 0; }
}

/* Bottom nav — phone */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 0.7rem; color: var(--ink-muted); min-height: var(--nav-h);
}
.bottom-nav a.active { color: var(--accent); font-weight: 600; }
.bottom-nav svg { width: 22px; height: 22px; }
@media (min-width: 900px) { .bottom-nav { display: none; } }

/* Hero */
.hero {
  margin: 20px auto 8px;
  width: min(100% - 32px, var(--max));
  border-radius: 22px;
  padding: 28px 22px;
  background:
    radial-gradient(120% 120% at 100% 0%, rgba(244,162,97,0.35), transparent 55%),
    radial-gradient(80% 80% at 0% 100%, rgba(232,93,4,0.18), transparent 50%),
    var(--bg-elevated);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line);
}
.hero h1 { font-size: clamp(1.6rem, 5vw, 2.2rem); margin-bottom: 8px; }
.hero p { color: var(--ink-secondary); font-size: 0.98rem; max-width: 36em; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--touch); padding: 0 18px; border-radius: 999px;
  font-weight: 600; font-size: 0.92rem; transition: .2s ease;
}
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 8px 20px rgba(232,93,4,0.28); }
.btn-primary:active { transform: scale(0.98); }
.btn-ghost { background: var(--bg-soft); color: var(--ink); border: 1px solid var(--line); }

/* Sections */
.section { margin: 28px auto; width: min(100% - 32px, var(--max)); }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.section-head h2 { font-size: 1.15rem; }
.section-head a { color: var(--accent); font-size: 0.88rem; font-weight: 500; min-height: var(--touch); display: inline-flex; align-items: center; }

/* Book grid — phone 3 cols tight, larger on tablet */
.book-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px 10px;
}
@media (min-width: 600px) {
  .book-grid { grid-template-columns: repeat(4, 1fr); gap: 20px 16px; }
}
@media (min-width: 900px) {
  .book-grid { grid-template-columns: repeat(6, 1fr); }
}
.book-card { display: flex; flex-direction: column; gap: 8px; }
.book-cover {
  position: relative; aspect-ratio: 3/4.2; border-radius: 10px; overflow: hidden;
  background: var(--bg-soft); box-shadow: var(--shadow-sm);
  transition: transform .25s ease, box-shadow .25s ease;
}
.book-card:active .book-cover, .book-card:hover .book-cover {
  transform: translateY(-3px); box-shadow: var(--shadow-md);
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.badge {
  position: absolute; top: 8px; left: 8px;
  font-size: 0.65rem; font-weight: 700; letter-spacing: 0.02em;
  padding: 3px 7px; border-radius: 6px; backdrop-filter: blur(8px);
}
.badge-ai { background: var(--ai-soft); color: var(--ai); }
.badge-done { background: rgba(42,157,143,0.18); color: var(--success); right: 8px; left: auto; }
.book-meta { min-width: 0; }
.book-title {
  font-size: 0.86rem; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book-author { font-size: 0.75rem; color: var(--ink-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Ranking list */
.rank-list { background: var(--bg-elevated); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.rank-item {
  display: grid; grid-template-columns: 36px 52px 1fr auto; gap: 12px; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--line); min-height: 64px;
}
.rank-item:last-child { border-bottom: 0; }
.rank-no { font-weight: 800; font-size: 1.1rem; color: var(--ink-muted); text-align: center; }
.rank-item:nth-child(-n+3) .rank-no { color: var(--accent); }
.rank-cover { width: 52px; aspect-ratio: 3/4; border-radius: 6px; overflow: hidden; }
.rank-cover img { width: 100%; height: 100%; object-fit: cover; }
.rank-title { font-weight: 600; font-size: 0.95rem; }
.rank-sub { font-size: 0.78rem; color: var(--ink-muted); margin-top: 2px; }
.rank-views { font-size: 0.75rem; color: var(--ink-muted); }

/* Chips / filters */
.chips { display: flex; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; min-height: 36px; padding: 0 14px; border-radius: 999px;
  background: var(--bg-elevated); border: 1px solid var(--line); font-size: 0.86rem;
  display: inline-flex; align-items: center; color: var(--ink-secondary);
}
.chip.active { background: var(--accent); color: #fff; border-color: transparent; }

/* Book detail */
.book-hero {
  width: min(100% - 32px, var(--max)); margin: 20px auto;
  display: grid; gap: 20px;
}
@media (min-width: 720px) {
  .book-hero { grid-template-columns: 180px 1fr; align-items: start; }
}
.book-hero-cover {
  width: min(160px, 42vw); margin: 0 auto; aspect-ratio: 3/4.2;
  border-radius: 14px; overflow: hidden; box-shadow: var(--shadow-lg);
}
@media (min-width: 720px) { .book-hero-cover { width: 180px; margin: 0; } }
.book-hero-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-hero-info h1 { font-size: clamp(1.4rem, 4vw, 1.9rem); margin-bottom: 8px; }
.book-stats {
  display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 12px 0;
  font-size: 0.86rem; color: var(--ink-secondary);
}
.pill-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px; }
.pill {
  font-size: 0.75rem; font-weight: 600; padding: 5px 10px; border-radius: 999px;
  background: var(--bg-soft); color: var(--ink-secondary);
}
.pill.ai { background: var(--ai-soft); color: var(--ai); }
.book-desc {
  color: var(--ink-secondary); font-size: 0.95rem; line-height: 1.75;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.book-desc.expanded { -webkit-line-clamp: unset; }
.action-bar {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; margin-top: 18px;
  position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + 8px); z-index: 20;
}
@media (min-width: 900px) { .action-bar { position: static; grid-template-columns: auto auto; justify-content: start; } }
.action-bar .btn { width: 100%; box-shadow: var(--shadow-md); }

.chapter-panel {
  width: min(100% - 32px, var(--max)); margin: 8px auto 32px;
  background: var(--bg-elevated); border-radius: var(--radius); border: 1px solid var(--line);
  overflow: hidden;
}
.chapter-panel h2 { padding: 16px 16px 8px; font-size: 1.05rem; }
.chapter-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-top: 1px solid var(--line); min-height: var(--touch);
}
.chapter-row:active { background: var(--bg-soft); }
.chapter-row .title { font-size: 0.95rem; }
.chapter-row .meta { font-size: 0.75rem; color: var(--ink-muted); flex-shrink: 0; }

/* Footer */
.site-footer {
  text-align: center; padding: 32px 16px 24px; color: var(--ink-muted); font-size: 0.82rem;
}
@media (max-width: 899px) { .site-footer { padding-bottom: 8px; } }

/* Empty / 404 */
.empty { text-align: center; padding: 48px 16px; color: var(--ink-muted); }

/* Browse toolbar */
.browse-bar { margin: 16px auto; width: min(100% - 32px, var(--max)); display: grid; gap: 12px; }
.browse-bar .search-full input {
  width: 100%; height: 48px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg-elevated); padding: 0 16px; outline: none;
}

/* Homepage banners — mobile-first carousel */
.banner-wrap {
  width: min(100% - 24px, var(--max));
  margin: 14px auto 0;
}
.banner-carousel {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--line);
  background: var(--bg-soft);
  aspect-ratio: 2.2 / 1;
}
@media (max-width: 600px) {
  .banner-carousel { aspect-ratio: 16 / 9; border-radius: 14px; }
}
.banner-track {
  display: flex;
  height: 100%;
  transition: transform .4s cubic-bezier(.2,.8,.2,1);
  will-change: transform;
}
.banner-slide {
  flex: 0 0 100%;
  position: relative;
  display: block;
  height: 100%;
  color: #fff;
}
.banner-slide img {
  width: 100%; height: 100%; object-fit: cover;
}
.banner-caption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 28px 18px 16px;
  background: linear-gradient(transparent, rgba(0,0,0,0.65));
}
.banner-title { font-size: clamp(1.05rem, 3.5vw, 1.45rem); font-weight: 700; }
.banner-sub { font-size: 0.86rem; opacity: .9; margin-top: 4px; }
.banner-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(0,0,0,0.35); color: #fff; font-size: 1.4rem;
  display: grid; place-items: center; z-index: 2;
  backdrop-filter: blur(4px);
}
.banner-nav.prev { left: 8px; }
.banner-nav.next { right: 8px; }
.banner-dots {
  position: absolute; left: 0; right: 0; bottom: 8px;
  display: flex; justify-content: center; gap: 6px; z-index: 2;
}
.banner-dots button {
  width: 7px; height: 7px; border-radius: 999px; background: rgba(255,255,255,0.45);
  padding: 0; min-height: 0;
}
.banner-dots button.active { width: 16px; background: #fff; }
.topic-desc {
  color: var(--ink-secondary); font-size: 0.9rem; margin: -4px 0 12px;
  line-height: 1.6;
}
