/**
 * Enhanced Interactions - Super Player App
 * Phase 2: 交互增强
 * 
 * 包含：页面转场动画、点击反馈、加载状态等增强效果
 */

/* ========================================
   页面转场动画（增强版）
   ======================================== */

/* 前进动画 - 新页面从右侧滑入并放大 */
@keyframes page-enter-forward {
  from {
    opacity: 0;
    transform: translateX(100%) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

/* 前进动画 - 旧页面轻微左移、缩小并降低透明度 */
@keyframes page-exit-forward {
  from {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
  to {
    opacity: 0.5;
    transform: translateX(-20%) scale(0.95);
  }
}

/* 后退动画 - 当前页面右移、缩小并淡出 */
@keyframes page-enter-backward {
  from {
    opacity: 0.5;
    transform: translateX(-20%) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

/* 后退动画 - 当前页面右移并淡出 */
@keyframes page-exit-backward {
  from {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateX(100%) scale(0.95);
  }
}

/* 应用转场动画的类 */
.page-transition-enter-forward {
  animation: page-enter-forward var(--duration-normal) var(--ease-spring);
}

.page-transition-exit-forward {
  animation: page-exit-forward var(--duration-normal) var(--ease-spring);
}

.page-transition-enter-backward {
  animation: page-enter-backward var(--duration-normal) var(--ease-spring);
}

.page-transition-exit-backward {
  animation: page-exit-backward var(--duration-normal) var(--ease-spring);
}

/* ========================================
   点击反馈增强
   ======================================== */

/* 为所有可点击元素添加基础反馈 */
button,
a,
[role="button"],
[onclick],
.clickable {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--duration-fast) var(--ease-out);
}

button:active,
a:active,
[role="button"]:active,
[onclick]:active,
.clickable:active {
  transform: scale(0.97);
}

/* 卡片点击反馈 */
.card-interactive {
  position: relative;
  overflow: hidden;
  transition: all var(--duration-fast) var(--ease-out);
}

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

.card-interactive:active {
  transform: translateY(0) scale(0.98);
}

/* 导航按钮增强反馈 */
.nav-btn {
  position: relative;
  transition: all var(--duration-fast) var(--ease-out);
}

.nav-btn:active {
  transform: scale(0.95);
}

.nav-btn.active::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  animation: nav-indicator-appear var(--duration-fast) var(--ease-out);
}

@keyframes nav-indicator-appear {
  from {
    width: 0;
    opacity: 0;
  }
  to {
    width: 24px;
    opacity: 1;
  }
}

/* ========================================
   加载状态增强
   ======================================== */

/* 全屏加载遮罩 */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-normal) var(--ease-out);
}

.loading-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spinner-rotate 800ms linear infinite;
}

@keyframes spinner-rotate {
  to {
    transform: rotate(360deg);
  }
}

.loading-text {
  margin-top: var(--spacing-4);
  color: white;
  font-size: var(--text-base);
  font-weight: var(--font-medium);
}

/* 按钮加载状态增强 */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn-loading::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: currentColor;
  border-radius: var(--radius-full);
  animation: spinner-rotate 600ms linear infinite;
}

/* 内联加载指示器 */
.loading-inline {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-2);
}

.loading-inline::before {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spinner-rotate 600ms linear infinite;
}

/* ========================================
   骨架屏增强
   ======================================== */

/* 列表骨架屏 */
.skeleton-list {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-4);
}

.skeleton-list-item {
  display: flex;
  gap: var(--spacing-3);
  padding: var(--spacing-4);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
}

.skeleton-list-item-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-list-item-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-2);
}

.skeleton-list-item-title {
  height: 16px;
  width: 60%;
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-list-item-text {
  height: 12px;
  width: 80%;
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  animation-delay: 0.1s;
}

/* 卡片骨架屏 */
.skeleton-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--spacing-4);
}

.skeleton-card-item {
  aspect-ratio: 1;
  border-radius: var(--radius-lg);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

/* ========================================
   焦点可见性增强
   ======================================== */

/* 仅在键盘导航时显示焦点环 */
.focus-visible:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* 默认隐藏焦点环 */
:focus:not(.focus-visible) {
  outline: none;
}

/* ========================================
   Hover 状态增强
   ======================================== */

/* 链接 hover */
a:not(.btn):hover {
  color: var(--color-primary);
  text-decoration: underline;
}

/* 图标按钮 hover */
.icon-btn {
  width: var(--touch-target-min);
  height: var(--touch-target-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  transition: all var(--duration-fast) var(--ease-out);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.05);
}

.icon-btn:active {
  transform: scale(0.95);
}

/* ========================================
   滚动行为优化
   ======================================== */

/* 平滑滚动 */
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* 自定义滚动条 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ========================================
   触摸反馈优化
   ======================================== */

/* 移除默认的触摸高亮 */
* {
  -webkit-tap-highlight-color: transparent;
}

/* 触摸延迟优化 */
a,
button,
input,
textarea,
select {
  touch-action: manipulation;
}

/* ========================================
   状态指示器
   ======================================== */

/* 成功状态 */
.state-success {
  color: var(--color-success);
  animation: state-appear var(--duration-fast) var(--ease-out);
}

/* 错误状态 */
.state-error {
  color: var(--color-error);
  animation: state-shake var(--duration-normal) var(--ease-out);
}

@keyframes state-appear {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes state-shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-10px);
  }
  75% {
    transform: translateX(10px);
  }
}

/* ========================================
   进度指示器
   ======================================== */

.progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-primary-hover));
  border-radius: var(--radius-full);
  transition: width var(--duration-normal) var(--ease-out);
}

.progress-bar-indeterminate .progress-bar-fill {
  width: 30%;
  animation: progress-indeterminate 1.5s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(400%);
  }
}

/* ========================================
   空状态优化
   ======================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-12) var(--spacing-6);
  text-align: center;
  animation: empty-state-appear var(--duration-slow) var(--ease-out);
}

@keyframes empty-state-appear {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin-bottom: var(--spacing-4);
  opacity: 0.5;
}

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--color-text-primary);
  margin-bottom: var(--spacing-2);
}

.empty-state-description {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--spacing-6);
  max-width: 300px;
}
