/**
 * 移动端体验增强CSS - SoundFlows
 * 解决移动端常见问题，提升用户体验
 */

/* =============================================
   移动端Meta标签和基础设置
   ============================================= */

/* 确保正确viewport */
@-webkit-viewport {
  width: device-width;
  initial-scale: 1;
  user-scalable: yes;
}

@-moz-viewport {
  width: device-width;
  initial-scale: 1;
  user-scalable: yes;
}

@-ms-viewport {
  width: device-width;
  initial-scale: 1;
  user-scalable: yes;
}

@-o-viewport {
  width: device-width;
  initial-scale: 1;
  user-scalable: yes;
}

@viewport {
  width: device-width;
  initial-scale: 1;
  user-scalable: yes;
}

/* =============================================
   iOS特定修复
   ============================================= */

/* 修复iOS Safari地址栏影响 */
html {
  height: 100%;
  position: relative;
}

body {
  min-height: 100%;
  position: relative;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

/* 防止iOS橡皮筋效果 (现代方案) */
body {
  overscroll-behavior-y: none; /* 防止过度滚动 */
  -webkit-overflow-scrolling: touch; /* iOS平滑滚动 */
}

/* =============================================
   触摸优化
   ============================================= */

/* 优化触摸反馈 */
* {
  -webkit-tap-highlight-color: rgba(102, 102, 255, 0.3);
  -webkit-tap-highlight-color: transparent;
}

/* 按钮和可点击元素 */
button,
.button,
.btn,
.track-item,
.category-card,
.featured-track-btn,
.theme-nav-btn,
.language-btn,
.share-btn,
.tutorial-btn {
  min-height: 44px;
  min-width: 44px;
  position: relative;
  cursor: pointer;
  transition: all 0.2s ease;
}

/* 扩大触摸区域 */
button::before,
.button::before,
.btn::before {
  content: '';
  position: absolute;
  top: -5px;
  left: -5px;
  right: -5px;
  bottom: -5px;
  z-index: 1;
}

/* =============================================
   移动端导航优化
   ============================================= */

@media (max-width: 768px) {
  /* 底部固定导航栏 */
  .mobile-nav-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: rgba(13, 19, 31, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: #aab8dd;
    text-decoration: none;
    font-size: 12px;
    transition: color 0.3s ease;
  }

  .mobile-nav-item.active {
    color: #6666ff;
  }

  .mobile-nav-icon {
    font-size: 20px;
  }

  /* 为主内容区域添加底部padding，避免被导航栏遮挡 */
  .main-content-wrapper {
    padding-bottom: 80px;
  }
}

/* =============================================
   音频控件移动端优化
   ============================================= */

@media (max-width: 768px) {
  /* 音频控件布局 */
  .audio-controller {
    position: fixed;
    bottom: 60px;
    left: 0;
    right: 0;
    background: rgba(13, 19, 31, 0.98);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 15px;
    z-index: 999;
  }

  /* 播放控制按钮 */
  .playback-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 15px;
  }

  .play-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #6666ff;
    border: none;
    color: white;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(102, 102, 255, 0.3);
  }

  /* 进度条优化 */
  .progress-section {
    padding: 0 10px;
  }

  .progress-bar-container {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    cursor: pointer;
    position: relative;
  }

  .progress-bar {
    height: 100%;
    background: #6666ff;
    border-radius: 3px;
    position: relative;
  }

  .progress-handle {
    position: absolute;
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

/* =============================================
   横屏模式优化
   ============================================= */

@media (max-width: 768px) and (orientation: landscape) {
  /* 横屏时隐藏不必要元素 */
  .brand-subtitle,
  .healing-tip {
    display: none;
  }

  /* 调整布局 */
  .dashboard-content {
    padding: 10px;
  }

  .status-cards {
    flex-direction: row;
    gap: 10px;
  }

  .status-card {
    flex: 1;
    padding: 10px;
  }
}

/* =============================================
   手势支持
   ============================================= */

/* 滑动手势支持 */
.swipeable {
  touch-action: pan-y;
}

/* 水平滑动指示器 */
.swipe-indicator {
  display: none;
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.5);
  color: white;
  padding: 5px 15px;
  border-radius: 20px;
  font-size: 12px;
}

@media (max-width: 768px) {
  .swipe-indicator {
    display: block;
  }
}

/* =============================================
   移动端性能优化
   ============================================= */

/* 减少动画 */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 硬件加速 */
.gpu-accelerated {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

/* =============================================
   表单优化
   ============================================= */

@media (max-width: 768px) {
  input, textarea, select {
    font-size: 16px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.05);
    color: white;
    border-radius: 8px;
    width: 100%;
  }

  input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: #6666ff;
    background: rgba(255, 255, 255, 0.1);
  }

  /* 防止iOS缩放 */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  input[type="number"],
  textarea {
    font-size: 16px;
  }
}

/* =============================================
   加载状态优化
   ============================================= */

.mobile-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(13, 19, 31, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: #6666ff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* =============================================
   移动端调试辅助
   ============================================= */

/* 调试信息面板 */
.mobile-debug {
  position: fixed;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 10px;
  border-radius: 8px;
  font-size: 12px;
  z-index: 9999;
  display: none;
}

/* 只在开发环境显示 */
.debug-mode .mobile-debug {
  display: block;
}

/* =============================================
   PWA更新通知
   ============================================= */

.update-notification {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(102, 102, 255, 0.95);
  color: white;
  padding: 12px 20px;
  border-radius: 30px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 10000;
  animation: slideUp 0.3s ease;
}

.update-content {
  display: flex;
  align-items: center;
  gap: 15px;
  font-size: 14px;
}

.update-content button {
  background: white;
  color: #6666ff;
  border: none;
  padding: 6px 16px;
  border-radius: 20px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

@keyframes slideUp {
  from {
    transform: translate(-50%, 100%);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}