:root {
  --bg: #0c0c0f;
  --surface: #15161b;
  --surface-2: #1c1d24;
  --border: #2a2b33;
  --border-hover: #3d3e48;
  --text: #e4e4e7;
  --text-muted: #71717a;
  --text-dim: #52525b;
  --accent: #e8a838;
  --accent-dim: rgba(232, 168, 56, 0.12);
  --accent-hover: #f0b84a;
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.12);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.12);
  --blue: #3b82f6;
  --blue-dim: rgba(59, 130, 246, 0.12);
  --radius: 10px;
  --mono: 'Space Mono', monospace;
  --sans: 'DM Sans', system-ui, sans-serif;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 80% 60% at 50% -20%, rgba(232,168,56,0.04) 0%, transparent 60%),
    radial-gradient(circle at 80% 80%, rgba(59,130,246,0.02) 0%, transparent 40%);
}

.app { max-width: 800px; margin: 0 auto; padding: 32px 20px 80px; }

/* Header */
.header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 36px; padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.header-left { display: flex; align-items: center; gap: 14px; }
.logo { flex-shrink: 0; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; color: #fff; }
.tagline { font-size: 13px; color: var(--text-muted); margin-top: 1px; }
.header-right { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.health-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-dim); transition: background 0.3s;
}
.health-dot.ok { background: var(--green); box-shadow: 0 0 6px rgba(34,197,94,0.4); }
.health-dot.err { background: var(--red); }

/* Timeline */
.timeline {
  display: flex; align-items: center; justify-content: center;
  gap: 0; margin-bottom: 28px; padding: 16px 0;
}
.timeline-segment {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
  transition: all 0.3s;
  min-width: 80px;
}
.timeline-segment.active {
  border-color: var(--accent); color: var(--accent);
  background: var(--accent-dim);
}
.timeline-segment.filled { border-color: var(--border-hover); color: var(--text); }
.timeline-icon { font-size: 16px; line-height: 1; }
.timeline-connector {
  width: 32px; height: 1px; background: var(--border); flex-shrink: 0;
}

/* Uploads grid */
.uploads-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; margin-bottom: 20px;
}
.upload-zone {
  position: relative;
  background: var(--surface);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 140px;
  display: flex; align-items: center; justify-content: center;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.upload-zone.has-file {
  border-style: solid;
  border-color: var(--border-hover);
  padding: 8px;
}
.upload-zone.required .upload-label em {
  color: var(--accent); font-style: normal;
}
.upload-content {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.upload-icon { color: var(--text-dim); transition: color 0.2s; }
.upload-zone:hover .upload-icon { color: var(--accent); }
.upload-label { font-size: 13px; font-weight: 600; color: var(--text); }
.upload-hint { font-size: 11px; color: var(--text-dim); }
.music-select {
  width: 100%; margin-top: 6px; padding: 6px 10px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-muted); font-family: var(--sans); font-size: 11px;
  cursor: pointer; transition: border-color 0.2s;
}
.music-select:focus { outline: none; border-color: var(--accent); }
.music-select.has-selection { color: var(--accent); border-color: var(--accent); }

/* Upload preview */
.upload-preview {
  width: 100%; height: 100%; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
}
.upload-preview img, .upload-preview video {
  max-width: 100%; max-height: 100px; border-radius: 6px; object-fit: cover;
}
.upload-preview audio { width: 100%; height: 32px; }
.upload-meta {
  font-family: var(--mono); font-size: 10px; color: var(--text-muted);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.upload-clear {
  position: absolute; top: 2px; right: 2px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 14px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.upload-clear:hover { background: var(--red-dim); color: var(--red); border-color: var(--red); }

/* Config panel */
.config-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow: hidden;
}
.config-section {
  padding: 20px;
}
.config-section + .config-section {
  border-top: 1px solid var(--border);
}
.config-section h3 {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted);
  margin-bottom: 14px;
}
.config-row {
  display: flex; gap: 12px;
}
.config-field {
  flex: 1; display: flex; flex-direction: column; gap: 6px; cursor: pointer;
}
.config-field > span {
  font-size: 12px; color: var(--text-muted); font-weight: 500;
}
.input-with-unit {
  position: relative;
}
.input-with-unit input {
  width: 100%; padding: 8px 40px 8px 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-family: var(--mono); font-size: 13px;
  transition: border-color 0.2s;
}
.input-with-unit input:focus { outline: none; border-color: var(--accent); }
.unit {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-size: 11px; color: var(--text-dim); font-family: var(--mono);
  pointer-events: none;
}
select {
  width: 100%; padding: 8px 12px; appearance: none;
  background: var(--bg) 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='%2371717a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-family: var(--mono); font-size: 13px;
  cursor: pointer; transition: border-color 0.2s;
}
select:focus { outline: none; border-color: var(--accent); }

/* Toggle switch */
.toggle-label {
  display: inline-flex; align-items: center; gap: 10px; cursor: pointer;
}
.toggle-label input { display: none; }
.toggle-switch {
  width: 34px; height: 18px; border-radius: 9px;
  background: var(--border); position: relative;
  transition: background 0.2s; flex-shrink: 0;
}
.toggle-switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text-dim); transition: all 0.2s;
}
.toggle-label input:checked ~ .toggle-switch {
  background: var(--accent);
}
.toggle-label input:checked ~ .toggle-switch::after {
  transform: translateX(16px); background: #fff;
}

