* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --secondary: #8b5cf6;
  --success: #10b981;
  --danger: #ef4444;
  --bg: #0f172a;
  --card: #1e293b;
  --card-hover: #334155;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --border: #334155;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
               "Noto Sans KR", "Malgun Gothic", sans-serif;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 40px;
}

header {
  text-align: center;
  padding: 40px 20px 20px;
}

header h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, #818cf8, #c4b5fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-dim);
  margin-top: 8px;
  font-size: 1.05rem;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
}

.card h2 {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 1.3rem;
  flex-wrap: wrap;
}

.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 50%;
  font-size: 1rem;
  font-weight: bold;
}

/* 업로드 영역 */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: rgba(99, 102, 241, 0.05);
}

.upload-area:hover, .upload-area.dragover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.15);
}

.upload-icon {
  font-size: 3rem;
  margin-bottom: 10px;
}

.upload-placeholder p {
  color: var(--text-dim);
  margin: 4px 0;
}

.upload-placeholder strong {
  color: var(--text);
}

.hint {
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* 슬라이드 리스트 */
.slides-wrapper {
  margin-top: 16px;
}

.slides-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 10px 4px;
  scrollbar-width: thin;
}

.slides-list::-webkit-scrollbar { height: 8px; }
.slides-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.slide-item {
  flex: 0 0 140px;
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-hover);
  cursor: grab;
  transition: transform 0.15s;
}

.slide-item:hover { transform: translateY(-2px); }
.slide-item.dragging { opacity: 0.4; }

.slide-thumb {
  width: 100%;
  height: 90px;
  object-fit: cover;
  display: block;
}

.slide-info {
  padding: 4px 8px;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
}

.slide-actions {
  display: flex;
  justify-content: space-between;
  padding: 4px;
  background: rgba(0, 0, 0, 0.3);
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 0.9rem;
  transition: background 0.15s;
}

.btn-icon:hover { background: rgba(255, 255, 255, 0.1); }
.btn-icon.remove:hover { background: var(--danger); }

.empty-hint {
  text-align: center;
  color: var(--text-dim);
  padding: 20px;
  font-size: 0.9rem;
}

/* 스마트 프리셋 */
.preset-section {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(139, 92, 246, 0.08));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 20px;
}

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

.preset-label {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.hint-badge {
  background: var(--primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 10px;
  vertical-align: middle;
}

.preset-duration-select {
  background: var(--card-hover);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
}

.preset-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.preset-btn {
  background: var(--card-hover);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px 8px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
  text-align: center;
}

.preset-btn:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.preset-btn.active {
  border-color: var(--primary);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.2));
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
}

.preset-icon {
  font-size: 1.8rem;
  line-height: 1;
}

.preset-name {
  font-size: 0.88rem;
  font-weight: 600;
  margin-top: 2px;
}

.preset-desc {
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.2;
}

.preset-btn-random {
  background: linear-gradient(135deg, rgba(236, 72, 153, 0.15), rgba(139, 92, 246, 0.15));
  border-color: rgba(236, 72, 153, 0.3);
}

.preset-btn-random:hover {
  border-color: #ec4899;
  box-shadow: 0 4px 12px rgba(236, 72, 153, 0.3);
}

.preset-hint {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
}

@media (max-width: 500px) {
  .preset-buttons {
    grid-template-columns: repeat(2, 1fr);
  }
  .preset-icon { font-size: 1.5rem; }
  .preset-name { font-size: 0.8rem; }
}

/* 설정 그리드 */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting > span {
  font-weight: 500;
  font-size: 0.95rem;
}

.setting input[type="text"],
.setting select {
  background: var(--card-hover);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}

.setting input[type="text"]:focus,
.setting select:focus {
  outline: none;
  border-color: var(--primary);
}

.setting input[type="color"] {
  height: 40px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-hover);
  cursor: pointer;
}

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

.input-row input[type="range"] { flex: 1; }

.val {
  min-width: 50px;
  text-align: right;
  color: var(--primary);
  font-weight: 600;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* 음악 */
.audio-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.audio-row input[type="file"] {
  flex: 1;
  padding: 8px;
  background: var(--card-hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}

/* 버튼 */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

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

.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-dim);
}

/* 미리보기 */
.preview-wrapper {
  width: 100%;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
}

#previewCanvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* 진행 상태 */
.progress-box {
  margin-top: 20px;
  padding: 16px;
  background: var(--card-hover);
  border-radius: 10px;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  width: 0%;
  transition: width 0.2s;
}

#progressText {
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* 결과 */
.result-box {
  margin-top: 20px;
  padding: 20px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid var(--success);
  border-radius: 12px;
  text-align: center;
}

