/* ===========================
   CSS Variables & Reset
   =========================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1565C0;
  --primary-light: #1976D2;
  --primary-dark: #0D47A1;
  --primary-bg: #E3F2FD;
  --accent: #00897B;
  --accent-light: #E0F2F1;
  --bg: #F0F4F8;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --border: #DDE3EA;
  --text: #1A2332;
  --text-2: #4A5568;
  --text-3: #718096;
  --success: #2E7D32;
  --success-bg: #E8F5E9;
  --error: #C62828;
  --error-bg: #FFEBEE;
  --warning: #E65100;
  --warning-bg: #FFF3E0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --transition: 0.2s ease;
}

html { font-size: 15px; }

body {
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===========================
   Header
   =========================== */
.header {
  background: var(--primary-dark);
  background: linear-gradient(135deg, #0D47A1 0%, #1565C0 60%, #1976D2 100%);
  color: white;
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(13, 71, 161, 0.4);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo div {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.logo-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo-sub {
  font-size: 0.72rem;
  opacity: 0.75;
  font-weight: 400;
  letter-spacing: 0.03em;
}


/* ===========================
   Main Layout
   =========================== */
.main { padding: 24px; }

.container {
  max-width: 1280px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  align-items: start;
}

/* ===========================
   Panels
   =========================== */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-controls {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.panel-results {
  min-height: 600px;
  display: flex;
  flex-direction: column;
}

/* ===========================
   Step Sections
   =========================== */
.step-section {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.step-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.step-num {
  width: 26px;
  height: 26px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
}

.step-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.step-badge {
  background: var(--primary-bg);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 0.02em;
}

.step-badge.selected {
  background: var(--success-bg);
  color: var(--success);
}

.step-desc {
  font-size: 0.78rem;
  color: var(--text-3);
  margin-bottom: 10px;
}

/* ===========================
   Photo Input Area
   =========================== */
.photo-input-area {
  background: var(--surface-2);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  transition: var(--transition);
  overflow: hidden;
}

.photo-input-area.drag-over {
  border-color: var(--primary);
  background: var(--primary-bg);
}

.photo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px 16px;
  text-align: center;
}

.photo-placeholder p {
  font-size: 0.8rem;
  color: var(--text-3);
}

.photo-preview-wrap {
  position: relative;
}

.photo-preview-wrap img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  background: #000;
  display: block;
}

.photo-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  background: rgba(0,0,0,0.6);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.photo-remove:hover { background: rgba(198,40,40,0.8); }

.photo-buttons {
  display: flex;
  gap: 8px;
  padding: 10px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.photo-buttons .btn { flex: 1; font-size: 0.78rem; padding: 8px 6px; }

/* ===========================
   Shade Selector
   =========================== */
.shade-groups {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shade-group {}

.shade-group-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.shade-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.shade-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius-xs);
  background: white;
  cursor: pointer;
  transition: var(--transition);
  min-width: 48px;
  font-family: inherit;
}

.shade-btn:hover {
  border-color: var(--primary-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.shade-btn.active {
  border-color: var(--primary);
  background: var(--primary-bg);
  box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.15);
}

.shade-swatch {
  width: 24px;
  height: 20px;
  border-radius: 4px;
  background: var(--shade-color, #EEE);
  border: 1px solid rgba(0,0,0,0.1);
  display: block;
}

.shade-btn span:last-child {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-2);
  line-height: 1;
}

.shade-btn.active span:last-child { color: var(--primary); }

/* ===========================
   Prosthetic Type Selector
   =========================== */
.prosthetic-types {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.radio-card {
  cursor: pointer;
}

.radio-card input[type="radio"] { display: none; }

.radio-card-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  transition: var(--transition);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-2);
  text-align: center;
}

.radio-card input:checked + .radio-card-inner {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary);
}

.radio-card:hover .radio-card-inner {
  border-color: var(--primary-light);
  background: var(--primary-bg);
}

/* ===========================
   Buttons
   =========================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  font-size: 0.85rem;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-light);
  box-shadow: 0 4px 12px rgba(21,101,192,0.3);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
  color: var(--text);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn-outline:hover {
  background: var(--primary-bg);
}

.btn-generate {
  margin: 16px 20px 8px;
  width: calc(100% - 40px);
  padding: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 4px 12px rgba(21, 101, 192, 0.25);
  font-family: inherit;
}

.btn-generate:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(21, 101, 192, 0.35);
}

.btn-generate:active:not(:disabled) { transform: translateY(0); }

/* ===========================
   Disclaimer
   =========================== */
.disclaimer {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 0 20px 20px;
  font-size: 0.72rem;
  color: var(--text-3);
  line-height: 1.5;
}

.disclaimer svg { flex-shrink: 0; margin-top: 2px; }

/* ===========================
   Modals
   =========================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: white;
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  transform: translateY(16px) scale(0.97);
  transition: transform 0.25s ease;
}

.modal-overlay.active .modal {
  transform: translateY(0) scale(1);
}

.modal-camera {
  max-width: 600px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  width: 32px;
  height: 32px;
  background: var(--surface-2);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  line-height: 1;
}

.modal-close:hover { background: var(--border); color: var(--text); }

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-2);
  margin-bottom: 20px;
  line-height: 1.6;
}

.input-group { margin-bottom: 16px; }

.input-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrap input {
  width: 100%;
  padding: 10px 44px 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: monospace;
  color: var(--text);
  background: var(--surface-2);
  transition: var(--transition);
  outline: none;
}

.input-wrap input:focus {
  border-color: var(--primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(21,101,192,0.12);
}

.toggle-visibility {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  padding: 4px;
  display: flex;
  align-items: center;
}

.toggle-visibility:hover { color: var(--text); }

.modal-notice {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-3);
  background: var(--surface-2);
  border-radius: var(--radius-xs);
  padding: 10px 12px;
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-notice svg { flex-shrink: 0; margin-top: 1px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===========================
   Camera UI
   =========================== */
.camera-wrap {
  position: relative;
  background: #000;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 16px;
  aspect-ratio: 4/3;
}

#cameraVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-guide {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.face-guide {
  width: 200px;
  height: 260px;
  border: 2px dashed rgba(255,255,255,0.5);
  border-radius: 50%;
  position: relative;
}

.face-guide::before,
.face-guide::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.8);
}

