/* ===== CSS Variables & Themes ===== */
:root {
  --bg: #0e0e0f;
  --bg2: #161618;
  --bg3: #1e1e21;
  --border: #2a2a2e;
  --text: #e8e4dd;
  --text-muted: #7a7875;
  --text-dim: #4a4845;
  --accent: #c8a96e;
  --accent2: #8b6914;
  --accent-glow: rgba(200, 169, 110, 0.15);
  --red: #e05c5c;
  --font-size: 18px;
  --line-height: 1.8;
  --col-width: 680px;
  --radius: 6px;
  --transition: 0.2s ease;
}

[data-theme="sepia"] {
  --bg: #1a1510;
  --bg2: #221c14;
  --bg3: #2a241a;
  --border: #362e22;
  --text: #e8dcc8;
  --text-muted: #8a7860;
  --accent: #d4a060;
}

[data-theme="light"] {
  --bg: #f5f0e8;
  --bg2: #ede8df;
  --bg3: #e5dfd4;
  --border: #cdc7bc;
  --text: #1a1814;
  --text-muted: #6a6560;
  --text-dim: #b0aaa4;
  --accent: #8b5e0a;
  --accent-glow: rgba(139, 94, 10, 0.1);
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Source Serif 4', Georgia, serif;
  -webkit-font-smoothing: antialiased;
}

/* ===== Screens ===== */
.screen {
  position: fixed;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.screen.active {
  opacity: 1;
  pointer-events: all;
}

/* ===== Upload Screen ===== */
#upload-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.upload-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-lines {
  position: absolute;
  inset: -50%;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 60px,
      rgba(255,255,255,0.02) 60px,
      rgba(255,255,255,0.02) 61px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 60px,
      rgba(255,255,255,0.02) 60px,
      rgba(255,255,255,0.02) 61px
    );
}

