/* ===== CSS VARIABLES ===== */
:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface2: #f0ece4;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --border: #ddd8cf;
  --accent: #c0392b;
  --accent-rgb: 192,57,43;
  --accent2: #2980b9;
  --accent-hover: #a93226;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 10px;
  --reader-bg: #faf8f3;
  --reader-text: #2c2416;
  --highlight: #fff176;
  --highlight-active: #ffeb3b;
}

body.dark {
  --bg: #1a1a1a;
  --surface: #242424;
  --surface2: #2e2e2e;
  --text: #e8e0d0;
  --text-muted: #9a9a9a;
  --border: #3a3a3a;
  --accent: #e05252;
  --accent-rgb: 224,82,82;
  --accent2: #5b9bd5;
  --accent-hover: #c0392b;
  --shadow: 0 2px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --reader-bg: #1e1c18;
  --reader-text: #d4cbba;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Georgia', 'Times New Roman', serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
  overflow-x: hidden;
}

a { color: var(--accent2); text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }

/* ===== UTILITY ===== */
.hidden { display: none !important; }

/* ===== ICON BUTTONS ===== */
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }
#reader-mp3-btn { color: #1db954; }
#reader-mp3-btn:hover { color: #17a349; }
#reader-yt-btn  { color: #FF0000; }
#reader-yt-btn:hover  { color: #cc0000; }

body.light .moon-icon { display: block; }
body.light .sun-icon  { display: none;  }
body.dark  .sun-icon  { display: block; }
body.dark  .moon-icon { display: none;  }

/* ===== LIBRARY HEADER ===== */
.lib-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.lib-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.site-logo {
  height: 52px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}
.site-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  letter-spacing: -0.2px;
}
.site-name small {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0;
}

.lib-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lib-search-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  width: 260px;
  transition: border-color 0.2s;
}
.lib-search-wrap:focus-within { border-color: var(--accent); }
.lib-search-wrap svg { color: var(--text-muted); flex-shrink: 0; }
#search-library {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  flex: 1;
  min-width: 0;
  outline: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.ft-inline-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  transition: opacity 0.15s;
}
.ft-inline-btn:hover { opacity: 0.85; }

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  cursor: pointer;
  transition: background 0.15s;
}
.upload-btn:hover { background: var(--accent-hover); }

/* ===== HERO ===== */
.lib-main { padding: 40px 32px; max-width: 1200px; margin: 0 auto; }

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: 16px;
  padding: 48px 56px;
  margin-bottom: 40px;
  box-shadow: var(--shadow);
  gap: 32px;
}

.hero-text h1 {
  font-size: 36px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 12px;
}
.hero-text p {
  font-size: 16px;
  color: var(--text-muted);
  margin-bottom: 28px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.hero-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-size: 15px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.hero-upload-btn:hover { background: var(--accent-hover); transform: translateY(-1px); }

.hero-illustration svg { width: 200px; height: 160px; }

/* ===== DROP ZONE ===== */
.drop-zone {
  border: 2px dashed var(--accent);
  border-radius: 14px;
  padding: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 40px;
  background: var(--surface);
  transition: background 0.2s;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.drop-zone.drag-over { background: var(--surface2); }

/* ===== BOOKS SECTION ===== */
.books-section { }
.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.section-header h2 {
  font-size: 22px;
  font-weight: 700;
}
.count-badge {
  background: var(--accent);
  color: #fff;
  border-radius: 99px;
  padding: 2px 10px;
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 24px;
}

/* ===== BOOK CARD ===== */
.book-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}
.book-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }

