/* God Is Water - Enhanced Standalone HTML Book Styling */
/* Beautiful reading experience with dark mode, customizable width, and mobile-responsive */

:root {
  /* Light mode colors (default) */
  --book-bg: #faf8f3;
  --text-color: #2c2c2c;
  --heading-color: #1a1a1a;
  --accent-color: #2563eb;
  --link-color: #1e40af;
  --border-color: #e5e5e5;
  --code-bg: #f5f5f5;
  --quote-bg: rgba(0,0,0,0.02);
  --quote-border: #cbd5e1;
  --toc-bg: #ffffff;
  --control-bg: #ffffff;
  --control-border: #d1d5db;
  --control-shadow: rgba(0,0,0,0.1);
  --control-bg-soft: rgba(255,255,255,0.72);
  --control-bg-solid: rgba(255,255,255,0.96);

  /* Width presets */
  --width-narrow: 38rem;
  --width-medium: 42rem;
  --width-wide: 52rem;
  --width-full: 90%;

  /* Default width */
  --content-width: var(--width-medium);

  /* Font family presets */
  --font-noto-serif: "Noto Serif", "DejaVu Serif", "Liberation Serif", Georgia, serif;
  --font-gentium: "Gentium Book Plus", "Gentium Plus", "DejaVu Serif", Georgia, serif;
  --font-dejavu: "DejaVu Serif", "Liberation Serif", Georgia, serif;
  --font-eb-garamond: "EB Garamond", "Gentium Plus", Georgia, serif;
  --font-libre-baskerville: "Libre Baskerville", Georgia, serif;
  --font-crimson: "Crimson Pro", "Crimson Text", Georgia, serif;
  --font-merriweather: "Merriweather", Georgia, serif;
  --font-source-serif: "Source Serif Pro", Georgia, serif;
  --font-noto-sans: "Noto Sans", "DejaVu Sans", Arial, sans-serif;

  /* Default font selection */
  --body-font: var(--font-noto-serif);

  /* Typography customization */
  --font-scale: 1.0;
  --base-line-height: 1.7;
  --base-letter-spacing: 0em;
}

/* Screen-reader only utility */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Dark mode colors */
[data-theme="dark"] {
  --book-bg: #1a1a1a;
  --text-color: #e5e5e5;
  --heading-color: #f5f5f5;
  --accent-color: #60a5fa;
  --link-color: #93c5fd;
  --border-color: #374151;
  --code-bg: #2d2d2d;
  --quote-bg: rgba(255,255,255,0.05);
  --quote-border: #4b5563;
  --toc-bg: #262626;
  --control-bg: #262626;
  --control-border: #374151;
  --control-shadow: rgba(0,0,0,0.3);
  --control-bg-soft: rgba(38,38,38,0.55);
  --control-bg-solid: rgba(38,38,38,0.9);
}

/* Sepia theme - warm, easy on eyes */
[data-theme="sepia"] {
  --book-bg: #f4ecd8;
  --text-color: #5c4a3a;
  --heading-color: #3e2f23;
  --accent-color: #a0826d;
  --link-color: #8b6f47;
  --border-color: #d4c4a8;
  --code-bg: #ebe2d0;
  --quote-bg: rgba(112,85,51,0.08);
  --quote-border: #c8b89a;
  --toc-bg: #f9f4e8;
  --control-bg: #f9f4e8;
  --control-border: #d4c4a8;
  --control-shadow: rgba(92,74,58,0.15);
  --control-bg-soft: rgba(249,244,232,0.72);
  --control-bg-solid: rgba(249,244,232,0.96);
}

/* High contrast theme - accessibility */
[data-theme="high-contrast"] {
  --book-bg: #ffffff;
  --text-color: #000000;
  --heading-color: #000000;
  --accent-color: #0000ff;
  --link-color: #0000ee;
  --border-color: #000000;
  --code-bg: #f0f0f0;
  --quote-bg: #f5f5f5;
  --quote-border: #000000;
  --toc-bg: #ffffff;
  --control-bg: #ffffff;
  --control-border: #000000;
  --control-shadow: rgba(0,0,0,0.3);
  --control-bg-soft: rgba(255,255,255,0.85);
  --control-bg-solid: rgba(255,255,255,0.98);
}

/* Paper theme - cream background */
[data-theme="paper"] {
  --book-bg: #fffef7;
  --text-color: #2a2520;
  --heading-color: #1a1512;
  --accent-color: #7c5e3f;
  --link-color: #5a4428;
  --border-color: #e8e4d8;
  --code-bg: #f5f3e8;
  --quote-bg: rgba(124,94,63,0.05);
  --quote-border: #d8d0b8;
  --toc-bg: #fffef7;
  --control-bg: #fffef7;
  --control-border: #e8e4d8;
  --control-shadow: rgba(42,37,32,0.12);
  --control-bg-soft: rgba(255,254,247,0.72);
  --control-bg-solid: rgba(255,254,247,0.96);
}

/* Solarized Dark - scientifically designed for reduced eye strain */
[data-theme="solarized-dark"] {
  --book-bg: #002b36;
  --text-color: #839496;
  --heading-color: #93a1a1;
  --accent-color: #268bd2;
  --link-color: #2aa198;
  --border-color: #073642;
  --code-bg: #073642;
  --quote-bg: rgba(42,161,152,0.08);
  --quote-border: #586e75;
  --toc-bg: #073642;
  --control-bg: #073642;
  --control-border: #586e75;
  --control-shadow: rgba(0,0,0,0.4);
  --control-bg-soft: rgba(7,54,66,0.55);
  --control-bg-solid: rgba(7,54,66,0.92);
}

/* Solarized Light - complement to solarized dark */
[data-theme="solarized-light"] {
  --book-bg: #fdf6e3;
  --text-color: #657b83;
  --heading-color: #586e75;
  --accent-color: #268bd2;
  --link-color: #2aa198;
  --border-color: #eee8d5;
  --code-bg: #eee8d5;
  --quote-bg: rgba(42,161,152,0.06);
  --quote-border: #93a1a1;
  --toc-bg: #fdf6e3;
  --control-bg: #fdf6e3;
  --control-border: #eee8d5;
  --control-shadow: rgba(101,123,131,0.15);
  --control-bg-soft: rgba(253,246,227,0.72);
  --control-bg-solid: rgba(253,246,227,0.96);
}

/* Midnight - true black for OLED screens */
[data-theme="midnight"] {
  --book-bg: #000000;
  --text-color: #e0e0e0;
  --heading-color: #ffffff;
  --accent-color: #64b5f6;
  --link-color: #81c784;
  --border-color: #2a2a2a;
  --code-bg: #1a1a1a;
  --quote-bg: rgba(100,181,246,0.08);
  --quote-border: #424242;
  --toc-bg: #0a0a0a;
  --control-bg: #0a0a0a;
  --control-border: #2a2a2a;
  --control-shadow: rgba(0,0,0,0.6);
  --control-bg-soft: rgba(10,10,10,0.55);
  --control-bg-solid: rgba(10,10,10,0.95);
}

/* Nord - modern frost-themed palette */
[data-theme="nord"] {
  --book-bg: #2e3440;
  --text-color: #d8dee9;
  --heading-color: #eceff4;
  --accent-color: #88c0d0;
  --link-color: #81a1c1;
  --border-color: #3b4252;
  --code-bg: #3b4252;
  --quote-bg: rgba(136,192,208,0.08);
  --quote-border: #4c566a;
  --toc-bg: #2e3440;
  --control-bg: #2e3440;
  --control-border: #3b4252;
  --control-shadow: rgba(0,0,0,0.4);
  --control-bg-soft: rgba(46,52,64,0.55);
  --control-bg-solid: rgba(46,52,64,0.92);
}

/* Amber - red-shifted for night reading */
[data-theme="amber"] {
  --book-bg: #2b1d0e;
  --text-color: #ffb380;
  --heading-color: #ffd6b3;
  --accent-color: #ff9f5a;
  --link-color: #ffcc99;
  --border-color: #4a3520;
  --code-bg: #3a2818;
  --quote-bg: rgba(255,153,90,0.08);
  --quote-border: #6b4d2e;
  --toc-bg: #332415;
  --control-bg: #332415;
  --control-border: #4a3520;
  --control-shadow: rgba(0,0,0,0.5);
  --control-bg-soft: rgba(51,36,21,0.55);
  --control-bg-solid: rgba(51,36,21,0.92);
}

/* E-ink - grayscale optimized for e-readers */
[data-theme="eink"] {
  --book-bg: #ffffff;
  --text-color: #1a1a1a;
  --heading-color: #000000;
  --accent-color: #4a4a4a;
  --link-color: #2a2a2a;
  --border-color: #d0d0d0;
  --code-bg: #f5f5f5;
  --quote-bg: #f0f0f0;
  --quote-border: #999999;
  --toc-bg: #fafafa;
  --control-bg: #fafafa;
  --control-border: #d0d0d0;
  --control-shadow: rgba(0,0,0,0.15);
  --control-bg-soft: rgba(250,250,250,0.72);
  --control-bg-solid: rgba(250,250,250,0.96);
}