.upload-container {
  position: relative;
  width: 100%;
  max-width: 480px;
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-mark {
  width: 48px;
  height: 48px;
  background: var(--accent);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}
.logo-mark svg {
  width: 32px;
  height: 32px;
  display: block;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-title {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

.logo-sub {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 4px;
}

.upload-zone {
  width: 100%;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  padding: 56px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--bg2);
  position: relative;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.upload-zone.drag-over {
  transform: scale(1.01);
}

.upload-icon {
  width: 48px;
  height: 48px;
  color: var(--accent);
  margin-bottom: 8px;
}

.upload-icon svg { width: 100%; height: 100%; }

.upload-label {
  font-family: 'Playfair Display', serif;
  font-size: 18px;
  color: var(--text);
}

.upload-hint {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

/* Loading */
.upload-loading {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.loading-bar {
  width: 100%;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.loading-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
}

.loading-text {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

/* Recent Files */
.recent-files { width: 100%; }

.recent-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.recent-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 6px;
  transition: background 0.2s, border-color 0.2s;
}

.recent-item:hover { background: var(--bg3); border-color: var(--accent); }

.recent-icon {
  width: 28px;
  height: 34px;
  background: var(--accent);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 8px;
  font-weight: 500;
  color: var(--bg);
  letter-spacing: 0.5px;
}

.recent-info { flex: 1; min-width: 0; }

.recent-name {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.recent-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
}

.recent-progress {
  width: 40px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.recent-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

/* ===== Reader Screen ===== */
#reader-screen {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* Header */
.reader-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.header-title {
  flex: 1;
  font-family: 'Playfair Display', serif;
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Progress bar */
.reading-progress {
  height: 2px;
  background: var(--border);
  flex-shrink: 0;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease;
  width: 0%;
}

/* Main Text Area */
.reader-main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  padding: 48px 24px 32px;
  scroll-behavior: smooth;
}

.reader-main::-webkit-scrollbar { width: 4px; }
.reader-main::-webkit-scrollbar-track { background: transparent; }
.reader-main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.text-column {
  width: 100%;
  max-width: var(--col-width);
}

.page-indicator {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 32px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-indicator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.reading-text {
  font-size: var(--font-size);
  line-height: var(--line-height);
  color: var(--text);
  font-family: 'Source Serif 4', Georgia, serif;
  font-weight: 300;
}

.reading-text p {
  margin-bottom: 1.4em;
}

/* Animated word highlight while "reading" */
.word {
  display: inline;
  transition: color 0.1s;
}

.word.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-radius: 2px;
  padding: 0 1px;
}

.word.read {
  color: var(--text-muted);
}

.page-end-marker {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 40px;
  margin-bottom: 20px;
}

.end-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.end-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* ===== Footer Controls ===== */
.reader-footer {
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 72px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
  gap: 16px;
  position: relative;
}

.reader-footer .play-controls {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

/* Push the right-side cluster (audio + mode + speed) to the right edge. */
.reader-footer .audio-controls {
  margin-left: auto;
}

.footer-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Buttons */
.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon svg { width: 18px; height: 18px; }
.btn-icon:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }

.btn-ctrl {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-ctrl svg { width: 16px; height: 16px; }
.btn-ctrl:hover { border-color: var(--accent); color: var(--accent); }
.btn-ctrl:disabled { opacity: 0.3; cursor: not-allowed; }

.btn-play {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-play:hover { transform: scale(1.05); box-shadow: 0 0 30px var(--accent-glow); }
.btn-play svg { width: 18px; height: 18px; }
.btn-play.playing { background: var(--bg3); color: var(--accent); border: 2px solid var(--accent); }
.btn-play .icon-pause { display: none; }
.btn-play.playing .icon-play { display: none; }
.btn-play.playing .icon-pause { display: block; }

/* Page Input */
.page-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: var(--text);
}

#page-input {
  width: 44px;
  height: 32px;
  text-align: center;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  padding: 0 6px;
  outline: none;
  transition: border-color var(--transition);
}

#page-input:focus { border-color: var(--accent); }
#page-input::-webkit-inner-spin-button { -webkit-appearance: none; }

.page-sep { color: var(--text-dim); }
#total-pages { color: var(--text-muted); }

/* Speed Controls */
.speed-controls {
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}

.speed-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.speed-track {
  position: relative;
  width: 100px;
}

#speed-slider {
  width: 100%;
  -webkit-appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

#speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-glow);
}

.speed-value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 0.5px;
  min-width: 52px;
  text-align: right;
}

/* ===== Settings Panel ===== */
.settings-panel {
  position: fixed;
  top: 57px;
  right: 0;
  width: 280px;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-bottom-left-radius: 12px;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 100;
  box-shadow: -8px 8px 32px rgba(0,0,0,0.4);
}

.settings-panel.open { transform: translateX(0); }

.settings-inner { padding: 24px; }

.settings-inner h3 {
  font-family: 'Playfair Display', serif;
  font-size: 16px;
  color: var(--text);
  margin-bottom: 20px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child { border-bottom: none; }

.setting-row label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.setting-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.setting-control span {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--text);
  min-width: 40px;
  text-align: center;
}

.btn-sm {
  padding: 4px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-sm:hover { border-color: var(--accent); color: var(--accent); }

.theme-btns { gap: 6px; }

.btn-theme {
  padding: 5px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-theme:hover { border-color: var(--accent); color: var(--accent); }
.btn-theme.active { background: var(--accent); color: var(--bg); border-color: var(--accent); }

/* Toggle */
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.toggle input { display: none; }

.toggle-track {
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  position: relative;
  transition: background 0.2s;
}

.toggle-track::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }

.toggle-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
}

.setting-row-stack {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.setting-row-stack label {
  margin-bottom: 2px;
}

.voice-select {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  cursor: pointer;
  outline: none;
}

.voice-select:focus { border-color: var(--accent); }

/* Audio controls cluster (speaker toggle + volume + AI pill) */
.audio-controls {
  gap: 8px;
}

.btn-audio-toggle,
.btn-ai-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.btn-audio-toggle:hover,
.btn-ai-toggle:hover { color: var(--accent); border-color: var(--accent); }
.btn-audio-toggle input,
.btn-ai-toggle input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}
.btn-audio-toggle svg { width: 16px; height: 16px; }

/* Speaker toggle: show "on" when checked, "off" when not */
.btn-audio-toggle .icon-speaker-on { display: none; }
.btn-audio-toggle .icon-speaker-off { display: block; }
.btn-audio-toggle:has(input:checked) .icon-speaker-on { display: block; }
.btn-audio-toggle:has(input:checked) .icon-speaker-off { display: none; }
.btn-audio-toggle:has(input:checked) {
  color: var(--accent);
  border-color: var(--accent);
}

/* AI pill: prominent label that lights up gold when Kokoro is on */
.ai-control {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  position: relative;
}

.btn-ai-toggle {
  width: auto;
  padding: 0 12px;
  height: 32px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 1.5px;
  font-weight: 500;
}

.btn-ai-toggle .ai-label {
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-ai-toggle .ai-label::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.2s, box-shadow 0.2s;
}

.btn-ai-toggle:has(input:checked) {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.btn-ai-toggle:has(input:checked) .ai-label::before {
  background: var(--bg);
  box-shadow: 0 0 4px var(--bg);
}

/* Info button next to the AI toggle */
.btn-ai-info {
  width: 18px;
  height: 18px;
  border: 1px solid var(--text-dim);
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: help;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color var(--transition), border-color var(--transition);
}

.btn-ai-info svg { width: 12px; height: 12px; }
.btn-ai-info:hover,
.btn-ai-info:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  outline: none;
}

.btn-ai-info:hover .ai-info-tooltip,
.btn-ai-info:focus-visible .ai-info-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.ai-info-tooltip {
  position: absolute;
  bottom: calc(100% + 14px);
  right: -4px;
  width: 280px;
  padding: 12px 14px;
  background: var(--bg3);
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 12.5px;
  font-weight: 300;
  line-height: 1.5;
  color: var(--text);
  text-align: left;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
  z-index: 200;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  cursor: default;
}

.ai-info-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  right: 8px;
  border: 6px solid transparent;
  border-top-color: var(--accent);
}

.ai-info-tooltip strong {
  display: block;
  color: var(--accent);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 6px;
  font-weight: 500;
}

.ai-info-tooltip em {
  font-style: italic;
  color: var(--accent);
}

.ai-info-meta {
  display: block;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  line-height: 1.5;
}

#volume-slider {
  width: 90px;
  -webkit-appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 6px var(--accent-glow);
}

#volume-val {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  min-width: 32px;
  text-align: right;
}

/* Dim the volume slider + value when voice is disabled */
.audio-controls:has(#tts-toggle:not(:checked)) #volume-slider,
.audio-controls:has(#tts-toggle:not(:checked)) #volume-val {
  opacity: 0.35;
  pointer-events: none;
}

.show-all-voices {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  cursor: pointer;
  margin-top: 2px;
}
.show-all-voices input { margin: 0; cursor: pointer; }

.voice-tip {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  line-height: 1.5;
  color: var(--text-muted);
  margin-top: 4px;
}
.voice-tip strong { color: var(--accent); font-weight: 500; }

.kokoro-progress {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.kokoro-progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.kokoro-progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0;
  transition: width 0.3s ease;
}

.kokoro-progress-text {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
}

/* ===== Kokoro loading banner (global) ===== */
.kokoro-banner {
  background: linear-gradient(to right, var(--accent-glow), transparent 70%);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  animation: kokoro-banner-in 0.3s ease;
}

.kokoro-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 24px;
  max-width: 100%;
}

.kokoro-banner-spinner {
  width: 14px;
  height: 14px;
  color: var(--accent);
  animation: kokoro-spin 1s linear infinite;
  flex-shrink: 0;
}

.kokoro-banner-text {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.5px;
  color: var(--accent);
  flex-shrink: 0;
}

.kokoro-banner-bar {
  flex: 1;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  overflow: hidden;
  max-width: 240px;
}

.kokoro-banner-fill {
  height: 100%;
  background: var(--accent);
  width: 0;
  transition: width 0.3s ease;
}

@keyframes kokoro-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes kokoro-banner-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Settings icon prominence ===== */
.reader-header .btn-icon#settings-btn {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-glow);
}

