/* stories.css — Story, chapter, narration, contribution, AI dialogue styles */
/* Extracted from styles.css — Phase 6 refactoring (March 2026) */

.story-generation-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.95) 0%, rgba(118, 75, 162, 0.95) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100000;
  animation: storyOverlayFadeIn 0.3s ease-out;
}

@keyframes storyOverlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.story-generation-content {
  text-align: center;
  color: white;
  max-width: 400px;
  padding: 2rem;
}

.story-generation-icon {
  font-size: calc(4rem * var(--type-scale, 1));
  margin-bottom: 1.5rem;
  animation: storyIconPulse 2s ease-in-out infinite;
}

@keyframes storyIconPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
}

.story-generation-spinner {
  width: 80px;
  height: 80px;
  margin: 0 auto 1.5rem;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.story-generation-title {
  font-size: calc(1.5rem * var(--type-scale, 1));
  font-weight: 700;
  margin-bottom: 0.5rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.story-generation-message {
  font-size: calc(1.1rem * var(--type-scale, 1));
  opacity: 0.9;
  margin-bottom: 1rem;
  min-height: 3rem;
  transition: opacity 0.3s ease;
}

.story-generation-progress {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: calc(0.9rem * var(--type-scale, 1));
  opacity: 0.8;
}

.story-generation-dots {
  display: flex;
  gap: 4px;
}

.story-generation-dots span {
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  animation: storyDotPulse 1.4s ease-in-out infinite;
}

.story-generation-dots span:nth-child(2) { animation-delay: 0.2s; }

.story-generation-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes storyDotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.story-generation-tip {
  margin-top: 2rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  font-size: calc(0.9rem * var(--type-scale, 1));
  opacity: 0.9;
}

.story-generation-tip strong {
  display: block;
  margin-bottom: 0.25rem;
}

.contribution-section {
  padding: var(--space-xl);
  background: white;
}

.contribution-title {
  font-size: calc(1.25rem * var(--type-scale, 1));
  font-weight: 600;
  margin-bottom: var(--space-lg);
  color: var(--color-text);
}

.contribution-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: 1.5rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-xl);
  background: white;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: var(--space-lg);
  /* Touch-friendly minimum size */
  min-height: 80px;
  position: relative;
  overflow: hidden;
}

.contribution-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 0;
}

.contribution-btn:hover::before {
  opacity: 0.05;
}

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

.contribution-btn-icon {
  font-size: calc(2.5rem * var(--type-scale, 1));
  flex-shrink: 0;
  z-index: 1;
}

.contribution-btn-content {
  flex: 1;
  text-align: left;
  z-index: 1;
}

.contribution-btn-title {
  font-size: calc(1.125rem * var(--type-scale, 1));
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.25rem;
}

.contribution-btn-subtitle {
  font-size: calc(0.875rem * var(--type-scale, 1));
  color: var(--color-text-light);
}

.contribution-btn-arrow {
  font-size: calc(1.5rem * var(--type-scale, 1));
  color: var(--color-text-lighter);
  flex-shrink: 0;
  z-index: 1;
}

@media (max-width: 768px) {
  .person-name-mobile {
    font-size: calc(1.5rem * var(--type-scale, 1));
  }

  .contribution-btn {
    padding: 1.25rem;
  }

  .contribution-btn-icon {
    font-size: calc(2rem * var(--type-scale, 1));
  }

  .contribution-btn-title {
    font-size: calc(1rem * var(--type-scale, 1));
  }

  .ai-message-bubble {
    max-width: 85%;
  }
}

.story-filter-panel {
  background: var(--ffvr-surface-sunken, var(--color-bg-secondary));
  border-bottom: 1px solid var(--ffvr-rule, var(--color-border));
  padding: var(--space-md) var(--space-lg);
}

.story-profile-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  /* z-index 30001 ensures Focus modals ALWAYS appear above ALL other modals */
  /* Including Face Training (10003), FM modal (10002), etc. */
  z-index: 30001 !important;
  animation: fadeIn 0.2s ease-out;
}

.story-profile-modal {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.3s ease-out;
}

.story-profile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.story-profile-header h3 {
  margin: 0;
  font-size: var(--font-lg);
  color: var(--color-text);
  flex: 1;
  text-align: center;
}

.story-profile-close {
  background: none;
  border: none;
  font-size: calc(24px * var(--type-scale, 1));
  color: var(--color-text-light);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.story-profile-close:hover {
  color: var(--color-text);
}

.story-profile-save {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  padding: 8px 16px;
  font-weight: 500;
  cursor: pointer;
}

.story-profile-save:hover {
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.story-profile-name-section {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.story-profile-name-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--font-base);
}

.story-profile-name-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.story-profile-focus-label {
  font-size: var(--font-sm);
  color: var(--color-text-light);
  white-space: nowrap;
}

.story-profile-hint {
  padding: var(--space-sm) var(--space-lg);
  margin: 0;
  font-size: var(--font-sm);
  color: var(--color-text-light);
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
}

.story-profile-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm);
}

.story-profile-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: grab;
  transition: all 0.2s ease;
}

.story-profile-item:hover {
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.story-profile-item.dragging {
  opacity: 0.5;
  border-style: dashed;
  cursor: grabbing;
}

.story-profile-drag-handle {
  color: var(--color-text-light);
  font-size: calc(16px * var(--type-scale, 1));
  cursor: grab;
}

.story-profile-rank {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--font-sm);
  flex-shrink: 0;
}

.story-profile-info {
  flex: 1;
  min-width: 0;
}

.story-profile-title {
  display: block;
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.story-profile-arc {
  display: block;
  font-size: var(--font-xs);
  color: var(--color-text-light);
  margin-top: 2px;
}

.story-profile-empty {
  text-align: center;
  color: var(--color-text-light);
  padding: var(--space-xl);
}

.story-profile-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.story-profile-clear {
  background: none;
  border: 1px solid var(--color-error);
  border-radius: var(--radius-md);
  color: var(--color-error);
  padding: 8px 16px;
  cursor: pointer;
}

.story-profile-clear:hover {
  background: var(--color-error);
  color: white;
}

.story-profile-cancel {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-light);
  padding: 8px 16px;
  cursor: pointer;
  margin-left: auto;
}

.story-profile-cancel:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

@media (max-width: 768px) {
  .story-profile-modal {
    width: 95%;
    max-height: 85vh;
  }

  .story-profile-item {
    padding: var(--space-sm) var(--space-md);
  }

  .story-profile-drag-handle {
    font-size: calc(20px * var(--type-scale, 1));
    padding: 4px;
  }
}

.story-profile-item-remove {
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: calc(16px * var(--type-scale, 1));
  transition: all 0.15s;
}

.story-profile-item-remove:hover {
  background: rgba(239, 68, 68, 0.2);
  color: var(--color-error);
}

.story-profile-item-preview {
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: calc(16px * var(--type-scale, 1));
  transition: all 0.15s;
  margin-right: 4px;
}

.story-profile-item-preview:hover {
  background: rgba(102, 126, 234, 0.2);
  color: var(--color-primary);
}

.story-preview-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 10100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease-out;
}

.story-preview-modal {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease-out;
}

.story-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.story-preview-header h3 {
  margin: 0;
  font-size: calc(1.1rem * var(--type-scale, 1));
  font-weight: 600;
}

.story-preview-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: calc(1rem * var(--type-scale, 1));
  display: flex;
  align-items: center;
  justify-content: center;
}

.story-preview-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.story-preview-content {
  padding: 20px;
}

