/* =====================================================
   移动端导航栏设计 - 遮罩层模式
   版本: v4.0
   设计理念: 
   - 点击后显示全屏半透明遮罩层
   - 导航菜单在遮罩层上渲染
   - 居中或顶部卡片式布局
   - 流畅的淡入动画
   ===================================================== */

/* =====================================================
   移动端导航栏设计 - 遮罩层模式
   版本: v4.1
   设计理念: 
   - 点击后显示全屏半透明遮罩层
   - 导航菜单在遮罩层上渲染
   - 居中或顶部卡片式布局
   - 流畅的淡入动画
   
   页面层级结构（从底层到顶层）：
   1. 页面内容和页脚 - z-index: 0（默认，最底层）
   2. 遮罩层 - z-index: 9998（中间层，毛玻璃半透明）
   3. 菜单按钮内容 - z-index: 9999（上层，在遮罩层上）
   4. 导航栏和汉堡按钮 - z-index: 10000-10001（最上层）
   ===================================================== */

/* ===== 1. 移动端菜单按钮（汉堡图标） ===== */
/* 层级：导航栏(10000) < 汉堡按钮(10001) */
.mobile-menu-toggle {
  display: none;
  position: relative;
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  cursor: pointer;
  padding: 0;
  margin: 0;
  z-index: 10001 !important; /* 确保在导航栏上方 */
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  flex-shrink: 0;
  box-sizing: border-box;
}

.mobile-menu-toggle:active {
  transform: scale(0.95);
  background: rgba(168, 85, 247, 0.15);
}

.mobile-menu-toggle.active {
  background: rgba(168, 85, 247, 0.2);
  border-color: rgba(168, 85, 247, 0.4);
}

.mobile-menu-toggle span {
  display: block;
  width: 22px;
  height: 2.5px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 2px;
  transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  transform-origin: center;
}

.mobile-menu-toggle.active span {
  background: rgba(255, 255, 255, 1);
}

.mobile-menu-toggle.active span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.mobile-menu-toggle.active span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}

.mobile-menu-toggle.active span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ===== 2. 移动端导航遮罩层（全屏半透明毛玻璃） ===== */
/* 层级：页面内容和页脚(0) < 遮罩层(9998) < 菜单按钮(9999) < 导航栏(10000) */
.mobile-nav-overlay {
  display: block !important; /* 预加载，始终存在DOM中 */
  position: fixed !important;
  /* 从导航栏下方开始，覆盖整个视口 */
  top: var(--nav-height, 64px) !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  /* 确保覆盖整个视口和滚动区域 */
  width: 100vw !important;
  min-height: calc(100vh - var(--nav-height, 64px)) !important;
  height: calc(100vh - var(--nav-height, 64px)) !important;
  max-height: calc(100vh - var(--nav-height, 64px)) !important;
  /* 毛玻璃半透明效果 - 覆盖页面内容和页脚，提高不透明度 */
  background: rgba(0, 0, 0, 0.8) !important;
  backdrop-filter: blur(40px) saturate(200%) !important;
  -webkit-backdrop-filter: blur(40px) saturate(200%) !important;
  z-index: 9998 !important; /* 在页面内容和页脚上方，但在导航栏下方 */
  opacity: 0 !important;
  /* 优化动画：使用transform和opacity，GPU加速 */
  transform: translateZ(0) scale(1); /* 强制GPU加速 */
  /* 优化：使用更平滑的缓动函数，增加动画时长 */
  transition: opacity 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
  pointer-events: none !important;
  will-change: opacity, transform;
  /* 添加触感反馈 */
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  visibility: hidden !important;
  /* 确保覆盖所有内容，包括滚动区域 */
  overflow: hidden !important;
  contain: layout style paint !important;
  /* GPU加速优化 */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  perspective: 1000px;
  -webkit-perspective: 1000px;
}

.mobile-nav-overlay.active {
  display: block !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  visibility: visible !important;
  /* 优化动画：直接使用transition，不使用animation */
  transform: translateZ(0) scale(1); /* GPU加速 */
  /* 确保激活时完全覆盖 */
  width: 100vw !important;
  min-height: calc(100vh - var(--nav-height, 64px)) !important;
  height: calc(100vh - var(--nav-height, 64px)) !important;
  max-height: calc(100vh - var(--nav-height, 64px)) !important;
  left: 0 !important;
  right: 0 !important;
  top: var(--nav-height, 64px) !important;
  bottom: 0 !important;
}

