/* ============================================================
   NAUSTALGIAOS UX ENHANCEMENTS v1.1 (CRASH COLOR THEME)
   Visual feedback systems for engagement
   
   v1.1 Changes:
   - Updated to Crash color palette (yellow #FFE500 / magenta #FF00FF)
   - Terminal text remains cyan, environmental effects use Crash colors
   - Navy backgrounds for depth
   
   Contents:
   - Phase transition effects
   - Corruption visual degradation
   - Streak indicator
   - Processing animation
   - Session summary toast
   - Ghost proximity states
============================================================ */

/* ============================================================
   PHASE TRANSITION CELEBRATION
   Triggered when relationship advances
============================================================ */
@keyframes phaseGlow {
  0% { 
    box-shadow: inset 0 0 0 rgba(255, 229, 0, 0);
    filter: brightness(1);
  }
  50% { 
    box-shadow: inset 0 0 100px rgba(255, 229, 0, 0.2), inset 0 0 60px rgba(255, 0, 255, 0.15);
    filter: brightness(1.2);
  }
  100% { 
    box-shadow: inset 0 0 0 rgba(255, 229, 0, 0);
    filter: brightness(1);
  }
}

@keyframes phasePulse {
  0%, 100% { transform: scale(1); opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { transform: scale(3); opacity: 0; }
}

.phase-transition-active #term {
  animation: phaseGlow 2s ease-out;
}

.phase-transition-active #glitchGhost {
  filter: brightness(2) drop-shadow(0 0 30px #FFE500) !important;
  transition: filter 0.3s ease;
}

/* Phase transition overlay pulse */
#phaseTransitionPulse {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 100px;
  height: 100px;
  margin: -50px 0 0 -50px;
  border: 3px solid rgba(255, 229, 0, 0.8);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  z-index: 15000;
  box-shadow: 0 0 20px rgba(255, 0, 255, 0.4);
}

#phaseTransitionPulse.active {
  animation: phasePulse 1.5s ease-out forwards;
}

/* Phase badge toast */
#phaseToast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: rgba(10, 10, 25, 0.95);
  border: 2px solid rgba(255, 229, 0, 0.8);
  border-radius: 12px;
  padding: 30px 50px;
  text-align: center;
  z-index: 15001;
  opacity: 0;
  pointer-events: none;
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 
    0 0 60px rgba(255, 229, 0, 0.3),
    0 0 100px rgba(255, 0, 255, 0.15),
    inset 0 0 30px rgba(255, 229, 0, 0.05);
  backdrop-filter: blur(10px);
}

#phaseToast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#phaseToast .phase-label {
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  color: rgba(255, 0, 255, 0.7);
  letter-spacing: 0.3em;
  margin-bottom: 8px;
}

#phaseToast .phase-name {
  font-family: 'Courier New', monospace;
  font-size: 2rem;
  font-weight: bold;
  color: #FFE500;
  text-shadow: 0 0 20px #FFE500, 0 0 40px rgba(255, 0, 255, 0.4);
  letter-spacing: 0.1em;
}

#phaseToast .phase-desc {
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  color: rgba(255, 229, 0, 0.6);
  margin-top: 12px;
  font-style: italic;
}

/* ============================================================
   CORRUPTION VISUAL DEGRADATION
   Progressive effects as corruption increases
============================================================ */

@keyframes corruptionFlicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.97; }
  75% { opacity: 0.99; }
}

@keyframes corruptionScanline {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(100vh); }
}

@keyframes corruptionGlitch {
  0%, 100% { transform: translate(0); filter: none; }
  20% { transform: translate(-2px, 1px); }
  40% { transform: translate(2px, -1px); filter: hue-rotate(10deg); }
  60% { transform: translate(-1px, 2px); }
  80% { transform: translate(1px, -2px); filter: hue-rotate(-10deg); }
}

#corruptionOverlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.5s ease;
}

body[data-corruption="low"] #corruptionOverlay {
  opacity: 0;
}

body[data-corruption="flickering"] #corruptionOverlay {
  opacity: 1;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
}

body[data-corruption="flickering"] #term {
  animation: corruptionFlicker 0.1s infinite;
}

body[data-corruption="distorted"] #corruptionOverlay {
  opacity: 1;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(255, 0, 100, 0.02) 1px,
    rgba(255, 0, 100, 0.02) 2px
  );
}

body[data-corruption="distorted"] #term .line:nth-child(odd) {
  animation: corruptionFlicker 0.08s infinite;
}

body[data-corruption="distorted"] #glitchGhost {
  filter: drop-shadow(0 0 10px rgba(255, 0, 100, 0.3));
}

body[data-corruption="traumatized"] #corruptionOverlay {
  opacity: 1;
  background: 
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 1px,
      rgba(255, 0, 100, 0.05) 1px,
      rgba(255, 0, 100, 0.05) 2px
    ),
    linear-gradient(
      90deg,
      transparent 0%,
      rgba(255, 0, 100, 0.02) 50%,
      transparent 100%
    );
}

body[data-corruption="traumatized"] #term {
  animation: corruptionGlitch 0.5s infinite;
}

