:root {
  --bg: #1c1e24;
  --side: #15171c;
  --panel: #23262e;
  --panel-2: #2b2f39;
  --line: #2f333d;
  --text: #e9eaf0;
  --muted: #9a9fae;
  --dim: #6b7080;
  --accent: #8b7bff;
  --accent-2: #a597ff;
  --speak: #3fe08a;
  --danger: #ff5d6c;
  --radius: 14px;
  --font: "Rubik", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg { display: block; }

/* ---------- brand ---------- */
.brand-mark {
  width: 28px; height: 28px; border-radius: 9px; flex: none;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M16 7a4 4 0 0 0-4 4v5a4 4 0 0 0 8 0v-5a4 4 0 0 0-4-4zm-7 9a7 7 0 0 0 6 6.9V26h2v-3.1A7 7 0 0 0 23 16h-2a5 5 0 0 1-10 0z' fill='%23fff'/%3E%3C/svg%3E") center/100% no-repeat;
}

/* ---------- avatars ---------- */
.av {
  --s: 32px;
  position: relative;
  width: var(--s); height: var(--s); flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--c, #555);
  color: #fff; font-weight: 600; font-size: calc(var(--s) * .42);
  text-transform: uppercase;
  user-select: none;
  transition: box-shadow .12s ease;
}
.av img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.av-sm { --s: 24px; }
.av-md { --s: 36px; }
.av-lg { --s: 88px; }
.av-xl { --s: 112px; }
.speaking .av { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--speak); }
.speaking .av-lg { box-shadow: 0 0 0 3px var(--panel), 0 0 0 6px var(--speak), 0 0 24px 4px rgba(63, 224, 138, .35); }

/* ---------- login ---------- */
.login {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 24px 16px;
  overflow-y: auto;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(139, 123, 255, .22), transparent 60%),
    radial-gradient(700px 500px at 110% 110%, rgba(63, 224, 138, .12), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px 24px 22px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 22px; letter-spacing: -.01em; }
