/* ============================================
   READER MODE - Highlighting without AI interruption
   ============================================
   
   Reader mode allows users to highlight verses
   without triggering AI chat prompts automatically.
   
   Features:
   - Sidebar toggle for desktop users
   - Preserves verse highlighting functionality
   - Disables automatic AI prompt generation
   - Visual indicator when reader mode is active
*/

/* ==========================================
   SIDEBAR AI MODE HIGHLIGHTING
   ========================================== */

/* Biblia AI sidebar highlighting when in AI mode (not reader mode) */
#sidebar-ai-toggle.ai-mode-active {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.15), rgba(147, 51, 234, 0.12)) !important;
  color: #a855f7 !important;
  border: 1px solid rgba(168, 85, 247, 0.3) !important;
  box-shadow: 0 0 20px rgba(168, 85, 247, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
  font-weight: 600 !important;
  position: relative;
}

#sidebar-ai-toggle.ai-mode-active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(135deg, #a855f7, #9333ea);
  border-radius: 0 4px 4px 0;
  box-shadow: 0 0 8px rgba(168, 85, 247, 0.4);
}

#sidebar-ai-toggle.ai-mode-active .sidebar-icon {
  color: #a855f7 !important;
  filter: drop-shadow(0 0 8px rgba(168, 85, 247, 0.3));
  animation: ai-mode-glow 2s ease-in-out infinite;
}

#sidebar-ai-toggle.ai-mode-active .sidebar-text {
  color: #a855f7 !important;
  text-shadow: 0 0 8px rgba(168, 85, 247, 0.3);
}

/* Dark theme adjustments for AI mode */
[data-theme="dark"] #sidebar-ai-toggle.ai-mode-active {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.2), rgba(147, 51, 234, 0.15)) !important;
  color: #c084fc !important;
  border: 1px solid rgba(168, 85, 247, 0.4) !important;
}

[data-theme="dark"] #sidebar-ai-toggle.ai-mode-active .sidebar-icon,
[data-theme="dark"] #sidebar-ai-toggle.ai-mode-active .sidebar-text {
  color: #c084fc !important;
}

/* AI mode glow animation */
@keyframes ai-mode-glow {

  0%,
  100% {
    filter: drop-shadow(0 0 8px rgba(168, 85, 247, 0.3));
    transform: scale(1);
  }

  50% {
    filter: drop-shadow(0 0 12px rgba(168, 85, 247, 0.5));
    transform: scale(1.05);
  }
}

/* ==========================================
   READER MODE TOGGLE BUTTON (SIDEBAR)
   ========================================== */

/* Reader mode toggle styling in sidebar */
#reader-mode-toggle {
  position: relative;
  transition: all 0.3s ease;
}

/* Active state for reader mode */
#reader-mode-toggle.active {
  background: rgba(99, 102, 241, 0.15);
  border-left: 3px solid #6366f1;
  color: #6366f1;
}

[data-theme="dark"] #reader-mode-toggle.active {
  background: rgba(99, 102, 241, 0.2);
  color: #818cf8;
  border-left-color: #818cf8;
}

/* Reader mode icon styling */
#reader-mode-toggle .sidebar-icon {
  transition: all 0.3s ease;
}

#reader-mode-toggle.active .sidebar-icon {
  stroke: #6366f1;
  transform: scale(1.1);
}

[data-theme="dark"] #reader-mode-toggle.active .sidebar-icon {
  stroke: #818cf8;
}

/* Reader mode indicator badge */
#reader-mode-toggle.active::after {
  content: '';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  background: #6366f1;
  border-radius: 50%;
  border: 2px solid var(--sidebar-bg, #1e293b);
  animation: readerModePulse 2s infinite;
}

[data-theme="dark"] #reader-mode-toggle.active::after {
  background: #818cf8;
  border-color: var(--sidebar-bg, #0f172a);
}

/* Pulse animation for reader mode indicator */
@keyframes readerModePulse {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.7;
    transform: scale(1.2);
  }
}

/* ==========================================
   READER MODE ACTIVE STATE STYLING
   ========================================== */

/* Body class when reader mode is active */
.reader-mode-active {
  /* Custom property to indicate reader mode is on */
  --reader-mode: active;
}

/* Hide AI-related UI elements when reader mode is active */
.reader-mode-active #generate-prompts-btn {
  display: none !important;
}

.reader-mode-active #ai-chat-panel {
  pointer-events: none;
  opacity: 0.7;
}

