:root {
  --bg: #313338;
  --bg-side: #2b2d31;
  --bg-dark: #1e1f22;
  --bg-stage: #111214;
  --bg-hover: #35373c;
  --bg-active: #404249;
  --text: #f2f3f5;
  --text-dim: #b5bac1;
  --text-mute: #949ba4;
  --accent: #6d4aff;
  --speak: #23a55a;
  --speak-text: #2dc770;
  --warn: #f0b232;
  --danger: #da373c;
  --live: #d83c3e;
  --dots: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22'%3E%3Ccircle cx='1' cy='1' r='1' fill='%23fff' fill-opacity='.07'/%3E%3C/svg%3E");
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg-stage);
  color: var(--text);
  font: 15px/1.35 "gg sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
[hidden] { display: none !important; }
.ic { width: 20px; height: 20px; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.logo {
  width: 28px;
  height: 28px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
}
.logo .ic { width: 18px; height: 18px; }
.logo-lg { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 16px; }
.logo-lg .ic { width: 32px; height: 32px; }

/* ---------- вход ---------- */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--dots) var(--bg-stage);
}
.login-card {
  width: min(400px, 100%);
  background: var(--bg);
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 8px 32px rgb(0 0 0 / .4);
  text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card p { margin: 0 0 20px; color: var(--text-dim); }
.login-card input, .field {
  width: 100%;
  padding: 12px;
  border-radius: 6px;
  border: 0;
  background: var(--bg-dark);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  outline: none;
}
.login-card input:focus-visible, .field:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.login-card button {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  transition: filter .15s;
}
.login-card button:hover { filter: brightness(1.1); }

/* ---------- раскладка ---------- */
.app {
  display: grid;
  grid-template-columns: 248px 1fr 248px;
  grid-template-rows: minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

/* ---------- левая колонка ---------- */
.channels { background: var(--bg-side); display: flex; flex-direction: column; min-width: 0; }
.server-name {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  font-weight: 700;
  box-shadow: 0 1px 0 rgb(0 0 0 / .25);
}
.section-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 18px 12px 6px 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--text-mute);
}
.section-label > span { flex: 1; }
.section-label .ic { width: 14px; height: 14px; }
.mini-btn {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: var(--text-mute);
}
.mini-btn:hover { color: var(--text); background: var(--bg-hover); }
.mini-btn .ic { width: 16px; height: 16px; }

.rooms { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.room {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  color: var(--text-mute);
  cursor: pointer;
  user-select: none;
}
.room:hover { background: var(--bg-hover); color: var(--text-dim); }
.room.active { background: var(--bg-active); color: var(--text); }
.room-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.room-ic {
  width: 26px;
  height: 26px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 16%, transparent);
}
.room-ic .ic { width: 16px; height: 16px; }
.room-edit {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: var(--text-mute);
  opacity: 0;
}
.room-edit .ic { width: 14px; height: 14px; }
.room:hover .room-edit, .room-edit:focus-visible { opacity: 1; }
.room-edit:hover { color: var(--text); }
.room-users { padding: 2px 0 6px 34px; }
.room-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 6px;
  color: var(--text-dim);
  font-size: 14px;
  border-radius: 4px;
}
.room-user .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.off { color: var(--text-mute); }
.room-user .ic, .tile-name .ic { width: 16px; height: 16px; }

.live {
  background: var(--live);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  letter-spacing: .02em;
}

/* ---------- плашка голоса + пинг ---------- */
.voice-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 12px;
  border-top: 1px solid var(--bg-active);
  background: #232428;
}
.voice-info { flex: 1; min-width: 0; }
.voice-status { display: flex; align-items: baseline; gap: 8px; color: var(--speak-text); font-weight: 600; font-size: 14px; white-space: nowrap; }
#voiceStatus { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.voice-status .ping { flex: none; }
.voice-bar.connecting .voice-status { color: var(--warn); }
.voice-room { color: var(--text-mute); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ping { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ping.q4, .ping.q3 { color: var(--speak-text); }
.ping.q2 { color: var(--warn); }
.ping.q1 { color: #f26c6f; }

.signal { display: flex; align-items: flex-end; gap: 2px; height: 16px; }
.signal i { width: 4px; border-radius: 1px; background: var(--bg-active); }
.signal i:nth-child(1) { height: 25%; }
.signal i:nth-child(2) { height: 50%; }
.signal i:nth-child(3) { height: 75%; }
.signal i:nth-child(4) { height: 100%; }
.signal.q4 i, .signal.q3 i:nth-child(-n+3) { background: var(--speak); }
.signal.q2 i:nth-child(-n+2) { background: var(--warn); }
.signal.q1 i:nth-child(1) { background: var(--danger); }

.me {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px;
  background: #232428;
}
.me-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px;
  border-radius: 6px;
  text-align: left;
}
.me-btn:hover { background: var(--bg-hover); }
.me-info { display: block; flex: 1; min-width: 0; }
.me-name { display: block; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-sub { display: block; font-size: 12px; color: var(--text-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--text-dim);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-active); color: var(--text); }
.icon-btn.off { color: var(--danger); }
.icon-btn.on { color: var(--speak); }
#leaveBtn:hover { color: var(--danger); }

/* ---------- аватарки ---------- */
.avatar {
  --size: 32px;
  width: var(--size);
  height: var(--size);
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: hsl(var(--h) 55% 45%);
  background-size: cover;
  background-position: center;
  color: #fff;
  font-weight: 700;
  font-size: calc(var(--size) * .42);
  transition: box-shadow .12s;
}
.avatar.sm { --size: 24px; }
.avatar.xl { --size: 80px; }
.avatar.speaking { box-shadow: 0 0 0 2px var(--bg-side), 0 0 0 4px var(--speak); }
.avatar-wrap { position: relative; flex: none; display: inline-flex; }
.avatar-wrap .dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--speak);
  border: 3px solid var(--bg-side);
}
.me .avatar-wrap .dot { border-color: #232428; }

/* ---------- сцена ---------- */
.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--dots) var(--bg-stage);
}
.stage-header {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  font-weight: 700;
}
#stageTitle { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.share-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}
.share-btn:hover { filter: brightness(1.1); }
.share-btn.on { background: var(--danger); }

