:root {
  --accent: #ff5a1f;
  --accent-text: #1a0d06;
  --radius: 12px;
}

/* Dark theme (default) */
:root, :root[data-theme="dark"] {
  --bg: #0e1013;
  --sidebar: #15181e;
  --panel: #171a21;
  --panel-head: #1b1f28;
  --input: #0e1013;
  --border: #2a2e38;
  --text: #e8e9ed;
  --muted: #8b90a0;
  --hover: #22262f;
}

/* Light theme */
:root[data-theme="light"] {
  --bg: #f4f5f7;
  --sidebar: #ffffff;
  --panel: #ffffff;
  --panel-head: #f7f8fa;
  --input: #ffffff;
  --border: #e2e5ea;
  --text: #1a1d23;
  --muted: #6b7180;
  --hover: #eef0f3;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---- App shell ---- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 17px;
  line-height: 1.1;
}
.sidebar-brand small { color: var(--muted); font-weight: 600; font-size: 11px; }
.logo-dot { font-size: 22px; }

.sidebar-section { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.sidebar-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-bottom: 10px; font-weight: 700;
}
.history-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.history-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

.history-item {
  display: flex; gap: 10px; align-items: center;
  padding: 8px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent;
}
.history-item:hover { background: var(--hover); }
.history-item.active { border-color: var(--accent); background: var(--hover); }
.history-thumb { width: 38px; height: 68px; object-fit: cover; border-radius: 6px; background: #000; flex-shrink: 0; }
.history-meta { min-width: 0; flex: 1; }
.history-title { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-del { color: var(--muted); font-size: 15px; opacity: 0; border: none; background: none; cursor: pointer; padding: 2px 4px; }
.history-item:hover .history-del { opacity: 1; }
.history-badge { font-size: 10px; color: var(--accent); font-weight: 700; }

.sidebar-footer { display: flex; flex-direction: column; gap: 10px; }
.sidebar-hint { font-size: 11px; color: var(--muted); text-align: center; }

/* ---- Main ---- */
.main { flex: 1; min-width: 0; padding: 28px 32px 80px; max-width: 920px; }
.main-header { margin-bottom: 22px; }
.main-header h1 { font-size: 24px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0; }

/* ---- Panels ---- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; background: var(--panel-head);
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.panel-head h2 { font-size: 15px; margin: 0; }
.panel-head .hint { margin-left: auto; }
.panel-body { padding: 18px; }
.step {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  font-size: 12px; font-weight: 800; flex-shrink: 0;
}

/* ---- Fields ---- */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13.5px; }
.field label.check { font-weight: 600; }
.hint { color: var(--muted); font-weight: 400; font-size: 12px; }

input[type="text"], input[type="number"], input[type="file"], select, textarea {
  width: 100%; background: var(--input);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 10px 12px; font-size: 14px; font-family: inherit;
}
textarea { resize: vertical; }
input[type="color"] { width: 100%; height: 40px; background: var(--input); border: 1px solid var(--border); border-radius: 8px; padding: 4px; }

.row { display: flex; gap: 14px; flex-wrap: wrap; }
.half { flex: 1 1 220px; }
.third { flex: 1 1 150px; }

.radio-row { display: flex; gap: 14px; margin-bottom: 8px; font-size: 13px; }
.radio-row label { font-weight: 400; margin: 0; }

/* ---- Buttons ---- */
.primary-btn {
  background: var(--accent); color: var(--accent-text);
  border: none; border-radius: 8px; padding: 11px 18px;
  font-size: 14px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn.full, .ghost-btn.full { width: 100%; }
.primary-btn.big { padding: 14px; font-size: 15px; }

.ghost-btn {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 16px; font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.ghost-btn:hover { background: var(--hover); }

.mini-btn {
  background: var(--hover); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.mini-btn:hover { filter: brightness(1.1); }
.mini-btn.danger { color: #e8897b; }
.sound-defaults { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.logo-preview { display: block; height: 52px; width: auto; max-width: 180px; margin: 8px 0; object-fit: contain; background: #fff; border-radius: 8px; padding: 6px; }

button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Progress ---- */
.progress-overall { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
.progress-overall .progress-bar { flex: 1; margin: 0; }
.progress-bar { height: 10px; background: var(--input); border-radius: 6px; overflow: hidden; border: 1px solid var(--border); margin: 12px 0; }
.progress-bar.slim { height: 6px; margin: 6px 0 0; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.15s linear; }
.progress-pct { font-weight: 700; font-size: 18px; min-width: 52px; text-align: right; color: var(--accent); }
.muted { color: var(--muted); }
.upload-files-title { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin: 16px 0 8px; }
.upload-file { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: var(--panel-head); }
.upload-file.active { border-color: var(--accent); }
.upload-file.done { opacity: 0.75; }
.upload-file.error { border-color: #e85d4c; background: rgba(232, 93, 76, 0.08); }
.upload-file.error .upload-file-pct { color: #e85d4c; }
.upload-file-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.upload-file-name { font-weight: 600; word-break: break-all; }
.upload-file-pct { font-size: 13px; font-weight: 700; white-space: nowrap; color: var(--accent); }
.upload-file.done .upload-file-pct { color: #4caf7a; }
.upload-file-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---- Result ---- */
.result-top { display: flex; gap: 20px; margin-bottom: 18px; flex-wrap: wrap; }
.result-top video { width: 300px; max-width: 100%; border-radius: var(--radius); background: #000; }
.result-side { display: flex; flex-direction: column; gap: 10px; justify-content: center; }
.result-side h2 { margin: 0 0 4px; }

/* ---- BGM picker ---- */
.bgm-picker { display: flex; flex-direction: column; gap: 8px; }
.bgm-picker audio { width: 100%; height: 34px; }
.bgm-actions, .bgm-upload { display: flex; gap: 8px; align-items: center; }
.bgm-upload input[type="file"] { flex: 1; font-size: 12px; }

/* ---- Timeline editor cards ---- */
#timeline-cards { display: flex; flex-direction: column; gap: 10px; margin: 0 0 14px; }
.seg-card { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--panel-head); }
.seg-header { display: flex; align-items: center; gap: 12px; padding: 8px 12px; cursor: pointer; user-select: none; }
.seg-header:hover { background: var(--hover); }
.seg-thumb { width: 54px; height: 96px; object-fit: cover; border-radius: 6px; background: #000; flex-shrink: 0; }
.seg-index { color: var(--muted); font-size: 12px; width: 24px; flex-shrink: 0; }
.seg-summary { flex: 1; min-width: 0; }
.seg-caption-preview { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg-clip-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg-chevron { color: var(--muted); transition: transform 0.15s ease; flex-shrink: 0; }
.seg-card.expanded .seg-chevron { transform: rotate(90deg); }
.seg-editor { display: none; padding: 16px; border-top: 1px solid var(--border); }
.seg-card.expanded .seg-editor { display: block; }
.seg-editor label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }

.clip-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.clip-thumb-btn { border: 2px solid var(--border); border-radius: 8px; padding: 0; background: #000; cursor: pointer; width: 64px; height: 114px; overflow: hidden; }
.clip-thumb-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.clip-thumb-btn.selected { border-color: var(--accent); }

.preview-row { display: flex; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.preview-row video { width: 220px; max-width: 100%; border-radius: 8px; background: black; }
.inout-controls { display: flex; flex-direction: column; gap: 10px; justify-content: center; }
.inout-field { display: flex; align-items: center; gap: 8px; }
.inout-field label { margin: 0; width: 36px; font-size: 13px; }
.inout-field input { width: 80px; }
.inout-field button { padding: 6px 10px; font-size: 12px; }

.highlight-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.word-chip { background: var(--input); border: 1px solid var(--border); color: var(--text); border-radius: 999px; padding: 5px 12px; font-size: 12.5px; cursor: pointer; }
.word-chip.highlighted { background: #ffd000; border-color: #ffd000; color: #1a1200; font-weight: 700; }

code { background: var(--input); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; font-size: 12px; }

.hidden { display: none; }
.error { border-color: #c0392b; }
.error h2 { color: #e74c3c; }
a#download-link { color: var(--accent-text); }

/* ---- Responsive ---- */
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar-section { width: 100%; }
  .main { padding: 20px 16px 60px; }
}
