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

:root {
  --bg: #0f0f13;
  --bg2: #16161d;
  --bg3: #1e1e28;
  --bg4: #252533;
  --border: #2e2e3f;
  --border2: #3a3a50;
  --text: #f0f0f5;
  --text2: #a0a0b8;
  --text3: #6a6a82;
  --accent: #7c6af7;
  --accent2: #9d8ffb;
  --accent3: #5248c4;
  --green: #3ecf8e;
  --red: #f56565;
  --amber: #f6ad55;
  --radius: 12px;
  --radius2: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow2: 0 2px 12px rgba(0,0,0,0.3);
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

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

/* =====================
   HEADER
   ===================== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15,15,19,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

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

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

.logo-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
}

.logo-text {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}

.btn-settings {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius2);
  padding: 8px;
  color: var(--text2);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: all 0.2s;
}
.btn-settings:hover { color: var(--text); border-color: var(--border2); background: var(--bg3); }

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

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

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
}

.modal h2 { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.modal-desc { font-size: 14px; color: var(--text2); margin-bottom: 24px; line-height: 1.5; }
.field-hint { display: block; font-size: 12px; color: var(--text3); margin-top: 5px; }
.optional { font-size: 12px; color: var(--text3); font-weight: 400; }

.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

/* =====================
   MAIN LAYOUT
   ===================== */
.main {
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

/* =====================
   STEP INDICATOR
   ===================== */
.steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 48px;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  opacity: 0.35;
  transition: opacity 0.3s;
}

.step.active { opacity: 1; }
.step.done { opacity: 0.7; }

.step-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg3);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  transition: all 0.3s;
}

.step.active .step-num {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.step.done .step-num {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.step-label { font-size: 12px; color: var(--text2); font-weight: 500; white-space: nowrap; }
.step.active .step-label { color: var(--accent2); }

.step-line {
  flex: 1;
  height: 2px;
  background: var(--border);
  min-width: 40px;
  max-width: 100px;
  margin-bottom: 22px;
  transition: background 0.3s;
}

/* =====================
   SECTIONS
   ===================== */
.section { animation: fadeUp 0.3s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-header { margin-bottom: 28px; }
.section-header h2 { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 8px; }
.section-header p { color: var(--text2); font-size: 15px; }

/* =====================
   UPLOAD AREA
   ===================== */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg2);
  min-height: 200px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.upload-area:hover, .upload-area.dragover {
  border-color: var(--accent);
  background: rgba(124,106,247,0.05);
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  gap: 12px;
}

.upload-icon { color: var(--text3); }
.upload-text { font-size: 16px; font-weight: 500; color: var(--text2); }
.upload-hint { font-size: 13px; color: var(--text3); }

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  padding: 16px;
}

.preview-item {
  position: relative;
  aspect-ratio: 16/10;
  border-radius: var(--radius2);
  overflow: hidden;
  background: var(--bg3);
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  border: none;
  color: white;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.preview-item:hover .preview-remove { opacity: 1; }

.upload-actions { margin-top: 20px; }

/* =====================
   ANALYSIS RESULT
   ===================== */
.analysis-result { margin-top: 32px; }

.result-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.result-card h3 { font-size: 20px; font-weight: 700; margin-bottom: 24px; }

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

@media (max-width: 600px) { .result-grid { grid-template-columns: 1fr; } }

.result-block {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius2);
  padding: 20px;
}

.result-block h4 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text3);
  margin-bottom: 12px;
}

.result-text { font-size: 14px; color: var(--text2); line-height: 1.6; margin-top: 10px; }

/* Color Swatches */
.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.1);
  position: relative;
  cursor: default;
  flex-shrink: 0;
}

.swatch-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 11px;
  white-space: nowrap;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

.swatch:hover .swatch-tooltip { opacity: 1; }

/* Tags */
.tags { display: flex; flex-wrap: wrap; gap: 6px; }

.tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: rgba(124,106,247,0.15);
  border: 1px solid rgba(124,106,247,0.3);
  color: var(--accent2);
}

/* Result Summary */
.result-summary {
  background: linear-gradient(135deg, rgba(124,106,247,0.1), rgba(62,207,142,0.05));
  border: 1px solid rgba(124,106,247,0.2);
  border-radius: var(--radius2);
  padding: 20px;
  margin-bottom: 24px;
  font-size: 14px;
  color: var(--text2);
  line-height: 1.7;
}

/* =====================
   CATEGORY SELECTOR
   ===================== */
.category-section {
  margin-bottom: 24px;
}

.category-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.category-hint {
  font-size: 13px;
  color: var(--text3);
  margin-bottom: 16px;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.cat-card {
  background: var(--bg2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: left;
  cursor: pointer;
  transition: all 0.18s;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: inherit;
  position: relative;
  overflow: hidden;
}

.cat-card::after {
  content: '';
  position: absolute;
  top: 10px; right: 10px;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: transparent;
  transition: all 0.18s;
}

.cat-card:hover {
  border-color: var(--border2);
  background: var(--bg3);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

.cat-card.selected {
  border-color: var(--accent);
  background: rgba(124,106,247,0.08);
}

.cat-card.selected::after {
  background: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 6l3 3 5-5' stroke='white' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: 12px;
  background-position: center;
  background-repeat: no-repeat;
}

.cat-icon {
  font-size: 24px;
  line-height: 1;
  margin-bottom: 2px;
}

.cat-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.cat-card.selected .cat-name {
  color: var(--accent2);
}

.cat-desc {
  font-size: 12px;
  color: var(--text2);
  line-height: 1.5;
}

.cat-keywords {
  font-size: 11px;
  color: var(--text3);
  margin-top: 2px;
}

/* =====================
   BRIEF FORM
   ===================== */
.brief-form {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.analysis-badge {
  background: rgba(62,207,142,0.08);
  border: 1px solid rgba(62,207,142,0.2);
  border-radius: var(--radius2);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--green);
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.analysis-badge::before {
  content: "✓";
  width: 18px;
  height: 18px;
  background: var(--green);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bg);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.required { color: var(--accent2); }

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius2);
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.2s;
  outline: none;
  resize: vertical;
}

.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--text3); }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,106,247,0.15); }

