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

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Georgia', 'Times New Roman', serif;
  background: #0f0f0f;
  color: #d4d4d4;
  line-height: 1.8;
  min-height: 100vh;
  transition: background 0.4s, color 0.4s;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 60px 40px;
}

/* ===== PROGRESS BAR ===== */
.progress-wrap {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
  z-index: 100;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: #c4a97a;
  transition: width 0.1s linear;
}

/* ===== FADE TRANSITION ===== */
body.fade-in {
  animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== TOOLBAR ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid #2a2a2a;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-label {
  font-size: 0.7rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #5a4f3e;
  margin-right: 4px;
}

.theme-btn {
  background: none;
  border: 1px solid #2a2a2a;
  color: #8a7e6b;
  padding: 2px 10px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: 'Georgia', serif;
  transition: color 0.3s, border-color 0.3s, background 0.3s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.theme-btn:hover {
  color: #f0e6d0;
  border-color: #5a4f3e;
}

.theme-btn.active {
  color: #c4a97a;
  border-color: #c4a97a;
  background: rgba(196, 169, 122, 0.08);
}

.reading-time {
  font-size: 0.75rem;
  color: #5a4f3e;
  font-style: italic;
  margin-left: auto;
  white-space: nowrap;
}

.tool-icon-btn {
  background: none;
  border: 1px solid #2a2a2a;
  color: #8a7e6b;
  padding: 2px 8px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.72rem;
  font-family: 'Georgia', serif;
  transition: color 0.3s, border-color 0.3s, background 0.3s;
  line-height: 1.4;
  white-space: nowrap;
}

.tool-icon-btn:hover {
  color: #f0e6d0;
  border-color: #5a4f3e;
}

.tool-icon-btn .badge {
  display: inline-block;
  background: #c4a97a;
  color: #0f0f0f;
  font-size: 0.6rem;
  padding: 0 4px;
  border-radius: 6px;
  margin-left: 3px;
  line-height: 1.3;
  font-weight: 700;
}

/* ===== CHAPTER NAV DROPDOWN ===== */
.chapter-nav select {
  background: none;
  border: 1px solid #2a2a2a;
  color: #8a7e6b;
  padding: 2px 6px 2px 8px;
  border-radius: 3px;
  font-size: 0.75rem;
  font-family: 'Georgia', serif;
  cursor: pointer;
  outline: none;
  transition: color 0.3s, border-color 0.3s;
  -webkit-appearance: none;
  appearance: none;
}

.chapter-nav select:hover {
  color: #f0e6d0;
  border-color: #5a4f3e;
}

.chapter-nav select option {
  background: #0f0f0f;
  color: #d4d4d4;
}

/* ===== TOOLBAR AUTO-HIDE ===== */
.toolbar {
  transition: opacity 0.4s ease;
}
.toolbar.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ===== FULLSCREEN MODE ===== */
body.fullscreen-mode .toolbar,
body.fullscreen-mode .nav,
body.fullscreen-mode .chapter-header h2,
body.fullscreen-mode .back-to-top,
body.fullscreen-mode .progress-wrap,
body.fullscreen-mode .chapter-nav,
body.fullscreen-mode .tool-icon-btn,
body.fullscreen-mode .chapter-header .num .reading-time {
  display: none !important;
}
body.fullscreen-mode .chapter-header {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}
body.fullscreen-mode .chapter-header .num {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}
body.fullscreen-mode .container {
  padding-top: 40px;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1a1815;
  border: 1px solid #3a3228;
  color: #d4d4d4;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-family: 'Georgia', serif;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 200;
  white-space: nowrap;
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== QUOTES ===== */
.chapter-body p.quoted {
  background: rgba(196, 169, 122, 0.06);
  border-left: 2px solid #c4a97a;
  padding-left: 1em;
  cursor: default;
}

.chapter-body p.quote-clickable {
  cursor: pointer;
  position: relative;
}
.chapter-body p.quote-clickable::after {
  content: '\201C';
  position: absolute;
  right: -4px;
  top: 0;
  font-size: 1.4rem;
  color: #3a3228;
  opacity: 0;
  transition: opacity 0.3s;
  line-height: 1;
}
.chapter-body p.quote-clickable:hover::after {
  opacity: 1;
}
.chapter-body p.quote-clickable.quoted::after {
  content: '\201C';
  color: #c4a97a;
  opacity: 1;
}

.quotes-panel-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.quotes-panel-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.quotes-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  max-width: 90vw;
  height: 100%;
  background: #161412;
  border-left: 1px solid #2a2a2a;
  z-index: 160;
  transform: translateX(100%);
  transition: transform 0.35s ease;
  overflow-y: auto;
  padding: 28px 24px;
}
.quotes-panel.visible {
  transform: translateX(0);
}

.quotes-panel h3 {
  font-size: 1.1rem;
  font-weight: 400;
  color: #f0e6d0;
  margin-bottom: 0.5rem;
}
.quotes-panel .quotes-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: #8a7e6b;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}
.quotes-panel .quotes-close:hover {
  color: #f0e6d0;
}
.quotes-panel .quote-item {
  padding: 14px 0;
  border-bottom: 1px solid #2a2a2a;
  font-size: 0.95rem;
  line-height: 1.6;
  color: #b8aa94;
}
.quotes-panel .quote-item:last-child {
  border-bottom: none;
}
.quotes-panel .quote-item .quote-chapter {
  font-size: 0.7rem;
  color: #5a4f3e;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}
.quotes-panel .quote-empty {
  color: #5a4f3e;
  font-style: italic;
  font-size: 0.9rem;
  margin-top: 1rem;
}

/* ===== BACK TO TOP ===== */
.back-to-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid #3a3228;
  background: #1a1815;
  color: #8a7e6b;
  font-size: 1.1rem;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, background 0.3s, color 0.3s, border-color 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  line-height: 1;
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

.back-to-top:hover {
  background: #2a2420;
  color: #f0e6d0;
  border-color: #5a4f3e;
}

/* ===== LANDING TOC PROGRESS ===== */
.toc-item-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.toc-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 18px 12px 6px;
}

.toc-progress-track {
  height: 2px;
  width: 100%;
  background: #2a2a2a;
  border-radius: 1px;
  margin: 0 12px 10px;
  overflow: hidden;
}

.toc-progress-fill {
  height: 100%;
  width: 0%;
  background: #c4a97a;
  border-radius: 1px;
  transition: width 0.3s;
}

.toc-label {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toc-pct {
  font-size: 0.7rem;
  color: #5a4f3e;
  min-width: 32px;
  text-align: right;
}

.done-mark {
  display: none;
  color: #5cb85c;
  font-size: 0.85rem;
  margin-left: 4px;
}

.reset-btn {
  display: block;
  margin: 2rem auto 0;
  background: none;
  border: 1px solid #2a2a2a;
  color: #5a4f3e;
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: 'Georgia', serif;
  cursor: pointer;
  transition: color 0.3s, border-color 0.3s;
}

.reset-btn:hover {
  color: #e74c3c;
  border-color: #e74c3c;
}

/* ===== THEMES ===== */
/* Sepia */
.theme-sepia {
  background: #f4ecd8;
  color: #5b4636;
}
.theme-sepia .chapter-header { border-bottom-color: #dacfbb; }
.theme-sepia .chapter-header .num { color: #a0917a; }
.theme-sepia .chapter-header h2 { color: #3d2e1e; }
.theme-sepia .chapter-body p:first-of-type::first-letter { color: #8b6f47; }
.theme-sepia .break { color: #a0917a; }
.theme-sepia .nav { border-top-color: #dacfbb; }
.theme-sepia .nav a { color: #a0917a; }
.theme-sepia .nav a:hover { color: #5b4636; }
.theme-sepia .nav .back-home { color: #a0917a; }
.theme-sepia .toolbar { border-top-color: #dacfbb; }
.theme-sepia .toolbar-label { color: #a0917a; }
.theme-sepia .theme-btn { border-color: #dacfbb; color: #a0917a; }
.theme-sepia .theme-btn:hover { color: #5b4636; border-color: #8b6f47; }
.theme-sepia .theme-btn.active { color: #8b6f47; border-color: #8b6f47; background: rgba(139, 111, 71, 0.08); }
.theme-sepia .reading-time { color: #a0917a; }
.theme-sepia .chapter-nav select { border-color: #dacfbb; color: #a0917a; }
.theme-sepia .chapter-nav select:hover { color: #5b4636; border-color: #8b6f47; }
.theme-sepia .chapter-nav select option { background: #f4ecd8; color: #5b4636; }
.theme-sepia .back-to-top { background: #e8dfcc; border-color: #dacfbb; color: #a0917a; }
.theme-sepia .back-to-top:hover { background: #e0d5be; color: #5b4636; border-color: #8b6f47; }
.theme-sepia .toc-progress-track { background: #dacfbb; }
.theme-sepia .tool-icon-btn { border-color: #dacfbb; color: #a0917a; }
.theme-sepia .tool-icon-btn:hover { color: #5b4636; border-color: #8b6f47; }
.theme-sepia .tool-icon-btn .badge { background: #8b6f47; color: #f4ecd8; }
.theme-sepia .toast { background: #e8dfcc; border-color: #dacfbb; color: #5b4636; }
.theme-sepia .chapter-body p.quoted { background: rgba(139, 111, 71, 0.08); border-left-color: #8b6f47; }
.theme-sepia .chapter-body p.quote-clickable::after { color: #dacfbb; }
.theme-sepia .chapter-body p.quote-clickable.quoted::after { color: #8b6f47; }
.theme-sepia .quotes-panel-overlay { background: rgba(60,50,40,0.5); }
.theme-sepia .quotes-panel { background: #e8dfcc; border-left-color: #dacfbb; }
.theme-sepia .quotes-panel h3 { color: #3d2e1e; }
.theme-sepia .quotes-panel .quotes-close { color: #a0917a; }
.theme-sepia .quotes-panel .quotes-close:hover { color: #3d2e1e; }
.theme-sepia .quotes-panel .quote-item { border-bottom-color: #dacfbb; color: #5b4636; }
.theme-sepia .quotes-panel .quote-item .quote-chapter { color: #a0917a; }
.theme-sepia .quotes-panel .quote-empty { color: #a0917a; }

/* Light */
.theme-light {
  background: #ffffff;
  color: #333333;
}
.theme-light .chapter-header { border-bottom-color: #e0e0e0; }
.theme-light .chapter-header .num { color: #999999; }
.theme-light .chapter-header h2 { color: #1a1a1a; }
.theme-light .chapter-body p:first-of-type::first-letter { color: #666666; }
.theme-light .break { color: #999999; }
.theme-light .nav { border-top-color: #e0e0e0; }
.theme-light .nav a { color: #999999; }
.theme-light .nav a:hover { color: #333333; }
.theme-light .nav .back-home { color: #999999; }
.theme-light .toolbar { border-top-color: #e0e0e0; }
.theme-light .toolbar-label { color: #999999; }
.theme-light .theme-btn { border-color: #e0e0e0; color: #999999; }
.theme-light .theme-btn:hover { color: #333333; border-color: #666666; }
.theme-light .theme-btn.active { color: #333333; border-color: #333333; background: rgba(0,0,0,0.04); }
.theme-light .reading-time { color: #999999; }
.theme-light .chapter-nav select { border-color: #e0e0e0; color: #999999; }
.theme-light .chapter-nav select:hover { color: #333333; border-color: #666666; }
.theme-light .chapter-nav select option { background: #ffffff; color: #333333; }
.theme-light .back-to-top { background: #f5f5f5; border-color: #e0e0e0; color: #999999; }
.theme-light .back-to-top:hover { background: #eeeeee; color: #333333; border-color: #666666; }
.theme-light .toc-progress-track { background: #e0e0e0; }
.theme-light .tool-icon-btn { border-color: #e0e0e0; color: #999999; }
.theme-light .tool-icon-btn:hover { color: #333333; border-color: #666666; }
.theme-light .tool-icon-btn .badge { background: #333333; color: #ffffff; }
.theme-light .toast { background: #f5f5f5; border-color: #e0e0e0; color: #333333; }
.theme-light .chapter-body p.quoted { background: rgba(0,0,0,0.03); border-left-color: #999999; }
.theme-light .chapter-body p.quote-clickable::after { color: #e0e0e0; }
.theme-light .chapter-body p.quote-clickable.quoted::after { color: #999999; }
.theme-light .quotes-panel-overlay { background: rgba(0,0,0,0.2); }
.theme-light .quotes-panel { background: #ffffff; border-left-color: #e0e0e0; }
.theme-light .quotes-panel h3 { color: #1a1a1a; }
.theme-light .quotes-panel .quotes-close { color: #999999; }
.theme-light .quotes-panel .quotes-close:hover { color: #1a1a1a; }
.theme-light .quotes-panel .quote-item { border-bottom-color: #e0e0e0; color: #333333; }
.theme-light .quotes-panel .quote-item .quote-chapter { color: #999999; }
.theme-light .quotes-panel .quote-empty { color: #999999; }

/* ===== CONTINUE READING ===== */
.continue-reading {
  display: none;
  width: 100%;
  max-width: 380px;
  margin-bottom: 2rem;
  padding: 14px 20px;
  background: #1a1815;
  border: 1px solid #3a3228;
  border-radius: 6px;
  text-align: center;
  transition: background 0.3s;
}
.continue-reading.visible {
  display: block;
}
.continue-reading:hover {
  background: #221f1a;
}
.continue-reading a {
  color: #c4a97a;
  text-decoration: none;
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.continue-reading .label {
  color: #8a7e6b;
  font-size: 0.75rem;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.continue-reading .title {
  color: #f0e6d0;
  margin-top: 2px;
}

/* ===== LANDING ===== */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
}

.landing h1 {
  font-size: 3rem;
  font-weight: 400;
  color: #f0e6d0;
  letter-spacing: 4px;
  margin-bottom: 0.5rem;
}

.landing .subtitle {
  font-size: 1.1rem;
  color: #8a7e6b;
  font-style: italic;
  margin-bottom: 3rem;
}

.landing .toc {
  list-style: none;
  width: 100%;
  max-width: 380px;
}

.landing .toc li {
  border-top: 1px solid #2a2a2a;
}

.landing .toc li:last-child {
  border-bottom: 1px solid #2a2a2a;
}

.landing .toc a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 12px;
  color: #b8aa94;
  text-decoration: none;
  font-size: 1.05rem;
  transition: color 0.3s, background 0.3s;
}

.landing .toc a:hover {
  color: #f0e6d0;
  background: #1a1a1a;
}

.landing .toc .num {
  color: #5a4f3e;
  font-size: 0.85rem;
  letter-spacing: 1px;
}

/* ===== CHAPTER ===== */
.chapter-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #2a2a2a;
}

.chapter-header .num {
  font-size: 0.85rem;
  color: #5a4f3e;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.chapter-header h2 {
  font-size: 1.8rem;
  font-weight: 400;
  color: #f0e6d0;
}

.chapter-body p {
  margin-bottom: 1.3rem;
  text-indent: 1.5em;
}

.chapter-body p:first-of-type {
  text-indent: 0;
}

.chapter-body p:first-of-type::first-letter {
  float: left;
  font-size: 3.2rem;
  line-height: 1;
  margin-right: 8px;
  margin-top: 4px;
  color: #c4a97a;
  font-family: 'Georgia', serif;
}

/* ===== CHAPTER BREAK ===== */
.break {
  text-align: center;
  color: #5a4f3e;
  margin: 2rem 0;
  font-size: 1.2rem;
  letter-spacing: 8px;
}

/* ===== NAVIGATION ===== */
.nav {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid #2a2a2a;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav a {
  color: #8a7e6b;
  text-decoration: none;
  font-size: 0.95rem;
  transition: color 0.3s;
}

.nav a:hover {
  color: #f0e6d0;
}

.nav .back-home {
  color: #5a4f3e;
  font-size: 0.85rem;
}

/* ===== THEME OVERRIDES FOR LANDING ===== */
.theme-sepia .landing h1 { color: #3d2e1e; }
.theme-sepia .landing .subtitle { color: #a0917a; }
.theme-sepia .landing .toc li { border-color: #dacfbb; }
.theme-sepia .landing .toc a { color: #8b7a63; }
.theme-sepia .landing .toc a:hover { color: #3d2e1e; background: #e8dfcc; }
.theme-sepia .landing .toc .num { color: #a0917a; }
.theme-sepia .continue-reading { background: #e8dfcc; border-color: #dacfbb; }
.theme-sepia .continue-reading:hover { background: #e0d5be; }
.theme-sepia .continue-reading a { color: #8b6f47; }
.theme-sepia .continue-reading .label { color: #a0917a; }
.theme-sepia .continue-reading .title { color: #3d2e1e; }
.theme-sepia .landing .toolbar { border-top-color: #dacfbb; }
.theme-sepia .landing .toolbar-label { color: #a0917a; }
.theme-sepia .landing .theme-btn { border-color: #dacfbb; color: #a0917a; }
.theme-sepia .landing .theme-btn:hover { color: #5b4636; border-color: #8b6f47; }
.theme-sepia .landing .theme-btn.active { color: #8b6f47; border-color: #8b6f47; background: rgba(139, 111, 71, 0.08); }
.theme-sepia .reset-btn { border-color: #dacfbb; color: #a0917a; }
.theme-sepia .reset-btn:hover { border-color: #e74c3c; color: #e74c3c; }

.theme-light .landing h1 { color: #1a1a1a; }
.theme-light .landing .subtitle { color: #999999; }
.theme-light .landing .toc li { border-color: #e0e0e0; }
.theme-light .landing .toc a { color: #666666; }
.theme-light .landing .toc a:hover { color: #1a1a1a; background: #f5f5f5; }
.theme-light .landing .toc .num { color: #999999; }
.theme-light .continue-reading { background: #f5f5f5; border-color: #e0e0e0; }
.theme-light .continue-reading:hover { background: #eeeeee; }
.theme-light .continue-reading a { color: #333333; }
.theme-light .continue-reading .label { color: #999999; }
.theme-light .continue-reading .title { color: #1a1a1a; }
.theme-light .landing .toolbar { border-top-color: #e0e0e0; }
.theme-light .landing .toolbar-label { color: #999999; }
.theme-light .landing .theme-btn { border-color: #e0e0e0; color: #999999; }
.theme-light .landing .theme-btn:hover { color: #333333; border-color: #666666; }
.theme-light .landing .theme-btn.active { color: #333333; border-color: #333333; background: rgba(0,0,0,0.04); }
.theme-light .reset-btn { border-color: #e0e0e0; color: #999999; }
.theme-light .reset-btn:hover { border-color: #e74c3c; color: #e74c3c; }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .container {
    padding: 40px 20px;
  }
  .landing h1 {
    font-size: 2rem;
  }
  .chapter-header h2 {
    font-size: 1.4rem;
  }
  .toolbar {
    gap: 10px;
  }
  .reading-time {
    margin-left: 0;
    width: 100%;
  }
  .back-to-top {
    bottom: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }
}
