:root {
  --bg: #faf7f2;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --text: #22201d;
  --text-muted: #665f57;
  --accent: #b4690e;
  --accent-soft: rgba(180, 105, 14, 0.12);
  --border: rgba(34, 32, 29, 0.1);
  --vignette: radial-gradient(circle at 90% 8%, rgba(251, 191, 36, 0.12), transparent 52%);
  --header-bg: rgba(250, 247, 242, 0.84);
  --font-reader: 'Literata', Georgia, Cambria, serif;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --reader-size: 1.125rem;
  --reader-line: 1.75;
}

body[data-theme="winterfire"] {
  --bg: #0b1018;
  --surface: rgba(16, 23, 36, 0.78);
  --surface-solid: #111827;
  --text: #e6edf7;
  --text-muted: #9aa9bf;
  --accent: #f97316;
  --accent-soft: rgba(249, 115, 22, 0.16);
  --border: rgba(148, 197, 255, 0.14);
  --vignette:
    radial-gradient(ellipse at 50% 108%, rgba(234, 88, 12, 0.30) 0%, rgba(249, 115, 22, 0.10) 38%, transparent 68%),
    radial-gradient(ellipse at 50% -10%, rgba(125, 211, 252, 0.14) 0%, transparent 55%);
  --header-bg: rgba(11, 16, 24, 0.84);
}

body[data-theme="day"] {
  --bg: #fbf8f1;
  --surface: rgba(255, 253, 248, 0.78);
  --surface-solid: #fffdf8;
  --text: #231f1a;
  --text-muted: #6d655b;
  --accent: #b4690e;
  --accent-soft: rgba(180, 105, 14, 0.12);
  --border: rgba(35, 31, 26, 0.1);
  --vignette: radial-gradient(circle at 88% 6%, rgba(245, 158, 11, 0.14), transparent 55%);
  --header-bg: rgba(251, 248, 241, 0.86);
}

body[data-theme="ice"] {
  --bg: #f1f6fa;
  --surface: rgba(255, 255, 255, 0.76);
  --surface-solid: #ffffff;
  --text: #162433;
  --text-muted: #52677d;
  --accent: #0284c7;
  --accent-soft: rgba(2, 132, 199, 0.12);
  --border: rgba(22, 36, 51, 0.11);
  --vignette: radial-gradient(circle at 50% 0%, rgba(125, 211, 252, 0.2), transparent 60%);
  --header-bg: rgba(241, 246, 250, 0.85);
}

body[data-theme="fire"] {
  --bg: #18110e;
  --surface: rgba(32, 22, 18, 0.82);
  --surface-solid: #211713;
  --text: #f3e8df;
  --text-muted: #b59f91;
  --accent: #f97316;
  --accent-soft: rgba(249, 115, 22, 0.18);
  --border: rgba(243, 232, 223, 0.12);
  --vignette: radial-gradient(circle at 50% 100%, rgba(234, 88, 12, 0.18), transparent 58%);
  --header-bg: rgba(24, 17, 14, 0.86);
}

body[data-theme="wind"] {
  --bg: #f2f5f4;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --text: #1c2826;
  --text-muted: #5b6d6a;
  --accent: #0d9488;
  --accent-soft: rgba(13, 148, 136, 0.12);
  --border: rgba(28, 40, 38, 0.1);
  --vignette: linear-gradient(125deg, rgba(153, 246, 228, 0.14) 0%, transparent 50%, rgba(204, 251, 241, 0.12) 100%);
  --header-bg: rgba(242, 245, 244, 0.85);
}

body[data-theme="leaves"] {
  --bg: #f6f4ec;
  --surface: rgba(255, 254, 249, 0.78);
  --surface-solid: #fffef9;
  --text: #24261c;
  --text-muted: #626653;
  --accent: #657c32;
  --accent-soft: rgba(101, 124, 50, 0.13);
  --border: rgba(36, 38, 28, 0.1);
  --vignette: radial-gradient(circle at 12% 10%, rgba(163, 177, 108, 0.16), transparent 52%);
  --header-bg: rgba(246, 244, 236, 0.86);
}

