:root {
  --royal: #1f4fd8;
  --royal-dk: #1f3f9e;
  --ivory: #fbf7ee;
  --ivory-2: #f1e8d4;
  --gold: #c9a227;
  --ink: #1d2433;
  --muted: #5a6275;
  --line: #e3dccb;
  --green: #1f9d55;
  --red: #d64545;
  --amber: #c27c0e;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--ivory);
  color: var(--ink);
  overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

.btn {
  border: 0; border-radius: 10px; padding: 9px 16px;
  background: var(--royal); color: #fff; font-weight: 600;
}
.btn:hover { background: var(--royal-dk); }
.btn.gold { background: var(--gold); color: var(--ink); }
.btn.gold:hover { background: #b38f1f; }
.btn.ghost { background: transparent; color: var(--royal-dk); }
.btn.ghost:hover { background: #e9eefc; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.red { background: var(--red); }

/* login */
.login { height: 100%; display: grid; place-items: center; background: linear-gradient(160deg, var(--royal) 0%, var(--royal-dk) 100%); padding: 16px; }
.card { background: var(--ivory); border-radius: 18px; padding: 28px; width: min(360px, 100%); display: grid; gap: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.brand { font-size: 28px; font-weight: 800; color: var(--royal-dk); display: flex; align-items: center; gap: 10px; }
.logo { width: 40px; height: 40px; border-radius: 12px; background: var(--gold); color: var(--ink); display: grid; place-items: center; font-weight: 900; }
.sub { margin: -6px 0 6px; color: var(--muted); }
.card label { display: grid; gap: 4px; font-weight: 600; font-size: 13px; }
.card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.err { color: var(--red); min-height: 1.2em; margin: 0; font-size: 13px; }

/* app */
.app { height: 100%; display: flex; flex-direction: column; }
.videos { display: flex; gap: 8px; padding: 8px; overflow-x: auto; background: var(--royal-dk); flex: none; }
.videos:empty { display: none; }
.tile { position: relative; width: 192px; aspect-ratio: 16/9; border-radius: 10px; overflow: hidden; background: #111; flex: none; cursor: pointer; border: 2px solid transparent; }
.tile.speaking { border-color: var(--green); }
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile.screen video { object-fit: contain; }
.tile .name { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; padding: 2px 6px; border-radius: 6px; }
.tile.mirror video { transform: scaleX(-1); }

.middle { flex: 1; display: flex; min-height: 0; }
.stage-wrap { position: relative; flex: 1; display: grid; place-items: center; min-width: 0; background: var(--ivory-2); }
#map { image-rendering: pixelated; display: block; }
.stage { position: absolute; inset: 0; background: #0d1222; display: grid; place-items: center; }
.stage video { max-width: 100%; max-height: 100%; }
.stage-name { position: absolute; left: 12px; bottom: 12px; color: #fff; background: rgba(0,0,0,.6); padding: 4px 10px; border-radius: 8px; }
#stageClose { position: absolute; right: 12px; top: 12px; }

.menu { position: absolute; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.15); padding: 6px; display: grid; min-width: 170px; z-index: 5; }
.menu .who { font-weight: 700; padding: 6px 10px 4px; color: var(--royal-dk); }
.menu button { text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 8px; color: var(--ink); }
.menu button:hover { background: #eef2fd; }
.menu .vol { display: flex; align-items: center; gap: 6px; padding: 6px 8px 4px; border-top: 1px solid var(--line); margin-top: 4px; }
.menu .vol button { padding: 4px 6px; font-size: 16px; }
.menu .vol input { width: 120px; accent-color: var(--royal); }
.menu .vol span { font-size: 12px; color: var(--muted); min-width: 38px; text-align: right; }
.tile .tvol { position: absolute; right: 6px; top: 6px; border: 0; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 13px; padding: 2px 6px; }
.tile .tvol:hover { background: rgba(0,0,0,.85); }

/* chat */
.chat { width: 340px; flex: none; border-left: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); }
.chat-tabs { display: flex; gap: 6px; overflow-x: auto; flex: 1; }
.chip { border: 1px solid var(--line); background: var(--ivory); color: var(--ink); border-radius: 999px; padding: 4px 10px; white-space: nowrap; position: relative; font-size: 13px; }
.chip.active { background: var(--royal); border-color: var(--royal); color: #fff; }
.chip .pip { position: absolute; top: -2px; right: -2px; width: 9px; height: 9px; border-radius: 50%; background: var(--red); }
.chip .st { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.chat-title { padding: 8px 12px; font-weight: 700; color: var(--royal-dk); border-bottom: 1px solid var(--line); }
.chat-list { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; }
.msg .meta { font-size: 11px; color: var(--muted); }
.msg .txt { background: var(--ivory); border: 1px solid var(--line); padding: 6px 10px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.msg.mine { align-self: flex-end; text-align: right; }
.msg.mine .txt { background: var(--royal); color: #fff; border-color: var(--royal); text-align: left; }
.msg .txt a { color: var(--royal-dk); font-weight: 600; word-break: break-all; }
.msg.mine .txt a { color: #fff; text-decoration: underline; }
.msg .txt .copy { border: 0; background: rgba(0,0,0,.08); border-radius: 6px; padding: 0 5px; margin: 0 4px; font-size: 12px; vertical-align: middle; }
.msg.mine .txt .copy { background: rgba(255,255,255,.25); }
.msg .txt .copy:hover { background: rgba(0,0,0,.18); }
.chat-empty { color: var(--muted); text-align: center; margin-top: 30px; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; }

/* barra da call / gravação */
.callbar { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 6px 12px; background: #fdf3d6; border-top: 1px solid #ecd9a0; font-size: 13px; flex-wrap: wrap; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); display: inline-block; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.callbar a { color: var(--royal-dk); font-weight: 600; }

/* barra de baixo */
.bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--royal); color: #fff; flex: none; }
.me-chip { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.12); border: 0; color: #fff; border-radius: 12px; padding: 4px 12px 4px 4px; font-weight: 600; }
.me-chip canvas { image-rendering: pixelated; background: var(--ivory); border-radius: 8px; }
.controls { display: flex; gap: 6px; margin: 0 auto; }
.ctl { position: relative; display: flex; align-items: center; gap: 6px; border: 0; border-radius: 10px; padding: 8px 12px; background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.ctl:hover { background: rgba(255,255,255,.24); }
.ctl.on { background: var(--ivory); color: var(--royal-dk); }
.ctl.off .ico { filter: grayscale(1); opacity: .75; }
.ctl.live { background: var(--gold); color: var(--ink); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 2px solid #fff; }
.dot.on { background: var(--green); }
.dot.away { background: var(--amber); }
.dot.dnd { background: var(--red); }
.badge { position: absolute; top: -4px; right: -4px; background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; min-width: 18px; text-align: center; }
.room-lbl { font-weight: 700; white-space: nowrap; }

.toasts { position: fixed; right: 16px; bottom: 76px; display: grid; gap: 8px; z-index: 20; }
.toast { background: #fff; color: var(--ink); border-left: 4px solid var(--gold); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 10px 12px; display: grid; gap: 8px; max-width: 320px; }
.toast .acts { display: flex; gap: 6px; }

/* editor do boneco */
.dlg { border: 0; border-radius: 18px; padding: 22px; background: var(--ivory); color: var(--ink); width: min(520px, calc(100% - 32px)); }
.dlg::backdrop { background: rgba(15,25,60,.55); }
.dlg h2 { margin: 0 0 12px; color: var(--royal-dk); }
.av-wrap { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
#avPreview { image-rendering: pixelated; background: #fff; border-radius: 12px; border: 1px solid var(--line); }
.av-options { flex: 1; display: grid; gap: 10px; min-width: 240px; }
.av-row b { display: block; font-size: 12px; margin-bottom: 4px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.sw { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line); }
.sw.sel { border-color: var(--ink); box-shadow: 0 0 0 2px var(--gold); }
.opt { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; padding: 4px 9px; font-size: 13px; }
.opt.sel { background: var(--royal); color: #fff; border-color: var(--royal); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (max-width: 760px) {
  .ctl .lbl { display: none; }
  .room-lbl { display: none; }
  .chat { position: absolute; inset: 0 0 56px 0; width: auto; z-index: 10; }
}
