/* ---------- Base Styles (unchanged) ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
  -webkit-tap-highlight-color: transparent;
  /* Remove tap highlight on mobile */
}

.container {
  max-width: 800px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  position: relative; /* anchor absolute elements like theme toggle */
}

h1 {
  text-align: center;
  color: #333;
  margin-bottom: 30px;
  font-size: 2.5rem;
  background: linear-gradient(45deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ---------- Line Indicator Styles ---------- */
.line-indicator {
  position: absolute;
  bottom: 10px;
  right: 15px;
  background: rgba(102, 126, 234, 0.1);
  color: #667eea;
  padding: 5px 10px;
  border-radius: 15px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid rgba(102, 126, 234, 0.2);
}

/* ---------- Line Numbers Styles ---------- */
.textarea-wrapper {
  position: relative;
  display: flex;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.3s ease;
  min-height: 150px;
  resize: vertical;
}

.textarea-wrapper:focus-within {
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.line-numbers {
  background: #f8f9fa;
  color: #6c757d;
  padding: 15px 10px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  text-align: right;
  min-width: 50px;
  border-right: 1px solid #e0e0e0;
  user-select: none;
  white-space: pre;
  overflow: hidden;
  height: 100%;
  min-height: 150px;
}

.textarea-with-lines {
  width: 100%;
  height: 100%;
  min-height: 150px;
  padding: 15px;
  border: none;
  font-size: 16px;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.5;
  overflow-y: auto;
}

/* ---------- Textbox Padding ---------- */

/* ---------- Existing UI Elements ---------- */
.input-section {
  margin-bottom: 30px;
  position: relative;
}

textarea {
  width: 100%;
  height: 150px;
  padding: 15px;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
  transition: border-color 0.3s ease;
}

textarea:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.controls {
  display: flex;
  gap: 20px;
  margin-bottom: 30px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

label {
  font-weight: 600;
  color: #555;
}

input[type="range"] {
  width: 150px;
}

select {
  padding: 8px 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: white;
  cursor: pointer;
  transition: border-color 0.3s ease;
}

select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.wpm-display {
  background: #667eea;
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: bold;
  min-width: 80px;
  text-align: center;
}

.buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

button {
  padding: 8px 14px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: none;
  letter-spacing: 0.3px;
}

.btn-primary {
  background: linear-gradient(45deg, #667eea, #764ba2);
  color: white;
}

.btn-secondary {
  background: #f8f9fa;
  color: #495057;
  border: 2px solid #dee2e6;
}

.btn-download {
}

.btn-secondary:hover:not(:disabled) {
  background: #e9ecef;
  border-color: #adb5bd;
}

#exportBtn,
#importBtn {
  background: #ecfbf5;
  color: #1c8d6b;
  border: 1px solid #c8efe3;
}

#exportBtn:hover,
#importBtn:hover {
  background: #e4f8f1;
  border-color: #b7ebde;
  color: #177a5d;
}

/* Calmer styling for "Export as MD" */
#exportMdBtn {
  background: #f7f8fa;
  color: #353b44;
  border: 1px solid #e1e6ef;
}
#exportMdBtn:hover {
  background: #f1f3f5;
  border-color: #d7dee8;
  color: #2a3140;
}

/* Dark theme overrides for export/import controls */
:root[data-theme="dark"] #exportBtn,
:root[data-theme="dark"] #importBtn {
  background: rgba(64, 214, 168, 0.12);
  color: #9af1d7;
  border: 1px solid rgba(64, 214, 168, 0.28);
}
:root[data-theme="dark"] #exportBtn:hover,
:root[data-theme="dark"] #importBtn:hover {
  background: rgba(64, 214, 168, 0.18);
  border-color: rgba(64, 214, 168, 0.4);
}
:root[data-theme="dark"] #exportMdBtn {
  background: #151922;
  color: #d0d5dd;
  border: 1px solid #2a2f3a;
}
:root[data-theme="dark"] #exportMdBtn:hover {
  background: #1b2030;
  border-color: #3a4155;
}

.btn-danger {
  background: linear-gradient(45deg, #ff6b6b, #ee5a24);
  color: white;
}

.btn-fullscreen {
  background: linear-gradient(45deg, #28a745, #20c997);
  color: white;
}

.btn-teleprompt {
  background: linear-gradient(45deg, #6f42c1, #e83e8c);
  color: white;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.reader-display {
  background: #fff;
  border: 3px solid #667eea;
  border-radius: 15px;
  padding: 40px;
  margin: 30px 0;
  text-align: center;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.current-word {
  font-size: 3rem;
  font-weight: bold;
  color: #000;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
  animation: wordPop 0.1s ease-out;
}

@keyframes wordPop {
  0% {
    transform: scale(0.9);
    opacity: 0.7;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.progress-container {
  background: #e9ecef;
  border-radius: 10px;
  height: 8px;
  margin: 20px 0;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(45deg, #667eea, #764ba2);
  width: 0%;
  transition: width 0.3s ease;
  border-radius: 10px;
}

.stats {
  display: flex;
  justify-content: space-around;
  text-align: center;
  margin-top: 20px;
  flex-wrap: wrap;
  gap: 20px;
}

.stat-item {
  background: rgba(102, 126, 234, 0.1);
  padding: 15px;
  border-radius: 10px;
  min-width: 120px;
}

.stat-number {
  font-size: 1.5rem;
  font-weight: bold;
  color: #667eea;
}

.stat-label {
  color: #666;
  font-size: 0.9rem;
  margin-top: 5px;
}

.completion-message {
  text-align: center;
  padding: 20px;
  background: linear-gradient(45deg, #52c234, #061700);
  color: white;
  border-radius: 10px;
  margin: 20px 0;
  display: none;
}

/* ---------- FIXED Fullscreen styles ---------- */
body.fullscreen {
  overflow: hidden;
}

.container.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  margin: 0;
  border-radius: 0;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 9999;
  display: flex;
  flex-direction: column;
  background: #000;
  color: white;
}

/* Hide all controls in fullscreen mode */
.container.fullscreen .input-section,
.container.fullscreen .controls,
.container.fullscreen .progress-container,
.container.fullscreen .stats,
.container.fullscreen .export-import-buttons,
.container.fullscreen #modeControls,
.container.fullscreen #visualControls,
.container.fullscreen #visualStats,
.container.fullscreen #exportImportButtons,
.container.fullscreen .collapsible-panel,
.container.fullscreen #textPanel {
  display: none !important;
}

.container.fullscreen h1 {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: 1.5rem;
  background: linear-gradient(45deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.container.fullscreen .buttons {
  /* Use same layout behavior as main toolbar (inside .reader-toolbar) */
  position: static;
  bottom: auto;
  left: auto;
  transform: none;
  margin: 0;
  z-index: 1000;
  opacity: 1;
  transition: none;
}

.container.fullscreen .buttons:hover {
  opacity: 1;
  /* Fully opaque on hover */
}

.container.fullscreen .reader-display {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0; /* no extra spacing */
  background: #000;
  border: none;
  padding: 40px;
  width: min(900px, 80vw); /* fixed width in fullscreen so line indicator stays static */
  z-index: 500; /* ensure above background but below overlays */
}

.container.fullscreen .current-word {
  font-size: 4rem;
  color: white;
  text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
}

.fullscreen-exit-hint {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.9rem;
  display: none;
}

.container.fullscreen .fullscreen-exit-hint {
  display: block;
}

/* Place the fullscreen toolbar at the bottom on large screens too */
.container.fullscreen .reader-toolbar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(max(20px, env(safe-area-inset-bottom)) + 10px);
  width: min(900px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  z-index: 1000;
}

.btn-exit-fullscreen {
  background: linear-gradient(45deg, #6c757d, #495057);
  color: white;
}

/* Modified completion message in fullscreen */
.container.fullscreen .completion-message {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;
  width: 80%;
  max-width: 500px;
  background: linear-gradient(45deg, #52c234, #061700);
}

/* ---------- New Styles for Read‑To‑Me Mode ---------- */
.read-to-me-section {
  display: none;
  margin-top: 20px;
  gap: 20px;
  flex-direction: column;
}

.read-to-me-section .control-group {
  flex-wrap: wrap;
}

.read-to-me-section input[type="password"] {
  flex: 1 1 240px;
  padding: 8px 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.3s ease;
}

.read-to-me-section input[type="password"]:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Uniform styling for Title and Read-to-Me API Key inputs */
#documentTitleInput,
#apiKeyInput {
  padding: 8px 12px !important;
  border: 2px solid #e0e0e0 !important;
  border-radius: 8px !important;
  font-size: 14px !important;
  height: 44px !important;
  line-height: 1.2;
  box-sizing: border-box;
}

#documentTitleInput:focus,
#apiKeyInput:focus {
  outline: none !important;
  border-color: #667eea !important;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
}

/* New styles for playback controls */
.playback-controls {
  display: flex;
  gap: 10px;
  margin-top: 15px;
  justify-content: center;
}

.speed-display {
  background: #667eea;
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: bold;
  min-width: 80px;
  text-align: center;
}

.style-prompt-section {
  margin-top: 15px;
}

.style-prompt-section textarea {
  height: 120px;
}

/* New styles for sentence navigation buttons */
.sentence-nav-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 15px;
}

.btn-sentence-nav {
  padding: 10px 15px;
  font-size: 14px;
}

/* FIXED: Repositioned sentence navigation buttons in fullscreen mode */
.container.fullscreen .sentence-nav-buttons {
  /* Use same layout behavior as main toolbar (stacked in .reader-toolbar) */
  position: static;
  bottom: auto;
  left: auto;
  transform: none;
  margin: 0;
  z-index: 1000;
  width: 100%;
  display: flex;
  flex-direction: row;
  gap: 10px;
  justify-content: center;
  opacity: 1;
  transition: none;
}

.container.fullscreen .sentence-nav-buttons:hover {
  opacity: 1;
}

.sentence-nav-buttons {
  opacity: 0.3;
  /* Make buttons semi-transparent by default */
  transition: opacity 0.3s ease;
}

.sentence-nav-buttons:hover {
  opacity: 0.8;
  /* Become more visible on hover */
}

.btn-sentence-nav {
  background-color: rgba(40, 40, 40, 0.7);
  /* Dark, semi-transparent background */
  border: 1px solid rgba(80, 80, 80, 0.5);
  /* Subtle border */
  color: rgba(200, 200, 200, 0.8);
  /* Muted text color */
  padding: 8px 12px;
  margin: 0 4px;
  border-radius: 4px;
  font-size: 12px;
  /* Smaller text */
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-sentence-nav:hover {
  background-color: rgba(60, 60, 60, 0.8);
  color: rgba(220, 220, 220, 0.9);
  border-color: rgba(100, 100, 100, 0.7);
}

.btn-sentence-nav:active {
  background-color: rgba(80, 80, 80, 0.9);
}

/* Fullscreen sizing to match Start/Pause buttons */
.container.fullscreen .btn-sentence-nav {
  flex: 0 0 auto;     /* do not stretch */
  max-width: none;    /* natural width + min-width */
  min-width: 100px;   /* similar footprint as other pills */
  padding: 12px 16px;
  font-size: 14px;
  min-height: 44px;
  border-radius: 18px;
}

/* Alternative: Even more subtle version */
.btn-sentence-nav.ultra-subtle {
  background-color: transparent;
  border: 1px solid rgba(60, 60, 60, 0.3);
  color: rgba(120, 120, 120, 0.6);
  font-size: 11px;
}

.btn-sentence-nav.ultra-subtle:hover {
  background-color: rgba(30, 30, 30, 0.5);
  color: rgba(160, 160, 160, 0.8);
  border-color: rgba(80, 80, 80, 0.5);
}

/* ---------- TOC Panel Styles ---------- */
.toc-panel {
  position: fixed;
  top: 20px;
  right: -350px;
  width: 320px;
  height: calc(100vh - 40px);
  background: rgba(255, 255, 255, 0.95);
  border-radius: 15px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(10px);
  transition: right 0.3s ease;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.toc-panel.visible {
  right: 20px;
}

.toc-panel.undocked {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  right: auto;
  width: 400px;
  height: 500px;
  z-index: 2000;
}

.toc-header {
  padding: 15px 20px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(45deg, #667eea, #764ba2);
  color: white;
  border-radius: 15px 15px 0 0;
}

.toc-title {
  font-weight: 600;
  font-size: 16px;
}

.toc-controls {
  display: flex;
  gap: 5px;
}

.toc-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.2s ease;
}

.toc-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.toc-content {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-item {
  margin-bottom: 8px;
}

.toc-link {
  display: block;
  padding: 8px 12px;
  text-decoration: none;
  color: #333;
  border-radius: 8px;
  transition: background-color 0.2s ease;
}

.toc-link:hover {
  background-color: rgba(102, 126, 234, 0.1);
}

.toc-empty {
  color: #666;
  font-style: italic;
  text-align: center;
  padding: 20px;
}

/* ---------- Key Terms List Styles ---------- */
/* ------------------------------------------------------------------ */
/* Key-Terms panel: make the content area a flex column and            */
/* be sure the scrolling list is allowed to shrink.                    */
/* ------------------------------------------------------------------ */
#keyTermsPanel {
  overflow: hidden; /* Ensure panel itself doesn't overflow */
}

#keyTermsPanel .toc-content {
  display: flex;
  flex-direction: column; /* header + body stack vertically */
  height: 100%; /* Take full height of parent */
  overflow: hidden; /* Prevent content overflow */
}

#keyTermsContent {
  /* the header + list wrapper      */
  flex: 1 1 0; /* Fill remaining space, can shrink to 0 */
  display: flex;
  flex-direction: column;
  min-height: 0; /* Allow shrinking below content size */
  overflow: hidden; /* Prevent overflow */
}

.key-terms-header {
  /* header never shrinks */
  flex: 0 0 auto;
  margin-bottom: 10px;
}

#keyTermsList,               /* the scrolling area itself      */
.key-terms-list {
  flex: 1 1 0; /* Fill remaining space, can shrink to 0 */
  overflow-y: auto; /* Enable scrolling */
  overflow-x: hidden; /* Hide horizontal overflow */
  min-height: 0; /* Critical: prevents bleed-out */
  max-height: none !important; /* Override any inline max-height */
}

/* ---------- TOC Toggle Button Styles ---------- */
.toc-toggle {
  position: fixed;
  right: 20px;
  background: linear-gradient(45deg, #667eea, #764ba2);
  color: white;
  border: none;
  padding: 12px 8px;
  border-radius: 8px 0 0 8px;
  cursor: pointer;
  font-size: 14px;
  z-index: 999;
  transition: all 0.3s ease;
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

/* Position tabs vertically - equally spaced and centered */
#notesToggle {
  top: 30%;
  transform: translateY(-50%);
}
#tocToggle {
  top: 40%;
  transform: translateY(-50%);
}

#keyTermsToggle {
  top: 50%;
  transform: translateY(-50%);
}

#assistantToggle {
  top: 60%;
  transform: translateY(-50%);
}

#helpDocsLink,
#readwiseToggle {
  top: 70%;
  transform: translateY(-50%);
}

.toc-toggle:hover {
    background: linear-gradient(45deg, #5a6fd8, #6a4190);
    transform: translateY(-50%) translateX(-5px);
}

/* Discreet Help FAB ("?") */
.help-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    text-decoration: none;
    font-weight: 800;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 22px rgba(0,0,0,.18);
    z-index: 900;
    opacity: 0.9;
    transition: transform .18s ease, opacity .18s ease, box-shadow .18s ease;
}
.help-fab:hover {
    transform: translateY(-2px) scale(1.03);
    opacity: 1;
    box-shadow: 0 14px 28px rgba(0,0,0,.22);
}
.help-fab:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 3px;
}
/* Hide in fullscreen reading */
body.fullscreen .help-fab {
    display: none !important;
}
@media (max-width: 600px) {
    .help-fab {
        right: 16px;
        bottom: 16px;
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
}

/* Responsive tab positioning */
@media (max-width: 1200px) {
  .toc-toggle {
    right: 12px;
    font-size: 10px;
    padding: 8px 4px;
    max-width: 60px;
  }
}

@media (max-width: 900px) {
  .toc-toggle {
    right: 8px;
    font-size: 9px;
    padding: 6px 3px;
    max-width: 50px;
  }
}

@media (max-width: 600px) {
  .toc-toggle {
    right: 5px;
    font-size: 8px;
    padding: 5px 2px;
    max-width: 40px;
    width: auto;
    min-width: 30px;
  }
}

@media (max-width: 480px) {
  .toc-toggle {
    position: fixed;
    right: 2px;
    font-size: 7px;
    padding: 3px 1px;
    max-width: 35px;
    width: auto;
    min-width: 25px;
    min-height: 20px;
    border-radius: 6px 0 0 6px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  /* Adjust vertical positioning for very small screens */
  #notesToggle {
    top: 25%;
  }
  #tocToggle {
    top: 35%;
  }

  #keyTermsToggle {
    top: 50%;
  }

  #assistantToggle {
    top: 65%;
  }

  #helpDocsLink,
  #readwiseToggle {
    top: 75%;
  }
}

/* Additional fix for very narrow screens */
@media (max-width: 360px) {
  .toc-toggle {
    right: 1px;
    font-size: 6px;
    padding: 2px 1px;
    max-width: 30px;
    min-width: 20px;
    min-height: 18px;
  }

  /* Stack buttons closer together on very small screens */
  #notesToggle {
    top: 34%;
  }
  #tocToggle {
    top: 42%;
  }

  #keyTermsToggle {
    top: 50%;
  }

  #assistantToggle {
    top: 58%;
  }

  #helpDocsLink,
  #readwiseToggle {
    top: 66%;
  }
}