/* ===== 3. 移动端导航菜单（在遮罩层上渲染）- 无卡片，直接显示按钮 ===== */
/* 层级：遮罩层(9998) < 菜单按钮内容(9999) < 导航栏(10000) < 汉堡按钮(10001) */
.mobile-nav {
  display: flex !important; /* 预加载，始终存在DOM中 */
  position: fixed;
  /* 菜单在遮罩层可用区域内垂直居中 */
  /* 计算公式：导航栏高度 + (视口高度 - 导航栏高度) / 2 = 50vh + 导航栏高度 / 2 */
  top: calc(50vh + var(--nav-height, 64px) / 2);
  left: 50%;
  /* 优化：初始状态更隐蔽，使用translateY向下偏移，增加淡入效果 */
  transform: translate(-50%, -40%) translateZ(0) scale(0.9); /* GPU加速，初始缩放更小，向下偏移 */
  width: min(85%, 380px);
  max-width: 380px;
  /* 完全透明，无卡片样式 */
  background: none !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  z-index: 9999 !important; /* 在遮罩层上方，但在导航栏下方 */
  opacity: 0;
  visibility: hidden;
  overflow: visible !important;
  will-change: opacity, transform;
  /* 优化：使用更平滑的缓动函数，增加动画时长 */
  transition: opacity 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              visibility 0.4s ease;
  box-sizing: border-box;
  padding: 0 !important;
  margin: 0;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 16px;
  /* GPU加速优化 */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  perspective: 1000px;
  -webkit-perspective: 1000px;
}

.mobile-nav * {
  box-sizing: border-box;
}

.mobile-nav.active {
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
  /* 确保菜单在遮罩层可用区域内垂直居中 */
  top: calc(50vh + var(--nav-height, 64px) / 2) !important;
  left: 50% !important;
  /* 优化：平滑的缩放和位置动画，从下方轻微上浮 */
  transform: translate(-50%, -50%) translateZ(0) scale(1) !important; /* 平滑缩放动画 */
  pointer-events: auto !important;
  /* 优化：移除will-change以节省资源 */
  will-change: auto;
}

/* ===== 4. 移动端菜单内容容器 - 无padding，按钮直接显示 ===== */
.mobile-nav-content {
  display: flex !important;
  flex-direction: column;
  align-items: stretch !important;
  justify-content: center !important;
  padding: 0 !important;
  gap: 16px !important;
  opacity: 1 !important;
  visibility: visible !important;
  width: 100% !important;
  box-sizing: border-box;
  position: relative;
  z-index: 1;
}