.story-preview-meta {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.story-preview-arc {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: calc(12px * var(--type-scale, 1));
  font-weight: 500;
}

.story-preview-chapters {
  background: #f3f4f6;
  color: #6b7280;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: calc(12px * var(--type-scale, 1));
}

.story-preview-summary {
  color: #374151;
  line-height: 1.6;
  margin: 0 0 16px 0;
  font-size: calc(14px * var(--type-scale, 1));
}

.story-preview-people {
  color: #6b7280;
  font-size: calc(13px * var(--type-scale, 1));
}

.story-preview-people strong {
  color: #374151;
}

.story-preview-footer {
  padding: 16px 20px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
}

.story-preview-open {
  width: 100%;
  padding: 12px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: calc(14px * var(--type-scale, 1));
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.story-preview-open:hover {
  opacity: 0.9;
}

@media (min-width: 769px) {
  .story-filter-panel {
    display: flex;
    flex-direction: column;
  }

  .filter-panel-row-1 {
    margin-bottom: 0;
  }

  .story-filter-panel .filter-panel-row {
    display: contents;
  }

  .story-filter-panel {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
  }

  .focal-person-indicator {
    margin-bottom: 0;
    margin-right: auto;
  }

  .filter-search-wrapper {
    flex: 1;
    min-width: 200px;
    max-width: 400px;
  }

  /* Multi-column layout for modal */
  .family-focus-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  /* Removed max-width constraint - modal now fills app content area */
  /* Previously set to 600px which conflicted with base style of 100% - 40px */
}

@media (max-width: 768px) {
  .story-filter-panel {
    padding: var(--space-sm) var(--space-md);
  }

  .filter-panel-row-1 {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  .filter-panel-row-2 {
    margin-top: 8px;
  }

  .family-focus-btn {
    padding: 8px 12px;
    min-width: auto;
  }

  .filter-select {
    padding: 8px 10px;
    min-width: 60px;
    font-size: var(--font-xs);
  }

  .filter-era {
    min-width: 55px;
  }

  .filter-type {
    min-width: 65px;
  }

  /* Full-screen modal on iPhone (below nav, no sidebar on mobile).
     Uses safe-area-aware total header height per binary-hatching-pearl D1. */
  .family-focus-modal-overlay {
    top: var(--mobile-top-bar-total-height);
    left: 0;
    align-items: flex-end;
  }

  .family-focus-modal {
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .family-focus-grid-item {
    padding: 14px var(--space-md);
    min-height: 48px;
  }
}

.story-arc-group {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}

.story-arc-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.story-arc-icon {
  font-size: var(--font-2xl);
}

.story-arc-title {
  margin: 0;
  font-size: var(--font-xl);
  flex: 1;
}

.story-arc-count {
  font-size: var(--font-sm);
  opacity: 0.9;
}

.story-collection-header {
  flex-direction: column;
  align-items: flex-start;
}

.story-collection-group[data-collection="wonder"] .story-arc-header {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
}

.story-collection-group[data-collection="adventure"] .story-arc-header {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.story-collection-group[data-collection="courage"] .story-arc-header {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

.story-collection-group[data-collection="love"] .story-arc-header {
  background: linear-gradient(135deg, #ec4899 0%, #db2777 100%);
}

.story-collection-group[data-collection="legacy"] .story-arc-header {
  background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
}

.story-collection-group[data-collection="uncategorized"] .story-arc-header {
  background: linear-gradient(135deg, #64748b 0%, #475569 100%);
}

.story-arc-stories {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.story-gallery-card {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.story-gallery-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.story-gallery-thumb {
  aspect-ratio: 16/9;
  background: var(--color-bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.story-gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.story-thumb-placeholder {
  font-size: calc(3rem * var(--type-scale, 1));
}

.story-gallery-info {
  padding: var(--space-md);
}

.story-gallery-info h4 {
  margin: 0 0 var(--space-xs) 0;
  font-size: var(--font-base);
  color: var(--color-text);
}

.story-gallery-dates {
  font-size: var(--font-sm);
  color: var(--color-text-light);
}

.story-history-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: all 0.2s ease;
}

.story-history-card:hover {
  background: var(--color-bg-secondary);
  border-color: var(--color-primary);
  transform: translateX(4px);
}

.story-history-card.is-live {
  border-left: 4px solid #ef4444;
  background: linear-gradient(to right, rgba(239, 68, 68, 0.05), transparent);
}

.story-history-card.is-ended {
  border-left: 4px solid #22c55e;
}

.story-history-icon {
  font-size: var(--font-2xl);
  flex-shrink: 0;
  margin-top: 2px;
}

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

.story-history-header-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.story-history-title {
  margin: 0;
  font-size: var(--font-lg);
  color: var(--color-text);
}

.story-status-badge {
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--font-xs);
  font-weight: 600;
}

.story-status-badge.live {
  background: #fef2f2;
  color: #dc2626;
  animation: pulse-live 2s infinite;
}

.story-status-badge.ended {
  background: #f0fdf4;
  color: #16a34a;
}

.story-status-badge.regular {
  background: var(--color-bg-secondary);
  color: var(--color-text-light);
}

.story-history-subtitle {
  margin: var(--space-xs) 0 0 0;
  font-size: var(--font-sm);
  color: var(--color-text-light);
}

.story-history-meta {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-top: var(--space-sm);
  font-size: var(--font-sm);
  color: var(--color-text-light);
}

.story-history-updated {
  color: var(--color-primary);
}

.story-history-stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

.story-history-stat {
  padding: 2px 8px;
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
  font-size: var(--font-xs);
  color: var(--color-text-light);
}

.story-history-arrow {
  font-size: var(--font-xl);
  color: var(--color-text-light);
  flex-shrink: 0;
  align-self: center;
}

@media (max-width: 768px) {
  .stories-history-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .stories-history-filters {
    width: 100%;
    overflow-x: auto;
    padding-bottom: var(--space-xs);
  }

  .story-history-card {
    padding: var(--space-md);
  }

  .story-history-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-xs);
  }
}

.story-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: all 0.2s ease;
}

.story-card:hover {
  background: var(--color-bg-secondary);
  border-color: var(--color-primary);
}

.story-card.compact {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
}

.story-card-icon {
  font-size: var(--font-2xl);
  flex-shrink: 0;
}

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

.story-card-title {
  margin: 0;
  font-size: var(--font-lg);
  color: var(--color-text);
}

.compact .story-card-title {
  font-size: var(--font-base);
}

.story-card-subtitle {
  margin: var(--space-xs) 0 0 0;
  font-size: var(--font-sm);
  color: var(--color-text-light);
}

.story-card-meta {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-xs);
  font-size: var(--font-sm);
  color: var(--color-text-light);
}

.story-card-meta span {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.story-card-persons {
  margin-top: var(--space-xs);
  font-size: var(--font-sm);
  color: var(--color-text-light);
}

.story-card-arrow {
  font-size: var(--font-lg);
  color: var(--color-text-lighter);
  flex-shrink: 0;
}

.story-card.training-story {
  position: relative;
  border: 2px dashed #f59e0b;
  background: linear-gradient(135deg, #fef3c7, #fde68a);
}

.story-card.training-story:hover {
  background: linear-gradient(135deg, #fde68a, #fcd34d);
  border-color: #d97706;
}

.story-card.draft-story {
  border-left: 3px solid #667eea;
}

.story-card.training-story .story-card-title {
  color: #92400e;
}

.story-card.training-story .story-card-subtitle {
  color: #b45309;
}

.story-card.training-story .story-card-meta {
  color: #a16207;
}

.story-card.training-story .story-card-icon {
  background: rgba(217, 119, 6, 0.15);
}

.story-card-play {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  flex-shrink: 0;
}

.story-card-play:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.5);
}

.chapter-detail-view {
  max-width: 900px;
  margin: 0 auto;
}

.chapter-detail-header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.chapter-detail-back {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  margin-top: 4px;
}

.chapter-detail-back:hover {
  background: var(--color-bg-secondary);
  color: var(--color-text);
}

.chapter-detail-header-info {
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
  flex: 1;
}

.chapter-detail-header-icon {
  font-size: calc(2rem * var(--type-scale, 1));
  flex-shrink: 0;
}

.chapter-detail-story-title {
  margin: 0;
  font-size: var(--font-2xl);
  color: var(--color-text);
}

.chapter-detail-subtitle {
  margin: var(--space-xs) 0 0;
  font-size: var(--font-base);
  color: var(--color-text-light);
}

.chapter-detail-meta {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
  margin-top: var(--space-xs);
  font-size: var(--font-sm);
  color: var(--color-text-lighter);
}

.chapter-detail-play-full {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-xl);
  background: linear-gradient(135deg, #667eea, #764ba2);
  border: none;
  border-radius: var(--radius-lg);
  color: white;
  font-size: var(--font-base);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: var(--space-lg);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.chapter-detail-play-full:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.5);
}

.chapter-detail-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chapter-detail-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--color-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  transition: background 0.15s;
}

.chapter-detail-row:hover {
  background: var(--color-bg-secondary);
}

.chapter-detail-play {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  background: rgba(102, 126, 234, 0.15);
  border: 1px solid rgba(102, 126, 234, 0.3);
  color: #667eea;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  margin-top: 2px;
}

.chapter-detail-play:hover {
  background: rgba(102, 126, 234, 0.25);
  transform: scale(1.08);
}

.chapter-detail-num {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  background: var(--color-bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--color-text-light);
  flex-shrink: 0;
  margin-top: 2px;
}

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

.chapter-detail-title {
  font-weight: 600;
  color: var(--color-text);
  font-size: var(--font-base);
}

.chapter-detail-narrative {
  margin-top: var(--space-xs);
  font-size: var(--font-sm);
  color: var(--color-text-light);
  line-height: 1.5;
}

.chapter-detail-narrative.truncated {
  cursor: pointer;
}

.chapter-detail-narrative.truncated:not(.expanded) {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chapter-detail-narrative.expanded {
  -webkit-line-clamp: unset;
}

.chapter-detail-duration {
  font-size: var(--font-sm);
  color: var(--color-text-lighter);
  flex-shrink: 0;
  margin-top: 4px;
}

.story-card.create-story-card {
  background: linear-gradient(135deg, #1e3a5f 0%, #0d1b2a 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
}

.story-card.create-story-card:hover {
  background: linear-gradient(135deg, #264a75 0%, #162838 100%);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(30, 58, 95, 0.3);
}

.story-card.create-story-card .story-card-title {
  color: white;
  font-weight: 600;
}

.story-card.create-story-card .story-card-subtitle {
  color: rgba(255, 255, 255, 0.7);
}

.story-card.create-story-card .story-card-icon {
  background: rgba(255, 255, 255, 0.1);
  font-size: calc(1.5rem * var(--type-scale, 1));
}

.story-card.create-story-card .story-card-arrow {
  color: rgba(255, 255, 255, 0.6);
}

.story-detail-modal {
  /* modal-integrity-scan S4: visibility now owned by .ffa-modal/.is-open +
   * .ffa-modal--fullscreen (modal-foundation.css). Background retained; the
   * fixed/inset/z/overflow/display come from the foundation fullscreen type. */
  background: var(--color-bg);
}

.story-modal-header {
  position: sticky;
  top: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: var(--space-lg);
  z-index: 10;
}

.story-modal-header h2 {
  margin: 0;
  font-size: var(--font-2xl);
}

.story-modal-subtitle {
  margin: var(--space-xs) 0 0 0;
  opacity: 0.9;
}

.story-header-meta-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-xs);
}

.story-version-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-full);
  font-size: var(--font-xs);
  font-weight: var(--font-medium);
  color: rgba(255, 255, 255, 0.9);
  letter-spacing: 0.5px;
}

.story-modal-content {
  padding: var(--space-lg);
  max-width: 800px;
  margin: 0 auto;
}

.story-modal-meta {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  font-size: var(--font-sm);
  color: var(--color-text-light);
}

.story-watch-full-video {
  margin-bottom: var(--space-lg);
  text-align: center;
}

.story-media-header {
  font-size: var(--font-md);
  font-weight: 600;
  margin: 0 0 var(--space-sm) 0;
  color: var(--color-text);
}

.story-media-gallery {
  display: grid;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.story-video-gallery {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.story-photo-gallery {
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
}

.story-media-item {
  cursor: pointer;
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.story-media-item:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.story-media-item.video-item {
  background: linear-gradient(135deg, #1e293b, #334155);
  padding: var(--space-sm);
}

.story-media-item .video-thumb {
  aspect-ratio: 16/9;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.story-media-item .play-overlay {
  font-size: calc(2rem * var(--type-scale, 1));
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.story-media-item .media-caption {
  font-size: calc(0.75rem * var(--type-scale, 1));
  color: white;
  margin: var(--space-xs) 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.story-media-item.photo-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.story-media-item.more-photos {
  aspect-ratio: 1;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: var(--font-sm);
}

.story-photos-section {
  margin-bottom: var(--space-lg);
}

.story-photo-lightbox {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 10001;
  display: none;
  align-items: center;
  justify-content: center;
}

.story-photo-lightbox.active {
  display: flex;
}

.story-photo-lightbox .lightbox-content {
  position: relative;
  max-width: 95vw;
  max-height: 95vh;
}

.story-photo-lightbox .lightbox-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: calc(1.5rem * var(--type-scale, 1));
  cursor: pointer;
}

.story-photo-lightbox img {
  max-width: 95vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-md);
}

.story-gallery-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 10000;
  display: none;
  overflow-y: auto;
}

.story-gallery-modal.active {
  display: block;
}

.story-gallery-modal .gallery-modal-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-lg);
}

.story-gallery-modal .gallery-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-lg);
  color: white;
}

.story-gallery-modal .gallery-modal-header h3 {
  margin: 0;
}

.story-gallery-modal .gallery-close-btn {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: calc(1.5rem * var(--type-scale, 1));
  cursor: pointer;
}

.story-gallery-modal .gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-md);
}

.story-gallery-modal .gallery-item {
  cursor: pointer;
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: transform 0.2s;
}

.story-gallery-modal .gallery-item:hover {
  transform: scale(1.05);
}

.story-gallery-modal .gallery-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.story-gallery-modal .gallery-load-more {
  display: flex;
  justify-content: center;
  padding: var(--space-lg) 0;
}

.story-gallery-modal .btn-load-more-gallery {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border: none;
  padding: 12px 32px;
  border-radius: 24px;
  font-size: calc(1rem * var(--type-scale, 1));
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.story-gallery-modal .btn-load-more-gallery:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.story-gallery-modal .btn-load-more-gallery:active {
  transform: translateY(0);
}

.story-modal-chapters,

.story-modal-contributions {
  margin-bottom: var(--space-xl);
}

.story-modal-chapters h3,

.story-modal-contributions h3 {
  margin: 0 0 var(--space-md) 0;
  font-size: var(--font-lg);
  color: var(--color-text);
}

.story-persons-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.story-person-tag {
  display: inline-block;
  padding: var(--space-xs) var(--space-md);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-full);
  font-size: var(--font-sm);
  color: var(--color-text);
  cursor: pointer;
}

.story-person-tag:hover {
  background: var(--color-primary);
  color: white;
}

.story-chapter-item {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  align-items: center;
}

.story-chapter-item:hover {
  background: var(--color-bg-tertiary, #e5e7eb);
  transform: translateX(4px);
}

.story-chapter-item.expanded {
  background: var(--color-primary-light, #e0e7ff);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  margin-bottom: 0;
}

.chapter-expand-icon {
  font-size: calc(0.75rem * var(--type-scale, 1));
  color: var(--color-text-light);
  margin-left: auto;
  transition: transform 0.2s;
}

.story-chapter-item.expanded .chapter-expand-icon {
  transform: rotate(90deg);
}

.chapter-content-container {
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  margin-bottom: var(--space-sm);
  border-left: 3px solid var(--color-primary);
  overflow: hidden;
}

.chapter-narrative {
  background: var(--color-bg-primary, #ffffff);
  padding: 20px 20px 16px;
  font-size: calc(15px * var(--type-scale, 1));
  line-height: 1.7;
  color: var(--color-text-primary, #1f2937);
}

.chapter-narrative p {
  margin: 0 0 1em 0;
}

.chapter-narrative p:last-child {
  margin-bottom: 0;
}

.chapter-narrative em {
  font-style: italic;
  color: var(--color-text-secondary, #4b5563);
}

.chapter-narrative strong {
  font-weight: 600;
  color: #7c3aed;
  font-size: calc(13px * var(--type-scale, 1));
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.chapter-narrative .narrative-quote {
  margin: 1em 0;
  padding: 12px 16px 12px 20px;
  border-left: 3px solid #667eea;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.06), rgba(118, 75, 162, 0.04));
  border-radius: 0 8px 8px 0;
  font-style: italic;
  color: var(--color-text-secondary, #4b5563);
  line-height: 1.6;
  font-size: calc(14.5px * var(--type-scale, 1));
}

.chapter-narrative .narrative-quote:last-child {
  margin-bottom: 0;
}

.narration-master-toggle {
  margin: 0 0 4px 0;
  padding: 0 16px;
}

.narration-toggle-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(135deg, #1f2937, #111827);
  border-radius: 10px;
}

.narration-toggle-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.narration-toggle-icon {
  font-size: calc(18px * var(--type-scale, 1));
}

.narration-toggle-label {
  display: block;
  color: #e5e7eb;
  font-size: calc(13px * var(--type-scale, 1));
  font-weight: 600;
  letter-spacing: 0.3px;
}

.narration-toggle-voice {
  display: block;
  color: #9ca3af;
  font-size: calc(11px * var(--type-scale, 1));
  letter-spacing: 0.3px;
}

.narration-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.narration-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.narration-switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #4b5563;
  transition: 0.3s;
  border-radius: 24px;
}

.narration-switch-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

.narration-switch input:checked + .narration-switch-slider {
  background: linear-gradient(135deg, #667eea, #764ba2);
}

.narration-switch input:checked + .narration-switch-slider:before {
  transform: translateX(20px);
}

.chapter-subtitle {
  display: block;
  font-size: var(--font-sm, 13px);
  color: var(--color-text-light, #6b7280);
  font-style: italic;
  margin-top: 2px;
}

.narration-player {
  padding: 14px 16px 10px;
  background: linear-gradient(135deg, #1f2937, #111827);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  margin-bottom: 12px;
}

.narration-player-minimal {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 6px;
  border-radius: 20px;
  margin-bottom: 8px;
}

.narration-label-inline {
  color: #9ca3af;
  font-size: calc(12px * var(--type-scale, 1));
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}

.narration-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.narration-play-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  font-size: calc(16px * var(--type-scale, 1));
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.narration-play-btn:active {
  transform: scale(0.93);
}

.narration-label {
  color: #6b7280;
  font-size: calc(10px * var(--type-scale, 1));
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 6px;
  padding-left: 56px;
}

.narration-section {
  margin-bottom: 12px;
}

.narration-waveform {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
  width: 20px;
  cursor: pointer;
  padding: 4px 0;
  -webkit-tap-highlight-color: transparent;
  margin-bottom: 8px;
}

.narration-waveform.active .waveform-bar {
  animation: waveform-pulse 1.2s ease-in-out infinite;
}

.narration-waveform.active .waveform-bar:nth-child(1) {
  animation-delay: 0s;
}

.narration-waveform.active .waveform-bar:nth-child(2) {
  animation-delay: 0.2s;
}

.narration-waveform.active .waveform-bar:nth-child(3) {
  animation-delay: 0.4s;
}

.narration-waveform.active .waveform-bar:nth-child(4) {
  animation-delay: 0.1s;
}

.narration-waveform.narration-complete .waveform-bar {
  animation: none;
  background: linear-gradient(135deg, #10b981, #059669);
  opacity: 0.7;
  transform: scaleY(0.3);
}

.narration-player.narration-complete .narration-play-btn {
  color: #10b981;
}

.chapter-video-player {
  display: none;
  position: relative;
  width: 100%;
  max-width: 90%;
  margin: 12px auto;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.chapter-video-player .cvp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: linear-gradient(135deg, #1e293b, #0f172a);
}

.chapter-video-player .cvp-title {
  color: rgba(255, 255, 255, 0.7);
  font-size: calc(12px * var(--type-scale, 1));
  font-weight: 500;
}

.chapter-video-player .cvp-controls {
  display: flex;
  gap: 6px;
}

.chapter-video-player .cvp-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  font-size: calc(14px * var(--type-scale, 1));
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.chapter-video-player .cvp-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.chapter-video-player .cvp-video {
  width: 100%;
  display: block;
}

.chapter-video-player.cvp-app-panel {
  position: fixed;
  top: var(--nav-height, 60px);
  left: var(--side-nav-width, 60px);
  right: 0;
  bottom: 0;
  max-width: none;
  margin: 0;
  border-radius: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
}

.chapter-video-player.cvp-app-panel .cvp-header {
  padding: 8px 16px;
}

.chapter-video-player.cvp-app-panel .cvp-video {
  flex: 1;
  object-fit: contain;
  max-height: calc(100vh - var(--nav-height, 60px) - 44px);
}

@media (max-width: 768px) {
  .chapter-video-player.cvp-app-panel {
    left: 0;
    top: 0;
    z-index: 10001;
  }
  .chapter-video-player.cvp-app-panel .cvp-video {
    max-height: calc(100vh - 44px);
  }
}

.chapter-audio-clips {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chapter-media-container {
  background: var(--color-bg-tertiary, #f3f4f6);
  border-radius: 0;
  padding: var(--space-md);
  border-top: 1px solid var(--color-border-light, #e5e7eb);
}

.chapter-media-empty,

.chapter-media-error {
  text-align: center;
  padding: var(--space-lg);
  color: var(--color-text-light);
  font-size: var(--font-sm);
}

.chapter-media-error {
  color: var(--color-error, #ef4444);
}

.chapter-media-items {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.chapter-video-wrapper {
  width: 100%;
}

.chapter-video-wrapper video {
  width: 100%;
  border-radius: var(--radius-md);
  background: #000;
  max-height: 80vh;
}

.chapter-video-wrapper.infographic-video {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  border: 2px solid var(--color-primary);
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.2);
}

.story-chapter-item.has-infographic {
  border-left: 3px solid var(--color-primary);
}

.contribution-grid,

.contribution-card,

.chapter-video-caption,

.chapter-image-caption {
  margin: var(--space-xs) 0 0;
  font-size: var(--font-sm);
  color: var(--color-text-light);
  text-align: center;
}

.chapter-image-wrapper {
  text-align: center;
}

.chapter-image-wrapper img {
  max-height: 300px;
  object-fit: contain;
}

.chapter-document-wrapper {
  padding: var(--space-sm);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-sm);
}

.chapter-document-link {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}

.chapter-document-link:hover {
  text-decoration: underline;
}

.chapter-number {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary);
  color: white;
  border-radius: 50%;
  font-weight: 600;
  flex-shrink: 0;
}

.chapter-info {
  flex: 1;
}

.chapter-info strong {
  display: block;
  margin-bottom: var(--space-xs);
}

.chapter-info p {
  margin: 0;
  font-size: var(--font-sm);
  color: var(--color-text-light);
}

.story-modal-events {
  margin-bottom: var(--space-xl);
}

.story-modal-events h3 {
  margin: 0 0 var(--space-md) 0;
  font-size: var(--font-lg);
  color: var(--color-text);
}

.story-events-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.story-event-card {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  align-items: flex-start;
}

.story-event-card:hover {
  background: var(--color-bg-tertiary, #e5e7eb);
  transform: translateX(4px);
}

.story-event-card:active {
  transform: scale(0.98);
}

.story-event-card:hover .event-play-icon {
  opacity: 1;
}

.story-contribution {
  padding: var(--space-md);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
}

.contribution-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}

.contribution-type {
  font-size: var(--font-xs);
  padding: var(--space-xs) var(--space-sm);
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius-full);
  text-transform: capitalize;
}

.story-contribution p {
  margin: 0;
  color: var(--color-text);
}

.story-modal-stats {
  display: flex;
  gap: var(--space-lg);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
  color: var(--color-text-light);
  font-size: var(--font-sm);
}

@media (max-width: 768px) {
  .stories-header {
    flex-direction: column;
    align-items: stretch;
  }

  .stories-controls {
    justify-content: center;
  }

  .stories-view-modes {
    width: 100%;
    justify-content: center;
  }

  .stories-filters {
    flex-direction: column;
    gap: var(--space-sm);
  }

  .stories-filters .select-input {
    width: 100%;
  }

  .stories-gallery {
    grid-template-columns: repeat(2, 1fr);
  }

  .story-card {
    flex-wrap: wrap;
  }

  .story-card-arrow {
    display: none;
  }

  .story-modal-stats {
    flex-direction: column;
    gap: var(--space-sm);
  }
}

.story-modal-layout {
  display: flex;
  min-height: calc(100vh - 140px); /* Account for header and tabs */
}

.story-sidebar {
  width: 70px;
  min-width: 70px;
  background: linear-gradient(180deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.12) 100%);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-md) var(--space-xs);
  gap: var(--space-sm);
  position: sticky;
  top: 140px; /* Below header and tabs */
  height: fit-content;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
}

.story-modal-layout .story-modal-content {
  flex: 1;
  padding: var(--space-lg);
  max-width: none;
  margin: 0;
  overflow-y: auto;
}

@media (max-width: 768px) {
  .story-modal-layout {
    display: block !important; /* Use block instead of flex to fix iPhone layout */
    min-height: auto;
    padding-bottom: 85px; /* Space for bottom bar */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .story-sidebar {
    /* Show as horizontal bar at bottom instead of hiding */
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100% !important;
    min-width: unset !important;
    height: 70px !important;
    max-height: 70px !important;
    flex-direction: row !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    padding: 8px 16px !important;
    gap: 12px !important;
    border-right: none !important;
    border-top: 1px solid var(--color-border) !important;
    background: var(--color-bg-primary) !important;
    z-index: 1000 !important;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1) !important;
  }

  .story-sidebar .sidebar-header {
    display: none !important; /* Hide "Share" header on mobile */
  }

  .story-sidebar .sidebar-divider {
    display: none !important; /* Hide divider on mobile */
  }

  .story-sidebar .sidebar-btn {
    width: 50px !important;
    height: 50px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    flex-shrink: 0;
  }

  .story-sidebar .sidebar-label {
    font-size: 8px !important;
  }

  /* Hide Go Live from bottom bar on mobile - it shows at top */
  .story-sidebar .sidebar-btn.live-mode {
    display: none !important;
  }

  .story-modal-layout .story-modal-content {
    padding: var(--space-md);
    display: block !important;
    min-height: 100%;
  }
}

.story-header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  position: absolute;
  top: 70px;
  right: 16px;
  z-index: 101;
}
.story-go-live-mobile {
  display: none;
}

@media (max-width: 768px) {
  /* Header controls positioning on mobile */
  .story-header-controls {
    position: fixed;
    top: 70px;
    right: 16px;
    z-index: 101;
    display: flex;
    gap: 8px;
  }

  .story-go-live-mobile {
    display: flex; /* Show on mobile */
    position: static; /* Now inside flex container */
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: white;
    border: none;
    border-radius: 24px;
    padding: 10px 18px;
    font-size: calc(14px * var(--type-scale, 1));
    font-weight: 600;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.4);
    cursor: pointer;
    animation: goPulse 2s ease-in-out infinite;
  }

  .story-go-live-mobile::before {
    content: '●';
    color: white;
    animation: liveDot 1s ease-in-out infinite;
  }

  @keyframes goPulse {
    0%, 100% { box-shadow: 0 4px 12px rgba(220, 38, 38, 0.4); }
    50% { box-shadow: 0 4px 20px rgba(220, 38, 38, 0.6); }
  }

  @keyframes liveDot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
  }
}
.story-commentary-section {
  margin-top: var(--space-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg-secondary);
  overflow: hidden;
}

.story-commentary-section.expanded .commentary-toggle-icon {
  transform: rotate(90deg);
}

.contribution-bar {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%);
  border-top: 1px solid var(--color-border);
  position: sticky;
  bottom: 0;
  z-index: 10;
}

.contribution-bar-label {
  font-size: var(--font-sm);
  color: var(--color-text-light);
  font-weight: 500;
  text-align: center;
}

.contribution-bar-buttons {
  display: flex;
  justify-content: center;
  gap: var(--space-sm);
}

.contribution-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--space-sm) var(--space-md);
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 70px;
}

.contribution-btn:hover {
  background: var(--color-bg-secondary);
  border-color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.contribution-btn:active {
  transform: translateY(0);
}

.contribution-btn .contribution-icon {
  font-size: calc(1.5rem * var(--type-scale, 1));
}

.contribution-btn .contribution-label {
  font-size: var(--font-xs);
  color: var(--color-text-light);
  font-weight: 500;
}

.contribution-btn.voice:hover { border-color: #e74c3c; }

.contribution-btn.text:hover { border-color: #3498db; }

.contribution-btn.media:hover { border-color: #2ecc71; }

.contribution-btn-ai {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  width: 100%;
  margin-top: var(--space-xs);
}

.contribution-btn-ai:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.contribution-btn-ai:active {
  transform: translateY(0);
}

.contribution-btn-ai .contribution-icon {
  font-size: calc(1.2rem * var(--type-scale, 1));
}

.contribution-btn-ai .contribution-label {
  font-size: var(--font-sm);
}

.contribution-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  padding: var(--space-md);
  animation: fadeIn 0.2s ease;
}

.contribution-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1099;
  justify-content: center;
  align-items: center;
}

.contribution-modal.active {
  display: flex;
}

.contribution-modal-content {
  background: var(--color-bg-primary);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
  z-index: 1101;
  position: relative;
}

.contribution-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-bottom: none;
}

.contribution-modal-header h3 {
  margin: 0;
  font-size: var(--font-lg);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: white;
}

.contribution-modal-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  font-size: calc(1.5rem * var(--type-scale, 1));
  color: white;
  cursor: pointer;
  padding: var(--space-xs);
  line-height: 1;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.contribution-modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
  color: white;
}

.contribution-modal-body {
  padding: var(--space-lg);
}

.contribution-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.contribution-modal-footer .btn-cancel {
  padding: 10px 20px;
  border: 1px solid #d1d5db;
  background: white;
  color: #374151;
  border-radius: 8px;
  font-size: calc(0.9rem * var(--type-scale, 1));
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.contribution-modal-footer .btn-cancel:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.contribution-modal-footer .btn-submit {
  padding: 10px 24px;
  border: none;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 8px;
  font-size: calc(0.9rem * var(--type-scale, 1));
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.contribution-modal-footer .btn-submit:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.contribution-modal-footer .btn-submit:disabled {
  background: #d1d5db;
  cursor: not-allowed;
  box-shadow: none;
}

.contribution-type-selector {
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid #f3f4f6;
}

.contribution-type-selector label {
  display: block;
  font-size: calc(0.85rem * var(--type-scale, 1));
  font-weight: 500;
  color: #374151;
  margin-bottom: 8px;
}

.contribution-type-selector select {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: calc(0.9rem * var(--type-scale, 1));
  background: white;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.contribution-type-selector select:focus {
  outline: none;
  border-color: #667eea;
}

@media (max-width: 480px) {
  .contribution-bar {
    padding: var(--space-sm) var(--space-md);
  }

  .contribution-btn {
    min-width: 60px;
    padding: var(--space-xs) var(--space-sm);
  }

  .contribution-btn .contribution-icon {
    font-size: calc(1.2rem * var(--type-scale, 1));
  }

  .contribution-btn .contribution-label {
    font-size: calc(10px * var(--type-scale, 1));
  }

  .contribution-modal {
    max-height: 85vh;
  }

  .voice-recording-indicator {
    width: 100px;
    height: 100px;
    font-size: calc(2.5rem * var(--type-scale, 1));
  }
}

.story-modal-tabs {
  display: flex;
  gap: 0;
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--space-lg);
  position: sticky;
  top: 0;
  z-index: 5;
}

.story-tab-btn {
  flex: 1;
  padding: var(--space-md) var(--space-lg);
  border: none;
  background: transparent;
  color: var(--color-text-light);
  font-size: var(--font-base);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border-bottom: 3px solid transparent;
  max-width: 200px;
}

.story-tab-btn:hover {
  color: var(--color-text);
  background: rgba(102, 126, 234, 0.05);
}

.story-tab-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  background: rgba(102, 126, 234, 0.1);
}

.story-chat-tab {
  padding: 0 !important;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 180px);
  max-height: 600px;
}

.story-chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.story-chat-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
}

.story-chat-header h3 {
  margin: 0 0 var(--space-xs) 0;
  font-size: var(--font-lg);
  color: var(--color-text);
}

.story-chat-hint {
  margin: 0;
  font-size: var(--font-sm);
  color: var(--color-text-light);
}

.story-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  background: var(--color-bg-secondary);
}

.story-chat-welcome {
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-text-light);
}

.story-chat-welcome p {
  margin: var(--space-sm) 0;
}

.story-chat-welcome ul {
  text-align: left;
  display: inline-block;
  margin: var(--space-md) 0;
  padding-left: var(--space-lg);
}

.story-chat-welcome li {
  margin: var(--space-xs) 0;
  color: var(--color-text);
  font-style: italic;
}

.story-chat-message {
  display: flex;
  gap: var(--space-sm);
  max-width: 85%;
  animation: messageSlideIn 0.3s ease;
}

.story-chat-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.story-chat-message.assistant {
  align-self: flex-start;
}

.story-chat-message .message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(18px * var(--type-scale, 1));
  flex-shrink: 0;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}

.story-chat-message.user .message-avatar {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.story-chat-message .message-content {
  padding: var(--space-md);
  border-radius: var(--radius-lg);
  line-height: 1.5;
  font-size: var(--font-base);
}

.story-chat-message.user .message-content {
  background: var(--color-primary);
  color: white;
  border-bottom-right-radius: var(--radius-sm);
}

.story-chat-message.assistant .message-content {
  background: var(--color-bg);
  color: var(--color-text);
  border-bottom-left-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

.story-chat-input-area {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--color-bg);
  border-top: 1px solid var(--color-border);
}

.story-chat-input {
  flex: 1;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--font-base);
  font-family: inherit;
  resize: none;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 44px;
  max-height: 120px;
}

.story-chat-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.story-chat-input::placeholder {
  color: var(--color-text-light);
}

.story-chat-send-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.story-chat-send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.story-chat-send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.story-chat-send-btn .send-icon {
  font-size: calc(18px * var(--type-scale, 1));
}

.chat-mode-badge.contribution-mode {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2) 0%, rgba(5, 150, 105, 0.15) 100%);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.story-chat-input-area {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--color-bg);
  border-top: 1px solid var(--color-border);
}

