:root {
  --bg: #1e1f22; --side: #2b2d31; --main: #313338; --panel: #383a40; --line: #3f4147;
  --text: #e3e5e8; --muted: #9a9ca3; --accent: #1a8cff; --accent-h: #1272d6; --neon: #00d4ff;
  --danger: #da373c; --ok: #23a55a; --warn: #f0b232;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
.logo { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.error { color: #ff6b6f; min-height: 1.2em; margin: .4rem 0 0; font-size: .9rem; }
svg.i { width: 20px; height: 20px; flex: none; }
.spacer { flex: 1; }

input, select { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: .55rem .65rem; font: inherit; width: 100%; }
input[type=range] { padding: 0; border: 0; background: transparent; accent-color: var(--accent); }
input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); border-color: transparent; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); font-size: .95rem; }
label.check input, .options input { width: auto; }
.val { color: var(--text); font-variant-numeric: tabular-nums; }

button { font: inherit; border: 0; border-radius: 6px; padding: .5rem .9rem; cursor: pointer; color: var(--text); background: var(--panel); }
button:hover:not(:disabled) { filter: brightness(1.15); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: #fff; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.danger { background: var(--danger); color: #fff; }
button.small { padding: .3rem .7rem; font-size: .85rem; }
.icon-btn { background: transparent; padding: .35rem; border-radius: 6px; display: inline-grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--panel); color: var(--text); filter: none; }
.icon-btn.active { color: var(--text); }

