:root {
  --bg: #0b0c09;
  --bg-2: #12140f;
  --panel: #171a13;
  --line: #2a2f24;
  --text: #f3f0e6;
  --muted: #9a9a88;
  --accent: #c8f169;
  --accent-ink: #1a2208;
  --danger: #e07a6a;
  --ok: #7dcea0;
  --warn: #e2c36b;
  --rail: 248px;
  --display: "Sora", "IBM Plex Sans", sans-serif;
  --serif: var(--display);
  --sans: "IBM Plex Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1000px 560px at 0% -10%, #1d2814 0%, transparent 55%),
    radial-gradient(800px 480px at 100% 0%, #182028 0%, transparent 48%),
    var(--bg);
}

.app {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  min-height: 100vh;
}

.rail {
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-2) 90%, black);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 36px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
  color: var(--text);
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent);
}
.brand-text { font-size: 0.85rem; line-height: 1.15; font-weight: 600; font-family: var(--display); letter-spacing: -0.02em; }
.brand-text em {
  font-family: inherit;
  font-style: normal;
  font-weight: 500;
  color: var(--muted);
}

.nav { display: flex; flex-direction: column; gap: 6px; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav a:hover { color: var(--text); background: #1b1f16; }
.nav a.active {
  color: var(--accent-ink);
  background: var(--accent);
}

.rail-foot { margin-top: auto; }
.chip {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--accent);
  margin-bottom: 8px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip.muted-chip { color: var(--muted); }
.muted { color: var(--muted); }
.tiny { font-size: 0.75rem; line-height: 1.45; margin: 0; }

.main {
  padding: 32px 40px 72px;
  max-width: 1280px;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 20px;
}
.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 600;
}
h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.4rem, 4vw, 3.35rem);
  letter-spacing: -0.02em;
  line-height: 0.95;
}
.lede {
  margin: 12px 0 0;
  max-width: 48ch;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}
.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  background: var(--panel);
}
.toggle input { accent-color: var(--accent); }

.btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.15s, border-color 0.15s, transform 0.15s;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn.ghost:hover:not(:disabled) { border-color: var(--muted); }
.btn.sm { padding: 8px 12px; font-size: 0.78rem; }
.hidden { display: none !important; }

.ticker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px 16px;
  background: linear-gradient(180deg, #1a1f15, var(--panel));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px 12px;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}
.ticker-item { min-width: 0; }
.ticker-label {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 4px;
}
.ticker-item strong {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 400;
}
.ticker-bar {
  grid-column: 1 / -1;
  height: 4px;
  background: #10130e;
  border-radius: 99px;
  overflow: hidden;
}
.ticker-bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8fbf3a, var(--accent));
  transition: width 0.3s ease;
}

.workspace {
  display: grid;
  grid-template-columns: 1.55fr 0.9fr;
  gap: 16px;
  margin-bottom: 16px;
  align-items: start;
}

