/* ===== FONTS ===== */
@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');

/* ===== CSS CUSTOM PROPERTIES ===== */
:root {
  /* Backgrounds */
  --bg-void: #000;
  --bg-abyss: #050000;

  /* Text */
  --text-primary: #ff4444;
  --text-secondary: #ff8888;
  --text-dim: #662222;
  --text-elar: #ffb3b3;
  --text-system: #00ff55;

  /* Glows */
  --glow-red: 0 0 30px rgb(255 0 0 / 0.6);
  --glow-red-soft: 0 0 20px rgb(255 0 0 / 0.3);

  /* Typography */
  --font-main: 'VT323', monospace;
  --text-sm: 1rem;
  --text-md: 1.25rem;
  --text-lg: 1.5rem;
  --text-xl: 2.25rem;

  /* Spacing */
  --space-xs: 0.3125rem;
  --space-sm: 0.625rem;
  --space-md: 1.25rem;
  --space-lg: 1.875rem;
  --space-xl: 3.125rem;

  /* Animation */
  --anim-fast: 0.15s;
  --anim-medium: 0.3s;
  --anim-slow: 0.6s;

  /* Layers */
  --z-whispers: 1;
  --z-elar: 5;
  --z-dialogue: 10;
  --z-glitch: 20;
}

/* ===== RESET & GLOBAL ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100px;
  background:
    radial-gradient(ellipse at 50% 0%, #1a0000 0%, transparent 60%),
    radial-gradient(ellipse at 50% 100%, var(--bg-abyss) 0%, var(--bg-void) 100%);
  background-color: var(--bg-void);
  color: var(--text-primary);
  font-family: var(--font-main);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  cursor: default;
}

::selection {
  background: #ff2200;
  color: #000;
}

/* ===== GLITCH OVERLAY ===== */
#glitchOverlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgb(255 0 0 / 0.15) 0px,
    rgb(255 0 0 / 0.15) 2px,
    transparent 2px,
    transparent 6px
  );
  z-index: var(--z-glitch);
  transition: opacity 0.1s ease;
  will-change: opacity;
}

/* ===== FLOATING WHISPERS ===== */
.whisper {
  position: fixed;
  pointer-events: none;
  color: var(--text-dim);
  font-size: 0.875rem;
  z-index: var(--z-whispers);
  opacity: 0;
  white-space: nowrap;
  animation: whisperFloat 6s ease-in-out infinite;
}

/* Using :nth-child offset by 1 because whispers start at child 2 of their parent */
.whisper:nth-child(2) { top: 15%; left: 10%; animation-delay: 0s; }
.whisper:nth-child(3) { top: 70%; left: 75%; animation-delay: 1.5s; }
.whisper:nth-child(4) { top: 35%; left: 80%; animation-delay: 3s; }
.whisper:nth-child(5) { top: 55%; left: 15%; animation-delay: 4.5s; }
.whisper:nth-child(6) { top: 85%; left: 50%; animation-delay: 2s; }

@keyframes whisperFloat {
  0%,
  100% { opacity: 0; transform: translateY(0); }
  20%  { opacity: 0.4; }
  40%  { opacity: 0.1; }
  60%  { opacity: 0.5; transform: translateY(-10px); }
  80%  { opacity: 0; transform: translateY(-20px); }
}

/* ===== MAIN CONTENT ===== */
#content {
  position: relative;
  z-index: var(--z-dialogue);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  padding: 1.25rem;
}

/* ===== TITLE ===== */
#hellTitle {
  font-size: var(--text-xl);
  color: #ff2200;
  text-shadow:
    0 0 20px rgb(255 34 0 / 0.8),
    0 0 40px rgb(255 34 0 / 0.4),
    0 0 60px rgb(255 34 0 / 0.2),
    0 0 80px rgb(255 34 0 / 0.1);
  letter-spacing: 0.375rem;
  margin-bottom: var(--space-xl);
  animation: titleFlicker 4s ease-in-out infinite;
  text-align: center;
  user-select: none;
}

@keyframes titleFlicker {
  0%, 6%, 49%, 56%, 100% { opacity: 1; }
  3%, 53% {
    opacity: 0.5;
    text-shadow:
      0 0 10px rgb(255 34 0 / 0.4),
      0 0 20px rgb(255 34 0 / 0.2);
  }
  50% { opacity: 0.9; }
}

#hellTitle:hover {
  animation: titleCorrupt 0.3s linear infinite;
  color: #ff0000;
  cursor: pointer;
}

@keyframes titleCorrupt {
  0%, 100% { transform: translate(0); }
  25%       { transform: translate(-2px, 1px); }
  50%       { transform: translate(2px, -1px); }
  75%       { transform: translate(-1px, -1px); }
}

/* ===== ELARWYTH ===== */
#elarContainer {
  position: fixed;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: var(--z-elar);
  pointer-events: none;
}

#elarSprite {
  display: block;
  width: 280px;
  height: auto;
  filter:
    drop-shadow(0 0 30px rgb(255 0 0 / 0.6))
    saturate(0.2)
    hue-rotate(330deg)
    brightness(0.8);
  animation: elarFloat 6s ease-in-out infinite;
  cursor: pointer;
  pointer-events: all;
  will-change: transform;
}