/* Improved text editing buttons */
.text-edit-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.btn-text-edit {
  padding: 8px 12px;
  font-size: 12px;
  border-radius: 8px;
  text-transform: none;
  letter-spacing: normal;
  border: 1px solid #e0e0e0;
  background: white;
  color: #555;
  transition: all 0.2s ease;
  display: flex;
  align-items: center; /* vertical centering */
  justify-content: center; /* horizontal centering */
  gap: 4px;
}

.btn-text-edit:hover {
  background: #f8f9fa;
  border-color: #667eea;
  color: #667eea;
  transform: translateY(-1px);
}

/* Force all four buttons onto one row (no wrapping) */
.text-edit-buttons {
  flex-wrap: nowrap !important;
  overflow-x: auto;
}

.btn-text-edit {
  flex: 1 1 0;
  min-width: 0; /* Let buttons shrink more */
  white-space: nowrap;
}

/* --- Normalise word boxes so line‑breaks don't change --- */
.teleprompt-word,
.teleprompt-current-phrase-word,
.teleprompt-read-word,
.teleprompt-context-word {
  display: inline-block;
  padding: 2px 4px; /* identical on every state           */
  margin: 0 1px; /* identical on every state           */
  transition: background-color 0.2s, color 0.2s;
}

/* ---------- Document Editor Expand Button Responsive Styles ---------- */
.doc-editor-expand-btn {
  max-width: 120px !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  box-sizing: border-box !important;
}

@media (max-width: 768px) {
  .doc-editor-expand-btn {
    max-width: 100px !important;
    font-size: 11px !important;
    padding: 6px 8px !important;
    border-radius: 6px !important;
    right: 6px !important;
    top: 6px !important;
  }
}

@media (max-width: 480px) {
  .doc-editor-expand-btn {
    max-width: 80px !important;
    font-size: 10px !important;
    padding: 4px 6px !important;
    border-radius: 4px !important;
    right: 4px !important;
    top: 4px !important;
  }
}

@media (max-width: 360px) {
  .doc-editor-expand-btn {
    max-width: 70px !important;
    font-size: 9px !important;
    padding: 3px 5px !important;
    right: 3px !important;
    top: 3px !important;
  }
}

/* Ensure button doesn't interfere with parent container on very narrow screens */
@media (max-width: 320px) {
  .doc-editor-expand-btn {
    max-width: 60px !important;
    font-size: 8px !important;
    padding: 2px 4px !important;
    line-height: 1.2 !important;
  }
}

