/* ==========================================================================
   animations.css · 动效系统
   topfootballers.com · B01-4/68
   原则：只用 opacity 和 transform，不阻塞主线程，尊重 reduced-motion
   ========================================================================== */

/* ==========================================================================
   1. 关键帧定义
   ========================================================================== */

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

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

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

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

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

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

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

@keyframes glowPulse {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.1); }
}

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

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

@keyframes bounceIn {
  0%   { opacity: 0; transform: scale(0.3); }
  50%  { opacity: 1; transform: scale(1.05); }
  70%  { transform: scale(0.9); }
  100% { transform: scale(1); }
}

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

/* ==========================================================================
   2. 页面加载动效
   ========================================================================== */

.page-load-fade {
  animation: fadeIn var(--duration-slow) var(--ease-out);
}

.page-load-fade-up {
  animation: fadeInUp var(--duration-slow) var(--ease-out);
}

main > section:first-child {
  animation: fadeInUp 400ms var(--ease-out);
}

main > section:nth-child(2) {
  animation: fadeInUp 400ms var(--ease-out) 60ms backwards;
}

main > section:nth-child(3) {
  animation: fadeInUp 400ms var(--ease-out) 120ms backwards;
}

/* ==========================================================================
   3. 滚动触发动效（配合 IntersectionObserver 使用）
   ========================================================================== */

.scroll-fade {
  opacity: 0;
  transform: translateY(16px);
  transition:
    opacity 400ms var(--ease-out),
    transform 400ms var(--ease-out);
}

.scroll-fade.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.scroll-fade-delay-1 { transition-delay: 60ms; }
.scroll-fade-delay-2 { transition-delay: 120ms; }
.scroll-fade-delay-3 { transition-delay: 180ms; }

/* ==========================================================================
   4. 悬停动效（桌面端）
   ========================================================================== */

.hover-lift {
  transition:
    transform var(--duration-normal) var(--ease-out),
    box-shadow var(--duration-normal) var(--ease-out);
}

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

.hover-scale {
  transition: transform var(--duration-normal) var(--ease-spring);
}

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

.hover-glow {
  transition: box-shadow var(--duration-normal) var(--ease-out);
}

.hover-glow:hover {
  box-shadow: 0 0 0 4px var(--color-primary-100);
}

.hover-underline {
  position: relative;
}

.hover-underline::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: -2px;
  width: 0;
  height: 2px;
  background: var(--color-primary-500);
  transition: width var(--duration-normal) var(--ease-out);
}

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

/* ==========================================================================
   5. 聚焦动效（键盘导航反馈）
   ========================================================================== */

.focus-ring {
  transition: box-shadow var(--duration-fast) var(--ease-out);
}

.focus-ring:focus-visible {
  box-shadow: var(--shadow-focus);
  outline: 2px solid var(--color-primary-500);
  outline-offset: 2px;
}

/* ==========================================================================
   6. 点击反馈
   ========================================================================== */

.press-scale:active {
  transform: scale(0.97);
  transition: transform var(--duration-fast) var(--ease-spring);
}

.press-fade:active {
  opacity: 0.8;
  transition: opacity var(--duration-fast) var(--ease-out);
}

/* ==========================================================================
   7. 内容过渡（FAQ 折叠 / Tabs）
   ========================================================================== */

details {
  transition: background var(--duration-normal) var(--ease-out);
}

details[open] > summary {
  transition: color var(--duration-normal) var(--ease-out);
}

.fade-content {
  animation: fadeIn var(--duration-slow) var(--ease-out);
}

/* ==========================================================================
   8. 加载指示器
   ========================================================================== */

.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--color-neutral-200);
  border-top-color: var(--color-primary-500);
  border-radius: var(--radius-full);
  animation: spin 600ms linear infinite;
}

.spinner-large {
  width: 40px;
  height: 40px;
  border-width: 3px;
}

.loading-pulse {
  animation: pulse var(--loading-pulse) var(--ease-in-out) infinite;
}

/* ==========================================================================
   9. 装饰动效（光点 / 光晕）
   ========================================================================== */

.light-dot {
  animation: glowPulse 3s var(--ease-in-out) infinite;
}

.light-dot:nth-child(2n) { animation-duration: 2.5s; animation-delay: 0.5s; }
.light-dot:nth-child(3n) { animation-duration: 4s;   animation-delay: 1s; }
.light-dot:nth-child(4n) { animation-duration: 2.8s; animation-delay: 1.5s; }
.light-dot:nth-child(5n) { animation-duration: 3.2s; animation-delay: 0.8s; }

/* ==========================================================================
   10. 主题切换过渡
   ========================================================================== */

.theme-transition,
.theme-transition body,
.theme-transition .site-header,
.theme-transition .site-footer,
.theme-transition .article-card {
  transition:
    background-color var(--duration-slow) var(--ease-in-out),
    color var(--duration-slow) var(--ease-in-out),
    border-color var(--duration-slow) var(--ease-in-out);
}

/* ==========================================================================
   11. 页面进入 stagger
   ========================================================================== */

.stagger-children > * {
  animation: fadeInUp 400ms var(--ease-out) backwards;
}

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

/* ==========================================================================
   12. 减少动效偏好降级（全局）
   ========================================================================== */

@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;
  }

  .light-dot,
  .spinner,
  .loading-pulse {
    animation: none;
    opacity: 0.5;
  }

  .scroll-fade {
    opacity: 1;
    transform: none;
  }
}

/* ==========================================================================
   13. 移动端减少动效（性能优化）
   ========================================================================== */

@media (max-width: 768px) {
  .scroll-fade {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .hover-lift:hover,
  .hover-scale:hover {
    transform: none;
    box-shadow: none;
  }

  .light-dot {
    animation-duration: 3s;
  }

  /* 移动端只保留必要的点击反馈 */
  .press-scale:active {
    transform: scale(0.98);
  }
}
