:root {
  --bg: #0b0c0f;
  --panel: #12141a;
  --panel-2: #171a21;
  --line: #23262f;
  --text: #e7e9ee;
  --dim: #8b91a1;
  --accent: #7cf5c4;
  --accent-dim: #2c6f58;
  --warn: #f5b97c;
  --bad: #f57c7c;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

.app { display: grid; grid-template-columns: 340px 1fr; height: 100vh; }

/* ---------- panel ---------- */
.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand h1 { font-size: 15px; margin: 0; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; font-size: 11px; color: var(--dim); font-family: var(--mono); }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 12px var(--accent);
  flex: none;
}
.dot.busy { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); }
.hint { font-size: 11px; color: var(--dim); }
input, textarea, select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  width: 100%;
  resize: vertical;
}
textarea { font-size: 13px; line-height: 1.4; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent-dim); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--dim); }
.check input { width: auto; }
.check em { font-style: normal; opacity: .7; }
.adv summary {
  cursor: pointer; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--dim); padding: 6px 0;
}
.adv[open] summary { color: var(--text); }
.adv > *:not(summary) { margin-top: 10px; }

button {
  font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid transparent;
  padding: 10px 14px; font-weight: 600;
}
.go { background: var(--accent); color: #06120d; }
.go:hover { filter: brightness(1.08); }
.go:disabled { opacity: .45; cursor: default; }
.stop { background: transparent; border-color: var(--bad); color: var(--bad); }

.log {
  margin-top: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  border-top: 1px solid var(--line);
  padding-top: 10px;
  max-height: 190px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.log b { color: var(--text); font-weight: 500; }
.log .e { color: var(--bad); }

/* ---------- stage ---------- */
.stage { display: flex; flex-direction: column; min-width: 0; padding: 18px; gap: 12px; }
.stage-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tabs { display: flex; gap: 4px; background: var(--panel); padding: 4px; border-radius: 10px; border: 1px solid var(--line); }
.tab { background: transparent; color: var(--dim); padding: 6px 12px; font-size: 12px; font-weight: 500; border-radius: 7px; }
.tab.active { background: var(--panel-2); color: var(--text); }
.tab:disabled { opacity: .4; cursor: default; }
.stats { display: flex; gap: 16px; font-family: var(--mono); font-size: 11px; color: var(--dim); }
.stats b { color: var(--text); font-weight: 500; }
.stats .rt-ok b { color: var(--accent); }
.stats .rt-low b { color: var(--warn); }

.viewport { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.screen {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.screen video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
}
#finalScreen video { position: relative; }
.screen video.behind { opacity: 0; pointer-events: none; }
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at center, rgba(11,12,15,.55), rgba(11,12,15,.9));
  backdrop-filter: blur(2px);
  text-align: center;
  font-size: 13px;
  color: var(--dim);
}
.ov-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.badge {
  position: absolute; left: 12px; bottom: 12px;
  font-family: var(--mono); font-size: 11px;
  background: rgba(0,0,0,.6); border: 1px solid var(--line);
  padding: 4px 8px; border-radius: 6px; color: var(--text);
}
.badge:empty { display: none; }

.scrub { height: 4px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.scrub .bar { height: 100%; width: 0; background: var(--accent); transition: width .12s linear; }

.filmstrip { display: flex; gap: 8px; overflow-x: auto; min-height: 76px; padding-bottom: 4px; }
.cell {
  position: relative; flex: none; width: 128px; height: 72px;
  border-radius: 8px; overflow: hidden; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2);
}
.cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cell.pending { display: flex; align-items: center; justify-content: center; }
.cell.pending::after {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--dim);
  animation: spin .9s linear infinite;
}
.cell.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.cell .n {
  position: absolute; left: 5px; top: 4px;
  font-family: var(--mono); font-size: 10px;
  background: rgba(0,0,0,.65); padding: 1px 5px; border-radius: 4px;
}
.cell .rt {
  position: absolute; right: 5px; bottom: 4px;
  font-family: var(--mono); font-size: 10px;
  background: rgba(0,0,0,.65); padding: 1px 5px; border-radius: 4px; color: var(--accent);
}
.cell .rt.low { color: var(--warn); }
.dl {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--accent); text-decoration: none;
  font-family: var(--mono);
}