/* ---------- Enhanced Mobile Responsiveness ---------- */
@media (max-width: 768px) {
  body {
    padding: 10px;
    /* Reduce body padding on mobile */
  }

  .container {
    padding: 15px;
    border-radius: 15px;
    /* Slightly smaller radius on mobile */
  }

  h1 {
    font-size: 1.8rem;
    margin-bottom: 20px;
  }

  .current-word {
    font-size: 2.5rem;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 15px;
  }

  .control-group {
    justify-content: space-between;
    flex-wrap: wrap;
    /* Allow wrapping on very small screens */
  }

  .control-group label {
    min-width: 60px;
    /* Ensure labels have consistent width */
  }

  .control-group select {
    width: 100px;
    font-size: 16px;
    height: 44px;
    /* Larger touch target */
  }

  input[type="color"] {
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
  }

  .buttons {
    flex-direction: column;
    gap: 10px;
  }

  button {
    width: 100%;
    padding: 15px 20px;
    font-size: 18px;
    min-height: 54px;
    /* Larger touch target */
  }

  .reader-display {
    padding: 20px;
    min-height: 100px;
  }

  .stats {
    flex-direction: column;
    gap: 10px;
  }

  .stat-item {
    padding: 10px;
    min-width: auto;
  }

  textarea {
    height: 120px;
    font-size: 16px;
  }

  /* Improved text edit buttons on mobile */
  .text-edit-buttons {
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
  }

  .btn-text-edit {
    padding: 10px 12px;
    font-size: 12px;
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
  }

  /* TOC Panel mobile styles */
  .toc-panel {
    width: calc(100vw - 40px);
    right: -100vw;
    height: calc(100vh - 80px);
    top: 40px;
  }

  .toc-panel.visible {
    right: 20px;
  }

  .toc-panel.undocked {
    width: calc(100vw - 40px);
    height: calc(100vh - 80px);
    top: 40px;
    left: 20px;
    transform: none;
  }

  .toc-toggle {
    right: 10px;
    padding: 10px 6px;
    font-size: 12px;
  }

  /* Sentence navigation buttons on mobile */
  .sentence-nav-buttons {
    flex-wrap: wrap;
  }

  .btn-sentence-nav {
    flex: 1;
    min-height: 44px;
    /* Larger touch target */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
  }

  /* Fullscreen improvements for mobile */
  .container.fullscreen {
    padding: 10px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .container.fullscreen h1 {
    font-size: 1.2rem;
    top: 10px;
  }

  .container.fullscreen .current-word {
    font-size: min(3rem, 10vw);
    /* Responsive font size based on viewport width */
    padding: 0 10px;
    /* Ensure text doesn't touch edges */
  }

  .container.fullscreen .buttons {
    bottom: 60px;
    flex-direction: row;
    gap: 10px;
    width: 90%;
    /* Limit width to prevent overflow */
    flex-wrap: wrap;
    /* Allow wrapping on very small screens */
    justify-content: center;
  }

  .container.fullscreen button {
    width: auto;
    padding: 12px 16px;
    font-size: 14px;
    min-width: 80px;
    /* Ensure buttons have reasonable width */
    min-height: 44px;
    /* Larger touch target */
  }

  .fullscreen-exit-hint {
    font-size: 0.8rem;
    top: 35px;
  }

.container.fullscreen .fullscreen-exit-hint {
  display: block;
}

/* Fullscreen toolbar uses same flex column layout as main */
.container.fullscreen .reader-toolbar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(max(20px, env(safe-area-inset-bottom)) + 10px);
  width: min(900px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

  /* FIXED: Improved sentence navigation buttons positioning on narrow screens */
  .container.fullscreen .sentence-nav-buttons {
    /* Match main toolbar behavior on mobile */
    position: static;
    bottom: auto;
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
  }

  .container.fullscreen .btn-sentence-nav {
    flex: 1 1 40%;
    max-width: 48%;
    min-width: 110px;
    padding: 10px 0;
    font-size: 15px;
    min-height: 40px;
    border-radius: 18px;
  }

  /* Read-to-me section improvements for mobile */
  .read-to-me-section .control-group {
    margin-bottom: 15px;
  }

  .read-to-me-section input[type="password"],
  .read-to-me-section select {
    height: 44px;
    /* Larger touch target */
    font-size: 16px;
  }

  .playback-controls button {
    flex: 2;
    min-height: 54px;
    /* Larger touch target */
  }
}

/* Extra step-down for very narrow phones */
@media (max-width: 480px) {
  /* Ensure sentence nav clears multi-row visual controls */
  .container.fullscreen .sentence-nav-buttons {
    position: static;
    bottom: auto;
  }
}

/* Specific improvements for touch devices */
@media (hover: none) and (pointer: coarse) {
  button {
    min-height: 54px;
    /* Even larger touch targets on touch-only devices */
  }

  input[type="range"] {
    height: 40px;
    margin: 10px 0;
    /* Add vertical spacing */
  }

  .reader-display {
    min-height: 150px;
  }

  /* Make sliders easier to use on touch devices */
  input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }

  /* Improve tap targets for all interactive elements */
  select,
  input[type="color"],
  .btn-text-edit {
    min-height: 44px;
    min-width: 44px;
  }

  /* Add active state for better touch feedback */
  button:active,
  .btn-sentence-nav:active {
    transform: translateY(1px);
    opacity: 0.8;
  }
}

/* Specific improvements for small mobile devices */
@media (max-width: 380px) {
  .container.fullscreen .current-word {
    font-size: 8vw;
    /* Even smaller font on very small screens */
  }

  .container.fullscreen .buttons button {
    padding: 10px;
    font-size: 12px;
    min-width: 70px;
  }

  /* Match main toolbar behavior on very small screens */
  .container.fullscreen .sentence-nav-buttons {
    position: static;
    bottom: auto;
  }

  h1 {
    font-size: 1.5rem;
  }
}

/* ---------- Chapter Selection Modal Styles ---------- */
.chapter-selection-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
}

.chapter-selection-modal.visible {
  display: flex;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
}

.modal-content {
  position: relative;
  background: white;
  border-radius: 15px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 20px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(45deg, #667eea, #764ba2);
  color: white;
  border-radius: 15px 15px 0 0;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.modal-close-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.2s ease;
}

.modal-close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Fix: prevent modal header close buttons from stretching on mobile.
   Make them uniform and compact like other close buttons. */
.modal-header .modal-close-btn,
#readwiseModal .modal-header .modal-close-btn {
  width: auto !important;
  min-width: 0 !important;
  padding: 8px 12px;           /* keep consistent padding */
  border-radius: 8px;          /* slight rounding for consistency */
  display: inline-flex;        /* center the glyph inside */
  align-items: center;
  justify-content: center;
}

/* Optional tighter sizing for very small viewports */
@media (max-width: 480px) {
  .modal-header .modal-close-btn,
  #readwiseModal .modal-header .modal-close-btn {
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 16px;
  }
}

.modal-body {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.selection-controls {
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #e0e0e0;
}

.select-all-container {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-weight: 600;
  color: #333;
  font-size: 16px;
}

.select-all-container input[type="checkbox"] {
  margin-right: 10px;
  transform: scale(1.2);
}

.chapters-list {
  max-height: 300px;
  overflow-y: auto;
}

.chapter-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f0;
  transition: background-color 0.2s ease;
}

.chapter-item:hover {
  background-color: rgba(102, 126, 234, 0.05);
}

.chapter-item:last-child {
  border-bottom: none;
}

.chapter-checkbox {
  margin-right: 12px;
  transform: scale(1.1);
}

.chapter-title {
  flex: 1;
  color: #333;
  font-size: 14px;
  line-height: 1.4;
}

.chapter-preview {
  color: #666;
  font-size: 12px;
  margin-top: 4px;
  font-style: italic;
}

.modal-footer {
  padding: 20px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  gap: 15px;
  justify-content: flex-end;
  background: #f8f9fa;
  border-radius: 0 0 15px 15px;
}

.modal-footer button {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 100px;
}

/* Mobile responsiveness for modal */
@media (max-width: 768px) {
  .modal-content {
    width: 95%;
    max-height: 90vh;
  }

  .modal-header {
    padding: 15px;
  }

  .modal-header h3 {
    font-size: 16px;
  }

  .modal-body {
    padding: 15px;
  }

  .modal-footer {
    padding: 15px;
    flex-direction: column;
  }

  .modal-footer button {
    width: 100%;
    padding: 12px;
    font-size: 16px;
  }

  .chapters-list {
    max-height: 250px;
  }

  .chapter-item {
    padding: 15px 0;
  }

  .chapter-title {
    font-size: 15px;
  }

  /* Compact horizontal layout for visual buttons on mobile */
  .buttons#visualButtons {
    flex-direction: row !important;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }

  .buttons#visualButtons button {
    flex: 1 1 40%;
    max-width: 48%;
    min-width: 110px;
    padding: 10px 0;
    font-size: 15px;
    min-height: 40px;
    border-radius: 18px;
    width: auto;
  }

  /* Compact horizontal layout for export/import buttons on mobile */
  .buttons#exportImportButtons {
    flex-direction: row !important;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }

  .buttons#exportImportButtons button {
    flex: 1 1 30%;
    max-width: 32%;
    min-width: 100px;
    padding: 10px 0;
    font-size: 14px;
    min-height: 40px;
    border-radius: 18px;
    width: auto;
  }

  /* Fix for key terms remove button sizing on mobile */
  .btn-remove-keyterm {
    width: auto !important;
    min-width: 32px;
    max-width: 40px;
    flex: 0 0 auto !important;
    padding: 4px 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px !important;
    border-radius: 8px !important;
    margin-left: 8px;
  }

  .key-term-item > div {
    gap: 2px;
  }
}

/* ===================== */
/* Theme toggle button   */
/* ===================== */
.theme-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  opacity: 0.85;
  backdrop-filter: blur(6px);
  transition: transform 0.18s ease, opacity 0.18s ease, box-shadow 0.18s ease;
}
.theme-toggle:hover {
  opacity: 1;
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.16);
}
/* Hide in fullscreen reading */
.container.fullscreen .theme-toggle {
  display: none !important;
}

/* Subtle dark styling for the toggle when in dark mode or following system dark */
:root[data-theme="dark"] .theme-toggle {
  background: rgba(20, 22, 28, 0.85);
  color: #e6e6e6;
  border: 1px solid #2a2f3a;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}
:root[data-theme="dark"] .theme-toggle:hover {
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle {
    background: rgba(20, 22, 28, 0.85);
    color: #e6e6e6;
    border: 1px solid #2a2f3a;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  }
  :root:not([data-theme]) .theme-toggle:hover {
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.5);
  }
}

/* ======================================================= */
/* Dark theme overrides                                   */
/* - Applied when:                                        */
/*   1) User explicitly chooses dark: [data-theme="dark"] */
/*   2) System is dark and no explicit choice was made     */
/*      via @media(prefers-color-scheme: dark) block       */
/* ======================================================= */

/* 1) Explicit dark */
:root[data-theme="dark"] body {
  background: linear-gradient(135deg, #0b1020 0%, #151a2e 100%);
  color: #e6e6e6;
}
:root[data-theme="dark"] .container {
  background: rgba(16, 18, 24, 0.92);
  color: #e6e6e6;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}
:root[data-theme="dark"] label,
:root[data-theme="dark"] .stat-label {
  color: #c6c6c6;
}
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] .textarea-with-lines {
  background: #0f1117;
  color: #e6e6e6;
}
:root[data-theme="dark"] .textarea-wrapper {
  border-color: #2a2f3a;
}
:root[data-theme="dark"] .line-numbers {
  background: #0b0d13;
  color: #9aa4b2;
  border-right: 1px solid #2a2f3a;
}
:root[data-theme="dark"] select {
  background: #0f1117;
  color: #e6e6e6;
  border-color: #2a2f3a;
}

/* Dark mode for Title and Read-to-Me API Key inputs */
:root[data-theme="dark"] #documentTitleInput,
:root[data-theme="dark"] #apiKeyInput {
  background: #0f1117 !important;
  color: #e6e6e6 !important;
  border-color: #2a2f3a !important;
}
:root[data-theme="dark"] #stylePromptInput {
  background: #0f1117 !important;
  color: #e6e6e6 !important;
  border-color: #2a2f3a !important; /* was #e0e0e0 in dark; set to requested #2a2f3a */
}
:root[data-theme="dark"] .btn-secondary {
  background: #151922;
  color: #d0d5dd;
  border: 2px solid #2a2f3a;
}
:root[data-theme="dark"] .btn-secondary:hover:not(:disabled) {
  background: #1b2030;
  border-color: #3a4155;
}
:root[data-theme="dark"] .reader-display {
  background: #0f1117;
  border: 3px solid #4452c0; /* softened blue border for dark */
}
:root[data-theme="dark"] .current-word {
  color: #ffffff;
  text-shadow: none;
}
:root[data-theme="dark"] .progress-container {
  background: #2a2f3a;
}
:root[data-theme="dark"] .stat-item {
  background: rgba(102, 126, 234, 0.08);
}
:root[data-theme="dark"] .toc-panel {
  background: rgba(16, 18, 24, 0.96);
  color: #e6e6e6;
  border: 1px solid #2a2f3a;
}
:root[data-theme="dark"] .toc-link {
  color: #e6e6e6;
}
:root[data-theme="dark"] .toc-empty {
  color: #9aa4b2;
}
:root[data-theme="dark"] .line-indicator {
  background: rgba(102, 126, 234, 0.15);
  color: #b7c0ff;
  border: 1px solid rgba(102, 126, 234, 0.25);
}
:root[data-theme="dark"] .modal-content {
  background: #12151c;
  color: #e6e6e6;
}
:root[data-theme="dark"] .modal-footer {
  background: #0f1117;
  border-top: 1px solid #2a2f3a;
}
:root[data-theme="dark"] .selection-controls {
  border-bottom: 1px solid #2a2f3a;
}
:root[data-theme="dark"] .chapter-item {
  border-bottom: 1px solid #1d2230;
}
:root[data-theme="dark"] .chapter-item:hover {
  background-color: rgba(102, 126, 234, 0.08);
}
:root[data-theme="dark"] .chapter-title {
  color: #e6e6e6;
}
:root[data-theme="dark"] .chapter-preview {
  color: #9aa4b2;
}
:root[data-theme="dark"] .help-fab {
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.5);
}

