:root {
  --bg: #0e0e10;
  --panel: #17171b;
  --line: #2a2a31;
  --text: #f4f4f1;
  --muted: #9a9aa3;
  --accent: #ffe14d;
  --accent-ink: #0e0e10;
  --bad: #ff6b5b;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
button, select, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 10px; background: var(--line); padding: 9px 14px; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
button.icon { width: 40px; height: 40px; padding: 0; font-size: 16px; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.brand { font-weight: 900; letter-spacing: -.02em; font-size: 19px; }
.brand span { color: var(--accent); }
.status { color: var(--muted); font-size: 13px; text-align: right; }

.app { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.stage { padding: 12px 16px 0; display: flex; flex-direction: column; gap: 10px; }
.screen {
  position: relative; margin: 0 auto; background: #000; border-radius: var(--radius); overflow: hidden;
  height: min(52vh, 640px); aspect-ratio: 9 / 16; max-width: 100%;
}
.screen[data-aspect="16:9"] { aspect-ratio: 16 / 9; height: auto; width: 100%; max-height: 52vh; }
.screen[data-aspect="1:1"] { aspect-ratio: 1; }
.screen[data-aspect="4:5"] { aspect-ratio: 4 / 5; }
.screen canvas { width: 100%; height: 100%; display: block; }
.badge { position: absolute; left: 10px; top: 10px; padding: 5px 10px; border-radius: 999px; background: rgba(14,14,16,.78); color: var(--accent); font-size: 12px; font-weight: 700; pointer-events: none; }
.badge[hidden] { display: none; }
.drop {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 24px; text-align: center; cursor: pointer; color: var(--muted);
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--panel);
}
.drop strong { color: var(--text); font-size: 17px; }
.drop span:last-child { font-size: 13px; max-width: 30ch; }
.drop-icon { font-size: 34px; color: var(--accent); line-height: 1; }
.drop.hidden { display: none; }
body.dragging .screen { outline: 3px solid var(--accent); }

.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.controls input[type=range] { flex: 1; min-width: 120px; accent-color: var(--accent); }
.controls select { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 6px; margin-left: auto; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 84px; text-align: right; }

.clips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.clip { flex: 0 0 auto; display: flex; gap: 8px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px 6px 6px; font-size: 12px; max-width: 240px; }
.clip canvas, .clip .ph { width: 36px; height: 48px; object-fit: cover; border-radius: 6px; background: #000; flex: 0 0 auto; }
.clip .meta { min-width: 0; }
.clip .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.clip .state { color: var(--muted); }
.clip.error .state { color: var(--bad); }
.clip.add { cursor: pointer; color: var(--muted); padding: 6px 12px; }

.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; border-top: 1px solid var(--line); margin-top: 12px; }
.log { flex: 1; min-height: 120px; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.msg.ai { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.note { align-self: center; color: var(--muted); font-size: 12.5px; text-align: center; max-width: 95%; padding: 2px 8px; }
.msg.error { align-self: center; color: var(--bad); font-size: 13px; text-align: center; }
.msg .meta { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.msg a { color: var(--accent); }

.transcript { border-top: 1px solid var(--line); padding: 8px 16px; font-size: 13px; }
.transcript summary { cursor: pointer; color: var(--muted); }
.transcript ol { list-style: none; margin: 8px 0 0; padding: 0; max-height: 30vh; overflow-y: auto; }
.transcript li { padding: 3px 0; display: flex; gap: 8px; cursor: pointer; }
.transcript li .n { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 6.5em; }
.transcript li.cut { opacity: .4; text-decoration: line-through; cursor: default; }

.composer { display: flex; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.composer select { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0 6px; }
.composer textarea { flex: 1; resize: none; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; max-height: 120px; }
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.video-host { position: fixed; width: 2px; height: 2px; left: 0; bottom: 0; opacity: 0; pointer-events: none; overflow: hidden; }
.video-host video { width: 2px; height: 2px; }

@media (min-width: 900px) {
  .app { flex-direction: row; }
  .stage { flex: 1.2; padding: 16px; min-width: 0; }
  .screen { height: min(72vh, 820px); }
  .screen[data-aspect="16:9"] { max-height: 72vh; }
  .chat { flex: 1; max-width: 520px; border-top: 0; border-left: 1px solid var(--line); margin-top: 0; }
}
