/*
 * Retro Narrative Styles
 * ======================
 * 8-bit inspired styles for structured AI DM output
 * Includes NPC dialogue, perception-gated content, and action styling
 */

/* ========================================
 * Retro Design Tokens
 * ======================================== */

:root {
  /* Retro Color Palette */
  --retro-black: #0f0f23;
  --retro-dark-gray: #1a1a2e;
  --retro-purple: #7B68EE;
  --retro-gold: #FFD700;
  --retro-cyan: #00CED1;
  --retro-green: #32CD32;
  --retro-red: #DC143C;
  --retro-blue: #4169E1;
}

/* ========================================
 * Structured Narrative Container
 * ======================================== */

.structured-narrative {
  display: flex;
  flex-direction: column;
  gap: var(--space-3, 0.75rem);
}

.narrative-segment {
  margin: var(--space-3, 0.75rem) 0;
  padding: var(--space-3, 0.75rem);
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius-md, 6px);
  border: 1px solid rgba(255, 255, 255, 0.05);
  position: relative;
  /* Ensure segments stack properly and don't overlap */
  display: block;
  clear: both;
}

/* ========================================
 * NPC Dialogue Block
 * ======================================== */

.npc-dialogue {
  --npc-color: var(--retro-purple); /* Overridden per-NPC via inline style */

  background: color-mix(in srgb, var(--npc-color) 8%, transparent);
  border-left: 3px solid var(--npc-color);
  border-radius: var(--radius-sm, 4px);
  padding: var(--space-3, 0.75rem);
  position: relative;
}

.npc-header {
  display: flex;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  margin-bottom: var(--space-2, 0.5rem);
}