body[data-theme="ashes"] {
  --bg: #1e1e20;
  --surface: rgba(39, 39, 42, 0.82);
  --surface-solid: #27272a;
  --text: #e4e4e7;
  --text-muted: #a1a1aa;
  --accent: #d4a373;
  --accent-soft: rgba(212, 163, 115, 0.16);
  --border: rgba(228, 228, 231, 0.12);
  --vignette: radial-gradient(circle at 50% 92%, rgba(161, 161, 170, 0.12), transparent 60%);
  --header-bg: rgba(30, 30, 32, 0.86);
}

body[data-theme="night"] {
  --bg: #0c101b;
  --surface: rgba(19, 25, 42, 0.84);
  --surface-solid: #13192a;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #818cf8;
  --accent-soft: rgba(129, 140, 248, 0.18);
  --border: rgba(226, 232, 240, 0.12);
  --vignette: radial-gradient(circle at 50% 0%, rgba(99, 102, 241, 0.16), transparent 58%);
  --header-bg: rgba(12, 16, 27, 0.86);
}

body.plain-mode {
  --bg: #ffffff !important;
  --surface: #ffffff !important;
  --surface-solid: #ffffff !important;
  --text: #18181b !important;
  --text-muted: #52525b !important;
  --accent: #2563eb !important;
  --accent-soft: rgba(37, 99, 235, 0.1) !important;
  --border: rgba(24, 24, 27, 0.12) !important;
  --vignette: none !important;
  --header-bg: rgba(255, 255, 255, 0.94) !important;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: var(--vignette);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-ui);
  transition: background-color 0.65s ease, color 0.5s ease;
  overflow-x: hidden;
}

#ambient-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.92;
  transition: opacity 0.4s ease;
}

body.plain-mode #ambient-canvas { opacity: 0; }

.progress-track {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: transparent;
  z-index: 60;
  pointer-events: none;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.12s linear, background-color 0.5s ease;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.7rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
}

.brand-btn:hover { background: var(--accent-soft); }

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.42rem 0.68rem;
  border-radius: 8px;
  cursor: pointer;
}

.icon-btn:hover, .icon-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.icon-btn.active { color: var(--accent); }

main {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1.15rem 5rem;
}

.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem 1.75rem;
  margin-bottom: 1.5rem;
  backdrop-filter: blur(8px);
}

.novel-kicker {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.novel-title {
  font-family: var(--font-reader);
  font-size: clamp(1.75rem, 4vw, 2.35rem);
  font-weight: 600;
  margin: 0 0 0.75rem;
  line-height: 1.2;
}

.novel-blurb {
  color: var(--text-muted);
  font-size: 0.98rem;
  line-height: 1.65;
  margin: 0 0 1.25rem;
}

.resume-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.95rem 1.1rem;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  margin-top: 1rem;
}

.resume-meta { font-size: 0.88rem; line-height: 1.4; }
.resume-meta strong { display: block; font-size: 0.94rem; }

.primary-btn {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-family: var(--font-ui);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.section-heading {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 1.75rem 0 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toc-list { display: grid; gap: 0.65rem; }

.toc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.95rem 1.1rem;
  color: var(--text);
  font-family: var(--font-ui);
  cursor: pointer;
}

.toc-item:hover { border-color: var(--accent); transform: translateY(-1px); }
.toc-item-left { display: flex; align-items: center; gap: 0.9rem; min-width: 0; }
.toc-num { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); width: 1.6rem; flex-shrink: 0; }
.toc-title { font-weight: 600; font-size: 0.98rem; margin-bottom: 0.2rem; }
.toc-sub { font-size: 0.8rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.theme-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: capitalize;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}

.read-check { font-size: 0.74rem; color: var(--accent); font-weight: 600; }

.reader-header {
  text-align: center;
  margin: 1rem 0 2.5rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--border);
}