/* Ocean Day - fresh water theme for "God Is Water" */
[data-theme="ocean-day"] {
  --book-bg: #e8f4f8;
  --text-color: #1e3a5f;
  --heading-color: #0d2847;
  --accent-color: #0891b2;
  --link-color: #0e7490;
  --border-color: #bae6fd;
  --code-bg: #dbeafe;
  --quote-bg: rgba(14,116,144,0.08);
  --quote-border: #67e8f9;
  --toc-bg: #f0f9ff;
  --control-bg: #f0f9ff;
  --control-border: #bae6fd;
  --control-shadow: rgba(14,116,144,0.15);
  --control-bg-soft: rgba(240,249,255,0.72);
  --control-bg-solid: rgba(240,249,255,0.96);
}

/* Ocean Night - deep water theme for "God Is Water" */
[data-theme="ocean-night"] {
  --book-bg: #0a1929;
  --text-color: #b3d4e5;
  --heading-color: #cce7f5;
  --accent-color: #22d3ee;
  --link-color: #67e8f9;
  --border-color: #1e3a5f;
  --code-bg: #132f4c;
  --quote-bg: rgba(34,211,238,0.08);
  --quote-border: #0e7490;
  --toc-bg: #0d1f2e;
  --control-bg: #0d1f2e;
  --control-border: #1e3a5f;
  --control-shadow: rgba(0,0,0,0.4);
  --control-bg-soft: rgba(13,31,46,0.55);
  --control-bg-solid: rgba(13,31,46,0.92);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  font-family: var(--body-font);
  font-size: calc(18px * var(--font-scale));
  line-height: var(--base-line-height);
  color: var(--text-color);
  background: var(--book-bg);
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 2rem 1.5rem;
  letter-spacing: var(--base-letter-spacing);
  transition: background-color 0.3s ease, color 0.3s ease, font-family 0.3s ease;
  overflow-x: hidden;
}

/* Reading Controls Panel */
.reading-controls {
  position: fixed;
  top: 1rem;
  right: 0;
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-right: none;
  border-radius: 8px 0 0 8px;
  padding: 0.75rem;
  padding-left: 3rem;
  box-shadow: -2px 2px 8px var(--control-shadow);
  font-size: 14px;
  z-index: 1000;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  transition: transform 0.3s ease;
  transform: translateX(0);
}

.reading-controls.collapsed {
  transform: translateX(calc(100% - 2.5rem));
}

.controls-toggle {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2.5rem;
  background: var(--control-bg-soft);
  border: none;
  border-right: 1px solid var(--control-border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all 0.2s ease;
}

.controls-toggle:hover {
  background: var(--control-bg-solid);
}

.controls-content {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.reading-controls .control-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.reading-controls .control-group .control-actions {
  display: flex;
  gap: 0.35rem;
}

.reading-controls .control-group .control-actions button {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.control-actions {
  display: flex;
  gap: 0.35rem;
}

.reading-controls .control-group button {
  white-space: nowrap;
}

.reading-controls button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.reading-controls button,
.reading-controls select {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--control-bg-soft);
  color: var(--text-color);
  cursor: pointer;
  transition: all 0.2s ease;
}

.reading-controls select {
  padding-right: 0.5rem;
}

.reading-controls button:hover,
.reading-controls select:hover {
  background: var(--control-bg-solid);
  transform: translateY(-1px);
}

.reading-controls button:active {
  transform: translateY(0);
}

.reading-controls select {
  padding: 0.5rem;
  padding-right: 1.1rem;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: calc(100% - 0.35rem) center;
  background-size: 0.75rem;
}

/* Fix dropdown options in dark mode */
.reading-controls select option {
  background: var(--control-bg);
  color: var(--text-color);
}

.control-group {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: nowrap;
}

.control-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-color);
  opacity: 0.7;
  margin-right: 0.25rem;
}

@media (max-width: 900px) {
  body {
    padding-bottom: calc(6.5rem + env(safe-area-inset-bottom, 0));
  }

  .reading-controls {
    top: auto;
    bottom: calc(env(safe-area-inset-bottom, 0) + 0.75rem);
    right: 0.75rem;
    left: auto;
    width: clamp(240px, 80vw, 320px);
    flex-direction: column;
    gap: 0.75rem;
    padding: 1.4rem 0.9rem 0.7rem;
    border-radius: 16px;
    transform: translateY(0);
  }

  .reading-controls.collapsed {
    transform: translateY(calc(100% - 3.25rem));
    padding-top: 0.85rem;
  }

  .reading-controls.collapsed .controls-content,
  .reading-controls.collapsed #controls-hint {
    display: none;
  }

  .controls-toggle {
    top: -2.75rem;
    bottom: auto;
    left: auto;
    right: 0.9rem;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    border: 1px solid var(--control-border);
    transform: none;
    box-shadow: 0 8px 20px var(--control-shadow);
    background: var(--control-bg-soft);
    transition: top 0.3s ease, bottom 0.3s ease, box-shadow 0.3s ease;
  }

  .reading-controls:not(.collapsed) .controls-toggle {
    top: -3.7rem;
    bottom: auto;
    box-shadow: 0 12px 24px var(--control-shadow);
    background: var(--control-bg-solid);
  }

  .controls-content {
    width: 100%;
    flex-direction: column;
    gap: 0.75rem;
  }

  .control-group {
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
  }

  .control-label {
    font-size: 0.7rem;
    margin-right: 0;
  }

  .control-actions {
    width: 100%;
  }

  .control-actions button {
    flex: 1;
  }

  .reading-controls button,
  .reading-controls select {
    width: 100%;
  }

  .reading-controls button:hover,
  .reading-controls select:hover {
    transform: none;
  }

  button#controls-toggle {
    width: 5rem;
  }
}

.control-value {
  font-weight: 600;
  color: var(--heading-color);
  min-width: 1rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.tts-controls select {
  min-width: 8.5rem;
}

#tts-rate {
  max-width: 5rem;
  min-width: 3rem;
}

.control-hint {
  margin-top: 0.65rem;
  font-size: 0.75rem;
  color: var(--text-color);
  opacity: 0.7;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: 100%;
}

.control-hint:empty {
  display: none;
}

.control-hint .control-hint-item {
  line-height: 1.4;
}

.reader-popover {
  position: absolute;
  max-width: min(50rem, 92vw);
  background: var(--control-bg);
  color: var(--text-color);
  border: 1px solid var(--control-border);
  border-radius: 12px;
  box-shadow: 0 20px 40px var(--control-shadow);
  padding: 1.5rem;
  z-index: 1400;
}

.reader-popover h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--heading-color);
}

.reader-popover ul {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* Multi-column layout for shortcuts on wider screens */
@media (min-width: 768px) {
  .shortcuts-popover ul {
    display: block; /* Override flex for column layout */
    column-count: 2;
    column-gap: 2rem;
  }
}

@media (min-width: 1200px) {
  .shortcuts-popover ul {
    column-count: 3;
    column-gap: 2rem;
  }
}

.shortcuts-popover li {
  break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 0.6rem; /* Add spacing since we're overriding gap */
}

.reader-popover li {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.reader-popover kbd {
  background: var(--quote-bg);
  border: 1px solid var(--control-border);
  border-radius: 4px;
  padding: 0.2rem 0.45rem;
  font-size: 0.8rem;
  font-family: "JetBrains Mono", "DejaVu Sans Mono", Menlo, monospace;
}

.reader-popover li span {
  font-size: 0.85rem;
  flex: 1;
}

.reader-popover .close-popover {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.reader-popover .close-popover:hover {
  color: var(--accent-color);
}

.reader-popover:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 4px;
}

/* Search Bar */
.search-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--control-bg);
  border-bottom: 1px solid var(--control-border);
  box-shadow: 0 2px 8px var(--control-shadow);
  padding: 0.75rem 1rem;
  z-index: 1100;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

.search-bar.active {
  transform: translateY(0);
}

.search-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 1200px;
  margin: 0 auto;
  flex-wrap: wrap;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
  min-width: 200px;
}

#search-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  font-size: 0.95rem;
  background: var(--book-bg);
  color: var(--text-color);
  font-family: inherit;
}

#search-input:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 0;
}

/* Search History Dropdown */
.search-history-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.25rem;
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 6px;
  box-shadow: 0 4px 12px var(--control-shadow);
  max-height: 300px;
  overflow-y: auto;
  z-index: 1200;
  display: none;
}

.search-history-dropdown.show {
  display: block;
}

.search-history-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-color);
  opacity: 0.6;
  font-size: 0.9rem;
}

.search-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--control-border);
  transition: background 0.2s ease;
}