.book-cover {
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.book-spine {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 12px;
  opacity: 0.7;
}

.book-cover-content {
  padding: 20px 20px 20px 28px;
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.book-icon {
  opacity: 0.6;
}

.book-cover-title {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
  line-height: 1.3;
  word-break: break-word;
  text-align: center;
}

.book-progress-ring {
  position: absolute;
  top: 8px;
  right: 8px;
}

.book-meta {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}
.book-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin-bottom: 4px;
}
.book-size {
  font-size: 11px;
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.book-links {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.book-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.book-link-btn:hover { opacity: 0.82; transform: translateY(-1px); }
.book-link-mp3 { background: #1db954; color: #fff; }
.book-link-yt  { background: #FF0000; color: #fff; }

.book-card-actions {
  position: absolute;
  top: 8px;
  left: 20px;
}
.delete-book-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s;
  border: none;
  cursor: pointer;
}
.book-card:hover .delete-book-btn { opacity: 1; }

/* ===== READER VIEW ===== */
#reader-view {
  position: fixed;
  inset: 0;
  display: flex;
  background: var(--reader-bg);
  z-index: 200;
}

/* ===== SIDEBAR ===== */
.reader-sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 50;
  box-shadow: var(--shadow-lg);
}
.reader-sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.toc-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 12px 0;
}
.toc-list li a {
  display: block;
  padding: 8px 20px;
  color: var(--text);
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  text-decoration: none;
}
.toc-list li a:hover { background: var(--surface2); border-left-color: var(--accent); }
.toc-list li.toc-h2 a { padding-left: 32px; font-size: 13px; color: var(--text-muted); }
.toc-list li.toc-h3 a { padding-left: 44px; font-size: 12px; color: var(--text-muted); }

/* ===== READER MAIN ===== */
.reader-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
}

.reader-topbar {
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}

.back-btn {
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
}
.back-btn:hover { background: rgba(192,57,43,0.1); color: var(--accent); }

.reader-title-text {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.reader-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}
#font-decrease, #font-increase {
  font-size: 13px;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  min-width: 36px;
  text-align: center;
}

/* ===== SEARCH BAR ===== */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 24px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#search-input {
  flex: 1;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
#search-input:focus { border-color: var(--accent); }
#search-results-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  min-width: 60px;
}

/* ===== PROGRESS BAR ===== */
.progress-bar-wrap {
  height: 3px;
  background: var(--border);
  flex-shrink: 0;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
  width: 0%;
}

/* ===== READER CONTENT ===== */
.reader-content {
  flex: 1;
  overflow-y: auto;
  padding: 48px 24px;
  scroll-behavior: smooth;
}

.reader-content-inner {
  max-width: 720px;
  margin: 0 auto;
  font-size: 18px;
  line-height: 1.85;
  color: var(--reader-text);
  word-break: break-word;
}

.reader-content-inner h1,
.reader-content-inner h2,
.reader-content-inner h3,
.reader-content-inner h4 {
  font-weight: 700;
  line-height: 1.3;
  margin: 1.6em 0 0.6em;
  color: var(--text);
}
.reader-content-inner h1 { font-size: 2em; border-bottom: 2px solid var(--border); padding-bottom: 0.3em; }
.reader-content-inner h2 { font-size: 1.5em; }
.reader-content-inner h3 { font-size: 1.25em; }
.reader-content-inner p  { margin: 0 0 1.2em; }
.reader-content-inner img { max-width: 100%; border-radius: 8px; margin: 16px 0; }
.reader-content-inner table { border-collapse: collapse; width: 100%; margin: 16px 0; font-size: 15px; }
.reader-content-inner th,
.reader-content-inner td { border: 1px solid var(--border); padding: 10px 14px; }
.reader-content-inner th { background: var(--surface2); font-weight: 600; }
.reader-content-inner ul,
.reader-content-inner ol { padding-left: 2em; margin: 0 0 1.2em; }
.reader-content-inner li { margin-bottom: 0.4em; }
.reader-content-inner blockquote {
  border-left: 4px solid var(--accent);
  margin: 1em 0;
  padding: 0.5em 1.2em;
  color: var(--text-muted);
  font-style: italic;
  background: var(--surface2);
  border-radius: 0 8px 8px 0;
}

/* Search highlights */
.reader-content-inner mark.search-hl {
  background: var(--highlight);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
.reader-content-inner mark.search-hl.active {
  background: var(--highlight-active);
  outline: 2px solid #f57f17;
}

/* ===== READER FOOTER ===== */
.reader-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.progress-text {
  font-size: 13px;
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.bookmark-btn {
  color: var(--text-muted);
  font-size: 13px;
}
.bookmark-btn.active {
  color: var(--accent);
}
.bookmark-btn.active svg { fill: var(--accent); stroke: var(--accent); }

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a1a;
  color: #fff;
  padding: 12px 24px;
  border-radius: 99px;
  font-size: 14px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: toast-in 0.3s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }

/* ===== FILTER BAR ===== */
.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 28px;
  padding: 18px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 160px;
}