.login-sub { margin: -6px 0 6px; color: var(--muted); text-align: center; }
.av-pick { position: relative; cursor: pointer; border-radius: 50%; }
.av-pick .av { border: 2px dashed #4a4f5d; background-color: var(--panel-2); color: var(--muted); font-size: 13px; text-transform: none; font-weight: 500; }
.av-pick .av.has-img, .av-pick .av.has-letter { border: 0; }
.av-pick .av.has-letter { font-size: 46px; font-weight: 600; color: #fff; background-color: var(--c); }
.av-pick:hover .av { filter: brightness(1.08); }
.av-pick-badge {
  position: absolute; right: 2px; bottom: 2px;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 8h3l2-3h6l2 3h3v11H4z'/%3E%3Ccircle cx='12' cy='13' r='3.5'/%3E%3C/svg%3E") center/18px no-repeat;
  border: 3px solid var(--panel);
}
.link-btn { background: none; border: 0; color: var(--muted); font-size: 13px; text-decoration: underline; padding: 0; margin-top: -8px; }
.field { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.field input {
  width: 100%; height: 46px; padding: 0 14px;
  background: var(--side); border: 1px solid var(--line); border-radius: 12px;
  outline: none; transition: border-color .15s;
}
.field input:focus { border-color: var(--accent); }
.btn-primary {
  width: 100%; height: 48px; border: 0; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 16px;
  transition: background .15s, transform .05s;
}
.btn-primary:hover { background: var(--accent-2); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .6; cursor: wait; }
.login-err { margin: 0; min-height: 1em; color: var(--danger); font-size: 14px; text-align: center; }
.login-err:empty { display: none; }
.login-fine { margin: 0; color: var(--dim); font-size: 12.5px; text-align: center; }

/* ---------- app layout ---------- */
.app { height: 100%; height: 100dvh; display: grid; grid-template-columns: 300px 1fr; }
.side { background: var(--side); display: flex; flex-direction: column; min-height: 0; border-right: 1px solid #101216; }
.side-head { display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 16px; border-bottom: 1px solid #101216; flex: none; }
.side-head b { font-weight: 700; }
.online { margin-left: auto; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.online::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--speak); }
.online.off::before { background: var(--danger); }

.channels { flex: 1; overflow-y: auto; padding: 12px 8px; display: flex; flex-direction: column; gap: 4px; }
.ch {
  width: 100%; display: flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 10px;
  background: none; border: 0; border-radius: 8px;
  color: var(--muted); text-align: left; font-weight: 500;
}
.ch svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.ch:hover { background: #20232a; color: var(--text); }
.ch.active { background: #2a2e38; color: #fff; }
.ch-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-count { font-size: 12px; color: var(--dim); }
.ch-cap { font-size: 11px; color: var(--dim); }
.ch-users { list-style: none; margin: 0 0 6px; padding: 0 0 0 28px; display: flex; flex-direction: column; gap: 2px; }
.cu { display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 8px; border-radius: 6px; color: var(--muted); font-size: 14px; }
.cu .nick { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cu.me .nick { color: var(--text); }
.speaking .nick { color: #fff; }
.flags { display: flex; gap: 3px; color: var(--danger); }
.flags svg { width: 15px; height: 15px; }
.afk .cu { opacity: .7; }

.me-panel { flex: none; display: flex; align-items: center; gap: 6px; padding: 10px 8px calc(10px + env(safe-area-inset-bottom)); background: #111317; }
.me-who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.me-who .meta { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.me-who b { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-who small { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-who small.live { color: var(--speak); }
.me-btns { display: flex; gap: 0; }
.me-btns .icon-btn { width: 34px; height: 36px; }
.icon-btn {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 9px; background: none; color: var(--muted);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: #262a33; color: var(--text); }
.icon-btn.off { color: var(--danger); }
.icon-btn:focus-visible, .ch:focus-visible, .btn-primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.room-head { flex: none; height: 56px; display: flex; align-items: center; gap: 10px; padding: 0 20px; border-bottom: 1px solid #15171c; }
.room-icon svg { width: 22px; height: 22px; color: var(--muted); }
.room-head h1 { margin: 0; font-size: 17px; font-weight: 600; white-space: nowrap; }
.room-hint { color: var(--dim); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.banner {
  margin: 12px 20px 0; padding: 10px 14px; border-radius: 10px;
  background: rgba(255, 93, 108, .12); border: 1px solid rgba(255, 93, 108, .3); color: #ffc2c8; font-size: 14px;
}
.banner.click { cursor: pointer; background: rgba(139, 123, 255, .14); border-color: rgba(139, 123, 255, .4); color: #ddd8ff; }

.stage {
  flex: 1 1 55%; min-height: 0; overflow-y: auto;
  padding: 20px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px;
  align-content: start;
}
.tile {
  position: relative;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 12px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  min-width: 0;
  transition: border-color .15s, background .15s;
}
.tile.speaking { border-color: rgba(63, 224, 138, .45); background: #232a2a; }
.tile .nick { font-weight: 600; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .flags { position: absolute; top: 10px; right: 10px; }
.tile .flags svg { width: 18px; height: 18px; }
.tile .state { font-size: 12px; color: var(--dim); min-height: 18px; display: flex; align-items: center; gap: 6px; }
.tile .state.bad { color: var(--danger); }
.tile .state.wait::before { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
.tile.afk-tile .av { filter: grayscale(.6); opacity: .75; }
.tile.afk-tile::after { content: "z z"; position: absolute; top: 12px; left: 14px; color: var(--dim); font-weight: 600; letter-spacing: 2px; font-size: 12px; }
.vol { width: 100%; display: flex; align-items: center; gap: 6px; color: var(--dim); }
.vol svg { width: 16px; height: 16px; flex: none; }
.vol input { flex: 1; min-width: 0; accent-color: var(--accent); height: 18px; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  grid-column: 1 / -1;
  padding: 36px 16px; text-align: center; color: var(--muted);
  border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.empty button { margin-top: 14px; height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); }
.empty button:hover { border-color: var(--accent); }

/* ---------- chat ---------- */
.chat { flex: 1 1 45%; min-height: 0; display: flex; flex-direction: column; border-top: 1px solid #15171c; background: #1a1c21; }
.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 20px 6px; display: flex; flex-direction: column; }
.chat-log .none { margin: auto; color: var(--dim); font-size: 14px; }
.msg { display: flex; gap: 12px; padding: 6px 0 2px; }
.msg + .msg.cont { padding-top: 0; }
.msg .body { min-width: 0; flex: 1; }
.msg .head { display: flex; gap: 8px; align-items: baseline; }
.msg .head b { font-weight: 600; font-size: 14.5px; }
.msg .head time { font-size: 11.5px; color: var(--dim); }
.msg .text { word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; color: #d9dbe3; }
.msg .text a { color: var(--accent-2); }
.msg.cont .av { visibility: hidden; height: 0; }
.chat-form { flex: none; display: flex; gap: 8px; padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); }
.chat-form input {
  flex: 1; min-width: 0; height: 44px; padding: 0 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; outline: none;
}
.chat-form input:focus { border-color: var(--accent); }
.icon-btn.send { width: 44px; height: 44px; background: var(--accent); color: #fff; border-radius: 12px; }
.icon-btn.send:hover { background: var(--accent-2); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px);
  background: #0f1014; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 16px; font-size: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- push-to-talk ---------- */
.me-dock { flex: none; background: #111317; }
.ptt-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: calc(100% - 20px); height: 52px; margin: 10px 10px 0;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text); font-weight: 600;
  user-select: none; -webkit-user-select: none; touch-action: none; -webkit-touch-callout: none;
}
.ptt-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--dim); }
.ptt-btn.down { background: rgba(63, 224, 138, .16); border-color: var(--speak); }
.ptt-btn.down .ptt-dot { background: var(--speak); box-shadow: 0 0 0 4px rgba(63, 224, 138, .25); }

/* ---------- settings ---------- */
.settings {
  width: min(680px, calc(100% - 24px)); max-height: min(860px, calc(100dvh - 24px));
  padding: 0; border: 1px solid var(--line); border-radius: 20px;
  background: var(--panel); color: var(--text);
  box-shadow: 0 40px 100px rgba(0, 0, 0, .55);
  overflow: hidden;
}
.settings::backdrop { background: rgba(8, 9, 12, .7); backdrop-filter: blur(3px); }
.set-wrap { display: flex; flex-direction: column; max-height: inherit; margin: 0; }
.set-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 12px 24px; border-bottom: 1px solid var(--line); }
.set-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.set-body { overflow-y: auto; padding: 6px 24px 24px; }
.set-sec { padding: 18px 0 4px; }
.set-sec + .set-sec { border-top: 1px solid var(--line); }
.set-sec h3 { margin: 0 0 12px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.set-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.set-field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.set-field > span { font-size: 13.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.set-field output { color: var(--text); font-variant-numeric: tabular-nums; }
.set-field select, .keybind {
  width: 100%; height: 42px; padding: 0 12px;
  background: var(--side); border: 1px solid var(--line); border-radius: 10px; color: var(--text);
  outline: none; text-overflow: ellipsis;
}
.set-field select:focus, .keybind:focus-visible { border-color: var(--accent); }
.keybind { font-weight: 600; text-align: left; }
.keybind.wait { border-color: var(--accent); color: var(--accent-2); }
.set-field input[type=range] { accent-color: var(--accent); width: 100%; height: 22px; margin: 0; }
.set-note { margin: 10px 0 0; font-size: 13px; color: var(--dim); }
.set-note b { color: var(--text); font-weight: 500; }

.meter-row { display: flex; gap: 12px; align-items: center; }
.meter { position: relative; flex: 1; height: 34px; border-radius: 10px; background: var(--side); border: 1px solid var(--line); overflow: hidden; }
.meter-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #3a3f4c, #5b6070); transition: width .06s linear; }
.meter.on .meter-fill { background: linear-gradient(90deg, #2bb36a, var(--speak)); }
.meter-thr { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; opacity: .8; }
.meter input[type=range] {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0;
  -webkit-appearance: none; appearance: none; background: transparent; cursor: ew-resize;
}
.meter input[type=range]::-webkit-slider-runnable-track { height: 100%; background: transparent; }
.meter input[type=range]::-moz-range-track { height: 100%; background: transparent; }
.meter input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 34px; background: transparent; }
.meter input[type=range]::-moz-range-thumb { width: 16px; height: 34px; background: transparent; border: 0; }
.meter.ptt .meter-thr { display: none; }
.meter.ptt input { pointer-events: none; }
.btn-ghost {
  flex: none; height: 36px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font-size: 14px;
}
.btn-ghost:hover { border-color: var(--accent); }
.btn-ghost.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { position: relative; display: flex; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--side); cursor: pointer; }
.choice:hover { border-color: #444a58; }
.choice input { margin: 3px 0 0; accent-color: var(--accent); flex: none; }
.choice span { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.choice b { font-weight: 600; font-size: 14.5px; }
.choice small { color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.choice:has(input:checked) { border-color: var(--accent); background: rgba(139, 123, 255, .1); }
.choice.disabled { opacity: .45; pointer-events: none; }
.toggles { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 14.5px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.ptt-opts, .va-opts { margin-top: 14px; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .app { display: flex; flex-direction: column; }
  .side { display: contents; }
  .side-head { order: 1; height: 50px; background: var(--side); }
  .channels {
    order: 2; flex: none; flex-direction: row; overflow-x: auto; overflow-y: hidden;
    padding: 8px 12px; gap: 6px; background: var(--side); border-bottom: 1px solid #101216;
    scrollbar-width: none;
  }
  .channels::-webkit-scrollbar { display: none; }
  .ch-wrap { flex: none; }
  .ch { width: auto; height: 36px; padding: 0 12px; background: #20232a; border-radius: 999px; }
  .ch.active { background: var(--accent); color: #fff; }
  .ch.active .ch-count { color: rgba(255, 255, 255, .8); }
  .ch-cap { display: none; }
  .ch-users { display: none; }
  .main { order: 3; flex: 1; }
  .room-head { display: none; }
  .me-dock { order: 4; border-top: 1px solid #101216; }
  .stage { padding: 12px; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .tile { padding: 18px 10px 12px; }
  .av-lg { --s: 68px; }
  .banner { margin: 10px 12px 0; }
  .chat-log { padding: 10px 14px 4px; }
  .chat-form { padding: 8px 12px 10px; }
  .toast { bottom: 90px; }
  .settings { width: 100%; max-width: none; max-height: 100dvh; height: 100dvh; border-radius: 0; border: 0; margin: 0; }
  .set-body { padding: 4px 16px 24px; }
  .set-head { padding: 12px 10px 10px 16px; }
  .set-grid, .choices { grid-template-columns: 1fr; }
  .meter-row { flex-direction: column; align-items: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