/* Timer config */
.timer-config {
  display: flex; gap: 20px; align-items: center;
  opacity: 0.3; pointer-events: none; transition: opacity 0.3s;
}
.timer-config.enabled { opacity: 1; pointer-events: auto; }

.position-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 4px; flex-shrink: 0;
}
.position-grid button {
  width: 28px; height: 28px; border-radius: 4px;
  background: var(--bg); border: 1px solid var(--border);
  cursor: pointer; transition: all 0.15s;
  position: relative;
}
.position-grid button::after {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-dim); transform: translate(-50%, -50%);
  transition: all 0.15s;
}
.position-grid button:hover { border-color: var(--accent); }
.position-grid button:hover::after { background: var(--accent); }
.position-grid button.active {
  border-color: var(--accent); background: var(--accent-dim);
}
.position-grid button.active::after {
  background: var(--accent); width: 8px; height: 8px;
  box-shadow: 0 0 6px rgba(232,168,56,0.4);
}

.timer-preview { flex: 1; }
.timer-preview-screen {
  aspect-ratio: 16/9; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px;
  position: relative; overflow: hidden; max-width: 200px;
}
.timer-preview-badge {
  position: absolute; padding: 3px 8px;
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  background: rgba(0,0,0,0.6); color: #fff; border-radius: 4px;
  transition: all 0.3s;
  /* default: bottom-center */
  bottom: 6px; left: 50%; transform: translateX(-50%);
}