.npc-name {
  font-weight: 600;
  color: var(--npc-color);
  font-size: var(--font-size-sm, 0.875rem);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.npc-mood {
  font-size: var(--font-size-xs, 0.75rem);
  padding: 2px 6px;
  border-radius: var(--radius-sm, 4px);
  text-transform: lowercase;
  opacity: 0.8;
}

.npc-mood.friendly {
  background: rgba(50, 205, 50, 0.2);
  color: var(--retro-green);
}

.npc-mood.hostile {
  background: rgba(220, 20, 60, 0.2);
  color: var(--retro-red);
}

.npc-mood.neutral {
  background: rgba(128, 128, 128, 0.2);
  color: var(--color-text-secondary);
}

.npc-mood.suspicious {
  background: rgba(255, 165, 0, 0.2);
  color: #FFA500;
}

.npc-mood.mysterious {
  background: rgba(123, 104, 238, 0.2);
  color: var(--retro-purple);
}

.npc-mood.afraid {
  background: rgba(255, 255, 0, 0.15);
  color: #FFFF00;
}

.npc-mood.angry {
  background: rgba(220, 20, 60, 0.25);
  color: var(--retro-red);
}

.npc-mood.happy {
  background: rgba(50, 205, 50, 0.2);
  color: var(--retro-green);
}

.npc-speech-bubble {
  padding: var(--space-2, 0.5rem) 0;
}

.npc-speech-bubble p {
  margin: 0;
  color: var(--color-text-primary);
  line-height: 1.5;
}

/* Voice Variations - Subtle differences */
.voice-whispered .npc-speech-bubble {
  font-size: 0.9em;
  opacity: 0.9;
}

.voice-booming .npc-speech-bubble {
  font-weight: 500;
}

.voice-nervous .npc-speech-bubble,
.voice-elderly .npc-speech-bubble {
  font-style: italic;
}

/* Emotion Styling - Color hints only */
.emotion-angry .npc-name {
  color: var(--retro-red);
}

.emotion-nervous .npc-speech-bubble {
  font-style: italic;
}

/* ========================================
 * Inner Segment Types (beat, line, aside)
 * Context-aware via SegmentRegistry
 * ======================================== */

/* Base inner segment styles */
.npc-beat,
.npc-line,
.npc-aside {
  display: block;
  margin: var(--space-1, 0.25rem) 0;
}

.npc-beat:first-child,
.npc-line:first-child,
.npc-aside:first-child {
  margin-top: 0;
}

/* Beat - actions and gestures */
.npc-beat {
  font-style: italic;
  color: var(--color-text-secondary);
  opacity: 0.85;
}

.npc-beat em {
  font-style: normal; /* Already italic, em becomes normal */
  color: var(--npc-color);
  opacity: 0.9;
}

.npc-beat--action {
  /* Default action style */
}

.npc-beat--gesture {
  font-size: 0.95em;
}

.npc-beat--pause {
  margin: var(--space-2, 0.5rem) 0;
  opacity: 0.7;
}

/* Line - spoken dialogue */
.npc-line {
  color: var(--color-text-primary);
}

.npc-line--dialogue {
  /* Default dialogue style */
}

.npc-line--welcome {
  font-size: 1.05em;
  color: var(--npc-color);
}

.npc-line--prompt {
  /* Contains selection - subtle highlight */
  padding: var(--space-1, 0.25rem) 0;
}

.npc-line--reaction {
  /* Response to player choice */
}

.npc-line--inquiry {
  /* Question to player */
}

.npc-line--farewell {
  opacity: 0.9;
}

/* Aside - internal thoughts, muttering */
.npc-aside {
  font-style: italic;
  font-size: 0.9em;
  opacity: 0.75;
  color: var(--color-text-secondary);
}

.npc-aside--internal {
  /* Default internal thought */
}

.npc-aside--musing {
  opacity: 0.65;
}

.npc-aside--whisper {
  font-size: 0.85em;
  letter-spacing: 0.5px;
}

/* Pause indicator for segments that wait for input */
.npc-line[data-pause-after="true"]::after,
.npc-beat[data-pause-after="true"]::after {
  content: '';
  display: block;
  height: 2px;
  margin-top: var(--space-2, 0.5rem);
  background: linear-gradient(
    90deg,
    transparent 0%,
    color-mix(in srgb, var(--npc-color) 30%, transparent) 50%,
    transparent 100%
  );
}

/* Animation for animated segments */
@keyframes npc-segment-appear {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.npc-beat[data-animate="true"],
.npc-line[data-animate="true"],
.npc-aside[data-animate="true"] {
  animation: npc-segment-appear 0.3s ease-out;
}

/* ========================================
 * DM Narration Styles
 * ======================================== */

.dm-narration {
  padding: var(--space-3, 0.75rem);
  color: var(--color-text-primary);
  background: rgba(97, 175, 239, 0.06);
  border-left: 3px solid var(--color-accent-primary, #61afef);
  border-radius: var(--radius-sm, 4px);
  line-height: 1.6;
}

.dm-narration p {
  margin: 0 0 0.75rem 0;
  padding-bottom: 0.5rem;
}

.dm-narration p:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
}

/* Add subtle separator between paragraphs for readability */
.dm-narration p + p {
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

/* Mood variations */
.mood-tense {
  border-left: 2px solid var(--color-accent-warning);
  padding-left: var(--space-3, 0.75rem);
  background: rgba(229, 192, 123, 0.05);
}

.mood-mysterious {
  border-left: 2px solid var(--retro-purple);
  padding-left: var(--space-3, 0.75rem);
  background: rgba(123, 104, 238, 0.05);
}

.mood-ominous {
  border-left: 2px solid var(--retro-red);
  padding-left: var(--space-3, 0.75rem);
  background: rgba(220, 20, 60, 0.05);
}

.mood-calm {
  opacity: 0.9;
}

.mood-cheerful {
  border-left: 2px solid var(--retro-green);
  padding-left: var(--space-3, 0.75rem);
}

.mood-somber {
  opacity: 0.85;
  filter: saturate(0.8);
}

/* ========================================
 * DM Action Styles (Mechanical)
 * ======================================== */

.dm-action {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2, 0.5rem);
  padding: var(--space-2, 0.5rem) var(--space-3, 0.75rem);
  background: rgba(255, 215, 0, 0.08);
  border-left: 3px solid var(--retro-gold);
  border-radius: var(--radius-sm, 4px);
}

.dm-action p {
  margin: 0;
}

.dm-action--mechanical {
  font-family: var(--font-mono, 'Courier New', monospace);
  color: var(--retro-gold);
}

.dm-action .action-icon {
  font-size: var(--font-size-lg, 1.25rem);
  flex-shrink: 0;
}

/* ========================================
 * Perception-Gated Content
 * ======================================== */

.perception-revealed {
  position: relative;
  margin: var(--space-2, 0.5rem) 0;
  padding-left: 1.5em;
}

.perception-indicator {
  position: absolute;
  left: 0;
  opacity: 0.6;
  font-size: 0.9em;
}

/* Perception Tier Indicators */
.tier-obvious {
  border-left: 2px solid var(--color-accent-secondary);
  padding-left: var(--space-3, 0.75rem);
}

.tier-hidden {
  border-left: 2px solid var(--color-accent-primary);
  padding-left: var(--space-3, 0.75rem);
}

.tier-concealed {
  border-left: 2px solid var(--color-accent-warning);
  padding-left: var(--space-3, 0.75rem);
}

.tier-secret {
  border-left: 2px solid var(--retro-purple);
  padding-left: var(--space-3, 0.75rem);
}

/* Skill-specific coloring for perception checks */
.perception-revealed[data-skill="perception"] {
  --perception-color: #3b82f6; /* Blue */
}

.perception-revealed[data-skill="insight"] {
  --perception-color: #8b5cf6; /* Purple */
}

.perception-revealed[data-skill="investigation"] {
  --perception-color: #10b981; /* Green */
}

.perception-revealed[data-skill] {
  border-left-color: var(--perception-color);
}

.perception-revealed[data-skill] .perception-indicator {
  color: var(--perception-color);
}

/* ========================================
 * Passive Detection - Skill-Specific Styling
 * ======================================== */

/* Skill-specific color variables */
.perception-revealed[data-skill="perception"],
.perception-hidden[data-skill="perception"],
.perception-vague[data-skill="perception"] {
  --skill-color: #3b82f6; /* Blue */
  --skill-color-faded: rgba(59, 130, 246, 0.15);
  --skill-icon: '👁️';
}

.perception-revealed[data-skill="insight"],
.perception-hidden[data-skill="insight"],
.perception-vague[data-skill="insight"] {
  --skill-color: #8b5cf6; /* Purple */
  --skill-color-faded: rgba(139, 92, 246, 0.15);
  --skill-icon: '🧠';
}

.perception-revealed[data-skill="investigation"],
.perception-hidden[data-skill="investigation"],
.perception-vague[data-skill="investigation"] {
  --skill-color: #10b981; /* Green */
  --skill-color-faded: rgba(16, 185, 129, 0.15);
  --skill-icon: '🔍';
}

/* Revealed content styling */
.perception-revealed {
  position: relative;
  margin: var(--space-2, 0.5rem) 0;
  padding: var(--space-2, 0.5rem) var(--space-3, 0.75rem);
  padding-left: calc(var(--space-3, 0.75rem) + 3px);
  background: var(--skill-color-faded, rgba(59, 130, 246, 0.1));
  border-left: 3px solid var(--skill-color, #3b82f6);
  border-radius: 0 var(--radius-sm, 4px) var(--radius-sm, 4px) 0;
  animation: revealFadeIn 0.4s ease-out;
}

.perception-revealed .perception-indicator {
  position: absolute;
  left: var(--space-2, 0.5rem);
  top: var(--space-2, 0.5rem);
  color: var(--skill-color, #3b82f6);
  font-size: 0.9em;
  opacity: 0.8;
}

@keyframes revealFadeIn {
  from {
    opacity: 0;
    background: var(--skill-color-faded, rgba(59, 130, 246, 0.3));
  }
  to {
    opacity: 1;
    background: var(--skill-color-faded, rgba(59, 130, 246, 0.1));
  }
}

/* Skill badge for revealed content */
.perception-revealed::before {
  content: attr(data-skill);
  position: absolute;
  top: -0.5em;
  right: var(--space-2, 0.5rem);
  font-size: var(--font-size-xs, 0.75rem);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 6px;
  background: var(--skill-color, #3b82f6);
  color: white;
  border-radius: var(--radius-sm, 4px);
  opacity: 0.8;
}

/* Hidden perception content */
.perception-hidden {
  display: flex;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  padding: var(--space-2, 0.5rem) var(--space-3, 0.75rem);
  background: repeating-linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.1),
    rgba(0, 0, 0, 0.1) 10px,
    rgba(0, 0, 0, 0.15) 10px,
    rgba(0, 0, 0, 0.15) 20px
  );
  border-radius: var(--radius-sm, 4px);
  border: 1px dashed var(--skill-color, var(--color-text-muted));
}

.perception-hidden[data-skill] {
  border-color: var(--skill-color);
}

.perception-icon {
  opacity: 0.5;
  animation: perceptionPulse 2s ease-in-out infinite;
  color: var(--skill-color, inherit);
}

.perception-hint {
  color: var(--color-text-muted);
  font-style: italic;
  font-size: var(--font-size-sm, 0.875rem);
}

/* Skill-specific hint text */
.perception-hidden[data-skill="insight"] .perception-hint::before {
  content: '(Insight) ';
  color: var(--skill-color);
  font-weight: 500;
}

.perception-hidden[data-skill="investigation"] .perception-hint::before {
  content: '(Investigation) ';
  color: var(--skill-color);
  font-weight: 500;
}

@keyframes perceptionPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.7; }
}

/* Interactive perception (click-to-roll) */
.perception-interactive {
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

.perception-interactive:hover {
  background: repeating-linear-gradient(
    45deg,
    rgba(255, 215, 0, 0.1),
    rgba(255, 215, 0, 0.1) 10px,
    rgba(255, 215, 0, 0.15) 10px,
    rgba(255, 215, 0, 0.15) 20px
  );
  border-color: rgba(255, 215, 0, 0.5);
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.2);
}

.perception-interactive:focus-visible {
  outline: 2px solid var(--color-border-focus, #ffd700);
  outline-offset: 2px;
}

.perception-interactive .perception-roll-indicator {
  position: absolute;
  right: var(--space-2, 0.5rem);
  font-size: 1.1em;
  animation: diceWiggle 2s ease-in-out infinite;
}

@keyframes diceWiggle {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}

.perception-interactive:hover .perception-roll-indicator {
  animation: diceWiggleFast 0.3s ease-in-out infinite;
}

@keyframes diceWiggleFast {
  0%, 100% { transform: rotate(-10deg) scale(1.1); }
  50% { transform: rotate(10deg) scale(1.1); }
}

/* Revealed state after successful roll */
.perception-interactive.perception-revealed-success {
  cursor: default;
  background: var(--skill-color-faded, rgba(34, 197, 94, 0.15));
  border-color: var(--skill-color, #22c55e);
  border-style: solid;
  animation: revealSuccess 0.5s ease-out;
}

.perception-interactive.perception-revealed-success .perception-roll-indicator {
  display: none;
}

@keyframes revealSuccess {
  from {
    background: rgba(34, 197, 94, 0.4);
    transform: scale(1.02);
  }
  to {
    background: var(--skill-color-faded, rgba(34, 197, 94, 0.15));
    transform: scale(1);
  }
}

/* Revealed state after failed roll */
.perception-interactive.perception-revealed-failure {
  cursor: default;
  background: rgba(100, 100, 100, 0.1);
  border-color: var(--color-text-muted);
  border-style: solid;
}

.perception-interactive.perception-revealed-failure .perception-roll-indicator {
  display: none;
}

.perception-interactive.perception-revealed-failure .perception-hint {
  font-style: normal;
}

/* Vague perception (partial reveal) */
.perception-vague {
  display: flex;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  padding: var(--space-2, 0.5rem) var(--space-3, 0.75rem);
  background: var(--skill-color-faded, rgba(0, 0, 0, 0.1));
  border-left: 2px dashed var(--skill-color, var(--color-text-muted));
  border-radius: var(--radius-sm, 4px);
  animation: vaguePulse 3s ease-in-out infinite;
}

.perception-vague[data-skill] .perception-icon {
  color: var(--skill-color);
}

@keyframes vaguePulse {
  0%, 100% {
    background: var(--skill-color-faded, rgba(0, 0, 0, 0.05));
  }
  50% {
    background: var(--skill-color-faded, rgba(0, 0, 0, 0.12));
  }
}

/* ========================================
 * Player-Specific Content
 * ======================================== */

.player-specific {
  position: relative;
  padding: var(--space-2, 0.5rem) var(--space-3, 0.75rem);
  background: linear-gradient(
    135deg,
    rgba(97, 175, 239, 0.1) 0%,
    rgba(97, 175, 239, 0.05) 100%
  );
  border-left: 3px solid var(--color-accent-primary);
  border-radius: var(--radius-sm, 4px);
}

.player-specific-reason {
  display: inline-block;
  font-size: var(--font-size-xs, 0.75rem);
  padding: 2px 6px;
  background: rgba(97, 175, 239, 0.2);
  border-radius: var(--radius-sm, 4px);
  color: var(--color-accent-primary);
  margin-bottom: var(--space-1, 0.25rem);
}

/* DM view of player-specific content */
.player-specific.dm-view {
  border-style: dashed;
  opacity: 0.8;
}

.player-specific-indicator {
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-text-muted);
  font-style: italic;
  margin-bottom: var(--space-1, 0.25rem);
}

/* ========================================
 * Plain Text Segment
 * ======================================== */

.plain-text {
  padding: var(--space-2, 0.5rem);
  background: var(--color-bg-tertiary, rgba(255, 255, 255, 0.03));
  border-radius: var(--radius-sm, 4px);
  margin: var(--space-1, 0.25rem) 0;
}

.plain-text p {
  margin: 0;
}

/* ========================================
 * Inline Group - Mixed text and selections
 * Groups text fragments with inline selections to prevent fragmentation
 * ======================================== */

.narrative-segment.inline-group {
  padding: var(--space-2, 0.5rem);
  background: var(--color-bg-tertiary, rgba(255, 255, 255, 0.03));
  border-radius: var(--radius-sm, 4px);
  margin: var(--space-1, 0.25rem) 0;
  line-height: 1.8;
}

.inline-text {
  /* Inline text fragments between selections */
}

.inline-text strong {
  color: var(--color-text-emphasis, #f0f0f0);
  font-weight: 600;
}

.inline-text em {
  font-style: italic;
  color: var(--color-text-secondary, #a0a0a0);
}

/* ========================================
 * Fallback Segment Styles
 * For BaseSegment-generated classes that may not have specific styling
 * ======================================== */

.narrative-segment.segment-plain_text,
.narrative-segment.segment-npc_dialogue,
.narrative-segment.segment-action,
.narrative-segment.segment-perception,
.narrative-segment.segment-narration,
.narrative-segment.segment-character_specific {
  margin: var(--space-1, 0.25rem) 0;
}

/* ========================================
 * XML Parse Error Indicator
 * Shown when XML parsing fails and falls back to plain text
 * ======================================== */

.xml-parse-error {
  border-left: 3px solid var(--color-accent-error, #ff3b30);
  background: rgba(255, 59, 48, 0.1);
  padding: var(--space-2, 0.5rem);
  border-radius: var(--radius-sm, 4px);
}

.xml-parse-error::before {
  content: '⚠ Parse Error';
  display: block;
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-accent-error, #ff3b30);
  margin-bottom: var(--space-1, 0.25rem);
  font-weight: var(--font-weight-medium, 500);
}

/* ========================================
 * Scene Description Segment
 * For environment, location, atmosphere descriptions
 * ======================================== */

.segment-scene,
.dm-scene {
  position: relative;
  padding: var(--space-3, 0.75rem);
  background: linear-gradient(
    135deg,
    rgba(70, 130, 180, 0.08) 0%,
    rgba(70, 130, 180, 0.03) 100%
  );
  border-left: 3px solid #4682b4; /* Steel blue */
  border-radius: var(--radius-sm, 4px);
  margin: var(--space-2, 0.5rem) 0;
}

.dm-scene p {
  margin: 0;
  line-height: 1.6;
}

/* Scene with atmosphere indicator */
.dm-scene[data-atmosphere]::before {
  content: attr(data-atmosphere);
  display: inline-block;
  font-size: var(--font-size-xs, 0.75rem);
  padding: 2px 6px;
  background: rgba(70, 130, 180, 0.2);
  border-radius: var(--radius-sm, 4px);
  color: #4682b4;
  margin-bottom: var(--space-2, 0.5rem);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ========================================
 * Lore/Knowledge Segment
 * For history, legends, world knowledge
 * ======================================== */

.segment-lore,
.dm-lore {
  position: relative;
  padding: var(--space-3, 0.75rem);
  background: linear-gradient(
    135deg,
    rgba(138, 43, 226, 0.08) 0%,
    rgba(138, 43, 226, 0.03) 100%
  );
  border-left: 3px solid #8a2be2; /* Blue violet */
  border-radius: var(--radius-sm, 4px);
  margin: var(--space-2, 0.5rem) 0;
  font-style: italic;
}

.dm-lore p {
  margin: 0;
  line-height: 1.6;
}

.dm-lore::before {
  content: '📜';
  position: absolute;
  top: var(--space-2, 0.5rem);
  right: var(--space-2, 0.5rem);
  opacity: 0.4;
  font-size: 1.2rem;
}

/* Lore category badges */
.dm-lore[data-category]::after {
  content: attr(data-category);
  display: block;
  font-size: var(--font-size-xs, 0.75rem);
  padding: 2px 6px;
  background: rgba(138, 43, 226, 0.2);
  border-radius: var(--radius-sm, 4px);
  color: #a78bfa;
  margin-top: var(--space-2, 0.5rem);
  font-style: normal;
  width: fit-content;
}

/* ========================================
 * Combat/Danger Segment
 * For combat narration, threatening situations
 * ======================================== */

.segment-combat,
.dm-combat {
  padding: var(--space-3, 0.75rem);
  background: linear-gradient(
    135deg,
    rgba(220, 20, 60, 0.08) 0%,
    rgba(220, 20, 60, 0.03) 100%
  );
  border-left: 3px solid #dc143c; /* Crimson */
  border-radius: var(--radius-sm, 4px);
  margin: var(--space-2, 0.5rem) 0;
}

.dm-combat p {
  margin: 0;
}

/* ========================================
 * Narrative Callouts
 * For important information, warnings, rewards
 * ======================================== */

.narrative-callout {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2, 0.5rem);
  padding: var(--space-3, 0.75rem);
  border-radius: var(--radius-sm, 4px);
  margin: var(--space-2, 0.5rem) 0;
}

.narrative-callout .callout-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.narrative-callout .callout-content {
  flex: 1;
}

.narrative-callout .callout-content p {
  margin: 0;
}

/* Warning callout */
.narrative-callout.warning {
  background: linear-gradient(
    135deg,
    rgba(255, 152, 0, 0.12) 0%,
    rgba(255, 152, 0, 0.05) 100%
  );
  border-left: 3px solid #ff9800;
  border: 1px solid rgba(255, 152, 0, 0.3);
}

.narrative-callout.warning .callout-icon {
  color: #ff9800;
}

/* Danger callout */
.narrative-callout.danger {
  background: linear-gradient(
    135deg,
    rgba(244, 67, 54, 0.12) 0%,
    rgba(244, 67, 54, 0.05) 100%
  );
  border-left: 3px solid #f44336;
  border: 1px solid rgba(244, 67, 54, 0.3);
}

.narrative-callout.danger .callout-icon {
  color: #f44336;
}

/* Reward callout */
.narrative-callout.reward {
  background: linear-gradient(
    135deg,
    rgba(76, 175, 80, 0.12) 0%,
    rgba(76, 175, 80, 0.05) 100%
  );
  border-left: 3px solid #4caf50;
  border: 1px solid rgba(76, 175, 80, 0.3);
}

.narrative-callout.reward .callout-icon {
  color: #4caf50;
}

/* Discovery callout */
.narrative-callout.discovery {
  background: linear-gradient(
    135deg,
    rgba(33, 150, 243, 0.12) 0%,
    rgba(33, 150, 243, 0.05) 100%
  );
  border-left: 3px solid #2196f3;
  border: 1px solid rgba(33, 150, 243, 0.3);
}

.narrative-callout.discovery .callout-icon {
  color: #2196f3;
}

/* Info callout */
.narrative-callout.info {
  background: linear-gradient(
    135deg,
    rgba(156, 39, 176, 0.12) 0%,
    rgba(156, 39, 176, 0.05) 100%
  );
  border-left: 3px solid #9c27b0;
  border: 1px solid rgba(156, 39, 176, 0.3);
}

.narrative-callout.info .callout-icon {
  color: #9c27b0;
}

/* Quest callout */
.narrative-callout.quest {
  background: linear-gradient(
    135deg,
    rgba(255, 193, 7, 0.12) 0%,
    rgba(255, 193, 7, 0.05) 100%
  );
  border-left: 3px solid #ffc107;
  border: 1px solid rgba(255, 193, 7, 0.3);
}

.narrative-callout.quest .callout-icon {
  color: #ffc107;
}

/* ========================================
 * Collapsible Segments
 * For long descriptions that can be expanded
 * ======================================== */

.segment-collapsible {
  cursor: pointer;
}

.segment-collapsible .segment-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.segment-collapsible .segment-summary::after {
  content: '▼';
  font-size: 0.7rem;
  opacity: 0.5;
  transition: transform 0.2s ease;
}

.segment-collapsible.collapsed .segment-summary::after {
  transform: rotate(-90deg);
}

.segment-collapsible .segment-details {
  margin-top: var(--space-2, 0.5rem);
  padding-top: var(--space-2, 0.5rem);
  border-top: 1px dashed var(--color-border-subtle, rgba(255, 255, 255, 0.1));
  transition: all 0.3s ease;
}

.segment-collapsible.collapsed .segment-details {
  display: none;
}

/* ========================================
 * Animations - Typewriter segment reveal
 * ======================================== */

@keyframes segmentReveal {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.narrative-segment {
  opacity: 0;
  animation: segmentReveal 0.25s ease-out forwards;
}

/* Stagger animation for typewriter effect (150ms between segments) */
.structured-narrative .narrative-segment:nth-child(1) { animation-delay: 0ms; }
.structured-narrative .narrative-segment:nth-child(2) { animation-delay: 150ms; }
.structured-narrative .narrative-segment:nth-child(3) { animation-delay: 300ms; }
.structured-narrative .narrative-segment:nth-child(4) { animation-delay: 450ms; }
.structured-narrative .narrative-segment:nth-child(5) { animation-delay: 600ms; }
.structured-narrative .narrative-segment:nth-child(6) { animation-delay: 750ms; }
.structured-narrative .narrative-segment:nth-child(7) { animation-delay: 900ms; }
.structured-narrative .narrative-segment:nth-child(8) { animation-delay: 1050ms; }
.structured-narrative .narrative-segment:nth-child(9) { animation-delay: 1200ms; }
.structured-narrative .narrative-segment:nth-child(10) { animation-delay: 1350ms; }

/* ========================================
 * Reduced Motion
 * ======================================== */

@media (prefers-reduced-motion: reduce) {
  .narrative-segment {
    animation: none;
  }

  .perception-icon {
    animation: none;
    opacity: 0.5;
  }
}

/* ========================================
 * Responsive Adjustments
 * ======================================== */

@media (max-width: 768px) {
  .npc-dialogue {
    padding: var(--space-2, 0.5rem);
  }

  .npc-header {
    flex-wrap: wrap;
  }
}

/* ========================================
 * Memory Flashback Blocks
 * ======================================== */

.memory-flashback {
  position: relative;
  padding: var(--space-3, 0.75rem);
  padding-left: calc(var(--space-3, 0.75rem) + 3px);
  margin: var(--space-3, 0.75rem) 0;
  background: linear-gradient(
    135deg,
    rgba(147, 112, 219, 0.12) 0%,
    rgba(147, 112, 219, 0.04) 100%
  );
  border-left: 3px solid #9370db; /* Medium purple */
  border-radius: 0 var(--radius-md, 6px) var(--radius-md, 6px) 0;
  animation: memoryFadeIn 0.4s ease-out;
}

.memory-flashback::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(147, 112, 219, 0.02) 2px,
      rgba(147, 112, 219, 0.02) 4px
    );
  pointer-events: none;
  border-radius: 0 var(--radius-md, 6px) var(--radius-md, 6px) 0;
}

.memory-flashback-header {
  display: flex;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  margin-bottom: var(--space-2, 0.5rem);
  font-size: var(--font-size-xs, 0.75rem);
  color: #9370db;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.memory-flashback-icon {
  font-size: 1em;
  filter: drop-shadow(0 0 3px rgba(147, 112, 219, 0.5));
}

.memory-flashback-content {
  color: var(--color-text-secondary, #aaa);
  font-style: italic;
  line-height: 1.5;
}

.memory-flashback-content p {
  margin: 0;
}

.memory-flashback-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  margin-top: var(--space-2, 0.5rem);
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-text-muted, #666);
}

.memory-flashback-meta .memory-time {
  opacity: 0.7;
}

.memory-flashback-meta .memory-participants {
  display: flex;
  align-items: center;
  gap: var(--space-1, 0.25rem);
}

.memory-flashback-meta .memory-participants::before {
  content: '•';
  margin-right: var(--space-1, 0.25rem);
}

/* Memory category badges */
.memory-category {
  display: inline-block;
  padding: 2px 6px;
  font-size: var(--font-size-xs, 0.75rem);
  font-weight: 500;
  border-radius: var(--radius-sm, 4px);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.memory-category.combat {
  background: rgba(220, 20, 60, 0.2);
  color: #dc143c;
}

.memory-category.social {
  background: rgba(70, 130, 180, 0.2);
  color: #4682b4;
}

.memory-category.exploration {
  background: rgba(34, 139, 34, 0.2);
  color: #228b22;
}

.memory-category.discovery {
  background: rgba(255, 215, 0, 0.2);
  color: #daa520;
}

.memory-category.quest {
  background: rgba(255, 165, 0, 0.2);
  color: #ff8c00;
}

.memory-category.lore {
  background: rgba(138, 43, 226, 0.2);
  color: #8a2be2;
}

@keyframes memoryFadeIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ========================================
 * Memory Reference Links (Inline)
 * ======================================== */

.memory-reference {
  color: #9370db;
  cursor: pointer;
  position: relative;
  border-bottom: 1px dotted rgba(147, 112, 219, 0.5);
  transition: all 0.2s ease;
}

.memory-reference:hover {
  color: #b19cd9;
  border-bottom-color: #b19cd9;
  text-shadow: 0 0 8px rgba(147, 112, 219, 0.4);
}

.memory-reference::before {
  content: '💭';
  font-size: 0.8em;
  margin-right: 2px;
  opacity: 0.7;
}

.memory-reference.expanded {
  color: #b19cd9;
}

/* Inline memory expansion (on click) */
.memory-expansion {
  display: none;
  margin-top: var(--space-2, 0.5rem);
  padding: var(--space-2, 0.5rem);
  background: rgba(147, 112, 219, 0.08);
  border-radius: var(--radius-sm, 4px);
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--color-text-secondary, #aaa);
  font-style: italic;
}

.memory-reference.expanded + .memory-expansion {
  display: block;
  animation: memoryExpand 0.3s ease-out;
}

@keyframes memoryExpand {
  from {
    opacity: 0;
    max-height: 0;
  }
  to {
    opacity: 1;
    max-height: 200px;
  }
}

/* ========================================
 * NPC Relationship Context
 * ======================================== */

.npc-context-popover {
  position: absolute;
  z-index: 100;
  min-width: 280px;
  max-width: 350px;
  padding: var(--space-3, 0.75rem);
  background: var(--color-bg-elevated, #1a1a2e);
  border: 1px solid rgba(147, 112, 219, 0.3);
  border-radius: var(--radius-md, 6px);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.4),
    0 0 20px rgba(147, 112, 219, 0.15);
  animation: popoverFadeIn 0.2s ease-out;
}

.npc-context-popover::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 20px;
  width: 12px;
  height: 12px;
  background: var(--color-bg-elevated, #1a1a2e);
  border-left: 1px solid rgba(147, 112, 219, 0.3);
  border-top: 1px solid rgba(147, 112, 219, 0.3);
  transform: rotate(45deg);
}

@keyframes popoverFadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.npc-context-header {
  display: flex;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  margin-bottom: var(--space-2, 0.5rem);
  padding-bottom: var(--space-2, 0.5rem);
  border-bottom: 1px solid rgba(147, 112, 219, 0.2);
}

.npc-context-name {
  font-weight: 600;
  color: #9370db;
  font-size: var(--font-size-base, 1rem);
}

.npc-context-title {
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-text-muted, #666);
}

.npc-context-relationship {
  display: flex;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  margin-bottom: var(--space-2, 0.5rem);
}

.npc-context-relationship-label {
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-text-muted, #666);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.npc-context-relationship-value {
  display: flex;
  gap: 2px;
}

.npc-context-relationship-value .heart {
  font-size: 12px;
  color: #dc143c;
  opacity: 0.3;
}

.npc-context-relationship-value .heart.filled {
  opacity: 1;
}

.npc-context-memories {
  max-height: 150px;
  overflow-y: auto;
}

.npc-context-memories-title {
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-text-muted, #666);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-1, 0.25rem);
}

.npc-context-memory-item {
  padding: var(--space-1, 0.25rem) 0;
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--color-text-secondary, #aaa);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.npc-context-memory-item:last-child {
  border-bottom: none;
}

.npc-context-memory-item .memory-date {
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-text-muted, #666);
  margin-right: var(--space-1, 0.25rem);
}

.npc-context-empty {
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--color-text-muted, #666);
  font-style: italic;
  text-align: center;
  padding: var(--space-2, 0.5rem) 0;
}

/* ========================================
 * Lore Context Blocks
 * ======================================== */

.lore-context {
  position: relative;
  padding: var(--space-3, 0.75rem);
  padding-left: calc(var(--space-3, 0.75rem) + 3px);
  margin: var(--space-2, 0.5rem) 0;
  background: linear-gradient(
    135deg,
    rgba(138, 43, 226, 0.08) 0%,
    rgba(138, 43, 226, 0.03) 100%
  );
  border-left: 3px solid #8a2be2;
  border-radius: 0 var(--radius-md, 6px) var(--radius-md, 6px) 0;
}

.lore-context-header {
  display: flex;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  margin-bottom: var(--space-2, 0.5rem);
  font-size: var(--font-size-xs, 0.75rem);
  color: #8a2be2;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.lore-context-icon {
  font-size: 1em;
}

.lore-context-content {
  color: var(--color-text-secondary, #aaa);
  font-style: italic;
  line-height: 1.5;
}

.lore-context-source {
  margin-top: var(--space-2, 0.5rem);
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-text-muted, #666);
}

/* ========================================
 * Expandable Lore (Inline)
 * ======================================== */

.expandable-lore {
  color: #8a2be2;
  cursor: pointer;
  position: relative;
  border-bottom: 1px dotted rgba(138, 43, 226, 0.5);
  transition: all 0.2s ease;
}

.expandable-lore:hover {
  color: #9932cc;
  border-bottom-color: #9932cc;
  text-shadow: 0 0 8px rgba(138, 43, 226, 0.4);
}

.expandable-lore::after {
  content: '📜';
  font-size: 0.7em;
  margin-left: 3px;
  opacity: 0.7;
  vertical-align: super;
}

.expandable-lore.expanded {
  color: #9932cc;
}

.lore-expansion {
  display: none;
  margin-top: var(--space-2, 0.5rem);
  padding: var(--space-2, 0.5rem);
  background: rgba(138, 43, 226, 0.08);
  border-radius: var(--radius-sm, 4px);
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--color-text-secondary, #aaa);
  font-style: italic;
}

.expandable-lore.expanded + .lore-expansion {
  display: block;
  animation: loreExpand 0.3s ease-out;
}

@keyframes loreExpand {
  from {
    opacity: 0;
    max-height: 0;
  }
  to {
    opacity: 1;
    max-height: 300px;
  }
}

/* ========================================
 * Context Integration - Responsive
 * ======================================== */

@media (max-width: 768px) {
  .memory-flashback {
    padding: var(--space-2, 0.5rem);
    margin: var(--space-2, 0.5rem) 0;
  }

  .memory-flashback-header {
    font-size: 0.7rem;
  }

  .npc-context-popover {
    min-width: 240px;
    max-width: 280px;
    padding: var(--space-2, 0.5rem);
  }

  .lore-context {
    padding: var(--space-2, 0.5rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .memory-flashback {
    animation: none;
  }

  .npc-context-popover {
    animation: none;
  }

  .memory-reference.expanded + .memory-expansion,
  .expandable-lore.expanded + .lore-expansion {
    animation: none;
  }
}