/* AI Features (dark) */
:root[data-theme="dark"] .ai-config-section {
  background: #151922 !important;
  border: 1px solid #2a2f3a !important;
}
:root[data-theme="dark"] #summaryDisplay,
:root[data-theme="dark"] #quizDisplay {
  background: #0f1117 !important;
  border: 2px solid #2a2f3a !important;
  color: #e6e6e6;
}
/* Inputs/selects inside AI config have inline borders; override them */
:root[data-theme="dark"] #aiProviderSelect,
:root[data-theme="dark"] #aiModelSelect,
:root[data-theme="dark"] #aiApiKeyInput {
  background: #0f1117 !important;
  color: #e6e6e6 !important;
  border-color: #2a2f3a !important;
}
/* Tweak headings for readability on dark */
:root[data-theme="dark"] #summarySection h3,
:root[data-theme="dark"] #quizSection h3 {
  color: #9bb0ff;
}

/* Reasoning Settings (explicit dark) */
:root[data-theme="dark"] .ai-config-section [style*="background: #f0f4ff"],
:root[data-theme="dark"] .ai-config-section [style*="background:#f0f4ff"] {
  background: #1a1f2e !important;
}
:root[data-theme="dark"] .ai-config-section [style*="border: 1px solid #d0d7ff"],
:root[data-theme="dark"] .ai-config-section [style*="border:1px solid #d0d7ff"] {
  border-color: #3a4155 !important;
}
:root[data-theme="dark"] .ai-config-section [style*="color: #4f46e5"],
:root[data-theme="dark"] .ai-config-section [style*="color:#4f46e5"] {
  color: #9bb0ff !important;
}
:root[data-theme="dark"] #reasoningEffortSelect,
:root[data-theme="dark"] #reasoningMaxTokensInput {
  background: #0f1117 !important;
  color: #e6e6e6 !important;
  border-color: #3a4155 !important;
}
:root[data-theme="dark"] .ai-config-section [style*="border: 1px solid #d0d7ff"] select,
:root[data-theme="dark"] .ai-config-section [style*="border:1px solid #d0d7ff"] select {
  background: #0f1117 !important;
  color: #e6e6e6 !important;
  border-color: #3a4155 !important;
}
:root[data-theme="dark"] #reasoningModelSupport {
  color: #9aa4b2 !important;
}

/* MD Exporter Modal Styles */
.md-exporter-modal {
  position: fixed;
  z-index: 10000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.md-exporter-modal-content {
  background: white;
  margin: 10% auto;
  padding: 20px;
  border-radius: 15px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.md-exporter-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid #667eea;
}

.md-exporter-modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #667eea;
}

.md-exporter-modal-close {
  color: #aaa;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.2s ease;
}

.md-exporter-modal-close:hover {
  color: #667eea;
}

.md-exporter-form-group {
  margin-bottom: 15px;
}

.md-exporter-label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
  color: #333;
}

.md-exporter-select,
.md-exporter-input {
  width: 100%;
  padding: 10px;
  border: 2px solid #e0e0e0;
  border-radius: 5px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.3s ease;
}

.md-exporter-select:focus,
.md-exporter-input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.md-exporter-help-text {
  color: #666;
  font-size: 12px;
  margin-top: 5px;
  display: block;
}

.md-exporter-checkbox-group {
  margin-bottom: 20px;
}

.md-exporter-checkbox-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  color: #333;
}

.md-exporter-checkbox {
  margin-right: 10px;
}

.md-exporter-debug {
  margin-bottom: 15px;
  padding: 10px;
  background: #f0f0f0;
  border-radius: 5px;
  font-family: monospace;
  font-size: 12px;
  border: 1px solid #e0e0e0;
}

.md-exporter-modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid #e0e0e0;
}

/* AI Configuration Modal (explicit dark) - match existing modal pattern */
:root[data-theme="dark"] .ai-config-modal {
  background: rgba(0, 0, 0, 0.6) !important;
}
:root[data-theme="dark"] .ai-config-modal div {
  background: #12151c !important;
  color: #e6e6e6 !important;
}
:root[data-theme="dark"] .ai-config-modal > div {
  background: #12151c !important;
  color: #e6e6e6 !important;
  border: 1px solid #2a2f3a !important;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6) !important;
}

/* MD Exporter Modal Dark Theme */
:root[data-theme="dark"] .md-exporter-modal {
  background-color: rgba(0, 0, 0, 0.6);
}

:root[data-theme="dark"] .md-exporter-modal-content {
  background: #12151c;
  color: #e6e6e6;
  border: 1px solid #2a2f3a;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

:root[data-theme="dark"] .md-exporter-modal-header {
  border-bottom: 2px solid #9bb0ff;
}

:root[data-theme="dark"] .md-exporter-modal-header h3 {
  color: #9bb0ff;
}

:root[data-theme="dark"] .md-exporter-modal-close {
  color: #9aa4b2;
}

:root[data-theme="dark"] .md-exporter-modal-close:hover {
  color: #9bb0ff;
}

:root[data-theme="dark"] .md-exporter-label {
  color: #e6e6e6;
}

:root[data-theme="dark"] .md-exporter-select,
:root[data-theme="dark"] .md-exporter-input {
  background: #0f1117;
  color: #e6e6e6;
  border: 2px solid #2a2f3a;
}

:root[data-theme="dark"] .md-exporter-select:focus,
:root[data-theme="dark"] .md-exporter-input:focus {
  border-color: #9bb0ff;
  box-shadow: 0 0 0 3px rgba(155, 176, 255, 0.1);
}

:root[data-theme="dark"] .md-exporter-help-text {
  color: #9aa4b2;
}

:root[data-theme="dark"] .md-exporter-checkbox-label {
  color: #e6e6e6;
}

:root[data-theme="dark"] .md-exporter-checkbox {
  accent-color: #9bb0ff;
}

:root[data-theme="dark"] .md-exporter-debug {
  background: #0f1117;
  border: 1px solid #2a2f3a;
  color: #e6e6e6;
}

:root[data-theme="dark"] .md-exporter-modal-footer {
  border-top: 1px solid #2a2f3a;
}

/* All AI modals - use same pattern as working modals */
:root[data-theme="dark"] .custom-summary-modal div,
:root[data-theme="dark"] .quiz-generation-modal div,
:root[data-theme="dark"] .quiz-options-modal div,
:root[data-theme="dark"] .quiz-modal div {
  background: #12151c !important;
  color: #e6e6e6 !important;
}
:root[data-theme="dark"] .custom-summary-modal > div,
:root[data-theme="dark"] .quiz-generation-modal > div,
:root[data-theme="dark"] .quiz-options-modal > div,
:root[data-theme="dark"] .quiz-modal .quiz-modal-content {
  background: #12151c !important;
  color: #e6e6e6 !important;
  border: 1px solid #2a2f3a !important;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6) !important;
}

/* Modal headings in dark theme */
:root[data-theme="dark"] .ai-config-modal h3,
:root[data-theme="dark"] .custom-summary-modal h3,
:root[data-theme="dark"] .quiz-generation-modal h3,
:root[data-theme="dark"] .quiz-options-modal h3,
:root[data-theme="dark"] .quiz-modal h2 {
  color: #9bb0ff !important;
}

/* Custom Summary Modal (explicit dark) */
:root[data-theme="dark"] .custom-summary-modal {
  background: rgba(0, 0, 0, 0.6) !important;
}
:root[data-theme="dark"] .custom-summary-modal > div {
  background: #12151c !important;
  color: #e6e6e6 !important;
  border: 1px solid #2a2f3a !important;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6) !important;
}
:root[data-theme="dark"] .custom-summary-modal h3,
:root[data-theme="dark"] .custom-summary-modal h4 {
  color: #9bb0ff !important;
}
:root[data-theme="dark"] .custom-summary-modal textarea {
  background: #0f1117 !important;
  color: #e6e6e6 !important;
  border: 2px solid #2a2f3a !important;
}
:root[data-theme="dark"] .custom-summary-modal textarea::placeholder {
  color: #9aa4b2 !important;
}
:root[data-theme="dark"] .custom-summary-modal .preset-btn {
  background: #151922 !important;
  color: #d0d5dd !important;
  border: 2px solid #2a2f3a !important;
}
:root[data-theme="dark"] .custom-summary-modal .preset-btn:hover {
  background: #1b2030 !important;
  border-color: #3a4155 !important;
}

/* Quiz Generation Modal (explicit dark) */
:root[data-theme="dark"] .quiz-generation-modal {
  background: rgba(0, 0, 0, 0.6) !important;
}
:root[data-theme="dark"] .quiz-generation-modal > div {
  background: #12151c !important;
  color: #e6e6e6 !important;
  border: 1px solid #2a2f3a !important;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6) !important;
}
:root[data-theme="dark"] .quiz-generation-modal h3,
:root[data-theme="dark"] .quiz-generation-modal h4 {
  color: #9bb0ff !important;
}
:root[data-theme="dark"] .quiz-generation-modal select,
:root[data-theme="dark"] .quiz-generation-modal input[type="number"] {
  background: #0f1117 !important;
  color: #e6e6e6 !important;
  border: 2px solid #2a2f3a !important;
}
:root[data-theme="dark"] .quiz-generation-modal .quiz-count-btn {
  background: #151922 !important;
  color: #d0d5dd !important;
  border: 2px solid #2a2f3a !important;
}
:root[data-theme="dark"] .quiz-generation-modal .quiz-count-btn:hover {
  background: #1b2030 !important;
  border-color: #3a4155 !important;
}
:root[data-theme="dark"] .quiz-generation-modal label {
  color: #e6e6e6 !important;
}
:root[data-theme="dark"] .quiz-generation-modal input[type="checkbox"] {
  accent-color: #9bb0ff !important;
}
:root[data-theme="dark"] .ai-config-modal h3 {
  color: #9bb0ff !important;
}
:root[data-theme="dark"] .ai-config-modal h4 {
  color: #c6c6ff !important;
}
:root[data-theme="dark"] .ai-config-modal select,
:root[data-theme="dark"] .ai-config-modal input[type="text"],
:root[data-theme="dark"] .ai-config-modal input[type="password"],
:root[data-theme="dark"] .ai-config-modal textarea {
  background: #0f1117 !important;
  color: #e6e6e6 !important;
  border: 2px solid #2a2f3a !important;
}
:root[data-theme="dark"] .ai-config-modal a {
  color: #9bb0ff !important;
}
:root[data-theme="dark"] .ai-config-modal #apiKeyHelp,
:root[data-theme="dark"] .ai-config-modal #ollamaHelp {
  background: #0f1117 !important;
  border: 1px solid #2a2f3a !important;
  color: #c6c6c6 !important;
}
:root[data-theme="dark"] .ai-config-modal [style*="color:#666"],
:root[data-theme="dark"] .ai-config-modal [style*="color: #666"] {
  color: #9aa4b2 !important;
}
:root[data-theme="dark"] .ai-config-modal [style*="border: 2px solid #e0e0e0"],
:root[data-theme="dark"] .ai-config-modal [style*="border:2px solid #e0e0e0"],
:root[data-theme="dark"] .ai-config-modal [style*="border: 1px solid #e0e0e0"],
:root[data-theme="dark"] .ai-config-modal [style*="border:1px solid #e0e0e0"] {
  border-color: #2a2f3a !important;
}
:root[data-theme="dark"] .ai-config-modal [style*="background:#f8f9fa"],
:root[data-theme="dark"] .ai-config-modal [style*="background: #f8f9fa"],
:root[data-theme="dark"] .ai-config-modal [style*="background:#e8f5e8"],
:root[data-theme="dark"] .ai-config-modal [style*="background: #e8f5e8"] {
  background: #0f1117 !important;
  color: #c6c6c6 !important;
  border-color: #2a2f3a !important;
}