.image-stage {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.image-queue-wrap {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--panel) 88%, #1a2214), var(--panel));
}
.image-queue { display: grid; gap: 8px; max-height: 280px; overflow: auto; }
.image-queue-item .vq-select {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 10px;
  align-items: center;
}
.iq-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  background: #0a0c09;
}
.iq-copy { min-width: 0; display: grid; gap: 2px; }
.image-side .panel.compact h2 {
  margin-bottom: 8px;
  font-size: 0.92rem;
}
.image-preview-stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #050605;
  z-index: 2;
}
.image-preview-stage.hidden { display: none !important; }
.image-preview-stage img {
  flex: 1;
  width: 100%;
  min-height: 0;
  object-fit: contain;
  background: #050605;
}
.image-preview-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, black);
}
.image-preview-meta strong {
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drop.has-preview {
  cursor: default;
  padding: 0;
  place-items: stretch;
  border-style: solid;
  /* Absolute preview stage needs a real height — never collapse to content */
  min-height: min(52vh, 480px);
  height: min(52vh, 520px);
  max-height: min(58vh, 560px);
}
.drop.has-preview:hover { transform: none; box-shadow: none; }

.drop {
  min-height: 180px;
  max-height: min(46vh, 440px);
  border: 1px dashed color-mix(in srgb, var(--accent) 40%, var(--line));
  border-radius: 20px;
  background:
    linear-gradient(155deg, color-mix(in srgb, var(--panel) 75%, #2a3a18), var(--panel));
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}
.drop:hover, .drop.drag, .drop:focus-visible {
  border-color: var(--accent);
  outline: none;
  transform: translateY(-1px);
  box-shadow: 0 18px 40px rgba(0,0,0,0.25);
}
.drop.locked { opacity: 0.55; pointer-events: none; }
.drop.has-result {
  cursor: default;
  padding: 0;
  place-items: stretch;
  border-style: solid;
  min-height: min(52vh, 480px);
  height: min(52vh, 520px);
  max-height: min(58vh, 560px);
}
.drop.has-result:hover { transform: none; box-shadow: none; }
.drop-inner { text-align: center; padding: 20px 18px; }

.result-stage {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  cursor: default;
}
.ba-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #0a0c09;
  overflow: hidden;
  user-select: none;
}
.ba-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.ba-frame #baAfter,
.ba-frame #modalAfter {
  clip-path: inset(0 0 0 50%);
}
.ba-frame input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
  z-index: 3;
}
.ba-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  background: #fff;
  z-index: 2;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35);
}
.ba-line::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: color-mix(in srgb, var(--accent) 80%, #111);
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}
.ba-tag {
  position: absolute;
  top: 12px;
  z-index: 2;
  pointer-events: none;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 5px 9px;
  border-radius: 6px;
  background: rgba(0,0,0,0.55);
  color: #fff;
}
.ba-tag.left { left: 12px; }
.ba-tag.right { right: 12px; }
.ba-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.ba-toolbar .btn { flex: 1; min-width: 90px; text-align: center; }
.btn.sm { padding: 8px 12px; font-size: 0.82rem; }