.face-guide::before {
  top: -2px; left: -2px;
  border-right: none; border-bottom: none;
  border-radius: 2px 0 0 0;
}

.face-guide::after {
  bottom: -2px; right: -2px;
  border-left: none; border-top: none;
  border-radius: 0 0 2px 0;
}

.camera-guide p {
  margin-top: 16px;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.75);
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.camera-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  align-items: center;
}

.capture-btn {
  padding: 12px 28px;
  font-size: 0.9rem;
}

/* ===========================
   Results Panel
   =========================== */
.results-idle,
.results-loading,
.results-error {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 32px;
  text-align: center;
  gap: 16px;
  min-height: 500px;
}

.idle-icon {
  margin-bottom: 8px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.results-idle h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.results-idle p {
  font-size: 0.85rem;
  color: var(--text-3);
  line-height: 1.7;
}

.idle-steps {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.idle-step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-2);
  font-weight: 500;
}

.idle-step span {
  width: 20px;
  height: 20px;
  background: var(--primary-bg);
  color: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
}

.idle-arrow { color: var(--text-3); font-size: 1.1rem; }

/* ===========================
   Loading States
   =========================== */
.loading-steps {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 360px;
  margin-bottom: 24px;
}

.loading-step {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
}

.loading-step-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
}

.loading-step-icon.pending {
  background: var(--surface-2);
  color: var(--text-3);
  border: 2px solid var(--border);
}

.loading-step-icon.active {
  background: var(--primary-bg);
  color: var(--primary);
  border: 2px solid var(--primary);
  animation: pulse-ring 1.5s ease-out infinite;
}

.loading-step-icon.done {
  background: var(--success-bg);
  color: var(--success);
  border: 2px solid var(--success);
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(21,101,192,0.3); }
  70% { box-shadow: 0 0 0 8px rgba(21,101,192,0); }
  100% { box-shadow: 0 0 0 0 rgba(21,101,192,0); }
}

.loading-step-text strong {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.loading-step-text span {
  font-size: 0.75rem;
  color: var(--text-3);
}

.loading-bar-wrap {
  width: 100%;
  max-width: 360px;
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 12px;
}

.loading-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary) 0%, #42A5F5 100%);
  border-radius: 99px;
  width: 0%;
  transition: width 0.6s ease;
}

.loading-msg {
  font-size: 0.82rem;
  color: var(--text-3);
}

/* ===========================
   Error State
   =========================== */
.results-error h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.results-error p {
  font-size: 0.85rem;
  color: var(--text-3);
  max-width: 320px;
  line-height: 1.6;
}

/* ===========================
   Results Content
   =========================== */
.results-content {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.results-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.results-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.shade-tag, .prosthetic-tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
}

.shade-tag {
  background: var(--primary-bg);
  color: var(--primary);
}

.prosthetic-tag {
  background: var(--accent-light);
  color: var(--accent);
}

/* ===========================
   Before/After Comparison
   =========================== */
.comparison {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: start;
}

.comparison-panel {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #f0f0f0;
  border: 1px solid var(--border);
}

.comparison-panel img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: contain;
  background: #1a1a1a;
  display: block;
}

.comparison-label {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  backdrop-filter: blur(4px);
}

.comparison-label.after {
  background: rgba(21,101,192,0.8);
}

.image-watermark {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0,0,0,0.5);
  color: rgba(255,255,255,0.7);
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 4px;
  backdrop-filter: blur(4px);
  font-family: monospace;
}

.comparison-divider {
  display: flex;
  align-items: center;
  padding-top: 80px;
}

/* ===========================
   Analysis Card
   =========================== */
.analysis-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.analysis-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-2);
}

.analysis-content {
  padding: 16px;
  font-size: 0.85rem;
  line-height: 1.75;
  color: var(--text-2);
  white-space: pre-wrap;
}

.analysis-content strong {
  color: var(--text);
  font-weight: 600;
}

/* ===========================
   Result Actions
   =========================== */
.result-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===========================
   Responsive
   =========================== */
@media (max-width: 900px) {
  .container {
    grid-template-columns: 1fr;
  }

  .panel-results {
    min-height: auto;
  }

  .results-idle,
  .results-loading,
  .results-error {
    min-height: 360px;
    padding: 32px 20px;
  }
}

@media (max-width: 600px) {
  .main { padding: 12px; }
  .container { gap: 12px; }

  .shade-row { flex-wrap: wrap; }
  .shade-btn { min-width: 44px; }

  .comparison {
    grid-template-columns: 1fr;
  }

  .comparison-divider {
    display: none;
  }

  .header-inner { padding: 12px 16px; }

  .api-key-btn span { display: none; }
}

/* ===========================
   Spinner (for active icons)
   =========================== */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.loading-step-icon.active svg {
  animation: spin 1.5s linear infinite;
}
