/**
 * Shared Story Display Styles
 * Used by: results.html, story-view.html
 * 
 * This file contains all shared CSS for story display pages including:
 * - Story text container and paragraph styling
 * - Focus word display modes (color/underline)
 * - Word legend
 * - Word rating popup
 * - Sidebar panels (scope match, concepts, percentages)
 * - Action buttons
 * 
 * @version 1.0.0
 * @lastUpdated 2026-01-24
 */

/* ==========================================================================
   FOCUS MODE TOGGLE
   Toggle between color-highlighted and underlined focus words
   ========================================================================== */

.focus-mode-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #666;
}

.focus-mode-toggle label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}

.focus-mode-toggle input[type="radio"] { 
  display: none; 
}

.focus-mode-toggle label:has(input:checked) {
  background: #dc9435;
  color: white;
  font-weight: 600;
}

.focus-mode-toggle label:hover:not(:has(input:checked)) {
  background: #f5f5f5;
}

/* Word count toggle inside focus-mode-toggle */
.focus-mode-toggle .word-count-toggle {
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px solid #e5e7eb;
}

.focus-mode-toggle .word-count-toggle input[type="checkbox"] {
  display: inline-block;
  margin-right: 4px;
  cursor: pointer;
}

.focus-mode-toggle .word-count-toggle:has(input:checked) {
  background: #f0f9ff;
  color: #0369a1;
  font-weight: 500;
}

/* ==========================================================================
   WORD LEGEND
   Shows meaning of each word highlight style
   ========================================================================== */

.word-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: #f9fafb;
  border-radius: 8px;
  font-size: 12px;
  color: #666;
}

.word-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Legend items - Color mode (default) */
.word-legend-focus { 
  background: #fef3c7; 
  padding: 2px 6px; 
  border-radius: 4px; 
  font-weight: 500; 
}

.word-legend-good { 
  background: #d1fae5; 
  padding: 2px 6px; 
  border-radius: 4px; 
  font-weight: 500; 
  border: 1px solid #10b981; 
}

.word-legend-struggled { 
  background: #fee2e2; 
  padding: 2px 6px; 
  border-radius: 4px; 
  font-weight: 500; 
  border: 1px solid #ef4444; 
}

.word-legend-disallowed { 
  color: #dc2626; 
}

/* Legend items - Underline mode */
.word-legend.underline-mode .word-legend-focus { 
  background: none; 
  padding: 0; 
  font-weight: normal; 
  text-decoration: underline; 
  text-decoration-color: #dc9435; 
  text-underline-offset: 2px; 
}

.word-legend.underline-mode .word-legend-good { 
  background: none; 
  padding: 0; 
  font-weight: normal; 
  border: none; 
  text-decoration: underline; 
  text-decoration-color: #10b981; 
  text-underline-offset: 2px; 
}

.word-legend.underline-mode .word-legend-struggled { 
  background: none; 
  padding: 0; 
  font-weight: normal; 
  border: none; 
  text-decoration: underline; 
  text-decoration-color: #ef4444; 
  text-underline-offset: 2px; 
}

/* ==========================================================================
   STORY TEXT CONTAINER
   Main container for rendered story with focus word highlighting
   ========================================================================== */

.story-text .paragraph { 
  margin-bottom: 1.5em; 
}

.story-text .paragraph:last-child { 
  margin-bottom: 0; 
}

/* Disallowed word styling - red, clickable (no italic) */
.story-text .disallowed,
.story-text em.disallowed { 
  color: #dc2626; 
  font-style: normal; 
  cursor: pointer;
  padding: 2px 6px;
}

/* Interactive word base styling */
.word-interactive { 
  cursor: pointer; 
  border-radius: 4px; 
  transition: all 0.2s ease;
  padding: 2px 6px;
}

.word-interactive:hover { 
  background: rgba(220, 148, 53, 0.15); 
}

/* ==========================================================================
   COLOR MODE
   Focus words shown with colored backgrounds (yellow/green/red)
   ========================================================================== */