.corner-zoom {
  position: absolute;
  /* Left: keep bottom-right watermark region visible in the main compare view */
  left: 12px;
  right: auto;
  bottom: 12px;
  z-index: 4;
  display: flex;
  gap: 4px;
  padding: 6px;
  border-radius: 10px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.15);
  pointer-events: none;
}
.corner-zoom canvas {
  width: 72px;
  height: 72px;
  border-radius: 6px;
  background: #111;
  image-rendering: pixelated;
}
.corner-label {
  position: absolute;
  left: 8px;
  top: -18px;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.75);
  white-space: nowrap;
}
.conf-badge {
  position: absolute;
  /* Top-left under Before tag — free bottom-right for the mark */
  left: 12px;
  top: 44px;
  bottom: auto;
  right: auto;
  z-index: 4;
  max-width: min(70%, 320px);
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.35;
  pointer-events: none;
}
.history {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 140px;
  overflow: auto;
}
.image-side {
  gap: 10px;
}
.image-side .panel h2 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}
.image-side .stats-compact {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.image-side .history-fold {
  padding: 10px 12px;
}
.image-side .history-fold > summary {
  cursor: pointer;
  font-family: var(--serif);
  font-size: 0.95rem;
  font-weight: 600;
  list-style: none;
  color: var(--text);
}
.image-side .history-fold > summary::-webkit-details-marker { display: none; }
.image-side .history-fold > summary::after {
  content: " ▾";
  color: var(--muted);
  font-size: 0.75rem;
}
.image-side .history-fold[open] > summary {
  margin-bottom: 8px;
}
.image-side .history-fold[open] > summary::after { content: " ▴"; }
.batch-tip {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--text);
  font-size: 0.78rem;
  line-height: 1.4;
}
.history-item {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px;
  border-radius: 8px;
  background: #10130e;
  border: 0;
  width: 100%;
  text-align: left;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.history-item:hover { outline: 1px solid var(--accent); }
.history-item img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
}
.history-item .h-name {
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item.on { outline: 1px solid var(--accent); }
.history-item .h-meta {
  font-size: 0.68rem;
  color: var(--muted);
}
.history-empty { margin: 0; font-size: 0.78rem; color: var(--muted); }
.modal-wide { max-width: min(960px, 94vw); }
.modal-ba {
  min-height: min(70vh, 640px);
  border-radius: 12px;
  border: 1px solid var(--line);
}
.drop-kicker {
  margin: 0;
  color: var(--accent);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
}
.drop-title {
  margin: 10px 0 0;
  font-family: var(--serif);
  font-size: 2rem;
  font-weight: 400;
}
.drop-hint { margin: 8px 0 18px; color: var(--muted); font-size: 0.9rem; }

.side { display: flex; flex-direction: column; gap: 12px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.stats {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stats div {
  background: #10130e;
  border-radius: 10px;
  padding: 10px 12px;
}
.stats dt {
  margin: 0;
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.stats dd {
  margin: 4px 0 0;
  font-family: var(--serif);
  font-size: 1.45rem;
}
.now-line {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.45;
  min-height: 2.8em;
}
.now-eta { margin: 8px 0 0; font-size: 0.82rem; }
.actions-col { display: flex; flex-direction: column; gap: 8px; }
.actions-col .btn { width: 100%; }

.engine-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 4px;
}
.engine-opt {
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.engine-opt:hover { color: var(--text); }
.engine-opt.on {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}

.queue-wrap { margin-top: 4px; }
.video-queue-wrap {
  margin-top: 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--panel) 88%, #1a2214), var(--panel));
}
.video-queue {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}
.video-queue-item {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  background: #10130e;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
}
.video-queue-item .vq-select {
  display: grid;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0;
  cursor: pointer;
}
.video-queue-item strong {
  font-size: 0.86rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.video-queue-item .vq-select span {
  color: var(--muted);
  font-size: 0.75rem;
}
.video-queue-item:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.video-queue-item.on {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, #10130e);
}
.vq-strength {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.vq-chip {
  border: 1px solid var(--line);
  background: #0a0c09;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.vq-chip:hover:not(:disabled) { color: var(--text); border-color: var(--muted); }
.vq-chip.on {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
.vq-chip:disabled { opacity: 0.45; cursor: default; }
.queue-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}
.queue-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.65rem;
}
.status { margin: 0; color: var(--muted); font-size: 0.88rem; text-align: right; }
.empty-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.empty-hint.hidden { display: none; }

.queue { display: grid; gap: 10px; }
.card {
  display: grid;
  grid-template-columns: 76px 1fr auto;
  gap: 14px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  animation: rise 0.35s ease both;
}
.card.is-run {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
}
.card.is-done { border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); }
.card.is-error { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.thumb {
  width: 76px;
  height: 76px;
  border-radius: 12px;
  object-fit: cover;
  background: #000;
}
.card-body { min-width: 0; }
.card-name {
  margin: 0;
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta {
  margin: 4px 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}
.bar {
  height: 5px;
  background: #10130e;
  border-radius: 99px;
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8fbf3a, var(--accent));
  transition: width 0.25s ease;
}
.card-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  min-width: 96px;
}
.pill {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.pill.done { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.pill.error { color: var(--danger); }
.pill.run { color: var(--accent); }
.pill.wait { color: var(--warn); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.62);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }
.modal-card {
  width: min(560px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  cursor: pointer;
}
.modal-card h3 {
  margin: 0 0 14px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.5rem;
}
.compare {
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line);
}
.compare img { width: 100%; display: block; }
.modal-actions { margin-top: 14px; }

.top-actions .path-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.top-actions .path-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.82rem;
  padding: 8px 12px;
  border-radius: 9px;
  cursor: pointer;
}
.top-actions .path-tab.on {
  background: var(--accent);
  color: var(--accent-ink);
}

.mode-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.mode-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
}
.mode-tab.on {
  background: var(--accent);
  color: var(--accent-ink);
}
.hidden { display: none !important; }

.video-workspace { align-items: stretch; }
.video-stage {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.video-frame {
  position: relative;
  /* Explicit height so absolute video/canvas layout has usable clientHeight */
  height: min(58vh, 560px);
  min-height: 420px;
  max-height: 68vh;
  border-radius: 20px;
  border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--line));
  background:
    radial-gradient(800px 280px at 80% 120%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 60%),
    #050605;
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03);
  cursor: default;
}
.video-frame.has-media {
  height: min(62vh, 620px);
  min-height: 460px;
}
.video-viewport {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transform-origin: center center;
  will-change: transform;
}
.video-viewport video,
.video-viewport canvas {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
}
.video-viewport canvas {
  z-index: 2;
  cursor: crosshair;
  touch-action: none;
}
.video-empty {
  position: relative;
  z-index: 6;
  text-align: center;
  padding: 28px 18px;
  pointer-events: auto;
  cursor: pointer;
  width: min(420px, 92%);
}
.video-empty.hidden { display: none !important; }
.video-empty .btn {
  position: relative;
  z-index: 7;
  pointer-events: auto;
}
.video-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #1a1f15, var(--panel));
}
.video-toolbar.dim { opacity: 0.55; }
.tool-btn {
  border: 1px solid var(--line);
  background: #10130e;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tool-btn:hover { color: var(--text); border-color: var(--muted); }
.tool-btn.on {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
.tool-sep {
  width: 1px;
  height: 22px;
  background: var(--line);
  margin: 0 2px;
}
.tool-note {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
  flex: 1;
  min-width: 140px;
}
.tool-group {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.tool-btn.sm {
  padding: 6px 10px;
  min-width: 34px;
}
.tool-btn.tool-shape {
  min-width: 36px;
  font-size: 1rem;
  line-height: 1;
  padding: 7px 10px;
}
.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.zoom-controls input[type="range"] {
  width: 88px;
  accent-color: var(--accent);
}
.zoom-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  min-width: 40px;
  font-variant-numeric: tabular-nums;
}
.sel-label {
  margin: 12px 0 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.size-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.size-chip {
  border: 1px solid var(--line);
  background: #10130e;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  min-width: 42px;
}
.size-chip:hover { color: var(--text); }
.size-chip.on {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
.coord-input {
  width: 72px;
  border: 1px solid var(--line);
  background: #10130e;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 4px 6px;
  border-radius: 6px;
}
.coord-input:disabled {
  opacity: 0.45;
}
.stats dd { margin: 0; }
.nudge-pad {
  display: grid;
  justify-items: center;
  gap: 4px;
  margin-top: 4px;
}
.nudge-mid {
  display: flex;
  gap: 4px;
  align-items: center;
}
.nudge-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: #10130e;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
}
.nudge-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.nudge-btn.nudge-step {
  font-size: 0.75rem;
  color: var(--muted);
}
.nudge-hint { margin-top: 8px; }

.tune-row { margin-bottom: 14px; }
.tune-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.tune-slider {
  display: flex;
  align-items: center;
  gap: 10px;
}
.tune-slider input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
}
.tune-val {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text);
  min-width: 2.6em;
  text-align: right;
}
.tune-tip { margin-top: 4px; line-height: 1.35; }
.tune-peek {
  width: 100%;
  margin-top: 2px;
  user-select: none;
}
.tune-peek:active,
.tune-peek.holding {
  border-color: var(--accent);
  color: var(--accent);
}
.strength-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.review-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.review-pair-sm {
  gap: 6px;
  max-width: 80%;
}
.review-card {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #0c0f0a;
}
.review-card canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  image-rendering: auto;
  background: #000;
}
.review-card figcaption {
  padding: 5px 8px;
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--line);
}
#reviewLayout { margin-top: 8px; }