.search-history-item:last-of-type {
  border-bottom: none;
}

.search-history-item:hover {
  background: var(--quote-bg);
}

.history-query {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text-color);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-remove {
  padding: 0.25rem 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-color);
  opacity: 0.4;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  transition: opacity 0.2s ease;
}

.history-remove:hover {
  opacity: 1;
  color: #ef4444;
}

.search-history-footer {
  padding: 0.5rem;
  border-top: 1px solid var(--control-border);
  display: flex;
  justify-content: center;
}

.history-clear-btn {
  padding: 0.35rem 0.75rem;
  background: transparent;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  color: var(--text-color);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s ease;
  font-family: inherit;
}

.history-clear-btn:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.search-options {
  display: flex;
  gap: 0.5rem;
}

.search-option {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--book-bg);
  font-size: 0.85rem;
  font-weight: 600;
  user-select: none;
  transition: background 0.2s ease;
}

.search-option:hover {
  background: var(--quote-bg);
}

.search-option input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.search-option span {
  font-family: monospace;
  font-size: 0.9rem;
}

.search-results-info {
  font-size: 0.9rem;
  color: var(--text-color);
  white-space: nowrap;
  min-width: 80px;
  text-align: center;
}

.search-loading {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  opacity: 0.7;
}

.search-loading::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid var(--control-border);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.search-nav-buttons {
  display: flex;
  gap: 0.25rem;
}

.search-nav-buttons button {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--book-bg);
  color: var(--text-color);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.search-nav-buttons button:hover:not(:disabled) {
  background: var(--accent-color);
  color: white;
}

.search-nav-buttons button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

#search-close {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--book-bg);
  color: var(--text-color);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: all 0.2s ease;
}

#search-close:hover {
  background: #ef4444;
  color: white;
  border-color: #dc2626;
}

/* Search highlights */
.search-highlight {
  background: #fef08a;
  color: #000;
  border-radius: 2px;
  padding: 0 2px;
  transition: background 0.2s ease;
}

[data-theme="dark"] .search-highlight {
  background: #854d0e;
  color: #fef08a;
}

.search-highlight-current {
  background: #fbbf24;
  color: #000;
  box-shadow: 0 0 0 2px #f59e0b;
}

[data-theme="dark"] .search-highlight-current {
  background: #d97706;
  color: #fef3c7;
  box-shadow: 0 0 0 2px #f59e0b;
}

/* Hide search bar in focus mode */
body.focus-mode .search-bar {
  opacity: 0;
  pointer-events: none;
}

/* Mobile optimization for search */
@media (max-width: 768px) {
  .search-bar {
    padding: 0.5rem 0.75rem;
  }

  .search-controls {
    gap: 0.5rem;
  }

  .search-input-wrapper {
    min-width: 150px;
  }

  #search-input {
    font-size: 0.9rem;
  }

  .search-history-dropdown {
    max-height: 200px;
  }

  .search-options {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .search-results-info {
    font-size: 0.85rem;
    min-width: 70px;
  }

  .search-nav-buttons button,
  #search-close {
    width: 1.75rem;
    height: 1.75rem;
    font-size: 0.9rem;
  }
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 6rem;
  right: 1rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 250px;
  max-width: 400px;
  padding: 0.75rem 1rem;
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--control-shadow);
  pointer-events: auto;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease;
}

.toast-show {
  opacity: 1;
  transform: translateX(0);
}

.toast-hide {
  opacity: 0;
  transform: translateX(100%);
}

.toast-message {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text-color);
  line-height: 1.4;
}

.toast-action {
  padding: 0.25rem 0.75rem;
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s ease;
  font-family: inherit;
}

.toast-action:hover {
  opacity: 0.9;
}

.toast-close {
  padding: 0.25rem;
  background: transparent;
  border: none;
  color: var(--text-color);
  opacity: 0.6;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: opacity 0.2s ease;
}

.toast-close:hover {
  opacity: 1;
}

/* Toast types */
.toast-success {
  border-left: 4px solid #10b981;
}

.toast-error {
  border-left: 4px solid #ef4444;
}

.toast-warning {
  border-left: 4px solid #f59e0b;
}

.toast-info {
  border-left: 4px solid var(--accent-color);
}

/* Mobile toast positioning */
@media (max-width: 768px) {
  .toast-container {
    bottom: 4rem;
    right: 0.5rem;
    left: 0.5rem;
  }

  .toast {
    max-width: 100%;
  }
}

/* TOC Sidebar */
.toc-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: min(320px, 85vw);
  height: 100vh;
  background: var(--control-bg);
  border-right: 1px solid var(--control-border);
  box-shadow: 4px 0 12px var(--control-shadow);
  z-index: 1050;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  font-size: 14px;
}

.toc-sidebar:not(.hidden) {
  transform: translateX(0);
}

.toc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--control-border);
  background: var(--quote-bg);
}

.toc-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--heading-color);
}

.toc-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

/* Custom scrollbar for TOC */
.toc-content::-webkit-scrollbar {
  width: 8px;
}

.toc-content::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 4px;
}

.toc-content::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  transition: background 0.2s ease;
}

[data-theme="dark"] .toc-content::-webkit-scrollbar-thumb,
[data-theme="midnight"] .toc-content::-webkit-scrollbar-thumb,
[data-theme="ocean-night"] .toc-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
}

.toc-content::-webkit-scrollbar-thumb:hover {
  background: var(--accent-color);
}

/* Firefox scrollbar */
.toc-content {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
}

[data-theme="dark"] .toc-content,
[data-theme="midnight"] .toc-content,
[data-theme="ocean-night"] .toc-content {
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.toc-item {
  padding: 0.6rem 1.25rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
  border-left: 3px solid transparent;
}

.toc-item:hover {
  background: var(--quote-bg);
}

.toc-item.active {
  background: var(--quote-bg);
  border-left-color: var(--accent-color);
  font-weight: 500;
}

.toc-item-h1 {
  font-weight: 600;
  color: var(--heading-color);
  font-size: 0.95rem;
}

.toc-item-h2 {
  font-weight: 400;
  color: var(--text-color);
  font-size: 0.9rem;
  padding-left: 2rem;
}

.toc-item-h3 {
  font-weight: 400;
  color: var(--text-color);
  font-size: 0.85rem;
  padding-left: 3rem;
  opacity: 0.9;
}

/* Bookmarks Sidebar */
.bookmarks-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: min(350px, 90vw);
  height: 100vh;
  background: var(--control-bg);
  border-left: 1px solid var(--control-border);
  box-shadow: -4px 0 12px var(--control-shadow);
  z-index: 1050;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  font-size: 14px;
}

.bookmarks-sidebar:not(.hidden) {
  transform: translateX(0);
}

.bookmarks-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--control-border);
  background: var(--quote-bg);
}

.bookmarks-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--heading-color);
}

.bookmarks-header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.bookmarks-header-actions .bookmark-action-btn {
  min-width: auto;
  padding: 0.25rem 0.55rem;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.bookmarks-sync-indicator {
  border: none;
  background: transparent;
  color: var(--text-color);
  font-size: 1rem;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.bookmarks-sync-indicator:disabled {
  cursor: default;
  opacity: 0.4;
}

.bookmarks-sync-indicator.info {
  color: var(--text-secondary, var(--text-color));
}

.bookmarks-sync-indicator.success {
  color: #16a34a;
}

.bookmarks-sync-indicator.pending {
  color: #ff9800;
}

.bookmarks-sync-indicator.offline,
.bookmarks-sync-indicator.failed {
  color: #dc2626;
}

.bookmarks-sync-indicator.warning {
  color: #d97706;
}

.bookmarks-sync-indicator.syncing,
.bookmarks-sync-indicator.checking {
  color: var(--accent-color);
}

.close-sidebar {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-color);
  padding: 0.25rem;
  line-height: 1;
  transition: color 0.2s ease;
}

.close-sidebar:hover {
  color: var(--accent-color);
}

.bookmark-search-wrapper {
  padding: 0.75rem;
  border-bottom: 1px solid var(--control-border);
}

#bookmark-search-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: var(--book-bg);
  color: var(--text-color);
  font-family: inherit;
}

#bookmark-search-input:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 0;
}

#bookmark-search-input::placeholder {
  color: var(--text-color);
  opacity: 0.5;
}

.bookmarks-controls {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--control-border);
  flex-wrap: wrap;
}

.bookmarks-more {
  position: relative;
}

.bookmarks-more-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.25rem);
  background: var(--book-bg);
  border: 1px solid var(--control-border);
  border-radius: 8px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
  min-width: 200px;
  display: flex;
  flex-direction: column;
  z-index: 30;
  padding: 0.35rem 0;
}