.filter-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  transition: border-color 0.2s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}
.filter-select:focus { border-color: var(--accent); }

.clear-filters-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  align-self: flex-end;
}
.clear-filters-btn:hover { background: #fee; color: var(--accent); border-color: var(--accent); }

/* ── Full-text results ── */
.ft-results-section { margin-bottom: 24px; }
.ft-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}
.ft-results-label {
  font-size: 14px;
  color: var(--text-muted);
  font-family: sans-serif;
}
.ft-close-btn {
  font-size: 13px;
  gap: 5px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
}
.ft-close-btn:hover { color: var(--text); background: var(--surface2); }
.ft-results-grid {
  display: grid;
  gap: 16px;
}
.ft-result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  gap: 14px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.ft-result-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.ft-result-cover {
  width: 52px;
  height: 68px;
  border-radius: 6px;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ft-result-cover img { width: 100%; height: 100%; object-fit: cover; }
.ft-result-cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}
.ft-result-body { flex: 1; min-width: 0; }
.ft-result-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
  flex-wrap: wrap;
}
.ft-result-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ft-match-count {
  font-size: 11px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border-radius: 20px;
  padding: 2px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}
.ft-result-preacher {
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 8px;
  font-family: sans-serif;
}
.ft-result-snippets { display: flex; flex-direction: column; gap: 5px; }
.ft-snippet {
  font-size: 13px;
  color: var(--text-muted);
  font-family: sans-serif;
  line-height: 1.5;
  background: var(--surface2);
  border-left: 3px solid var(--accent);
  padding: 5px 8px;
  border-radius: 0 5px 5px 0;
}
.ft-snippet mark {
  background: rgba(var(--accent-rgb, 192,57,43), 0.18);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 2px;
  font-weight: 600;
}

