/* Critical styles for above-the-fold content - Performance Optimized */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  contain: layout style paint;
}

.header {
  text-align: center;
  margin-bottom: 30px;
  will-change: auto;
}

.loading {
  display: none;
  text-align: center;
  padding: 20px;
  transform: translateZ(0); /* Force GPU acceleration */
}

.error-message {
  display: none;
  color: #e74c3c;
  padding: 10px;
  margin: 10px 0;
  border-radius: 5px;
  background: #fdf2f2;
  contain: layout style;
}

/* Performance optimizations */
.search-history-items {
  contain: layout style paint;
  will-change: transform;
}

.search-history-item {
  transform: translateZ(0);
  backface-visibility: hidden;
}

.search-history-item.removing {
  transition:
    transform 0.3s ease-out,
    opacity 0.3s ease-out;
  will-change: transform, opacity;
}

/* Screen reader only content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus visible for keyboard navigation */
.modern-btn:focus-visible,
.modern-form-input:focus-visible,
.modern-form-select:focus-visible {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

/* Error message styles */
.app-error-message {
  display: none;
  background: var(--error-50);
  border: 1px solid var(--error-200);
  color: var(--error-700);
  padding: 12px 16px;
  margin: 16px 0;
  border-radius: 8px;
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  animation: slideDown 0.3s ease-out;
}

.app-error-message.alert-error {
  background: var(--error-50);
  border-color: var(--error-200);
  color: var(--error-700);
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Hide error messages during initialization */
body.initializing .app-error-message {
  display: none !important;
}

/* Initialization loading indicator */
.init-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--primary-500);
  height: 3px;
  z-index: 9999;
  animation: initProgress 2s ease-out forwards;
}

body:not(.initializing) .init-loading {
  display: none;
}

@keyframes initProgress {
  0% {
    width: 0%;
  }
  50% {
    width: 70%;
  }
  100% {
    width: 100%;
    opacity: 0;
  }
}

/* CLS Prevention - Fixed Heights for Form Elements */
.modern-form-section.search-section {
  min-height: 180px; /* 폼 섹션 최소 높이 */
}

.modern-form-group {
  min-height: 80px; /* 폼 그룹 최소 높이 (label + input + spacing) */
}

#character-name-group {
  min-height: 80px;
}

#lookup-character-btn {
  min-height: 48px; /* 버튼 고정 높이 */
  height: 48px;
}

/* Ranking Card Fixed Height */
.ranking-card {
  min-height: 140px; /* 데스크톱 기본 */
}

@media (max-width: 768px) {
  .ranking-card {
    min-height: 120px; /* 모바일 */
  }

  .modern-form-section.search-section {
    min-height: 160px;
  }

  .modern-form-group {
    min-height: 75px;
  }

  #lookup-character-btn {
    min-height: 44px;
    height: 44px;
  }
}