.bookmarks-more-menu button,
.bookmarks-more-menu label {
  border: none;
  background: transparent;
  font: inherit;
  color: var(--text-color);
  text-align: left;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.bookmarks-more-menu button:hover,
.bookmarks-more-menu label:hover {
  background: var(--quote-bg);
}

.bookmarks-more-menu.hidden {
  display: none;
}

.bookmark-action-btn {
  flex: 1;
  min-width: 80px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  background: var(--book-bg);
  color: var(--text-color);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s ease;
  text-align: center;
  font-family: inherit;
}

.bookmark-action-btn:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.bookmarks-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

.bookmarks-empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-color);
  opacity: 0.7;
}

.bookmarks-empty p {
  margin: 0.5rem 0;
  font-size: 0.95rem;
}

.bookmarks-empty .hint {
  font-size: 0.85rem;
  font-style: italic;
}

.bookmarks-sidebar .hidden {
  display: none !important;
}

.bookmark-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
  background: var(--book-bg);
  transition: all 0.2s ease;
}

.bookmark-item:hover {
  box-shadow: 0 2px 8px var(--control-shadow);
  border-color: var(--accent-color);
}

.bookmark-item.pinned {
  border-color: var(--accent-color);
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.18);
}

.bookmark-item.dragging {
  opacity: 0.6;
  cursor: grabbing;
}

.bookmark-item.drag-over {
  border-style: dashed;
  border-color: var(--accent-color);
}

.bookmark-content {
  flex: 1;
  min-width: 0;
}

.bookmark-name {
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text-color);
  font-size: 0.95rem;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.2s ease;
}

.bookmark-name:hover {
  background: var(--quote-bg);
  border-color: var(--control-border);
}

.bookmark-name:focus {
  outline: none;
  background: var(--book-bg);
  border-color: var(--accent-color);
}

.bookmark-meta {
  font-size: 0.75rem;
  color: var(--text-color);
  opacity: 0.6;
  margin-top: 0.25rem;
  padding-left: 0.5rem;
  white-space: nowrap;
}

.bookmark-actions {
  display: flex;
  gap: 0.25rem;
  align-items: flex-start;
}

.bookmark-pin-btn,
.bookmark-note-btn,
.bookmark-jump-btn,
.bookmark-delete-btn {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--book-bg);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.bookmark-note-btn:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
  transform: scale(1.05);
}

.bookmark-note-btn.has-note {
  background: rgba(59, 130, 246, 0.1);
  border-color: var(--accent-color);
}

.bookmark-pin-btn.active {
  background: rgba(37, 99, 235, 0.12);
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.bookmark-jump-btn:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
  transform: scale(1.05);
}

.bookmark-delete-btn:hover {
  background: #ef4444;
  color: white;
  border-color: #dc2626;
  transform: scale(1.05);
}

/* Bookmark note display */
.bookmark-note-display {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: var(--quote-bg);
  border-left: 3px solid var(--accent-color);
  border-radius: 4px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-color);
  display: flex;
  gap: 0.5rem;
}

.bookmark-note-display .note-label {
  flex-shrink: 0;
  opacity: 0.6;
}

.bookmark-note-display .note-text {
  flex: 1;
  word-break: break-word;
  white-space: pre-wrap;
}

/* Bookmark inline note editor */
.bookmark-inline-note {
  margin-top: 0.5rem;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--control-border);
  background: var(--control-bg);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.bookmark-inline-note textarea {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--control-border);
  background: var(--book-bg);
  color: var(--text-color);
  font-family: inherit;
  font-size: 0.85rem;
  resize: vertical;
  min-height: 80px;
}

.bookmark-inline-note textarea:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 0;
}

.bookmark-inline-note-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

.bookmark-inline-note-actions button {
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--book-bg);
  color: var(--text-color);
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.bookmark-inline-note-actions button:hover {
  background: var(--accent-color);
  color: #fff;
  border-color: var(--accent-color);
}

/* Hide bookmarks sidebar in focus mode */
body.focus-mode .bookmarks-sidebar {
  opacity: 0;
  pointer-events: none;
}

/* Mobile optimization for bookmarks */
@media (max-width: 768px) {
  .bookmarks-sidebar {
    width: 100vw;
  }

  .bookmarks-controls {
    flex-direction: column;
  }

  .bookmark-action-btn {
    min-width: 100%;
  }

  .bookmark-item {
    flex-direction: column;
    gap: 0.5rem;
  }

  .bookmark-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* Chapter Navigation Buttons */
.chapter-nav-buttons {
  position: fixed;
  bottom: 2rem;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 900;
  padding: 0 1rem;
  max-width: 100vw;
}

.chapter-nav-btn {
  pointer-events: auto;
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 50%;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--text-color);
  box-shadow: 0 4px 12px var(--control-shadow);
  transition: all 0.2s ease;
  position: relative;
}

.chapter-nav-btn:hover:not(:disabled) {
  background: var(--accent-color);
  color: white;
  transform: scale(1.1);
  box-shadow: 0 6px 16px var(--control-shadow);
}

.chapter-nav-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.chapter-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.chapter-nav-btn .nav-arrow {
  font-size: 1.25rem;
  font-weight: bold;
  line-height: 1;
}

/* Positioning for prev/next buttons */
.chapter-nav-prev {
  margin-left: 0;
}

.chapter-nav-next {
  margin-right: 0;
}

/* Mobile optimization */
@media (max-width: 768px) {
  .chapter-nav-buttons {
    bottom: 1rem;
    padding: 0 0.5rem;
  }

  .chapter-nav-btn {
    width: 2.75rem;
    height: 2.75rem;
    font-size: 1.1rem;
  }

  .chapter-nav-btn .nav-arrow {
    font-size: 1.1rem;
  }
}

/* Touch-friendly targets on mobile */
@media (hover: none) and (pointer: coarse) {
  .chapter-nav-btn {
    width: 3.25rem;
    height: 3.25rem;
  }
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-family: "Noto Serif", Georgia, serif;
  font-weight: 600;
  line-height: 1.3;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  color: var(--heading-color);
  transition: color 0.3s ease;
}

h1 {
  font-size: 2.5rem;
  text-align: center;
  margin-top: 3rem;
  margin-bottom: 2rem;
  letter-spacing: -0.02em;
  border-bottom: 3px solid var(--accent-color);
  padding-bottom: 1rem;
}

h2 {
  font-size: 1.8rem;
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

h3 {
  font-size: 1.4rem;
  margin-top: 2rem;
}

h4 {
  font-size: 1.2rem;
  margin-top: 1.5rem;
}

/* Paragraphs */
p {
  margin-bottom: 1.2rem;
  text-align: left;
  hyphens: auto;
  orphans: 3;
  widows: 3;
}

p + p {
  text-indent: 0;
}

/* Links */
a {
  color: var(--link-color);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: all 0.2s ease;
}

a:hover {
  border-bottom-color: var(--link-color);
}

/* Table of Contents */
nav#TOC {
  background: var(--toc-bg);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 2rem;
  margin: 3rem 0;
  box-shadow: 0 2px 8px var(--control-shadow);
  transition: all 0.3s ease;
}

nav#TOC > ul {
  list-style: none;
  padding-left: 0;
}

nav#TOC ul {
  margin: 0.5rem 0;
}

nav#TOC li {
  margin: 0.5rem 0;
  line-height: 1.5;
}

nav#TOC a {
  color: var(--text-color);
  font-weight: 500;
  border-bottom: 1px dotted var(--border-color);
}

nav#TOC a.active {
  color: var(--accent-color);
  border-bottom-color: var(--accent-color);
  font-weight: 600;
}

nav#TOC a:hover {
  color: var(--accent-color);
  border-bottom-color: var(--accent-color);
}

/* Lists */
ul, ol {
  margin: 1rem 0 1.5rem 2rem;
  padding-left: 0;
}

li {
  margin: 0.5rem 0;
}

/* Blockquotes */
blockquote {
  margin: 2rem 0;
  padding: 1rem 1.5rem;
  border-left: 4px solid var(--quote-border);
  background: var(--quote-bg);
  font-style: italic;
  color: var(--text-color);
  opacity: 0.9;
  transition: all 0.3s ease;
}

blockquote p {
  margin-bottom: 0.5rem;
}

/* Code blocks */
pre {
  background: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-size: 0.9rem;
  transition: all 0.3s ease;
}

code {
  font-family: "DejaVu Sans Mono", "Courier New", monospace;
  background: var(--code-bg);
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  font-size: 0.9em;
  transition: background 0.3s ease;
}

pre code {
  background: none;
  padding: 0;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 2rem 0;
  font-size: 0.95rem;
}

th, td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  font-weight: 600;
  background: var(--quote-bg);
  border-bottom: 2px solid var(--border-color);
}

/* Images */
img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 2rem auto;
  border-radius: 4px;
  box-shadow: 0 2px 8px var(--control-shadow);
}

/* Figures */
figure {
  margin: 2rem 0;
}

figcaption {
  text-align: center;
  font-style: italic;
  font-size: 0.9rem;
  color: var(--text-color);
  opacity: 0.7;
  margin-top: 0.5rem;
}

