/**
 * Splatoon 3 Hub - 移动端优化样式 v4.0
 * 全面移动端适配，保持斯普拉遁风格
 * 包含：底部导航、触控优化、响应式布局、性能降级
 */

/* ============================================
   1. CSS 变量与断点定义
   ============================================ */
:root {
  --mobile-breakpoint: 768px;
  --tablet-breakpoint: 1024px;
  --bottom-nav-height: 64px;
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --touch-target-min: 44px;
}

/* ============================================
   2. 基础移动端设置
   ============================================ */
@viewport {
  width: device-width;
  initial-scale: 1;
  maximum-scale: 5;
  user-scalable: yes;
}

/* 禁用自动字体调整 */
html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* iPhone 刘海屏适配 */
@supports (padding-top: env(safe-area-inset-top)) {
  .safe-area-top {
    padding-top: env(safe-area-inset-top);
  }
  
  .safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  .fixed-bottom {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* ============================================
   3. 触摸优化（全局）
   ============================================ */
@media (pointer: coarse) {
  /* 最小触摸目标 44x44px */
  button,
  a,
  .clickable,
  .filter-btn,
  .nav-link,
  .card,
  .polaroid-item,
  .stage-card,
  .resource-card,
  .link-card,
  .feature-card,
  .mode-card {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* 增大点击区域 */
  .official-nav-menu a {
    padding: 12px 16px;
  }
  
  /* 表单元素 */
  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 16px; /* 防止iOS缩放 */
  }
  
  /* 增大按钮内边距 */
  .official-btn,
  .filter-btn,
  .category-filter-btn {
    padding: 12px 24px;
  }
}

/* 触摸反馈效果 */
@media (hover: none) {
  /* 移除hover效果，使用:active代替 */
  .card:hover,
  .official-card:hover,
  .polaroid-item:hover,
  .stage-card:hover,
  .resource-card:hover,
  .link-card:hover,
  .feature-card:hover,
  .mode-card:hover {
    transform: none !important;
  }
  
  /* 触摸时的视觉反馈 */
  .card:active,
  .official-card:active,
  .polaroid-item:active,
  .stage-card:active,
  .resource-card:active,
  .link-card:active,
  .feature-card:active,
  .mode-card:active {
    transform: scale(0.98) !important;
    opacity: 0.9;
  }
  
  /* 触摸反馈波纹效果 */
  .touch-feedback {
    position: relative;
    overflow: hidden;
  }
  
  .touch-feedback::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(255,255,255,0.3) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
  }
  
  .touch-feedback:active::after {
    opacity: 1;
  }
}

/* ============================================
   4. 动画降级与性能优化
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 移动端动画简化 */
@media (pointer: coarse) {
  /* 简化故障艺术效果 */
  .glitch-text,
  .sg-glitch-text {
    animation: none !important;
    text-shadow: 
      2px 0 #00ffff,
      -2px 0 #ff00ff !important;
  }
  
  .glitch-text::before,
  .glitch-text::after,
  .sg-glitch-text::before,
  .sg-glitch-text::after {
    display: none !important;
  }
  
  /* 简化悬停动画 */
  .polaroid-item,
  .stage-card,
  .resource-card,
  .link-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }
  
  /* 禁用复杂背景动画 */
  .ink-blob {
    animation-duration: 30s !important;
  }
  
  /* 减少粒子数量 */
  .particle {
    display: none;
  }
  
  .particle:nth-child(-n+10) {
    display: block;
  }
}

/* ============================================
   5. 移动端底部固定导航栏（可滚动）
   ============================================ */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  background: rgba(15, 15, 26, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 1000;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* 可滚动容器 */
.mobile-bottom-nav-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  scroll-behavior: smooth;
}

.mobile-bottom-nav-scroll::-webkit-scrollbar {
  display: none;
}

.mobile-bottom-nav-inner {
  display: flex;
  align-items: center;
  height: 64px;
  padding: 0 8px;
  min-width: min-content;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 72px;
  height: 100%;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.6);
  transition: all 0.2s ease;
  position: relative;
  gap: 4px;
  padding: 0 4px;
}

.mobile-nav-item .nav-icon {
  font-size: 22px;
  line-height: 1;
  transition: transform 0.2s ease;
}

