:root { color-scheme: dark; }
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%;
  background: #0a0a0a; color: #ccc;
  font: 12px/1.5 -apple-system, system-ui, monospace;
  overflow: hidden;
}

#stage {
  position: fixed; inset: 0 380px 0 0;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  transition: inset 0.18s ease;
  overflow: hidden; /* clip zoomed-in canvas to the stage region */
  user-select: none; /* dragging to pan shouldn't select text */
}
body.minimized #stage { inset: 0; padding: 0; }

#canvas {
  max-width: 100%; max-height: 100%;
  background: #000;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
}
body.minimized #canvas { max-width: 100vw; max-height: 100vh; box-shadow: none; }
#canvas.empty { display: none; }

#empty-hint {
  position: absolute;
  color: #444; font-size: 13px; letter-spacing: 0.04em;
  pointer-events: none;
}
#stage:has(#canvas:not(.empty)) #empty-hint { display: none; }

#overlay {
  position: fixed; pointer-events: none; display: none; z-index: 50;
}
#overlay.visible { display: block; }
#overlay.interactive { pointer-events: auto; cursor: crosshair; }

#toggle-panel {
  position: fixed; top: 10px; right: 10px; z-index: 200;
  width: 26px; height: 26px; border-radius: 4px;
  background: rgba(20, 20, 20, 0.85); color: #aaa;
  border: 1px solid #2a2a2a; cursor: pointer;
  font: inherit; font-size: 14px; line-height: 22px; padding: 0;
}
#toggle-panel:hover { background: rgba(40, 40, 40, 0.95); color: #fff; }
body:not(.minimized) #toggle-panel { right: 390px; }
body.minimized #toggle-panel { transform: scaleX(-1); }

#side {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px;
  background: #0d0d0d; border-left: 1px solid #1a1a1a;
  display: flex; flex-direction: column; padding: 12px 14px 16px;
  overflow-y: auto;
  transition: transform 0.18s ease;
}
body.minimized #side { transform: translateX(100%); }

/* Workflow indicator — 4-step progress strip at the top of the sidebar.
   States are toggled in JS: .pending (gray), .active (blue), .done (green). */
#workflow {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  margin-bottom: 10px;
  padding: 4px;
  background: #0a0a0a; border: 1px solid #1a1a1a; border-radius: 4px;
}
#workflow .step {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 5px 2px; border-radius: 3px;
  font-size: 9.5px; letter-spacing: 0.04em; text-transform: uppercase;
  color: #555; cursor: default;
  transition: color 0.15s, background 0.15s;
}
#workflow .step .num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid currentColor; font-size: 11px; font-weight: 600;
  line-height: 1;
}
#workflow .step .lbl { font-weight: 600; }
#workflow .step.active  { color: #4af; background: rgba(70, 170, 255, 0.08); }
#workflow .step.active .num { background: rgba(70, 170, 255, 0.15); }
#workflow .step.done { color: #4c8; }
#workflow .step.done .num { background: #4c8; color: #0a0a0a; border-color: #4c8; }