.video-side .panel.compact {
  padding: 12px 14px;
}
.video-side .panel.compact h2 {
  margin-bottom: 8px;
  font-size: 0.92rem;
}
.video-side .panel.compact .muted.tiny {
  margin: 4px 0 0;
}
.pos-inline {
  margin: 6px 0 0;
  font-variant-numeric: tabular-nums;
}
.actions-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.actions-row .btn { flex: 1; }
.status-panel .now-line { margin: 0; font-size: 0.92rem; }
.status-panel .now-eta { margin: 4px 0 0; }
.status-actions { margin-top: 10px !important; gap: 8px; }
#btnDownloadVideo.btn.primary:disabled {
  opacity: 0.45;
}
#btnDownloadVideo.btn.primary:not(:disabled) {
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent),
    0 8px 22px color-mix(in srgb, var(--accent) 28%, transparent);
}

.position-select {
  width: 100%;
  margin-top: 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #10130e;
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
}
.position-select:disabled {
  opacity: 0.55;
}
.advanced-lock {
  margin-top: 8px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}
.advanced-lock summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  user-select: none;
}
.advanced-lock[open] summary { margin-bottom: 8px; }

.video-transport {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.video-transport input[type="range"] { flex: 1; min-width: 120px; }

.path-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #10130e;
  margin-bottom: 10px;
}
.path-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.8rem;
  padding: 9px 8px;
  border-radius: 9px;
  cursor: pointer;
}
.path-tab.on {
  background: var(--accent);
  color: var(--accent-ink);
}

