:root {
  --bg: #f4f4f2; --card: #fff; --ink: #1d1d1b; --muted: #6b6b66; --line: #e3e2dd;
  --accent: #ff6c00; --accent-ink: #fff; --ok: #1f9d55; --warn: #c98a00; --bad: #d23c2a;
  --chord: #ff6c00; --radius: 12px; --shadow: 0 1px 3px rgba(0,0,0,.08), 0 6px 24px rgba(0,0,0,.05);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141413; --card: #1f1f1d; --ink: #ecebe6; --muted: #a09f99; --line: #33332f; --shadow: none; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; display: flex; flex-direction: column; min-height: 100vh; }
[hidden] { display: none !important; }
h2 { margin: 0 0 .5rem; font-size: 1.35rem; } h3 { margin: 0 0 .5rem; font-size: 1.05rem; }
.muted { color: var(--muted); } .hint { color: var(--muted); font-size: .85rem; margin: .4rem 0; }
.note { background: color-mix(in srgb, var(--accent) 8%, var(--card)); border-left: 3px solid var(--accent); padding: .5rem .7rem; border-radius: 6px; font-size: .88rem; }
.error { color: var(--bad); }
.pad { padding: 1rem; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .6rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; } .brand b { color: var(--accent); } .brand em { font-style: normal; font-size: .7rem; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 .3rem; margin-left: .3rem; }
.status { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--muted); min-width: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--ok); } .dot.off { background: var(--bad); }
.badge { border: 1px solid var(--line); border-radius: 999px; padding: .05rem .5rem; white-space: nowrap; }
.badge.relay { border-color: var(--warn); color: var(--warn); }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen { flex: 1; padding: 1rem; min-height: 0; }
.screen.center { display: flex; align-items: center; justify-content: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; }
.card.narrow { max-width: 30rem; width: 100%; }
.eyebrow { color: var(--accent); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; margin: 0 0 .3rem; }
.actions, .row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: 1rem; }
.small-list { padding-left: 1.1rem; }