/* Book card preacher/date badge */
.book-badge {
  position: absolute;
  bottom: 8px;
  left: 20px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.book-badge span {
  display: inline-block;
  background: rgba(0,0,0,0.45);
  color: #fff;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 99px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  backdrop-filter: blur(4px);
}

/* ===== TTS BAR ===== */
.tts-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.tts-bar.hidden { display: none; }

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

.tts-play-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  min-width: 110px;
  justify-content: center;
}
.tts-play-btn:hover { background: var(--accent-hover); transform: scale(1.02); }
.tts-play-btn.playing { background: #e67e22; }
.tts-play-btn.playing:hover { background: #ca6f1e; }

.tts-stop-btn { color: var(--text-muted); }
.tts-stop-btn:hover { color: var(--accent); background: #fee; }

.tts-meta {
  flex: 1;
  min-width: 120px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tts-progress-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.tts-progress {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.3s;
  width: 0%;
}

.tts-status {
  font-size: 11px;
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tts-settings {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.tts-setting-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.tts-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.tts-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  max-width: 160px;
}
.tts-select:focus { border-color: var(--accent); }

/* Currently-reading paragraph highlight */
.reader-content-inner .tts-reading {
  background: linear-gradient(135deg, rgba(192,57,43,0.08), rgba(41,128,185,0.06));
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin-left: -15px;
  border-radius: 0 6px 6px 0;
  animation: tts-pulse 2s ease-in-out infinite;
  transition: background 0.3s;
}
@keyframes tts-pulse {
  0%, 100% { background: linear-gradient(135deg, rgba(192,57,43,0.08), rgba(41,128,185,0.06)); }
  50%       { background: linear-gradient(135deg, rgba(192,57,43,0.14), rgba(41,128,185,0.10)); }
}

/* TTS active indicator on the button */
#tts-btn.active { color: var(--accent); }

/* Word-level highlight box (positioned absolutely over current spoken word) */
.tts-word-box {
  position: absolute;
  display: none;
  background: rgba(255, 200, 0, 0.45);
  border-radius: 3px;
  pointer-events: none;
  z-index: 200;
  transition: left 0.05s, top 0.05s, width 0.05s;
}

/* ===== BOOK COVER IMAGE ===== */
.book-cover img.cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ===== HIGHLIGHT TOOLBAR ===== */
.hl-toolbar {
  position: fixed;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 6px 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  transition: opacity 0.15s;
}
.hl-toolbar.hidden { display: none; }

.hl-color {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
  padding: 0;
}
.hl-color:hover { transform: scale(1.2); border-color: rgba(0,0,0,0.2); }

.hl-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 2px;
}

.hl-erase {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  padding: 0;
}
.hl-erase:hover { background: #fee; color: var(--accent); }

/* User highlight marks */
.reader-content-inner mark.user-hl {
  border-radius: 2px;
  padding: 1px 0;
  cursor: pointer;
}
.reader-content-inner mark.user-hl.hl-yellow { background: #FFE066; color: inherit; }
.reader-content-inner mark.user-hl.hl-green  { background: #B9F5C2; color: inherit; }
.reader-content-inner mark.user-hl.hl-blue   { background: #BDE3FF; color: inherit; }
.reader-content-inner mark.user-hl.hl-pink   { background: #FFB3C6; color: inherit; }
.reader-content-inner mark.user-hl.hl-orange { background: #FFD6A5; color: inherit; }

body.dark .reader-content-inner mark.user-hl.hl-yellow { background: #7a6500; color: #fff; }
body.dark .reader-content-inner mark.user-hl.hl-green  { background: #1a5c26; color: #fff; }
body.dark .reader-content-inner mark.user-hl.hl-blue   { background: #0d3d6b; color: #fff; }
body.dark .reader-content-inner mark.user-hl.hl-pink   { background: #7a1f35; color: #fff; }
body.dark .reader-content-inner mark.user-hl.hl-orange { background: #7a4200; color: #fff; }

/* ===== SHARE MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-overlay.hidden { display: none; }

.share-modal-box {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
  overflow: hidden;
}

.share-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 16px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.share-book-title {
  font-size: 14px;
  color: var(--text-muted);
  padding: 12px 24px 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-style: italic;
}

.share-platforms {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 20px 24px 24px;
}

.share-platform {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
  text-align: center;
}
.share-platform svg { width: 28px; height: 28px; }
.share-platform:hover { background: var(--bg); transform: translateY(-2px); border-color: var(--accent); }

.share-platform:nth-child(1) { color: #25D366; }
.share-platform:nth-child(2) { color: #0088cc; }
.share-platform:nth-child(3) { color: #1877F2; }
.share-platform:nth-child(4) { color: #000; }
.share-platform:nth-child(5) { color: #0A66C2; }
.share-platform:nth-child(6) { color: var(--accent); }
.share-copy-btn { color: var(--text-muted); border: none; background: var(--surface2); font-family: inherit; }
.share-copy-btn.copied { color: #27ae60; border-color: #27ae60; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .lib-header { padding: 0 16px; }
  .site-name { display: none; }
  .site-logo { height: 42px; }
  .lib-search-wrap { width: 220px; }
  .ft-inline-btn span, .ft-inline-btn { font-size: 11px; padding: 5px 7px; }
  .lib-main { padding: 24px 16px; }
  .hero { flex-direction: column; padding: 32px 24px; text-align: center; }
  .hero-illustration { display: none; }
  .hero-text h1 { font-size: 26px; }
  .books-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
  .reader-topbar { padding: 0 8px; height: 48px; gap: 2px; }
  .reader-content { padding: 32px 16px; }
  .reader-content-inner { font-size: 16px; }
  .reader-title-text { font-size: 12px; }
  .reader-sidebar { width: 260px; }
  /* Smaller icon buttons in the reader topbar */
  .reader-topbar .icon-btn { padding: 5px 6px; }
  .reader-topbar .icon-btn svg { width: 16px; height: 16px; }
  /* Shrink the back button label */
  .back-btn { font-size: 12px; padding: 5px 7px; }
  /* Shrink font-size buttons */
  #font-decrease, #font-increase { min-width: 28px; font-size: 12px; }
  /* Reduce gap between controls */
  .reader-controls { gap: 0; }
}

@media (max-width: 480px) {
  .lib-search-wrap { width: 160px; }
  .ft-inline-btn { font-size: 0; padding: 5px 7px; gap: 0; }
  .ft-inline-btn svg { width: 15px; height: 15px; }
  .books-grid { grid-template-columns: repeat(2, 1fr); }
  /* On very small screens hide the book title — save every pixel for buttons */
  .reader-title-text { display: none; }
  .reader-topbar { gap: 1px; padding: 0 6px; }
  .reader-topbar .icon-btn { padding: 5px 5px; }
}