.result-box h3 { margin-bottom: 12px; color: var(--success); }

.result-box video {
  width: 100%;
  max-height: 400px;
  border-radius: 8px;
  margin-bottom: 14px;
  background: #000;
}

footer {
  text-align: center;
  padding: 30px 20px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* 슬라이드 카운트 배지 */
.slide-count {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-left: auto;
}

/* 업로드 로딩 */
.upload-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.upload-loading p {
  color: var(--text-dim);
  font-size: 0.95rem;
  text-align: center;
  max-width: 100%;
  word-break: break-all;
}

/* 슬라이드 액션 바 */
.slides-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}

.btn-small {
  padding: 8px 14px;
  font-size: 0.85rem;
}

.duration-info {
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 500;
}

/* AI 변신 버튼 */
.btn-ai {
  background: linear-gradient(135deg, #ec4899, #8b5cf6, #6366f1);
  background-size: 200% 200%;
  color: white;
  border: none;
  animation: aiGlow 3s ease infinite;
  position: relative;
}

.btn-ai:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(236, 72, 153, 0.5);
}

@keyframes aiGlow {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* 모달 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
}

.modal-content {
  position: relative;
  background: var(--card);
  border-radius: 20px;
  padding: 30px;
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--card-hover);
  border: none;
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.modal-close:hover { background: var(--danger); }

.modal-content h2 {
  background: linear-gradient(135deg, #ec4899, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 1.8rem;
  margin-bottom: 6px;
}

.modal-subtitle {
  color: var(--text-dim);
  margin-bottom: 24px;
}

.ai-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.ai-info-card {
  background: var(--card-hover);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.ai-info-icon { font-size: 1.8rem; margin-bottom: 8px; }

.ai-info-card h3 {
  font-size: 1rem;
  margin-bottom: 6px;
}

.ai-info-card p, .ai-info-card li {
  font-size: 0.88rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.ai-info-card ul {
  list-style: none;
  padding-left: 0;
  margin-top: 6px;
}

.ai-info-card ul li {
  padding: 3px 0;
}

.ai-info-card a {
  color: var(--primary);
  text-decoration: none;
}

.ai-info-card a:hover { text-decoration: underline; }

.ai-config {
  background: var(--card-hover);
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.ai-config h3 {
  font-size: 1.05rem;
  margin-bottom: 14px;
}

.ai-config .setting {
  margin-bottom: 14px;
}

.ai-config .setting:last-child { margin-bottom: 0; }

.ai-config input[type="password"],
.ai-config input[type="text"],
.ai-config select {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}

.modal-warning {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid #f59e0b;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 20px;
  font-size: 0.88rem;
}

.modal-warning strong { display: block; margin-bottom: 6px; color: #fbbf24; }
.modal-warning ul { padding-left: 20px; color: var(--text-dim); }
.modal-warning li { margin: 4px 0; line-height: 1.5; }

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

.ai-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 30px 20px;
  background: var(--card-hover);
  border-radius: 12px;
  margin-top: 20px;
}

.ai-progress p { text-align: center; }

.ai-result {
  margin-top: 20px;
  padding: 20px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid var(--success);
  border-radius: 12px;
}

.ai-result h3 {
  color: var(--success);
  margin-bottom: 12px;
  text-align: center;
}

.ai-result video {
  width: 100%;
  max-height: 360px;
  border-radius: 8px;
  background: #000;
  margin-bottom: 14px;
}

@media (max-width: 600px) {
  .modal-content {
    padding: 20px;
    max-height: 95vh;
  }
  .ai-info-grid { grid-template-columns: 1fr; }
}

/* 토스트 알림 */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  max-width: 420px;
  padding: 16px 20px;
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border);
  z-index: 9999;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.3s, transform 0.3s;
  font-size: 0.95rem;
  line-height: 1.5;
  word-break: keep-all;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast small {
  color: var(--text-dim);
  font-size: 0.8rem;
  display: inline-block;
  margin-top: 2px;
}

.toast-success { border-left: 4px solid var(--success); }
.toast-warn    { border-left: 4px solid #f59e0b; }
.toast-error   { border-left: 4px solid var(--danger); }
.toast-info    { border-left: 4px solid var(--primary); }

@media (max-width: 600px) {
  .toast {
    left: 10px;
    right: 10px;
    max-width: none;
  }
}

@media (max-width: 600px) {
  header h1 { font-size: 1.8rem; }
  .card { padding: 18px; }
  .actions { flex-direction: column; }
  .actions .btn { width: 100%; }
}