.compare-rail {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}
.compare-rail input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
  pointer-events: auto;
  z-index: 5;
}
.compare-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  background: var(--text);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35);
  transform: translateX(-50%);
  pointer-events: none;
}
.compare-line::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--text);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  transform: translate(-50%, -50%);
}
.compare-tag {
  position: absolute;
  top: 14px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 8px;
  border-radius: 6px;
  background: rgba(0,0,0,0.55);
  color: var(--text);
  pointer-events: none;
}
.compare-tag.left { left: 14px; }
.compare-tag.right { right: 14px; }

.video-viewport canvas {
  z-index: 2;
  cursor: default;
  touch-action: none;
  mix-blend-mode: normal;
}
.video-viewport canvas.no-hit {
  pointer-events: none !important;
}
.video-frame.is-panning,
.video-frame.is-panning canvas {
  cursor: grabbing !important;
}


.mobile-tabs {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: rgba(11, 12, 9, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.mobile-tab {
  border: 1px solid var(--line);
  background: #10130e;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 12px 10px;
  border-radius: 14px;
  cursor: pointer;
  min-height: 48px;
}
.mobile-tab.on {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .rail {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px 14px 10px;
    gap: 12px;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .rail .nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
  }
  .rail .nav a {
    padding: 8px 10px;
    font-size: 0.82rem;
  }
  .rail-foot {
    margin-top: 0;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }
  .rail-foot .muted { display: none; }
  .workspace, .ticker { grid-template-columns: 1fr; }
  .main { padding: 16px 14px 88px; }
  .top { flex-direction: column; align-items: stretch; gap: 12px; }
  .top-actions { width: 100%; justify-content: stretch; flex-wrap: wrap; }
  .top-actions .btn { flex: 1; min-height: 44px; }
  .mode-tabs { width: 100%; }
  .mode-tab { flex: 1; min-height: 42px; }
  /* Keep a real stage height — height:auto collapses absolute preview to ~min-height */
  .drop {
    min-height: 160px;
    max-height: none;
    height: auto;
  }
  .drop.has-result,
  .drop.has-preview {
    min-height: min(48vh, 360px);
    height: min(50vh, 420px);
    max-height: min(56vh, 480px);
  }
  .video-frame {
    height: min(48vh, 400px);
    min-height: 280px;
    max-height: 54vh;
  }
  .video-frame.has-media {
    height: min(52vh, 440px);
    min-height: 300px;
  }
  .image-side, .video-side { order: 2; }
  .image-stage, .video-stage { order: 1; }
  .btn, .size-chip, .vq-chip, .tool-btn { min-height: 40px; }
  .ticker { gap: 8px; }
  .ticker-item { padding: 8px; }
  .modal-card { margin: 12px; max-height: calc(100vh - 24px); overflow: auto; }
  .modal-ba { min-height: 40vh; }
}

@media (max-width: 720px) {
  .mobile-tabs { display: grid; }
  .mode-tabs { display: none; }
  .rail .nav a:not(.active) { display: none; }
  .brand-text { font-size: 0.78rem; }
  .top h1 { font-size: 1.55rem; }
  .top .lede { font-size: 0.9rem; }
  .panel h2 { font-size: 0.9rem; }
  .actions-col .btn { width: 100%; }
  .ba-toolbar { flex-wrap: wrap; }
  .ba-toolbar .btn, .ba-toolbar a.btn { flex: 1; justify-content: center; }
  .review-pair { grid-template-columns: 1fr 1fr; gap: 8px; }
  .corner-zoom { transform: scale(0.85); transform-origin: bottom left; }
  .video-queue, .image-queue { max-height: 40vh; }
  .strength-chips { display: flex; flex-wrap: wrap; }
  .strength-chips .size-chip { flex: 1; text-align: center; }
  .drop.has-result,
  .drop.has-preview {
    min-height: min(44vh, 320px);
    height: min(46vh, 360px);
    max-height: min(52vh, 400px);
  }
  .video-frame,
  .video-frame.has-media {
    height: min(46vh, 360px);
    min-height: 260px;
    max-height: 50vh;
  }
  .image-preview-meta { padding: 8px 12px; }
  .image-preview-meta strong { font-size: 0.8rem; }
}