.story-chat-input-area > .chat-mode-badge {
  margin-bottom: 0;
}

.story-chat-input-area > textarea {
  flex: 1;
}

.story-chat-input-area > .story-chat-send-btn {
  align-self: flex-end;
  position: absolute;
  right: var(--space-lg);
  bottom: calc(var(--space-md) + 44px + var(--space-sm));
}

.story-chat-input-area {
  position: relative;
}

.story-chat-input-area > textarea {
  padding-right: 60px;
}

.story-chat-input-area > .story-chat-send-btn {
  position: absolute;
  right: calc(var(--space-lg) + 4px);
  bottom: calc(var(--space-md) + 4px);
}

.ai-dialogue-input-area .chat-mode-badge {
  margin-bottom: 8px;
}

@media (max-width: 768px) {
  .story-modal-tabs {
    padding: 0 var(--space-md);
  }

  .story-tab-btn {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-sm);
  }

  .story-chat-tab {
    height: calc(100vh - 200px);
  }

  .story-chat-message {
    max-width: 90%;
  }

  .story-chat-header {
    padding: var(--space-md);
  }

  .story-chat-messages {
    padding: var(--space-md);
  }

  .story-chat-input-area {
    padding: var(--space-sm) var(--space-md);
  }
}

.ai-dialogue-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.ai-dialogue-container {
  position: relative;
  background: var(--color-bg);
  border-radius: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: none;
  animation: none;
}