.tiles {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 16px 16px;
}
.focus { flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; }
.grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: calc(var(--cols, 1) * var(--tw, 320px) + (var(--cols, 1) - 1) * 8px);
}
.grid > .tile { width: var(--tw, 320px); }
.strip { flex: none; display: flex; justify-content: safe center; gap: 8px; overflow-x: auto; }
.strip > .tile { width: 192px; flex: none; }

.tile {
  position: relative;
  aspect-ratio: 16 / 9;
  container-type: size;
  border-radius: 10px;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.tile.user { background: hsl(var(--h) 22% 17%); }
.tile .avatar { --size: clamp(64px, 40cqh, 190px); }
/* говорящего выделяет рамка плитки (кольца у аватарки в плитке нет — как в Дискорде) */
.tile.user::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px var(--speak), inset 0 0 0 4px rgb(0 0 0 / .35);
  opacity: 0;
  transition: opacity .12s;
  pointer-events: none;
}
.tile.user.speaking::after { opacity: 1; }
.tile-name {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgb(0 0 0 / .55);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile.screen { background: #000; cursor: zoom-in; }
.tile.screen video { width: 100%; height: 100%; object-fit: contain; }
.tile.screen:fullscreen { border-radius: 0; cursor: zoom-out; }

.empty { flex: 1; display: grid; place-items: center; padding: 16px; }
.empty-card {
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
  color: var(--text-mute);
}
.empty-card .ic { width: 48px; height: 48px; color: var(--accent); margin-bottom: 8px; }
.empty-card b { color: var(--text); font-size: 18px; }

/* ---------- правая колонка ---------- */
.members { background: var(--bg-side); overflow-y: auto; padding-bottom: 8px; }
.members .section-label { padding-top: 20px; }
.member { display: flex; align-items: center; gap: 12px; padding: 6px 16px; }
.member-info { flex: 1; min-width: 0; }
.member .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .sub { display: flex; align-items: center; gap: 4px; color: var(--text-mute); font-size: 12px; min-width: 0; }
.member .sub span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .sub .ic { width: 12px; height: 12px; color: var(--speak-text); }

/* ---------- диалоги ---------- */
.dlg {
  width: min(460px, calc(100% - 32px));
  padding: 24px;
  border: 0;
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 16px 48px rgb(0 0 0 / .5);
}
.dlg::backdrop { background: rgb(0 0 0 / .7); }
.dlg h2 { margin: 0 0 16px; font-size: 20px; }
.field-label {
  display: block;
  margin: 16px 0 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .02em;
  color: var(--text-dim);
}
.pills, .icon-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.pill, .icon-opt { position: relative; cursor: pointer; }
.pill input, .icon-opt input { position: absolute; opacity: 0; pointer-events: none; }
.pill span {
  display: block;
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--bg-dark);
  font-weight: 600;
  font-size: 14px;
  transition: background .12s;
}
.pill:hover span { background: var(--bg-hover); }
.pill input:checked + span { background: var(--accent); color: #fff; }
.icon-opt span {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, transparent);
  box-shadow: inset 0 0 0 2px transparent;
}
.icon-opt input:checked + span { box-shadow: inset 0 0 0 2px var(--c); }
.pill input:focus-visible + span, .icon-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.hint { margin: 16px 0 0; color: var(--text-mute); font-size: 13px; }
.dlg-actions { display: flex; align-items: center; gap: 8px; margin-top: 24px; }
.spacer { flex: 1; }
.btn { padding: 9px 16px; border-radius: 6px; font-weight: 600; font-size: 14px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost:hover { text-decoration: underline; }
.btn.danger { color: #f26c6f; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 15%, transparent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--bg-dark);
  box-shadow: 0 8px 24px rgb(0 0 0 / .5);
  font-size: 14px;
}

@media (max-width: 900px) {
  .app { grid-template-columns: 220px 1fr; }
  .members { display: none; }
}
@media (max-width: 600px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100dvh; }
  .stage { min-height: 60dvh; }
}

/* ---------- вход с паролем ---------- */
.login-card input + input { margin-top: 10px; }
.login-error { min-height: 20px; margin-top: 10px; color: #f26c6f; font-size: 14px; text-align: left; }
.login-card button:disabled { opacity: .6; cursor: wait; }

/* ---------- профиль ---------- */
.dlg form { position: relative; }
.dlg-close {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  font-size: 22px;
  line-height: 1;
  color: var(--text-mute);
}
.dlg-close:hover { color: var(--text); background: var(--bg-hover); }
.profile { display: flex; align-items: center; gap: 16px; }
.profile .hint { margin: 4px 0 0; }
.profile-name { font-size: 18px; font-weight: 700; }
label.btn { display: inline-block; cursor: pointer; }

/* ---------- меню громкости (правый клик) ---------- */
.user-menu {
  position: fixed;
  z-index: 10;
  width: 240px;
  padding: 12px;
  border-radius: 8px;
  background: var(--bg-dark);
  box-shadow: 0 8px 24px rgb(0 0 0 / .5);
}
.um-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.um-head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu .field-label { margin: 12px 0 6px; }
.um-row { display: flex; align-items: center; gap: 8px; }
.um-row input { flex: 1; min-width: 0; accent-color: var(--accent); }
.um-row span { width: 44px; text-align: right; font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.um-check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; cursor: pointer; }
.um-check input { width: 16px; height: 16px; accent-color: var(--danger); }
.dlg .um-check { margin-top: 20px; }
.dlg .um-check input { accent-color: var(--accent); }
.kicked { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgb(0 0 0 / .75); }

/* ---------- пространство: кружки, которые можно таскать ---------- */
.view-tabs { display: flex; gap: 2px; padding: 3px; border-radius: 8px; background: var(--bg-dark); }
.view-tabs button { padding: 5px 12px; border-radius: 6px; font-size: 13px; font-weight: 600; color: var(--text-mute); }
.view-tabs button:hover { color: var(--text); }
.view-tabs button.active { background: var(--bg-active); color: var(--text); }
.space { position: relative; flex: 1; min-height: 0; overflow: hidden; margin: 0 16px 16px; }
/* мир фиксированного размера 1600×900, масштабируется под окно — у всех одинаковые координаты */
.world {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1600px;
  height: 900px;
  transform: translate(-50%, -50%) scale(var(--s, 1));
  border-radius: 24px;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / .06);
}
.space-user { position: absolute; left: 0; top: 0; width: 144px; height: 144px; will-change: transform; }
.space-user .avatar { --size: 144px; box-shadow: 0 8px 24px rgb(0 0 0 / .45); transition: box-shadow .12s; }
.space-user.speaking .avatar { box-shadow: 0 0 0 5px var(--bg-stage), 0 0 0 10px var(--speak), 0 8px 24px rgb(0 0 0 / .45); }
.space-user { cursor: grab; touch-action: none; }
.space-user:active { cursor: grabbing; }
.space-user .live { position: absolute; left: 50%; top: -10px; transform: translateX(-50%); font-size: 14px; padding: 2px 8px; }
.space-name {
  position: absolute;
  left: 50%;
  top: calc(100% + 12px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 8px;
  background: rgb(0 0 0 / .55);
  font-size: 20px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}
.space-name .ic { width: 20px; height: 20px; }
.space-user.mine .space-name { background: var(--accent); }
.space-banner {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 12px;
  border-radius: 10px;
  background: var(--bg-dark);
  box-shadow: 0 8px 24px rgb(0 0 0 / .5);
  font-size: 14px;
  white-space: nowrap;
}
.space-hint { position: absolute; left: 0; bottom: 0; font-size: 12px; color: var(--text-mute); pointer-events: none; }

/* ---------- настройки голоса ---------- */
select.field { appearance: none; cursor: pointer; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--text-mute) 50%), linear-gradient(135deg, var(--text-mute) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; font-size: 14px; }
.ns-list { display: grid; gap: 6px; }
.ns-opt { position: relative; cursor: pointer; }
.ns-opt input { position: absolute; opacity: 0; pointer-events: none; }
.ns-opt span { display: grid; gap: 2px; padding: 10px 12px; border-radius: 8px; background: var(--bg-dark); box-shadow: inset 0 0 0 2px transparent; transition: background .12s; }
.ns-opt:hover span { background: var(--bg-hover); }
.ns-opt input:checked + span { box-shadow: inset 0 0 0 2px var(--accent); }
.ns-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.ns-opt b { font-size: 14px; }
.ns-opt small { font-size: 12px; color: var(--text-mute); }
#settingsDlg { max-height: calc(100dvh - 32px); overflow-y: auto; }