.story-text.color-mode u { 
  text-decoration: none; 
}

.story-text.color-mode .word-interactive.focus-word { 
  background: #fef3c7; 
  font-weight: 500; 
  position: relative; 
  text-decoration: none !important; 
}

.story-text.color-mode .word-interactive.focus-word:hover { 
  background: #fde68a; 
  transform: scale(1.02); 
}

/* Rated states - apply to ALL words (focus AND non-focus) */
.story-text.color-mode .word-interactive.rated-good { 
  background: #d1fae5; 
  border: 1px solid #10b981; 
  text-decoration: none !important; 
}

.story-text.color-mode .word-interactive.rated-good:hover { 
  background: #a7f3d0; 
}

.story-text.color-mode .word-interactive.rated-struggled { 
  background: #fee2e2; 
  border: 1px solid #ef4444; 
  text-decoration: none !important; 
}

.story-text.color-mode .word-interactive.rated-struggled:hover { 
  background: #fecaca; 
}

/* Celebration animation for "Got it!" - applies to ALL words */
.story-text.color-mode .word-interactive.celebrate { 
  animation: celebrateFlip 0.6s ease-out; 
}

.story-text.color-mode .word-interactive.celebrate::after { 
  content: '🎉'; 
  position: absolute; 
  top: -20px; 
  right: -10px; 
  font-size: 16px; 
  animation: sparkle 0.6s ease-out forwards; 
  pointer-events: none; 
}

@keyframes celebrateFlip {
  0% { transform: scale(1); }
  50% { transform: scale(1.2) rotate(5deg); }
  100% { transform: scale(1); }
}

@keyframes sparkle {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-20px); }
}

/* ==========================================================================
   UNDERLINE MODE
   Focus words shown with colored underlines (classic decodable style)
   ========================================================================== */

.story-text.underline-mode u { 
  text-decoration: none; 
}

.story-text.underline-mode .word-interactive.focus-word { 
  text-decoration: underline; 
  text-decoration-color: #dc9435; 
  text-underline-offset: 3px; 
  background: none; 
  padding: 0; 
  font-weight: normal; 
}

.story-text.underline-mode .word-interactive.focus-word:hover { 
  background: rgba(220, 148, 53, 0.15); 
  transform: none; 
}

/* Rated states in underline mode - use outline to avoid text jump */
.story-text.underline-mode .word-interactive.rated-good { 
  background: #d1fae5; 
  outline: 2px solid #10b981;
  outline-offset: 1px;
  border-radius: 4px;
}

.story-text.underline-mode .word-interactive.rated-struggled { 
  background: #fee2e2; 
  outline: 2px solid #ef4444;
  outline-offset: 1px;
  border-radius: 4px;
}

/* ==========================================================================
   WORD RATING POPUP
   Popup shown when clicking a focus word to rate as "Got it!" or "Needs practice"
   ========================================================================== */

.word-popup {
  position: absolute;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  padding: 12px;
  min-width: 180px;
  z-index: 1000;
  animation: popupFadeIn 0.2s ease-out;
}

@keyframes popupFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.word-popup-header {
  font-size: 16px;
  font-weight: 600;
  color: #374151;
  text-align: center;
  margin-bottom: 8px;
}

.word-popup-subscope {
  font-size: 11px;
  color: #9ca3af;
  text-align: center;
  margin-bottom: 10px;
}

/* Rating buttons container */
.word-popup-btns {
  display: flex;
  gap: 8px;
}