/* Submit */
.submit-btn {
  width: 100%; padding: 14px;
  background: var(--accent); color: #000;
  border: none; border-radius: var(--radius);
  font-family: var(--sans); font-size: 15px; font-weight: 700;
  cursor: pointer; transition: all 0.2s;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  letter-spacing: -0.01em;
}
.submit-btn:hover { background: var(--accent-hover); transform: translateY(-1px); }
.submit-btn:active { transform: translateY(0); }
.submit-btn:disabled {
  background: var(--surface-2); color: var(--text-dim);
  cursor: not-allowed; transform: none;
}
.submit-btn:disabled svg { stroke: var(--text-dim); }
.submit-btn svg { stroke: #000; }

/* Job panel */
.job-panel {
  margin-top: 28px; padding: 24px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.job-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.job-header h2 { font-size: 15px; font-weight: 700; }
.job-id {
  display: block; font-family: var(--mono); font-size: 11px;
  color: var(--text-dim); margin-bottom: 18px;
}

/* Status badge */
.status-badge {
  padding: 3px 12px; border-radius: 20px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em;
}
.status-badge.pending { background: var(--blue-dim); color: var(--blue); }
.status-badge.processing {
  background: var(--accent-dim); color: var(--accent);
  animation: pulse 1.8s ease-in-out infinite;
}
.status-badge.done { background: var(--green-dim); color: var(--green); }
.status-badge.error { background: var(--red-dim); color: var(--red); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* Progress steps */
.progress-steps {
  display: flex; gap: 4px; margin-bottom: 18px;
}
.step {
  flex: 1; display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; border-radius: 6px;
  background: var(--bg); font-size: 10px; font-weight: 600;
  color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 0.04em; transition: all 0.3s;
}
.step-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--border); flex-shrink: 0; transition: all 0.3s;
}
.step.active { color: var(--accent); }
.step.active .step-dot {
  background: var(--accent); box-shadow: 0 0 6px rgba(232,168,56,0.5);
  animation: pulse 1.2s ease-in-out infinite;
}
.step.done { color: var(--green); }
.step.done .step-dot { background: var(--green); animation: none; }

/* Progress bar */
.progress-bar-container {
  position: relative; height: 28px; margin-bottom: 18px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; width: 0; background: var(--accent);
  border-radius: 6px; transition: width 0.5s ease;
}
.progress-bar-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: var(--text);
  font-family: var(--mono); pointer-events: none;
}

/* Metrics */
.metrics {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin-bottom: 16px;
}
.metric {
  padding: 10px 12px; background: var(--bg);
  border-radius: 6px; border: 1px solid var(--border);
}
.metric.total { border-color: var(--accent); background: var(--accent-dim); }
.metric-label {
  display: block; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dim); margin-bottom: 2px;
}
.metric-value {
  font-family: var(--mono); font-size: 13px; font-weight: 700; color: var(--text);
}
.metric.total .metric-value { color: var(--accent); }

/* Error panel */
.error-panel {
  padding: 12px 16px; background: var(--red-dim);
  border: 1px solid rgba(239,68,68,0.2); border-radius: 6px;
  color: var(--red); font-size: 13px; margin-bottom: 16px;
}

/* Result panel */
.result-panel { margin-top: 16px; }
.result-panel video {
  width: 100%; border-radius: 8px; background: #000;
  max-height: 420px; margin-bottom: 14px;
}
.download-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; background: var(--green);
  color: #000; border-radius: 6px; font-weight: 700;
  font-size: 13px; text-decoration: none;
  transition: all 0.2s;
}
.download-btn:hover { background: #34d46f; transform: translateY(-1px); }
.download-btn svg { stroke: #000; }

.hidden { display: none !important; }

/* History panel */
.history-panel {
  margin-top: 28px; padding: 24px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.history-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.history-header h2 { font-size: 15px; font-weight: 700; }
.refresh-btn {
  width: 30px; height: 30px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.refresh-btn:hover { border-color: var(--accent); color: var(--accent); }
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-empty { font-size: 13px; color: var(--text-dim); text-align: center; padding: 20px 0; }
.history-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
  transition: border-color 0.15s;
}
.history-item:hover { border-color: var(--border-hover); }
.history-item-info { flex: 1; min-width: 0; }
.history-item-date {
  font-family: var(--mono); font-size: 11px; color: var(--text-muted);
  margin-bottom: 2px;
}
.history-item-meta {
  font-size: 11px; color: var(--text-dim);
  display: flex; gap: 10px; flex-wrap: wrap;
}
.history-item-meta span { white-space: nowrap; }
.history-item .status-badge { flex-shrink: 0; font-size: 10px; }
.history-item-link {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 6px;
  background: var(--green-dim); color: var(--green);
  display: flex; align-items: center; justify-content: center;
  text-decoration: none; transition: all 0.15s;
}
.history-item-link:hover { background: var(--green); color: #000; }

/* Responsive */
@media (max-width: 600px) {
  .uploads-grid { grid-template-columns: 1fr; }
  .config-row { flex-direction: column; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .progress-steps { flex-wrap: wrap; }
}