/* AssistantInfoSection (explicit dark) */
:root[data-theme="dark"] .ai-config-modal #assistantInfoSection {
  background: #0f1117 !important;
  border: 1px dashed #2a2f3a !important;
  color: #c6c6c6 !important;
}
:root[data-theme="dark"] .ai-config-modal #assistantInfoBody {
  color: #c6c6c6 !important;
}
:root[data-theme="dark"] .ai-config-modal #toggleAssistantInfoBtn {
  background: #151922 !important;
  color: #d0d5dd !important;
  border: 1px solid #2a2f3a !important;
}

/* Assistant panel (explicit dark) */
:root[data-theme="dark"] #assistantPanel .chat-messages {
  background: #0f1117 !important;
  border-bottom: 1px solid #2a2f3a !important;
  color: #e6e6e6;
}
:root[data-theme="dark"] #assistantPanel .assistant-message .message-content {
  background: #151922 !important;
  color: #e6e6e6 !important;
  border: 1px solid #2a2f3a !important;
}
:root[data-theme="dark"] #assistantPanel .message-header {
  color: #9aa4b2 !important;
}
:root[data-theme="dark"] #assistantPanel .system-message .message-content {
  background: #0e223d !important;
  color: #9bc1ff !important;
  border-color: #274b78 !important;
}
:root[data-theme="dark"] #assistantPanel .error-message .message-content {
  background: #3b1f22 !important;
  color: #ffb4b4 !important;
  border-color: #7a2f36 !important;
}
:root[data-theme="dark"] #assistantPanel .chat-input-container {
  background: #12151c !important;
  border-top: 1px solid #2a2f3a !important;
  box-shadow: 0 -6px 10px -8px rgba(0, 0, 0, 0.6) !important;
}
:root[data-theme="dark"] #assistantPanel #chatInput {
  background: #0f1117 !important;
  color: #e6e6e6 !important;
  border-color: #2a2f3a !important;
}
:root[data-theme="dark"] #assistantPanel .context-indicator {
  background: #0f1117 !important;
  color: #c6c6c6 !important;
}

/* Readwise panel (explicit dark) */
:root[data-theme="dark"] #readwisePanel {
  background: #151922 !important;
  border-color: #2a2f3a !important;
  color: #e6e6e6;
}
:root[data-theme="dark"] #readwisePanel input,
:root[data-theme="dark"] #readwisePanel select {
  background: #0f1117 !important;
  color: #e6e6e6 !important;
  border-color: #2a2f3a !important;
}
:root[data-theme="dark"] #readwisePanel .rw-multi-menu {
  background: #0f1117 !important;
  border-color: #2a2f3a !important;
}
:root[data-theme="dark"] #readwisePanel .rw-multi-item:hover {
  background: #1b2030 !important;
}
/* Override inline light backgrounds/borders within Readwise panel */
:root[data-theme="dark"] #readwisePanel [style*="background:#fff"],
:root[data-theme="dark"] #readwisePanel [style*="background: #fff"] {
  background: #0f1117 !important;
  color: #e6e6e6 !important;
}
:root[data-theme="dark"] #readwisePanel [style*="background:#fafbff"],
:root[data-theme="dark"] #readwisePanel [style*="background: #fafbff"],
:root[data-theme="dark"] #readwisePanel [style*="background:#f7f8ff"],
:root[data-theme="dark"] #readwisePanel [style*="background: #f7f8ff"] {
  background: #151922 !important;
  color: #e6e6e6 !important;
}
:root[data-theme="dark"] #readwisePanel [style*="border:1px solid #e0e0e0"],
:root[data-theme="dark"] #readwisePanel [style*="border: 1px solid #e0e0e0"],
:root[data-theme="dark"] #readwisePanel [style*="border:2px solid #e0e0e0"],
:root[data-theme="dark"] #readwisePanel [style*="border: 2px solid #e0e0e0"] {
  border-color: #2a2f3a !important;
}
:root[data-theme="dark"] #readwisePanel [style*="color:#333"],
:root[data-theme="dark"] #readwisePanel [style*="color: #333"] {
  color: #e6e6e6 !important;
}
:root[data-theme="dark"] #readwisePanel [style*="color:#666"],
:root[data-theme="dark"] #readwisePanel [style*="color: #666"] {
  color: #9aa4b2 !important;
}

/* Subdued Readwise multi-toggle (baseline, higher specificity to override injected styles) */
:root #readwisePanel .rw-multi-toggle {
  background: #f7f8fa;
  color: #353b44;
  border: 1px solid #e1e6ef;
  border-radius: 10px;
  padding: 6px 10px; /* keep compact size */
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
:root #readwisePanel .rw-multi-toggle:hover {
  background: #f1f3f5;
  border-color: #d7dee8;
  color: #2a3140;
}
:root #readwisePanel .rw-multi-toggle:focus-visible {
  outline: 2px solid #9bb0ff;
  outline-offset: 2px;
}

/* Light theme: selected category chips inside menu */
#readwisePanel .rw-multi-item input:checked + span {
  color: #4c57c3;
  background: #eef1ff;
  border-radius: 6px;
  padding: 0 4px;
}

/* Dark theme subdued toggle */
:root[data-theme="dark"] #readwisePanel .rw-multi-toggle {
  background: #151922;
  color: #d0d5dd;
  border: 1px solid #2a2f3a;
  border-radius: 10px;
}
:root[data-theme="dark"] #readwisePanel .rw-multi-toggle:hover {
  background: #1b2030;
  border-color: #3a4155;
}
:root[data-theme="dark"] #readwisePanel .rw-multi-toggle:focus-visible {
  outline: 2px solid #9bb0ff;
  outline-offset: 2px;
}

/* Dark theme: selected category chips inside menu */
:root[data-theme="dark"] #readwisePanel .rw-multi-item input:checked + span {
  color: #b9c0ff;
  background: rgba(155,176,255,0.14);
  border-radius: 6px;
  padding: 0 4px;
}

/* Readwise list uniform dark styling */
:root[data-theme="dark"] #readwisePanel .rw-list {
  background: #0f1117 !important;
  border-color: #2a2f3a !important;
}
:root[data-theme="dark"] #readwisePanel .rw-list-header {
  background: #12151c !important;
  color: #e6e6e6 !important;
  border-bottom: 1px solid #2a2f3a !important;
}
:root[data-theme="dark"] #readwisePanel .rw-list-row {
  background: transparent !important;
}
:root[data-theme="dark"] #readwisePanel .rw-list-row > div {
  color: #e6e6e6 !important;
}
/* Convert light separators in generated rows to dark */
:root[data-theme="dark"] #readwisePanel [style*="border-top:1px solid #eee"],
:root[data-theme="dark"] #readwisePanel [style*="border-top: 1px solid #eee"] {
  border-top: 1px solid #2a2f3a !important;
}

/* Notes & Tags panel (explicit dark) */
:root[data-theme="dark"] #notesPanel {
  background: rgba(16, 18, 24, 0.96) !important;
  border: 1px solid #2a2f3a !important;
  color: #e6e6e6 !important;
}
:root[data-theme="dark"] #notesPanel .toc-content {
  color: #e6e6e6 !important;
}
:root[data-theme="dark"] #notesPanel label {
  color: #e6e6e6 !important;
}
:root[data-theme="dark"] #notesPanel textarea,
:root[data-theme="dark"] #notesPanel input[type="text"] {
  background: #0f1117 !important;
  color: #e6e6e6 !important;
  border: 2px solid #2a2f3a !important;
}
:root[data-theme="dark"] #notesPanel textarea::placeholder,
:root[data-theme="dark"] #notesPanel input[type="text"]::placeholder {
  color: #9aa4b2 !important;
}
:root[data-theme="dark"] #notesPanel textarea:focus,
:root[data-theme="dark"] #notesPanel input[type="text"]:focus {
  outline: none !important;
  border-color: #3a4155 !important;
  box-shadow: 0 0 0 3px rgba(155,176,255,0.18) !important;
}
:root[data-theme="dark"] #notesPanel #selectionActionsHint {
  color: #9aa4b2 !important;
}
:root[data-theme="dark"] #notesPanel .toc-btn,
:root[data-theme="dark"] #notesPanel button {
  background: #151922 !important;
  color: #d0d5dd !important;
  border: 1px solid #2a2f3a !important;
}
:root[data-theme="dark"] #notesPanel [style*="border:2px solid #e0e0e0"],
:root[data-theme="dark"] #notesPanel [style*="border: 2px solid #e0e0e0"],
:root[data-theme="dark"] #notesPanel [style*="border:1px solid #e0e0e0"],
:root[data-theme="dark"] #notesPanel [style*="border: 1px solid #e0e0e0"] {
  border-color: #2a2f3a !important;
}
:root[data-theme="dark"] #notesPanel [style*="color:#333"],
:root[data-theme="dark"] #notesPanel [style*="color: #333"] {
  color: #e6e6e6 !important;
}
:root[data-theme="dark"] #notesPanel [style*="color:#666"],
:root[data-theme="dark"] #notesPanel [style*="color: #666"] {
  color: #9aa4b2 !important;
}

/* Keep fullscreen appearance constant across themes (explicit dark) */
:root[data-theme="dark"] .container.fullscreen {
  background: #000 !important;
  color: #fff !important;
}
:root[data-theme="dark"] .container.fullscreen .reader-display {
  background: #000 !important;
  border: none !important;
}
:root[data-theme="dark"] .container.fullscreen .current-word {
  color: #fff !important;
  text-shadow: 2px 2px 8px rgba(0,0,0,0.5) !important;
}
:root[data-theme="dark"] .container.fullscreen .buttons {
  opacity: 0.3 !important;
}

