:root {
  --bg: #0f1113;
  --panel: #16181c;
  --panel-2: #1c1f24;
  --line: #2b2f36;
  --text: #e4e6e9;
  --dim: #8b9099;
  --accent: #8fa1bb;        /* muted steel blue: sliders, focus, small accents */
  --accent-dim: #55606f;
  --ok: #5d8f6f;
  --danger: #c96a6a;
  --radius: 10px;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
.mono { font-family: var(--mono); }
.dim { color: var(--dim); }
.grow { flex: 1; }
.spacer { flex: 1; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 9px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; flex: 1; flex-wrap: wrap; }

/* ---------- buttons / fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 7px 13px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font-size: 13px; cursor: pointer; white-space: nowrap;
  transition: border-color .15s, background .15s, opacity .15s;
}
.btn:hover:not(:disabled) { border-color: #3c424b; background: #23262c; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: #e4e6e9; border-color: #e4e6e9; color: #17191d; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #f2f4f6; border-color: #f2f4f6; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #0d1a12; font-weight: 600; text-decoration: none; }
.btn.ok:hover:not(:disabled) { background: #6da180; border-color: #6da180; }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 4px 9px; font-size: 12px; }
.btn.small { padding: 5px 12px; font-size: 12px; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.field.inline { flex-direction: row; align-items: center; gap: 7px; }
.field > span { color: var(--dim); }
select, input[type=text], input[type=number] {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 7px; font: inherit; font-size: 12px; min-width: 0;
}
select:focus, input:focus { outline: 1px solid var(--accent-dim); outline-offset: 0; }
input[type=range] { accent-color: var(--accent); }

/* the spinner arrows eat the width a value like 0.055 needs */
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }

/* ---------- layout ---------- */
main { flex: 1; display: grid; grid-template-columns: 316px 1fr; min-height: 0; }

.panel {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--dim); }
#groups {
  overflow-y: auto; overflow-x: hidden; padding-bottom: 30px;
  scrollbar-width: none;              /* the panel scrolls, quietly */
  -ms-overflow-style: none;
}
#groups::-webkit-scrollbar { width: 0; height: 0; }

