/* 移动端性能优化CSS - 专门解决PageSpeed Insights问题 */

/* 1. 防止CLS的基础设置 */
* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  line-height: 1.4;
  overflow-x: hidden;
}

/* 2. 图片优化 - 防止CLS */
img {
  max-width: 100%;
  height: auto;
  display: block;
  /* 为所有图片设置默认宽高比 */
  aspect-ratio: 16/9;
}

img[width][height] {
  aspect-ratio: attr(width) / attr(height);
}

/* 图片加载占位符 */
img:not([src]) {
  background: #f0f0f0;
  border: 1px solid #ddd;
}

/* 3. 容器固定尺寸 - 防止CLS */
.container {
  max-width: 100%;
  margin: 0 auto;
  padding: 0 15px;
}

/* 头部固定高度 */
header,
.header {
  height: 60px !important; /* 移动端较小高度 */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* 主内容区域 */
main,
.main-content {
  margin-top: 60px; /* 为固定头部留出空间 */
  min-height: calc(100vh - 60px);
}

/* 4. 首屏内容优化 - 改善LCP */
.hero,
.banner,
.hero-banner {
  height: 300px !important; /* 移动端较小高度 */
  background: linear-gradient(135deg, #2E7135 0%, #4CAF50 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: white;
  /* 确保首屏内容立即可见 */
  content-visibility: visible;
  contain-intrinsic-size: 300px;
}

.hero-content {
  padding: 20px 15px;
  max-width: 100%;
}

.hero-title {
  font-size: 1.8rem;
  font-weight: 700;
  margin: 0 0 15px 0;
  line-height: 1.2;
}

.hero-subtitle {
  font-size: 1rem;
  margin: 0 0 20px 0;
  opacity: 0.9;
}

/* 5. 按钮和交互元素 */
.btn {
  display: inline-block;
  padding: 12px 24px;
  background: #fff;
  color: #2E7135;
  text-decoration: none;
  border-radius: 4px;
  font-weight: 600;
  border: 2px solid transparent;
  /* 防止按钮导致的布局偏移 */
  min-height: 44px;
  min-width: 120px;
  text-align: center;
}

/* 6. 网格和布局 - 防止CLS */
.grid {
  display: grid;
  gap: 15px;
  grid-template-columns: 1fr; /* 移动端单列布局 */
}

.card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  overflow: hidden;
  /* 固定最小高度防止CLS */
  min-height: 250px;
}

.card-image {
  width: 100%;
  height: 150px;
  object-fit: cover;
  background: #f5f5f5;
}

.card-content {
  padding: 15px;
  min-height: 100px; /* 防止内容变化导致的CLS */
}

/* 7. 加载状态和占位符 */
.loading,
.placeholder {
  min-height: 200px;
  background: #f8f9fa;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6c757d;
}

.loading::after {
  content: '';
  width: 30px;
  height: 30px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid #2E7135;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 8. 字体优化 - 防止FOIT/FOUT */
@font-face {
  font-family: 'OptimizedFont';
  src: url('/static/fonts/main.woff2') format('woff2');
  font-display: swap; /* 立即显示后备字体 */
  font-weight: 400;
  font-style: normal;
}

/* 9. 第三方内容容器 */
.ad-container,
.widget-container {
  min-height: 100px;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 4px;
}

/* 10. 性能优化的可见性控制 */
.above-fold {
  content-visibility: visible;
}

.below-fold {
  content-visibility: auto;
  contain-intrinsic-size: 200px;
}

/* 11. 移动端特殊优化 */
@media (max-width: 768px) {
  /* 减少不必要的阴影和效果 */
  .card {
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  }
  
  /* 优化触摸目标大小 */
  button,
  .btn,
  a {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* 减少动画以提升性能 */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 12. 关键路径CSS内联优化 */
.critical-content {
  /* 确保关键内容立即渲染 */
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* 13. 预加载状态 */
.preload-image {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
} 