/* 2) Follow system dark if user has not explicitly chosen */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) body {
    background: linear-gradient(135deg, #0b1020 0%, #151a2e 100%);
    color: #e6e6e6;
  }
  :root:not([data-theme]) .container {
    background: rgba(16, 18, 24, 0.92);
    color: #e6e6e6;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  }
  :root:not([data-theme]) label,
  :root:not([data-theme]) .stat-label {
    color: #c6c6c6;
  }
  :root:not([data-theme]) textarea,
  :root:not([data-theme]) .textarea-with-lines {
    background: #0f1117;
    color: #e6e6e6;
  }
  :root:not([data-theme]) .textarea-wrapper {
    border-color: #2a2f3a;
  }
  :root:not([data-theme]) .line-numbers {
    background: #0b0d13;
    color: #9aa4b2;
    border-right: 1px solid #2a2f3a;
  }
  :root:not([data-theme]) select {
    background: #0f1117;
    color: #e6e6e6;
    border-color: #2a2f3a;
  }

  /* System dark (no explicit choice) for Title and API Key inputs */
  :root:not([data-theme]) #documentTitleInput,
  :root:not([data-theme]) #apiKeyInput {
    background: #0f1117 !important;
    color: #e6e6e6 !important;
    border-color: #2a2f3a !important;
  }
  :root:not([data-theme]) #exportBtn,
  :root:not([data-theme]) #importBtn {
    background: rgba(64, 214, 168, 0.12);
    color: #9af1d7;
    border: 1px solid rgba(64, 214, 168, 0.28);
  }
  :root:not([data-theme]) #exportBtn:hover,
  :root:not([data-theme]) #importBtn:hover {
    background: rgba(64, 214, 168, 0.18);
    border-color: rgba(64, 214, 168, 0.4);
  }
  :root:not([data-theme]) #exportMdBtn {
    background: #151922;
    color: #d0d5dd;
    border: 1px solid #2a2f3a;
  }
  :root:not([data-theme]) #exportMdBtn:hover {
    background: #1b2030;
    border-color: #3a4155;
  }
  :root:not([data-theme]) #stylePromptInput {
    background: #0f1117 !important;
    color: #e6e6e6 !important;
    border-color: #2a2f3a !important; /* align with explicit dark */
  }
  :root:not([data-theme]) .btn-secondary {
    background: #151922;
    color: #d0d5dd;
    border: 2px solid #2a2f3a;
  }
  :root:not([data-theme]) .btn-secondary:hover:not(:disabled) {
    background: #1b2030;
    border-color: #3a4155;
  }
  :root:not([data-theme]) .reader-display {
    background: #0f1117;
    border: 3px solid #4452c0;
  }
  :root:not([data-theme]) .current-word {
    color: #ffffff;
    text-shadow: none;
  }
  :root:not([data-theme]) .progress-container {
    background: #2a2f3a;
  }
  :root:not([data-theme]) .stat-item {
    background: rgba(102, 126, 234, 0.08);
  }
  :root:not([data-theme]) .toc-panel {
    background: rgba(16, 18, 24, 0.96);
    color: #e6e6e6;
    border: 1px solid #2a2f3a;
  }
  :root:not([data-theme]) .toc-link {
    color: #e6e6e6;
  }
  :root:not([data-theme]) .toc-empty {
    color: #9aa4b2;
  }
  :root:not([data-theme]) .line-indicator {
    background: rgba(102, 126, 234, 0.15);
    color: #b7c0ff;
    border: 1px solid rgba(102, 126, 234, 0.25);
  }
  :root:not([data-theme]) .modal-content {
    background: #12151c;
    color: #e6e6e6;
  }
  :root:not([data-theme]) .modal-footer {
    background: #0f1117;
    border-top: 1px solid #2a2f3a;
  }
  :root:not([data-theme]) .selection-controls {
    border-bottom: 1px solid #2a2f3a;
  }
  :root:not([data-theme]) .chapter-item {
    border-bottom: 1px solid #1d2230;
  }
  :root:not([data-theme]) .chapter-item:hover {
    background-color: rgba(102, 126, 234, 0.08);
  }
  :root:not([data-theme]) .chapter-title {
    color: #e6e6e6;
  }
  :root:not([data-theme]) .chapter-preview {
    color: #9aa4b2;
  }
  :root:not([data-theme]) .help-fab {
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.5);
  }

  /* AI Features (system dark when no explicit choice) */
  :root:not([data-theme]) .ai-config-section {
    background: #151922 !important;
    border: 1px solid #2a2f3a !important;
  }
  :root:not([data-theme]) #summaryDisplay,
  :root:not([data-theme]) #quizDisplay {
    background: #0f1117 !important;
    border: 2px solid #2a2f3a !important;
    color: #e6e6e6;
  }
  :root:not([data-theme]) #aiProviderSelect,
  :root:not([data-theme]) #aiModelSelect,
  :root:not([data-theme]) #aiApiKeyInput {
    background: #0f1117 !important;
    color: #e6e6e6 !important;
    border-color: #2a2f3a !important;
  }
  :root:not([data-theme]) #summarySection h3,
  :root:not([data-theme]) #quizSection h3 {
    color: #9bb0ff;
  }

  /* AI Configuration Modal (system dark) - match existing modal pattern */
  :root:not([data-theme]) .ai-config-modal {
    background: rgba(0, 0, 0, 0.6) !important;
  }
  :root:not([data-theme]) .ai-config-modal div {
    background: #12151c !important;
    color: #e6e6e6 !important;
  }
  :root:not([data-theme]) .ai-config-modal > div {
    background: #12151c !important;
    color: #e6e6e6 !important;
    border: 1px solid #2a2f3a !important;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6) !important;
  }

  /* All AI modals - use same pattern as working modals (system dark) */
  :root:not([data-theme]) .custom-summary-modal div,
  :root:not([data-theme]) .quiz-generation-modal div,
  :root:not([data-theme]) .quiz-options-modal div,
  :root:not([data-theme]) .quiz-modal div {
    background: #12151c !important;
    color: #e6e6e6 !important;
  }
  :root:not([data-theme]) .custom-summary-modal > div,
  :root:not([data-theme]) .quiz-generation-modal > div,
  :root:not([data-theme]) .quiz-options-modal > div,
  :root:not([data-theme]) .quiz-modal .quiz-modal-content {
    background: #12151c !important;
    color: #e6e6e6 !important;
    border: 1px solid #2a2f3a !important;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6) !important;
  }

  /* Modal headings in dark theme (system dark) */
  :root:not([data-theme]) .ai-config-modal h3,
  :root:not([data-theme]) .custom-summary-modal h3,
  :root:not([data-theme]) .quiz-generation-modal h3,
  :root:not([data-theme]) .quiz-options-modal h3,
  :root:not([data-theme]) .quiz-modal h2 {
    color: #9bb0ff !important;
  }

  /* Custom Summary Modal (system dark) */
  :root:not([data-theme]) .custom-summary-modal {
    background: rgba(0, 0, 0, 0.6) !important;
  }
  :root:not([data-theme]) .custom-summary-modal > div {
    background: #12151c !important;
    color: #e6e6e6 !important;
    border: 1px solid #2a2f3a !important;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6) !important;
  }
  :root:not([data-theme]) .custom-summary-modal h3,
  :root:not([data-theme]) .custom-summary-modal h4 {
    color: #9bb0ff !important;
  }
  :root:not([data-theme]) .custom-summary-modal textarea {
    background: #0f1117 !important;
    color: #e6e6e6 !important;
    border: 2px solid #2a2f3a !important;
  }
  :root:not([data-theme]) .custom-summary-modal textarea::placeholder {
    color: #9aa4b2 !important;
  }
  :root:not([data-theme]) .custom-summary-modal .preset-btn {
    background: #151922 !important;
    color: #d0d5dd !important;
    border: 2px solid #2a2f3a !important;
  }
  :root:not([data-theme]) .custom-summary-modal .preset-btn:hover {
    background: #1b2030 !important;
    border-color: #3a4155 !important;
  }

  /* Quiz Generation Modal (system dark) */
  :root:not([data-theme]) .quiz-generation-modal {
    background: rgba(0, 0, 0, 0.6) !important;
  }
  :root:not([data-theme]) .quiz-generation-modal > div {
    background: #12151c !important;
    color: #e6e6e6 !important;
    border: 1px solid #2a2f3a !important;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6) !important;
  }
  :root:not([data-theme]) .quiz-generation-modal h3,
  :root:not([data-theme]) .quiz-generation-modal h4 {
    color: #9bb0ff !important;
  }
  :root:not([data-theme]) .quiz-generation-modal select,
  :root:not([data-theme]) .quiz-generation-modal input[type="number"] {
    background: #0f1117 !important;
    color: #e6e6e6 !important;
    border: 2px solid #2a2f3a !important;
  }
  :root:not([data-theme]) .quiz-generation-modal .quiz-count-btn {
    background: #151922 !important;
    color: #d0d5dd !important;
    border: 2px solid #2a2f3a !important;
  }
  :root:not([data-theme]) .quiz-generation-modal .quiz-count-btn:hover {
    background: #1b2030 !important;
    border-color: #3a4155 !important;
  }
  :root:not([data-theme]) .quiz-generation-modal label {
    color: #e6e6e6 !important;
  }
  :root:not([data-theme]) .quiz-generation-modal input[type="checkbox"] {
    accent-color: #9bb0ff !important;
  }
  :root:not([data-theme]) .ai-config-modal h3 {
    color: #9bb0ff !important;
  }
  :root:not([data-theme]) .ai-config-modal h4 {
    color: #c6c6ff !important;
  }
  :root:not([data-theme]) .ai-config-modal select,
  :root:not([data-theme]) .ai-config-modal input[type="text"],
  :root:not([data-theme]) .ai-config-modal input[type="password"],
  :root:not([data-theme]) .ai-config-modal textarea {
    background: #0f1117 !important;
    color: #e6e6e6 !important;
    border: 2px solid #2a2f3a !important;
  }
  :root:not([data-theme]) .ai-config-modal a {
    color: #9bb0ff !important;
  }
  :root:not([data-theme]) .ai-config-modal #apiKeyHelp,
  :root:not([data-theme]) .ai-config-modal #ollamaHelp {
    background: #0f1117 !important;
    border: 1px solid #2a2f3a !important;
    color: #c6c6c6 !important;
  }
  :root:not([data-theme]) .ai-config-modal [style*="color:#666"],
  :root:not([data-theme]) .ai-config-modal [style*="color: #666"] {
    color: #9aa4b2 !important;
  }
  :root:not([data-theme]) .ai-config-modal [style*="border: 2px solid #e0e0e0"],
  :root:not([data-theme]) .ai-config-modal [style*="border:2px solid #e0e0e0"],
  :root:not([data-theme]) .ai-config-modal [style*="border: 1px solid #e0e0e0"],
  :root:not([data-theme]) .ai-config-modal [style*="border:1px solid #e0e0e0"] {
    border-color: #2a2f3a !important;
  }
  :root:not([data-theme]) .ai-config-modal [style*="background:#f8f9fa"],
  :root:not([data-theme]) .ai-config-modal [style*="background: #f8f9fa"],
  :root:not([data-theme]) .ai-config-modal [style*="background:#e8f5e8"],
  :root:not([data-theme]) .ai-config-modal [style*="background: #e8f5e8"] {
    background: #0f1117 !important;
    color: #c6c6c6 !important;
    border-color: #2a2f3a !important;
  }

  /* AssistantInfoSection (system dark) */
  :root:not([data-theme]) .ai-config-modal #assistantInfoSection {
    background: #0f1117 !important;
    border: 1px dashed #2a2f3a !important;
    color: #c6c6c6 !important;
  }
  :root:not([data-theme]) .ai-config-modal #assistantInfoBody {
    color: #c6c6c6 !important;
  }
  :root:not([data-theme]) .ai-config-modal #toggleAssistantInfoBtn {
    background: #151922 !important;
    color: #d0d5dd !important;
    border: 1px solid #2a2f3a !important;
  }

  /* Assistant panel (system dark) */
  :root:not([data-theme]) #assistantPanel .chat-messages {
    background: #0f1117 !important;
    border-bottom: 1px solid #2a2f3a !important;
    color: #e6e6e6;
  }
  :root:not([data-theme]) #assistantPanel .assistant-message .message-content {
    background: #151922 !important;
    color: #e6e6e6 !important;
    border: 1px solid #2a2f3a !important;
  }
  :root:not([data-theme]) #assistantPanel .message-header {
    color: #9aa4b2 !important;
  }
  :root:not([data-theme]) #assistantPanel .system-message .message-content {
    background: #0e223d !important;
    color: #9bc1ff !important;
    border-color: #274b78 !important;
  }
  :root:not([data-theme]) #assistantPanel .error-message .message-content {
    background: #3b1f22 !important;
    color: #ffb4b4 !important;
    border-color: #7a2f36 !important;
  }
  :root:not([data-theme]) #assistantPanel .chat-input-container {
    background: #12151c !important;
    border-top: 1px solid #2a2f3a !important;
    box-shadow: 0 -6px 10px -8px rgba(0, 0, 0, 0.6) !important;
  }
  :root:not([data-theme]) #assistantPanel #chatInput {
    background: #0f1117 !important;
    color: #e6e6e6 !important;
    border-color: #2a2f3a !important;
  }
  :root:not([data-theme]) #assistantPanel .context-indicator {
    background: #0f1117 !important;
    color: #c6c6c6 !important;
  }

  /* Readwise panel (system dark) */
  :root:not([data-theme]) #readwisePanel {
    background: #151922 !important;
    border-color: #2a2f3a !important;
    color: #e6e6e6;
  }
  :root:not([data-theme]) #readwisePanel input,
  :root:not([data-theme]) #readwisePanel select {
    background: #0f1117 !important;
    color: #e6e6e6 !important;
    border-color: #2a2f3a !important;
  }
  :root:not([data-theme]) #readwisePanel .rw-multi-menu {
    background: #0f1117 !important;
    border-color: #2a2f3a !important;
  }
  :root:not([data-theme]) #readwisePanel .rw-multi-item:hover {
    background: #1b2030 !important;
  }
  /* Override inline light backgrounds/borders within Readwise panel */
  :root:not([data-theme]) #readwisePanel [style*="background:#fff"],
  :root:not([data-theme]) #readwisePanel [style*="background: #fff"] {
    background: #0f1117 !important;
    color: #e6e6e6 !important;
  }
  :root:not([data-theme]) #readwisePanel [style*="background:#fafbff"],
  :root:not([data-theme]) #readwisePanel [style*="background: #fafbff"],
  :root:not([data-theme]) #readwisePanel [style*="background:#f7f8ff"],
  :root:not([data-theme]) #readwisePanel [style*="background: #f7f8ff"] {
    background: #151922 !important;
    color: #e6e6e6 !important;
  }
  :root:not([data-theme]) #readwisePanel [style*="border:1px solid #e0e0e0"],
  :root:not([data-theme]) #readwisePanel [style*="border: 1px solid #e0e0e0"],
  :root:not([data-theme]) #readwisePanel [style*="border:2px solid #e0e0e0"],
  :root:not([data-theme]) #readwisePanel [style*="border: 2px solid #e0e0e0"] {
    border-color: #2a2f3a !important;
  }
  :root:not([data-theme]) #readwisePanel [style*="color:#333"],
  :root:not([data-theme]) #readwisePanel [style*="color: #333"] {
    color: #e6e6e6 !important;
  }
  :root:not([data-theme]) #readwisePanel [style*="color:#666"],
  :root:not([data-theme]) #readwisePanel [style*="color: #666"] {
    color: #9aa4b2 !important;
  }

  /* System dark (no explicit choice): subdued toggle */
  :root:not([data-theme]) #readwisePanel .rw-multi-toggle {
    background: #151922;
    color: #d0d5dd;
    border: 1px solid #2a2f3a;
    border-radius: 10px;
  }
  :root:not([data-theme]) #readwisePanel .rw-multi-toggle:hover {
    background: #1b2030;
    border-color: #3a4155;
  }
  :root:not([data-theme]) #readwisePanel .rw-multi-toggle:focus-visible {
    outline: 2px solid #9bb0ff;
    outline-offset: 2px;
  }

  /* System dark: selected chips */
  :root:not([data-theme]) #readwisePanel .rw-multi-item input:checked + span {
    color: #b9c0ff;
    background: rgba(155,176,255,0.14);
    border-radius: 6px;
    padding: 0 4px;
  }

  /* MD Exporter Modal Dark Theme (system dark) */
  :root:not([data-theme]) .md-exporter-modal {
    background-color: rgba(0, 0, 0, 0.6);
  }

  :root:not([data-theme]) .md-exporter-modal-content {
    background: #12151c;
    color: #e6e6e6;
    border: 1px solid #2a2f3a;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  }

  :root:not([data-theme]) .md-exporter-modal-header {
    border-bottom: 2px solid #9bb0ff;
  }

  :root:not([data-theme]) .md-exporter-modal-header h3 {
    color: #9bb0ff;
  }

  :root:not([data-theme]) .md-exporter-modal-close {
    color: #9aa4b2;
  }

  :root:not([data-theme]) .md-exporter-modal-close:hover {
    color: #9bb0ff;
  }

  :root:not([data-theme]) .md-exporter-label {
    color: #e6e6e6;
  }

  :root:not([data-theme]) .md-exporter-select,
  :root:not([data-theme]) .md-exporter-input {
    background: #0f1117;
    color: #e6e6e6;
    border: 2px solid #2a2f3a;
  }

  :root:not([data-theme]) .md-exporter-select:focus,
  :root:not([data-theme]) .md-exporter-input:focus {
    border-color: #9bb0ff;
    box-shadow: 0 0 0 3px rgba(155, 176, 255, 0.1);
  }

  :root:not([data-theme]) .md-exporter-help-text {
    color: #9aa4b2;
  }

  :root:not([data-theme]) .md-exporter-checkbox-label {
    color: #e6e6e6;
  }

  :root:not([data-theme]) .md-exporter-checkbox {
    accent-color: #9bb0ff;
  }

  :root:not([data-theme]) .md-exporter-debug {
    background: #0f1117;
    border: 1px solid #2a2f3a;
    color: #e6e6e6;
  }

  :root:not([data-theme]) .md-exporter-modal-footer {
    border-top: 1px solid #2a2f3a;
  }

  /* Readwise list uniform dark styling (system dark) */
  :root:not([data-theme]) #readwisePanel .rw-list {
    background: #0f1117 !important;
    border-color: #2a2f3a !important;
  }
  :root:not([data-theme]) #readwisePanel .rw-list-header {
    background: #12151c !important;
    color: #e6e6e6 !important;
    border-bottom: 1px solid #2a2f3a !important;
  }
  :root:not([data-theme]) #readwisePanel .rw-list-row {
    background: transparent !important;
  }
  :root:not([data-theme]) #readwisePanel .rw-list-row > div {
    color: #e6e6e6 !important;
  }
  /* Convert light separators in generated rows to dark */
  :root:not([data-theme]) #readwisePanel [style*="border-top:1px solid #eee"],
  :root:not([data-theme]) #readwisePanel [style*="border-top: 1px solid #eee"] {
    border-top: 1px solid #2a2f3a !important;
  }

  /* Notes & Tags panel (system dark) */
  :root:not([data-theme]) #notesPanel {
    background: rgba(16, 18, 24, 0.96) !important;
    border: 1px solid #2a2f3a !important;
    color: #e6e6e6 !important;
  }
  :root:not([data-theme]) #notesPanel .toc-content {
    color: #e6e6e6 !important;
  }
  :root:not([data-theme]) #notesPanel label {
    color: #e6e6e6 !important;
  }
  :root:not([data-theme]) #notesPanel textarea,
  :root:not([data-theme]) #notesPanel input[type="text"] {
    background: #0f1117 !important;
    color: #e6e6e6 !important;
    border: 2px solid #2a2f3a !important;
  }
  :root:not([data-theme]) #notesPanel textarea::placeholder,
  :root:not([data-theme]) #notesPanel input[type="text"]::placeholder {
    color: #9aa4b2 !important;
  }
  :root:not([data-theme]) #notesPanel textarea:focus,
  :root:not([data-theme]) #notesPanel input[type="text"]:focus {
    outline: none !important;
    border-color: #3a4155 !important;
    box-shadow: 0 0 0 3px rgba(155,176,255,0.18) !important;
  }
  :root:not([data-theme]) #notesPanel #selectionActionsHint {
    color: #9aa4b2 !important;
  }
  :root:not([data-theme]) #notesPanel .toc-btn,
  :root:not([data-theme]) #notesPanel button {
    background: #151922 !important;
    color: #d0d5dd !important;
    border: 1px solid #2a2f3a !important;
  }
  :root:not([data-theme]) #notesPanel [style*="border:2px solid #e0e0e0"],
  :root:not([data-theme]) #notesPanel [style*="border: 2px solid #e0e0e0"],
  :root:not([data-theme]) #notesPanel [style*="border:1px solid #e0e0e0"],
  :root:not([data-theme]) #notesPanel [style*="border: 1px solid #e0e0e0"] {
    border-color: #2a2f3a !important;
  }
  :root:not([data-theme]) #notesPanel [style*="color:#333"],
  :root:not([data-theme]) #notesPanel [style*="color: #333"] {
    color: #e6e6e6 !important;
  }
  :root:not([data-theme]) #notesPanel [style*="color:#666"],
  :root:not([data-theme]) #notesPanel [style*="color: #666"] {
    color: #9aa4b2 !important;
  }

  /* Keep fullscreen appearance constant across themes (system dark) */
  :root:not([data-theme]) .container.fullscreen {
    background: #000 !important;
    color: #fff !important;
  }
  :root:not([data-theme]) .container.fullscreen .reader-display {
    background: #000 !important;
    border: none !important;
  }
  :root:not([data-theme]) .container.fullscreen .current-word {
    color: #fff !important;
    text-shadow: 2px 2px 8px rgba(0,0,0,0.5) !important;
  }
  :root:not([data-theme]) .container.fullscreen .buttons {
    opacity: 0.3 !important;
  }
}

