:root {
  --bg: #faf6f0;
  --bg-card: #fff8f0;
  --text: #2c2418;
  --text-secondary: #6b5d4f;
  --accent: #c2653a;
  --accent-hover: #a8512a;
  --border: #e8ddd0;
  --system-bg: #f0ebe3;
  --system-border: #c2975b;
  --system-text: #5a4a2e;
  --nav-bg: #fff8f0;
  --shadow: 0 1px 4px rgba(44, 36, 24, 0.08);
  --progress-bar: #c2653a;
  --font-body: 'Libre Baskerville', 'Georgia', serif;
  --font-display: 'Cormorant Garamond', 'Garamond', serif;
}

[data-theme="dark"] {
  --bg: #1a1612;
  --bg-card: #231f1a;
  --text: #d4cabb;
  --text-secondary: #9a8e7e;
  --accent: #d4845a;
  --accent-hover: #e09a72;
  --border: #3a332a;
  --system-bg: #2a2418;
  --system-border: #8a7040;
  --system-text: #c4a86a;
  --nav-bg: #231f1a;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  --progress-bar: #d4845a;
}

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

html {
  scroll-behavior: smooth;
  font-size: 18px;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.85;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

/* ── Reading progress bar ── */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--progress-bar);
  z-index: 100;
  width: 0%;
  transition: width 0.1s linear;
}

/* ── Theme toggle ── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: border-color 0.2s, color 0.2s;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.moon { display: none; }
[data-theme="dark"] .sun { display: none; }
[data-theme="dark"] .moon { display: inline; }

/* ── Index page ── */
.index-header {
  display: flex;
  justify-content: flex-end;
  padding: 1.5rem 2rem;
  max-width: 800px;
  margin: 0 auto;
}

.index-content {
  max-width: 700px;
  margin: 0 auto;
  padding: 0 2rem 4rem;
}

.hero {
  text-align: center;
  padding: 2rem 0 3rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}

.hero-ornament {
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1.5rem;
}

.hero h1 {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.hero-cn {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 0.8rem;
}

.hero-author {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.hero-desc {
  font-style: italic;
  font-size: 0.95rem;
  color: var(--text-secondary);
  max-width: 500px;
  margin: 0 auto;
  line-height: 1.7;
}

/* ── Support banner ── */
.support-banner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 2.5rem;
  box-shadow: var(--shadow);
}

.support-banner p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.kofi-btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 0.6rem 1.8rem;
  border-radius: 6px;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: background 0.2s, transform 0.1s;
}

.kofi-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

/* ── Table of contents ── */
.toc-section, .about-section, .request-section {
  margin-bottom: 2.5rem;
}

.toc-section h2, .about-section h2, .request-section h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.chapter-list {
  list-style: none;
  counter-reset: none;
  padding: 0;
}

.chapter-list li {
  border-bottom: 1px solid var(--border);
}

.chapter-list li:last-child {
  border-bottom: none;
}

.chapter-list a {
  display: block;
  padding: 0.6rem 0.3rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.15s, padding-left 0.15s;
}

.chapter-list a:hover {
  color: var(--accent);
  padding-left: 0.6rem;
}

.about-section p, .request-section p {
  font-size: 0.9rem;
  margin-bottom: 0.8rem;
  color: var(--text-secondary);
}

.about-section a, .request-section a {
  color: var(--accent);
  text-decoration: none;
}

.about-section a:hover, .request-section a:hover {
  text-decoration: underline;
}

/* ── Chapter page ── */
.chapter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 750px;
  margin: 0 auto;
  padding: 1.2rem 2rem;
}

.back-to-toc {
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.15s;
}

.back-to-toc:hover {
  color: var(--accent);
}

.chapter-content {
  max-width: 650px;
  margin: 0 auto;
  padding: 1rem 2rem 3rem;
}

.chapter-content h1 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 2rem;
  line-height: 1.3;
  color: var(--text);
}

.chapter-content article p {
  text-indent: 1.5em;
  margin-bottom: 0.4rem;
}

.chapter-content article p.system-msg {
  text-indent: 0;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  background: var(--system-bg);
  border-left: 3px solid var(--system-border);
  padding: 0.6rem 1rem;
  margin: 1rem 0;
  border-radius: 4px;
  color: var(--system-text);
}

/* ── Chapter navigation ── */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 650px;
  margin: 0 auto;
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
}

.chapter-nav a {
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--accent);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.chapter-nav a:hover {
  background: var(--bg-card);
  border-color: var(--accent);
}

.nav-prev { margin-right: auto; }
.nav-next { margin-left: auto; }

/* ── Chapter select dropdown ── */
.chapter-select-wrapper {
  flex: 1;
  max-width: 220px;
  min-width: 0;
}

.chapter-select {
  width: 100%;
  padding: 0.45rem 0.6rem;
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b5d4f' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 1.8rem;
  text-overflow: ellipsis;
  transition: border-color 0.15s;
}

.chapter-select:hover,
.chapter-select:focus {
  border-color: var(--accent);
  outline: none;
}

[data-theme="dark"] .chapter-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239a8e7e' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
}

/* ── Footer ── */
.site-footer {
  max-width: 650px;
  margin: 0 auto;
  padding: 2rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

.site-footer em {
  font-style: italic;
}

.disclaimer {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  opacity: 0.7;
}

/* ── Chapter support CTA ── */
.chapter-support {
  max-width: 650px;
  margin: 0 auto;
  padding: 2rem;
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 2rem;
}

.chapter-support > p:first-child {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.chapter-support .request-note {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.chapter-support .request-note a {
  color: var(--accent);
  text-decoration: none;
}

.chapter-support .request-note a:hover {
  text-decoration: underline;
}

/* ── Collapsible chapter list ── */
.chapter-list.collapsed li:nth-child(n+11) {
  display: none;
}

.show-all-btn {
  display: block;
  margin: 1rem auto 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 1.5rem;
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.show-all-btn:hover {
  background: var(--bg-card);
  border-color: var(--accent);
}

.show-all-btn.hidden {
  display: none;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  html { font-size: 16px; }
  .hero h1 { font-size: 1.8rem; }
  .chapter-content { padding: 1rem 1.2rem 2rem; }
  .chapter-content h1 { font-size: 1.4rem; }
  .chapter-nav { padding: 1rem 1.2rem; flex-wrap: wrap; }
  .chapter-select-wrapper { max-width: 100%; order: -1; flex-basis: 100%; margin-bottom: 0.5rem; }
  .chapter-header { padding: 1rem 1.2rem; }
  .index-content { padding: 0 1.2rem 3rem; }
  .index-header { padding: 1rem 1.2rem; }
}
