/* === AI Novel Reader — Core Styles === */
/* Three themes: light / sepia / dark */

:root {
  --reader-width: 720px;
  --sidebar-width: 240px;
  --toolbar-height: 44px;
  --font-size: 20px;
  --line-height: 2.0;
  --transition-speed: 0.3s;
}

/* === Themes === */

/* Light theme (default) */
[data-theme="light"] {
  --bg: #F5F0E8;
  --text: #2C2C2C;
  --text-secondary: #6B6B6B;
  --toolbar-bg: rgba(245, 240, 232, 0.95);
  --sidebar-bg: #EDE8DD;
  --sidebar-text: #555;
  --sidebar-active: #2C2C2C;
  --border: #D4CFC4;
  --progress-bar: #8B4513;
  --link: #8B4513;
  --hover: rgba(139, 69, 19, 0.08);
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* Sepia theme */
[data-theme="sepia"] {
  --bg: #EAE0C8;
  --text: #3D3226;
  --text-secondary: #8B7D6B;
  --toolbar-bg: rgba(234, 224, 200, 0.95);
  --sidebar-bg: #DED4B8;
  --sidebar-text: #5C4F3E;
  --sidebar-active: #3D3226;
  --border: #C4B998;
  --progress-bar: #8B6914;
  --link: #8B6914;
  --hover: rgba(139, 105, 20, 0.08);
  --shadow: 0 1px 3px rgba(0,0,0,0.05);
}

/* Dark theme */
[data-theme="dark"] {
  --bg: #1A1A1A;
  --text: #B0A998;
  --text-secondary: #6B6358;
  --toolbar-bg: rgba(26, 26, 26, 0.95);
  --sidebar-bg: #222222;
  --sidebar-text: #888;
  --sidebar-active: #C8C0B0;
  --border: #333333;
  --progress-bar: #8B7355;
  --link: #C8A96E;
  --hover: rgba(200, 169, 110, 0.08);
  --shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", "宋体", Georgia, serif;
  font-size: var(--font-size);
  line-height: var(--line-height);
  transition: background var(--transition-speed), color var(--transition-speed);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* === Top Toolbar === */
.reader-toolbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--toolbar-height);
  background: var(--toolbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; gap: 20px;
  padding: 0 16px; box-shadow: var(--shadow);
}
.toolbar-btn {
  background: none; border: 1px solid var(--border); color: var(--text);
  padding: 4px 12px; border-radius: 4px; cursor: pointer; font-size: 14px;
  transition: all 0.2s; font-family: inherit;
}
.toolbar-btn:hover { background: var(--hover); }
.toolbar-btn.active { background: var(--link); color: var(--bg); border-color: var(--link); }
.toolbar-divider { width: 1px; height: 20px; background: var(--border); }
.font-size-group { display: flex; gap: 4px; }
.font-size-group .toolbar-btn { padding: 4px 8px; min-width: 32px; }

/* === Reading Progress Bar === */
.reading-progress {
  position: fixed; top: var(--toolbar-height); left: 0; z-index: 99;
  height: 2px; background: var(--progress-bar);
  transition: width 0.15s linear;
}

/* === Layout === */
.reader-layout {
  display: flex;
  margin-top: calc(var(--toolbar-height) + 2px);
  min-height: calc(100vh - var(--toolbar-height));
}

/* === Sidebar TOC === */
.toc-sidebar {
  width: var(--sidebar-width); min-width: var(--sidebar-width);
  background: var(--sidebar-bg); border-right: 1px solid var(--border);
  padding: 20px 12px; overflow-y: auto;
  position: fixed; top: calc(var(--toolbar-height) + 2px); left: 0;
  bottom: 0; z-index: 50;
  transition: transform var(--transition-speed);
}
.toc-title {
  font-size: 16px; font-weight: bold; color: var(--sidebar-active);
  margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.toc-volume {
  font-size: 14px; font-weight: bold; color: var(--sidebar-active);
  margin: 12px 0 4px 0; cursor: pointer;
}
.toc-chapter {
  font-size: 13px; color: var(--sidebar-text);
  padding: 3px 8px; cursor: pointer; border-radius: 3px;
  display: block; text-decoration: none; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.toc-chapter:hover { background: var(--hover); color: var(--sidebar-active); }
.toc-chapter.active { background: var(--hover); color: var(--link); font-weight: bold; }

/* === Main Reading Area === */
.reader-main {
  flex: 1; display: flex; justify-content: center;
  margin-left: var(--sidebar-width);
  padding: 40px 20px 80px;
}
.reader-content {
  max-width: var(--reader-width); width: 100%;
}
.chapter-title {
  font-size: 28px; font-weight: bold; text-align: center;
  margin-bottom: 8px; color: var(--text);
}
.chapter-meta {
  text-align: center; color: var(--text-secondary); font-size: 14px;
  margin-bottom: 32px;
}
.chapter-body {
  font-size: var(--font-size); line-height: var(--line-height);
}
.chapter-body p {
  text-indent: 2em; margin-bottom: 0.8em;
}
.chapter-body hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* === Chapter Navigation === */
.chapter-nav { display: flex; justify-content: space-between; align-items: center; margin: 40px 0 20px; }
.nav-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 8px 16px; border: 1px solid var(--border);
  border-radius: 6px; color: var(--link); text-decoration: none;
  font-size: 15px; transition: all 0.2s;
}
.nav-btn:hover { background: var(--hover); border-color: var(--link); }
.nav-btn.disabled { opacity: 0.35; pointer-events: none; }
.nav-toc { color: var(--text-secondary); font-size: 14px; text-decoration: none; }
.nav-toc:hover { color: var(--link); }

/* === TOC Toggle (mobile) === */
.toc-toggle {
  display: none; position: fixed; left: 10px; bottom: 20px; z-index: 110;
  width: 44px; height: 44px; border-radius: 50%; background: var(--link);
  color: var(--bg); border: none; font-size: 20px; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.toc-overlay {
  display: none; position: fixed; inset: 0; z-index: 105;
  background: rgba(0,0,0,0.4);
}

/* === Responsive === */
@media (max-width: 1100px) {
  .toc-sidebar { transform: translateX(-100%); }
  .toc-sidebar.open { transform: translateX(0); }
  .reader-main { margin-left: 0; }
  .toc-toggle { display: flex; align-items: center; justify-content: center; }
  .toc-overlay.show { display: block; }
}
@media (max-width: 768px) {
  :root { --reader-width: 100%; }
  .reader-main { padding: 24px 16px 80px; }
  .chapter-title { font-size: 22px; }
  .reader-toolbar { gap: 8px; padding: 0 8px; }
  .toolbar-btn { padding: 4px 8px; font-size: 12px; }
}

/* === Back to Home Link === */
.back-home {
  position: fixed; top: 8px; right: 16px; z-index: 101;
  font-size: 13px; color: var(--text-secondary); text-decoration: none;
}
.back-home:hover { color: var(--link); }

/* === No-select on toolbar === */
.reader-toolbar, .toc-sidebar, .chapter-nav { user-select: none; }


/* === Audiobook / TTS === */
.tts-panel {
  display: none; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  background: var(--toolbar-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; min-width: 200px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 200; margin-top: 4px;
}
.tts-panel.show { display: block; }
.tts-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.tts-row:last-child { margin-bottom: 0; }
.tts-row label { color: var(--text-secondary); white-space: nowrap; font-size: 12px; }
.tts-row select { flex: 1; padding: 4px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); color: var(--text); font-size: 12px; }
.tts-row input[type=range] { flex: 1; }
.tts-row .tts-val { font-size: 11px; color: var(--text-secondary); min-width: 28px; text-align: right; }
.tts-btn-group { display: flex; gap: 6px; }
.tts-action { flex: 1; padding: 6px 12px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); color: var(--text); cursor: pointer; font-size: 13px; font-family: inherit; }
.tts-action:hover { background: var(--hover); }
.tts-action.primary { background: var(--link); color: var(--bg); border-color: var(--link); }
.tts-wrapper { position: relative; }