.ai-dialogue-header {
  padding: var(--space-lg);
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark, #5a67d8));
  color: white;
  position: relative;
}

.ai-dialogue-header h3 {
  margin: 0 0 var(--space-xs) 0;
  font-size: var(--font-xl);
  font-weight: 700;
}

.ai-dialogue-subtitle {
  margin: 0;
  opacity: 0.9;
  font-size: var(--font-sm);
}

.ai-dialogue-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: white;
  font-size: var(--font-xl);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.ai-dialogue-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.ai-dialogue-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  min-height: 200px;
  max-height: none; /* No max-height, use flex layout */
  background: var(--color-bg-secondary);
}

.ai-dialogue-welcome {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-lg);
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.ai-dialogue-welcome .ai-avatar {
  font-size: calc(2.5rem * var(--type-scale, 1));
  flex-shrink: 0;
}

.ai-dialogue-message {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  animation: messageSlideIn 0.3s ease-out;
}

.ai-dialogue-message.user {
  flex-direction: row-reverse;
}

.ai-dialogue-message .message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(1.25rem * var(--type-scale, 1));
  flex-shrink: 0;
}

.ai-dialogue-message .message-content {
  max-width: 75%;
  padding: var(--space-md);
  border-radius: var(--radius-lg);
  line-height: 1.5;
}

