:root {
  --bg: #08090d;
  --bg-2: #0d1016;
  --panel: #131820;
  --panel-2: #191f2a;
  --line: #2a3344;
  --line-2: #3a4558;
  --gold: #e2b043;
  --gold-2: #f3d48a;
  --live: #ff3355;
  --prev: #3ee07f;
  --text: #f3efe6;
  --muted: #8b93a3;
  --blue: #7eb0ff;
  --danger: #ff6b6b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --font: "Manrope", "Segoe UI", sans-serif;
  --cond: "Barlow Condensed", "Arial Narrow", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
a { color: var(--gold); text-decoration: none; }

.bg-grid {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(226, 176, 67, 0.12), transparent 55%),
    radial-gradient(900px 400px at 100% 0%, rgba(126, 176, 255, 0.08), transparent 50%),
    linear-gradient(180deg, #0b0d12 0%, #08090d 100%);
  z-index: -2;
}
.bg-grid::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at 50% 30%, black, transparent 75%);
  z-index: -1;
}

.topbar, .login-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 9, 13, 0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--cond);
  letter-spacing: 0.18em;
  font-size: 22px;
  font-weight: 700;
}
.brand i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 12px var(--live);
  display: inline-block;
}
.brand span { color: var(--gold); }

.chip, .tally {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.tally.live { border-color: var(--live); color: var(--live); }
.tally.prev { border-color: var(--prev); color: var(--prev); }
.tally.idle { color: var(--muted); }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px 48px;
}
.login-card {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  background: linear-gradient(180deg, rgba(25,31,42,0.95), rgba(13,16,22,0.95));
  border: 1px solid var(--line);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.login-visual {
  padding: 36px;
  background:
    linear-gradient(160deg, rgba(226,176,67,0.16), transparent 42%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'><circle cx='12' cy='12' r='1.2' fill='rgba(255,255,255,0.12)'/></svg>");
}
.login-visual h1 {
  font-family: var(--cond);
  font-size: clamp(42px, 7vw, 72px);
  line-height: 0.9;
  margin: 18px 0 12px;
  letter-spacing: 0.02em;
}
.login-visual p { color: var(--muted); max-width: 36ch; }
.cred-box {
  margin-top: 28px;
  padding: 16px;
  border: 1px dashed var(--line-2);
  border-radius: 14px;
  background: rgba(0,0,0,0.25);
}
.cred-box b { color: var(--gold-2); letter-spacing: 0.08em; }
.cred-row { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; font-variant-numeric: tabular-nums; }
.login-form { padding: 36px; display: flex; flex-direction: column; gap: 12px; }
.login-form h2 { margin: 0 0 6px; font-size: 22px; }
label { font-size: 12px; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
input, select, textarea {
  width: 100%;
  background: #0c0f14;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); }
.btn {
  border: 0;
  border-radius: 10px;
  padding: 12px 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.btn-gold { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #1a1408; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn-live { background: var(--live); color: white; }
.btn-prev { background: #1b3a28; color: var(--prev); border: 1px solid #2e6a48; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.small { padding: 8px 10px; font-size: 12px; }
.btn.active { outline: 2px solid var(--gold); }
.err { color: var(--danger); min-height: 1.2em; font-size: 13px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { color: var(--muted); font-size: 13px; }

.studio-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}
.workspace {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  gap: 12px;
  padding: 12px;
  align-items: start;
}
.col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.panel h3 {
  margin: 0 0 10px;
  font-family: var(--cond);
  letter-spacing: 0.12em;
  font-size: 18px;
  color: var(--gold-2);
  text-transform: uppercase;
}
.source-grid { display: grid; gap: 10px; }
.tile {
  position: relative;
  background: #07090e;
  border: 2px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 16/9;
}
.tile video, .tile canvas { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.tile.pgm { border-color: var(--live); box-shadow: 0 0 0 1px rgba(255,51,85,0.35); }
.tile.pvw { border-color: var(--prev); }
.tile .meta {
  position: absolute;
  left: 8px; right: 8px; bottom: 8px;
  display: flex; justify-content: space-between; gap: 6px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  text-shadow: 0 1px 4px #000;
}
.tile .badge {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0,0,0,0.7);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11px;
}
.monitors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.monitor { min-height: 0; }
.monitor .screen {
  aspect-ratio: 16/9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--line);
  position: relative;
}
.monitor .screen.pgm { border-color: var(--live); }
.monitor .screen.pvw { border-color: var(--prev); }
.monitor canvas, .monitor video { width: 100%; height: 100%; object-fit: contain; display: block; }
.monitor header, .panel-head {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;
}
.clock { font-variant-numeric: tabular-nums; color: var(--gold-2); font-family: var(--cond); font-size: 22px; }
.transport {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  padding: 10px 12px 16px;
  border-top: 1px solid var(--line);
  background: #0b0e14;
}
.anim-grid, .mix-grid, .color-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.anim-grid button, .mix-grid button, .color-grid button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.anim-grid button:hover, .mix-grid button:hover { border-color: var(--gold); }
.anim-grid button.on, .mix-grid button.on, .layout-btn.on { background: #2a2316; border-color: var(--gold); color: var(--gold-2); }
.fader { width: 100%; accent-color: var(--gold); }
.kv { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin: 4px 0; }
.qr { width: 132px; height: 132px; background: white; border-radius: 8px; padding: 6px; }
.qr img { display: block; width: 100%; height: 100%; }
.join-url { font-size: 11px; word-break: break-all; color: var(--blue); }
.log {
  height: 90px; overflow: auto; font-size: 11px; color: var(--muted);
  background: #0a0c11; border-radius: 8px; padding: 8px; border: 1px solid var(--line);
}
.hidden { display: none !important; }
.overlay-title {
  position: absolute; left: 6%; right: 6%; bottom: 10%;
  padding: 10px 14px;
  background: linear-gradient(90deg, rgba(0,0,0,0.8), rgba(0,0,0,0.2));
  border-left: 4px solid var(--gold);
  pointer-events: none;
}
.cam-page { min-height: 100vh; display: flex; flex-direction: column; }
.cam-preview { flex: 1; min-height: 52vh; background: #000; position: relative; }
.cam-preview video { width: 100%; height: 100%; min-height: 52vh; object-fit: contain; }
.cam-id { margin: 6px 0 8px; }
.cam-dock {
  padding: 16px;
  background: #0e1118;
  border-top: 1px solid var(--line);
}
.onair {
  position: absolute; top: 16px; left: 16px; right: 16px;
  background: var(--live); color: white; font-weight: 800;
  letter-spacing: 0.2em; text-align: center; padding: 10px;
  border-radius: 10px; display: none;
}
.onair.show { display: block; }
.res-pill {
  position: absolute; bottom: 16px; left: 16px;
  background: rgba(0,0,0,0.65); padding: 6px 10px; border-radius: 999px; font-size: 12px;
}
.layout-row { display: flex; gap: 6px; flex-wrap: wrap; }
.layout-btn { flex: 1; min-width: 72px; }
.meter {
  height: 8px; background: #222; border-radius: 99px; overflow: hidden; margin-top: 6px;
}
.meter > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #3ee07f, #e2b043, #ff3355); }
.file-list { display: flex; flex-direction: column; gap: 6px; max-height: 160px; overflow: auto; }
.file-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: #0c1017; border: 1px solid var(--line); border-radius: 8px; padding: 8px;
  font-size: 12px;
}
.shortcuts { font-size: 11px; color: var(--muted); line-height: 1.6; }
.toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 50;
  background: #151b26; border: 1px solid var(--gold); color: var(--text);
  padding: 10px 14px; border-radius: 10px; display: none; box-shadow: var(--shadow);
}
.toast.show { display: block; }
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .login-card { grid-template-columns: 1fr; }
  .monitors { grid-template-columns: 1fr; }
}