.form-group select { appearance: none; cursor: pointer; }

.form-actions { display: flex; gap: 12px; align-items: center; margin-top: 28px; flex-wrap: wrap; }

/* Generation progress */
.gen-timer { font-variant-numeric: tabular-nums; opacity: 0.75; font-size: 14px; }

.gen-progress {
  width: 100%;
  margin-top: 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius2);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gen-progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.gen-progress-bar::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  width: var(--pct, 0%);
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
  transition: width 0.8s ease;
}

.gen-progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text2);
}

#genTimeLeft {
  font-variant-numeric: tabular-nums;
  color: var(--text3);
  font-size: 12px;
}

/* =====================
   STORYBOARD OUTPUT
   ===================== */
.sb-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.sb-header-actions { display: flex; gap: 10px; flex-shrink: 0; }

.style-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 32px;
  padding: 16px 20px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius2);
}

.style-bar .tag { font-size: 13px; }
.style-bar .tag.tag-mood {
  background: rgba(246,173,85,0.12);
  border-color: rgba(246,173,85,0.35);
  color: var(--amber);
}

.scenes-container {
  display: grid;
  gap: 20px;
}

.scene-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s;
}

.scene-card:hover { border-color: var(--border2); }

.scene-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}

.scene-num {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.scene-title { font-size: 15px; font-weight: 700; flex: 1; }
.scene-time {
  font-size: 12px;
  color: var(--text3);
  background: var(--bg4);
  padding: 3px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.scene-body {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
}

@media (max-width: 640px) { .scene-body { grid-template-columns: 1fr; } }

.scene-visual {
  background: var(--bg3);
  border-right: 1px solid var(--border);
  padding: 20px;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.scene-visual-frame {
  aspect-ratio: 16/9;
  background: var(--bg4);
  border-radius: var(--radius2);
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.scene-visual-desc {
  font-size: 12px;
  color: var(--text3);
  text-align: center;
  line-height: 1.5;
}

.scene-shot-info {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.shot-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.shot-badge.wide { background: rgba(246,173,85,0.15); color: var(--amber); border: 1px solid rgba(246,173,85,0.3); }
.shot-badge.medium { background: rgba(124,106,247,0.15); color: var(--accent2); border: 1px solid rgba(124,106,247,0.3); }
.shot-badge.close { background: rgba(62,207,142,0.15); color: var(--green); border: 1px solid rgba(62,207,142,0.3); }
.shot-badge.other { background: var(--bg4); color: var(--text2); border: 1px solid var(--border); }

.scene-details { padding: 20px; display: flex; flex-direction: column; gap: 14px; }

.detail-row { display: flex; flex-direction: column; gap: 4px; }
.detail-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text3); }
.detail-value { font-size: 14px; color: var(--text); line-height: 1.6; }

.detail-row.highlight .detail-value {
  color: var(--accent2);
  font-style: italic;
}

.scene-colors {
  display: flex;
  gap: 5px;
}

.scene-color {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.1);
}

/* Direction Card */
.direction-card {
  margin-top: 24px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.direction-card h3 { font-size: 18px; font-weight: 700; margin-bottom: 20px; }

.direction-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }

.direction-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius2);
  padding: 16px;
}

.direction-item h5 { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text3); margin-bottom: 8px; }
.direction-item p { font-size: 14px; color: var(--text2); line-height: 1.6; }

/* =====================
   FRAME ART
   ===================== */
.frame-art { width: 100%; height: 100%; }

.scene-visual-frame.frame-loading {
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg4) 50%, var(--bg3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

.scene-visual-frame.frame-loading::after {
  content: 'AI 드로잉 중...';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text3);
  letter-spacing: 0.3px;
}

.scene-visual-frame svg,
.scene-visual-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.illust-banner {
  padding: 12px 16px;
  background: rgba(124,106,247,0.08);
  border: 1px solid rgba(124,106,247,0.2);
  border-radius: var(--radius2);
  font-size: 13px;
  color: var(--accent2);
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.illust-banner-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.illust-banner-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.illust-time {
  font-size: 12px;
  color: var(--text3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.illust-bar-wrap {
  height: 3px;
  background: rgba(124,106,247,0.15);
  border-radius: 2px;
  overflow: hidden;
}

.illust-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
  transition: width 0.8s ease;
}

/* =====================
   BUTTONS
   ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius2);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  white-space: nowrap;
  text-decoration: none;
}

.btn-lg { padding: 14px 28px; font-size: 16px; }

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent2); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg4); color: var(--text); border-color: var(--border2); }

/* Spinner */
.spinner {
  width: 18px;
  height: 18px;
  animation: spin 0.8s linear infinite;
}

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

.btn-loader {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* =====================
   TOAST
   ===================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius2);
  padding: 12px 20px;
  font-size: 14px;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  z-index: 2000;
  max-width: 400px;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error { border-color: var(--red); color: var(--red); }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.info { border-color: var(--accent); color: var(--accent2); }

/* =====================
   LOADING SKELETON
   ===================== */
.skeleton {
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg4) 50%, var(--bg3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}

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

/* =====================
   SCENE VISUAL GRAPHICS
   ===================== */
.visual-scene-bg {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}
