/* ============================================================
   THINKING MASTERY SYSTEM — ANIMATIONS
   Keyframes, animation utilities, transitions, hover effects
   ============================================================ */


/* ──────────────────────────────────────────
   1. KEYFRAME DEFINITIONS
   ────────────────────────────────────────── */

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

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

/* Slide in from right */
@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(28px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Slide out to right */
@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(28px);
  }
}

/* Slide in from left */
@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-28px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Slide up */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Slide down */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Slide up and out */
@keyframes slideUpOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

/* Scale in */
@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.88);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Scale bounce in */
@keyframes scaleBounceIn {
  0%   { opacity: 0; transform: scale(0.5); }
  70%  { opacity: 1; transform: scale(1.06); }
  85%  { transform: scale(0.97); }
  100% { opacity: 1; transform: scale(1); }
}

/* Shimmer (skeleton loading) */
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Pulse / glow */
@keyframes pulse {
  0%   { opacity: 1; }
  50%  { opacity: 0.65; }
  100% { opacity: 1; }
}

/* Pulse ring (expanding ring for active/live elements) */
@keyframes pulseRing {
  0% {
    box-shadow: 0 0 0 0 rgba(167, 139, 250, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(167, 139, 250, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(167, 139, 250, 0);
  }
}

/* Bounce (achievement unlock) */
@keyframes bounce {
  0%   { transform: translateY(0) scale(1); }
  20%  { transform: translateY(-18px) scale(1.04); }
  40%  { transform: translateY(0) scale(0.98); }
  60%  { transform: translateY(-9px) scale(1.01); }
  80%  { transform: translateY(0) scale(0.99); }
  100% { transform: translateY(0) scale(1); }
}

/* Confetti-style scale bounce */
@keyframes popIn {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  80%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}

/* Spin (loading spinner) */
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Spin slow */
@keyframes spinSlow {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Progress bar fill */
@keyframes progressFill {
  from { width: 0%; }
  to   { width: 100%; }
}

/* Progress bar grow from a stored width variable */
@keyframes progressGrow {
  from { width: 0%; }
  to   { width: var(--target-width, 100%); }
}

/* Count up (numeric animation base) */
@keyframes countUp {
  from { transform: translateY(6px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* Graph draw (knowledge graph edge lines) */
@keyframes graphDraw {
  from {
    stroke-dashoffset: 1000;
    opacity: 0;
  }
  to {
    stroke-dashoffset: 0;
    opacity: 1;
  }
}

/* Graph node appear */
@keyframes graphNodeIn {
  from {
    r: 0;
    opacity: 0;
  }
  to {
    r: var(--node-r, 8);
    opacity: 1;
  }
}

/* Float (subtle hover/idle float for decorative elements) */
@keyframes float {
  0%   { transform: translateY(0px); }
  50%  { transform: translateY(-8px); }
  100% { transform: translateY(0px); }
}

/* Shake (error state) */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15%       { transform: translateX(-6px); }
  30%       { transform: translateX(5px); }
  45%       { transform: translateX(-4px); }
  60%       { transform: translateX(3px); }
  75%       { transform: translateX(-2px); }
}

/* Wiggle */
@keyframes wiggle {
  0%   { transform: rotate(0deg); }
  20%  { transform: rotate(-8deg); }
  40%  { transform: rotate(8deg); }
  60%  { transform: rotate(-5deg); }
  80%  { transform: rotate(5deg); }
  100% { transform: rotate(0deg); }
}

/* Heart beat (for streak display) */
@keyframes heartbeat {
  0%   { transform: scale(1); }
  14%  { transform: scale(1.15); }
  28%  { transform: scale(1); }
  42%  { transform: scale(1.1); }
  70%  { transform: scale(1); }
}

/* Ripple (button click) */
@keyframes ripple {
  from {
    width: 0;
    height: 0;
    opacity: 0.5;
  }
  to {
    width: 200%;
    height: 200%;
    opacity: 0;
  }
}

/* Glow pulse (accent elements) */
@keyframes glowPulse {
  0%, 100% {
    box-shadow: 0 0 12px rgba(167, 139, 250, 0.2);
  }
  50% {
    box-shadow: 0 0 28px rgba(167, 139, 250, 0.45);
  }
}

/* Star twinkle */
@keyframes twinkle {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.8); }
}

/* Gradient shift (animated gradient backgrounds) */
@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Marquee scroll */
@keyframes marquee {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

/* Typewriter blink cursor */
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* XP bar fill on level up */
@keyframes xpFill {
  0%   { width: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-blue)); }
  50%  { width: 0%; }
  51%  { background: linear-gradient(90deg, var(--accent-gold), var(--accent-orange)); }
  100% { width: var(--xp-target, 0%); background: linear-gradient(90deg, var(--accent-gold), var(--accent-orange)); }
}


/* ──────────────────────────────────────────
   2. ANIMATION UTILITY CLASSES
   ────────────────────────────────────────── */

/* Base animation class */
.animate-fade-in {
  animation: fadeIn 0.3s ease forwards;
}

.animate-fade-out {
  animation: fadeOut 0.25s ease forwards;
}

.animate-slide-up {
  animation: slideUp 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.animate-slide-down {
  animation: slideDown 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.animate-slide-in-right {
  animation: slideInRight 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.animate-slide-in-left {
  animation: slideInLeft 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.animate-scale-in {
  animation: scaleIn 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.animate-scale-bounce {
  animation: scaleBounceIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.animate-pulse {
  animation: pulse 2.5s ease-in-out infinite;
}

.animate-pulse-ring {
  animation: pulseRing 2s infinite;
}

.animate-bounce {
  animation: bounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.animate-spin {
  animation: spin 0.8s linear infinite;
}

.animate-spin-slow {
  animation: spinSlow 6s linear infinite;
}

.animate-float {
  animation: float 3s ease-in-out infinite;
}

.animate-shake {
  animation: shake 0.4s ease;
}

.animate-wiggle {
  animation: wiggle 0.5s ease;
}

.animate-heartbeat {
  animation: heartbeat 1.4s ease infinite;
}

.animate-glow {
  animation: glowPulse 2.5s ease-in-out infinite;
}

.animate-twinkle {
  animation: twinkle 1.8s ease-in-out infinite;
}

.animate-pop-in {
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.animate-gradient {
  background-size: 200% 200%;
  animation: gradientShift 4s ease infinite;
}


/* Animation delay utilities */
.delay-0   { animation-delay: 0ms; }
.delay-100 { animation-delay: 100ms; }
.delay-150 { animation-delay: 150ms; }
.delay-200 { animation-delay: 200ms; }
.delay-300 { animation-delay: 300ms; }
.delay-400 { animation-delay: 400ms; }
.delay-500 { animation-delay: 500ms; }
.delay-700 { animation-delay: 700ms; }
.delay-1000{ animation-delay: 1000ms; }

/* Animation duration utilities */
.duration-150  { animation-duration: 150ms; }
.duration-200  { animation-duration: 200ms; }
.duration-300  { animation-duration: 300ms; }
.duration-500  { animation-duration: 500ms; }
.duration-700  { animation-duration: 700ms; }
.duration-1000 { animation-duration: 1000ms; }

/* Animation fill mode */
.fill-forwards { animation-fill-mode: forwards; }
.fill-both     { animation-fill-mode: both; }


/* Stagger children animations */
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 60ms; }
.stagger > *:nth-child(3) { animation-delay: 120ms; }
.stagger > *:nth-child(4) { animation-delay: 180ms; }
.stagger > *:nth-child(5) { animation-delay: 240ms; }
.stagger > *:nth-child(6) { animation-delay: 300ms; }
.stagger > *:nth-child(7) { animation-delay: 360ms; }
.stagger > *:nth-child(8) { animation-delay: 420ms; }

.stagger-sm > *:nth-child(1) { animation-delay: 0ms; }
.stagger-sm > *:nth-child(2) { animation-delay: 40ms; }
.stagger-sm > *:nth-child(3) { animation-delay: 80ms; }
.stagger-sm > *:nth-child(4) { animation-delay: 120ms; }
.stagger-sm > *:nth-child(5) { animation-delay: 160ms; }
.stagger-sm > *:nth-child(6) { animation-delay: 200ms; }
.stagger-sm > *:nth-child(7) { animation-delay: 240ms; }
.stagger-sm > *:nth-child(8) { animation-delay: 280ms; }


/* ──────────────────────────────────────────
   3. TRANSITION UTILITIES
   ────────────────────────────────────────── */

.transition-none {
  transition: none !important;
}

.transition-fast {
  transition: all var(--transition-fast) !important;
}

.transition-all {
  transition: all var(--transition) !important;
}

.transition-slow {
  transition: all var(--transition-slow) !important;
}

.transition-colors {
  transition:
    color var(--transition),
    background-color var(--transition),
    border-color var(--transition) !important;
}

.transition-transform {
  transition: transform var(--transition) !important;
}

.transition-opacity {
  transition: opacity var(--transition) !important;
}

.transition-shadow {
  transition: box-shadow var(--transition) !important;
}


/* ──────────────────────────────────────────
   4. HOVER ANIMATION UTILITIES
   ────────────────────────────────────────── */

/* Lift on hover */
.hover-lift {
  transition: transform var(--transition), box-shadow var(--transition);
}

.hover-lift:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

/* Strong lift */
.hover-lift-lg {
  transition: transform var(--transition), box-shadow var(--transition);
}

.hover-lift-lg:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow-lg);
}

/* Glow on hover */
.hover-glow {
  transition: box-shadow var(--transition), border-color var(--transition);
}

.hover-glow:hover {
  box-shadow: var(--shadow-accent);
  border-color: var(--border-accent);
}

/* Scale on hover */
.hover-scale {
  transition: transform var(--transition-fast);
}

.hover-scale:hover {
  transform: scale(1.03);
}

.hover-scale-sm:hover {
  transform: scale(1.015);
}

.hover-scale-lg:hover {
  transform: scale(1.06);
}

/* Dim on hover */
.hover-dim {
  transition: opacity var(--transition);
}

.hover-dim:hover {
  opacity: 0.75;
}

/* Brighten (for images/icons) */
.hover-brighten {
  transition: filter var(--transition);
}

.hover-brighten:hover {
  filter: brightness(1.2);
}

/* Underline grow (link hover) */
.hover-underline {
  position: relative;
  text-decoration: none;
}

.hover-underline::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 0;
  height: 1px;
  background: currentColor;
  transition: width var(--transition);
}

.hover-underline:hover::after {
  width: 100%;
}

/* Rotate icon on hover */
.hover-rotate {
  transition: transform var(--transition);
}

.hover-rotate:hover {
  transform: rotate(15deg);
}

.hover-rotate-90:hover {
  transform: rotate(90deg);
}

.hover-rotate-180:hover {
  transform: rotate(180deg);
}

/* Accent border reveal */
.hover-accent-border {
  border: 1px solid var(--border);
  transition: border-color var(--transition);
}

.hover-accent-border:hover {
  border-color: var(--accent);
}

/* Background reveal */
.hover-bg-reveal {
  transition: background var(--transition);
}

.hover-bg-reveal:hover {
  background: var(--surface-hover);
}


/* ──────────────────────────────────────────
   5. FOCUS / INTERACTION STATE ANIMATIONS
   ────────────────────────────────────────── */

/* Button ripple effect */
.btn-ripple {
  position: relative;
  overflow: hidden;
}

.btn-ripple .ripple {
  position: absolute;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.15);
  transform: scale(0);
  animation: ripple 0.5s linear;
  pointer-events: none;
}

/* Input focus animation */
.form-input-animated,
.form-select-animated,
.form-textarea-animated {
  border-bottom: 2px solid var(--border);
  border-left: none;
  border-right: none;
  border-top: none;
  border-radius: 0;
  background: transparent;
  padding: var(--space-3) 0;
  transition: border-color var(--transition);
}

.form-input-animated:focus,
.form-select-animated:focus,
.form-textarea-animated:focus {
  border-bottom-color: var(--accent);
  box-shadow: none;
}


/* ──────────────────────────────────────────
   6. GRAPH ANIMATION UTILITIES
   ────────────────────────────────────────── */

/* Applied to SVG line/path elements for draw-on effect */
.graph-edge {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  animation: graphDraw 0.8s ease forwards;
}

.graph-node {
  animation: scaleBounceIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  transform-origin: center;
}

/* Delay classes for node animations */
.graph-node:nth-child(1)  { animation-delay: 0ms; }
.graph-node:nth-child(2)  { animation-delay: 40ms; }
.graph-node:nth-child(3)  { animation-delay: 80ms; }
.graph-node:nth-child(4)  { animation-delay: 120ms; }
.graph-node:nth-child(5)  { animation-delay: 160ms; }
.graph-node:nth-child(6)  { animation-delay: 200ms; }
.graph-node:nth-child(7)  { animation-delay: 240ms; }
.graph-node:nth-child(8)  { animation-delay: 280ms; }
.graph-node:nth-child(9)  { animation-delay: 320ms; }
.graph-node:nth-child(10) { animation-delay: 360ms; }


/* ──────────────────────────────────────────
   7. PAGE TRANSITION ANIMATIONS
   ────────────────────────────────────────── */

/* View enter animation — applied to #view-root content */
.page-enter {
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.page-enter-fade {
  animation: fadeIn 0.25s ease forwards;
}

.page-exit {
  animation: slideUpOut 0.2s ease forwards;
}

/* Section reveal (scroll-triggered or mount) */
.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}


/* ──────────────────────────────────────────
   8. PROGRESS & STATUS ANIMATIONS
   ────────────────────────────────────────── */

/* Progress bar initial animation */
.progress-fill-animated {
  animation: progressGrow 0.9s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Streak fire animation */
.streak-icon-animated {
  animation: heartbeat 1.4s ease infinite, wiggle 2s ease 1s 1;
}

/* Level up badge flash */
.level-up-flash {
  animation: glowPulse 0.4s ease 3, scaleBounceIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Checkmark draw for completed items */
@keyframes checkDraw {
  from { stroke-dashoffset: 30; }
  to   { stroke-dashoffset: 0; }
}

.check-animated {
  stroke-dasharray: 30;
  stroke-dashoffset: 30;
  animation: checkDraw 0.35s ease forwards;
}

/* Quiz answer feedback flash */
.answer-correct-flash {
  animation: pulse 0.4s ease 2;
}

.answer-incorrect-flash {
  animation: shake 0.4s ease;
}


/* ──────────────────────────────────────────
   9. REDUCED MOTION SUPPORT
   ────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .skeleton {
    animation: none;
    background: var(--surface-overlay);
  }

  .animate-float,
  .animate-pulse,
  .animate-spin,
  .animate-spin-slow,
  .animate-heartbeat,
  .animate-twinkle,
  .animate-glow,
  .streak-icon-animated {
    animation: none !important;
  }
}


/* ──────────────────────────────────────────
   10. SPECIAL EFFECT: GRADIENT TEXT
   ────────────────────────────────────────── */

.text-gradient {
  background: linear-gradient(135deg, var(--accent), var(--accent-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.text-gradient-gold {
  background: linear-gradient(135deg, var(--accent-gold), var(--accent-orange));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.text-gradient-emerald {
  background: linear-gradient(135deg, var(--accent-emerald), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.text-gradient-animated {
  background: linear-gradient(270deg, var(--accent), var(--accent-blue), var(--accent-emerald), var(--accent));
  background-size: 300% 100%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 4s ease infinite;
}


/* ──────────────────────────────────────────
   11. SPECIAL EFFECT: GLASSMORPHISM
   ────────────────────────────────────────── */

.glass {
  background: rgba(15, 15, 26, 0.65);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.glass-strong {
  background: rgba(15, 15, 26, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}


/* ──────────────────────────────────────────
   12. SPECIAL EFFECT: NOISE / GRAIN OVERLAY
   ────────────────────────────────────────── */

.noise-overlay {
  position: relative;
}

.noise-overlay::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  border-radius: inherit;
  opacity: 0.5;
}


/* ──────────────────────────────────────────
   13. SPECIAL EFFECT: AURORA BACKGROUND
   ────────────────────────────────────────── */

.aurora-bg {
  position: relative;
  overflow: hidden;
}

.aurora-bg::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(
    ellipse at 30% 40%,
    rgba(167, 139, 250, 0.08) 0%,
    transparent 50%
  ),
  radial-gradient(
    ellipse at 70% 60%,
    rgba(96, 165, 250, 0.06) 0%,
    transparent 45%
  ),
  radial-gradient(
    ellipse at 50% 20%,
    rgba(52, 211, 153, 0.04) 0%,
    transparent 40%
  );
  pointer-events: none;
  animation: gradientShift 12s ease-in-out infinite;
}


/* ──────────────────────────────────────────
   14. ICON ANIMATIONS
   ────────────────────────────────────────── */

/* Notification bell ring */
@keyframes bellRing {
  0%   { transform: rotate(0deg); }
  10%  { transform: rotate(15deg); }
  20%  { transform: rotate(-12deg); }
  30%  { transform: rotate(10deg); }
  40%  { transform: rotate(-8deg); }
  50%  { transform: rotate(5deg); }
  60%  { transform: rotate(-3deg); }
  100% { transform: rotate(0deg); }
}

.icon-bell-ring {
  display: inline-block;
  transform-origin: top center;
  animation: bellRing 0.8s ease;
}

/* Sparkle */
@keyframes sparkle {
  0%   { transform: scale(0) rotate(0deg); opacity: 1; }
  100% { transform: scale(1.5) rotate(180deg); opacity: 0; }
}

.icon-sparkle {
  animation: sparkle 0.6s ease-out forwards;
}

/* Trophy bounce */
.icon-trophy {
  display: inline-block;
  animation: bounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}


/* ──────────────────────────────────────────
   15. CHART / DATA VIZ ANIMATIONS
   ────────────────────────────────────────── */

/* Bar chart bars grow up */
@keyframes barGrow {
  from { transform: scaleY(0); transform-origin: bottom; }
  to   { transform: scaleY(1); transform-origin: bottom; }
}

.chart-bar-animated {
  animation: barGrow 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Donut / pie chart fill */
@keyframes donutFill {
  from { stroke-dashoffset: 283; }
  to   { stroke-dashoffset: var(--donut-target, 0); }
}

.donut-fill-animated {
  animation: donutFill 0.9s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Number count-up (text animation via opacity/slide) */
.number-animated {
  animation: countUp 0.4s ease;
}