/* ---------- Simplified Reader-focused layout ---------- */
.reader-first {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

/* Make reader display the hero element */
.reader-display {
  background: #fff;
  border: 3px solid #667eea;
  border-radius: 20px;
  padding: 60px 40px;
  margin: 0;
  text-align: center;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
  max-width: 700px;
  box-shadow: 0 8px 32px rgba(102, 126, 234, 0.15);
}

.current-word {
  font-size: 3.5rem;
  font-weight: 700;
  color: #333;
  text-shadow: none;
  letter-spacing: -0.02em;
}

/* Compact toolbar directly below reader */
.reader-toolbar {
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: center;
  width: 100%;
  max-width: 700px;
}

/* Primary action buttons - most important */
.reader-toolbar #visualButtons {
  order: 1;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Essential controls - compact single row */
.reader-toolbar #visualControls {
  order: 2;
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  margin: 0;
}

/* Sentence navigation - subtle and secondary */
.reader-toolbar #sentenceNavButtons {
  order: 3;
  display: flex;
  gap: 8px;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.reader-toolbar #sentenceNavButtons:hover {
  opacity: 1;
}

/* Streamlined button styling */
.reader-toolbar .buttons button {
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  line-height: 1.2;
  min-height: 48px;
  transition: all 0.2s ease;
}