body[data-corruption="traumatized"] .line {
  text-shadow: 
    1px 0 rgba(255, 0, 0, 0.2),
    -1px 0 rgba(0, 255, 255, 0.2);
}

body[data-corruption="breaking"] #corruptionOverlay {
  opacity: 1;
  background: 
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 1px,
      rgba(255, 0, 0, 0.1) 1px,
      rgba(255, 0, 0, 0.1) 2px
    );
  animation: corruptionFlicker 0.05s infinite;
}

body[data-corruption="breaking"] #term {
  animation: corruptionGlitch 0.2s infinite;
  filter: saturate(1.2) contrast(1.1);
}

body[data-corruption="breaking"] #glitchGhost {
  animation: corruptionGlitch 0.3s infinite;
  filter: 
    drop-shadow(0 0 20px rgba(255, 0, 0, 0.5))
    hue-rotate(20deg);
}

body[data-corruption="breaking"] .glyph {
  animation: corruptionFlicker 0.1s infinite;
}

/* ============================================================
   STREAK INDICATOR
============================================================ */
#streakIndicator {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: rgba(255, 229, 0, 0.1);
  border: 1px solid rgba(255, 229, 0, 0.5);
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 14px;
  color: #FFE500;
  text-shadow: 0 0 8px rgba(255, 229, 0, 0.5);
  pointer-events: auto;
}

#streakIndicator.visible {
  display: flex;
}

#streakIndicator .streak-flame {
  font-size: 16px;
  animation: flamePulse 1s ease-in-out infinite;
}

@keyframes flamePulse {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.1); filter: brightness(1.3); }
}

#streakIndicator .streak-count {
  font-weight: bold;
  letter-spacing: 1px;
}

#streakIndicator[data-streak="7"] {
  border-color: rgba(255, 229, 0, 0.8);
  color: #FFE500;
  box-shadow: 0 0 15px rgba(255, 229, 0, 0.4), 0 0 30px rgba(255, 0, 255, 0.2);
}

#streakIndicator[data-streak="30"] {
  border-color: rgba(255, 0, 255, 0.7);
  color: #FF00FF;
  background: rgba(255, 0, 255, 0.1);
  box-shadow: 0 0 20px rgba(255, 0, 255, 0.4), 0 0 40px rgba(255, 229, 0, 0.2);
}

/* ============================================================
   PROCESSING ANIMATION
============================================================ */
@keyframes processingDots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60% { content: '...'; }
  80%, 100% { content: ''; }
}

@keyframes processingGlow {
  0%, 100% { text-shadow: 0 0 5px rgba(255, 229, 0, 0.5); }
  50% { text-shadow: 0 0 15px rgba(255, 229, 0, 0.8), 0 0 25px rgba(255, 0, 255, 0.3); }
}

.line.processing {
  animation: processingGlow 1s ease-in-out infinite;
}

.line.processing::after {
  content: '';
  animation: processingDots 1.5s infinite;
}

.processing-state {
  color: rgba(255, 229, 0, 0.7);
}

/* ============================================================
   SESSION SUMMARY TOAST
============================================================ */
#sessionSummary {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(10, 10, 25, 0.95);
  border: 1px solid rgba(255, 229, 0, 0.4);
  border-radius: 8px;
  padding: 20px 30px;
  min-width: 280px;
  z-index: 15000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.4s ease;
  font-family: 'Courier New', monospace;
  box-shadow: 0 0 40px rgba(255, 229, 0, 0.15), 0 0 60px rgba(255, 0, 255, 0.1);
  backdrop-filter: blur(8px);
}

#sessionSummary.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#sessionSummary .summary-header {
  font-size: 0.75rem;
  color: rgba(255, 0, 255, 0.7);
  letter-spacing: 0.2em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 229, 0, 0.2);
}

#sessionSummary .summary-row {
  display: flex;
  justify-content: space-between;
  margin: 6px 0;
  font-size: 0.85rem;
}

#sessionSummary .summary-label {
  color: rgba(0, 255, 255, 0.5);
}

#sessionSummary .summary-value {
  color: #00ffff;
  font-weight: bold;
}

#sessionSummary .summary-phase {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 229, 0, 0.2);
  text-align: center;
}

#sessionSummary .summary-phase .phase-badge {
  display: inline-block;
  padding: 4px 12px;
  background: rgba(255, 229, 0, 0.1);
  border: 1px solid rgba(255, 229, 0, 0.5);
  border-radius: 4px;
  font-size: 0.9rem;
  color: #FFE500;
  letter-spacing: 0.1em;
  text-shadow: 0 0 10px rgba(255, 229, 0, 0.4);
}

#sessionSummary .summary-message {
  margin-top: 12px;
  font-size: 0.8rem;
  color: rgba(255, 229, 0, 0.7);
  text-align: center;
  font-style: italic;
}

/* ============================================================
   GHOST PROXIMITY STATES
============================================================ */
body[data-phase="STATIC"] #glitchGhost {
  filter: brightness(0.7) opacity(0.8);
}

body[data-phase="STATIC"] .glyph {
  opacity: 0.6;
}