.ai-dialogue-message.user .message-content {
  background: var(--color-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.ai-dialogue-message.assistant .message-content {
  background: white;
  color: var(--color-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.ai-dialogue-message.typing .message-content {
  padding: var(--space-sm) var(--space-md);
}

.ai-dialogue-input-area {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  display: flex;
  gap: var(--space-sm);
  align-items: flex-end;
}

.ai-dialogue-input {
  flex: 1;
  padding: var(--space-sm) var(--space-md);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: var(--font-base);
  resize: none;
  font-family: inherit;
  line-height: 1.5;
  transition: border-color 0.2s ease;
}

.ai-dialogue-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.ai-dialogue-buttons {
  display: flex;
  flex-direction: row;
  gap: var(--space-xs);
  align-items: stretch;
}

.ai-dialogue-voice {
  padding: var(--space-sm);
  background: var(--color-bg-tertiary, #f5f5f5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: calc(1.25rem * var(--type-scale, 1));
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  transition: all 0.2s ease;
}

.ai-dialogue-voice:hover:not(:disabled) {
  background: var(--color-bg-secondary);
  border-color: var(--color-primary);
}

.ai-dialogue-voice:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ai-dialogue-voice.recording {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border-color: #dc2626;
  animation: voice-recording-pulse 1.5s ease-in-out infinite;
}

.ai-dialogue-voice.recording .voice-icon {
  color: white;
}

.ai-dialogue-send {
  padding: var(--space-sm) var(--space-md);
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-sm);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  transition: all 0.2s ease;
  white-space: nowrap;
}

.ai-dialogue-send:hover:not(:disabled) {
  background: var(--color-primary-dark, #5a67d8);
  transform: translateY(-1px);
}

.ai-dialogue-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ai-dialogue-footer {
  padding: var(--space-md) var(--space-lg);
  padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
  background: var(--color-bg-secondary);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: var(--space-sm);
}

.ai-dialogue-save {
  flex: 1;
  padding: var(--space-md) var(--space-lg);
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border: none;
  border-radius: var(--radius-lg);
  font-size: var(--font-base);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ai-dialogue-save:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.ai-dialogue-save:disabled {
  background: var(--color-text-light);
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-dialogue-exit {
  padding: var(--space-md) var(--space-lg);
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: var(--font-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.ai-dialogue-exit:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text);
}

.ai-dialogue-finish {
  flex: 1;
  padding: var(--space-md) var(--space-lg);
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border: none;
  border-radius: var(--radius-lg);
  font-size: var(--font-base);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ai-dialogue-finish:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.ai-dialogue-finish:disabled {
  background: var(--color-text-light);
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .ai-dialogue-modal {
    top: var(--mobile-top-bar-total-height);
    left: 0;
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }

  .ai-dialogue-container {
    border-radius: 0;
    max-height: none;
    height: 100%;
  }

  .ai-dialogue-messages {
    max-height: none;
    flex: 1;
  }

  .ai-dialogue-message .message-content {
    max-width: 85%;
  }
}

.chapter-player-modal {
  /* Inherits from .event-video-player-modal */
}

.chapter-player-wrapper {
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  max-width: 95vw;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
}

.chapter-player-wrapper.desktop {
  width: 1200px;
  max-width: 95vw;
}

/* fluffy-puzzling-dongarra S1 D1 (Iron-Law audit-all-peers): max-width/height
   100vw/100vh → 100% so the chapter-player wrapper anchors to its parent
   bounds, not to the iOS Safari visual viewport with scrollbar gutter. */
.chapter-player-wrapper.mobile {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  border-radius: 0;
  box-sizing: border-box;
}

.chapter-player-container.desktop-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chapter-player-container.mobile-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chapter-video-main {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  min-width: 0;
}

.chapter-video-main video {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
}

.mobile-layout .chapter-video-main video {
  max-height: 50vh;
}

.chapter-title-overlay {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.95), rgba(118, 75, 162, 0.95));
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.chapter-title-overlay.visible {
  opacity: 1;
}

.chapter-current-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #1a365d, #2c5282);
  color: white;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chapter-indicator-label {
  font-size: calc(0.7rem * var(--type-scale, 1));
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.7;
}

.chapter-indicator-title {
  flex: 1;
  font-size: calc(0.95rem * var(--type-scale, 1));
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-list-toggle {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 6px;
  width: 36px;
  height: 36px;
  font-size: calc(1.2rem * var(--type-scale, 1));
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chapter-list-toggle:hover {
  background: rgba(255, 255, 255, 0.25);
}

.chapter-sidebar {
  width: 320px;
  min-width: 280px;
  background: #111;
  border-left: 1px solid #333;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.3s ease, min-width 0.3s ease;
}

.chapter-sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-left: none;
}

.chapter-sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #1a365d, #2c5282);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chapter-sidebar-header h4 {
  margin: 0;
  color: white;
  font-size: calc(0.95rem * var(--type-scale, 1));
  flex: 1;
}

.chapter-sidebar-header .chapter-count {
  font-size: calc(0.75rem * var(--type-scale, 1));
  color: rgba(255, 255, 255, 0.7);
}

.chapter-sidebar-collapse {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 4px;
  width: 28px;
  height: 28px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(0.8rem * var(--type-scale, 1));
}

.chapter-sidebar-collapse:hover {
  background: rgba(255, 255, 255, 0.25);
}

.chapter-sidebar-expand {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: linear-gradient(135deg, #1a365d, #2c5282);
  border: none;
  border-radius: 8px 0 0 8px;
  padding: 12px 8px;
  color: white;
  font-size: calc(0.8rem * var(--type-scale, 1));
  cursor: pointer;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  z-index: 10;
}

.chapter-sidebar-expand:hover {
  background: linear-gradient(135deg, #2c5282, #3182ce);
}

.chapter-list,

.chapter-list-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.chapter-list-mobile {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #111;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  border-top: 1px solid #333;
  z-index: 50;
}

.chapter-list-mobile.expanded {
  max-height: 60vh;
  overflow-y: auto;
}

.chapter-list-header-mobile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, #1a365d, #2c5282);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  position: sticky;
  top: 0;
  z-index: 10;
}

.chapter-list-header-mobile h4 {
  margin: 0;
  color: white;
  font-size: calc(0.95rem * var(--type-scale, 1));
}

.chapter-list-close-mobile {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  color: white;
  font-size: calc(1.2rem * var(--type-scale, 1));
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chapter-list-close-mobile:hover {
  background: rgba(255, 255, 255, 0.25);
}

.chapter-nav-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.2s;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.chapter-nav-item:hover {
  background: rgba(102, 126, 234, 0.15);
}

.chapter-nav-item.active {
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.3), rgba(118, 75, 162, 0.3));
  border-left: 3px solid #667eea;
}

.chapter-nav-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(0.8rem * var(--type-scale, 1));
  font-weight: 600;
  flex-shrink: 0;
}

.chapter-nav-item.active .chapter-nav-number {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
}

.chapter-nav-info {
  flex: 1;
  min-width: 0;
}

.chapter-nav-title {
  color: #e5e5e5;
  font-size: calc(0.9rem * var(--type-scale, 1));
  font-weight: 500;
  line-height: 1.3;
}

.chapter-nav-item.active .chapter-nav-title {
  color: white;
}

.chapter-nav-desc {
  color: rgba(255, 255, 255, 0.5);
  font-size: calc(0.75rem * var(--type-scale, 1));
  margin-top: 4px;
  line-height: 1.4;
}

.chapter-nav-time {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
}

.chapter-start-time {
  color: #667eea;
  font-size: calc(0.8rem * var(--type-scale, 1));
  font-weight: 500;
  font-family: monospace;
}

.chapter-nav-item.active .chapter-start-time {
  color: #a5b4fc;
}

.chapter-duration {
  color: rgba(255, 255, 255, 0.4);
  font-size: calc(0.7rem * var(--type-scale, 1));
  margin-top: 2px;
}

@media (max-width: 768px) {
  /* fluffy-puzzling-dongarra S1 D1 (Iron-Law audit-all-peers): max-width/height
     100vw/100vh → 100% on the mobile-breakpoint override of the .desktop
     variant of chapter-player. Same anchoring discipline. */
  .chapter-player-wrapper.desktop {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    box-sizing: border-box;
  }

  .chapter-player-container.desktop-layout {
    flex-direction: column;
  }

  .chapter-sidebar {
    width: 100%;
    max-height: 40vh;
    border-left: none;
    border-top: 1px solid #333;
  }

  .chapter-title-overlay {
    bottom: 60px;
    padding: 8px 16px;
  }

  .overlay-chapter-title {
    font-size: calc(1rem * var(--type-scale, 1));
  }
}

.story-card-live-indicator {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: #dc2626;
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: calc(0.7rem * var(--type-scale, 1));
  font-weight: 700;
  text-transform: uppercase;
  z-index: 10;
}

.story-card-live-indicator .live-dot-small {
  width: 6px;
  height: 6px;
  background: white;
  border-radius: 50%;
  animation: livePulse 1.5s ease-in-out infinite;
}

.story-person-picker-modal {
  display: none;
  position: fixed;
  top: var(--nav-height);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1100;
  justify-content: center;
  align-items: center;
  padding: var(--space-md);
}

.story-person-picker-content {
  background: var(--color-bg);
  border-radius: var(--radius-xl);
  max-width: 400px;
  width: 100%;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.story-person-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

.story-person-picker-header h3 {
  margin: 0;
  font-size: var(--font-lg);
}

.story-person-picker-search {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

.story-person-picker-search input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--font-base);
}

.story-person-picker-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm) 0;
  max-height: 300px;
}

.story-person-picker-item {
  display: flex;
  flex-direction: column;
  padding: var(--space-sm) var(--space-lg);
  cursor: pointer;
  transition: background 0.2s ease;
}

.story-person-picker-item:hover {
  background: var(--color-bg-secondary);
}

.story-person-picker-name {
  font-weight: 600;
  color: var(--color-text);
}

.story-person-picker-rel {
  font-size: var(--font-sm);
  color: var(--color-text-light);
}

.story-person-picker-empty {
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-text-light);
}

.story-person-picker-loading {
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-text-light);
}

.story-person-picker-context {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
}

.story-person-picker-context label {
  display: block;
  margin-bottom: var(--space-xs);
  font-weight: 600;
  color: var(--color-text);
}

.story-person-picker-context input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--font-base);
  margin-bottom: var(--space-md);
}