/* Ghost/tint styles to reduce visual weight */
.reader-toolbar .btn-primary {
  background: #f1f3ff;
  color: #4c57c3;
  border: 1px solid #d9defd;
}
.reader-toolbar .btn-secondary {
  background: #f7f8fa;
  color: #353b44;
  border: 1px solid #e1e6ef;
}
.reader-toolbar .btn-danger {
  background: #fff2f2;
  color: #b94a4a;
  border: 1px solid #f4caca;
}
.reader-toolbar .btn-fullscreen {
  background: #ecfbf5;
  color: #1c8d6b;
  border: 1px solid #c8efe3;
}
.reader-toolbar .btn-teleprompt {
  background: #f5ecff;
  color: #7a48b1;
  border: 1px solid #e3d3fa;
}

/* Badge softer */
.reader-toolbar .wpm-display {
  background: #eef1ff;
  color: #4c57c3;
  padding: 6px 10px;
  border-radius: 12px;
  font-weight: 700;
}

/* Subtle focus rings for accessibility */
.reader-toolbar .buttons button:focus-visible,
.sentence-nav-buttons .btn-sentence-nav:focus-visible {
  outline: 2px solid #9bb0ff;
  outline-offset: 2px;
  box-shadow: none;
}

/* Dark theme soft tints */
:root[data-theme="dark"] .reader-toolbar .btn-primary {
  background: rgba(155, 176, 255, 0.12);
  color: #b9c0ff;
  border: 1px solid rgba(155, 176, 255, 0.32);
}
:root[data-theme="dark"] .reader-toolbar .btn-secondary {
  background: #151922;
  color: #d0d5dd;
  border: 1px solid #2a2f3a;
}
:root[data-theme="dark"] .reader-toolbar .btn-danger {
  background: rgba(255, 130, 130, 0.12);
  color: #ffb4b4;
  border: 1px solid rgba(255, 130, 130, 0.28);
}
:root[data-theme="dark"] .reader-toolbar .btn-fullscreen {
  background: rgba(64, 214, 168, 0.12);
  color: #9af1d7;
  border: 1px solid rgba(64, 214, 168, 0.28);
}
:root[data-theme="dark"] .reader-toolbar .btn-teleprompt {
  background: rgba(195, 150, 255, 0.12);
  color: #d8c4ff;
  border: 1px solid rgba(195, 150, 255, 0.28);
}
:root[data-theme="dark"] .reader-toolbar .wpm-display {
  background: rgba(155, 176, 255, 0.18);
  color: #d6dcff;
}

/* Sentence nav compact subtle pills */
.reader-toolbar .btn-sentence-nav {
  background: #f2f4f7;
  color: #475467;
  border: 1px solid #e5e7eb;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 8px;
}
:root[data-theme="dark"] .reader-toolbar .btn-sentence-nav {
  background: #1b2030;
  color: #c6cbd7;
  border: 1px solid #2a2f3a;
}

/* Mobile/thin display optimizations */
@media (max-width: 768px) {
  /* Simplified reader-first layout for mobile */
  .reader-first {
    margin-top: 15px;
    gap: 12px;
  }
  
  /* Make reader display more prominent on mobile */
  .reader-display {
    padding: 40px 20px;
    min-height: 140px;
    max-width: 100%;
    border-radius: 16px;
    box-shadow: 0 6px 24px rgba(102, 126, 234, 0.12);
  }
  
  .current-word {
    font-size: 2.8rem;
    font-weight: 700;
  }
  
  /* Compact toolbar for mobile */
  .reader-toolbar {
    gap: 12px;
    max-width: 100%;
  }
  
  /* Primary buttons - horizontal layout on mobile */
  .reader-toolbar #visualButtons {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
  }
  
  .reader-toolbar .buttons button {
    flex: 1 1 auto;
    min-width: 80px;
    max-width: 120px;
    min-height: 44px;
    padding: 10px 8px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 10px;
  }
  
  /* Essential controls - stack vertically on mobile */
  .reader-toolbar #visualControls {
    flex-direction: column;
    gap: 12px;
    width: 100%;
    align-items: stretch;
  }
  
  .reader-toolbar #visualControls .control-group {
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
  }
  
  .reader-toolbar .wpm-display {
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 700;
    min-width: 80px;
  }
  
  /* Sentence navigation - horizontal pills on mobile */
  .reader-toolbar #sentenceNavButtons {
    display: flex;
    gap: 6px;
    justify-content: center;
    width: 100%;
    opacity: 0.8;
  }
  
  .reader-toolbar .btn-sentence-nav {
    flex: 1;
    max-width: 140px;
    padding: 8px 6px;
    font-size: 11px;
    text-align: center;
    border-radius: 6px;
  }
}

/* Very thin displays (phones in portrait) */
@media (max-width: 480px) {
  .reader-first {
    margin-top: 10px;
    gap: 10px;
  }
  
  .reader-display {
    padding: 30px 15px;
    min-height: 120px;
    border-radius: 14px;
  }
  
  .current-word {
    font-size: 2.4rem;
  }
  
  .reader-toolbar {
    gap: 10px;
  }
  
  /* Stack primary buttons in 2x2 grid on very small screens */
  .reader-toolbar #visualButtons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  
  .reader-toolbar .buttons button {
    min-width: 0;
    max-width: none;
    padding: 12px 6px;
    font-size: 13px;
  }
  
  /* Make controls more compact */
  .reader-toolbar #visualControls .control-group {
    padding: 0 5px;
  }
  
  .reader-toolbar .wpm-display {
    padding: 6px 10px;
    font-size: 13px;
  }
  
  /* Sentence nav buttons stack on very small screens */
  .reader-toolbar #sentenceNavButtons {
    flex-direction: column;
    gap: 4px;
  }
  
  .reader-toolbar .btn-sentence-nav {
    max-width: none;
    padding: 6px 8px;
    font-size: 10px;
  }
}

/* Collapsible Text & Modes panel */
.collapsible-panel {
  margin-top: 18px;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.6);
  overflow: hidden;
}

.collapsible-panel > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 700;
  color: #333;
  background: linear-gradient(45deg, #eef1ff, #f7f7ff);
  user-select: none;
}

.collapsible-panel[open] > summary {
  border-bottom: 1px solid #e0e0e0;
}

.collapsible-panel .panel-body {
  padding: 14px;
}

/* Dark theme for collapsible panel */
:root[data-theme="dark"] .collapsible-panel {
  border-color: #2a2f3a;
  background: rgba(16, 18, 24, 0.6);
}
:root[data-theme="dark"] .collapsible-panel > summary {
  color: #e6e6e6;
  background: linear-gradient(45deg, #0e1224, #151a2e);
  border-bottom-color: #2a2f3a;
}

/* Mobile tweaks to keep controls close to reader */
@media (max-width: 768px) {
  .reader-toolbar {
    gap: 10px;
    margin-top: 8px;
  }
  .collapsible-panel {
    margin-top: 14px;
  }
}

/* ============================
   Read‑to‑Me: compact & calm
   ============================ */
.read-to-me-section {
  gap: 14px;
}

/* Compact controls */
.read-to-me-section .playback-controls button {
  padding: 8px 12px;
  font-size: 14px;
  border-radius: 10px;
  line-height: 1.1;
}

/* Ghost/tint styles for reduced visual weight */
.read-to-me-section .btn-primary {
  background: #f1f3ff;
  color: #4c57c3;
  border: 1px solid #d9defd;
}
.read-to-me-section .btn-secondary {
  background: #f7f8fa;
  color: #353b44;
  border: 1px solid #e1e6ef;
}
.read-to-me-section .btn-danger {
  background: #fff2f2;
  color: #b94a4a;
  border: 1px solid #f4caca;
}
.read-to-me-section .btn-download {
  background: #f7f8fa;
  color: #2c3a4d;
  border: 1px solid #e1e6ef;
}

/* Audio sentence nav = subtle pills */
.read-to-me-section .btn-sentence-nav {
  background: #f2f4f7;
  color: #475467;
  border: 1px solid #e5e7eb;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 8px;
}

/* Focus rings for accessibility */
.read-to-me-section .playback-controls button:focus-visible,
.read-to-me-section .btn-sentence-nav:focus-visible {
  outline: 2px solid #9bb0ff;
  outline-offset: 2px;
  box-shadow: none;
}

/* Dark theme tints */
:root[data-theme="dark"] .read-to-me-section .btn-primary {
  background: rgba(155, 176, 255, 0.12);
  color: #b9c0ff;
  border: 1px solid rgba(155, 176, 255, 0.32);
}
:root[data-theme="dark"] .read-to-me-section .btn-secondary,
:root[data-theme="dark"] .read-to-me-section .btn-download {
  background: #151922;
  color: #d0d5dd;
  border: 1px solid #2a2f3a;
}
:root[data-theme="dark"] .read-to-me-section .btn-danger {
  background: rgba(255, 130, 130, 0.12);
  color: #ffb4b4;
  border: 1px solid rgba(255, 130, 130, 0.28);
}
:root[data-theme="dark"] .read-to-me-section .btn-sentence-nav {
  background: #1b2030;
  color: #c6cbd7;
  border: 1px solid #2a2f3a;
}

/* Phone tweaks */
@media (max-width: 768px) {
  .read-to-me-section .playback-controls {
    gap: 8px;
    flex-wrap: wrap;
  }
  .read-to-me-section .playback-controls button {
    min-height: 40px;
    font-size: 15px;
  }
}

/* ============================
   AI Features: compact & calm
   ============================ */
.ai-features-section .ai-action-buttons {
  gap: 10px !important;
}

/* Compact primary actions */
.ai-features-section .ai-action-buttons .btn-primary {
  padding: 8px 12px;
  font-size: 14px;
  border-radius: 10px;
  line-height: 1.1;
  background: #f1f3ff;
  color: #4c57c3;
  border: 1px solid #d9defd;
}

/* Focus rings */
.ai-features-section .ai-action-buttons .btn-primary:focus-visible {
  outline: 2px solid #9bb0ff;
  outline-offset: 2px;
  box-shadow: none;
}

/* Calm cards for outputs (override inline with !important) */
#summaryDisplay,
#quizDisplay {
  background: #f8fafc !important;
  border: 1px solid #e5e7eb !important;
}

/* Dark variants */
:root[data-theme="dark"] .ai-features-section .ai-action-buttons .btn-primary {
  background: rgba(155, 176, 255, 0.12);
  color: #b9c0ff;
  border: 1px solid rgba(155, 176, 255, 0.32);
}
:root[data-theme="dark"] #summaryDisplay,
:root[data-theme="dark"] #quizDisplay {
  background: #0f1117 !important;
  border: 1px solid #2a2f3a !important;
}

/* Phone tweaks */
@media (max-width: 768px) {
  .ai-features-section .ai-action-buttons .btn-primary {
    min-height: 40px;
    font-size: 15px;
  }
}

/* Mobile/thin: make AI Config button icon-only */
@media (max-width: 768px) {
  #aiConfigBtn {
    width: 40px !important;
    min-width: 40px !important;
    padding: 8px 0 !important;
    font-size: 0 !important; /* visually hide the label; screen readers still read it */
    border-radius: 10px !important;
    position: relative;
  }
  #aiConfigBtn::before {
    content: "⚙️";
    font-size: 18px;
    line-height: 1;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}
