/* ============================================
   ANIMATIONS - Dragonfly-Inspired
   ============================================ */

/* --- Glitch Text Effect --- */
.glitch {
  position: relative;
  display: inline-block;
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.glitch::before {
  color: var(--theme-accent);
  z-index: -1;
  animation: glitch-1 3s infinite linear alternate-reverse;
}

.glitch::after {
  color: var(--fg);
  z-index: -2;
  animation: glitch-2 2.5s infinite linear alternate-reverse;
}

@keyframes glitch-1 {
  0%   { clip-path: inset(40% 0 61% 0); transform: translate(-2px, -1px); }
  5%   { clip-path: inset(10% 0 85% 0); transform: translate(1px, 2px); }
  10%  { clip-path: inset(80% 0 5% 0);  transform: translate(-1px, 0); }
  15%  { clip-path: inset(25% 0 58% 0); transform: translate(2px, 1px); }
  20%  { clip-path: inset(55% 0 31% 0); transform: translate(-2px, -2px); }
  25%  { clip-path: inset(0);            transform: translate(0); }
  100% { clip-path: inset(0);            transform: translate(0); }
}

@keyframes glitch-2 {
  0%   { clip-path: inset(65% 0 13% 0); transform: translate(2px, 1px); }
  5%   { clip-path: inset(15% 0 72% 0); transform: translate(-1px, -2px); }
  10%  { clip-path: inset(48% 0 36% 0); transform: translate(1px, 0); }
  15%  { clip-path: inset(5% 0 78% 0);  transform: translate(-2px, 1px); }
  20%  { clip-path: inset(90% 0 2% 0);  transform: translate(2px, -1px); }
  25%  { clip-path: inset(0);            transform: translate(0); }
  100% { clip-path: inset(0);            transform: translate(0); }
}

/* Subtle glitch variant */
.glitch-subtle::before {
  animation: glitch-subtle-1 8s infinite linear;
}

.glitch-subtle::after {
  animation: glitch-subtle-2 6s infinite linear;
}

@keyframes glitch-subtle-1 {
  0%, 90%  { clip-path: inset(0); transform: translate(0); }
  91%      { clip-path: inset(30% 0 50% 0); transform: translate(-1px, 0); }
  93%      { clip-path: inset(70% 0 10% 0); transform: translate(1px, 0); }
  95%      { clip-path: inset(0); transform: translate(0); }
  100%     { clip-path: inset(0); transform: translate(0); }
}

@keyframes glitch-subtle-2 {
  0%, 92%  { clip-path: inset(0); transform: translate(0); }
  93%      { clip-path: inset(10% 0 70% 0); transform: translate(1px, 0); }
  94%      { clip-path: inset(50% 0 30% 0); transform: translate(-1px, 0); }
  96%      { clip-path: inset(0); transform: translate(0); }
  100%     { clip-path: inset(0); transform: translate(0); }
}

/* --- Scanline Moving Effect --- */
.ascii-bg-animate::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 200%;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 2px,
    rgba(255, 255, 255, 0.015) 2px,
    rgba(255, 255, 255, 0.015) 4px
  );
  animation: scanlineMove 8s linear infinite;
  pointer-events: none;
  z-index: 1;
}

@keyframes scanlineMove {
  0%   { transform: translateY(0); }
  100% { transform: translateY(-50%); }
}

/* --- Fade Animations --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(40px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

.anim-fade-in-up {
  animation: fadeInUp 0.8s var(--ease-out) forwards;
}

.anim-fade-in-left {
  animation: fadeInLeft 0.8s var(--ease-out) forwards;
}

.anim-fade-in-right {
  animation: fadeInRight 0.8s var(--ease-out) forwards;
}

.anim-fade-in {
  animation: fadeIn 0.6s var(--ease-out) forwards;
}

/* --- Character Reveal --- */
@keyframes charReveal {
  from {
    opacity: 0;
    transform: translateY(60px) rotateX(-80deg);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotateX(0);
    filter: blur(0);
  }
}

.char.visible {
  animation: charReveal 0.7s var(--ease-out) forwards;
}

/* --- Pulse Glow --- */
@keyframes pulseGlow {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(var(--theme-accent-rgb, 255, 107, 53), 0);
  }
  50% {
    box-shadow: 0 0 20px 4px rgba(var(--theme-accent-rgb, 255, 107, 53), 0.15);
  }
}

.pulse-glow {
  animation: pulseGlow 3s ease-in-out infinite;
}

/* --- Accent line pulse --- */
@keyframes accentPulse {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 1; }
}

.accent-pulse {
  animation: accentPulse 2s ease-in-out infinite;
}

/* --- Border Draw --- */
@keyframes borderDraw {
  0%   { clip-path: polygon(0 0, 0 0, 0 0, 0 0); }
  25%  { clip-path: polygon(0 0, 100% 0, 100% 0, 0 0); }
  50%  { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 0); }
  75%  { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); }
  100% { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); }
}

.border-draw {
  animation: borderDraw 1s var(--ease-out) forwards;
}

/* --- Scale In --- */
@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.anim-scale-in {
  animation: scaleIn 0.6s var(--ease-out) forwards;
}

/* --- Typewriter Cursor --- */
@keyframes cursorBlink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

.typewriter-cursor::after {
  content: '|';
  color: var(--theme-accent);
  animation: cursorBlink 1s step-end infinite;
  margin-left: 2px;
}

/* --- Float / Levitate --- */
@keyframes levitate {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

.levitate {
  animation: levitate 4s ease-in-out infinite;
}

/* --- Line Expand --- */
@keyframes lineExpand {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

.line-expand {
  transform-origin: left;
  animation: lineExpand 0.8s var(--ease-out) forwards;
}

/* --- Matrix Fade --- */
@keyframes matrixFade {
  0%   { opacity: 0.8; }
  50%  { opacity: 0.3; }
  100% { opacity: 0.8; }
}

.matrix-fade {
  animation: matrixFade 3s ease-in-out infinite;
}

/* --- Flicker --- */
@keyframes flicker {
  0%, 19.999%, 22%, 62.999%, 64%, 64.999%, 70%, 100% {
    opacity: 1;
  }
  20%, 21.999%, 63%, 63.999%, 65%, 69.999% {
    opacity: 0.4;
  }
}

.flicker {
  animation: flicker 5s linear infinite;
}

/* --- Horizontal Scroll Text --- */
@keyframes marquee {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

.marquee-track {
  display: flex;
  width: max-content;
  animation: marquee 30s linear infinite;
}

.marquee-track:hover {
  animation-play-state: paused;
}

/* --- Loading spinner --- */
@keyframes spinRotate {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.spin {
  animation: spinRotate 1s linear infinite;
}

/* --- Noise shimmer --- */
@keyframes noiseShimmer {
  0%   { background-position: 0 0; }
  100% { background-position: 256px 256px; }
}

.noise-shimmer {
  animation: noiseShimmer 1s steps(8) infinite;
}