.layers { display: flex; flex-direction: column; border-bottom: 1px solid var(--line); }
.layer {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 8px 3px 12px; border-left: 3px solid transparent;
}
.layer:hover { background: var(--panel-2); }
.layer.on { border-left-color: var(--accent); background: var(--panel-2); }
.layer-kind {
  flex: 0 1 auto; min-width: 0; font-size: 12.5px;
  background: none; border-color: transparent; padding: 4px 4px 4px 0;
}
.layer.on .layer-kind, .layer:hover .layer-kind { border-color: var(--line); padding-left: 6px; }
.layer-where {
  flex: 1; min-width: 0; text-align: right; white-space: nowrap; overflow: hidden;
  background: none; border: none; padding: 5px 2px; cursor: pointer;
  font: inherit; font-size: 11px; color: var(--dim);
}
.layer-drop {
  background: none; border: none; color: var(--dim); cursor: pointer;
  font: inherit; font-size: 13px; line-height: 1; padding: 4px 6px; border-radius: 5px;
}
.layer-drop:hover { color: var(--danger); background: #23262c; }

details.group { border-bottom: 1px solid var(--line); }
details.group > summary {
  padding: 8px 12px; cursor: pointer; font-weight: 600; font-size: 12.5px;
  list-style: none; display: flex; align-items: center; gap: 8px;
}
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::before {
  content: "+"; color: var(--dim); font-family: var(--mono);
  transition: transform .15s; display: inline-block;
}
details.group[open] > summary::before { content: "-"; }
details.group > summary:hover { background: var(--panel-2); }
.group-body { padding: 3px 12px 12px; display: flex; flex-direction: column; gap: 7px; }
.group-help { font-size: 11px; color: var(--dim); margin: -2px 0 4px; }

.row { display: grid; grid-template-columns: 100px 1fr; align-items: center; gap: 8px; }
.row > label { font-size: 12px; color: #c2c6cc; line-height: 1.25; }
.row .control { display: flex; align-items: center; gap: 6px; min-width: 0; }
.row .control input[type=range] { flex: 1; min-width: 40px; }
.row .control input[type=number] { width: 54px; flex: none; text-align: right; }
.row .control input[type=text] { flex: 1; }
.row .control select { flex: 1; }
.hint { grid-column: 2; font-size: 11px; color: var(--dim); margin-top: -4px; }
.auto-tag { font-size: 11px; color: var(--dim); display: flex; align-items: center; gap: 4px; }

.swatch {
  width: 26px; height: 23px; border-radius: 5px; border: 1px solid var(--line);
  padding: 0; background: none; cursor: pointer; flex: none; overflow: hidden;
  position: relative;
}
.swatch input[type=color] {
  position: absolute; inset: -6px; width: 200%; height: 200%;
  border: none; padding: 0; background: none; cursor: pointer;
}
.row .control input.hex { flex: 0 0 92px; width: 92px; font-family: var(--mono); font-size: 11px; padding: 4px 5px; }
.row .control.has-auto input.hex { flex: 1 1 54px; width: auto; min-width: 46px; }
.row .control.has-auto input[type=number] { width: 50px; }
.row .control.has-auto input[type=range] { min-width: 30px; }
.auto-tag input[type=checkbox] { width: 13px; height: 13px; }
.axes { display: flex; gap: 10px; flex-wrap: wrap; }
.axes label { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: #c2c6cc; }

/* ---------- stage ---------- */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage-head {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px; border-bottom: 1px solid var(--line);
}
.log-name { font-size: 13px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.viewport {
  flex: 1; min-height: 0; padding: 20px;
  display: flex; align-items: center; justify-content: center;
  background: #0c0e10;
  background-image:
    linear-gradient(45deg, #14161a 25%, transparent 25%, transparent 75%, #14161a 75%),
    linear-gradient(45deg, #14161a 25%, transparent 25%, transparent 75%, #14161a 75%);
  background-size: 22px 22px;
  background-position: 0 0, 11px 11px;
}
.frame { position: relative; max-width: 100%; max-height: 100%; display: flex;
  align-items: center; justify-content: center; }
.frame.has-backdrop { box-shadow: 0 10px 40px rgba(0,0,0,.5); }
#backdrop-img { max-width: 100%; max-height: 100%; display: block; border-radius: 4px; }
.preview { image-rendering: auto; max-width: 100%; max-height: 100%; }
.preview.placed {
  position: absolute; max-width: none; max-height: none;
  cursor: grab; touch-action: none;
  outline: 1px solid transparent; outline-offset: 2px;
}
.preview.placed:hover { outline-color: rgba(143, 161, 187, .45); }
.preview.placed.active { outline-color: rgba(143, 161, 187, .35); }
.preview.placed.dragging { cursor: grabbing; outline-color: var(--accent); }

/* the stand-in frame the overlays are arranged on when there is no video */
.frame-guide {
  position: absolute; border: 1px dashed var(--line); border-radius: 4px;
  pointer-events: none;
}
.frame-guide::after {
  content: attr(data-size); position: absolute; top: 100%; right: 0;
  padding-top: 4px; font-size: 11px; color: var(--dim); font-family: var(--mono);
}
.placeholder { padding: 40px; text-align: center; max-width: 460px; z-index: 9; }
/* with footage loaded but no log yet, the prompt sits over the video */
.frame.has-backdrop .placeholder, .frame.staged .placeholder {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(12, 14, 16, .82); border: 1px solid var(--line);
  border-radius: 10px; padding: 24px 28px;
}
.placeholder p { margin: 6px 0; }
.placeholder .lead { font-size: 15px; color: var(--text); }
.placeholder-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.viewport.drop { outline: 2px dashed var(--accent); outline-offset: -10px; }

.transport {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel);
}
.transport input[type=range] { flex: 1; }
#scrub-time { font-size: 13px; min-width: 74px; text-align: right; }

.sync {
  display: flex; flex-direction: column; gap: 7px;
  padding: 9px 16px; border-top: 1px solid var(--line); background: var(--panel);
}
.sync-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.sync-row:empty, .sync-row:has(> .dim:empty) { display: none; }
.sync-step {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 11px; color: var(--dim);
}
.sync-text { font-size: 12.5px; color: #c2c6cc; }
.sync-text b { color: var(--text); font-weight: 600; }
.sync-times { font-size: 12px; color: var(--dim); }
.sync-text.aligned { color: var(--ok); }
.link-toggle { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--dim); }

/* the footage fills the pane, scaling up when it is smaller than the space */
#backdrop-video, .frame.has-backdrop #backdrop-img {
  width: 100%; height: 100%; object-fit: contain; display: block; border-radius: 4px;
}
.frame.has-backdrop, .frame.staged { width: 100%; height: 100%; }

.export { padding: 12px 16px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.export-row { display: flex; align-items: center; gap: 10px; }
.bar { height: 6px; background: var(--panel-2); border-radius: 4px; margin-top: 10px; overflow: hidden; }
#bar-fill { height: 100%; width: 0; background: #b9c0ca; transition: width .2s; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: #21242a; border: 1px solid var(--line); border-left: 3px solid var(--accent);
  padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 20;
  box-shadow: 0 10px 30px rgba(0,0,0,.45); max-width: 80vw;
}
.toast.error { border-left-color: var(--danger); }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; grid-template-rows: minmax(0, 45%) minmax(0, 55%); }
  .panel { border-right: none; border-bottom: 1px solid var(--line); }
}