.reader-header .btn-icon#settings-btn:hover {
  background: var(--accent);
  color: var(--bg);
  transform: rotate(20deg);
}

.reader-header .btn-icon#settings-btn svg {
  transition: transform 0.3s ease;
}

/* Speed slider state when Kokoro is on (Kokoro renders at its own pace) */
.speed-controls.disabled {
  display: none;
}

/* ===== Utility ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.3s ease forwards; }

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.reading-cursor::after {
  content: '|';
  color: var(--accent);
  animation: cursor-blink 1s infinite;
  margin-left: 2px;
}

/* ===== Headings (in reading text) ===== */
.reading-text .heading {
  font-family: 'Playfair Display', serif;
  color: var(--accent);
  font-weight: 600;
  line-height: 1.3;
  margin: 1.6em 0 0.6em;
  letter-spacing: 0.2px;
}
.reading-text .heading-l1 { font-size: 1.5em; }
.reading-text .heading-l2 { font-size: 1.25em; color: var(--text); }
.reading-text .heading-l3 { font-size: 1.1em; color: var(--text); }
.reading-text .heading-l4 { font-size: 1em; color: var(--text-muted); }
.reading-text .heading .word.active { color: var(--bg); background: var(--accent); }
.reading-text .empty-page {
  color: var(--text-muted);
  font-style: italic;
}