.mobile-nav-item .nav-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* 活跃状态 */
.mobile-nav-item.active {
  color: var(--highlight-color, #E6007E);
}

.mobile-nav-item.active .nav-icon {
  transform: scale(1.2);
}

/* 活跃指示器 - 墨鱼喷墨效果 */
.mobile-nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 3px;
  background: linear-gradient(90deg, var(--highlight-color, #E6007E), #FF69B4);
  border-radius: 0 0 3px 3px;
  box-shadow: 0 2px 8px rgba(230, 0, 126, 0.6);
  animation: ink-pulse 2s ease-in-out infinite;
}

@keyframes ink-pulse {
  0%, 100% { 
    opacity: 1; 
    box-shadow: 0 2px 8px rgba(230, 0, 126, 0.6);
  }
  50% { 
    opacity: 0.7; 
    box-shadow: 0 2px 12px rgba(230, 0, 126, 0.8);
  }
}

/* 点击反馈 */
.mobile-nav-item:active {
  transform: scale(0.95);
}

/* 滚动提示 */
.mobile-nav-scroll-hint {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 1;
}

.mobile-nav-scroll-hint::before {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid rgba(255, 255, 255, 0.5);
  border-bottom: 2px solid rgba(255, 255, 255, 0.5);
  transform: rotate(-45deg);
  animation: scroll-hint-bounce 1.5s ease-in-out infinite;
}

@keyframes scroll-hint-bounce {
  0%, 100% { transform: rotate(-45deg) translateX(0); }
  50% { transform: rotate(-45deg) translateX(4px); }
}

/* ============================================
   6. 移动端布局适配（< 768px）
   ============================================ */
@media (max-width: 767px) {
  /* 显示底部导航 */
  .mobile-bottom-nav {
    display: block;
  }
  
  /* 主内容区域调整 */
  main {
    padding-top: 0 !important; /* 移除顶部导航栏的padding */
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px) + 20px);
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
  
  /* 容器内边距调整 */
  .container {
    padding-left: 16px;
    padding-right: 16px;
  }
  
  /* 隐藏顶部导航栏 - 使用底部导航替代 */
  .official-nav {
    display: none !important;
  }
  
  /* 为顶部留出安全区域 */
  body {
    padding-top: env(safe-area-inset-top, 0px);
  }
  
  
  
  /* Hero区域字体调整 */
  .hero-title,
  .intro-hero h1,
  .music-hero h1,
  .gathering-hero h1,
  .stages-hero h1,
  .resources-hero h1,
  .extras-hero h1 {
    font-size: clamp(28px, 8vw, 40px) !important;
    line-height: 1.2;
  }
  
  .hero-subtitle,
  .intro-hero p,
  .music-hero p,
  .gathering-hero p,
  .stages-hero p,
  .resources-hero p,
  .extras-hero p {
    font-size: clamp(14px, 4vw, 18px) !important;
  }
  
  /* Section标题调整 */
  .section-title {
    font-size: clamp(28px, 7vw, 40px) !important;
    letter-spacing: 1px;
  }
  
  .section-subtitle {
    font-size: clamp(13px, 3.5vw, 16px) !important;
  }
  
  /* 快速导航按钮调整 */
  .intro-quick-nav,
  .music-quick-nav,
  .gathering-quick-nav,
  .stages-quick-nav,
  .resources-quick-nav,
  .extras-quick-nav {
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }
  
  .intro-quick-nav a,
  .music-quick-nav a,
  .gathering-quick-nav a,
  .stages-quick-nav a,
  .resources-quick-nav a,
  .extras-quick-nav a {
    width: 100%;
    max-width: 280px;
    text-align: center;
    padding: 12px 20px;
    font-size: 14px;
  }
  
  /* 网格布局改为单列 */
  .quick-entry-grid,
  .grid.grid-2,
  .grid.grid-3,
  .grid.grid-4,
  .feature-cards,
  .mode-cards,
  .game-modes-grid,
  .ranked-modes-grid,
  .boss-grid,
  .tips-cards {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }
  
  /* 资源卡片网格 */
  .resources-grid,
  .links-grid {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }
  
  /* 作品网格 */
  .works-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px;
  }
  
  /* 拍立得画廊单列布局 */
  .polaroid-grid {
    gap: 16px;
    padding: 16px 8px;
  }
  
  .polaroid-item {
    width: 100% !important;
    max-width: 100%;
    margin: 0 auto;
  }
  
  /* 地图网格 */
  .stages-grid {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }
  
  /* 表格横向滚动 */
  .awards-table,
  .platform-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  
  /* 筛选按钮横向滚动 */
  .resources-filters,
  .links-filters,
  .music-category-filters,
  .stages-category-filters,
  .polaroid-filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding-bottom: 8px;
    scrollbar-width: none;
  }
  
  .resources-filters::-webkit-scrollbar,
  .links-filters::-webkit-scrollbar,
  .music-category-filters::-webkit-scrollbar,
  .stages-category-filters::-webkit-scrollbar,
  .polaroid-filters::-webkit-scrollbar {
    display: none;
  }
  
  .filter-btn,
  .category-filter-btn {
    flex-shrink: 0;
    padding: 10px 16px;
    font-size: 13px;
  }
  
  /* 灯箱全屏优化 */
  .polaroid-lightbox-content {
    max-width: 100vw;
    max-height: 100vh;
    margin: 0;
    border-radius: 0;
  }
  
  .polaroid-lightbox-nav {
    width: 48px;
    height: 48px;
  }
  
  .polaroid-lightbox-prev {
    left: 8px;
  }
  
  .polaroid-lightbox-next {
    right: 8px;
  }
  
  /* 音乐播放器移动端优化 */
  .music-player-container {
    position: fixed;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    left: 0;
    right: 0;
    z-index: 998;
  }
  
  .music-player-bar {
    border-radius: 12px 12px 0 0;
    margin: 0;
  }
  
  /* 卡片内边距调整 */
  .card,
  .official-card,
  .intro-card,
  .extras-card,
  .feature-card,
  .mode-card,
  .game-mode-card,
  .ranked-mode-card,
  .boss-card,
  .tip-card {
    padding: 20px;
  }
  
  /* 聚会信息卡片 */
  .gathering-info-card {
    padding: 20px;
  }
  
  .gathering-activities {
    flex-direction: column;
    gap: 8px;
  }
  
  .activity-tag {
    width: 100%;
    justify-content: center;
  }
  
  /* 联系信息卡片 */
  .contact-item {
    flex-direction: column;
    text-align: center;
    gap: 8px;
  }
  
  .contact-icon {
    font-size: 28px;
  }
}