/* Strong and emphasis */
strong {
  font-weight: 600;
  color: var(--heading-color);
}

em {
  font-style: italic;
}

/* Horizontal rules */
hr {
  border: none;
  border-top: 2px solid var(--border-color);
  margin: 3rem 0;
}

/* Multilingual script support */
.hebrew {
  font-family: "FreeSerif", "Noto Serif Hebrew", "Arial Unicode MS", serif;
  direction: rtl;
  unicode-bidi: embed;
  font-size: 1.1em;
}

.arabic {
  font-family: "FreeSerif", "Noto Naskh Arabic", "Arial Unicode MS", serif;
  direction: rtl;
  unicode-bidi: embed;
  font-size: 1.1em;
}

.gurmukhi {
  font-family: "Noto Sans Gurmukhi", "FreeSerif", "Arial Unicode MS", sans-serif;
  font-size: 1.1em;
}

.japanese {
  font-family: "Droid Sans Fallback", "Noto Sans CJK JP", "Arial Unicode MS", sans-serif;
  font-size: 1.05em;
}

.devanagari {
  font-family: "FreeSerif", "Noto Sans Devanagari", "Arial Unicode MS", serif;
  font-size: 1.1em;
}

.symbols {
  font-family: "FreeSerif", "DejaVu Sans", "Symbola", "Arial Unicode MS", sans-serif;
}

.footnote-popover {
  position: absolute;
  max-width: min(26rem, 90vw);
  max-height: 60vh;
  background: var(--control-bg);
  color: var(--text-color);
  border: 1px solid var(--control-border);
  border-radius: 10px;
  box-shadow: 0 18px 30px var(--control-shadow);
  padding: 1rem 1.25rem;
  line-height: 1.55;
  z-index: 1200;
  overflow-y: auto;
}

.footnote-popover p:last-child {
  margin-bottom: 0;
}

/* Header metadata */
.title {
  font-size: 3rem;
  text-align: center;
  margin: 2rem 0 1rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--heading-color);
}

.subtitle {
  font-size: 1.3rem;
  text-align: center;
  color: var(--text-color);
  opacity: 0.8;
  font-style: italic;
  margin-bottom: 0.5rem;
}

.author {
  text-align: center;
  font-size: 1.1rem;
  margin: 1rem 0;
  color: var(--text-color);
  opacity: 0.7;
}

.date {
  text-align: center;
  color: var(--text-color);
  opacity: 0.6;
  margin-bottom: 3rem;
}

/* Print styles */
@media print {
  body {
    background: white;
    max-width: 100%;
    padding: 1cm;
    color: black;
  }

  .reading-controls {
    display: none;
  }

  a {
    color: black;
    text-decoration: underline;
  }

  img {
    page-break-inside: avoid;
  }

  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
    color: black;
  }
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
  html {
    font-size: 16px;
  }

  body {
    padding: 1rem;
    padding-bottom: 4rem;
    max-width: 100%;
  }

  h1 {
    font-size: 2rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  .title {
    font-size: 2.2rem;
  }

  /* Make controls more compact on mobile */
  .reading-controls {
    position: fixed;
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: none;
    border: 1px solid var(--control-border);
    border-bottom: none;
    border-radius: 0;
    padding: 0.5rem;
    padding-left: 0;
    padding-bottom: calc(env(safe-area-inset-bottom) + 0.5rem);
    box-shadow: 0 -2px 8px var(--control-shadow);
    transform: translateY(0);
  }

  .reading-controls.collapsed {
    transform: translateY(calc(100% + 1rem));
  }

  .controls-toggle {
    /* Fixed FAB button - stays visible even when panel collapses */
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom) + 1rem);
    right: 1rem;
    left: auto;
    top: auto;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    border: 2px solid var(--control-border);
    background: var(--control-bg);
    box-shadow: 0 2px 12px var(--control-shadow);
    z-index: 1001;
    transform: none !important;
  }

  .controls-content {
    flex-direction: row;
    justify-content: space-around;
    width: 100%;
    padding-left: 0;
  }

  .reading-controls button,
  .reading-controls select {
    font-size: 0.75rem;
    padding: 0.4rem 0.6rem;
  }

  .reading-controls .control-group {
    flex: 1 1 100%;
    justify-content: space-between;
  }

  .reading-controls .control-group .control-actions {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .control-group {
    flex: 1 1 100%;
    flex-wrap: wrap;
  }

  .control-value {
    text-align: left;
  }

  .tts-controls select {
    width: 100%;
  }

  .control-actions {
    width: 100%;
  }

  .control-group .control-label {
    width: 100%;
  }

  .control-label {
    display: none;
  }

  nav#TOC {
    padding: 1rem;
    margin: 2rem 0;
  }

  /* Adjust multilingual text for mobile */
  .hebrew,
  .arabic,
  .gurmukhi,
  .japanese,
  .devanagari {
    font-size: 1em;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 14px;
  }

  .controls-content {
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .reading-controls button:not(.controls-toggle),
  .reading-controls select {
    flex: 1 1 45%;
    min-width: 80px;
  }

  .control-actions {
    gap: 0.25rem;
  }

  .control-actions button {
    flex: 1 1 48%;
  }
}

/* Tablet landscape and larger */
@media (min-width: 769px) and (max-width: 1024px) {
  body {
    padding: 2rem;
  }

  .reading-controls {
    top: 1.5rem;
    right: 0;
  }
}

/* Large screens */
@media (min-width: 1400px) {
  html {
    font-size: 19px;
  }

  .reading-controls {
    top: 2rem;
    right: 0;
  }
}

/* Selection */
::selection {
  background: rgba(37, 99, 235, 0.2);
  color: inherit;
}

/* Smooth transitions for theme changes */
body,
h1, h2, h3, h4, h5, h6,
a,
nav#TOC,
blockquote,
pre,
code,
th {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Focus styles for accessibility */
button:focus,
select:focus,
a:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }
}

/* ====================
   HIGHLIGHTS SYSTEM
   ==================== */

/* Highlight spans - like physical highlighter markers */
.highlight {
  position: relative;
  padding: 3px 2px;
  margin: 0 -1px;
  border-radius: 3px;
  transition: all 0.2s ease;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  /* background-color and border-bottom set via JS based on type */
}

.highlight:hover {
  filter: brightness(1.15);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  transform: translateY(-1px);
}

/* Flash animation for scrolling to highlight */
@keyframes highlightFlash {
  0%, 100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.4);
    box-shadow: 0 0 12px currentColor;
  }
}

/* Highlight popup menu */
.highlight-popup {
  position: absolute;
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 10px;
  padding: 0.6rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
  z-index: 2000;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 14px;
  opacity: 0;
  transform: scale(0.9) translateY(5px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.highlight-popup.visible {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.highlight-btn-wrapper {
  position: relative;
  display: inline-block;
}

.highlight-color-btn,
.highlight-cancel-btn {
  width: 40px;
  height: 40px;
  border: 2px solid;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  position: relative;
}

.highlight-color-btn:hover,
.highlight-cancel-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.highlight-color-btn:active,
.highlight-cancel-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.highlight-cancel-btn {
  background: var(--control-bg);
  border-color: var(--control-border);
  color: var(--text-secondary);
}

.highlight-cancel-btn:hover {
  background: rgba(229, 57, 53, 0.1);
  border-color: #e53935;
  color: #e53935;
}

.highlight-popup-separator {
  width: 1px;
  height: 30px;
  background: var(--control-border);
  margin: 0 0.25rem;
}

/* Highlight tooltips - appear above buttons */
.highlight-tooltip {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(5px);
  background: var(--control-bg-solid);
  color: var(--text-color);
  border: 1px solid var(--control-border);
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.85rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s 0.2s;
  z-index: 2001;
  box-shadow: 0 4px 12px var(--control-shadow);
}

.highlight-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--control-bg-solid);
}

.highlight-tooltip.visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
  transition-delay: 0s, 0s, 0s;
}

.highlight-tooltip strong {
  display: block;
  font-weight: 600;
  margin-bottom: 0.2rem;
  font-size: 0.9rem;
}

.highlight-tooltip span {
  display: block;
  opacity: 0.85;
  font-size: 0.8rem;
}

/* Highlight note dialog */
.highlight-note-dialog {
  position: fixed;
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  z-index: 2001;
  max-width: 500px;
  width: 90%;
}

.note-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.note-dialog-header h3 {
  margin: 0;
  font-size: 1.2rem;
}

.close-dialog-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-color);
  opacity: 0.6;
  transition: opacity 0.2s ease;
}

.close-dialog-btn:hover {
  opacity: 1;
}

.note-dialog-excerpt {
  font-style: italic;
  color: var(--text-color);
  opacity: 0.8;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--quote-bg);
  border-left: 3px solid var(--accent-color);
  border-radius: 4px;
}