.chapter-meta-row {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.chapter-title {
  font-family: var(--font-reader);
  font-size: clamp(1.7rem, 4vw, 2.35rem);
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 0.5rem;
}

.chapter-prose {
  font-family: var(--font-reader);
  font-size: var(--reader-size);
  line-height: var(--reader-line);
  max-width: 64ch;
  margin: 0 auto;
}

.chapter-prose p { margin: 0 0 1.4em; text-wrap: pretty; }
.chapter-prose p.first-para::first-letter {
  float: left;
  font-size: 3.2em;
  line-height: 0.85;
  padding-right: 0.14em;
  padding-top: 0.06em;
  font-weight: 600;
  color: var(--accent);
}

.scene-break {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 2.4rem 0;
  color: var(--accent);
  opacity: 0.75;
}

.chapter-nav {
  max-width: 64ch;
  margin: 3.25rem auto 0;
  padding-top: 1.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.nav-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.65rem 1rem;
  border-radius: 10px;
  font-family: var(--font-ui);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
}

.nav-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.nav-btn:disabled { opacity: 0.38; cursor: not-allowed; }

.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.42);
  z-index: 70;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(360px, 92vw);
  background: var(--surface-solid);
  color: var(--text);
  border-left: 1px solid var(--border);
  z-index: 80;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }

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

.drawer-tabs { display: flex; gap: 0.35rem; }

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
}
.tab-btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.drawer-body {
  padding: 0.85rem 1rem;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.drawer-row {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.72rem 0.85rem;
  color: var(--text);
  font-family: var(--font-ui);
  cursor: pointer;
}
.drawer-row:hover, .drawer-row.current { border-color: var(--accent); background: var(--accent-soft); }

.bookmark-card { border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem 0.85rem; display: flex; flex-direction: column; gap: 0.4rem; }
.bookmark-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-size: 0.82rem; font-weight: 600; }
.bookmark-snippet { font-size: 0.78rem; color: var(--text-muted); line-height: 1.45; }
.bookmark-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 0.2rem; }
.mini-link { background: none; border: none; padding: 0; font-size: 0.78rem; font-weight: 600; color: var(--accent); cursor: pointer; }
.mini-del { background: none; border: none; padding: 0; font-size: 0.76rem; color: var(--text-muted); cursor: pointer; }
.mini-del:hover { color: #ef4444; }

.settings-popover {
  position: fixed;
  top: 58px;
  right: max(1rem, calc(50% - 480px + 1rem));
  width: min(300px, calc(100vw - 2rem));
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  z-index: 65;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  display: none;
}
.settings-popover.open { display: block; }
.setting-group { margin-bottom: 0.9rem; }
.setting-group:last-child { margin-bottom: 0; }
.setting-label { font-size: 0.76rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.45rem; display: block; }
.seg-control { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.35rem; }
.seg-control.two { grid-template-columns: repeat(2, 1fr); }
.seg-btn { background: transparent; border: 1px solid var(--border); color: var(--text); font-family: var(--font-ui); font-size: 0.8rem; padding: 0.42rem 0.5rem; border-radius: 8px; cursor: pointer; }
.seg-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.toast {
  position: fixed; bottom: 1.25rem; left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--surface-solid);
  color: var(--text);
  border: 1px solid var(--accent);
  padding: 0.55rem 1rem;
  border-radius: 999px;
  font-size: 0.82rem;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 90;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.hidden { display: none !important; }

@media (max-width: 560px) {
  .btn-label-hide-sm { display: none; }
  .hero-card { padding: 1.4rem 1.15rem; }
}

.toc-search {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  margin-bottom: 0.85rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.toc-search::placeholder { color: var(--text-muted); }
.toc-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.drawer-search-wrap {
  padding: 0.75rem 1rem 0;
}
.drawer-search-wrap .toc-search {
  margin-bottom: 0;
  padding: 0.52rem 0.78rem;
  font-size: 0.84rem;
}