.story-person-picker-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
}

.story-person-grid-content {
  max-width: 500px;
}

.story-person-picker-actions-top {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  align-items: center;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
}

.story-person-picker-actions-top .btn-sm {
  padding: 4px 12px;
  font-size: var(--font-sm);
}

.story-tag-count {
  margin-left: auto;
  font-size: var(--font-sm);
  color: var(--color-text-light);
}

.story-person-picker-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-xs);
  padding: var(--space-md);
  overflow-y: auto;
  max-height: 300px;
}

.story-person-grid-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--color-bg);
}

.story-person-grid-item:hover {
  border-color: var(--color-primary);
  background: rgba(102, 126, 234, 0.05);
}

.story-person-grid-item.checked {
  border-color: var(--color-success);
  background: rgba(16, 185, 129, 0.1);
}

.story-person-checkbox {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(12px * var(--type-scale, 1));
  font-weight: bold;
  color: white;
  flex-shrink: 0;
}

.story-person-checkbox.checked {
  background: var(--color-success);
  border-color: var(--color-success);
}

.story-person-name {
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.story-person-picker-footer {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-border);
  justify-content: flex-end;
  background: var(--color-bg-secondary);
}

@media (max-width: 480px) {
  .story-person-picker-grid {
    grid-template-columns: 1fr;
  }
}

.story-persons-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}

.story-persons-header h3 {
  margin: 0;
}

.story-add-person-btn {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-sm);
}

.story-persons-empty {
  color: var(--color-text-light);
  font-style: italic;
  font-size: var(--font-sm);
  margin: var(--space-sm) 0;
}

.story-chapters-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
  gap: var(--space-sm);
  flex-wrap: nowrap;
}

.story-chapters-header h3 {
  margin: 0;
  flex-shrink: 1;
  min-width: 0;
}

.story-add-chapter-btn {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-sm);
  flex-shrink: 0;
  white-space: nowrap;
  background: linear-gradient(135deg, var(--color-primary, #667eea), var(--color-primary-dark, #5a67d8));
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  min-width: fit-content;
}

.story-add-chapter-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.story-chapters-empty {
  color: var(--color-text-light);
  font-style: italic;
  font-size: var(--font-sm);
  margin: var(--space-sm) 0;
}

.chapter-reorder-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chapter-reorder-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-xs);
  cursor: grab;
  transition: all 0.2s;
  border: 2px solid transparent;
}

.chapter-reorder-item:active {
  cursor: grabbing;
}

.chapter-reorder-item.dragging {
  opacity: 0.5;
  background: var(--color-bg-tertiary);
}

.chapter-reorder-item.drag-over {
  border-color: var(--color-primary);
  background: white;
}