.word-popup-btn {
  flex: 1;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.word-popup-btn.good {
  background: #d1fae5;
  color: #065f46;
}

.word-popup-btn.good:hover {
  background: #a7f3d0;
}

.word-popup-btn.struggled {
  background: #fee2e2;
  color: #991b1b;
}

.word-popup-btn.struggled:hover {
  background: #fecaca;
}

.word-popup-btn:disabled { 
  opacity: 0.5; 
  cursor: not-allowed; 
}

.word-popup-btn.active { 
  box-shadow: inset 0 0 0 2px currentColor; 
  font-weight: 700; 
}

/* Status indicator (current rating) */
.word-popup-status {
  text-align: center;
  font-size: 11px;
  margin: 6px 0;
  padding: 4px 8px;
  border-radius: 4px;
}

.word-popup-status .status-good { 
  color: #059669; 
  background: #d1fae5; 
  padding: 4px 10px; 
  border-radius: 4px; 
}

.word-popup-status .status-struggled { 
  color: #dc2626; 
  background: #fee2e2; 
  padding: 4px 10px; 
  border-radius: 4px; 
}

.word-popup-status .status-unrated { 
  color: #92400e; 
  background: #fef3c7; 
  padding: 4px 10px; 
  border-radius: 4px; 
}

/* Pending status - shows rating progress */
.word-popup-status .status-pending {
  color: #6b7280;
  background: #f3f4f6;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
}

/* Net score indicator in header corner */
.word-popup-net {
  font-size: 11px;
  font-weight: 500;
  margin-left: 8px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #f3f4f6;
  color: #6b7280;
}
.word-popup-net.positive {
  background: #ecfdf5;
  color: #059669;
}
.word-popup-net.negative {
  background: #fef2f2;
  color: #dc2626;
}

/* Additional popup actions (coming soon features) */
.word-popup-actions {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e5e7eb;
}

.word-popup-action {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  background: transparent;
  color: #6b7280;
  font-size: 13px;
  cursor: not-allowed;
  text-align: left;
}

.word-popup-action:disabled { 
  opacity: 0.5; 
}

.word-popup-action .coming-soon {
  font-size: 10px;
  color: #9ca3af;
  margin-left: auto;
}

/* ==========================================================================
   SIDEBAR PANEL (SCOPE MATCH)
   Right-side panel showing validation metrics and concepts
   ========================================================================== */

.scope-panel { 
  background: white; 
  border-radius: 12px; 
  padding: 20px; 
  box-shadow: 0 2px 8px rgba(0,0,0,0.1); 
}

.scope-panel h3 { 
  color: #000; 
  font-size: 16px; 
  margin: 0 0 12px 0; 
  font-weight: 600; 
}

/* Targeted patterns count box */
.targeted-patterns { 
  background: #f5f5f5; 
  padding: 12px; 
  border-radius: 8px; 
  margin-bottom: 16px; 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
}

.targeted-patterns span:first-child { 
  font-weight: 500; 
}

.targeted-patterns span:last-child { 
  font-size: 20px; 
  font-weight: 700; 
}

/* ==========================================================================
   CONCEPTS LIST
   List of subscopes with hit/miss indicators
   ========================================================================== */

.concepts-list { 
  margin-bottom: 16px; 
}

.concepts-list h4 { 
  font-size: 15px; 
  font-weight: 600; 
  margin: 0 0 10px 0; 
}

.concept-item { 
  display: flex; 
  justify-content: space-between; 
  padding: 6px 0; 
  border-bottom: 1px solid #f0f0f0; 
  font-size: 15px; 
  position: relative;
}

.concept-item:hover { 
  background: #fafafa; 
}

.concept-hit { 
  color: #4caf50; 
  font-weight: 600; 
}

.concept-miss {
  color: #dc2626;
  font-weight: 600;
}

.concept-words {
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
  margin-top: 2px;
}

/* Tooltip for concept items (shows word list on hover) */
.concept-item .tooltip {
  position: absolute;
  bottom: 100%;
  left: 0;
  background: #333;
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  margin-bottom: 8px;
  max-width: 300px;
  white-space: normal;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.concept-item .tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 20px;
  border: 6px solid transparent;
  border-top-color: #333;
}

.concept-item:hover .tooltip { 
  opacity: 1; 
}

/* ==========================================================================
   PATTERN PERCENTAGE
   Focus word percentage display with color-coded thresholds
   Thresholds: >= 10% = success (green), >= 5% = warning (yellow), < 5% = danger (red)
   ========================================================================== */

.pattern-percentage h4 { 
  color: #000; 
  font-size: 15px; 
  font-weight: 600; 
  margin: 0 0 8px 0; 
}

.percentage-box { 
  padding: 12px; 
  border-radius: 8px; 
  margin-bottom: 6px; 
}

.percentage-box.optimal { 
  background: #fef3e7; 
}

.percentage-box.success { 
  background: #ecfdf5; 
}

.percentage-box.warning { 
  background: #fef3c7; 
}

.percentage-box.danger { 
  background: #fef2f2; 
}

.percentage-box.normal { 
  background: #f5f5f5; 
}

.percentage-display { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
}

.percentage-display span:first-child { 
  font-weight: 500; 
  font-size: 13px; 
}

.percentage-display span:last-child { 
  font-size: 20px; 
  font-weight: 700; 
}

.percentage-display span.optimal-color { 
  color: #ff6b35; 
}

.percentage-display span.success-color { 
  color: #059669; 
}

.percentage-display span.warning-color { 
  color: #d97706; 
}

.percentage-display span.danger-color { 
  color: #dc2626; 
}

.optimal-range { 
  font-size: 11px; 
  color: #666; 
  margin-top: 4px; 
}

/* ==========================================================================
   DISALLOWED WORDS
   List of words that shouldn't appear in the story
   ========================================================================== */

.disallowed-words h4 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 8px 0;
  color: #000;
}

