/* ====== Reset & Base ====== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #fafaf9;
  --bg-card: #ffffff;
  --text: #1c1917;
  --text-secondary: #78716c;
  --border: #e7e5e4;
  --primary: #b45309;
  --primary-hover: #92400e;
  --accent: #f59e0b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* ====== Header ====== */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-title { font-size: 20px; font-weight: 700; }
.site-title a { color: var(--text); }

.lang-select {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  outline: none;
}
.lang-select:focus { border-color: var(--primary); }

/* ====== Category Bar ====== */
.category-bar {
  display: flex;
  gap: 8px;
  padding: 10px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  flex-wrap: wrap;
  max-height: 76px;
  position: relative;
}

.category-bar.expanded {
  max-height: none;
}

.category-bar-wrapper {
  position: relative;
}

.category-expand-btn {
  position: absolute;
  right: 16px;
  bottom: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  z-index: 10;
}
.category-expand-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
}

/* Category overlay for expanded state */
.category-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.category-overlay.show {
  display: flex;
}

.category-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 500px;
  width: 90%;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}

.category-card h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--text);
}

.category-card .cat-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.category-card .cat-chip {
  padding: 6px 16px;
  font-size: 14px;
}

.cat-chip {
  padding: 4px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.cat-chip:hover { border-color: var(--primary); color: var(--primary); }
.cat-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ====== Novel Grid (Index) ====== */
.novel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 140px);
  gap: 16px;
  padding: 24px;
  justify-content: center;
  align-items: start;
}

.novel-card {
  width: 140px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  color: var(--text);
}

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

.novel-cover {
  width: 140px;
  height: 186px;
  object-fit: cover;
  background: var(--border);
  display: block;
}

.novel-title {
  margin: 0;
  padding: 4px 6px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
  height: 42px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.continue-btn {
  display: block;
  padding: 4px 8px;
  margin: 0 6px 6px;
  background: var(--primary);
  color: #fff;
  border-radius: 4px;
  font-size: 11px;
  text-align: center;
  font-weight: 500;
}
.continue-btn:hover {
  background: var(--primary-hover);
  color: #fff;
}

/* ====== Detail Page ====== */
.detail-page { padding: 24px; flex: 1; max-width: 900px; margin: 0 auto; width: 100%; }

.detail-header {
  display: flex;
  gap: 24px;
  margin-bottom: 32px;
}

.detail-cover {
  width: 180px;
  height: 250px;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--border);
  flex-shrink: 0;
}

.detail-meta { flex: 1; }
.detail-meta h2 { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.detail-author { color: var(--text-secondary); font-size: 14px; margin-bottom: 12px; }

.detail-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tag {
  padding: 3px 10px;
  background: #fef3c7;
  color: #92400e;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.detail-desc {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent);
  display: inline-block;
}

.chapter-list { display: flex; flex-direction: column; gap: 2px; }

.chapter-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--text);
  transition: background 0.15s;
}

.chapter-item:hover { background: #fef3c7; }
.chapter-num {
  min-width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--border);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.detail-footer-links {
  display: flex;
  justify-content: center;
  padding: 24px 0;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px 0;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.page-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.page-btn:disabled { opacity: 0.3; cursor: default; }
.page-ellipsis { color: var(--text-secondary); font-size: 14px; padding: 0 4px; }

/* ====== Read Page ====== */
.read-body { background: #fffdf8; }

.read-header {
  padding: 12px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.read-title {
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.read-footer-links {
  display: flex;
  justify-content: center;
  gap: 16px;
  max-width: 700px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

.read-content {
  max-width: 700px;
  margin: 0 auto;
  padding: 32px 20px 60px;
  font-size: 17px;
  line-height: 2;
}

.read-content p {
  text-indent: 2em;
  margin-bottom: 1em;
}

.read-nav {
  display: flex;
  justify-content: space-between;
  max-width: 700px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

/* ====== Buttons ====== */
.btn {
  display: inline-block;
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  transition: all 0.2s;
  cursor: pointer;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); color: #fff; }

.btn-nav {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  min-width: 120px;
}
.btn-nav:hover { border-color: var(--primary); color: var(--primary); }
.btn-nav.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

/* ====== Error & Status Messages ====== */
.loading-msg, .error-msg, .empty-msg {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 20px;
  font-size: 15px;
}

.error-msg a { text-decoration: underline; }

/* ====== Error Page ====== */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  gap: 16px;
}

.error-page h1 { font-size: 72px; font-weight: 800; color: var(--border); }
.error-page p { font-size: 18px; color: var(--text-secondary); }

/* ====== Footer ====== */
.site-footer {
  text-align: center;
  padding: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

/* ====== TOC Overlay ====== */
.toc-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toc-overlay.hidden { display: none; }

.toc-panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 90%;
  max-width: 400px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}

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

.toc-header h3 { font-size: 16px; font-weight: 600; }

.toc-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
}
.toc-close:hover { color: var(--text); }

.toc-list {
  overflow-y: auto;
  padding: 8px 0;
}

.toc-item {
  display: block;
  padding: 8px 16px;
  font-size: 14px;
  color: var(--text);
  border-left: 3px solid transparent;
}

.toc-item:hover { background: #fef3c7; }
.toc-item.toc-active {
  background: #fef3c7;
  border-left-color: var(--primary);
  font-weight: 600;
  color: var(--primary);
}

/* ====== Responsive ====== */
@media (max-width: 640px) {
  .novel-grid {
    grid-template-columns: repeat(auto-fill, 120px);
    gap: 12px;
    padding: 16px;
  }

  .novel-card { width: 120px; }
  .novel-cover { width: 120px; height: 160px; }

  .detail-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .detail-cover { width: 140px; height: 195px; }
  .detail-tags { justify-content: center; }
  .detail-desc { text-align: left; }

  .read-content { font-size: 16px; padding: 20px 16px 40px; }
  .read-nav { padding: 0 16px 24px; }
}