/* Primary action — for the headline buttons (Generate inpaint, Record). */
button.primary-action {
  background: #4af; color: #000; font-weight: 600;
  border: 1px solid #4af; padding: 9px 12px; font-size: 12px;
  letter-spacing: 0.02em; cursor: pointer;
  transition: background 0.12s;
}
button.primary-action:hover { background: #6cf; border-color: #6cf; }
button.primary-action:disabled {
  background: #1a1a1a; color: #555; border-color: #222;
  cursor: not-allowed; font-weight: 500;
}

/* Progress bar — for long-running ops (download, inference, recording). */
.progress-bar {
  display: none;
  position: relative; height: 6px; margin: 4px 0;
  background: #1a1a1a; border: 1px solid #222; border-radius: 3px;
  overflow: hidden;
}
.progress-bar.active { display: block; }
.progress-bar .bar-fill {
  height: 100%; background: #4af;
  transition: width 0.18s ease;
}
.progress-bar.indeterminate .bar-fill {
  width: 30% !important;
  animation: indeterminate 1.4s ease-in-out infinite;
  background: linear-gradient(90deg, #2a6fa0, #4af, #2a6fa0);
}
@keyframes indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

section { margin-top: 14px; }
h3 {
  font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  color: #999; border-bottom: 1px solid #1f1f1f;
  padding-bottom: 4px; margin-bottom: 8px;
  display: flex; align-items: baseline; justify-content: space-between;
}
h3 span { color: #555; font-weight: normal; }
h3 .hint { font-size: 9px; }

#slot-bar { display: flex; flex-direction: column; gap: 6px; }
.slots { display: grid; gap: 6px; }
.slots-2 { grid-template-columns: 1fr 1fr; }
.slot {
  aspect-ratio: 4/3; background: #1a1a1a; border: 1px solid #222;
  position: relative; cursor: pointer; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  color: #555; font-size: 10px;
}
.slot:hover { border-color: #444; color: #888; }
.slot.drop-target { border-color: #4af; box-shadow: 0 0 0 1px #4af inset; }
.slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slot .lab {
  position: absolute; top: 3px; left: 4px; color: #fff;
  background: rgba(0, 0, 0, 0.6); padding: 1px 5px;
  font-size: 9px; pointer-events: none;
}

.row-btns { display: flex; gap: 4px; }
.row-btns button {
  flex: 1; background: #1a1a1a; color: #ccc; border: 1px solid #222;
  padding: 4px 6px; cursor: pointer; font: inherit; font-size: 10.5px;
}
.row-btns button:hover { background: #222; color: #fff; }

.play-row { display: flex; gap: 4px; margin-bottom: 6px; }
.play-row button {
  flex: 1; background: #1a1a1a; color: #ccc; border: 1px solid #222;
  padding: 6px; cursor: pointer; font: inherit; font-size: 12px;
}
.play-row button:hover { background: #222; }
.play-row button.active { background: #4af; color: #000; border-color: #4af; }

.slider-row {
  display: grid; grid-template-columns: 64px 1fr 60px; align-items: center;
  gap: 6px; padding: 3px 0; font-size: 11px;
}
.slider-row > span:first-child { color: #888; }
.slider-row input[type="range"] { width: 100%; accent-color: #4af; }
.slider-row .num {
  font-variant-numeric: tabular-nums; color: #aaa; text-align: right;
  font-size: 10.5px;
}

#segment-panel button,
#inpaint-panel button,
#regions-clear {
  display: block; width: 100%; margin-top: 4px;
  background: #1a1a1a; color: #ccc; border: 1px solid #222;
  padding: 6px 10px; cursor: pointer; font: inherit; font-size: 11px;
  text-align: left;
}
#segment-panel button:hover,
#inpaint-panel button:hover,
#regions-clear:hover { background: #222; color: #fff; }

#segment-panel button:disabled,
#inpaint-panel button:disabled,
#regions-clear:disabled {
  opacity: 0.4; cursor: not-allowed;
}

#segment-panel button.toggle.active {
  background: #4af; color: #000; border-color: #4af;
}

#segment-panel .sub-buttons {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 4px;
}
#segment-panel .sub-buttons button { margin-top: 0; }

.status { color: #888; font-size: 10.5px; padding: 2px 0 6px; min-height: 16px; }

#regions-list { display: flex; flex-direction: column; gap: 3px; padding: 2px 0 8px; }
.region-row {
  display: flex; align-items: center; gap: 4px;
  background: #161616; border: 1px solid #222; padding: 4px 6px;
  border-left-width: 4px;
}
.region-row.empty {
  color: #555; font-style: italic; padding: 10px;
  text-align: center; justify-content: center;
  border-left-width: 1px;
}
.region-row .num {
  color: #777; font-weight: 600; font-size: 10px;
  min-width: 14px; font-variant-numeric: tabular-nums;
}
.region-row .name {
  flex: 1; background: transparent; border: none; color: #ccc;
  font: inherit; font-size: 11px; outline: none; padding: 2px 0;
  border-bottom: 1px solid transparent;
}
.region-row .name:hover { border-bottom-color: #333; }
.region-row .name:focus { border-bottom-color: #4af; }
.region-row .up,
.region-row .down,
.region-row .del {
  background: #1a1a1a; color: #aaa; border: 1px solid #222;
  cursor: pointer; font: inherit; font-size: 10px; padding: 1px 5px;
  line-height: 1;
}
.region-row .up:hover,
.region-row .down:hover { background: #222; color: #fff; }
.region-row .del:hover { background: #422; color: #f55; border-color: #844; }

#gpu-error {
  position: fixed; inset: 0; display: none;
  align-items: center; justify-content: center; flex-direction: column;
  background: #0a0a0a; color: #ccc; padding: 32px; text-align: center;
  z-index: 1000; gap: 12px;
}
#gpu-error.show { display: flex; }
#gpu-error b { color: #fff; }
#gpu-error a { color: #4af; text-decoration: none; }

#filepicker { display: none; }

/* Generic util — toggles a block off. */
.hidden { display: none !important; }

/* Tweakpane container — Tweakpane handles its own internals, we just give
   each pane a little vertical breathing room. */
.tp-host { margin: 10px 0 6px; }
.tp-host .tp-dfwv { width: 100% !important; font-family: -apple-system, system-ui, monospace; font-size: 10.5px; }
.tp-host .tp-lblv { padding-top: 2px !important; padding-bottom: 2px !important; }

#library-section {
  padding: 8px 0 4px;
  border-top: 1px solid #1a1a1a;
  border-bottom: 1px solid #1a1a1a;
  display: flex; flex-direction: column; gap: 4px;
  max-height: 220px;
}
.library-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 9.5px; color: #666;
}
.library-title {
  color: #999; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
}
#library-grid {
  display: grid; grid-template-columns: repeat(auto-fill, 56px); gap: 4px;
  overflow-y: auto; padding-bottom: 4px;
  min-height: 24px;
}
.library-thumb {
  position: relative; width: 56px; height: 42px;
  border: 1px solid #222; border-radius: 2px; overflow: hidden;
  cursor: pointer; background: #111;
  transition: border-color 0.1s;
}
.library-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.library-thumb:hover { border-color: #4af; }
.library-thumb.active { border-color: #4af; box-shadow: 0 0 0 1px #4af inset; }
.library-thumb.active::after {
  content: '●'; position: absolute; top: 1px; right: 2px;
  font-size: 8px; color: #4af; text-shadow: 0 0 2px #000;
  pointer-events: none;
}
.library-empty {
  grid-column: 1 / -1;
  color: #555; font-size: 10px; padding: 10px 4px; text-align: center;
}

.method-panel { display: none; padding: 2px 0 4px; }
.method-panel.active { display: block; }

.select-row {
  display: grid; grid-template-columns: 64px 1fr; gap: 6px; align-items: center;
  padding: 4px 0; font-size: 11px;
}
.select-row > span { color: #888; }
.select-row select {
  width: 100%; background: #1a1a1a; color: #ccc; border: 1px solid #222;
  padding: 4px 6px; font: inherit; font-size: 11px; outline: none;
  cursor: pointer;
}
.select-row select:hover { border-color: #333; }
.select-row select:focus { border-color: #4af; }

.kv-row {
  display: grid; grid-template-columns: 64px 1fr; gap: 6px; align-items: center;
  padding: 3px 0; font-size: 11px;
}
.kv-row.prompt-row { align-items: start; }
.kv-row > span { color: #888; }
.kv-row input, .kv-row textarea {
  width: 100%; background: #1a1a1a; color: #ccc; border: 1px solid #222;
  padding: 4px 6px; font: inherit; font-size: 11px; outline: none;
}
.kv-row input:focus, .kv-row textarea:focus { border-color: #4af; }
.kv-row textarea { resize: vertical; min-height: 28px; line-height: 1.4; }

.hint-line {
  color: #555; font-size: 10px; padding: 4px 0;
}

.bg-slot {
  aspect-ratio: 4/3; margin-top: 4px;
}
.bg-slot .placeholder { padding: 4px; text-align: center; }