/* ===== Sentence mode ===== */
.sentence {
  display: inline;
  transition: color 0.2s, background 0.2s;
  border-radius: 3px;
}
.reading-text.sentence-mode .word.active { background: transparent; color: inherit; padding: 0; }
.reading-text.sentence-mode .sentence.active {
  color: var(--accent);
  background: var(--accent-glow);
  padding: 2px 4px;
  box-shadow: 0 0 0 1px var(--accent-glow);
}
.reading-text.sentence-mode .sentence.read { color: var(--text-muted); }

/* ===== Reading Stats ===== */
.reading-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
}
.reading-stats .stat { display: inline-flex; align-items: center; gap: 4px; }
.reading-stats .stat-label {
  text-transform: uppercase;
  color: var(--text-dim);
  font-size: 9px;
  letter-spacing: 1px;
}
.reading-stats .stat-val { color: var(--text); }
.reading-stats .stat-sep { color: var(--text-dim); }

/* ===== Search Bar ===== */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 0;
  background: var(--bg2);
  border-bottom: 1px solid transparent;
  overflow: hidden;
  transition: height 0.2s ease, border-color 0.2s ease;
  flex-shrink: 0;
}
.search-bar.open {
  height: 48px;
  border-bottom-color: var(--border);
}
.search-icon {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
}
#search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 15px;
}
#search-input::placeholder { color: var(--text-dim); }
.search-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  min-width: 50px;
  text-align: right;
}
.btn-icon-sm {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-icon-sm svg { width: 14px; height: 14px; }
.btn-icon-sm:hover { color: var(--accent); border-color: var(--accent); }

.word.search-hit {
  background: rgba(255, 215, 0, 0.15);
  border-radius: 2px;
  color: var(--text);
}
.word.search-hit-active {
  background: var(--accent);
  color: var(--bg);
  padding: 0 2px;
}


/* ===== TOC Sidebar ===== */
.toc-panel {
  position: fixed;
  top: 57px;
  left: 0;
  bottom: 72px;
  width: 320px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-shadow: 8px 0 32px rgba(0,0,0,0.4);
}
.toc-panel.open { transform: translateX(0); }

.toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.toc-header h3 {
  font-family: 'Playfair Display', serif;
  font-size: 16px;
  color: var(--text);
  font-weight: 600;
}

.toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.toc-list::-webkit-scrollbar { width: 4px; }
.toc-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.toc-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 20px;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.toc-item:hover { background: var(--bg3); color: var(--accent); }
.toc-item.active {
  background: var(--accent-glow);
  border-left-color: var(--accent);
  color: var(--accent);
}
.toc-text {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 14px;
  color: inherit;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.toc-page {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.toc-l1 .toc-text { font-weight: 600; font-family: 'Playfair Display', serif; font-size: 15px; }
.toc-l2 { padding-left: 32px; }
.toc-l2 .toc-text { font-size: 13px; }
.toc-l3 { padding-left: 44px; }
.toc-l3 .toc-text { font-size: 13px; color: var(--text-muted); }
.toc-l4 { padding-left: 56px; }
.toc-l4 .toc-text { font-size: 12px; color: var(--text-muted); }

.toc-empty, .notes-empty {
  padding: 20px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.6;
  font-style: italic;
}

/* ===== Notes Panel ===== */
.notes-panel {
  position: fixed;
  top: 57px;
  right: 0;
  bottom: 72px;
  width: 340px;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}
.notes-panel.open { transform: translateX(0); }

.notes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.notes-header h3 {
  font-family: 'Playfair Display', serif;
  font-size: 16px;
  color: var(--text);
  font-weight: 600;
}

.notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}
.notes-list::-webkit-scrollbar { width: 4px; }
.notes-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.note-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
  transition: border-color 0.2s;
}
.note-item:hover { border-color: var(--accent); }
.note-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.note-page {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
}
.note-page:hover { text-decoration: underline; }
.note-delete {
  width: 20px;
  height: 20px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  border-radius: 3px;
}
.note-delete:hover { color: var(--red); background: var(--bg2); }
.note-body {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}

.notes-footer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.notes-footer .btn-sm { flex: 1; }
.notes-footer.disabled .btn-sm {
  opacity: 0.4;
  pointer-events: none;
}

/* ===== Selection menu ===== */
.selection-menu {
  position: fixed;
  background: var(--bg3);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 200;
  transform: translate(-50%, -100%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.selection-menu.open {
  opacity: 1;
  pointer-events: all;
}
.selection-menu button {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.5px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 3px;
}
.selection-menu button:hover { background: var(--accent-glow); color: var(--accent); }
.selection-menu svg { width: 14px; height: 14px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--accent);
  color: var(--bg);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.5px;
  padding: 8px 16px;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 300;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Footer responsive ===== */
.reader-footer { gap: 12px; }
/* Responsive footer */
@media (max-width: 1100px) {
  .reading-stats { display: none; }
  #volume-val { display: none; }
  #volume-slider { width: 70px; }
}

@media (max-width: 900px) {
  .speed-controls { display: none; }
  #volume-slider { width: 60px; }
}

@media (max-width: 600px) {
  .reader-footer { gap: 8px; padding: 0 12px; }
  #volume-slider { display: none; }
  .audio-controls { gap: 4px; }
  .header-controls { gap: 4px; }
  .btn-ai-toggle { padding: 0 10px; font-size: 10px; }
}

/* Show the AI info tooltip when its panel has the "open" class (for click-to-toggle on touch) */
.btn-ai-info.open .ai-info-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* First-visit attention pulse on the info button + tooltip */
.btn-ai-info.attention {
  color: var(--accent);
  border-color: var(--accent);
  animation: ai-info-pulse 1.6s ease-out infinite;
}

@keyframes ai-info-pulse {
  0%   { box-shadow: 0 0 0 0 var(--accent); }
  70%  { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.btn-ai-info.attention .ai-info-tooltip {
  border-color: var(--accent);
  animation: ai-tip-glow 2.4s ease-in-out infinite;
}

@keyframes ai-tip-glow {
  0%, 100% { box-shadow: 0 6px 24px rgba(0,0,0,0.5), 0 0 0 0 var(--accent-glow); }
  50%      { box-shadow: 0 6px 24px rgba(0,0,0,0.5), 0 0 16px 2px var(--accent-glow); }
}

/* ============================================================
   SEO content on the upload screen
   ============================================================ */

.upload-container { max-width: 680px; }

.seo-content {
  width: 100%;
  margin-top: 24px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 15px;
  line-height: 1.6;
  text-align: left;
}

.seo-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 600;
  font-size: 22px;
  line-height: 1.3;
  color: var(--text);
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}

.seo-h2 {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 600;
  font-size: 17px;
  color: var(--text);
  margin: 24px 0 8px;
  letter-spacing: -0.005em;
}

.seo-lede { margin: 0 0 18px; color: var(--text-muted); }

.seo-features, .seo-steps {
  margin: 0 0 18px;
  padding-left: 18px;
}
.seo-features { list-style: none; padding-left: 0; }
.seo-features li {
  position: relative;
  padding: 6px 0 6px 18px;
  border-bottom: 1px solid var(--border);
}
.seo-features li:last-child { border-bottom: 0; }
.seo-features li::before {
  content: "";
  position: absolute;
  left: 0; top: 14px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.7;
}
.seo-features strong, .seo-content strong { color: var(--text); font-weight: 500; }
.seo-steps li { padding: 3px 0; }

.seo-footer-note {
  margin-top: 22px;
  font-size: 13px;
  color: var(--text-dim);
}

/* ============================================================
   Ad slot (Google AdSense)
   ============================================================ */

.ad-slot {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  padding: 10px 12px 12px;
  position: relative;
  overflow: hidden;
  min-height: 90px;
}

.ad-slot[hidden] { display: none !important; }

.ad-label {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
  opacity: 0.6;
}

.ad-slot .adsbygoogle { display: block; min-height: 70px; }

/* Make absolutely sure no ads ever appear in the reader. */
#reader-screen .ad-slot,
#reader-screen .adsbygoogle { display: none !important; }

/* ============================================================
   Cookie consent banner
   ============================================================ */

.consent-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 9999;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.4);
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
}

.consent-banner[hidden] { display: none !important; }

.consent-text { margin: 0; }

.consent-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.consent-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.consent-btn:hover { color: var(--text); border-color: var(--accent); }

.consent-btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.consent-btn-primary:hover { color: var(--bg); opacity: 0.9; }

@media (max-width: 600px) {
  .seo-content { font-size: 14px; }
  .seo-title { font-size: 19px; }
  .seo-h2 { font-size: 15px; }
}

