:root {
  --bg: #f7f3ec;
  --fg: #221d17;
  --muted: #7d7365;
  --card: #fffdf9;
  --soft: #f0eadf;
  --line: #e5ddcf;
  --line-strong: #d5c9b7;
  --accent: #b4442e;
  --accent-dark: #8f3423;
  --accent-soft: #f7e5df;
  --gold: #9a6b22;
  --gold-soft: #f8efd9;
  --shadow: 0 18px 42px -32px rgba(34, 29, 23, 0.4);
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Noto Serif CJK SC", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

body.night {
  --bg: #171513;
  --fg: #e8e1d5;
  --muted: #9e9488;
  --card: #201d1a;
  --soft: #2a2520;
  --line: #342f29;
  --line-strong: #464038;
  --accent: #d4634b;
  --accent-dark: #b44a34;
  --accent-soft: #36241f;
  --gold: #d2a45e;
  --gold-soft: #332a1e;
  --shadow: 0 18px 42px -32px rgba(0, 0, 0, 0.7);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

header#top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--card);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--fg);
  border-radius: 8px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-mark svg { width: 19px; height: 19px; }

.brand-text {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.brand-text small {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.searchbox {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 220px;
  max-width: 560px;
  height: 42px;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.searchbox:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 17px;
  height: 17px;
  color: var(--muted);
  pointer-events: none;
  display: flex;
}

.search-icon svg { width: 100%; height: 100%; }

.searchbox input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 12px 0 38px;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 14px;
}

.searchbox input::placeholder { color: var(--muted); }

.searchbox button {
  height: 100%;
  padding: 0 18px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.18s;
}

.searchbox button:hover:not(:disabled) { background: var(--accent-dark); }
.searchbox button:disabled { opacity: 0.7; }

.hint {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.hint:empty { display: none; }

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 30px 20px 80px;
}

.hero { padding: 16px 0 28px; }

.eyebrow {
  margin: 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero h1 {
  margin: 10px 0 0;
  font-family: var(--serif);
  font-size: clamp(30px, 4.4vw, 42px);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.hero-sub {
  margin: 12px 0 0;
  max-width: 560px;
  font-size: 14px;
  line-height: 1.8;
  color: var(--muted);
}

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

.section-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
}

.section-head span { font-size: 11px; color: var(--muted); letter-spacing: 0.08em; }

.hot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 26px;
  min-height: 0;
}

.hot:empty::after {
  content: "暂无热门搜索";
  font-size: 13px;
  color: var(--muted);
}

.hot .tag {
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--fg);
  font-size: 13px;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
}

.hot .tag:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 46px 20px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  background: var(--card);
  background: color-mix(in srgb, var(--card) 70%, transparent);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.welcome-icon { width: 46px; height: 46px; color: var(--line-strong); }
.welcome-icon svg { width: 100%; height: 100%; }
.welcome p { margin: 0; }

.bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--muted);
}