.chapter-reorder-item.new-chapter {
  background: linear-gradient(135deg, #dbeafe 0%, #e0e7ff 100%);
  border: 2px dashed var(--color-primary);
}

.chapter-reorder-handle {
  color: var(--color-text-light);
  font-size: calc(16px * var(--type-scale, 1));
  cursor: grab;
}

.chapter-reorder-number {
  width: 24px;
  height: 24px;
  background: var(--color-primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-sm);
  font-weight: 600;
}

.chapter-reorder-title {
  flex: 1;
  font-size: var(--font-base);
}

.chapter-reorder-item.new-chapter .chapter-reorder-title {
  font-weight: 600;
  color: var(--color-primary);
}

@media (max-width: 768px) {
  .story-person-picker-content {
    max-height: 90vh;
    margin: var(--space-sm);
  }

  .story-person-picker-list {
    max-height: 250px;
  }

  .add-chapter-modal-content {
    width: 95%;
    max-height: 90vh;
    margin: var(--space-sm);
  }

  .add-chapter-modal-header,
  .add-chapter-modal-body,
  .add-chapter-modal-footer {
    padding: var(--space-md);
  }
}

@media (min-width: 1024px) {
  /* Desktop windowing - modals render beside sidebar, not over it */


  /* All modals must respect FAA header boundary */
  /* Mobile Modal (used for training photos, documents, AI review) - render in app window */
  .mobile-modal {
    top: var(--nav-height) !important;
    left: var(--side-nav-width) !important;
    width: calc(100% - var(--side-nav-width)) !important;
    max-width: none !important;
    max-height: calc(100vh - var(--nav-height)) !important;
    transform: none !important;
  }

  /* Story Modal - render in app window */
  .story-modal,
  .story-detail-modal {
    top: var(--nav-height) !important;
    left: var(--side-nav-width) !important;
    width: calc(100% - var(--side-nav-width)) !important;
    max-width: none !important;
    max-height: calc(100vh - var(--nav-height)) !important;
    transform: none !important;
  }

  /* AI Document Analysis Modal - render in app window */
  .ai-modal-fullscreen {
    top: var(--nav-height) !important;
    left: var(--side-nav-width) !important;
    width: calc(100% - var(--side-nav-width)) !important;
    max-width: none !important;
    max-height: calc(100vh - var(--nav-height)) !important;
    transform: none !important;
  }

  /* Voice Training Modal - render in app window */
  .voice-training-modal {
    top: var(--nav-height) !important;
    left: var(--side-nav-width) !important;
    width: calc(100% - var(--side-nav-width)) !important;
    max-width: none !important;
    max-height: calc(100vh - var(--nav-height)) !important;
    transform: none !important;
  }

  /* Training Photo Modal - render in app window */
  .training-photo-modal {
    top: var(--nav-height) !important;
    left: var(--side-nav-width) !important;
    width: calc(100% - var(--side-nav-width)) !important;
    max-width: none !important;
    max-height: calc(100vh - var(--nav-height)) !important;
    transform: none !important;
  }

  /* Document Upload Modal - render in app window */
  .document-upload-modal {
    top: var(--nav-height) !important;
    left: var(--side-nav-width) !important;
    width: calc(100% - var(--side-nav-width)) !important;
    max-width: none !important;
    max-height: calc(100vh - var(--nav-height)) !important;
    transform: none !important;
  }

  /* Photo Source Modal - render in app window */
  .photo-source-modal-overlay {
    top: var(--nav-height) !important;
    left: var(--side-nav-width) !important;
    width: calc(100% - var(--side-nav-width)) !important;
    height: calc(100vh - var(--nav-height)) !important;
  }

  /* Media Modal (photo viewer) - render in app window */
  .media-modal-overlay {
    top: var(--nav-height) !important;
    left: var(--side-nav-width) !important;
    width: calc(100% - var(--side-nav-width)) !important;
    height: calc(100vh - var(--nav-height)) !important;
  }

  /* Feedback Modal - render in app window */
  .feedback-modal-overlay {
    top: var(--nav-height) !important;
    left: var(--side-nav-width) !important;
    width: calc(100% - var(--side-nav-width)) !important;
    height: calc(100vh - var(--nav-height)) !important;
  }

  /* Generic modal-overlay class - render in app window */
  .modal-overlay {
    top: var(--nav-height) !important;
    left: var(--side-nav-width) !important;
    width: calc(100% - var(--side-nav-width)) !important;
    height: calc(100vh - var(--nav-height)) !important;
  }

  /* Login overlay should still cover full screen (before authentication) */
  .login-overlay {
    left: 0 !important;
    width: 100% !important;
  }

  /* Generic modal backdrops - respect sidebar */
  .modal-backdrop-windowed {
    left: var(--side-nav-width);
    width: calc(100% - var(--side-nav-width));
  }

  /* Ensure sidebar stays above modals (z-index management) */
  .side-nav {
    z-index: 10001;
  }

  /* CRITICAL - All modals and overlays must respect header height */
  /* Desktop: modals render within app window (below header, right of sidebar) */
  /* Added media-browser-modal-overlay to respect app window frame */
  .modal-overlay,
  .leaderboard-hero-overlay,
  .leaderboard-hero-side-by-side,
  .ai-dialogue-modal,
  .contribution-modal,
  .photo-source-modal-overlay,
  .media-modal-overlay,
  .feedback-modal-overlay,
  .media-browser-modal-overlay {
    top: var(--nav-height) !important;
  }

  /* Media Browser Modal - render in app window (below header, right of sidebar) */
  .media-browser-modal-overlay {
    left: var(--side-nav-width) !important;
    width: calc(100% - var(--side-nav-width)) !important;
    height: calc(100vh - var(--nav-height)) !important;
  }

  /* AI Dialogue Modal - render in app window (below header, right of sidebar) */
  .ai-dialogue-modal {
    left: var(--side-nav-width) !important;
    width: calc(100% - var(--side-nav-width)) !important;
    height: calc(100vh - var(--nav-height)) !important;
  }
}

@media (max-width: 767px) {
  /* binary-hatching-pearl D1 Iron-Law fix (2026-05-09): the prior block here
     overrode .top-nav height to `var(--nav-height)` (60px, no safe-area) and
     .main-content margin-top likewise. On iPhone with notch / Dynamic Island,
     this hid the hamburger button behind the safe-area. The canonical mobile
     top-bar height now lives in `mobile.css` as `--mobile-top-bar-total-height`
     (= 56px + env(safe-area-inset-top)); this stylesheet defers to it. */

  /* excavating-mobile-bookends S1 D1+D2 (2026-05-15) — Iron-Law smoking-gun #3.
     REMOVED `.top-nav .nav-center { display: none }`. Pre-S1, since the Phase 6
     stories.css extraction (March 2026), that rule hid the entire .nav-center
     on mobile at specificity (0,2,0) — silently defeating EVERY prior fix that
     touched the lower-specificity `.nav-center` rule in styles.css (most
     recently cementing-modal-chrome-fleet S1 D4, 2026-05-13 — see
     styles.css:3536+). Six consecutive trains touched the mobile header title
     slot; each shipped deployment-gate ✅ via cURL+grep against the styles.css
     surface, yet the iPhone realization gate kept failing because stories.css
     always won the cascade. The stale comment labeled .nav-center as "search"
     — but `.nav-center` is the canonical mobile title slot per the FFA Window
     Frame top-band contract (mobile-shell.js::_injectMobileTopBar appends
     `.mobile-view-title` + `.mobile-view-focus-identifier` into it; child
     visibility is independently governed by mobile.css:238 which hides only
     `.focus-chips-container`, leaving the title + focus-identifier visible).
     This is the same cascade-specificity audit class as the white-band smoking
     gun captured in memory `feedback_top_nav_white_smoking_gun.md` — the fix
     at one specificity level was overridden by an undiscovered duplicate at
     a higher specificity level.
     INVARIANT (grep-checkable): .nav-center is the canonical mobile title
     slot. NEVER apply `display: none` to `.nav-center`, `.top-nav .nav-center`,
     `nav.top-nav .nav-center`, or any equivalent selector at any breakpoint
     ≤768px. See `MOBILE_SCAFFOLD_CONTRACT § Cell C-1` + `mobile-shell.js`
     header docblock for the title-slot contract. */

  /* Circular user control on mobile (like desktop) */
  .top-nav .user-menu-rect {
    background: var(--color-primary);
    border-radius: var(--radius-full);
    padding: 8px 12px;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* All modal overlays and backdrops respect mobile-aware header on mobile.
     Use the canonical safe-area-aware total height from mobile.css. */
  .modal-overlay,
  .leaderboard-hero-overlay,
  .ai-dialogue-modal,
  .contribution-modal,
  .photo-source-modal-overlay,
  .media-modal-overlay,
  .feedback-modal-overlay {
    top: var(--mobile-top-bar-total-height) !important;
    left: 0 !important;
    width: 100% !important;
  }

  /* Hide Hello Joe/Leaderboard panel completely on mobile */
  .leaderboard-hero-overlay,
  .leaderboard-hero-side-by-side {
    display: none !important;
  }
}

.ai-dialogue-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, #0d1b2a 0%, #1b2838 100%);
  z-index: 15000;  /* Raised from 10000 to ensure above all modals */
  display: none;
}

.ai-dialogue-modal.active {
  display: flex !important;  /* Force display to override any conflicts */
}

.ai-dialogue-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 100%; /* Fill entire app area instead of 600px centered */
  margin: 0;
}

.ai-dialogue-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(255,255,255,0.05);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.ai-dialogue-back {
  background: none;
  border: none;
  color: #fff;
  padding: 8px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
}

.ai-dialogue-back:hover {
  background: rgba(255,255,255,0.1);
}

.ai-dialogue-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: calc(18px * var(--type-scale, 1));
  font-weight: 600;
  color: #fff;
}

.ai-dialogue-icon {
  font-size: calc(24px * var(--type-scale, 1));
}

.ai-dialogue-mode-toggle {
  display: flex;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 2px;
}

.ai-dialogue-mode-toggle button {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.6);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: calc(14px * var(--type-scale, 1));
  cursor: pointer;
  transition: all 0.2s;
}

.ai-dialogue-mode-toggle button.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
}

.ai-dialogue-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.ai-dialogue-preview {
  background: linear-gradient(180deg, rgba(26, 41, 56, 0.98) 0%, #1a2938 100%);
  border-top: 1px solid rgba(255,255,255,0.1);
  max-height: 50%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  animation: aiDialogueSlideUp 0.3s ease-out;
}

.ai-dialogue-preview.minimized {
  max-height: 48px;
}

.ai-dialogue-preview.minimized .ai-preview-items,

.ai-dialogue-preview.minimized .ai-preview-actions {
  display: none;
}

.ai-dialogue-preview.minimized .ai-preview-toggle svg {
  transform: rotate(180deg);
}

.ai-dialogue-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(0,0,0,0.3);
  border-top: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.ai-dialogue-input-area .ai-send-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.ai-dialogue-input-area .ai-send-btn svg {
  width: 20px;
  height: 20px;
  stroke: white;
  fill: white;
}

.ai-dialogue-input-area .ai-send-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

@media (max-width: 767px) {
  .ai-dialogue-container {
    max-width: 100%;
  }

  .ai-dialogue-header {
    padding: 10px 12px;
  }

  .ai-dialogue-title {
    font-size: calc(16px * var(--type-scale, 1));
  }

  .ai-dialogue-mode-toggle button {
    padding: 5px 10px;
    font-size: calc(13px * var(--type-scale, 1));
  }

  .ai-message {
    max-width: 90%;
    padding: 10px 14px;
  }

  .ai-preview-actions {
    flex-direction: column;
  }

  .ai-save-btn,
  .ai-exit-btn {
    width: 100%;
    padding: 14px;
  }
}

.chapter-draft-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #fff;
  font-size: calc(11px * var(--type-scale, 1));
  font-weight: var(--font-semibold);
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chapter-draft-badge::before {
  content: '✎';
}

.chapter-narrative {
  padding: var(--space-md);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
  margin-top: var(--space-sm);
  font-size: var(--font-sm);
  color: var(--color-text);
  line-height: 1.7;
  border-left: 3px solid var(--color-primary);
}

.unified-ai-modal.story-comment-mode {
  background: rgba(0, 0, 0, 0.3);
  padding: 24px;
  align-items: center;
  justify-content: center;
}

.unified-ai-modal.story-comment-mode .unified-ai-container {
  /* 85% of App Panel dimensions — large but clearly a modal */
  width: calc((100vw - var(--side-nav-width)) * 0.85);
  max-width: 95%;
  height: calc((100vh - var(--nav-height)) * 0.85);
  max-height: 95%;
  border-radius: var(--radius-xl);
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.5);
}

