: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; }
}