/* Disable interactions with bible text in reader mode */
.reader-mode-active .chapter-content {
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ==========================================
   AI TOGGLE BUTTON IN READER MODE
   ========================================== */

/* Transform AI toggle button when reader mode is active */
.reader-mode-active #ai-toggle-btn {
  background: linear-gradient(135deg, #6366f1, #8b5cf6) !important;
  box-shadow:
    0 0 20px rgba(99, 102, 241, 0.6),
    0 0 40px rgba(99, 102, 241, 0.4),
    0 4px 12px rgba(99, 102, 241, 0.3) !important;
  animation: readerModeButtonPulse 2s infinite;
  border: 2px solid rgba(255, 255, 255, 0.3);
  position: relative;
  overflow: visible;
}

/* Dark theme AI button in reader mode */
[data-theme="dark"] .reader-mode-active #ai-toggle-btn {
  background: linear-gradient(135deg, #818cf8, #a78bfa) !important;
  box-shadow:
    0 0 20px rgba(129, 140, 248, 0.6),
    0 0 40px rgba(129, 140, 248, 0.4),
    0 4px 12px rgba(129, 140, 248, 0.3) !important;
}

/* Reader mode icon overlay on AI button */
.reader-mode-active #ai-toggle-btn::before {
  content: '';
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  background: #fbbf24;
  border-radius: 50%;
  border: 2px solid white;
  z-index: 10;
  animation: readerModeIconBounce 1.5s infinite;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2.5' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2z'/%3E%3Cpath d='M9 8h6'/%3E%3Cpath d='M9 12h6'/%3E%3Cpath d='M9 16h4'/%3E%3C/svg%3E");
  background-size: 12px 12px;
  background-position: center;
  background-repeat: no-repeat;
}

/* Dark theme reader mode icon */
[data-theme="dark"] .reader-mode-active #ai-toggle-btn::before {
  background: #f59e0b;
  border-color: #0f172a;
}

/* Change AI button icon to indicate reader mode exit */
.reader-mode-active #ai-toggle-btn svg {
  transform: scale(1.1);
  filter: brightness(1.2);
}

/* Hover effect for AI button in reader mode */
.reader-mode-active #ai-toggle-btn:hover {
  transform: scale(1.15) !important;
  background: linear-gradient(135deg, #4f46e5, #7c3aed) !important;
  box-shadow:
    0 0 30px rgba(99, 102, 241, 0.8),
    0 0 50px rgba(99, 102, 241, 0.5),
    0 6px 16px rgba(99, 102, 241, 0.4) !important;
}

[data-theme="dark"] .reader-mode-active #ai-toggle-btn:hover {
  background: linear-gradient(135deg, #6366f1, #8b5cf6) !important;
  box-shadow:
    0 0 30px rgba(129, 140, 248, 0.8),
    0 0 50px rgba(129, 140, 248, 0.5),
    0 6px 16px rgba(129, 140, 248, 0.4) !important;
}

/* Pulse animation for AI button in reader mode */
@keyframes readerModeButtonPulse {

  0%,
  100% {
    box-shadow:
      0 0 20px rgba(99, 102, 241, 0.6),
      0 0 40px rgba(99, 102, 241, 0.4),
      0 4px 12px rgba(99, 102, 241, 0.3);
  }

  50% {
    box-shadow:
      0 0 25px rgba(99, 102, 241, 0.8),
      0 0 50px rgba(99, 102, 241, 0.6),
      0 4px 16px rgba(99, 102, 241, 0.4);
  }
}

/* Bounce animation for reader mode icon */
@keyframes readerModeIconBounce {

  0%,
  100% {
    transform: scale(1) translateY(0);
  }

  50% {
    transform: scale(1.1) translateY(-2px);
  }
}

/* Tooltip update for AI button in reader mode */
.reader-mode-active #ai-toggle-btn {
  position: relative;
}

.reader-mode-active #ai-toggle-btn::after {
  content: 'Exit Reader Mode & Generate AI Prompts';
  position: absolute;
  bottom: -40px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 1000;
}

[data-theme="dark"] .reader-mode-active #ai-toggle-btn::after {
  background: rgba(255, 255, 255, 0.9);
  color: #0f172a;
}

.reader-mode-active #ai-toggle-btn:hover::after {
  opacity: 1;
}

/* Reader mode notification */
.reader-mode-notification {
  position: fixed;
  top: 80px;
  right: 20px;
  background: #6366f1;
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  z-index: 1000;
  transform: translateX(100%);
  transition: all 0.3s ease;
  max-width: 300px;
}

.reader-mode-notification.show {
  transform: translateX(0);
}

[data-theme="dark"] .reader-mode-notification {
  background: #818cf8;
  color: #0f172a;
  box-shadow: 0 4px 12px rgba(129, 140, 248, 0.3);
}

/* Reader mode notification icon */
.reader-mode-notification::before {
  content: '📖';
  margin-right: 8px;
  font-size: 16px;
}

/* ==========================================
   VERSE HIGHLIGHTING IN READER MODE
   ========================================== */

/* Enhanced verse highlighting styles for reader mode */
.reader-mode-active .v.selected {
  background: linear-gradient(120deg,
      rgba(99, 102, 241, 0.15) 0%,
      rgba(99, 102, 241, 0.25) 50%,
      rgba(99, 102, 241, 0.15) 100%);
  border-left: 3px solid #6366f1;
  padding-left: 8px;
  margin-left: -8px;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(99, 102, 241, 0.1);
}

[data-theme="dark"] .reader-mode-active .v.selected {
  background: linear-gradient(120deg,
      rgba(129, 140, 248, 0.15) 0%,
      rgba(129, 140, 248, 0.25) 50%,
      rgba(129, 140, 248, 0.15) 100%);
  border-left-color: #818cf8;
  box-shadow: 0 1px 3px rgba(129, 140, 248, 0.1);
}

