/* Reader - main styles */
:root {
  --bg: #1a1a2e;
  --fg: #eaeaea;
  --accent: #0f3460;
  --card: #16213e;
  --font-size: 1.05rem;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: var(--font-size);
  line-height: 1.7;
  padding: 0 1rem 5rem;
  -webkit-tap-highlight-color: transparent;
}
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 0.75rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.header h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: var(--card); }
.nav-row {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  padding: 1rem 0;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 0.75rem 1rem;
}
.chapter-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 1rem 0 1.5rem;
  text-align: center;
}
.content {
  white-space: pre-line;
  word-wrap: break-word;
  max-width: 42em;
  margin: 0 auto;
}
.loading, .error { text-align: center; padding: 2rem; color: #888; }
.error { color: #e57373; }
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  max-width: 320px;
  height: 100%;
  background: var(--card);
  padding: 1.25rem;
  box-shadow: -4px 0 20px rgba(0,0,0,0.3);
  z-index: 20;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  overflow-y: auto;
}
.settings-panel.open { transform: translateX(0); }
.settings-panel h3 { margin: 0 0 1rem; font-size: 1rem; }
.settings-panel label { display: block; margin-bottom: 0.5rem; font-size: 0.9rem; }
.settings-panel .row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.settings-panel .color-swatch {
  width: 40px; height: 40px; border-radius: 8px; cursor: pointer;
  border: 2px solid transparent;
}
.settings-panel .color-swatch.active { border-color: #fff; }
.settings-panel .font-size-btn {
  padding: 0.5rem 0.75rem; border-radius: 6px; background: var(--accent);
  color: #fff; border: none; cursor: pointer; font-size: 0.9rem;
}
.settings-panel .rate-btn.active { border: 2px solid #fff; box-sizing: border-box; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 15; display: none; }
.overlay.open { display: block; }
#audioStatus { font-size: 0.85rem; color: #888; margin-left: 0.25rem; }
#btnAudio.playing { background: #2d5a3d; }
.audio-controls {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.6rem 1rem;
  background: var(--card);
  border-top: 1px solid rgba(255,255,255,0.12);
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.3);
}
.audio-controls .seek-wrap { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0; }
.audio-controls .seek-wrap input[type="range"] {
  flex: 1; min-width: 100px; height: 28px; cursor: pointer;
  -webkit-appearance: none; appearance: none;
  background: transparent;
}
.audio-controls .seek-wrap input[type="range"]::-webkit-slider-runnable-track {
  height: 8px; background: rgba(255,255,255,0.2); border-radius: 4px;
}
.audio-controls .seek-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent, #3b82f6); margin-top: -5px; cursor: grab;
}
.audio-controls .seek-wrap input[type="range"]::-moz-range-track {
  height: 8px; background: rgba(255,255,255,0.2); border-radius: 4px;
}
.audio-controls .seek-wrap input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: var(--accent, #3b82f6); cursor: grab; border: none;
}
.audio-controls .time { font-size: 0.8rem; color: #ccc; white-space: nowrap; min-width: 5rem; }
.audio-controls .audio-speed-btn.active { border: 2px solid #fff; box-sizing: border-box; }
.audio-progress-label { font-size: 0.8rem; color: #aaa; white-space: nowrap; }
body.audio-controls-visible { padding-bottom: 90px; }
#bookList { padding: 1rem 0; }
#bookList a, #bookList .book-card { display: block; padding: 0.85rem 1rem; margin: 0.5rem 0; background: var(--card); border-radius: 10px; color: var(--fg); text-decoration: none; font-size: 1rem; border: 1px solid rgba(255,255,255,0.08); }
#bookList a:hover, #bookList a:active, #bookList .book-card:hover { background: var(--accent); }
#bookList .continue-card { background: linear-gradient(135deg, var(--accent) 0%, #1a3a52 100%); margin-bottom: 1rem; }
#bookList .home-title { font-size: 1.25rem; margin: 0 0 1rem; font-weight: 600; }
#bookList .section-label { font-size: 0.85rem; color: #888; margin: 1rem 0 0.5rem; }
#bookInfoPage { display: none; padding: 1rem 0; max-width: 42em; margin: 0 auto; }
#bookInfoPage .info-title { font-size: 1.35rem; margin: 0 0 0.5rem; font-weight: 600; }
#bookInfoPage .info-meta { font-size: 0.9rem; color: #888; margin-bottom: 1rem; }
#bookInfoPage .info-desc { white-space: pre-line; line-height: 1.6; margin-bottom: 1.5rem; color: #ccc; }
#bookInfoPage .info-stats { font-size: 0.9rem; color: #888; margin-bottom: 1.5rem; }
#bookInfoPage .info-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
#bookInfoPage .info-chapters { margin-top: 1rem; max-height: 40vh; overflow-y: auto; }
#bookInfoPage .info-latest-chapters { margin-top: 1rem; margin-bottom: 1rem; }
#bookInfoPage .info-latest-chapters .section-label { margin-bottom: 0.5rem; }
#bookInfoPage .chapters-pagination { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; font-size: 0.9rem; }
#bookInfoPage .chapters-pagination .btn { min-width: auto; padding: 0.4rem 0.75rem; }
.chapters-panel { position: fixed; top: 0; left: 0; width: 100%; max-width: 320px; height: 100%; background: var(--card); padding: 1rem; box-shadow: 4px 0 20px rgba(0,0,0,0.3); z-index: 20; transform: translateX(-100%); transition: transform 0.2s ease; overflow-y: auto; }
.chapters-panel.open { transform: translateX(0); }
.chapters-panel h3 { margin: 0 0 1rem; font-size: 1rem; }
.chapters-panel .ch-item { display: block; padding: 0.6rem 0.75rem; margin: 0.25rem 0; border-radius: 8px; color: var(--fg); text-decoration: none; font-size: 0.9rem; border: none; background: transparent; width: 100%; text-align: left; cursor: pointer; }
.chapters-panel .ch-item:hover, .chapters-panel .ch-item:active { background: rgba(255,255,255,0.08); }
.chapters-panel .ch-item.current { background: var(--accent); color: #fff; }
.chapters-panel .panel-pagination { margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid rgba(255,255,255,0.1); display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; font-size: 0.9rem; }
.chapters-panel .panel-pagination .btn { min-width: auto; padding: 0.4rem 0.75rem; }
@media (max-width: 640px) {
  body { padding: 0 0.75rem 5rem; font-size: 1rem; }
  .header h1 { font-size: 0.95rem; max-width: 50vw; }
  .nav-row { padding: 0.75rem 0.5rem; gap: 0.5rem; flex-wrap: wrap; padding-bottom: max(0.75rem, env(safe-area-inset-bottom)); }
  .nav-row .btn { flex: 1; min-width: 100px; }
  .content { font-size: 1.05rem; }
  .chapter-title { font-size: 1.15rem; margin: 0.75rem 0 1rem; }
}
