/* =============================================================================
   ANIMATIONS.CSS — Keyframes, Transitions, Micro-interactions
   HTTP Learning Portal
   ============================================================================= */

/* =============================================================================
   KEYFRAME DEFINITIONS
   ============================================================================= */

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

@keyframes float {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
  100% { transform: translateY(0px); }
}

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

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Network packet flying animation */
@keyframes packetFly {
  0% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
  40% {
    transform: translateX(60px) scale(0.8);
    opacity: 0.8;
  }
  60% {
    transform: translateX(60px) scale(0.8);
    opacity: 0.8;
  }
  100% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
}

/* Response reveal */
@keyframes responseReveal {
  0% {
    opacity: 0;
    transform: translateY(8px);
    max-height: 0;
  }
  100% {
    opacity: 1;
    transform: translateY(0);
    max-height: 1000px;
  }
}

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

/* Bounce */
@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
    animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
  }
  50% {
    transform: translateY(-8px);
    animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
  }
}

/* Glow pulse for active send button */
@keyframes glowPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(46, 160, 67, 0);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(46, 160, 67, 0.15);
  }
}

/* Status code color flash */
@keyframes statusFlash {
  0%   { background: var(--color-bg-secondary); }
  30%  { background: var(--flash-color, var(--color-success-bg)); }
  100% { background: var(--color-bg-secondary); }
}

/* =============================================================================
   ANIMATION UTILITY CLASSES
   ============================================================================= */

.animate-fade-in        { animation: fadeIn 300ms ease both; }
.animate-fade-in-up     { animation: fadeInUp 350ms cubic-bezier(0.4, 0, 0.2, 1) both; }
.animate-fade-in-down   { animation: fadeInDown 350ms cubic-bezier(0.4, 0, 0.2, 1) both; }
.animate-slide-in-right { animation: slideInRight 350ms cubic-bezier(0.4, 0, 0.2, 1) both; }
.animate-slide-in-left  { animation: slideInLeft 350ms cubic-bezier(0.4, 0, 0.2, 1) both; }
.animate-scale-in       { animation: scaleIn 250ms cubic-bezier(0.4, 0, 0.2, 1) both; }
.animate-spin           { animation: spin 1s linear infinite; }
.animate-pulse          { animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }

/* Stagger delays for list animations */
.stagger-1 { animation-delay: 50ms; }
.stagger-2 { animation-delay: 100ms; }
.stagger-3 { animation-delay: 150ms; }
.stagger-4 { animation-delay: 200ms; }
.stagger-5 { animation-delay: 250ms; }

/* =============================================================================
   LOADING SKELETON
   ============================================================================= */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-bg-tertiary) 25%,
    var(--color-border-secondary) 50%,
    var(--color-bg-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
  color: transparent;
}

/* =============================================================================
   REQUEST SIMULATOR ANIMATION
   ============================================================================= */

/* Network diagram animation container */
.network-flow {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-4);
}

.network-flow__node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  z-index: 1;
}

.network-flow__node-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: var(--color-bg-surface);
  border: 2px solid var(--color-border-primary);
  transition: all var(--transition-normal);
}

.network-flow__node-label {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  font-weight: var(--font-weight-medium);
}

.network-flow__line {
  flex: 1;
  height: 2px;
  background: var(--color-border-primary);
  position: relative;
  overflow: visible;
}

.network-flow__packet {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}

.network-flow__packet--request {
  background: var(--color-accent-primary);
  left: -6px;
  box-shadow: 0 0 8px var(--color-accent-primary);
}

.network-flow__packet--response {
  background: var(--color-success);
  right: -6px;
  box-shadow: 0 0 8px var(--color-success);
}

/* Packet travel animation */
@keyframes travelRight {
  0%   { left: -6px; opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { left: calc(100% + 6px); opacity: 0; }
}

@keyframes travelLeft {
  0%   { right: -6px; opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { right: calc(100% + 6px); opacity: 0; }
}

.network-flow.is-sending .network-flow__packet--request {
  animation: travelRight 0.8s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.network-flow.is-receiving .network-flow__packet--response {
  animation: travelLeft 0.8s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.network-flow.is-sending .network-flow__node-icon:first-child,
.network-flow.is-receiving .network-flow__node-icon:last-child {
  border-color: var(--color-accent-primary);
  box-shadow: 0 0 0 4px rgba(88, 166, 255, 0.15);
}

/* =============================================================================
   LOADING SPINNER
   ============================================================================= */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.spinner--dark {
  border: 2px solid var(--color-border-primary);
  border-top-color: var(--color-accent-primary);
}

.spinner--sm {
  width: 12px;
  height: 12px;
}

.spinner--lg {
  width: 24px;
  height: 24px;
  border-width: 3px;
}

/* =============================================================================
   PAGE TRANSITIONS
   ============================================================================= */
.page-enter {
  animation: fadeInUp 400ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

/* =============================================================================
   MICRO-INTERACTIONS
   ============================================================================= */

/* Send button glow when ready */
.btn--send:not(:disabled) {
  animation: glowPulse 3s ease infinite;
}

.btn--send:not(:disabled):hover {
  animation: none;
}

/* Copy button success state */
.code-block__copy-btn.is-copied svg {
  animation: scaleIn 200ms ease;
}

/* Method card hover lift */
.method-card {
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

.method-card:hover {
  transform: translateX(2px);
}

/* Status card hover */
.status-card {
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.status-card:hover {
  transform: translateY(-2px);
}

/* =============================================================================
   RESPONSE PANEL ANIMATIONS
   ============================================================================= */
.response-panel__body.is-revealed {
  animation: responseReveal 400ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

/* Typing effect for response text */
.typing-cursor::after {
  content: '|';
  animation: cursorBlink 1s step-end infinite;
  color: var(--color-accent-primary);
  font-weight: var(--font-weight-regular);
}

/* =============================================================================
   HERO GRADIENT ANIMATION
   ============================================================================= */
@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.hero__title-gradient {
  background: linear-gradient(135deg, var(--color-accent-primary) 0%, #a855f7 50%, #ec4899 100%);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 4s ease infinite;
}

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