:root {
  --bg: #0c0d10;
  --panel: #16181d;
  --panel-2: #1e2127;
  --border: #2a2e37;
  --text: #e9ebf0;
  --muted: #8b909c;
  --accent: #f97316;
  --accent-2: #6366f1;
  --danger: #ef4444;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Space Grotesk", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 70% -10%, #1a1430 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: rgba(12,13,16,.8); backdrop-filter: blur(10px); z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 18px; }
.brand .back { font-size: 20px; margin-right: 4px; color: var(--muted); }
.dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: inline-block; }
.user { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.avatar { width: 30px; height: 30px; border-radius: 50%; }

.container { max-width: 1100px; margin: 0 auto; padding: 28px 24px 80px; }
h1 { font-size: 34px; margin: 0 0 6px; }
h2 { font-size: 20px; margin: 32px 0 14px; }

.hero { padding: 28px 0 8px; }
.newproject { display: flex; gap: 10px; margin-top: 18px; }
.newproject input { flex: 1; max-width: 420px; }

input, textarea, select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 11px 13px; font: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent-2); }
textarea { width: 100%; resize: vertical; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

.btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 18px; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 500;
  transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--accent-2); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #fb923c); border: none; color: #1a0f00; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.composer { padding: 20px; }
.composer .row { display: flex; gap: 14px; align-items: flex-end; margin-top: 12px; flex-wrap: wrap; }
.composer .row label { min-width: 150px; }
.composer button { margin-left: auto; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.card.project { overflow: hidden; transition: .15s; }
.card.project:hover { transform: translateY(-3px); border-color: var(--accent-2); }
.thumb { aspect-ratio: 16/9; background: linear-gradient(135deg, #20232b, #2b2030); display: grid; place-items: center; color: var(--muted); font-size: 26px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-body { padding: 12px 14px; }
.card-title { font-weight: 600; margin-bottom: 3px; }

.clips .clip { overflow: hidden; display: flex; flex-direction: column; }
.clip-media { aspect-ratio: 16/9; background: #000; display: grid; place-items: center; }
.clip-media video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.pending { display: flex; flex-direction: column; gap: 10px; align-items: center; color: var(--muted); font-size: 13px; }
.pending.failed { color: var(--danger); }
.prompt { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 32px; }
.actions { display: flex; gap: 8px; margin-top: 12px; }

.spinner { width: 26px; height: 26px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner { padding: 12px 14px; border-radius: 10px; margin: 10px 0; font-size: 14px; }
.banner.error { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.4); color: #fca5a5; }
.hidden { display: none !important; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 10; }
.modal-box { padding: 22px; width: 460px; max-width: 92vw; display: flex; flex-direction: column; gap: 12px; }
.modal-box h3 { margin: 0; }
.row.end { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Scene editor ---------- */
body.editor { background: #000; display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.editor-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 18px; border-bottom: 1px solid #161616; background: #050505; }
.eb-left, .eb-right { display: flex; align-items: center; gap: 12px; flex: 1; }
.eb-right { justify-content: flex-end; }
.scene-title { font-size: 14px; color: #cfd2d8; }
.iconbtn { background: transparent; border: none; color: #cfd2d8; font-size: 18px; cursor: pointer; padding: 6px 8px; border-radius: 8px; line-height: 1; }
.iconbtn:hover { background: #1a1a1a; }
.eb-center { display: flex; gap: 6px; flex: 0 0 auto; }
.hist-thumb { width: 42px; height: 30px; border-radius: 6px; background-size: cover; background-position: center; cursor: pointer; border: 2px solid transparent; opacity: .8; }
.hist-thumb:hover { border-color: var(--accent-2); opacity: 1; }
.hist-thumb.pending { filter: grayscale(1) brightness(.5); }

.stage { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; gap: 24px; padding: 24px 28px; min-height: 0; }
.ar-badge { position: absolute; left: 18px; top: 18px; font-size: 12px; color: #6b6f78; border: 1px solid #222; border-radius: 6px; padding: 2px 8px; }
.player-col { display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 70%; min-width: 0; }
.player-wrap { position: relative; background: #000; border-radius: 12px; overflow: hidden; display: grid; place-items: center; max-height: 62vh; }
#player { max-width: 100%; max-height: 62vh; display: block; background: #000; }
.empty-stage { display: none; width: 520px; height: 290px; place-items: center; color: #555; }
.controls { display: flex; align-items: center; gap: 14px; background: #0c0c0c; border: 1px solid #1c1c1c; border-radius: 999px; padding: 6px 16px; }
.controls .time { font-size: 12px; color: #9aa0aa; font-variant-numeric: tabular-nums; }
.controls .play { font-size: 20px; }

.extend-panel { width: 300px; flex: 0 0 300px; padding: 16px; display: flex; flex-direction: column; gap: 12px; background: #0d0e12; align-self: center; }
.ep-head { display: flex; gap: 12px; align-items: center; }
.ep-thumb { width: 70px; height: 44px; border-radius: 8px; background: #222 center/cover; flex: 0 0 auto; }
.ep-title { font-weight: 600; font-size: 14px; }
.extend-panel textarea, .extend-panel select { width: 100%; }
.btn.block { width: 100%; justify-content: center; }

.timeline { background: #050505; border-top: 1px solid #161616; padding: 14px 18px 18px; }
.tl-inner { position: relative; }
.track { display: flex; gap: 4px; height: 64px; }
.seg { position: relative; display: flex; border-radius: 8px; overflow: hidden; border: 2px solid transparent; cursor: pointer; min-width: 60px; background: #111; }
.seg.active { border-color: var(--accent); }
.seg .frame { flex: 1; background-size: cover; background-position: center; border-right: 1px solid rgba(0,0,0,.4); }
.seg-tag { position: absolute; left: 6px; bottom: 4px; right: 26px; font-size: 11px; color: #fff; text-shadow: 0 1px 3px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg-dl { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 6px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; opacity: 0; transition: .15s; text-decoration: none; }
.seg:hover .seg-dl { opacity: 1; }
.seg-dl:hover { background: var(--accent); color: #1a0f00; }
#mergeBtn.busy { opacity: .6; pointer-events: none; }
.seg.rendering { align-items: center; justify-content: center; border: 1px dashed #333; background: #0c0c0c; }
.seg-rendering { display: flex; align-items: center; gap: 8px; color: #888; font-size: 12px; }
.playhead { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--accent); left: 0; pointer-events: none; box-shadow: 0 0 8px var(--accent); }
.playhead::before { content: ""; position: absolute; top: -5px; left: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 360px; max-width: 92vw; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-brand { font-size: 18px; font-weight: 600; }
.login-title { font-size: 24px; margin: 4px 0 6px; }
.login-card label { color: var(--muted); font-size: 13px; }
.login-card input { width: 100%; margin-top: 6px; }
