/**
 * 海角社区视频解析系统 - 动画效果
 * 现代化交互动画和过渡效果
 * 使用统一的主题变量系统
 */

/* 动画变量已在themes.css中定义，这里添加额外的动画配置 */
:root {
  --animation-duration-instant: 0.1s;
  --animation-duration-fast: 0.15s;
  --animation-duration-normal: 0.3s;
  --animation-duration-slow: 0.5s;
  --animation-duration-slower: 0.75s;

  /* 高级缓动函数 */
  --easing-in-out-back: cubic-bezier(0.68, -0.6, 0.32, 1.6);
  --easing-in-out-circ: cubic-bezier(0.85, 0, 0.15, 1);
  --easing-in-out-expo: cubic-bezier(0.87, 0, 0.13, 1);
  --easing-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* 页面加载动画 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  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 scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slideInUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* 脉冲动画 */
@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

/* 摇摆动画 */
@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  10%, 30%, 50%, 70%, 90% {
    transform: translateX(-5px);
  }
  20%, 40%, 60%, 80% {
    transform: translateX(5px);
  }
}

/* 旋转加载动画 */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* 渐变背景动画 */
@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* ===== 页面元素入场动画 ===== */
.animate-fade-in-up {
  animation: fadeInUp var(--animation-duration-normal) var(--easing-smooth) forwards;
  opacity: 0;
}

.animate-fade-in-down {
  animation: fadeInDown var(--animation-duration-normal) var(--easing-smooth) forwards;
  opacity: 0;
}

.animate-fade-in-left {
  animation: fadeInLeft var(--animation-duration-normal) var(--easing-smooth) forwards;
  opacity: 0;
}

.animate-fade-in-right {
  animation: fadeInRight var(--animation-duration-normal) var(--easing-smooth) forwards;
  opacity: 0;
}

.animate-scale-in {
  animation: scaleIn var(--animation-duration-normal) var(--easing-spring) forwards;
  opacity: 0;
}

.animate-slide-in-up {
  animation: slideInUp var(--animation-duration-normal) var(--easing-smooth) forwards;
}

/* 动画延迟类 */
.animate-delay-1 {
  animation-delay: 0.1s;
}

.animate-delay-2 {
  animation-delay: 0.2s;
}

.animate-delay-3 {
  animation-delay: 0.3s;
}

.animate-delay-4 {
  animation-delay: 0.4s;
}

.animate-delay-5 {
  animation-delay: 0.5s;
}

/* 动画速度修饰符 */
.animate-fast {
  animation-duration: var(--animation-duration-fast) !important;
}

.animate-slow {
  animation-duration: var(--animation-duration-slow) !important;
}

.animate-slower {
  animation-duration: var(--animation-duration-slower) !important;
}

/* ===== 交互动画 ===== */

/* 悬停效果 */
.hover-lift {
  transition: var(--transition-base);
}

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

.hover-scale {
  transition: var(--transition-base);
}

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

.hover-glow {
  transition: var(--transition-base);
  position: relative;
  overflow: hidden;
}

.hover-glow::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left var(--animation-duration-slow) ease;
}

.hover-glow:hover::before {
  left: 100%;
}

/* 点击反馈 */
.click-feedback {
  position: relative;
  overflow: hidden;
}

.click-feedback::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width var(--animation-duration-fast) ease, height var(--animation-duration-fast) ease;
}

.click-feedback:active::after {
  width: 200px;
  height: 200px;
}

/* 脉冲动画 */
.animate-pulse {
  animation: pulse 2s infinite;
}

.animate-pulse-slow {
  animation: pulse 3s infinite;
}

/* 摇摆动画 */
.animate-shake {
  animation: shake var(--animation-duration-slow) ease-in-out;
}

/* 旋转动画 */
.animate-spin {
  animation: spin 1s linear infinite;
}

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

/* 渐变背景动画 */
.animate-gradient {
  background-size: 200% 200%;
  animation: gradientShift 3s ease infinite;
}