/* ============================================
   7. 平板适配（768px - 1024px）
   ============================================ */
@media (min-width: 768px) and (max-width: 1024px) {
  /* 双列布局 */
  .quick-entry-grid,
  .grid.grid-2,
  .grid.grid-3,
  .grid.grid-4,
  .feature-cards,
  .mode-cards,
  .game-modes-grid,
  .ranked-modes-grid,
  .tips-cards {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  /* 地图网格双列 */
  .stages-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  /* 资源网格双列 */
  .resources-grid,
  .links-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  /* Boss网格三列 */
  .boss-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
  
  /* 作品网格三列 */
  .works-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

/* ============================================
   8. iOS 特定修复
   ============================================ */
@supports (-webkit-touch-callout: none) {
  body {
    -webkit-overflow-scrolling: touch;
  }
  
  /* 修复 fixed 定位在键盘弹出时的问题 */
  .fixed-element {
    position: -webkit-sticky;
    position: sticky;
  }
  
  /* 修复 100vh 问题 */
  .full-height {
    height: -webkit-fill-available;
    height: 100vh;
  }
}

/* iOS 底部导航栏适配 */
@supports (-webkit-touch-callout: none) {
  .ios-bottom-bar {
    padding-bottom: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  
  .mobile-bottom-nav {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
}

/* ============================================
   9. Android 特定修复
   ============================================ */
@supports not (-webkit-touch-callout: none) {
  /* Android 隐藏滚动条但保持滚动 */
  .hide-scrollbar {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  
  .hide-scrollbar::-webkit-scrollbar {
    display: none;
  }
}

/* ============================================
   10. 输入法适配
   ============================================ */
.keyboard-open .fixed-bottom {
  position: absolute;
}

input:focus,
textarea:focus {
  scroll-margin-top: 100px;
}

/* ============================================
   11. GPU 加速优化
   ============================================ */
.gpu-accelerated {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

.animated {
  will-change: transform, opacity;
}

.animation-complete {
  will-change: auto;
}

/* ============================================
   12. 字体优化
   ============================================ */
@media (max-width: 375px) {
  html {
    font-size: 14px;
  }
}

@media (min-width: 376px) and (max-width: 767px) {
  html {
    font-size: 15px;
  }
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ============================================
   13. 内容可见性优化
   ============================================ */
.content-visibility {
  content-visibility: auto;
  contain-intrinsic-size: 0 500px;
}

/* 图片懒加载占位 */
.lazy-image {
  background: linear-gradient(90deg, 
    rgba(255,255,255,0.05) 25%, 
    rgba(255,255,255,0.1) 50%, 
    rgba(255,255,255,0.05) 75%
  );
  background-size: 200% 100%;
}

.lazy-image.loaded {
  background: none;
}

/* 避免布局抖动 */
.aspect-ratio-box {
  position: relative;
}

.aspect-ratio-box::before {
  content: '';
  display: block;
  padding-top: var(--aspect-ratio, 56.25%);
}

.aspect-ratio-box > * {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ============================================
   14. 横屏适配
   ============================================ */
@media (max-width: 767px) and (orientation: landscape) {
  /* 横屏时隐藏底部导航 */
  .mobile-bottom-nav {
    display: none;
  }
  
  main {
    padding-bottom: 20px;
  }
  
  /* 恢复部分网格布局 */
  .works-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .boss-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  
  /* Hero区域字体调整 */
  .hero-title,
  .intro-hero h1,
  .music-hero h1,
  .gathering-hero h1,
  .stages-hero h1,
  .resources-hero h1,
  .extras-hero h1 {
    font-size: clamp(24px, 6vw, 32px) !important;
  }
}

/* ============================================
   15. 低性能设备优化
   ============================================ */
.performance-low {
  .neon-grid-advanced::before {
    animation: none !important;
  }
  
  .ink-blob {
    animation: none !important;
  }
  
  .glitch-text {
    animation: none !important;
  }
  
  .card,
  .official-card {
    box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
  }
}

/* ============================================
   16. 手势滑动支持
   ============================================ */
.swipe-container {
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  display: flex;
  gap: 16px;
  padding: 8px 16px;
}

.swipe-container::-webkit-scrollbar {
  display: none;
}

.swipe-item {
  scroll-snap-align: start;
  flex-shrink: 0;
  width: 85%;
  max-width: 340px;
}

/* 音乐列表磁带滚动效果 */
.tape-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tape-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: rgba(15, 20, 35, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  gap: 12px;
}

.tape-item:active {
  transform: scale(0.98);
  background: rgba(230, 0, 126, 0.1);
}

.tape-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(230, 0, 126, 0.2);
  border-radius: 8px;
  font-size: 18px;
}

.tape-info {
  flex: 1;
  min-width: 0;
}

.tape-title {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tape-meta {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

.tape-arrow {
  color: rgba(255, 255, 255, 0.4);
  font-size: 18px;
}

/* ============================================
   17. 可折叠手风琴（用于资源卡片）
   ============================================ */
.accordion-item {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  margin-bottom: 8px;
  overflow: hidden;
}

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: rgba(15, 20, 35, 0.9);
  cursor: pointer;
  transition: background 0.2s;
}

.accordion-header:active {
  background: rgba(230, 0, 126, 0.1);
}

.accordion-header h4 {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  margin: 0;
}

.accordion-icon {
  transition: transform 0.3s ease;
  color: rgba(255, 255, 255, 0.6);
}

.accordion-item.open .accordion-icon {
  transform: rotate(180deg);
}

.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  background: rgba(15, 20, 35, 0.7);
}

.accordion-item.open .accordion-content {
  max-height: 500px;
}

.accordion-body {
  padding: 16px;
}

/* ============================================
   18. 图片画廊移动端优化
   ============================================ */
.gallery-scroll-container {
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  display: flex;
  gap: 12px;
  padding: 8px 0;
}

.gallery-scroll-container::-webkit-scrollbar {
  display: none;
}

.gallery-scroll-item {
  scroll-snap-align: center;
  flex-shrink: 0;
  width: 90vw;
  max-width: 400px;
}

.gallery-scroll-item img {
  width: 100%;
  height: auto;
  border-radius: 12px;
  pointer-events: none; /* 防止长按弹出菜单 */
  -webkit-user-drag: none;
}

/* 横向滚动指示器 */
.scroll-indicator {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 12px;
}

.scroll-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transition: all 0.3s ease;
}

.scroll-dot.active {
  width: 20px;
  border-radius: 3px;
  background: #E6007E;
}

/* ============================================
   19. 页面特定的移动端隐藏/显示
   ============================================ */
@media (max-width: 767px) {
  /* 隐藏桌面端特定元素 */
  .desktop-only {
    display: none !important;
  }
  
  /* 显示移动端特定元素 */
  .mobile-only {
    display: block !important;
  }
  
  /* 调整间距 */
  .section {
    padding: 40px 0;
  }
  
  .section-header {
    margin-bottom: 24px;
  }
  
  /* 减小页脚内边距 */
  .official-footer {
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
}

@media (min-width: 768px) {
  .mobile-only {
    display: none !important;
  }
}

/* ============================================
   20. 打印样式
   ============================================ */
@media print {
  .mobile-bottom-nav,
  .menu-toggle,
  .music-player-container {
    display: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
}