.ai-header-model-badge.story-studio {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.1));
  color: white;
  font-weight: 600;
}

.unified-ai-header.story-studio-mode {
  background: linear-gradient(135deg, #6d28d9 0%, #4c1d95 100%);
}

.story-studio-mode .unified-ai-new-convo-btn { display: none; }

.story-studio-mode .unified-ai-exit-studio-btn { display: inline-flex; }

.story-studio-badge {
  background: linear-gradient(135deg, #667eea, #764ba2) !important;
  color: white !important;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: calc(10px * var(--type-scale, 1));
  letter-spacing: 0.03em;
}

.story-seeds .seed-text {
  font-size: calc(13px * var(--type-scale, 1));
  color: #6366f1;
  background: #eef2ff;
  padding: 8px 12px;
  border-radius: 6px;
  margin: 4px 0 0;
}

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.chapter-item:hover {
  border-color: #6366f1;
}

.chapter-item.active {
  background: #6366f1;
  border-color: #6366f1;
  color: white;
}

.chapter-num {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e5e7eb;
  border-radius: 50%;
  font-size: calc(12px * var(--type-scale, 1));
  font-weight: 600;
}

.chapter-item.active .chapter-num {
  background: rgba(255, 255, 255, 0.2);
}

.chapter-title {
  font-size: calc(13px * var(--type-scale, 1));
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.chapter-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.chapter-item.active {
  background: rgba(245, 158, 11, 0.2);
  border-left: 3px solid #f59e0b;
}

.chapter-num {
  width: 24px;
  height: 24px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(0.75rem * var(--type-scale, 1));
  font-weight: 600;
}

.chapter-title {
  font-size: calc(0.85rem * var(--type-scale, 1));
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.story-card-new-dot {
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    display: inline-block;
    margin-left: 6px;
    vertical-align: middle;
    animation: newBadgePulse 2s ease-in-out 3;
}

/* ══════════════════════════════════════════════════════════════════════════
   The Reading Room — Stories modal themed vessel (Issue 8)
   directing-desktop-scenes S6. Mounted-vessel pattern (R20): the modal keeps
   its geometry contract (app-pane pinning at ≥1024px, ladder rungs, band
   citizenship); it carries its own library-night room, the chassis floats at
   positive inset inside it, and the content sits padded within the frame.
   Scroll conversion (R22): the surface flips from whole-element scroll to
   flex column + per-tab internal scroll so the frame never scrolls away
   with the prose. Readability law (R21): the story itself reads on a
   parchment page; the dark glass is chrome only.
   EVERY rule scoped under .ffvc-framed, which only ever stamps on desktop
   (FFVChassis gates) — the mobile story surface is byte-identical.
   ════════════════════════════════════════════════════════════════════════ */

.story-detail-modal.ffvc-framed {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background:
        radial-gradient(ellipse 80% 62% at 26% 14%,
            rgba(58, 72, 44, 0.34), rgba(7, 11, 9, 0.95) 76%),
        #0a0e0c;
    padding: 36px 52px 42px;
}
.story-detail-modal.ffvc-framed > :not(.ffv-chassis-layer):not(.ffs-handle) {
    position: relative;
    z-index: 1;
}

/* chrome rows pin; the tab surface scrolls internally */
.story-detail-modal.ffvc-framed .story-modal-header {
    position: static;
    flex-shrink: 0;
    background: linear-gradient(110deg,
        rgba(37, 52, 38, 0.85), rgba(24, 32, 24, 0.8) 55%, rgba(46, 36, 20, 0.75));
    border-bottom: 1px solid rgba(217, 179, 106, 0.25);
    border-radius: 10px 12px 0 0;
}
.story-detail-modal.ffvc-framed .story-modal-header h2 {
    font-family: var(--ffv-display-font, 'Playfair Display', Georgia, serif);
    font-weight: 600;
    letter-spacing: 0.012em;
    color: #f0e3c0;
    text-shadow: 0 0 22px rgba(217, 179, 106, 0.25);
}
.story-detail-modal.ffvc-framed .story-modal-tabs {
    position: static;
    flex-shrink: 0;
    background: rgba(16, 22, 17, 0.72);
    border-bottom: 1px solid rgba(217, 179, 106, 0.18);
}
.story-detail-modal.ffvc-framed .story-tab-btn { color: #b7ab8c; }
.story-detail-modal.ffvc-framed .story-tab-btn:hover {
    color: #ecdfba;
    background: rgba(217, 179, 106, 0.07);
}
.story-detail-modal.ffvc-framed .story-tab-btn.active {
    color: #e9cf9a;
    border-bottom-color: var(--ffv-brass, #d9b36a);
    background: rgba(217, 179, 106, 0.1);
}
.story-detail-modal.ffvc-framed .narration-master-toggle {
    flex-shrink: 0;
    margin-top: 8px;
}
.story-detail-modal.ffvc-framed .narration-toggle-content {
    background: linear-gradient(135deg, #1c2b20, #14201a);
    border: 1px solid rgba(217, 179, 106, 0.18);
}

/* the internal scroll region (per tab) */
.story-detail-modal.ffvc-framed .story-tab-content {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    max-height: none;
    overflow-y: auto;
}
.story-detail-modal.ffvc-framed .story-modal-layout { min-height: 100%; }
.story-detail-modal.ffvc-framed .story-sidebar {
    top: 12px;
    background: linear-gradient(180deg,
        rgba(217, 179, 106, 0.08), rgba(58, 72, 44, 0.12));
    border-right: 1px solid rgba(217, 179, 106, 0.14);
}

/* the reading page: parchment centered on the glass */
.story-detail-modal.ffvc-framed .story-modal-layout .story-modal-content {
    background: var(--ffv-page, #f7f0df);
    max-width: 920px;
    margin: 18px auto 28px;
    border-radius: 4px 6px 5px 4px;
    box-shadow:
        0 14px 44px rgba(5, 8, 6, 0.55),
        0 0 0 1px rgba(217, 179, 106, 0.2);
    padding: 34px 42px 40px;
}

/* the chat page: same parchment, its own card */
.story-detail-modal.ffvc-framed .story-chat-tab {
    padding: 16px 22px 22px !important;
}
.story-detail-modal.ffvc-framed .story-chat-container {
    background: var(--ffv-page, #f7f0df);
    border-radius: 5px;
    box-shadow:
        0 14px 44px rgba(5, 8, 6, 0.5),
        0 0 0 1px rgba(217, 179, 106, 0.2);
    overflow: hidden;
}
.story-detail-modal.ffvc-framed .story-chat-header {
    background: var(--ffv-page-deep, #efe4c9);
}

/* truly-ambient-fergiai S4 (W4) — the quieter SECOND line under a Fergi reply.
   It qualifies an answer (the W1.3 degradation notice; a handoff's "Fergi took
   you to the Light Table"); it never replaces one, which is why it is not a
   message bubble. */
.story-chat-note {
    margin: 4px 0 10px 44px;
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--text-tertiary, #8a8175);
    font-style: italic;
}

/* ============================================================================
   Compact Stories card — enhancing-trio-biographies S2 (LS-004), Joe 2026-10-05:
   official photo left (it sets the row height), bold title, as much analysis as
   fits; no author line, no action row; the whole card Watches. The analysis
   clamp is MEASURED to the photo by FFAStoryCard.fit (js/core/story-card.js);
   the -webkit-line-clamp here is only the pre-measure floor. At large text the
   card grows (min-height, not height) instead of clipping the title.
   ============================================================================ */
.bio-card.bio-card--compact {
    grid-template-columns: 88px 1fr auto;
    gap: 14px;
    padding: 10px 12px;
    align-items: start;
    min-height: 108px;
}
.bio-card.bio-card--compact .bio-card-portrait {
    width: 88px;
    height: 88px;
}
.bio-card.bio-card--compact .bio-card-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.bio-card.bio-card--compact .bio-card-title {
    margin: 0;
    font-weight: 700;
    line-height: 1.25;
    font-size: calc(1.05rem * var(--type-scale, 1));
}
.bio-card.bio-card--compact .bio-card-title .bio-card-version,
.bio-card.bio-card--compact .bio-card-title .bio-card-unauthorized {
    vertical-align: middle;
    margin-left: 6px;
}
.bio-card.bio-card--compact .bio-card-analysis {
    margin: 4px 0 0;
    font-size: calc(0.9rem * var(--type-scale, 1));
    line-height: 1.4;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    color: var(--ffvr-ink-muted, #475569);
}
.bio-card.bio-card-tinted.bio-card--compact .bio-card-analysis {
    color: rgba(255, 255, 255, 0.94);
}
.bio-card.bio-card--compact .bio-reorder-controls {
    align-self: center;
}
.bio-card.bio-card--compact:focus-visible {
    outline: 3px solid #fde68a;
    outline-offset: 2px;
}
.bio-card.bio-card--compact .ffa-card-portrait--missing {
    background: rgba(255, 255, 255, 0.12);
}
@media (max-width: 640px) {
    .bio-card.bio-card--compact {
        grid-template-columns: 72px 1fr auto;
        grid-template-areas: "portrait body reorder";
        min-height: 92px;
    }
    .bio-card.bio-card--compact .bio-card-portrait {
        width: 72px;
        height: 72px;
    }
}