.note-dialog-textarea {
  width: 100%;
  min-height: 100px;
  padding: 0.75rem;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  background: var(--book-bg);
  color: var(--text-color);
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
  margin-bottom: 1rem;
}

.note-dialog-textarea:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 0;
}

.note-dialog-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.note-dialog-btn {
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.note-save-btn {
  background: var(--accent-color);
  color: white;
}

.note-save-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.note-submit-btn {
  background: #4caf50;
  color: white;
}

.note-submit-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.note-delete-btn {
  background: transparent;
  color: #e53935;
  border: 1px solid #e53935;
}

.note-delete-btn:hover {
  background: #e53935;
  color: white;
}

/* Highlights sidebar */
.highlights-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  height: 100vh;
  background: var(--control-bg);
  border-left: 1px solid var(--control-border);
  box-shadow: -4px 0 12px var(--control-shadow);
  z-index: 1500;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.3s ease;
  font-size: 14px;
}

/* Sidebar search */
.sidebar-search {
  position: relative;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--control-border);
}

.sidebar-search-input {
  width: 100%;
  padding: 0.6rem 2rem 0.6rem 0.8rem;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: var(--bg-color);
  color: var(--text-color);
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.sidebar-search-input:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.sidebar-search-clear {
  position: absolute;
  right: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.25rem;
  opacity: 0.6;
  transition: opacity 0.2s ease;
}

.sidebar-search-clear:hover {
  opacity: 1;
}

.search-results-count {
  padding: 0.5rem 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* Sidebar analytics */
.sidebar-analytics {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--control-border);
  background: rgba(0, 0, 0, 0.02);
}

.analytics-summary {
  margin-bottom: 0.5rem;
}

.analytics-stat {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 0.5rem;
  justify-content: center;
}

.analytics-number {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-color);
  line-height: 1;
}

.analytics-label {
  font-size: 0.75rem;
  color: var(--text-color);
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.analytics-types {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.analytics-hint {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.25rem;
}

.analytics-type {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  background: var(--bg-color);
  border: 1px solid var(--control-border);
  cursor: pointer;
  transition: all 0.18s ease;
  font: inherit;
}

.analytics-type:disabled {
  cursor: not-allowed;
  opacity: 0.3;
}

.analytics-type.inactive {
  opacity: 0.45;
  border-style: dashed;
}

.analytics-type:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

.analytics-type-icon {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  border: 1px solid var(--type-color, var(--control-border));
}

.analytics-type-label {
  font-size: 0.75rem;
  color: var(--text-color);
}

.analytics-sync-status {
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.85rem;
  text-align: center;
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.analytics-sync-status.pending {
  background: rgba(255, 152, 0, 0.1);
  color: #ff9800;
  border: 1px solid rgba(255, 152, 0, 0.3);
}

.analytics-sync-status.failed {
  background: rgba(229, 57, 53, 0.1);
  color: #e53935;
  border: 1px solid rgba(229, 57, 53, 0.3);
}

.analytics-sync-status.success {
  background: rgba(76, 175, 80, 0.1);
  color: #2e7d32;
  border: 1px solid rgba(76, 175, 80, 0.3);
}

.analytics-sync-status.info {
  background: rgba(33, 150, 243, 0.08);
  color: #1565c0;
  border: 1px solid rgba(33, 150, 243, 0.25);
}

.analytics-sync-status.offline {
  background: rgba(158, 158, 158, 0.12);
  color: #424242;
  border: 1px solid rgba(158, 158, 158, 0.3);
}

.analytics-sync-status.warning {
  background: rgba(255, 193, 7, 0.15);
  color: #795548;
  border: 1px solid rgba(255, 193, 7, 0.35);
}

.analytics-sync-status .status-text {
  flex: 1;
}

.analytics-sync-status .sync-updated {
  font-size: 0.75rem;
  opacity: 0.8;
}

.analytics-sync-retry {
  border: 1px solid var(--control-border);
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-color);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.analytics-sync-retry:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.highlights-sidebar.hidden {
  transform: translateX(100%);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--control-border);
}

.sidebar-header h3 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--heading-color);
}

.sidebar-header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.sidebar-action-btn {
  background: none;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-color);
  transition: all 0.2s ease;
}

.sidebar-action-btn:hover {
  background: var(--quote-bg);
  transform: translateY(-1px);
}

.sidebar-close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-color);
  opacity: 0.6;
  transition: opacity 0.2s ease;
}

.sidebar-close-btn:hover {
  opacity: 1;
}

/* More actions dropdown */
.sidebar-more-actions {
  position: relative;
}

.sidebar-more-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: var(--control-bg-solid);
  border: 1px solid var(--control-border);
  border-radius: 6px;
  box-shadow: 0 4px 12px var(--control-shadow);
  min-width: 160px;
  z-index: 1000;
  overflow: hidden;
}

.sidebar-more-menu.hidden {
  display: none;
}

.sidebar-menu-item {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  color: var(--text-color);
  font-size: 0.9rem;
  transition: background 0.2s ease;
}

.sidebar-menu-item:hover {
  background: var(--quote-bg);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
}

.sidebar-empty {
  text-align: center;
  color: var(--text-color);
  opacity: 0.6;
  margin-top: 2rem;
  padding: 0 1rem;
}

.sidebar-section {
  margin-bottom: 2rem;
}

.sidebar-section h4 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  font-weight: 600;
}

.sidebar-highlight-item {
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  background: var(--quote-bg);
  border-left: 4px solid;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}

.sidebar-highlight-item:hover {
  transform: translateX(-4px);
  box-shadow: 2px 2px 8px var(--control-shadow);
}

.sidebar-highlight-text {
  margin: 0 0 0.5rem 0;
  font-size: 0.9rem;
  color: var(--text-color);
  line-height: 1.4;
  padding-right: 4.5rem;
}

/* Highlight action buttons container */
.highlight-actions {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sidebar-highlight-item:hover .highlight-actions {
  opacity: 1;
}

.highlight-jump-btn,
.highlight-delete-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  background: var(--control-bg);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

.highlight-jump-btn {
  color: var(--accent-color);
}

.highlight-jump-btn:hover {
  background: var(--accent-color);
  color: white;
  transform: scale(1.1);
}

.highlight-delete-btn {
  color: #e53935;
}

.highlight-delete-btn:hover {
  background: #e53935;
  filter: brightness(1.1);
  transform: scale(1.1);
}

.sidebar-highlight-note {
  margin: 0 0 0.5rem 0;
  font-size: 0.85rem;
  color: var(--text-color);
  opacity: 0.8;
  font-style: italic;
  padding: 0.5rem;
  background: var(--book-bg);
  border-radius: 4px;
}

.sidebar-highlight-meta {
  font-size: 0.75rem;
  color: var(--text-color);
  opacity: 0.5;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .highlights-sidebar {
    width: 100%;
    max-width: 100%;
  }

  .highlight-note-dialog {
    width: 95%;
    padding: 1rem;
  }

  .note-dialog-actions {
    flex-direction: column;
  }

  .note-dialog-btn {
    width: 100%;
  }

  .analytics-types {
    grid-template-columns: 1fr;
  }

  .analytics-type-icon {
    width: 28px;
    height: 28px;
    font-size: 0.85rem;
  }

  .highlight-actions {
    opacity: 1;
  }

  /* Mobile popup adjustments */
  .highlight-popup {
    padding: 0.5rem;
    gap: 0.4rem;
  }

  .highlight-color-btn,
  .highlight-cancel-btn {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }

  .highlight-popup-separator {
    height: 36px;
  }

  /* Tooltips on mobile - show below cursor to avoid finger blocking view */
  .highlight-tooltip {
    bottom: auto;
    top: calc(100% + 12px);
    font-size: 0.8rem;
    padding: 0.5rem 0.7rem;
    max-width: 150px;
    white-space: normal;
    text-align: center;
  }

  .highlight-tooltip::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: var(--control-bg-solid);
  }

  .highlight-tooltip strong {
    font-size: 0.85rem;
  }

  .highlight-tooltip span {
    font-size: 0.75rem;
  }
}

/* ====================
   PWA FEATURES
   ==================== */

/* Offline indicator */
.offline-indicator {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: #ff9800;
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 3000;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.offline-indicator.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(-100%);
  pointer-events: none;
}

/* Update notification */
.update-notification {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--control-bg);
  border: 2px solid var(--accent-color);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  z-index: 3000;
  max-width: 360px;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.update-notification-content p {
  margin: 0 0 0.5rem 0;
  color: var(--text-color);
}

.update-notification-content p:first-child {
  font-weight: 600;
  color: var(--accent-color);
}