.disallowed-words .disallowed-word { 
  display: inline-block; 
  background: #fef2f2; 
  color: #dc2626; 
  padding: 4px 10px; 
  border-radius: 12px; 
  font-size: 12px; 
  margin: 2px; 
}

/* ==========================================================================
   ACTION BUTTONS
   PDF download, copy, favorite, etc.
   ========================================================================== */

.action-buttons { 
  display: flex; 
  gap: 12px; 
  margin-bottom: 30px; 
  flex-wrap: wrap; 
}

.action-btn { 
  flex: 1; 
  min-width: 140px; 
  padding: 14px; 
  border: 2px solid #e0e0e0; 
  border-radius: 8px; 
  background: white; 
  cursor: pointer; 
  font-weight: 600; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  gap: 8px; 
  font-size: 14px; 
  transition: all 0.2s; 
}

.action-btn:hover { 
  background: #f5f5f5; 
  border-color: #dc9435; 
}

/* ==========================================================================
   RESPONSIVE ADJUSTMENTS
   ========================================================================== */

@media (max-width: 900px) {
  .results-grid { 
    grid-template-columns: 1fr; 
  }
  
  .word-legend {
    gap: 8px;
    font-size: 11px;
  }
  
  .action-buttons {
    flex-direction: column;
  }
  
  .action-btn {
    min-width: 100%;
  }
}

@media (max-width: 480px) {
  .focus-mode-toggle {
    flex-wrap: wrap;
  }
  
  .word-popup {
    min-width: 160px;
  }
}

/* ==========================================================================
   SUBSCOPE TOGGLE CONTROLS
   Checkboxes and buttons in the Concepts Being Worked On panel
   ========================================================================== */

.subscope-toggle-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border, #e5e7eb);
}

.subscope-toggle-all-btn {
  font-size: 12px;
  background: none;
  border-radius: 4px;
  padding: 3px 8px;
  cursor: pointer;
  font-weight: 500;
}

.subscope-toggle-all-btn[data-action="select-all"] {
  color: #2563eb;
  border: 1px solid #2563eb;
}

.subscope-toggle-all-btn[data-action="clear-all"] {
  color: var(--color-text-muted, #6b7280);
  border: 1px solid #d1d5db;
}

.subscope-toggle-row {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0f0f0;
}

.subscope-toggle-row .concept-item {
  border-bottom: none;
  padding-bottom: 4px;
}

.subscope-toggle-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}

.subscope-toggle-row label strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subscope-toggle {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
  border: 2px solid #d1d5db;
  border-radius: 4px;
  background: white;
  position: relative;
  transition: background 0.15s, border-color 0.15s;
}