button { font: inherit; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: .5rem .9rem; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.big { padding: .75rem 1.3rem; font-size: 1rem; width: 100%; margin-top: .8rem; }
button.ghost { background: transparent; }
button.small { padding: .25rem .6rem; font-size: .85rem; }
button.link { border: 0; background: none; color: var(--accent); padding: 0 .2rem; text-decoration: underline; }
button.danger, .ctl.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; }
textarea { width: 100%; font-family: var(--mono); font-size: .85rem; }
label { display: block; margin: .6rem 0; font-size: .9rem; }
label > select, label > input:not([type=checkbox]):not([type=radio]), label > textarea { display: block; width: 100%; margin-top: .25rem; }
label.check, label.radio { display: flex; align-items: center; gap: .45rem; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: .8rem 0; padding: .4rem .8rem .6rem; }
legend { font-size: .9rem; font-weight: 600; padding: 0 .3rem; }
details.fx summary { cursor: pointer; font-size: .85rem; color: var(--muted); margin-top: .6rem; }
details.fx pre { font-size: .75rem; background: var(--bg); padding: .5rem; border-radius: 6px; overflow: auto; }

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: .5rem auto 1rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Preparação */
.lobby { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 1rem; max-width: 64rem; margin: 0 auto; }
.video-box { position: relative; aspect-ratio: 4 / 3; background: #111; border-radius: 10px; overflow: hidden; }
.video-box video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.novideo { position: absolute; inset: 0; display: grid; place-items: center; color: #aaa; }
.meter { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; margin-top: .8rem; border: 1px solid var(--line); }
#meter-bar { height: 100%; width: 0; background: var(--ok); transition: width 60ms linear; }
#meter-bar.hot { background: var(--warn); } #meter-bar.clip { background: var(--bad); }
.peerline { color: var(--muted); font-size: .9rem; }

/* Sala */
.room { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(20rem, 1fr); gap: 1rem; height: 100%; min-height: 0; }
.stage { display: flex; flex-direction: column; gap: .7rem; min-height: 0; overflow: auto; }
.videos { position: relative; background: #111; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 10; flex: none; }
#remote-video { width: 100%; height: 100%; object-fit: contain; background: #111; }
.pip { position: absolute; right: .7rem; bottom: .7rem; width: 26%; max-width: 12rem; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 2px solid rgba(255,255,255,.7); background: #222; transform: scaleX(-1); }
.placeholder { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #ddd; gap: .6rem; text-align: center; padding: 1rem; }
.avatar { width: 84px; height: 84px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 2rem; font-weight: 700; }
.banner { position: absolute; left: .7rem; right: .7rem; top: .7rem; background: rgba(20,20,20,.85); color: #fff; padding: .55rem .8rem; border-radius: 8px; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; font-size: .9rem; }
.banner button { padding: .2rem .6rem; font-size: .85rem; }
.controls { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
.ctl { min-width: 7rem; }
.ctl.off { background: color-mix(in srgb, var(--bad) 14%, var(--card)); border-color: var(--bad); }
.ctl.on { background: color-mix(in srgb, var(--accent) 14%, var(--card)); border-color: var(--accent); }
.diag dl { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; font-size: .88rem; margin: .6rem 0; }
.diag dt { color: var(--muted); } .diag dd { margin: 0; font-variant-numeric: tabular-nums; }
.diag-tools label { margin: .4rem 0; }

.side { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs .tab, .tabs .dtab { flex: 1; border: 0; border-radius: 0; background: none; padding: .7rem; border-bottom: 2px solid transparent; }
.tabs .active { border-bottom-color: var(--accent); font-weight: 600; }
.count { background: var(--accent); color: #fff; border-radius: 999px; font-size: .7rem; padding: 0 .4rem; margin-left: .2rem; }
.tabpane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chart-head { padding: .7rem .8rem .3rem; border-bottom: 1px solid var(--line); }
.chart-title { font-size: 1rem; margin-bottom: .2rem; }
.control-line { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; font-size: .85rem; }
.control-line #btn-load-chart { margin-left: auto; }
.chart-tools { display: flex; flex-wrap: wrap; gap: .4rem .7rem; align-items: center; margin: .5rem 0 .2rem; font-size: .88rem; }
.chart-tools .grp { display: inline-flex; align-items: center; gap: .3rem; margin: 0; }
.chart-tools input[type=number] { width: 4.3rem; padding: .2rem .4rem; display: inline-block; margin: 0; }
.chart-tools select { padding: .2rem .4rem; display: inline-block; width: auto; margin: 0; }
.val { min-width: 6.5rem; text-align: center; font-variant-numeric: tabular-nums; }
.beatline { min-height: 1.5rem; display: flex; align-items: center; gap: .6rem; }
.beat { font-family: var(--mono); letter-spacing: .15em; color: var(--accent); font-weight: 700; }
.chips { display: flex; gap: .3rem; flex-wrap: wrap; margin: .3rem 0; }
.chip { font-size: .78rem; padding: .15rem .55rem; border-radius: 999px; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.small-label { font-size: .8rem; margin: .2rem 0; color: var(--muted); }
.chart-view { flex: 1; overflow: auto; padding: .4rem .2rem 2rem; }
pre.chart { font-family: var(--mono); font-size: .9rem; line-height: 1.35; margin: 0; padding: 0 .6rem; }
.ln { white-space: pre; min-height: 1.2em; }
.ln-chords .ch { color: var(--chord); font-weight: 700; }
.sec { font-weight: 700; color: var(--muted); }
.sec-block { border-left: 3px solid transparent; margin-left: -.6rem; padding-left: calc(.6rem - 3px); border-radius: 2px; transition: background .2s; }
.sec-block.active { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.ln-tab { color: var(--muted); }

.chat-list { list-style: none; margin: 0; padding: .7rem; flex: 1; overflow: auto; display: flex; flex-direction: column; gap: .5rem; }
.chat-list li { max-width: 85%; background: var(--bg); border-radius: 10px; padding: .4rem .6rem; }
.chat-list li.me { align-self: flex-end; background: color-mix(in srgb, var(--accent) 15%, var(--card)); }
.chat-list .who { font-size: .75rem; color: var(--muted); }
.chat-list .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-form { display: flex; gap: .4rem; padding: .6rem; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; }

.stars { display: flex; gap: .3rem; }
.stars button { width: 2.4rem; padding: .3rem 0; }
.stars button.sel { background: var(--accent); color: #fff; border-color: var(--accent); }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); width: min(40rem, 94vw); padding: 1rem; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.small-tabs { margin-bottom: .6rem; }
.examples { display: grid; gap: .4rem; }
.examples button { text-align: left; }

.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .4rem; z-index: 50; width: min(34rem, 94vw); }
.toast { background: #222; color: #fff; border-radius: 10px; padding: .6rem .8rem; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; box-shadow: var(--shadow); font-size: .9rem; }
.toast button { padding: .2rem .6rem; font-size: .85rem; }

@media (max-width: 860px) {
  .lobby, .room { grid-template-columns: 1fr; }
  .room { height: auto; }
  .side { min-height: 70vh; }
  .ctl { min-width: 0; flex: 1 1 30%; }
  .screen { padding: .6rem; }
  .status #status-text { max-width: 11rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
.selftest-log { font-size: .78rem; background: var(--bg); padding: .6rem; border-radius: 8px; min-height: 6rem; white-space: pre-wrap; }
.card.selftest { max-width: 48rem; margin: 0 auto; }