.bar-title {
  flex: 1;
  min-width: 0;
  color: var(--fg);
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button.back {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 12px;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
}

button.back:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.books {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

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

.book:hover {
  border-color: var(--line-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.cover {
  position: relative;
  width: 78px;
  height: 106px;
  flex: none;
  border-radius: 8px;
  overflow: hidden;
  background: var(--soft);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 700;
  user-select: none;
}

.cover img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.25s;
}

.cover img.loaded { opacity: 1; }

.book .meta { min-width: 0; display: flex; flex-direction: column; gap: 5px; }

.book .name {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 16px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.book .auth { font-size: 12px; color: var(--muted); }

.book .abs {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}

.book .stats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--soft);
  color: var(--muted);
  font-size: 10px;
  line-height: 1.7;
  white-space: nowrap;
}

.chip.score { background: var(--gold-soft); color: var(--gold); }
.chip.done { background: var(--accent-soft); color: var(--accent); }

.book.skeleton { pointer-events: none; }
.book.skeleton .cover { background: var(--soft); color: transparent; }
.sk-line {
  height: 11px;
  border-radius: 5px;
  background: var(--soft);
  animation: pulse 1.2s ease-in-out infinite;
}
.sk-line.title { width: 70%; height: 14px; }
.sk-line.sub { width: 45%; }
.sk-line.text { width: 100%; }
.sk-line.short { width: 60%; }

@keyframes pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.empty {
  padding: 46px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.empty button {
  margin-top: 12px;
  padding: 7px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--card);
  color: var(--fg);
  font-size: 12px;
}

.bookhead {
  display: flex;
  gap: 20px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  margin-bottom: 16px;
}

.bookhead .cover {
  width: 118px;
  height: 158px;
  border-radius: 9px;
  font-size: 38px;
}

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

.bookhead h2 {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 24px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.bookhead .author { font-size: 13px; color: var(--muted); margin-bottom: 10px; }

.bookhead .stats { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }

.bookhead .tags { font-size: 12px; color: var(--muted); line-height: 1.7; margin-bottom: 8px; overflow-wrap: anywhere; }

.bookhead .abstract {
  margin: 0;
  font-size: 13px;
  line-height: 1.75;
  color: var(--ink-soft, #4b4238);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

body.night .bookhead .abstract { color: var(--muted); }

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

button.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.18s;
}

button.primary:hover:not(:disabled) { background: var(--accent-dark); }
button.primary:disabled { opacity: 0.5; }

.status { font-size: 12px; color: var(--muted); }

.progress {
  height: 6px;
  margin: 0 0 16px;
  background: var(--soft);
  border-radius: 999px;
  overflow: hidden;
}

.progress > div {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  border-radius: inherit;
  transition: width 0.3s;
}

.chapter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.chapter-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
}

.chapter-count { font-family: var(--sans); font-size: 11px; font-weight: 400; color: var(--muted); margin-left: 4px; }

#chapterFilter {
  width: 180px;
  max-width: 100%;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--card);
  font-size: 12px;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

#chapterFilter:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.chapters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
}

.chapters .ch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  text-align: left;
  font-size: 13px;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.chapters .ch:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.chapters .ch span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapters .ch .w { flex: none; font-size: 10px; color: var(--muted); }

.more {
  display: block;
  margin: 14px auto 0;
  padding: 8px 22px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font-size: 12px;
}

.more:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.read-progress { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }

.readerbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 760px;
  margin: 0 auto 12px;
  flex-wrap: wrap;
}

.reader-tools { display: flex; align-items: center; gap: 6px; }

.readerbar button {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  padding: 5px 11px;
  border-radius: 7px;
  font-size: 12px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.readerbar button:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.readerbar .to-top { border-color: transparent; background: transparent; color: var(--muted); }

.content {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 44px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  font-family: var(--serif);
  font-size: var(--fs, 18px);
  line-height: 2;
  color: var(--fg);
  overflow-wrap: break-word;
}

.content h3 {
  margin: 0 0 30px;
  font-size: 1.2em;
  font-weight: 700;
  text-align: center;
  line-height: 1.5;
}

.content p { margin: 0 0 0.9em; text-indent: 2em; }
.content p:last-child { margin-bottom: 0; }

.content .empty { font-family: var(--sans); font-size: 13px; padding: 24px 0; }

.pager {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}

.pager button {
  padding: 8px 24px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font-size: 13px;
}

.pager button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.pager button:disabled { opacity: 0.35; }

@media (max-width: 720px) {
  header#top { padding: 10px 14px; gap: 10px; }
  .brand-text { font-size: 18px; }
  .hint { order: 4; width: 100%; margin-left: 0; font-size: 11px; }
  .searchbox { flex: 1 1 100%; order: 3; max-width: none; margin-top: 2px; }
  main { padding: 22px 14px 60px; }
  .hero { padding: 10px 0 22px; }
  .hero h1 { font-size: 28px; }
  .hero-sub { font-size: 13px; }
  .books { grid-template-columns: 1fr; }
  .bookhead { gap: 14px; padding: 14px; }
  .bookhead .cover { width: 96px; height: 130px; }
  .bookhead h2 { font-size: 20px; }
  .bookhead .abstract { -webkit-line-clamp: 4; }
  .chapters { grid-template-columns: 1fr; }
  .chapter-head { align-items: stretch; }
  #chapterFilter { width: 100%; }
  .content { padding: 24px 18px; border-radius: 12px; line-height: 1.95; }
  .content h3 { margin-bottom: 22px; }
  .bar-title { font-size: 17px; }
}

@media (max-width: 420px) {
  .bookhead { flex-direction: column; }
  .bookhead .cover { width: 84px; height: 114px; }
  .book .cover { width: 68px; height: 94px; }
  .book .name { font-size: 15px; }
}