.subscope-toggle:checked {
  background: #4caf50;
  border-color: #4caf50;
}

.subscope-toggle:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 6px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.subscope-toggle:focus-visible {
  outline: 2px solid #4caf50;
  outline-offset: 2px;
}

.subscope-toggle-row .concept-hit {
  flex-shrink: 0;
}

.subscope-word-list {
  font-size: 13px;
  color: #666;
  margin-top: 4px;
  padding-left: 28px;
  font-style: italic;
}

/* ==========================================================================
   LINE WORD COUNTS
   Shows word count at end of each line in story text
   ========================================================================== */

.line-word-count {
  color: var(--color-text-muted, #999);
  font-size: 11px;
  white-space: nowrap;
  margin-left: 4px;
}

/* ==========================================================================
   Dark Mode Overrides
   ========================================================================== */

[data-theme="dark"] .focus-mode-toggle {
  color: var(--color-text-muted);
}

[data-theme="dark"] .focus-mode-toggle label:hover:not(:has(input:checked)) {
  background: var(--color-bg-subtle);
}

[data-theme="dark"] .focus-mode-toggle .word-count-toggle {
  border-left-color: var(--color-border);
}

[data-theme="dark"] .word-legend {
  background: var(--color-bg-subtle);
  color: var(--color-text-muted);
}

[data-theme="dark"] .word-popup {
  background: var(--color-bg-card);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .word-popup-header {
  color: var(--color-text);
}

[data-theme="dark"] .word-popup-subscope {
  color: var(--color-text-placeholder);
}

[data-theme="dark"] .word-popup-actions {
  border-top-color: var(--color-border);
}

[data-theme="dark"] .word-popup-action {
  color: var(--color-text-muted);
}

[data-theme="dark"] .word-popup-net {
  background: var(--color-bg-subtle);
  color: var(--color-text-muted);
}

[data-theme="dark"] .word-popup-net.positive {
  background: #1a2e28;
  color: var(--color-success);
}

[data-theme="dark"] .word-popup-net.negative {
  background: #2e1a1a;
  color: var(--color-error);
}

[data-theme="dark"] .word-popup-status .status-pending {
  background: var(--color-bg-subtle);
  color: var(--color-text-muted);
}

[data-theme="dark"] .scope-panel {
  background: var(--color-bg-card);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .scope-panel h3 {
  color: var(--color-text);
}

[data-theme="dark"] .targeted-patterns {
  background: var(--color-bg-subtle);
}

[data-theme="dark"] .concept-item {
  border-bottom-color: var(--color-border);
}

[data-theme="dark"] .concept-item:hover {
  background: var(--color-bg-subtle);
}

[data-theme="dark"] .concept-words {
  color: var(--color-text-muted);
}

[data-theme="dark"] .pattern-percentage h4 {
  color: var(--color-text);
}

[data-theme="dark"] .percentage-box.optimal { background: #2a1f10; }
[data-theme="dark"] .percentage-box.success { background: #1a2e28; }
[data-theme="dark"] .percentage-box.warning { background: #2e2510; }
[data-theme="dark"] .percentage-box.danger { background: #2e1a1a; }
[data-theme="dark"] .percentage-box.normal { background: var(--color-bg-subtle); }

[data-theme="dark"] .optimal-range {
  color: var(--color-text-muted);
}

[data-theme="dark"] .disallowed-words h4 {
  color: var(--color-text);
}

[data-theme="dark"] .disallowed-words .disallowed-word {
  background: #2e1a1a;
}

[data-theme="dark"] .action-btn {
  background: var(--color-bg-card);
  border-color: var(--color-border);
  color: var(--color-text);
}

[data-theme="dark"] .action-btn:hover {
  background: var(--color-bg-subtle);
}

[data-theme="dark"] .subscope-toggle-row {
  border-bottom-color: var(--color-border);
}

[data-theme="dark"] .subscope-toggle {
  background: var(--color-bg-subtle);
  border-color: var(--color-border);
}

[data-theme="dark"] .subscope-word-list {
  color: var(--color-text-muted);
}

[data-theme="dark"] .concepts-list h4 {
  color: var(--color-text);
}

/* --- Story panel (main content card) --- */
[data-theme="dark"] .story-panel {
  background: var(--color-bg-card) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .story-panel h2 {
  color: var(--color-text) !important;
}

/* --- Story text container background --- */
.story-text.story-pass {
  background: #ecfdf5;
  border: 2px solid #86efac;
}

.story-text.story-fail {
  background: #fef5f5;
  border: 2px solid #fca5a5;
}

[data-theme="dark"] .story-text {
  background: var(--color-bg-subtle) !important;
  border-color: var(--color-border) !important;
  color: var(--color-text) !important;
}

[data-theme="dark"] .story-text.story-pass {
  background: #1a2e1a !important;
  border-color: #2d5a2d !important;
}

[data-theme="dark"] .story-text.story-fail {
  background: #2e1a1a !important;
  border-color: #5a2d2d !important;
}

/* --- Results header --- */
[data-theme="dark"] .results-header h1 {
  color: var(--color-text) !important;
}

/* --- Tabs --- */
[data-theme="dark"] .tab {
  background: var(--color-bg-card) !important;
  color: var(--color-primary) !important;
}

[data-theme="dark"] .tab.active {
  background: #ff8a3d !important;
  color: white !important;
}

/* --- Focus word highlighting in color mode (dark equivalents) --- */
[data-theme="dark"] .story-text.color-mode .word-interactive.focus-word {
  background: #3d2e0a !important;
  color: #fde68a;
}

[data-theme="dark"] .story-text.color-mode .word-interactive.focus-word:hover {
  background: #4d3a0d !important;
}

[data-theme="dark"] .story-text.color-mode .word-interactive.rated-good {
  background: #1a2e28 !important;
  border-color: #10b981 !important;
}

[data-theme="dark"] .story-text.color-mode .word-interactive.rated-good:hover {
  background: #1f3d33 !important;
}

[data-theme="dark"] .story-text.color-mode .word-interactive.rated-struggled {
  background: #2e1a1a !important;
  border-color: #ef4444 !important;
}

[data-theme="dark"] .story-text.color-mode .word-interactive.rated-struggled:hover {
  background: #3d1f1f !important;
}

/* --- Comprehension section --- */
[data-theme="dark"] .comprehension {
  background: var(--color-bg-subtle) !important;
}

[data-theme="dark"] .comprehension h3 {
  color: #f472b6 !important;
}

[data-theme="dark"] .comprehension p {
  color: var(--color-text-muted) !important;
}

/* --- Text size controls --- */
[data-theme="dark"] .text-size-label {
  color: var(--color-text-muted) !important;
}

[data-theme="dark"] .text-size-buttons {
  background: var(--color-bg-subtle) !important;
}

[data-theme="dark"] .text-size-btn {
  background: var(--color-bg-card) !important;
  border-color: var(--color-border) !important;
  color: var(--color-text-muted) !important;
}

[data-theme="dark"] .text-size-btn:hover {
  border-color: var(--color-primary) !important;
  background: #3d2e0a !important;
}

[data-theme="dark"] .text-size-display {
  color: var(--color-text-muted) !important;
}

/* --- Story meta (story-view.html) --- */
[data-theme="dark"] .story-meta {
  background: var(--color-bg-subtle) !important;
}

[data-theme="dark"] .story-meta-item {
  border-bottom-color: var(--color-border) !important;
}

[data-theme="dark"] .story-meta-item span:first-child {
  color: var(--color-text-muted) !important;
}

[data-theme="dark"] .story-meta-item span:last-child {
  color: var(--color-text) !important;
}

/* --- Prompt display (story-view.html) --- */
[data-theme="dark"] .prompt-display {
  background: var(--color-bg-subtle) !important;
}

[data-theme="dark"] .prompt-display p {
  color: var(--color-text-secondary) !important;
}

/* --- Back link --- */
[data-theme="dark"] .back-link {
  color: var(--color-primary) !important;
}

/* --- Story date --- */
[data-theme="dark"] .story-date {
  color: var(--color-text-muted) !important;
}

/* --- Markup label --- */
[data-theme="dark"] .markup-label {
  color: var(--color-text) !important;
}

/* --- Nav buttons --- */
[data-theme="dark"] .back-btn {
  color: var(--color-primary) !important;
}

[data-theme="dark"] .create-btn {
  background: var(--color-bg-card) !important;
  color: var(--color-primary) !important;
}

/* --- Action button danger variant --- */
[data-theme="dark"] .action-btn.danger {
  color: #ef4444 !important;
  border-color: #5a2d2d !important;
}

[data-theme="dark"] .action-btn.danger:hover {
  background: #2e1a1a !important;
}

/* --- Loading/error states --- */
[data-theme="dark"] .loading-text {
  color: var(--color-text-muted) !important;
}

[data-theme="dark"] .loading-spinner {
  border-color: var(--color-border) !important;
  border-top-color: var(--color-primary) !important;
}

/* --- Failure/warning banner (results page) --- */
[data-theme="dark"] #failureBanner {
  background: linear-gradient(135deg, #2e2510 0%, #3d3015 100%) !important;
  border-color: #b45309 !important;
}
[data-theme="dark"] #failureBanner h3 {
  color: #fbbf24 !important;
}
[data-theme="dark"] #failureBanner > div > div > p {
  color: #d1d5db !important;
}
[data-theme="dark"] #failureBanner div[style*="background: white"] {
  background: #1e1e1e !important;
  border-left-color: #b45309 !important;
}
[data-theme="dark"] #failureBanner strong[style*="color: #92400e"] {
  color: #fbbf24 !important;
}
[data-theme="dark"] #failureBanner p[style*="color: #78350f"] {
  color: #d1d5db !important;
}
[data-theme="dark"] #resultsTitle[style*="color: #92400e"] {
  color: #fbbf24 !important;
}

/* --- Best attempt retry feedback (results page) --- */
[data-theme="dark"] #retryFeedbackMessage {
  background: #1a2332 !important;
  border-color: #b45309 !important;
}
[data-theme="dark"] #retryFeedbackMessage div[style*="color: #dc9435"] {
  color: #fbbf24 !important;
}
[data-theme="dark"] #retryFeedbackMessage div[style*="color: #4b5563"] {
  color: #d1d5db !important;
}

