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

:root {
  --bg: #f5f0ea;
  --surface: #ffffff;
  --border: #ddd8d0;
  --border-dash: #c8c0b4;
  --text: #2d2926;
  --text-muted: #7a7168;
  --accent: #4a3f35;
  --accent-light: #e8e0d4;
  --radius: 12px;
  --radius-sm: 8px;
}

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

.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

header {
  text-align: center;
  margin-bottom: 36px;
}

header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}

.subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Section */
.section {
  margin-bottom: 28px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
  letter-spacing: 0.2px;
}

.optional {
  font-weight: 400;
  opacity: 0.7;
}

/* Upload Areas */
.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.upload-area {
  border: 1.5px dashed var(--border-dash);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.upload-area:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.upload-area.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}

.upload-icon { color: var(--text-muted); }

.upload-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.upload-formats {
  font-size: 11px;
  color: var(--text-muted);
}

.bgm-upload {
  padding: 24px 20px;
}

/* BGM info */
.bgm-info {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
}

.bgm-info.visible { display: flex; }

.bgm-info span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.1s, background 0.1s;
}

.remove-btn:hover { color: var(--text); background: var(--accent-light); }

/* Clip List */
.clip-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 80px;
  overflow: hidden;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state svg { opacity: 0.5; }
.empty-state p { font-size: 13px; }

.clip-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: grab;
  transition: background 0.1s;
}

.clip-item:last-child { border-bottom: none; }
.clip-item:hover { background: #faf8f5; }
.clip-item.dragging { opacity: 0.4; }
.clip-item.drag-over { border-top: 2px solid var(--accent); }

.drag-handle {
  color: var(--border-dash);
  font-size: 18px;
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}

.clip-thumbnail {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg);
  flex-shrink: 0;
}

.clip-thumb-placeholder {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-muted);
}

.clip-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.clip-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clip-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.clip-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  letter-spacing: 0.3px;
}

.clip-badge.image {
  background: #e8f0fe;
  color: #3c6fcd;
}

.clip-badge.video {
  background: #fde8e8;
  color: #c43333;
}

.clip-duration {
  font-size: 11px;
  color: var(--text-muted);
}

.clip-subtitle-input {
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}

.clip-subtitle-input:focus { border-color: var(--accent); }
.clip-subtitle-input::placeholder { color: var(--text-muted); }

.clip-order-btns {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.order-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 10px;
  width: 24px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.1s, background 0.1s, border-color 0.1s;
  line-height: 1;
}

.order-btn:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}

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

.clip-delete {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  padding: 6px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: color 0.1s, background 0.1s;
}

.clip-delete:hover { color: #c43333; background: #fde8e8; }

/* Settings */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

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

.setting-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.setting-value {
  font-weight: 600;
  color: var(--text);
}

.setting-select {
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
  cursor: pointer;
  font-family: inherit;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%237a7168' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  transition: border-color 0.15s;
}

.setting-select:focus { border-color: var(--accent); }

.setting-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

.setting-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.setting-range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* Generate */
.generate-section {
  margin-top: 8px;
}

.generate-btn {
  width: 100%;
  padding: 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--bg);
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: 0.2px;
}

.generate-btn:hover:not(:disabled) {
  opacity: 0.88;
  transform: translateY(-1px);
}

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

.generate-btn:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Progress */
.progress-section {
  display: none;
  margin-top: 20px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.progress-section.visible { display: block; }

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 10px;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* Result */
.result-section {
  display: none;
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.result-section.visible { display: block; }

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}

.download-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  padding: 6px 14px;
  border: 1.5px solid var(--accent);
  border-radius: 99px;
  transition: background 0.15s, color 0.15s;
}

.download-btn:hover {
  background: var(--accent);
  color: var(--bg);
}

#resultVideo {
  width: 100%;
  max-height: 480px;
  display: block;
  background: #000;
}

/* Ratio Modal */
.ratio-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.ratio-modal-overlay.visible { display: flex; }

.ratio-modal-box {
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 24px 20px;
  max-width: 560px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.ratio-modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.ratio-modal-sub {
  font-size: 12px;
  color: var(--text-muted);
  min-height: 16px;
}

.ratio-options {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 8px 0;
}

.ratio-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: none;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 14px 12px 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.ratio-option:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-2px);
}

.ratio-option:active { transform: translateY(0); }

.ratio-preview-wrap {
  overflow: hidden;
  border-radius: 6px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.ratio-preview-vid { display: none; }

.ratio-option-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  line-height: 1.5;
}

.ratio-option-label small {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 11px;
}

.ratio-cancel-btn {
  font-size: 12px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 16px;
  border-radius: 6px;
  font-family: inherit;
  transition: background 0.1s;
}

.ratio-cancel-btn:hover { background: var(--accent-light); }

.clip-crop-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  background: #f0e8d8;
  color: #8a6a3a;
}

/* Responsive */
@media (max-width: 480px) {
  .upload-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .container { padding: 24px 16px 40px; }
}
