:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #f2b544;
  --ok: #3ecf8e;
  --warn: #f2b544;
  --bad: #ef5a5a;
  --twitch: #a970ff;
  --youtube: #ff4e45;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: #1a1405; border-color: var(--accent); font-weight: 600; }
input[type=text], input[type=password], input[type=number] {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
label { display: block; color: var(--muted); font-size: 12px; margin: 10px 0 4px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

header.top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
header.top h1 { font-size: 16px; margin: 0 8px 0 0; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
  border: 1px solid var(--line); border-radius: 999px; font-size: 12.5px; background: var(--panel-2);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip.live .dot { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.chip.starting .dot, .chip.retrying .dot { background: var(--warn); }
.chip.error .dot { background: var(--bad); }
.chip .sub { color: var(--muted); }

main.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px;
  padding: 16px; height: calc(100% - 53px);
}
@media (max-width: 1000px) {
  main.layout { grid-template-columns: 1fr; height: auto; }
  .chat-card { height: 70vh; }
}
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; min-width: 0;
}
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; overflow: auto; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }

/* crop editor */
.crop-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 180px; gap: 14px; align-items: start; }
@media (max-width: 700px) { .crop-wrap { grid-template-columns: 1fr; } }
.stage { position: relative; background: #000; border-radius: 8px; overflow: hidden; aspect-ratio: 16 / 9; touch-action: none; }
.stage video { width: 100%; height: 100%; display: block; object-fit: contain; }
.stage .offline {
  position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted);
  background: repeating-linear-gradient(45deg, #111 0 12px, #141414 12px 24px);
}
.shade { position: absolute; background: rgba(0,0,0,.55); pointer-events: none; }
.cropbox {
  position: absolute; border: 2px solid var(--accent); cursor: grab;
  box-shadow: 0 0 0 1px rgba(0,0,0,.6);
}
.cropbox:active { cursor: grabbing; }
.cropbox .safe { position: absolute; left: 0; right: 0; bottom: 0; height: 22%; background: rgba(239,90,90,.18); border-top: 1px dashed rgba(239,90,90,.7); }
.cropbox .safe-r { position: absolute; top: 40%; right: 0; bottom: 22%; width: 16%; background: rgba(239,90,90,.18); border-left: 1px dashed rgba(239,90,90,.7); }
.cropbox.no-safe .safe, .cropbox.no-safe .safe-r { display: none; }
.vpreview { aspect-ratio: 9 / 16; background: #000; border-radius: 8px; overflow: hidden; position: relative; }
.vpreview video { width: 100%; height: 100%; object-fit: cover; display: block; }
.vpreview .offline { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; padding: 8px; }
input[type=range] { width: 100%; accent-color: var(--accent); }

/* outputs table */
table.outputs { width: 100%; border-collapse: collapse; }
table.outputs td { padding: 6px 4px; border-top: 1px solid var(--line); vertical-align: middle; }
table.outputs td.err { color: var(--bad); font-size: 12px; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* chat */
.chat-card { display: flex; flex-direction: column; min-height: 0; padding: 0; }
.chat-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chat-head h2 { margin: 0; flex: 1; }
.filters { display: flex; gap: 6px; }
.filters button { padding: 2px 8px; font-size: 12px; opacity: .45; }
.filters button.on { opacity: 1; }
.chat-log { flex: 1; overflow-y: auto; padding: 8px 12px; min-height: 0; }
.msg { padding: 4px 0; word-wrap: break-word; }
.msg .tag {
  display: inline-block; font-size: 10.5px; font-weight: 700; padding: 0 5px; border-radius: 4px;
  margin-right: 6px; vertical-align: 1px; color: #fff;
}
.msg .tag.twitch { background: var(--twitch); }
.msg .tag.youtube { background: var(--youtube); }
.msg .fmt { font-size: 10.5px; color: var(--muted); margin-right: 4px; }
.msg .user { font-weight: 700; margin-right: 4px; }
.msg img.emote { height: 1.5em; vertical-align: middle; }
.msg .paid { background: var(--accent); color: #1a1405; font-weight: 700; padding: 0 6px; border-radius: 4px; margin-right: 4px; }
.chat-status { padding: 8px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 18px;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 14px; padding: 8px 12px 12px; }
legend { color: var(--muted); padding: 0 6px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; margin-top: 10px; }
.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 10;
}
.toast.show { opacity: 1; }
.copy { display: flex; gap: 6px; }
.copy input { flex: 1; }

@media (max-width: 700px) {
  header.top .chips { order: 3; flex-basis: 100%; }
  header.top #openSettings { margin-left: auto; }
  .vpreview { max-width: 200px; margin: 0 auto; }
  table.outputs td:nth-child(3) { display: none; }
  table.outputs .chip { white-space: normal; }
}

/* layer editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 16px; align-items: start; }
@media (max-width: 760px) { .editor { grid-template-columns: 1fr; } .editor-side { max-width: 300px; margin: 0 auto; width: 100%; } }
.hint { font-size: 12px; margin: 6px 0 10px; }
.src-rect, .dst-rect { position: absolute; border: 2px solid var(--c, var(--accent)); cursor: grab; touch-action: none; }
.src-rect { background: color-mix(in srgb, var(--c) 10%, transparent); }
.src-rect.sel, .dst-rect.sel { box-shadow: 0 0 0 2px #fff, 0 0 12px var(--c); z-index: 5; }
.src-rect .tag, .dst-rect .tag {
  position: absolute; top: 0; left: 0; background: var(--c); color: #111; font-size: 11px; font-weight: 700;
  padding: 0 5px; border-bottom-right-radius: 4px; white-space: nowrap; pointer-events: none;
}
.dst-rect.off { border-style: dashed; opacity: .45; }
.handle { position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; background: #fff; border: 2px solid var(--c); border-radius: 3px; cursor: nwse-resize; touch-action: none; }
.canvas-wrap { position: relative; aspect-ratio: 9 / 16; background: #000; border-radius: 8px; overflow: hidden; }
.canvas-wrap canvas { width: 100%; height: 100%; display: block; }
.vpreview.small { width: 140px; margin: 0 auto; }
.layer-list { display: flex; flex-direction: column; gap: 6px; }
.layer-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); cursor: pointer; }
.layer-row.sel { border-color: var(--c); box-shadow: inset 3px 0 0 var(--c); }
.layer-row .swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--c); flex: none; }
.layer-row input.name { flex: 1; min-width: 60px; background: transparent; border: 1px solid transparent; padding: 3px 6px; }
.layer-row input.name:focus { border-color: var(--line); background: var(--bg); }
.layer-row .type { font-size: 11px; color: var(--muted); }
.layer-row button { padding: 3px 8px; }
.layer-row.off .swatch { opacity: .3; }
.inspector { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.inspector:empty { display: none; }
.inspector button { font-size: 12px; padding: 4px 9px; }

/* attention aids */
.aid-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.aid-grid:empty { display: none; }
.aid-grid.results { margin-top: 10px; }
.aid { position: relative; border-radius: 8px; overflow: hidden; background: #000; aspect-ratio: 16 / 9; border: 2px solid transparent; }
.aid.playing { border-color: var(--accent); }
.aid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.aid .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 6px; font-size: 11px; background: linear-gradient(transparent, rgba(0,0,0,.85)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aid button { position: absolute; top: 4px; right: 4px; padding: 0 7px; font-size: 12px; background: rgba(0,0,0,.7); }
.aid.job { display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; padding: 8px; }
.aid.job.failed { color: var(--bad); }
.button-like { display: inline-block; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; color: var(--text); font-size: 14px; margin: 0; }

/* go live */
.golive { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.dest {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 12px 14px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--panel-2);
}
.dest .dname { font-weight: 700; font-size: 15px; }
.dest .dstate { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.dest .dhears { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.dest.on { border-color: var(--warn); }
.dest.on.live { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, var(--panel-2)); }
.dest.on.live .dstate { color: var(--ok); font-weight: 700; }
.dest.on.retrying .dstate, .dest.on.starting .dstate { color: var(--warn); }
.dest.on.error { border-color: var(--bad); }
.dest.twitch .dname { color: var(--twitch); }
.dest.youtube .dname { color: var(--youtube); }
.dest:disabled { opacity: .5; cursor: not-allowed; }

/* audio routing */
table.routing { width: 100%; border-collapse: collapse; }
table.routing th { font-size: 12px; color: var(--muted); font-weight: 600; text-align: center; padding: 4px; }
table.routing th:first-child { text-align: left; }
table.routing td { padding: 4px; border-top: 1px solid var(--line); text-align: center; }
table.routing td:first-child { display: flex; align-items: center; gap: 8px; text-align: left; }
table.routing .tnum { width: 20px; color: var(--muted); font-size: 12px; text-align: right; flex: none; }
table.routing input.tname { background: transparent; border: 1px solid transparent; padding: 4px 6px; }
table.routing input.tname:focus { border-color: var(--line); background: var(--bg); }
table.routing tr.absent { opacity: .4; }
button.route { min-width: 56px; padding: 4px 10px; font-size: 12.5px; color: var(--muted); }
button.route.on { background: color-mix(in srgb, var(--ok) 22%, var(--panel-2)); border-color: var(--ok); color: var(--text); font-weight: 600; }
select.sel { width: 100%; padding: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
/* viewer stats */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.stat-tile { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.stat-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; color: var(--text); }
.stat-tile.hero .stat-value { font-size: 34px; }
.stat-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.swatch.tw { background: #a970ff; }
.swatch.yt { background: #f74a41; }
.viewer-chart { position: relative; margin-top: 12px; height: 150px; }
.viewer-chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.viewer-chart .grid { stroke: var(--line); stroke-width: 1; }
.viewer-chart .axis { fill: var(--muted); font-size: 11px; }
.viewer-chart .empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.chart-tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12px; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.4); z-index: 3; }
.chart-tip .row { gap: 6px; }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.chart-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.stat-chat { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; margin-top: 10px; color: var(--muted); }
.stat-chat b { color: var(--text); font-variant-numeric: tabular-nums; }
.stat-table { margin-top: 8px; font-size: 12px; }
.stat-table table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.stat-table th, .stat-table td { text-align: right; padding: 3px 6px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.stat-table th:first-child, .stat-table td:first-child { text-align: left; }

/* preview transport label */
.transport-badge { position: absolute; top: 6px; right: 6px; z-index: 6; font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: rgba(62, 207, 142, .85); color: #06241a; pointer-events: none; }
.transport-badge.slow { background: rgba(242, 181, 68, .9); color: #2a1d02; }

/* delay meter */
.delay-steps { margin: 0 0 10px; padding-left: 20px; font-size: 13px; }
.delay-steps li { margin: 3px 0; }
table.delay { width: 100%; border-collapse: collapse; margin-top: 12px; }
table.delay td { padding: 6px 4px; border-top: 1px solid var(--line); }
table.delay td.num { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
table.delay td.err { color: var(--bad); font-size: 12px; }

/* text layer inspector */
.text-inspector { flex-basis: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 6px 10px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.text-inspector label { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.text-inspector label.wide { grid-column: 1 / -1; }
.text-inspector label.check { flex-direction: row; align-items: center; margin-top: 18px; }
.text-inspector textarea { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: inherit; resize: vertical; }
.text-inspector input[type=color] { width: 100%; height: 34px; padding: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.text-inspector input[type=number] { width: 100%; }

/* vertical sleep */
.vpreview .offline { flex-direction: column; gap: 8px; }
.vpreview .offline button { font-size: 12px; padding: 4px 8px; }
.sleep-btn { display: block; margin: 8px auto 0; font-size: 12px; padding: 4px 10px; }

/* chat overlay builder */
.overlay-builder { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
@media (max-width: 860px) { .overlay-builder { grid-template-columns: 1fr; } }
.ov-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 12px; }
.ov-grid label { display: flex; flex-direction: column; gap: 4px; }
.ov-grid label.check { flex-direction: row; align-items: center; margin-top: 22px; }
.ov-grid input[type=color] { width: 100%; height: 36px; padding: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.ov-grid input[type=number] { width: 100%; }
.ov-preview iframe {
  width: 100%; height: 420px; border: 1px solid var(--line); border-radius: 8px; display: block;
  background: repeating-conic-gradient(#2a2f3a 0 25%, #1c2029 0 50%) 0 0 / 20px 20px;
}
h3.sub { font-size: 13px; margin: 14px 0 0; }
h3.sub:first-of-type { margin-top: 0; }
@media (max-width: 700px) {
  table.routing th { font-size: 11px; }
  button.route { min-width: 0; padding: 4px 8px; }
}

/* ---------- platform sign-in + connections ---------- */
.signin-btn { display: block; text-align: center; padding: 10px; margin: 8px 0; border-radius: 8px; font-weight: 600;
  text-decoration: none; color: #fff; background: color-mix(in srgb, var(--brand) 78%, #000); border: 1px solid var(--brand); }
.signin-btn:hover { background: var(--brand); color: #000; }
.conn { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.conn:last-child { border-bottom: 0; }
.conn .who { flex: 1; }
.conn .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.conn .warn { color: var(--bad); font-size: 12px; }
