/*
 * 光影集 H5 跨平台 CSS 兼容性补丁
 * 目标: 确保在 Chrome 60+, Edge 79+, Firefox 55+, Safari 12+, Android 5+ 上正常渲染
 * 
 * 本文件包含:
 * 1. CSS 变量降级方案
 * 2. Flexbox 兼容性
 * 3. Grid 降级方案
 * 4. backdrop-filter 降级
 * 5. 移动端特殊优化
 */

/* ============ 1. CSS 变量降级 ============ */
/* 为不支持 CSS 变量的旧浏览器提供 fallback */

@supports not (--test: 0) {
  /* 旧浏览器直接使用硬编码值 */
  .topbar {
    background: rgba(255, 255, 255, 0.82);
  }
  .brand-dot {
    background: linear-gradient(135deg, #6366f1, #8b5cf6 50%, #ec4899);
  }
  .brand-name {
    color: #6366f1;
  }
  .search:focus {
    border-color: #6366f1;
  }
  .btn-primary {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
  }
  .badge-admin {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
  }
  .tag-item.active {
    background: #6366f1;
    color: #fff;
  }
  .photo-item .photo-overlay {
    background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
  }
}

/* ============ 2. backdrop-filter 降级 ============ */
/* 不支持 backdrop-filter 的浏览器使用半透明背景 */
@supports not ((backdrop-filter: blur(14px)) or (-webkit-backdrop-filter: blur(14px))) {
  .topbar {
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  }
  
  .modal-mask {
    background: rgba(0, 0, 0, 0.5);
  }
  
  .photo-item .photo-overlay {
    background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
  }
}

/* ============ 3. CSS Grid 降级 ============ */
/* 不支持 CSS Grid 的浏览器使用 Flexbox */
@supports not (display: grid) {
  .photo-grid {
    display: flex !important;
    flex-wrap: wrap;
    gap: 12px;
  }
  
  .photo-grid .photo-item,
  .photo-grid .photo-add {
    width: calc(33.333% - 8px);
    margin: 0;
  }
  
  .photo-grid.full {
    display: flex !important;
  }
  
  @media (max-width: 600px) {
    .photo-grid .photo-item,
    .photo-grid .photo-add {
      width: calc(50% - 6px);
    }
  }
}

/* ============ 4. Flexbox 兼容性 ============ */
/* 为旧版浏览器添加 Flexbox 前缀 */

.flex-fallback {
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
}

.flex-center {
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
}

/* ============ 5. sticky 定位降级 ============ */
@supports not (position: sticky) {
  .topbar {
    position: fixed;
    top: 0;
  }
  .wall-wrap {
    padding-top: 64px;
  }
}

/* ============ 6. 移动端优化 ============ */

/* 防止 iOS Safari 缩放 */
@supports (-webkit-touch-callout: none) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
}

/* 移动端触摸优化 */
@media (hover: none) {
  .btn-primary,
  .btn-ghost,
  .btn-danger,
  .photo-item,
  .tag-item,
  .modal-close,
  .user-area,
  .tag-manage-btn,
  #adminBtn,
  #exportBtn,
  #uploadBtn {
    min-height: 44px;
    min-width: 44px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  
  /* 移动端降低动画复杂度 */
  .btn-primary,
  .btn-ghost,
  .btn-danger {
    transition: background-color 0.15s ease;
  }
  
  .photo-item:hover .photo-overlay {
    opacity: 0;
  }
  
  .photo-item:active .photo-overlay {
    opacity: 1;
  }
}

/* ============ 7. 图片加载优化 ============ */

img {
  -webkit-user-drag: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* 图片占位符 - 防止布局抖动 */
img[loading] {
  background: #f0f0f0;
}

/* ============ 8. 安全区域适配（刘海屏等） ============ */
@supports (padding: max(0px)) {
  .topbar {
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
  }
  
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ============ 9. 减少动画偏好 ============ */
@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;
  }
}

/* ============ 10. 打印样式 ============ */
@media print {
  .topbar,
  .tag-bar-wrap,
  .user-area,
  .actions {
    display: none !important;
  }
  
  body {
    background: #fff;
  }
}

/* ============ 11. 高对比度模式支持 ============ */
@media (prefers-contrast: high) {
  :root {
    --border: #000;
    --text: #000;
    --text-muted: #333;
  }
  
  .btn-primary {
    border: 2px solid #000;
  }
}

/* ============ 12. 深色模式支持 ============ */
@media (prefers-color-scheme: dark) {
  /* 可选的深色模式支持 */
  /* 当前保持明亮主题，可后续扩展 */
}