.center { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.card { background: var(--side); border-radius: 10px; padding: 1.4rem; }
.login { width: min(370px, 100%); display: flex; flex-direction: column; gap: .8rem; }
.login h1 { font-size: 1.7rem; text-align: center; }
.login-logo { align-self: center; border-radius: 22px; box-shadow: 0 0 36px rgba(0,180,255,.3); }
.login > p.muted { text-align: center; margin-top: -.3rem; }

/* ---------- layout: rooms | main | members ---------- */
.layout { display: grid; grid-template-columns: 260px 1fr 240px; height: 100vh; }
.layout.no-members { grid-template-columns: 260px 1fr; }
.layout.no-members .members { display: none; }

.sidebar { background: var(--side); display: flex; flex-direction: column; min-height: 0; }
.brand { padding: 0 1rem; font-weight: 700; font-size: 1.05rem; border-bottom: 1px solid #1f2023; height: 49px; display: flex; align-items: center; gap: .55rem; }
.brand img { border-radius: 7px; }
.section-head { display: flex; align-items: center; justify-content: space-between; padding: .9rem .6rem .3rem 1rem; text-transform: uppercase; font-size: .72rem; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.rooms { list-style: none; margin: 0; padding: 0 .5rem; overflow-y: auto; flex: 1; }
.room { margin-bottom: 2px; }
.room-row { display: flex; align-items: center; gap: .45rem; padding: .4rem .5rem; border-radius: 6px; color: var(--muted); cursor: pointer; }
.room-row:hover { background: var(--panel); color: var(--text); }
.room.active .room-row { background: #404249; color: var(--text); }
.room-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-row .more { visibility: hidden; }
.room-row:hover .more { visibility: visible; }
.live { font-size: .62rem; background: var(--danger); color: #fff; border-radius: 4px; padding: .05rem .35rem; font-weight: 700; letter-spacing: .02em; }
.room-people { list-style: none; margin: 0 0 .3rem; padding: 0 0 0 1.9rem; }
.room-people li { display: flex; align-items: center; gap: .4rem; font-size: .88rem; color: var(--muted); padding: .12rem 0; }
.room-people li .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-people .avatar { width: 22px; height: 22px; font-size: .6rem; }
.room-people svg.i { width: 15px; height: 15px; }

.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: inline-grid; place-items: center; font-weight: 700; font-size: .8rem; flex: none; text-transform: uppercase; position: relative; }
.userbar { display: flex; align-items: center; gap: .25rem; padding: .55rem .5rem; background: #232428; }
.me-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; padding-left: .35rem; }
.me-text b { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text small { color: var(--muted); font-size: .75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text small.on { color: var(--ok); }

/* ---------- main ---------- */
.main { background: var(--main); min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.topbar { display: flex; align-items: center; gap: .7rem; padding: 0 .8rem 0 1.2rem; height: 49px; border-bottom: 1px solid #26272b; flex: none; }
.topbar h2 { font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: .72rem; padding: .1rem .55rem; border-radius: 99px; background: var(--panel); color: var(--muted); }
.pill.ok { background: #1d4a31; color: #8fe0ad; }
.pill.warn { background: #4f3e12; color: #f6d27c; }
.empty { margin: auto; text-align: center; padding: 2rem; }
.empty-logo { border-radius: 26px; box-shadow: 0 0 40px rgba(0,180,255,.25); margin-bottom: .8rem; }
.call { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.banner { margin: .8rem 1.2rem 0; padding: .65rem 1rem; border-radius: 8px; background: var(--panel); display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.banner span { flex: 1; }

/* Stage: the stream is always shown whole (contain) and centered; size presets scale it. */
.stage { padding: .9rem 1.2rem 0; display: flex; justify-content: center; flex: none; }
.stage-frame { position: relative; background: #000; border-radius: 10px; overflow: hidden; width: 100%; display: flex; flex-direction: column; }
.stage[data-size="s"] .stage-frame { max-width: 55%; }
.stage[data-size="m"] .stage-frame { max-width: 80%; }
.stage[data-size="l"] .stage-frame { max-width: 100%; }
.stage-video { display: flex; align-items: center; justify-content: center; background: #000; }
.stage-video video { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; max-height: var(--stage-max-h, 46vh); object-fit: contain; background: #000; }
.stage[data-size="s"] { --stage-max-h: 34vh; }
.stage[data-size="m"] { --stage-max-h: 52vh; }
.stage[data-size="l"] { --stage-max-h: 72vh; }
.stage-bar { display: flex; align-items: center; gap: .35rem; padding: .35rem .6rem; background: #111214; }
.stage-label { flex: 1; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vol { flex-direction: row; align-items: center; gap: .3rem; color: var(--muted); }
.vol input { width: 100px; }
.stage-frame:fullscreen { border-radius: 0; justify-content: center; }
.stage-frame:fullscreen .stage-video { flex: 1; min-height: 0; }
.stage-frame:fullscreen .stage-video video { width: 100%; height: 100%; max-height: none; }

.tiles { flex: 1; overflow-y: auto; padding: 1rem 1.2rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .8rem; align-content: start; min-height: 120px; }
.stage:not([hidden]) ~ .tiles { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.tile { background: var(--panel); border-radius: 10px; padding: 1rem .6rem .7rem; display: flex; flex-direction: column; align-items: center; gap: .45rem; border: 2px solid transparent; cursor: pointer; transition: border-color .12s; }
.tile:hover { background: #3d3f45; }
.tile.me { cursor: default; }
.tile.speaking { border-color: var(--neon); box-shadow: 0 0 14px rgba(0,212,255,.35); }
.tile .avatar { width: 54px; height: 54px; font-size: 1.15rem; }
.tile .tname { font-size: .9rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .badges { display: flex; gap: .3rem; min-height: 20px; color: var(--muted); align-items: center; }
.red { color: #ff6b6f; }
.crown { color: var(--warn); }

.controls { display: flex; justify-content: center; gap: .6rem; padding: .75rem; border-top: 1px solid #26272b; flex-wrap: wrap; flex: none; }
.ctl { display: flex; align-items: center; gap: .45rem; padding: .6rem 1rem; border-radius: 99px; }
.ctl.off { background: #4a1d1f; color: #ff9a9d; }
.ctl.on { background: var(--danger); color: #fff; }
.ctl.leave { background: var(--danger); color: #fff; }

/* ---------- members ---------- */
.members { background: var(--side); overflow-y: auto; padding: .6rem .5rem 1rem; }
.mgroup { text-transform: uppercase; font-size: .72rem; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: .9rem .5rem .35rem; }
.member { display: flex; align-items: center; gap: .6rem; padding: .35rem .5rem; border-radius: 6px; }
.member:hover { background: var(--panel); }
.member.off { opacity: .45; }
.member .mtext { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.member .mtext b { font-weight: 500; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: .3rem; }
.member .mtext b svg.i { width: 14px; height: 14px; }
.member .mtext small { font-size: .74rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%; border: 3px solid var(--side); background: #80848e; }
.dot.on { background: var(--ok); }
.dot.voice { background: var(--accent); }

/* ---------- popups ---------- */
dialog { background: var(--side); color: var(--text); border: 1px solid var(--line); border-radius: 10px; width: min(440px, 94vw); padding: 1.3rem; }
dialog.wide { width: min(560px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog form { display: flex; flex-direction: column; gap: .85rem; }
dialog input:not([type]), dialog input[type=text], dialog input[type=password] { margin-top: .2rem; }
dialog .actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .3rem; }
dialog .actions.spread { justify-content: space-between; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.options { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .4rem; }
.options legend { font-size: .85rem; color: var(--muted); margin-bottom: .35rem; padding: 0; }
.options label { flex-direction: row; align-items: center; gap: .5rem; padding: .55rem .7rem; border-radius: 8px; background: var(--bg); color: var(--text); cursor: pointer; font-size: .93rem; flex-wrap: wrap; }
.options label:has(input:checked) { outline: 2px solid var(--accent); }
.hint { font-size: .82rem; margin: 0; }
.meter-wrap { display: flex; flex-direction: column; gap: .3rem; }
.meter { position: relative; height: 10px; border-radius: 5px; background: var(--bg); overflow: hidden; }
.meter-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--ok); transition: width .05s linear; }
.meter-fill.closed { background: #5c5f66; }
.meter-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--warn); }
.room-pick { display: flex; flex-direction: column; gap: .3rem; }
.room-pick button { text-align: left; }

.popmenu { position: fixed; z-index: 20; background: #111214; border-radius: 8px; padding: .35rem; min-width: 210px; box-shadow: 0 8px 30px rgba(0,0,0,.5); display: flex; flex-direction: column; }
.popmenu .mhead { font-size: .78rem; color: var(--muted); padding: .3rem .6rem; }
.popmenu .mslider { padding: .3rem .6rem .5rem; font-size: .85rem; color: var(--muted); }
.popmenu .mslider input { margin-top: .3rem; }
.popmenu hr { border: 0; border-top: 1px solid var(--line); margin: .3rem 0; width: 100%; }
.popmenu button { background: transparent; text-align: left; padding: .45rem .6rem; font-size: .9rem; border-radius: 4px; }
.popmenu button:hover { background: var(--accent); filter: none; }
.popmenu button.red { color: #ff6b6f; }
.popmenu button.red:hover { background: var(--danger); color: #fff; }

.toast { position: fixed; bottom: 5.2rem; left: 50%; transform: translateX(-50%); background: #111214; border: 1px solid var(--line); padding: .65rem 1rem; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.4); z-index: 30; max-width: 92vw; }

.mobile-only { display: none; }
@media (max-width: 1000px) {
  .layout, .layout.no-members { grid-template-columns: 240px 1fr; }
  .members { position: fixed; top: 49px; right: 0; bottom: 0; width: 250px; z-index: 9; box-shadow: -4px 0 30px rgba(0,0,0,.5); }
  .layout.no-members .members { display: none; }
}
@media (max-width: 760px) {
  .layout, .layout.no-members { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 22% 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 30px rgba(0,0,0,.5); }
  .sidebar.open { transform: none; }
  .mobile-only { display: inline-grid; }
  .topbar { padding-left: .5rem; }
  .ctl .lbl { display: none; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); }
  .stage { padding: .6rem .6rem 0; }
  .grid2 { grid-template-columns: 1fr; }
}
.mempty { font-size: .82rem; padding: .2rem .5rem .4rem; }
.me-text small.red { color: #ff6b6f; }
.userbar .icon-btn.off { color: #ff6b6f; }
.userbar .icon-btn { padding: .4rem; }