.scrub { position: relative; }
.scrub .buf {
  position: absolute; inset: 0 auto 0 0; width: 0;
  background: var(--accent-dim); transition: width .2s linear;
}
.scrub .bar { position: relative; }

.restyle-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.restyle-box .lbl em { font-style: normal; color: var(--accent); text-transform: none; letter-spacing: 0; }
.restyle-box textarea { background: var(--panel); font-size: 12px; }
.alt { background: transparent; border-color: var(--accent-dim); color: var(--accent); }
.alt:hover:not(:disabled) { background: rgba(124, 245, 196, .08); }
.alt:disabled { opacity: .4; cursor: default; }
#restyleStatus:not(:empty) { font-family: var(--mono); color: var(--accent); }
#restyleStatus.err { color: var(--bad); }
#restyledScreen video, #finalScreen video { position: relative; width: 100%; height: 100%; }

.alt.ready {
  background: rgba(124, 245, 196, .12);
  border-color: var(--accent);
  animation: nudge 1.6s ease-in-out 3;
}
@keyframes nudge { 50% { background: rgba(124, 245, 196, .26); } }

/* ---------- background jobs ---------- */
.jobs { display: flex; flex-direction: column; gap: 8px; }
.jobs:empty { display: none; }
.job {
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
  padding: 10px 12px; display: flex; flex-direction: column; gap: 7px;
}
.job.done { border-color: var(--accent-dim); }
.job.failed { border-color: var(--bad); }
.job-head { display: flex; align-items: baseline; gap: 10px; font-size: 12.5px; }
.job-head b { font-weight: 600; }
.job-head .id { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.job-head .right { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--dim); }
.job-bar { height: 5px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.job-bar i { display: block; height: 100%; background: var(--accent); transition: width .4s ease; }
.job.failed .job-bar i { background: var(--bad); }
.job-steps { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  font-family: var(--mono); font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: var(--panel-2); color: var(--dim); border: 1px solid var(--line);
}
.chip.running { color: var(--accent); border-color: var(--accent-dim); }
.chip.done { color: var(--text); }
.chip.failed { color: var(--bad); border-color: var(--bad); }
.job-note { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.job-note.err { color: var(--bad); }
.job a { color: var(--accent); font-family: var(--mono); font-size: 11px; }

.lbl em.sub { font-style: normal; color: var(--accent); text-transform: none; letter-spacing: 0; }
.hint b { color: var(--text); font-weight: 500; }

/* Running bars animate so a slowly-creeping fraction cannot be mistaken for a stall,
   and finished bars go quiet so they do not read as in-progress. */
.job-bar i.live {
  background-image: linear-gradient(100deg,
    rgba(11,12,15,.32) 0 12px, rgba(255,255,255,.10) 12px 24px, rgba(11,12,15,.32) 24px 36px);
  background-size: 36px 100%;
  animation: crawl 1.1s linear infinite;
}
@keyframes crawl { to { background-position: 36px 0; } }
.job.done .job-bar i { background: var(--accent-dim); }
.job-pct { font-family: var(--mono); font-size: 11px; color: var(--accent); }
.job.done .job-pct { color: var(--dim); }
.job-head .tag {
  font-family: var(--mono); font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--dim);
}
.job.done .job-head .tag { color: var(--accent); border-color: var(--accent-dim); }
.job.failed .job-head .tag { color: var(--bad); border-color: var(--bad); }

/* ---------- generation history ---------- */
.history { border-top: 1px solid var(--line); padding-top: 12px; }
.history > summary {
  cursor: pointer; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--dim); padding: 2px 0 10px;
}
.history[open] > summary { color: var(--text); }
.history > summary em { font-style: normal; color: var(--dim); text-transform: none; letter-spacing: 0; }
.history-list { display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow-y: auto; }
.hrow {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--panel);
  padding: 7px 10px 7px 7px;
}
.hrow.busy { border-color: var(--accent-dim); }
.hrow img {
  width: 96px; height: 54px; object-fit: cover; border-radius: 5px;
  background: var(--panel-2); flex: none;
}
.hrow .noimg { width: 96px; height: 54px; border-radius: 5px; background: var(--panel-2); flex: none; }
.hrow .meta { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.hrow .p { font-size: 12.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hrow .sub { font-family: var(--mono); font-size: 10.5px; color: var(--dim); }
.hrow .sub b { color: var(--text); font-weight: 500; }
.hrow .acts { display: flex; gap: 6px; flex: none; }
.hrow button {
  font-size: 11.5px; padding: 5px 10px; border-radius: 7px;
  background: transparent; border: 1px solid var(--line); color: var(--dim); font-weight: 500;
}
.hrow button:hover:not(:disabled) { color: var(--text); border-color: var(--accent-dim); }
.hrow button.go2 { border-color: var(--accent-dim); color: var(--accent); }
.hrow button:disabled { opacity: .4; cursor: default; }
.hrow .pill {
  font-family: var(--mono); font-size: 10px; color: var(--accent);
  border: 1px solid var(--accent-dim); border-radius: 4px; padding: 1px 5px;
}

/* keep the job list from pushing history off-screen */
.jobs { max-height: 300px; overflow-y: auto; }

/* ---------- dispatch modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: flex;
  align-items: center; justify-content: center; padding: 24px;
  background: rgba(6, 7, 9, .72); backdrop-filter: blur(3px);
}
.modal-card {
  width: 100%; max-width: 620px; max-height: 90vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
  animation: pop .14s ease-out;
}
@keyframes pop { from { transform: translateY(6px) scale(.99); opacity: 0; } }
.modal-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 15px; margin: 0; }
.modal-sub { margin: 3px 0 0; font-family: var(--mono); font-size: 11px; color: var(--dim); }
.modal-x {
  margin-left: auto; background: transparent; border: none; color: var(--dim);
  font-size: 22px; line-height: 1; padding: 0 4px; cursor: pointer;
}
.modal-x:hover { color: var(--text); }
.modal-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 13px; }
.modal-body .row { grid-template-columns: 1fr 1fr 1fr; }
.modal-shot { display: flex; gap: 11px; align-items: center; }
.modal-shot img {
  width: 132px; height: 74px; object-fit: cover; border-radius: 7px;
  background: var(--panel-2); flex: none;
}
.modal-shotmeta { min-width: 0; }
.modal-shotmeta .p { font-size: 13px; color: var(--text); }
.modal-shotmeta .sub { font-family: var(--mono); font-size: 11px; color: var(--dim); margin-top: 3px; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 18px 16px; border-top: 1px solid var(--line);
}
.modal-foot button { padding: 9px 16px; }
.modal-foot #dmCancel { background: transparent; border-color: var(--line); color: var(--dim); }
.modal-foot #dmCancel:hover { color: var(--text); }
#dmEst { font-family: var(--mono); color: var(--accent); }
#dmEst.err { color: var(--bad); }

.hrow .pill.bad { color: var(--bad); border-color: var(--bad); }

/* history rows carry their variations underneath */
.hrow { flex-direction: column; align-items: stretch; gap: 7px; }
.hrow.attached { border-color: var(--accent-dim); }
.hmain { display: flex; align-items: center; gap: 10px; }
.variants { display: flex; flex-wrap: wrap; gap: 5px; padding-left: 106px; }
.vchip {
  font-family: var(--mono); font-size: 10.5px; padding: 2px 7px; border-radius: 5px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--dim); cursor: pointer;
}
.vchip:hover { color: var(--text); border-color: var(--accent-dim); }
.vchip.on { color: var(--accent); border-color: var(--accent-dim); }
.vchip.pending {
  cursor: default; color: var(--accent);
  border-color: var(--accent-dim); animation: pulse 1.3s ease-in-out infinite;
}

/* ---------- selected clip ---------- */
.selected {
  display: flex; align-items: center; gap: 9px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2);
  padding: 7px 9px 7px 7px;
}
.selected.on { border-color: var(--accent-dim); }
.selected img {
  width: 74px; height: 42px; object-fit: cover; border-radius: 5px;
  background: var(--panel); flex: none; display: none;
}
.selected.on img { display: block; }
.selmeta { min-width: 0; flex: 1; }
.selmeta .p {
  font-size: 12.5px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.selmeta .sub { font-family: var(--mono); font-size: 10.5px; color: var(--dim); margin-top: 2px; }
.selclear {
  background: transparent; border: none; color: var(--dim);
  font-size: 18px; line-height: 1; padding: 0 3px; cursor: pointer; flex: none;
}
.selclear:hover { color: var(--text); }
/* whole history row is the click target now */
.hrow { cursor: pointer; }
.hrow:hover { border-color: var(--accent-dim); }
.hrow.attached { border-color: var(--accent); }
.variants { padding-left: 106px; }
