:root {
  --bg: #13111c; --panel: #1c1930; --panel2: #242040; --line: #332e52; --text: #f1eefb; --dim: #a9a3c4;
  --accent: #7c6cff; --accent2: #5b4be0; --ok: #4fd08a; --warn: #ffc65c; --bad: #ff7b8a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: #a9b8ff; }
h1 { font-size: 24px; margin: 0 0 8px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.dim { color: var(--dim); }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--accent2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.ghost:hover { background: var(--panel2); }
.btn.bad { background: #c9374b; }
.btn.ok { background: #1f9d60; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.on { background: var(--warn); color: #221a00; }
input[type=text], input[type=password], textarea { width: 100%; background: #100e18; color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; }
textarea { resize: vertical; }
label { display: block; margin: 14px 0 6px; color: var(--dim); font-size: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.center { max-width: 640px; margin: 0 auto; padding: 32px 16px; }
.err { color: var(--bad); min-height: 20px; margin-top: 10px; }
.note { background: #2b2440; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.note.warn { border-color: #6b5320; background: #2e2610; color: #ffe2a3; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* app layout: media on the left, side panel on the right */
.app { display: grid; grid-template-columns: minmax(0, 1fr) 380px; grid-template-rows: auto minmax(0, 1fr); height: 100%; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.top .title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: var(--panel2); color: var(--dim); white-space: nowrap; }
.badge.live { background: #d5354a; color: #fff; }
.badge.ok { background: #1f9d60; color: #fff; }
.main { padding: 16px; overflow: auto; min-width: 0; }
.side { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; color: var(--dim); padding: 12px 2px; white-space: nowrap; font-size: 14px; font: inherit; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.act { color: var(--text); border-bottom-color: var(--accent); }
.tabs .count { background: var(--accent); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 6px; margin-left: 4px; }
.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; overflow-y: auto; padding: 10px 12px; min-height: 0; }
.footer { padding: 10px 12px; border-top: 1px solid var(--line); }

.screen { position: relative; background: #000; border-radius: 14px; overflow: hidden; aspect-ratio: 16 / 9; width: 100%; max-height: calc(100vh - 190px); margin: 0 auto; }
.screen video, .screen canvas { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; background: rgba(12, 10, 22, .86); gap: 12px; font-size: 17px; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }

/* live stage as the guest sees it: tiles side by side */
.stage { position: absolute; inset: 0; display: grid; gap: 2px; background: #000; }
.stage.n1 { grid-template-columns: 1fr; }
.stage.n2 { grid-template-columns: 1fr 1fr; }
.stage.n3, .stage.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.tile { position: relative; background: #1b1830; overflow: hidden; min-height: 0; }
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile .name { position: absolute; left: 8px; bottom: 8px; background: rgba(0, 0, 0, .6); padding: 3px 9px; border-radius: 8px; font-size: 13px; }

.msg { padding: 8px 10px; border-radius: 10px; background: var(--panel2); margin-bottom: 8px; overflow-wrap: anywhere; }
.msg .who { font-weight: 700; font-size: 13px; color: #c9c1ff; }
.msg .when { font-size: 11px; color: var(--dim); margin-left: 6px; font-weight: 400; }
.msg.staff { background: #2a2f5a; }
.msg.pending { border: 1px dashed #6b5320; }
.msg .acts { margin-top: 6px; display: flex; gap: 6px; }
.person { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; justify-content: flex-end; }
.person .av { width: 36px; height: 36px; border-radius: 50%; background: var(--panel2); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; overflow: hidden; }
.person .av img { width: 100%; height: 100%; object-fit: cover; }
.person .nm { flex: 1 1 150px; min-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .hand { color: var(--warn); font-size: 12px; font-weight: 700; }
.linkbox { display: flex; gap: 6px; margin: 4px 0 10px; }
.linkbox input { font-size: 13px; padding: 7px 9px; }
.empty { color: var(--dim); text-align: center; padding: 24px 8px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2b2440; border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: 90vw; }
.modal { position: fixed; inset: 0; background: rgba(8, 6, 16, .8); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.modal .card { max-width: 460px; width: 100%; }
.offscreen { position: fixed; left: -4000px; top: 0; width: 320px; height: 180px; opacity: 0; pointer-events: none; }

@media (max-width: 860px) {
  html, body { height: auto; }
  .app { display: block; height: auto; }
  .side { border-left: 0; border-top: 1px solid var(--line); height: 70vh; }
  .screen { max-height: none; }
}