/* 加载动画 */
.loading-dots {
  display: inline-flex;
  gap: 4px;
}

.loading-dots::after {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: loadingDots 1.4s infinite ease-in-out both;
}

.loading-dots::before {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: loadingDots 1.4s infinite ease-in-out both;
  animation-delay: -0.16s;
}

@keyframes loadingDots {
  0%, 80%, 100% {
    transform: scale(0);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* 进度条动画 */
.progress-bar {
  position: relative;
  overflow: hidden;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  height: 8px;
}

.progress-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: var(--bg-gradient);
  border-radius: var(--radius-full);
  transition: width var(--animation-duration-slow) var(--easing-smooth);
}

.progress-bar.animate::after {
  animation: progressShine 2s infinite;
}

@keyframes progressShine {
  0% {
    box-shadow: 0 0 10px rgba(67, 97, 238, 0.3);
  }
  50% {
    box-shadow: 0 0 20px rgba(67, 97, 238, 0.6);
  }
  100% {
    box-shadow: 0 0 10px rgba(67, 97, 238, 0.3);
  }
}

/* ===== 页面过渡动画 ===== */
.page-transition {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--animation-duration-normal) var(--easing-smooth),
              transform var(--animation-duration-normal) var(--easing-smooth);
}

.page-transition.loaded {
  opacity: 1;
  transform: translateY(0);
}

/* 滚动触发动画 */
.scroll-animate {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity var(--animation-duration-slow) var(--easing-smooth),
              transform var(--animation-duration-slow) var(--easing-smooth);
}

.scroll-animate.in-view {
  opacity: 1;
  transform: translateY(0);
}

.scroll-animate-left {
  opacity: 0;
  transform: translateX(-30px);
  transition: opacity var(--animation-duration-slow) var(--easing-smooth),
              transform var(--animation-duration-slow) var(--easing-smooth);
}

.scroll-animate-left.in-view {
  opacity: 1;
  transform: translateX(0);
}

.scroll-animate-right {
  opacity: 0;
  transform: translateX(30px);
  transition: opacity var(--animation-duration-slow) var(--easing-smooth),
              transform var(--animation-duration-slow) var(--easing-smooth);
}

.scroll-animate-right.in-view {
  opacity: 1;
  transform: translateX(0);
}

.scroll-animate-scale {
  opacity: 0;
  transform: scale(0.9);
  transition: opacity var(--animation-duration-slow) var(--easing-smooth),
              transform var(--animation-duration-slow) var(--easing-spring);
}

.scroll-animate-scale.in-view {
  opacity: 1;
  transform: scale(1);
}

/* ===== 特殊效果动画 ===== */

/* 打字机效果 */
.typewriter {
  overflow: hidden;
  border-right: 2px solid var(--primary-color);
  white-space: nowrap;
  animation: typing 3.5s steps(40, end), blink-caret 0.75s step-end infinite;
}

@keyframes typing {
  from {
    width: 0;
  }
  to {
    width: 100%;
  }
}

@keyframes blink-caret {
  from, to {
    border-color: transparent;
  }
  50% {
    border-color: var(--primary-color);
  }
}

/* 浮动动画 */
.float {
  animation: float 3s ease-in-out infinite;
}

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

/* 呼吸灯效果 */
.breathe {
  animation: breathe 2s ease-in-out infinite;
}

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

/* 减少动画（用户偏好） */
@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;
  }

  .animate-fade-in-up,
  .animate-fade-in-down,
  .animate-fade-in-left,
  .animate-fade-in-right,
  .animate-scale-in,
  .scroll-animate,
  .scroll-animate-left,
  .scroll-animate-right,
  .scroll-animate-scale {
    opacity: 1;
    transform: none;
  }
}

/* 延迟动画 */
.animate-delay-1 {
  animation-delay: 0.1s;
}

.animate-delay-2 {
  animation-delay: 0.2s;
}

.animate-delay-3 {
  animation-delay: 0.3s;
}

.animate-delay-4 {
  animation-delay: 0.4s;
}