.update-notification-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.update-btn,
.dismiss-btn {
  flex: 1;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.update-btn {
  background: var(--accent-color);
  color: white;
}

.update-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.dismiss-btn {
  background: transparent;
  color: var(--text-color);
  border: 1px solid var(--control-border);
}

.dismiss-btn:hover {
  background: var(--quote-bg);
}

/* Generic PWA notification */
.pwa-notification {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 8px;
  padding: 1rem 1.5rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 3000;
  max-width: 400px;
  color: var(--text-color);
  animation: slideIn 0.3s ease;
}

.pwa-notification.fade-out {
  animation: fadeOut 0.3s ease forwards;
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
}

/* Install button (in controls) */
#pwa-install-btn {
  position: relative;
}

#pwa-install-btn::after {
  content: '';
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: #4caf50;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.6;
    transform: scale(1.2);
  }
}

@keyframes highlightFlash {
  0% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.7);
  }
  50% {
    opacity: 1;
    box-shadow: 0 0 0 10px rgba(37, 99, 235, 0);
  }
  100% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
  }
}

/* Cache Management Dialog */
.cache-stats-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.2s ease;
}

.cache-stats-content {
  background: var(--control-bg);
  color: var(--text-color);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.cache-stats-content h3 {
  margin: 0 0 1.5rem 0;
  font-size: 1.5rem;
  color: var(--accent-color);
}

.cache-stats-content h4 {
  margin: 0 0 0.75rem 0;
  font-size: 1.1rem;
  color: var(--text-color);
}

.cache-stats-section {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 8px;
}

.cache-stats-section p {
  margin: 0.5rem 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.cache-progress-bar {
  width: 100%;
  height: 24px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  overflow: hidden;
  margin: 0.75rem 0;
}

.cache-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4caf50 0%, #66bb6a 100%);
  transition: width 0.3s ease;
}

.cache-progress-fill[style*="width: 7"],
.cache-progress-fill[style*="width: 8"],
.cache-progress-fill[style*="width: 9"] {
  background: linear-gradient(90deg, #ff9800 0%, #ffb74d 100%);
}

.cache-progress-fill[style*="width: 10"] {
  background: linear-gradient(90deg, #f44336 0%, #ef5350 100%);
}

.cache-stats-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.cache-action-btn {
  flex: 1;
  min-width: 120px;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cache-action-btn.prune-btn {
  background: #ff9800;
  color: white;
}

.cache-action-btn.prune-btn:hover {
  background: #f57c00;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 152, 0, 0.3);
}

.cache-action-btn.clear-btn {
  background: #f44336;
  color: white;
}

.cache-action-btn.clear-btn:hover {
  background: #d32f2f;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(244, 67, 54, 0.3);
}

.cache-action-btn.close-btn {
  background: var(--control-border);
  color: var(--text-color);
}

.cache-action-btn.close-btn:hover {
  background: var(--text-secondary);
  transform: translateY(-2px);
}

/* Mobile responsive PWA */
@media (max-width: 768px) {
  .update-notification {
    bottom: 1rem;
    right: 1rem;
    left: 1rem;
    max-width: none;
  }

  .offline-indicator {
    top: 0.5rem;
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
  }

  .pwa-notification {
    bottom: 1rem;
    max-width: calc(100% - 2rem);
  }

  .cache-stats-content {
    padding: 1.5rem;
    max-height: 90vh;
  }

  .cache-stats-content h3 {
    font-size: 1.3rem;
  }

  .cache-stats-actions {
    flex-direction: column;
  }

  .cache-action-btn {
    min-width: 100%;
  }
}

/* ============================================================================
   DICTIONARY POPUP
   ============================================================================ */

.dictionary-popup {
  position: fixed;
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 2001;
  max-width: 550px;
  width: 90%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  font-size: 14px;
}

.dictionary-popup.visible {
  opacity: 1;
  pointer-events: auto;
}

.dictionary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--control-border);
}

.dictionary-word {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--heading-color);
  margin: 0;
}

.dictionary-phonetic {
  font-size: 0.9rem;
  color: var(--text-color);
  opacity: 0.7;
  font-style: italic;
  margin-top: 0.25rem;
}

.dictionary-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-color);
  padding: 0.25rem;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.2s ease;
}

.dictionary-close:hover {
  opacity: 1;
}

.dictionary-content {
  padding: 1rem 1.25rem;
  max-height: 400px;
  overflow-y: auto;
}

.dictionary-definition {
  margin-bottom: 1rem;
}

.dictionary-definition:last-child {
  margin-bottom: 0;
}

.dictionary-part-of-speech {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-color);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.dictionary-meaning {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-color);
  margin-bottom: 0.5rem;
}

.dictionary-example {
  font-size: 0.9rem;
  font-style: italic;
  color: var(--text-color);
  opacity: 0.8;
  padding-left: 1rem;
  border-left: 2px solid var(--border-color);
  margin-top: 0.25rem;
}

.dictionary-loading {
  padding: 2rem;
  text-align: center;
  color: var(--text-color);
  opacity: 0.6;
}

.dictionary-error {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-color);
  opacity: 0.7;
  font-size: 0.95rem;
}

.dictionary-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--control-border);
  font-size: 0.8rem;
  color: var(--text-color);
  opacity: 0.6;
  text-align: center;
}

/* ============================================================================
   CITATION POPUPS
   ============================================================================ */

.citation-popup {
  position: fixed;
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 2001;
  max-width: 500px;
  width: 90%;
  opacity: 0;
  transition: opacity 0.2s ease;
  font-size: 14px;
}

.citation-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--control-border);
}

.citation-popup-header h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--heading-color);
}

.citation-popup-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-color);
  opacity: 0.6;
  transition: opacity 0.2s ease, transform 0.2s ease;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.citation-popup-close:hover {
  opacity: 1;
  transform: scale(1.1);
}

.citation-popup-content {
  padding: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-color);
}

.citation-popup-content em {
  font-style: italic;
}

.citation-popup-content a {
  color: var(--link-color);
  text-decoration: none;
}

.citation-popup-content a:hover {
  text-decoration: underline;
}

.citation-popup-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--control-border);
  display: flex;
  justify-content: flex-end;
}

.citation-popup-link {
  color: var(--link-color);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.citation-popup-link:hover {
  color: var(--accent-color);
  transform: translateX(2px);
}

.citation-popup-link.secondary {
  opacity: 0.8;
}

/* Citation metadata formatting */
.citation-metadata {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--control-border);
  display: grid;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.citation-meta-item {
  display: flex;
  gap: 0.5rem;
}

.citation-meta-label {
  font-weight: 600;
  color: var(--text-muted, #999);
  min-width: 80px;
  flex-shrink: 0;
}

.citation-meta-value {
  color: var(--text-color);
}

.citation-meta-value a {
  color: var(--link-color);
  text-decoration: none;
  word-break: break-all;
}

.citation-meta-value a:hover {
  text-decoration: underline;
}

.citation-doi-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: rgba(33, 150, 243, 0.1);
  color: var(--link-color);
  border: 1px solid rgba(33, 150, 243, 0.35);
  font-size: 0.78rem;
  font-weight: 600;
  width: max-content;
  transition: all 0.2s ease;
}

.citation-doi-badge:hover {
  color: var(--accent-color);
  border-color: var(--accent-color);
}

/* Citation footer with actions */
.citation-popup-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--control-border);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
}

.citation-popup-actions {
  display: flex;
  gap: 0.5rem;
}

.citation-key-pill {
  margin: 0 1.25rem 0.5rem 1.25rem;
  border: 1px solid var(--control-border);
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-color);
  border-radius: 999px;
  font-size: 0.75rem;
  padding: 0.2rem 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.citation-key-pill::before {
  content: '@';
  color: var(--accent-color);
  font-weight: 600;
}

.citation-key-pill.copied {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.citation-action-btn,
.citation-copy-btn {
  border: 1px solid var(--control-border);
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-color);
  border-radius: 8px;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.citation-action-btn:hover,
.citation-copy-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.citation-action-btn.copied,
.citation-copy-btn.copied {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.citation-copy-btn.copied {
  background: #10b981;
}

/* Enhanced citation text formatting */
.citation-popup-content .citation-title {
  font-style: italic;
  font-weight: 500;
}

.citation-popup-content .citation-author {
  font-weight: 500;
}

.citation-popup-content .citation-year {
  font-weight: 500;
}

/* Make citation links look clickable */
.citation a {
  cursor: help;
  position: relative;
}

.citation a:hover {
  text-decoration: underline;
  text-decoration-style: dotted;
}

/* Typography Modal */
.typography-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.typography-modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.typography-modal {
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 12px;
  box-shadow: 0 8px 32px var(--control-shadow);
  width: min(440px, 90vw);
  max-height: 85vh;
  overflow: auto;
  animation: modalSlideIn 0.3s ease;
  font-size: 15px;
}

@keyframes modalSlideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.typography-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--control-border);
}

.typography-modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--heading-color);
}

.typography-modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-color);
  padding: 0.25rem;
  line-height: 1;
  transition: color 0.2s ease;
}

.typography-modal-close:hover {
  color: var(--accent-color);
}

