:root {
  --bg: #0f0f14;
  --bg-elevated: #171722;
  --border: #2a2a3a;
  --text: #ececf4;
  --muted: #9a9ab0;
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 12px;
  --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--accent-hover); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #222233; padding: 0.1rem 0.35rem; border-radius: 4px; }

.app-shell { min-height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: #12121a;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; flex-shrink: 0; }
.nav { display: flex; gap: 0.75rem; flex: 1; min-width: 0; flex-wrap: wrap; }
.logout-form { flex-shrink: 0; margin-left: auto; }
.nav a { color: var(--muted); padding: 0.35rem 0.6rem; border-radius: 8px; }
.nav a.active, .nav a:hover { color: var(--text); background: var(--bg-elevated); text-decoration: none; }
.main-content { padding: 1.25rem; max-width: 1200px; margin: 0 auto; }

.btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  font: inherit;
}
.btn-primary { background: var(--accent); border-color: transparent; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { border-color: var(--accent); }
.btn-ghost { background: transparent; }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.project-card {
  display: block;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  color: inherit;
  text-decoration: none;
}
.project-card:hover { border-color: var(--accent); text-decoration: none; }
.empty-state, .auth-card, .panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.auth-card { max-width: 420px; margin: 4rem auto; }
.stack { display: grid; gap: 0.75rem; }
.stack.compact { margin-bottom: 1rem; }
label { display: grid; gap: 0.35rem; font-size: 0.95rem; }
input, textarea {
  width: 100%;
  background: #0c0c12;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.65rem;
  font: inherit;
}
textarea { resize: vertical; min-height: 120px; }
.muted { color: var(--muted); }
.alert { padding: 0.65rem 0.75rem; border-radius: 8px; }
.alert-error { background: rgba(248, 113, 113, 0.12); color: #fecaca; }
.alert-warn { background: rgba(251, 191, 36, 0.12); color: #fde68a; }
.btn-danger {
  background: rgba(248, 113, 113, 0.18);
  border: 1px solid rgba(248, 113, 113, 0.45);
  color: #fecaca;
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.28); }
.danger-zone {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(260px, 0.9fr);
  gap: 1rem;
}
@media (max-width: 860px) {
  .split-layout { grid-template-columns: 1fr; }
}
.step-nav { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 1rem; }
.step-nav button {
  background: #0c0c12;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
}
.step-nav button.active { color: var(--text); border-color: var(--accent); }
.step-nav button:disabled { opacity: 0.45; cursor: not-allowed; }
.scene-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.65rem; }
.scene-list li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.65rem;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.scene-thumb {
  max-width: 100%;
  max-height: 120px;
  border-radius: 8px;
  margin-bottom: 0.35rem;
  display: block;
}
.scene-upload { border-top: 1px solid var(--border); padding-top: 0.65rem; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.video-preview { width: 100%; max-height: 360px; background: #000; border-radius: 8px; }
.scene-index {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  background: var(--accent);
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.scene-list-editable li { align-items: start; }
.scene-editor-body { display: grid; gap: 0.5rem; min-width: 0; }
.scene-duration-label input { max-width: 8rem; }
.scene-move-row { margin-top: 0.15rem; }
.scene-timeline-summary { margin-bottom: 0.75rem; }
.timeline-hint { font-size: 0.88rem; color: var(--muted); }
.scene-editor-form { margin-top: 0.5rem; }
.meta-list { display: grid; gap: 0.5rem; }
.meta-list div { display: flex; justify-content: space-between; gap: 1rem; }
.meta-list dt { color: var(--muted); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 0.55rem 0.35rem;
}
.status-pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.85rem;
  background: #222233;
}
.status-completed { background: rgba(34, 197, 94, 0.15); }
.status-failed, .status-interrupted { background: rgba(248, 113, 113, 0.15); }
.status-running, .status-queued { background: rgba(139, 92, 246, 0.15); }
.alert-ok { background: rgba(34, 197, 94, 0.12); border: 1px solid rgba(34, 197, 94, 0.35); }
.h3 { font-size: 1rem; margin: 0.75rem 0 0.35rem; }
.narration-block audio,
.music-block audio { width: 100%; margin-top: 0.35rem; }
.subtitle-block,
.music-block,
.motion-block,
.style-presets-block {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #12121a;
}
.style-diff-list {
  margin: 0.35rem 0 0.5rem;
  padding-left: 1.1rem;
  font-size: 0.92rem;
}
.style-diff-before {
  opacity: 0.75;
  text-decoration: line-through;
}
.style-diff-after {
  color: var(--accent, #a78bfa);
}
.style-presets-block select,
.style-presets-block .btn {
  max-width: 100%;
}
.motion-block select {
  width: 100%;
  max-width: 100%;
}
.job-live-panel { margin: 0.75rem 0; padding: 0.65rem; border-radius: 8px; background: rgba(139, 92, 246, 0.08); }
.job-live-line { margin: 0.25rem 0; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
[x-cloak] { display: none !important; }

@media (max-width: 480px) {
  .topbar {
    flex-wrap: wrap;
    gap: 0.45rem;
    padding: 0.55rem 0.75rem;
  }
  .brand {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .logout-form {
    order: 2;
  }
  .logout-form .btn {
    padding: 0.35rem 0.55rem;
    font-size: 0.85rem;
  }
  .logout-user { display: none; }
  .nav {
    order: 3;
    flex: 1 1 100%;
    gap: 0.25rem;
  }
  .nav a {
    padding: 0.3rem 0.45rem;
    font-size: 0.88rem;
  }
  .subtitle-block,
  .music-block,
  .motion-block,
  .style-presets-block {
    overflow-wrap: anywhere;
  }
  .motion-block select,
  .style-presets-block select {
    width: 100%;
  }
  .style-presets-block .btn {
    width: 100%;
  }
  .subtitle-block .btn-row,
  .music-block .btn-row {
    flex-direction: column;
    align-items: stretch;
  }
  .subtitle-block .btn-row .btn,
  .music-block .btn-row .btn {
    width: 100%;
  }
  .music-block input[type="number"] {
    width: 100%;
  }
}