/* ===== 5. 移动端菜单项 - 直接显示在遮罩层上 ===== */
.mobile-nav-link {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
  padding: 20px 28px !important;
  color: rgba(255, 255, 255, 1) !important;
  text-decoration: none !important;
  font-size: 18px !important;
  font-weight: 600 !important;
  border-radius: 20px !important;
  transition: background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative !important;
  -webkit-tap-highlight-color: transparent;
  height: 72px !important;
  min-height: 72px !important;
  background: rgba(255, 255, 255, 0.2) !important;
  backdrop-filter: blur(20px) saturate(200%) !important;
  -webkit-backdrop-filter: blur(20px) saturate(200%) !important;
  border: 2px solid rgba(255, 255, 255, 0.35) !important;
  width: 100% !important;
  /* 菜单项始终可见，避免闪烁 */
  opacity: 1 !important;
  visibility: visible !important;
  transform: translateY(0) translateZ(0) !important; /* 确保transform稳定 */
  margin: 0 !important;
  overflow: visible !important;
  will-change: transform, background-color;
  z-index: 2;
  line-height: 1.5;
  white-space: nowrap;
  box-shadow: 
    0 8px 24px rgba(0, 0, 0, 0.5),
    0 4px 16px rgba(168, 85, 247, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 0 40px rgba(168, 85, 247, 0.2) !important;
}

/* 菜单项动画已移除，避免重复打开时的闪烁 */
/* 菜单项始终可见，只通过菜单容器的opacity控制显示 */

/* 悬停和激活效果 - 增强版 */
.mobile-nav-link:hover,
.mobile-nav-link:focus {
  background: rgba(168, 85, 247, 0.35) !important;
  backdrop-filter: blur(24px) saturate(200%) !important;
  -webkit-backdrop-filter: blur(24px) saturate(200%) !important;
  color: rgba(255, 255, 255, 1) !important;
  border-color: rgba(168, 85, 247, 0.7) !important;
  transform: translateY(-2px);
  outline: none;
  box-shadow: 
    0 12px 32px rgba(0, 0, 0, 0.6),
    0 6px 20px rgba(168, 85, 247, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 0 50px rgba(168, 85, 247, 0.3) !important;
}

.mobile-nav-link:active {
  background: rgba(168, 85, 247, 0.4) !important;
  transform: scale(0.98) translateY(0);
  color: rgba(255, 255, 255, 1) !important;
  box-shadow: 
    0 4px 16px rgba(0, 0, 0, 0.5),
    0 2px 8px rgba(168, 85, 247, 0.35),
    inset 0 2px 4px rgba(0, 0, 0, 0.2) !important;
}

.mobile-nav-link.active {
  color: rgba(255, 255, 255, 1) !important;
  background: rgba(168, 85, 247, 0.4) !important;
  backdrop-filter: blur(24px) saturate(200%) !important;
  -webkit-backdrop-filter: blur(24px) saturate(200%) !important;
  border-color: rgba(168, 85, 247, 0.8) !important;
  font-weight: 600;
  box-shadow: 
    0 8px 24px rgba(168, 85, 247, 0.4),
    0 4px 16px rgba(168, 85, 247, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 0 50px rgba(168, 85, 247, 0.3) !important;
}

/* 外部链接图标 - 已移除箭头 */

/* ===== 6. 菜单项分隔线 ===== */
.mobile-nav-divider {
  height: 1px;
  background: linear-gradient(90deg, 
    transparent 0%,
    rgba(255, 255, 255, 0.1) 50%,
    transparent 100%);
  margin: 0.75rem 0;
}

/* ===== 7. 移动端菜单底部区域 ===== */
.mobile-nav-footer {
  margin-top: 1rem;
  padding: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.mobile-nav-footer p {
  font-size: 0.875rem;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
  margin: 0;
}

/* ===== 8. 移动端专用样式 ===== */
@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex !important;
  }

  .mobile-nav-overlay {
    display: block !important;
  }

  .mobile-nav {
    display: flex !important; /* 修复：使用flex而不是block */
  }

  .mobile-nav:not(.active) {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    /* 不移除display，保持flex布局 */
  }

  .mobile-nav.active {
    display: flex !important; /* 修复：使用flex而不是block */
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  .desktop-nav {
    display: none !important;
  }
}

/* ===== 9. 菜单打开时的body锁定 ===== */
body.mobile-nav-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
  -webkit-overflow-scrolling: touch;
}

/* 确保菜单打开时，所有页面内容都在遮罩层下方 */
body.mobile-nav-open main,
body.mobile-nav-open footer,
body.mobile-nav-open section,
body.mobile-nav-open article,
body.mobile-nav-open div:not(.mobile-nav):not(.mobile-nav-overlay):not(.navbar):not(.mobile-menu-toggle) {
  position: relative;
  z-index: 0 !important; /* 确保在遮罩层下方 */
}

/* iOS Safari 特殊处理 */
@supports (-webkit-touch-callout: none) {
  body.mobile-nav-open {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
  }
}

/* ===== 10. 触摸优化 ===== */
@media (pointer: coarse) {
  .mobile-nav-link {
    min-height: 56px;
    padding: 1.25rem 1.5rem;
  }

  .mobile-menu-toggle {
    min-width: 48px;
    min-height: 48px;
  }

  /* 增强触摸反馈 */
  .mobile-nav-link:active {
    background: rgba(139, 92, 246, 0.35) !important;
  }
}

/* ===== 11. 小屏幕优化 ===== */
@media (max-width: 480px) {
  .mobile-nav {
    width: 92%;
    max-width: 360px;
    border-radius: 20px;
  }

  .mobile-nav-content {
    padding: 1.5rem 1.25rem;
  }

  .mobile-nav-link {
    font-size: 1rem;
    padding: 1rem 1.25rem;
    min-height: 52px;
    border-radius: 14px;
  }

  .mobile-menu-toggle {
    width: 44px;
    height: 44px;
  }
}

/* ===== 12. 横屏优化 ===== */
@media (orientation: landscape) and (max-height: 500px) {
  .mobile-nav {
    top: calc(45vh + var(--nav-height, 64px) / 2) !important;
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .mobile-nav.active {
    top: calc(45vh + var(--nav-height, 64px) / 2) !important;
  }

  .mobile-nav-content {
    padding: 1.25rem 1.5rem;
    gap: 0.5rem;
  }

  .mobile-nav-link {
    min-height: 48px;
    padding: 0.875rem 1.25rem;
    font-size: 0.9375rem;
  }
}

/* ===== 13. 高对比度模式支持 ===== */
@media (prefers-contrast: high) {
  .mobile-nav-link {
    border: 1px solid rgba(255, 255, 255, 0.2);
  }

  .mobile-nav-link.active {
    border-color: rgba(139, 92, 246, 0.6);
  }
}

/* ===== 14. 减少动画模式支持 ===== */
@media (prefers-reduced-motion: reduce) {
  .mobile-nav,
  .mobile-nav-link,
  .mobile-menu-toggle,
  .mobile-nav-overlay {
    animation: none !important;
    transition: none !important;
  }

  .mobile-nav.active {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

/* ===== 15. 性能优化 ===== */
/* GPU加速优化已在遮罩层和菜单的基础样式中定义 */

/* 确保菜单内容始终可见 */
.mobile-nav .mobile-nav-content,
.mobile-nav .mobile-nav-link {
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
  color: #ffffff !important;
  transform: translateY(0) translateZ(0) !important; /* 确保transform稳定，避免闪烁 */
}

/* 强制覆盖可能的冲突样式 */
@media (max-width: 768px) {
  .mobile-nav {
    display: flex !important; /* 预加载，始终存在 */
  }
  
  .mobile-nav.active {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  .mobile-nav.active .mobile-nav-content {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  .mobile-nav.active .mobile-nav-link {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    color: #ffffff !important;
  }
}

/* ===== 16. 焦点可见性 ===== */
.mobile-menu-toggle:focus-visible {
  outline: 2px solid rgba(139, 92, 246, 0.8);
  outline-offset: 2px;
}

.mobile-nav-link:focus-visible {
  outline: 2px solid rgba(139, 92, 246, 0.8);
  outline-offset: 2px;
  border-radius: 16px;
}