.animate-delay-5 {
  animation-delay: 0.5s;
}

/* 悬停效果 */
.hover-lift {
  transition: transform var(--animation-speed-normal) var(--easing-smooth),
              box-shadow var(--animation-speed-normal) var(--easing-smooth);
}

.hover-lift:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}

.hover-scale {
  transition: transform var(--animation-speed-fast) var(--easing-smooth);
}

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

.hover-glow {
  transition: box-shadow var(--animation-speed-normal) var(--easing-smooth);
}

.hover-glow:hover {
  box-shadow: 0 0 20px rgba(67, 97, 238, 0.3);
}

/* 按钮动画效果 */
.btn-animated {
  position: relative;
  overflow: hidden;
  transition: all var(--animation-speed-normal) var(--easing-smooth);
}

.btn-animated::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left var(--animation-speed-slow) var(--easing-smooth);
}

.btn-animated:hover::before {
  left: 100%;
}

.btn-animated:active {
  transform: scale(0.98);
}

/* 加载状态 */
.loading {
  position: relative;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* 输入框焦点动画 */
.input-animated {
  position: relative;
  transition: all var(--animation-speed-normal) var(--easing-smooth);
}

.input-animated:focus {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(67, 97, 238, 0.15);
}

/* 卡片入场动画 */
.card-entrance {
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp var(--animation-speed-normal) var(--easing-smooth) forwards;
}

/* 导航项动画 */
.nav-item-animated {
  position: relative;
  transition: all var(--animation-speed-normal) var(--easing-smooth);
}

.nav-item-animated::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  transition: all var(--animation-speed-normal) var(--easing-smooth);
  transform: translateX(-50%);
}

.nav-item-animated:hover::after,
.nav-item-animated.active::after {
  width: 80%;
}

/* 通知动画 */
.notification-slide-in {
  animation: slideInUp var(--animation-speed-normal) var(--easing-bounce);
}

/* 模态框动画 */
.modal-fade-in {
  animation: scaleIn var(--animation-speed-normal) var(--easing-smooth);
}

/* 渐变背景动画 */
.gradient-animated {
  background: linear-gradient(-45deg, #4361ee, #4cc9f0, #f72585, #4361ee);
  background-size: 400% 400%;
  animation: gradientShift 8s ease infinite;
}

/* 文字打字机效果 */
@keyframes typewriter {
  from {
    width: 0;
  }
  to {
    width: 100%;
  }
}

.typewriter {
  overflow: hidden;
  border-right: 2px solid var(--primary-color);
  white-space: nowrap;
  animation: typewriter 3s steps(40, end), blink-caret 0.75s step-end infinite;
}

@keyframes blink-caret {
  from, to {
    border-color: transparent;
  }
  50% {
    border-color: var(--primary-color);
  }
}

/* 滚动触发动画 */
.scroll-reveal {
  opacity: 0;
  transform: translateY(50px);
  transition: all 0.6s var(--easing-smooth);
}

.scroll-reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* 性能优化 */
.will-change-transform {
  will-change: transform;
}

.will-change-opacity {
  will-change: opacity;
}

/* 波纹效果 */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  transform: scale(0);
  animation: ripple-animation 0.6s linear;
  pointer-events: none;
}

@keyframes ripple-animation {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

/* 返回顶部按钮 */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  border: none;
  color: white;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8px 24px rgba(67, 97, 238, 0.3);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-to-top:hover {
  transform: translateY(-4px) scale(1.1);
  box-shadow: 0 12px 32px rgba(67, 97, 238, 0.4);
}

.back-to-top:active {
  transform: translateY(-2px) scale(1.05);
}

.back-to-top svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* 移动端返回顶部按钮调整 */
@media (max-width: 767px) {
  .back-to-top {
    bottom: calc(80px + env(safe-area-inset-bottom) + 16px);
    right: 16px;
    width: 48px;
    height: 48px;
  }

  .back-to-top svg {
    width: 20px;
    height: 20px;
  }
}

/* 减少动画的媒体查询 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