#elarSprite:hover {
  filter:
    drop-shadow(0 0 50px rgb(255 0 0 / 0.9))
    saturate(0.1)
    hue-rotate(350deg)
    brightness(1.2);
}

@keyframes elarFloat {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-15px); }
}

#elarGlow {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  width: 350px;
  height: 350px;
  background: radial-gradient(
    circle,
    rgb(255 0 0 / 0.25) 0%,
    rgb(255 0 0 / 0.1)  40%,
    transparent         70%
  );
  border-radius: 50%;
  animation: glowPulse 3s ease-in-out infinite;
  pointer-events: none;
  will-change: transform, opacity;
}

@keyframes glowPulse {
  0%, 100% { scale: 1;   opacity: 0.6; }
  50%       { scale: 1.3; opacity: 1; }
}

/* ===== DIALOGUE BOX ===== */
#dialogueBox {
  position: fixed;
  bottom: 0;
  left: 50%;
  translate: -50% 0;
  width: min(85%, 800px);
  background: rgb(0 0 0 / 0.9);
  border: 2px solid #330000;
  border-bottom: none;
  border-radius: 15px 15px 0 0;
  padding: var(--space-md) var(--space-lg);
  z-index: var(--z-dialogue);
  box-shadow:
    0 -10px 30px rgb(0 0 0 / 0.7),
    var(--glow-red-soft);
  animation: dialogueRise 0.5s ease-out both;
}

@keyframes dialogueRise {
  from { opacity: 0; translate: -50% 20px; }
  to   { opacity: 1; translate: -50% 0; }
}

#nameplate {
  font-size: var(--text-lg);
  font-weight: bold;
  letter-spacing: 0.1875rem;
  margin-bottom: var(--space-sm);
  text-transform: uppercase;
  transition: color var(--anim-medium) ease;
}

#dialogueText {
  font-size: var(--text-md);
  line-height: 1.7;
  min-height: 5rem;
  max-height: 12.5rem;
  overflow-y: auto;
  white-space: pre-wrap;
  color: #ffcccc;
  /* Prevent scrollbar-induced layout shift */
  scrollbar-gutter: stable;
}

#dialogueText::-webkit-scrollbar { width: 4px; }
#dialogueText::-webkit-scrollbar-track { background: rgb(255 0 0 / 0.1); }
#dialogueText::-webkit-scrollbar-thumb { background: rgb(255 0 0 / 0.4); border-radius: 2px; }

#continueBtn {
  display: block;
  margin: var(--space-md) 0 0 auto;
  padding: 8px 25px;
  border-radius: 999px;
  border: 1px solid #662222;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: var(--text-sm);
  cursor: pointer;
  transition:
    background var(--anim-medium) ease,
    border-color var(--anim-medium) ease,
    color var(--anim-medium) ease,
    box-shadow var(--anim-medium) ease,
    transform var(--anim-medium) ease;
}

#continueBtn::after {
  content: ' ▼';
  display: inline-block;
  animation: bounceDown 1.5s ease-in-out infinite;
  font-size: 0.75rem;
}

@keyframes bounceDown {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(4px); }
}

#continueBtn:hover {
  background: rgb(255 0 0 / 0.15);
  border-color: #ff4444;
  color: #ff6666;
  box-shadow: var(--glow-red-soft);
  transform: translateY(-2px);
}

#continueBtn:active { transform: translateY(0); }

#continueBtn:focus-visible {
  outline: 2px solid #ff4444;
  outline-offset: 3px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  :root {
    --text-xl: 1.75rem;
  }

  #elarSprite { width: 200px; }
  #elarGlow   { width: 250px; height: 250px; }

  #dialogueBox {
    width: 95%;
    padding: var(--space-sm) var(--space-md);
  }

  #nameplate   { font-size: var(--text-md); }
  #dialogueText {
    min-height: 3.75rem;
    max-height: 10rem;
  }

  .whisper { font-size: 0.75rem; }
}

@media (max-width: 480px) {
  :root {
    --text-xl: 1.375rem;
    --text-lg: 1.125rem;
    --text-md: 0.875rem;
    --text-sm: 0.75rem;
  }

  #hellTitle    { letter-spacing: 0.1875rem; }
  #elarSprite   { width: 150px; }
  #elarGlow     { width: 200px; height: 200px; }

  #dialogueBox  {
    width: 100%;
    padding: var(--space-sm);
  }

  #nameplate    { letter-spacing: 0.125rem; }
  #dialogueText { min-height: 3.125rem; max-height: 8.125rem; }

  .whisper { font-size: 0.625rem; }

  .whisper:nth-child(2) { top: 10%; left: 5%; }
  .whisper:nth-child(3) { top: 80%; left: 60%; }
  .whisper:nth-child(4) { top: 25%; left: 75%; }
  .whisper:nth-child(5) { top: 65%; left: 5%; }
  .whisper:nth-child(6) { top: 90%; left: 40%; }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .whisper { opacity: 0.2; }
}