/**
 * Image Display Styles
 * 이미지 표시 및 미리보기 → 원본 전환 UI
 */

/* ===== Generation Progress ===== */
.generation-progress {
  padding: 2rem;
  text-align: center;
}

.progress-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(0, 0, 0, 0.1);
  border-top-color: var(--primary-color, #3b82f6);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===== Generation Result ===== */
.generation-result {
  margin-top: 2rem;
}

.image-container {
  position: relative;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  background: #f9fafb;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  /* 16:9 aspect ratio - 이미지 로드 전에도 영역 확보 */
  aspect-ratio: 16 / 9;
}

.result-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain; /* 이미지 비율 유지하면서 컨테이너에 맞춤 */
  transition: opacity 0.3s ease;
}

.result-image.preview-mode {
  cursor: pointer;
}

.result-image.preview-mode:hover {
  opacity: 0.9;
}

.result-image.original-mode {
  cursor: default;
}

/* ===== Loading Indicator ===== */
.loading-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.95);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  z-index: 10;
}

.loading-indicator .spinner {
  width: 40px;
  height: 40px;
}

.loading-indicator p {
  margin: 0;
  font-size: 0.875rem;
  color: #6b7280;
}

/* ===== Image Controls ===== */
.image-controls {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  background: white;
  border-top: 1px solid #e5e7eb;
}

.image-controls .btn {
  flex: 1;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.image-controls .btn-primary {
  background: #3b82f6;
  color: white;
}

.image-controls .btn-primary:hover {
  background: #2563eb;
}

.image-controls .btn-secondary {
  background: #f3f4f6;
  color: #374151;
}

.image-controls .btn-secondary:hover {
  background: #e5e7eb;
}

.image-controls .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Result Info ===== */
.result-info {
  padding: 1rem;
  text-align: center;
}

.result-timestamp {
  margin: 0;
  font-size: 0.875rem;
  color: #6b7280;
}

/* ===== Adventure History Section ===== */
.adventure-history-section {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 2px solid #e5e7eb;
}

.adventure-history-section h3 {
  margin: 0 0 1.5rem 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #111827;
}

.adventure-history-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

/* ===== History Card ===== */
.history-card {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.history-image-container {
  position: relative;
  width: 100%;
  padding-top: 100%; /* 1:1 aspect ratio */
  background: #f9fafb;
  overflow: hidden;
}

.history-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-info {
  padding: 0.75rem;
}

.history-timestamp {
  margin: 0 0 0.25rem 0;
  font-size: 0.75rem;
  color: #6b7280;
}

.history-characters {
  margin: 0;
  font-size: 0.875rem;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Empty History ===== */
.history-empty {
  grid-column: 1 / -1;
  padding: 3rem;
  text-align: center;
  color: #6b7280;
}

.history-empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.history-empty p {
  margin: 0.5rem 0;
}

/* ===== Responsive Design ===== */
@media (max-width: 1024px) {
  .adventure-history-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .adventure-history-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .image-controls {
    flex-direction: column;
  }

  .image-controls .btn {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .adventure-history-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== Hidden State ===== */
.hidden {
  display: none !important;
}

/* ===== Fullscreen Overlay ===== */
.fullscreen-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.fullscreen-overlay.active {
  opacity: 1;
}

.fullscreen-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.fullscreen-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.fullscreen-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 10;
}

.fullscreen-close:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
  transform: scale(1.1);
}

.fullscreen-controls {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1rem;
  z-index: 10;
}

.fullscreen-download {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  color: white;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
}

.fullscreen-download:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
}

.fullscreen-download svg {
  width: 20px;
  height: 20px;
}

/* ===== Fullscreen Responsive ===== */
@media (max-width: 768px) {
  .fullscreen-container {
    padding: 1rem;
  }

  .fullscreen-close {
    width: 40px;
    height: 40px;
    top: 0.5rem;
    right: 0.5rem;
  }

  .fullscreen-controls {
    bottom: 1rem;
  }

  .fullscreen-download {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
  }
}

/* ===== WebP Support Detection ===== */
.no-webp .result-image[data-webp] {
  /* Fallback for browsers without WebP support */
  content: attr(data-fallback);
}

/* ===== Image Placeholder ===== */
.image-placeholder {
  width: 100%;
  height: 400px;
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  font-size: 1rem;
}

.image-placeholder::before {
  content: '🖼️';
  font-size: 3rem;
  display: block;
  margin-bottom: 0.5rem;
}

/* ===== Lazy Loading States ===== */
.result-image[loading='lazy'] {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.result-image[loading='lazy'].loaded {
  opacity: 1;
}

.history-image[loading='lazy'] {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.history-image[loading='lazy'].loaded {
  opacity: 1;
}

/* ===== Image Error State ===== */
.image-error {
  width: 100%;
  height: 400px;
  background: #fee2e2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #dc2626;
  font-size: 1rem;
}

.image-error::before {
  content: '⚠️';
  font-size: 3rem;
  display: block;
  margin-bottom: 0.5rem;
}

.history-image-error {
  width: 100%;
  height: 100%;
  background: #fee2e2;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #dc2626;
  font-size: 0.875rem;
}

.history-image-error::before {
  content: '⚠️';
  font-size: 2rem;
}

/* ===== Blur-up Loading Effect ===== */
.result-image.blur-up {
  filter: blur(10px);
  transition: filter 0.3s ease;
}

.result-image.blur-up.loaded {
  filter: blur(0);
}

/* ===== Skeleton Loading Animation ===== */
@keyframes skeleton-loading {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.skeleton-loading {
  background: linear-gradient(90deg, #f3f4f6 0%, #e5e7eb 50%, #f3f4f6 100%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
}