/* ==========================================================================
   High-Contrast Color Blind Mode — Story Highlighting
   Swaps green→blue, red→magenta and adds non-color visual cues (patterns,
   borders, text decorations) so color is never the sole differentiator.
   ========================================================================== */

/* --- Legend items: color mode --- */
[data-a11y="high-contrast"] .word-legend-good {
  background: var(--a11y-good-bg, #dbeafe);
  border-color: var(--a11y-good-border, #2563eb);
  color: var(--a11y-good-text, #1e40af);
}

[data-a11y="high-contrast"] .word-legend-struggled {
  background: var(--a11y-struggled-bg, #fce7f3);
  border-color: var(--a11y-struggled-border, #be185d);
  color: var(--a11y-struggled-text, #9d174d);
}

[data-a11y="high-contrast"] .word-legend-disallowed {
  color: var(--a11y-disallowed, #9d174d);
}

/* --- Legend items: underline mode --- */
[data-a11y="high-contrast"] .word-legend.underline-mode .word-legend-good {
  text-decoration-color: var(--a11y-good-border, #2563eb);
}

[data-a11y="high-contrast"] .word-legend.underline-mode .word-legend-struggled {
  text-decoration-color: var(--a11y-struggled-border, #be185d);
  text-decoration-style: dashed;
}

/* --- Color mode: rated words --- */
[data-a11y="high-contrast"] .story-text.color-mode .word-interactive.rated-good {
  background: var(--a11y-good-bg, #dbeafe);
  border-color: var(--a11y-good-border, #2563eb);
}

[data-a11y="high-contrast"] .story-text.color-mode .word-interactive.rated-good:hover {
  background: #bfdbfe;
}

[data-a11y="high-contrast"] .story-text.color-mode .word-interactive.rated-struggled {
  background: var(--a11y-struggled-bg, #fce7f3);
  border-color: var(--a11y-struggled-border, #be185d);
}

[data-a11y="high-contrast"] .story-text.color-mode .word-interactive.rated-struggled:hover {
  background: #fbcfe8;
}

/* --- Underline mode: rated words --- */
[data-a11y="high-contrast"] .story-text.underline-mode .word-interactive.rated-good {
  background: var(--a11y-good-bg, #dbeafe);
  outline-color: var(--a11y-good-border, #2563eb);
}

[data-a11y="high-contrast"] .story-text.underline-mode .word-interactive.rated-struggled {
  background: var(--a11y-struggled-bg, #fce7f3);
  outline-color: var(--a11y-struggled-border, #be185d);
  outline-style: dashed;
}

/* --- Disallowed words: magenta instead of red, add wavy underline --- */
[data-a11y="high-contrast"] .story-text .disallowed,
[data-a11y="high-contrast"] .story-text em.disallowed {
  color: var(--a11y-disallowed, #9d174d);
  text-decoration: underline wavy var(--a11y-struggled-border, #be185d);
  text-underline-offset: 3px;
}

[data-a11y="high-contrast"] .disallowed-words .disallowed-word {
  background: var(--a11y-struggled-bg, #fce7f3);
  color: var(--a11y-disallowed, #9d174d);
  border-color: var(--a11y-struggled-border, #be185d);
}

/* --- Word rating popup --- */
[data-a11y="high-contrast"] .word-popup-btn.good {
  background: var(--a11y-good-bg, #dbeafe);
  color: var(--a11y-good-text, #1e40af);
}

[data-a11y="high-contrast"] .word-popup-btn.good:hover {
  background: #bfdbfe;
}

[data-a11y="high-contrast"] .word-popup-btn.struggled {
  background: var(--a11y-struggled-bg, #fce7f3);
  color: var(--a11y-struggled-text, #9d174d);
}

[data-a11y="high-contrast"] .word-popup-btn.struggled:hover {
  background: #fbcfe8;
}

[data-a11y="high-contrast"] .word-popup-status .status-good {
  color: var(--a11y-good-text, #1e40af);
  background: var(--a11y-good-bg, #dbeafe);
}

[data-a11y="high-contrast"] .word-popup-status .status-struggled {
  color: var(--a11y-struggled-text, #9d174d);
  background: var(--a11y-struggled-bg, #fce7f3);
}

/* --- Scope match indicators (hit/miss in sidebar) --- */
[data-a11y="high-contrast"] .concept-hit .concept-indicator {
  color: var(--a11y-good-border, #2563eb);
}

[data-a11y="high-contrast"] .concept-miss .concept-indicator {
  color: var(--a11y-struggled-border, #be185d);
}

/* --- Pattern percentage colors --- */
[data-a11y="high-contrast"] .pattern-pct.success {
  color: var(--a11y-good-border, #2563eb);
}

[data-a11y="high-contrast"] .pattern-pct.danger {
  color: var(--a11y-struggled-border, #be185d);
}

/* --- Dark mode + high contrast combined --- */
[data-theme="dark"][data-a11y="high-contrast"] .story-text.color-mode .word-interactive.rated-good {
  background: #1e3a5f;
  border-color: #3b82f6;
}

[data-theme="dark"][data-a11y="high-contrast"] .story-text.color-mode .word-interactive.rated-struggled {
  background: #4a1942;
  border-color: #ec4899;
}

[data-theme="dark"][data-a11y="high-contrast"] .story-text .disallowed,
[data-theme="dark"][data-a11y="high-contrast"] .story-text em.disallowed {
  color: #f472b6;
  text-decoration-color: #ec4899;
}

[data-theme="dark"][data-a11y="high-contrast"] .disallowed-words .disallowed-word {
  background: #4a1942;
  color: #f472b6;
}