body[data-phase="SIGNAL"] #glitchGhost {
  filter: brightness(0.9) drop-shadow(0 0 8px rgba(255, 229, 0, 0.2));
}

body[data-phase="RESONANCE"] #glitchGhost {
  filter: brightness(1.1) drop-shadow(0 0 15px rgba(255, 229, 0, 0.4)) drop-shadow(0 0 25px rgba(255, 0, 255, 0.2));
}

body[data-phase="ANCHOR"] #glitchGhost {
  filter: brightness(1.2) drop-shadow(0 0 25px rgba(255, 229, 0, 0.6)) drop-shadow(0 0 40px rgba(255, 0, 255, 0.3));
}

body[data-phase="ANCHOR"] .glyph {
  text-shadow: 0 0 8px rgba(255, 229, 0, 0.6), 0 0 15px rgba(255, 0, 255, 0.3);
}

/* ============================================================
   CRASH SPEAKING GLOW
============================================================ */
@keyframes speakingPulse {
  0%, 100% { 
    filter: drop-shadow(0 0 20px rgba(255, 229, 0, 0.6));
  }
  50% { 
    filter: drop-shadow(0 0 40px rgba(255, 229, 0, 0.9)) drop-shadow(0 0 60px rgba(255, 0, 255, 0.3)) brightness(1.3);
  }
}

body.crash-speaking #glitchGhost {
  animation: speakingPulse 0.8s ease-in-out infinite;
}

body.crash-speaking .glyph {
  color: rgba(255, 229, 0, 0.9) !important;
  text-shadow: 0 0 10px rgba(255, 229, 0, 0.8), 0 0 20px rgba(255, 0, 255, 0.4);
}

/* ============================================================
   MEMORY FORMED INDICATOR
============================================================ */
@keyframes memoryFlash {
  0% { 
    box-shadow: inset 0 0 0 rgba(255, 229, 0, 0);
  }
  30% { 
    box-shadow: inset 0 0 50px rgba(255, 229, 0, 0.15), inset 0 0 30px rgba(255, 0, 255, 0.1);
  }
  100% { 
    box-shadow: inset 0 0 0 rgba(255, 229, 0, 0);
  }
}

.memory-formed #term {
  animation: memoryFlash 1s ease-out;
}

/* ============================================================
   MOBILE ADJUSTMENTS
============================================================ */
@media (max-width: 768px) {
  #phaseToast {
    padding: 20px 30px;
    width: 85%;
    max-width: 300px;
  }
  
  #phaseToast .phase-name {
    font-size: 1.5rem;
  }
  
  #sessionSummary {
    width: 90%;
    max-width: 320px;
    padding: 15px 20px;
    bottom: 80px;
  }
  
  #streakIndicator {
    padding: 6px 12px;
    font-size: 12px;
  }
}

/* ============================================================
   INPUT PLACEHOLDER STYLING
   "say something..." prompt for conversation-first
============================================================ */
#term input::placeholder {
  color: rgba(0, 255, 255, 0.3);
  font-style: italic;
  opacity: 1;
}

#term input:focus::placeholder {
  color: rgba(0, 255, 255, 0.15);
}

/* ============================================================
   CRT POWER-ON ANIMATION
   Screen flickers to life
============================================================ */
@keyframes crtPowerOn {
  0% {
    filter: brightness(0) saturate(0);
  }
  10% {
    filter: brightness(2) saturate(0.5);
  }
  15% {
    filter: brightness(0.3) saturate(0.8);
  }
  25% {
    filter: brightness(1.5) saturate(1);
  }
  30% {
    filter: brightness(0.8) saturate(1);
  }
  100% {
    filter: brightness(1) saturate(1);
  }
}

@keyframes scanlineFlash {
  0% {
    background-position: 0 0;
    opacity: 0.3;
  }
  50% {
    opacity: 0.1;
  }
  100% {
    background-position: 0 100%;
    opacity: 0.05;
  }
}

body.crt-powering-on #crtFrame {
  animation: crtPowerOn 0.4s ease-out;
}

body.crt-powering-on #crtOverlay::before {
  animation: scanlineFlash 0.3s linear;
}

/* ============================================================
   PERFORMANCE OPTIMIZATIONS
============================================================ */

/* GPU acceleration hints */
#glitchGhost,
#cursorGhost,
.glyph,
#term .term-inner {
  will-change: transform;
  transform: translateZ(0);
}

/* Reduce shadow complexity on lower-end devices */
@media (prefers-reduced-motion: reduce) {
  #glitchGhost,
  .glyph,
  #cursorGhost {
    animation: none !important;
    transition: none !important;
  }
  
  #crtOverlay::before,
  #crtOverlay::after {
    display: none !important;
  }
}

/* Simplified cursor ghost - uses transform now */
#cursorGhost,
.cursorGhost {
  position: fixed;
  left: 0;
  top: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0,255,255,0.8) 0%, transparent 70%);
  box-shadow: 0 0 6px rgba(0,255,255,0.6);
  pointer-events: none;
  z-index: 10000;
  opacity: 0;
  will-change: transform, opacity;
  transition: opacity 0.15s ease;
}