/* Reader mode verse text styling */
.reader-mode-active .verse-text-wrapper.underline,
.reader-mode-active .verse-text.underline {
  background: rgba(99, 102, 241, 0.1);
  border-radius: 3px;
  padding: 2px 4px;
  text-decoration: none;
  border-bottom: 2px solid rgba(99, 102, 241, 0.3);
}

[data-theme="dark"] .reader-mode-active .verse-text-wrapper.underline,
[data-theme="dark"] .reader-mode-active .verse-text.underline {
  background: rgba(129, 140, 248, 0.1);
  border-bottom-color: rgba(129, 140, 248, 0.3);
}

/* ==========================================
   MOBILE RESPONSIVENESS
   ========================================== */

/* Hide reader mode toggle on mobile devices and tablets */
@media (max-width: 768px) {
  #reader-mode-toggle {
    display: none !important;
  }

  .reader-mode-notification {
    top: 60px;
    right: 10px;
    left: 10px;
    max-width: none;
    text-align: center;
  }
}

/* Hide on touch devices with narrow screens */
@media (max-width: 1023px) and (pointer: coarse) {
  #reader-mode-toggle {
    display: none !important;
  }
}

/* ==========================================
   COLLAPSED SIDEBAR STYLING
   ========================================== */

/* Reader mode toggle in collapsed sidebar */
.sidebar.collapsed #reader-mode-toggle .sidebar-text {
  display: none;
}

.sidebar.collapsed #reader-mode-toggle {
  justify-content: center;
  padding: 12px 0;
}

.sidebar.collapsed #reader-mode-toggle.active::after {
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
}

/* ==========================================
   ACCESSIBILITY ENHANCEMENTS
   ========================================== */

/* Focus states for reader mode toggle */
#reader-mode-toggle:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
}

/* Mobile Reader Mode Highlighting */
@media (max-width: 768px) {

  /* Mobile reader mode verse highlighting - matches AI mode exactly */
  body.reader-mode-active .v.selected {
    background-color: var(--user-highlight-bg-25) !important;
    box-shadow:
      0 2px 8px var(--user-highlight-bg-15),
      0 0 0 2px var(--user-highlight-border) !important;
    border-radius: 8px !important;
    padding: 6px 8px !important;
    font-weight: inherit !important;
    color: var(--user-highlight-text) !important;
    transform: none !important;
    z-index: 10 !important;
    position: relative !important;
  }

  /* Mobile reader mode verse text highlighting - matches AI mode exactly */
  body.reader-mode-active .verse-text.selected,
  body.reader-mode-active .verse-text-wrapper.selected,
  body.reader-mode-active .verse-text.underline,
  body.reader-mode-active .verse-text-wrapper.underline {
    background: var(--user-highlight-selected) !important;
    border-left: 4px solid var(--user-highlight-border) !important;
    border-radius: 8px !important;
    padding: 8px 12px 8px 16px !important;
    margin: 4px 0 !important;
    box-shadow:
      0 2px 12px var(--user-highlight-bg-15),
      0 4px 24px var(--user-highlight-bg-05) !important;
    transform: translateX(4px) !important;
    position: relative !important;
    z-index: 5 !important;
  }

  /* Dark theme support for mobile reader mode - matches AI mode */
  [data-theme="dark"] body.reader-mode-active .v.selected {
    background-color: var(--user-highlight-bg-35) !important;
    color: var(--user-highlight-text) !important;
    box-shadow:
      0 2px 12px var(--user-highlight-bg-20),
      0 0 0 2px var(--user-highlight-border) !important;
  }

  [data-theme="dark"] body.reader-mode-active .verse-text.selected,
  [data-theme="dark"] body.reader-mode-active .verse-text-wrapper.selected,
  [data-theme="dark"] body.reader-mode-active .verse-text.underline,
  [data-theme="dark"] body.reader-mode-active .verse-text-wrapper.underline {
    background: var(--user-highlight-selected) !important;
    border-left-color: var(--user-highlight-border) !important;
    box-shadow:
      0 2px 16px var(--user-highlight-bg-25),
      0 4px 32px var(--user-highlight-bg-10) !important;
    color: #000000 !important;
    text-shadow: none !important;
  }

  /* Ensure all nested elements in dark mode have proper text color - matches AI mode */
  [data-theme="dark"] body.reader-mode-active .verse-text.selected *,
  [data-theme="dark"] body.reader-mode-active .verse-text-wrapper.selected *,
  [data-theme="dark"] body.reader-mode-active .verse-text.underline *,
  [data-theme="dark"] body.reader-mode-active .verse-text-wrapper.underline * {
    color: #000000 !important;
    text-shadow: none !important;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {

  #reader-mode-toggle,
  #reader-mode-toggle .sidebar-icon,
  .reader-mode-notification,
  #reader-mode-toggle.active::after {
    transition: none;
    animation: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  #reader-mode-toggle.active {
    background: #6366f1;
    color: white;
    border-left-color: #4f46e5;
  }

  .reader-mode-active .v.selected {
    background: #6366f1;
    color: white;
    border-left-color: #4f46e5;
  }
}