* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { overflow-x: hidden; width: 100%; }

:root {
  --bg: #f8f6f1;
  --card: #fff;
  --text: #2c2c2c;
  --text2: #666;
  --accent: #c0392b;
  --accent2: #e74c3c;
  --border: #e8e4dc;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --sidebar-w: 300px;
  --reader-font-size: 1.05rem;
  --reader-line-height: 2;
  --reader-font: "LXGW WenKai", "LXGW WenKai Screen", "Noto Serif SC", Georgia, serif;
  --ui-font: "Noto Sans SC", -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

body {
  font-family: var(--ui-font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

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

/* Header */
.header {
  background: linear-gradient(135deg, #2c3e50, #34495e);
  color: #fff;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
}
.header h1 { font-size: 1.2rem; white-space: nowrap; }
.header h1 span { color: #e74c3c; }

.search-box {
  flex: 1;
  min-width: 0;
  max-width: 500px;
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 0.5rem 1rem 0.5rem 2.2rem;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  background: rgba(255,255,255,0.15);
  color: #fff;
  outline: none;
}
.search-box input::placeholder { color: rgba(255,255,255,0.5); }
.search-box input:focus { background: rgba(255,255,255,0.25); }
.search-box::before {
  content: "🔍";
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
}

.nav-links { display: flex; gap: 1rem; }
.nav-links a { color: rgba(255,255,255,0.8); font-size: 0.9rem; }
.nav-links a:hover { color: #fff; }

/* Container */
.container { max-width: 1200px; margin: 0 auto; padding: 2rem; }
.page-title { font-size: 1.3rem; font-weight: 600; margin-bottom: 1.2rem; color: var(--text); }

/* Book grid */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.5rem;
}

.book-card {
  background: var(--card);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}
.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.book-cover {
  height: 160px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 2rem;
  font-weight: bold;
  position: relative;
}
.progress-badge {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  backdrop-filter: blur(4px);
}
.progress-text {
  font-size: 0.72rem;
  color: var(--accent);
  margin-top: 0.4rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-info { padding: 1rem; }
.book-info h3 { font-size: 1rem; margin-bottom: 0.3rem; }
.book-info .meta {
  font-size: 0.8rem;
  color: var(--text2);
  margin-bottom: 0.4rem;
}
.book-info .keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.tag {
  background: #f0ebe3;
  color: var(--text2);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
}

/* Book detail */
.book-detail {
  display: flex;
  gap: 2rem;
  margin-bottom: 2rem;
  background: var(--card);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.book-detail .info { flex: 1; }
.book-detail h2 { font-size: 1.8rem; margin-bottom: 0.5rem; }
.book-detail .synopsis {
  color: var(--text);
  margin-top: 1rem;
  line-height: 1.9;
  font-size: 0.95rem;
  padding: 1rem;
  background: var(--bg);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

/* Book stats */
.book-stats {
  display: flex;
  gap: 2rem;
  margin: 1.2rem 0;
  padding: 1rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.book-stats .stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.book-stats .stat b {
  font-size: 1.4rem;
  color: var(--text);
  font-weight: 600;
}
.book-stats .stat span {
  font-size: 0.8rem;
  color: var(--text2);
  margin-top: 0.1rem;
}

/* CTA */
.cta-row { display: flex; gap: 0.8rem; margin: 1.2rem 0; flex-wrap: wrap; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.7rem 1.6rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
}
.btn-primary:hover { background: var(--accent2); color: #fff; transform: translateY(-1px); }
.btn-cta { font-size: 1rem; padding: 0.8rem 1.8rem; }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.7rem 1.4rem;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn-ghost:hover { background: var(--bg); border-color: var(--accent); color: var(--accent); }

/* Last read highlight in TOC */
.chapter-list a.last-read {
  background: #fff3f0;
  border-left: 3px solid var(--accent);
  padding-left: 0.8rem;
  color: var(--accent);
  font-weight: 500;
}

/* TOC (book detail page) */
.toc { background: var(--card); border-radius: 10px; padding: 1.5rem; box-shadow: var(--shadow); }
.toc h3 { margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 2px solid var(--border); }
.volume-title {
  font-weight: 600;
  margin: 1rem 0 0.5rem;
  color: var(--accent);
}
.chapter-list { list-style: none; }
.chapter-list li {
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  transition: background 0.15s;
}
.chapter-list li:hover { background: var(--bg); }
.chapter-list a {
  display: flex;
  justify-content: space-between;
  color: var(--text);
}
.chapter-list .word-count { color: var(--text2); font-size: 0.8rem; }

/* ============================
   Reader Layout
   ============================ */
.reader-layout {
  display: flex;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* Sidebar */
.reader-sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s ease;
  z-index: 50;
}
.reader-sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-w));
}
.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.sidebar-header h3 {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.sidebar-header a {
  color: var(--text);
  font-size: 0.85rem;
}
.sidebar-filter {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-filter input {
  width: 100%;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  font-family: var(--ui-font);
}
.sidebar-filter input:focus { border-color: var(--accent); background: var(--card); }

.sidebar-toc {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}
.sidebar-toc .volume-title {
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  margin: 0.3rem 0 0;
}
.sidebar-toc .ch-item {
  display: block;
  padding: 0.45rem 1rem 0.45rem 1.5rem;
  font-size: 0.85rem;
  color: var(--text);
  transition: background 0.15s;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.sidebar-toc .ch-item:hover { background: var(--bg); }
.sidebar-toc .ch-item.active {
  background: #fdf2f0;
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* Reader main area */
.reader-main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* Top toolbar */
.reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
  flex-shrink: 0;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 0.5rem; }
.toolbar-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.toolbar-btn:hover { background: var(--bg); border-color: #ccc; }
.toolbar-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.toolbar-sep {
  width: 1px;
  height: 1.2rem;
  background: var(--border);
  margin: 0 0.2rem;
}
.chapter-title-bar {
  font-size: 0.85rem;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
  text-align: center;
}

/* Font size controls */
.font-controls {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.font-controls .toolbar-btn { min-width: 2rem; justify-content: center; }
.font-label { font-size: 0.8rem; color: var(--text2); min-width: 2.5rem; text-align: center; }

/* Reader content area */
.reader-body {
  flex: 1;
  padding: 3rem 4rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}
.reader-body h1.chapter-heading {
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
  text-align: center;
  font-weight: 700;
  color: var(--text);
  font-family: var(--reader-font);
}
.chapter-meta {
  text-align: center;
  color: var(--text2);
  font-size: 0.85rem;
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.reader-content {
  font-family: var(--reader-font);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
  text-indent: 2em;
  color: var(--text);
}
.reader-content p { margin-bottom: 0.8em; }

/* Bottom navigation */
.reader-bottom-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 0;
  margin-top: 2rem;
  border-top: 1px solid var(--border);
}
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
  transition: all 0.2s;
}
.nav-btn:hover { background: var(--bg); border-color: var(--accent); color: var(--accent); }
.nav-btn:disabled, .nav-btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.nav-btn:disabled:hover, .nav-btn[disabled]:hover { background: var(--card); border-color: var(--border); color: var(--text); }
.nav-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.nav-btn.primary:hover { background: var(--accent2); }

/* Reading progress bar */
.progress-bar {
  position: fixed;
  top: 56px;
  left: 0;
  height: 3px;
  background: var(--accent);
  transition: width 0.1s;
  z-index: 99;
}

/* Theme variations */
body.theme-dark {
  --bg: #1a1a2e;
  --card: #16213e;
  --text: #e0e0e0;
  --text2: #a0a0a0;
  --border: #2a2a4a;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}
body.theme-sepia {
  --bg: #f4ecd8;
  --card: #faf5e8;
  --text: #5b4636;
  --text2: #8b7355;
  --border: #e0d5bf;
}
body.theme-green {
  --bg: #e8f0e8;
  --card: #f0f5f0;
  --text: #2f4f2f;
  --text2: #5a7a5a;
  --border: #c8d8c8;
}

/* Responsive */
@media (max-width: 768px) {
  .header { padding: 0.5rem 0.8rem; gap: 0.5rem; }
  .header h1 { font-size: 1.1rem; }
  .nav-links { display: none; }
  .search-box { flex-basis: 100%; order: 1; max-width: none; }

  .container { padding: 1rem; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.8rem; }
  .book-cover { height: 120px; font-size: 1.5rem; }
  .book-detail { flex-direction: column; gap: 1rem; padding: 1.2rem; }
  .book-detail h2 { font-size: 1.4rem; }
  .book-stats { gap: 1.2rem; }
  .book-stats .stat b { font-size: 1.1rem; }
  .cta-row .btn-primary, .cta-row .btn-ghost { flex: 1; justify-content: center; }
  .btn-cta { font-size: 0.95rem; padding: 0.7rem 1.2rem; }
  .reader-body { padding: 1.5rem 1.2rem; }
  .reader-body h1.chapter-heading { font-size: 1.4rem; }
  .chapter-meta { margin-bottom: 1.5rem; padding-bottom: 1rem; }

  .reader-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 75vw;
    min-width: 75vw;
    max-width: 300px;
    box-shadow: 4px 0 12px rgba(0,0,0,0.15);
    z-index: 200;
  }
  .reader-sidebar.collapsed { margin-left: -100vw; box-shadow: none; }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 150;
  }
  .reader-sidebar.collapsed ~ .sidebar-backdrop,
  .sidebar-backdrop.hidden { display: none; }

  .reader-toolbar {
    flex-wrap: wrap;
    padding: 0.4rem 0.8rem;
    gap: 0.3rem;
  }
  .toolbar-left { flex-wrap: wrap; }
  .toolbar-right { flex-wrap: wrap; }
  .chapter-title-bar { max-width: 100%; flex-basis: 100%; order: -1; text-align: left; font-size: 0.8rem; }
  .toolbar-btn { padding: 0.3rem 0.5rem; font-size: 0.8rem; }

  .reader-content { font-size: 1rem !important; }

  .reader-bottom-nav { flex-direction: column; gap: 0.8rem; padding: 1rem 0; }
  .nav-btn { width: 100%; justify-content: center; font-size: 0.85rem; }

  .progress-bar { top: 0; }

  .reader-layout { height: 100vh; }
}

/* Btn (legacy, used in non-reader pages) */
.btn {
  padding: 0.5rem 1.2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
.btn:hover { background: var(--accent2); }
.btn:disabled { background: #ccc; cursor: not-allowed; }

/* Search results */
.search-results h2 { margin-bottom: 1rem; }
.result-item {
  background: var(--card);
  padding: 1rem 1.2rem;
  border-radius: 8px;
  margin-bottom: 0.8rem;
  box-shadow: var(--shadow);
}
.result-item h4 { margin-bottom: 0.3rem; }
.result-item .snippet { color: var(--text2); font-size: 0.9rem; }
.result-item mark { background: #ffeaa7; padding: 0 2px; border-radius: 2px; }
.result-section { margin-bottom: 2rem; }

/* Empty state */
.empty {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text2);
}
.empty .icon { font-size: 3rem; margin-bottom: 1rem; }

/* Loading */
.loading { text-align: center; padding: 2rem; color: var(--text2); }

/* Scrollbar styling for sidebar */
.sidebar-toc::-webkit-scrollbar { width: 4px; }
.sidebar-toc::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.sidebar-toc::-webkit-scrollbar-thumb:hover { background: #bbb; }
