/* ========================================
   Performance Optimization CSS
   ======================================== */

/* 🚀 Critical CSS Optimization */

/* 1. GPU 가속 활성화 */
.gpu-accelerated {
  transform: translateZ(0);
  will-change: transform;
}

.smooth-scroll {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* 2. 레이아웃 쉬프트 방지 */
.prevent-layout-shift {
  contain: layout;
}

/* 이미지 placeholder - 로딩 전 공간 확보 */
.image-placeholder {
  aspect-ratio: 16 / 9;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

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

/* 3. 폰트 로딩 최적화 */
@font-face {
  font-family: 'OptimizedFont';
  src: url("/fonts/font.woff2") format('woff2');
  font-display: swap; /* 폰트 로딩 중 시스템 폰트 표시 */
}

/* 4. 애니메이션 최적화 - transform과 opacity만 사용 */
.optimized-animation {
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* ❌ 피해야 할 속성들 (리플로우 유발)
   - width, height, margin, padding
   - top, left, right, bottom
   - font-size, border-width
*/

/* 5. 스크롤 성능 최적화 */
.scroll-container {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* 6. 렌더링 최적화 */
.render-optimized {
  contain: content; /* 내부 변경이 외부에 영향 안 줌 */
}

/* 7. 모바일 터치 최적화 */
.touch-optimized {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* 더블탭 줌 방지 */
}

/* 8. Chart.js 컨테이너 최적화 */
.chart-container {
  position: relative;
  width: 100%;
  max-width: 100%;
  contain: layout style paint;
}

.chart-container canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

/* 9. 테이블 성능 최적화 */
.optimized-table {
  table-layout: fixed; /* 빠른 렌더링 */
  width: 100%;
}

/* 10. 모바일 성능 최적화 */
@media (max-width: 768px) {
  /* 불필요한 애니메이션 제거 */
  * {
    animation-duration: 0s !important;
    transition-duration: 0s !important;
  }

  /* 중요한 인터랙션만 애니메이션 허용 */
  button, a, .interactive {
    animation-duration: initial !important;
    transition-duration: 0.2s !important;
  }
}

/* 11. Lazy Loading 스타일 */
.lazy-load {
  opacity: 0;
  transition: opacity 0.3s;
}

.lazy-load.loaded {
  opacity: 1;
}

/* 12. Critical CSS - Above the Fold */
.above-fold {
  /* 첫 화면에 보이는 콘텐츠 */
  display: block;
}

.below-fold {
  /* 스크롤 후 보이는 콘텐츠 - lazy load */
  content-visibility: auto;
  contain-intrinsic-size: 500px; /* 예상 높이 */
}

/* 13. 성능 모니터링 */
.performance-debug {
  outline: 1px solid red;
}

.performance-debug * {
  outline: 1px solid blue;
}

/* 14. 리소스 힌트 활용 */
/*
  HTML에서 사용:
  <link rel="preconnect" href="https://cdn.jsdelivr.net">
  <link rel="dns-prefetch" href="https://cdn.jsdelivr.net">
  <link rel="preload" href="/critical.css" as="style">
*/

/* ========================================
   모바일 성능 우선 최적화
   ======================================== */

/* 15. 터치 스크롤 최적화 */
@media (hover: none) and (pointer: coarse) {
  /* 모바일 디바이스 전용 */
  body {
    -webkit-overflow-scrolling: touch;
  }

  /* 터치 영역 확대 */
  button, a, input, select {
    min-height: 44px;
    min-width: 44px;
  }
}

/* 16. 네트워크 성능 최적화 */
@media (prefers-reduced-data: reduce) {
  /* 데이터 절약 모드 */
  * {
    background-image: none !important;
  }
}

/* 17. 배터리 절약 모드 */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* ========================================
   Android 기기별 최적화
   ======================================== */

/* 저사양 기기 (2GB RAM 이하) */
@media (max-width: 768px) and (max-resolution: 2dppx) {
  .heavy-animation {
    animation: none;
  }

  .complex-shadow {
    box-shadow: none;
  }

  .blur-effect {
    backdrop-filter: none;
  }
}

/* 중간 사양 기기 */
@media (min-width: 768px) and (max-width: 1024px) {
  .chart-container {
    max-height: 400px;
  }
}

/* 고사양 기기 (플래그십) */
@media (min-width: 1024px) and (min-resolution: 3dppx) {
  /* 고급 효과 허용 */
  .enhanced-visual {
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
  }
}

/* ========================================
   Chrome DevTools 성능 측정 가이드
   ======================================== */

/*
  성능 측정 방법:

  1. Chrome DevTools 열기 (F12)
  2. Performance 탭 선택
  3. 녹화 시작 → 페이지 상호작용 → 녹화 중지
  4. 확인할 지표:
     - FCP (First Contentful Paint) < 1.8s
     - LCP (Largest Contentful Paint) < 2.5s
     - TBT (Total Blocking Time) < 300ms
     - CLS (Cumulative Layout Shift) < 0.1

  5. Lighthouse 탭에서 Mobile 성능 점수 확인
     - Performance > 90점 목표
     - Best Practices > 90점 목표
*/