.typography-modal-body {
  padding: 1.5rem;
}

.typography-control-group {
  margin-bottom: 1.75rem;
}

.typography-control-group:last-child {
  margin-bottom: 0;
}

.typography-control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--heading-color);
}

.typography-control-value {
  font-size: 0.9rem;
  color: var(--text-color);
  opacity: 0.8;
  font-weight: 400;
  font-family: monospace;
}

.typography-slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border-color);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.typography-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-color);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.typography-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-color);
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.typography-slider::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 3px 10px rgba(0,0,0,0.3);
}

.typography-slider::-moz-range-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 3px 10px rgba(0,0,0,0.3);
}

.typography-modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--control-border);
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.typography-btn {
  padding: 0.6rem 1.25rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--control-border);
  background: var(--control-bg);
  color: var(--text-color);
}

.typography-btn:hover {
  background: var(--quote-bg);
  transform: translateY(-1px);
}

.typography-btn-primary {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.typography-btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* Mobile responsive */
@media (max-width: 768px) {
  .citation-popup {
    max-width: calc(100% - 2rem);
    max-height: 80vh;
    overflow-y: auto;
  }

  .citation-popup-content {
    font-size: 0.85rem;
  }
}

/* ============================================================================
   FOCUS MODE
   ============================================================================ */

/* Hide all UI elements in focus mode for distraction-free reading */
body.focus-mode .reading-controls,
body.focus-mode .highlights-sidebar,
body.focus-mode .citation-popup,
body.focus-mode .highlight-popup,
body.focus-mode .highlight-note-dialog,
body.focus-mode #TOC,
body.focus-mode .chapter-nav-buttons,
body.focus-mode .search-bar,
body.focus-mode .bookmarks-sidebar,
body.focus-mode .toc-sidebar,
body.focus-mode .toast-container {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* Show a subtle hint on how to exit focus mode */
body.focus-mode::before {
  content: 'Press F or ESC to exit focus mode';
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  z-index: 10000;
  opacity: 0;
  animation: fadeInOut 3s ease-in-out;
  pointer-events: none;
}

@keyframes fadeInOut {
  0% { opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { opacity: 0; }
}

/* ============================================================================
   SPEED READER (RSVP)
   ============================================================================ */

.speed-reader-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 4000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.speed-reader-overlay.active {
  display: flex;
}

.speed-reader-container {
  background: var(--control-bg);
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  max-width: 1400px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.speed-reader-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--control-border);
}

.speed-reader-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--heading-color);
}

.speed-reader-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-color);
  opacity: 0.6;
  transition: opacity 0.2s ease;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.speed-reader-close:hover {
  opacity: 1;
}

.speed-reader-display {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  position: relative;
  min-height: 200px;
}

.speed-reader-focus-point {
  position: absolute;
  width: 2px;
  height: 100%;
  background: var(--accent-color);
  opacity: 0.3;
  left: 50%;
  transform: translateX(-50%);
}

.speed-reader-word {
  font-size: 3rem;
  font-weight: 500;
  color: var(--text-color);
  text-align: center;
  line-height: 1.2;
  position: relative;
  z-index: 1;
  font-family: var(--body-font);
}

.speed-reader-word .word-before,
.speed-reader-word .word-after {
  color: var(--text-color);
}

.speed-reader-word .word-orp {
  color: var(--accent-color);
  font-weight: 700;
}

.speed-reader-word .word-chunk {
  color: var(--text-color);
}

.speed-reader-context-before,
.speed-reader-context-after {
  position: absolute;
  font-size: 1.5rem;
  color: var(--text-color);
  opacity: 0.3;
  z-index: 0;
  font-family: var(--body-font);
  max-width: 40%;
  text-align: center;
}

.speed-reader-context-before {
  top: 50%;
  left: 10%;
  transform: translateY(-50%);
}

.speed-reader-context-after {
  top: 50%;
  right: 10%;
  transform: translateY(-50%);
}

.speed-reader-progress {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--control-border);
  border-bottom: 1px solid var(--control-border);
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--quote-bg);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-fill {
  height: 100%;
  background: var(--accent-color);
  transition: width 0.2s ease;
  border-radius: 3px;
}

.progress-text {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted, #999);
}

.speed-reader-controls {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.speed-control-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.speed-preset-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.speed-preset-btn {
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--book-bg);
  color: var(--text-color);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.speed-preset-btn:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.speed-options-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 0.5rem;
}

.speed-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-color);
  cursor: pointer;
  user-select: none;
}

.speed-option input[type="checkbox"] {
  cursor: pointer;
  width: 18px;
  height: 18px;
}

.speed-wpm-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--quote-bg);
  border-radius: 8px;
}

.speed-wpm-input {
  width: 85px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--book-bg);
  color: var(--text-color);
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  font-family: inherit;
}

.speed-wpm-input:focus {
  outline: none;
  border-color: var(--accent-color);
}

.wpm-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted, #999);
  text-transform: uppercase;
}

.speed-playback-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.speed-btn {
  padding: 0.75rem 1.25rem;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: var(--book-bg);
  color: var(--text-color);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
}

.speed-btn:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
  transform: scale(1.05);
}

.speed-btn:active {
  transform: scale(0.98);
}

.speed-play-pause {
  min-width: 60px;
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.speed-play-pause:hover {
  background: var(--accent-hover, var(--accent-color));
}

.play-icon {
  font-size: 1.2rem;
}

.speed-restart-btn-wrapper {
  display: flex;
  justify-content: center;
}

.speed-restart {
  background: transparent;
  border-color: var(--control-border);
}

.speed-restart:hover {
  background: var(--quote-bg);
  border-color: var(--text-color);
  color: var(--text-color);
  transform: none;
}

.speed-reader-help {
  padding: 0.75rem 1.5rem;
  text-align: center;
  border-top: 1px solid var(--control-border);
  background: var(--quote-bg);
}

.speed-reader-help small {
  font-size: 0.75rem;
  color: var(--text-muted, #999);
}

/* Mobile optimization */
@media (max-width: 768px) {
  .speed-reader-word {
    font-size: 2rem;
  }

  .speed-reader-display {
    padding: 2rem 1rem;
    min-height: 150px;
  }

  .speed-control-group {
    flex-wrap: wrap;
  }

  .speed-playback-controls {
    gap: 0.5rem;
  }

  .speed-btn {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
  }
}

/* ============================================================================
   AUTO-SCROLL MODE
   ============================================================================ */

.autoscroll-overlay {
  position: fixed;
  bottom: -200px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3500;
  transition: bottom 0.3s ease;
}

.autoscroll-overlay.active {
  bottom: 2rem;
}

.autoscroll-controls {
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.autoscroll-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.autoscroll-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-color);
  white-space: nowrap;
  position: relative;
  cursor: help;
}

.autoscroll-tooltip {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(5px);
  background: var(--control-bg-solid);
  color: var(--text-color);
  border: 1px solid var(--control-border);
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.75rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s 0.2s;
  z-index: 3600;
  box-shadow: 0 4px 12px var(--control-shadow);
  font-weight: 400;
}

.autoscroll-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--control-bg-solid);
}

.autoscroll-title:hover .autoscroll-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
  transition-delay: 0s, 0s, 0s;
}

.autoscroll-close {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-color);
  opacity: 0.6;
  transition: opacity 0.2s ease;
  padding: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.autoscroll-close:hover {
  opacity: 1;
}

.autoscroll-speed-presets {
  display: flex;
  gap: 0.25rem;
}

.autoscroll-preset-btn {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--book-bg);
  color: var(--text-color);
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.autoscroll-preset-btn:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.autoscroll-speed-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.autoscroll-speed-display {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  background: var(--quote-bg);
  border-radius: 4px;
  min-width: 70px;
  justify-content: center;
}

#autoscroll-speed-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-color);
}

.autoscroll-speed-unit {
  font-size: 0.65rem;
  color: var(--text-muted, #999);
  text-transform: uppercase;
}

.autoscroll-btn {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--book-bg);
  color: var(--text-color);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  min-width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.autoscroll-btn:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.autoscroll-playback {
  display: flex;
}

.autoscroll-btn-large {
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--accent-color);
  border-radius: 4px;
  background: var(--accent-color);
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  min-width: 50px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.autoscroll-btn-large:hover {
  background: var(--accent-hover, var(--accent-color));
}

.autoscroll-btn-large:active {
  transform: scale(0.95);
}

.autoscroll-help {
  display: none;
}

/* Hide navigation buttons when auto-scroll is active */
body.autoscroll-active .chapter-nav-buttons {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

@media (max-width: 768px) {
  .autoscroll-overlay.active {
    bottom: 1rem;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }

  .autoscroll-controls {
    padding: 0.4rem 0.6rem;
    gap: 0.5rem;
  }

  .autoscroll-speed-presets {
    display: none;
  }

  .autoscroll-title {
    font-size: 0.75rem;
  }
}
