:root {
  --bg: #faf8f5;
  --fg: #2c2c2c;
  --muted: #888;
  --accent: #c0392b;
  --card-bg: #fff;
  --border: #e8e4df;
  --sidebar-bg: #f5f1ec;
  --hover-bg: #ede8e1;
  --active-bg: #e0d8cf;
  --radius: 6px;
  --max-width: 720px;
  --sidebar-width: 300px;
}

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

body {
  font-family: "Noto Serif SC", "Source Han Serif CN", Georgia, "Times New Roman", serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.loading { color: var(--muted); text-align: center; padding: 2rem; }

/* === 主页 === */
.home-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.home-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border);
}

.home-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--fg);
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
}

.book-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: box-shadow 0.2s, transform 0.15s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.book-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  transform: translateY(-2px);
}

.book-cover {
  width: 100%;
  aspect-ratio: 5/7;
  background: var(--sidebar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-cover-text {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-size: 2.5rem;
  font-weight: 700;
  font-family: serif;
}

.book-info {
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.book-info h3 {
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-info .author {
  color: var(--muted);
  font-size: 0.85rem;
}

.book-info .desc {
  font-size: 0.82rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-info .chapter-count {
  font-size: 0.78rem;
  color: var(--accent);
  margin-top: auto;
}

/* === 阅读器 === */
.reader-layout {
  display: flex;
  min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.back-link {
  font-size: 0.9rem;
  color: var(--accent);
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--muted);
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
}

.sidebar-close:hover { background: var(--hover-bg); }

.book-title {
  font-size: 1rem;
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
}

.toc {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.toc-group { list-style: none; }

.toc-item {
  display: flex;
  align-items: center;
  padding: 0.4rem 1rem;
  font-size: 0.86rem;
  color: var(--fg);
  border: none;
  background: none;
  text-align: left;
  width: 100%;
  cursor: pointer;
  line-height: 1.5;
  transition: background 0.15s;
}

.toc-item:hover { background: var(--hover-bg); }
.toc-item.active { background: var(--active-bg); color: var(--accent); font-weight: 600; }
.toc-item[data-level="2"] { padding-left: 1.8rem; font-size: 0.82rem; }
.toc-item[data-level="3"] { padding-left: 2.6rem; font-size: 0.8rem; }
.toc-item[data-level="4"] { padding-left: 3.4rem; font-size: 0.78rem; }

.toc-item.no-link {
  cursor: default;
  font-weight: 600;
  color: var(--fg);
}

.toc-item.no-link:hover { background: transparent; }

.toc-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0.1rem 0.3rem;
  margin-right: 0.2rem;
  border-radius: 2px;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.toc-toggle:hover { background: var(--hover-bg); }
.toc-toggle.collapsed { transform: rotate(-90deg); }

.toc-children { list-style: none; }
.toc-children.collapsed { display: none; }

/* 主内容区 */
.content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.content-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.content-header .chapter-indicator {
  flex: 1;
}

.menu-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius);
  color: var(--fg);
}

.menu-btn:hover { background: var(--hover-bg); }

.chapter-indicator {
  font-size: 0.85rem;
  color: var(--muted);
}

.chapter-content {
  flex: 1;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.5rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.chapter-content h1,
.chapter-content h2,
.chapter-content h3 {
  margin: 1.5em 0 0.5em;
  line-height: 1.4;
}

.chapter-content p {
  margin: 0.8em 0;
  text-indent: 2em;
}

.chapter-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1rem auto;
  border-radius: var(--radius);
}

.chapter-content blockquote {
  border-left: 3px solid var(--border);
  margin: 1em 0;
  padding: 0.5em 1em;
  color: var(--muted);
}

/* 底部导航 */
.chapter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
}

.nav-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 0.5rem 1.2rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--fg);
  transition: background 0.15s;
}

.nav-btn:hover { background: var(--hover-bg); }
.nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.progress {
  font-size: 0.85rem;
  color: var(--muted);
}

/* 遮罩 */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 50;
}

.overlay.active { display: block; }

/* === 设置面板 === */
.settings-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--muted);
  padding: 0.2rem 0.3rem;
  border-radius: 3px;
  margin-left: auto;
  transition: color 0.15s;
}

.settings-btn:hover { color: var(--fg); }

.settings-panel {
  position: absolute;
  right: 0;
  top: 100%;
  width: 240px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 20;
  display: none;
  overflow: hidden;
}

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

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9rem;
}

.settings-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--muted);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}

.settings-close:hover { background: var(--hover-bg); }

.settings-item {
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-item label {
  font-size: 0.85rem;
  color: var(--fg);
}

.font-size-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.font-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--fg);
  transition: background 0.15s;
}

.font-btn:hover { background: var(--hover-bg); }

.font-size-value {
  font-size: 0.82rem;
  color: var(--muted);
  min-width: 2.5rem;
  text-align: center;
}

/* === 响应式 === */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transform: translateX(-100%);
  }

  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .menu-btn { display: block; }

  .chapter-content { padding: 1.5rem 1rem; }

  .home-container { padding: 1.5rem 1rem; }

  .book-grid { grid-template-columns: repeat(2, 1fr); }
}

/* 滚动条美化 */
.sidebar::-webkit-scrollbar,
.chapter-content::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-thumb,
.chapter-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
