:root {
  --bg: #0e1116;
  --panel: #171c24;
  --panel2: #1e2530;
  --text: #e8ecf1;
  --muted: #93a0b0;
  --accent: #ff4d5a;
  --accent2: #ffb84d;
  --ok: #3ddc84;
  --border: #2a3341;
  font-size: 16px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
}
header {
  padding: 18px 28px 0;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #141922, var(--bg));
}
h1 { margin: 0 0 14px; font-size: 1.5rem; letter-spacing: 0.5px; }
h1 span { color: var(--accent); }
#steps { display: flex; gap: 8px; flex-wrap: wrap; }
#steps button {
  background: none; border: none; color: var(--muted);
  padding: 10px 14px; cursor: pointer; font-size: 0.95rem;
  border-bottom: 3px solid transparent;
}
#steps button.active { color: var(--text); border-bottom-color: var(--accent); }
#steps button.done { color: var(--ok); }
main { max-width: 1100px; margin: 0 auto; padding: 24px 28px 80px; }
.step { display: none; }
.step.active { display: block; animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
h2 { margin-top: 8px; }
h2 small { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.hint { color: var(--muted); font-size: 0.9rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 14px 0; }
input, select, textarea {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 0.95rem; font-family: inherit;
}
input { flex: 1; min-width: 240px; }
textarea { width: 100%; resize: vertical; }
button.primary {
  background: var(--accent); color: #fff; border: none;
  padding: 11px 18px; border-radius: 8px; font-size: 0.95rem;
  cursor: pointer; font-weight: 600; white-space: nowrap;
}
button.primary:hover { filter: brightness(1.1); }
button.primary:disabled { opacity: 0.5; cursor: wait; }
button.primary.big { font-size: 1.05rem; padding: 14px 26px; }
.btnlink { display: inline-block; text-decoration: none; text-align: center;
  background: var(--accent); color: #fff; padding: 11px 18px; border-radius: 8px; font-weight: 600; }
.status { color: var(--accent2); min-height: 1.2em; margin: 8px 0; white-space: pre-wrap; }
.status.error { color: #ff7b7b; }
.status.ok { color: var(--ok); }
.warn { background: #3a2a12; border: 1px solid #7a5a20; color: #ffcf87;
  padding: 10px 14px; border-radius: 8px; margin: 10px 0 14px; font-size: 0.9rem; }
.hidden { display: none !important; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.grid2 label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
label.inline { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-top: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; cursor: pointer; transition: border-color 0.15s;
}
.card:hover { border-color: var(--accent); }
.card.selected { border-color: var(--ok); box-shadow: 0 0 0 1px var(--ok); }
.card h4 { margin: 0 0 6px; }
.card .meta { font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }
.card ul { margin: 8px 0 0; padding-left: 18px; font-size: 0.85rem; color: var(--muted); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 0.72rem; margin-right: 6px; }
.badge.low { background: #14401f; color: var(--ok); }
.badge.medium { background: #403714; color: var(--accent2); }
.badge.high { background: #401414; color: #ff7b7b; }

.scene {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; margin: 12px 0;
}
.scene .n { color: var(--accent); font-weight: 700; }
.scene .visual { color: var(--muted); font-size: 0.82rem; margin-top: 6px; }
.clip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-top: 10px; }
.clip-grid .thumb {
  position: relative; border-radius: 8px; overflow: hidden; cursor: pointer;
  aspect-ratio: 9/16; border: 2px solid transparent; background: #000;
}
.clip-grid .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.clip-grid .thumb.selected { border-color: var(--ok); }
.clip-grid .thumb .dur { position: absolute; bottom: 4px; right: 6px; font-size: 0.7rem;
  background: rgba(0,0,0,0.7); padding: 1px 5px; border-radius: 4px; }

/* Hover-to-preview: the real clip plays over its poster. It only fades in once
   frames have decoded (.ready), so the poster is never swapped for a black box. */
.clip-grid .thumb video.hover-preview {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity 0.18s ease; pointer-events: none; background: #000;
}
.clip-grid .thumb video.hover-preview.ready { opacity: 1; }
.clip-grid .thumb.previewing .dur { opacity: 0.85; }
.clip-grid .thumb::after {
  content: "▶"; position: absolute; top: 4px; left: 6px; font-size: 0.62rem;
  color: rgba(255,255,255,0.75); text-shadow: 0 1px 3px #000;
  opacity: 0; transition: opacity 0.18s ease; pointer-events: none;
}
.clip-grid .thumb:hover::after { opacity: 1; }
.scene audio { width: 100%; margin-top: 8px; }

.style-card { text-align: center; }
.style-card .preview {
  background: #000 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Crect width='40' height='40' fill='%23222'/%3E%3C/svg%3E");
  border-radius: 8px; height: 120px; display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 1.3rem; margin-bottom: 10px; font-family: "Arial Black", Arial, sans-serif;
}
#result-video { width: 300px; max-width: 100%; border-radius: 12px; border: 1px solid var(--border); display: block; margin: 16px 0; }
pre { background: var(--panel); padding: 14px; border-radius: 8px; white-space: pre-wrap; font-size: 0.82rem; color: var(--muted); }
.log {
  list-style: none; margin: 10px 0; padding: 12px 16px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  max-height: 220px; overflow-y: auto; font-size: 0.85rem; color: var(--muted);
}
.log li { padding: 3px 0; animation: fade 0.2s ease; }
.log li:last-child { color: var(--text); }
.pack-block { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin: 12px 0; }
.pack-block h4 { margin: 0 0 8px; display: flex; align-items: center; gap: 10px; }
.pack-block h4 small { color: var(--muted); font-weight: 400; }
.pack-block pre { margin: 0; background: var(--panel2); color: var(--text); }
.pack-block ul { margin: 0; padding-left: 20px; }
button.copy {
  background: var(--panel2); border: 1px solid var(--border); color: var(--muted);
  font-size: 0.72rem; padding: 3px 10px; border-radius: 6px; cursor: pointer;
}
button.copy:hover { color: var(--text); border-color: var(--accent); }
.header-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.header-actions { display: flex; gap: 8px; }
button.ghost {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 0.88rem;
}
button.ghost:hover { border-color: var(--accent); }
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 20px; margin: 12px 0;
}
.panel h3 { margin: 0 0 10px; }
.panel h3 small { color: var(--muted); font-weight: 400; font-size: 0.8rem; }
.panel label { display: block; color: var(--muted); font-size: 0.9rem; margin: 8px 0 4px; }
.panel textarea, .panel input { width: 100%; }
.project-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 6px;
}
.project-row:hover { background: var(--panel2); }
.project-row .meta { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.project-row:hover { background: var(--panel2); }
button.ghost.small { padding: 4px 10px; font-size: 0.75rem; }
.project-row .p-status { font-size: 0.75rem; min-width: 0; }
.ai-panel {
  background: var(--panel2); border: 1px solid var(--border);
  border-left: 3px solid var(--accent2); border-radius: 8px;
  padding: 12px 14px; margin: 10px 0;
}
.ai-panel .ai-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.ai-panel pre { background: var(--bg); color: var(--text); font-size: 0.84rem; margin: 0; }
.ai-panel details { margin-top: 8px; }
.ai-panel details pre { font-size: 0.78rem; color: var(--muted); margin-top: 6px; }
.ai-upload {
  display: inline-block; margin-top: 10px; padding: 8px 12px;
  background: var(--panel); border: 1px dashed var(--border); border-radius: 8px;
  font-size: 0.85rem; color: var(--muted); cursor: pointer;
}
.ai-upload:hover { border-color: var(--ok); color: var(--text); }
.ai-upload input { display: block; margin-top: 6px; }
.brief-field { display: block; margin: 10px 0; color: var(--muted); font-size: 0.9rem; }
.brief-field small { color: var(--muted); font-size: 0.78rem; }
.brief-field input, .brief-field textarea { width: 100%; margin-top: 4px; }
.topic-row {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.topic-row:hover { background: var(--panel2); }
.topic-row.done { opacity: 0.62; }
.topic-row .t-main { flex: 1; min-width: 0; }
.topic-row .t-title { margin-bottom: 4px; }
.topic-row .t-hook { color: var(--accent2); font-size: 0.86rem; }
.topic-row .t-sum { font-size: 0.82rem; margin-top: 2px; }
.topic-row .t-actions { display: flex; gap: 6px; flex-shrink: 0; }
.topic-row .t-actions button { font-size: 0.8rem; padding: 6px 10px; }
.cost { color: var(--accent2); }
.usage {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; margin: 10px 0; font-size: 0.88rem;
}
.usage .hint { font-size: 0.78rem; }
.progress-bar { background: var(--panel2); border-radius: 8px; height: 10px; overflow: hidden; margin: 10px 0; }
.progress-bar div { background: var(--ok); height: 100%; transition: width 0.3s; }
.storage-bar {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px 14px; border-bottom: 1px solid var(--border);
  margin-bottom: 6px; font-size: 0.88rem;
}
.storage-bar .progress-bar { margin: 0; height: 8px; }
.storage-bar .progress-bar div { height: 100%; transition: width 0.3s; }
.sfx-result {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 8px; margin: 6px 0; background: var(--panel2);
}
.sfx-result.selected { border-color: var(--ok); }
.sfx-result .t { flex: 1; font-size: 0.85rem; }
.sfx-result .t small { color: var(--muted); display: block; }
.sfx-result audio { height: 30px; max-width: 220px; }
.sfx-result button { white-space: nowrap; }
details summary { cursor: pointer; color: var(--muted); margin-top: 14px; }
progress { width: 100%; }
