:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --text: #101828;
  --muted: #5b6677;
  --line: #e3e7ee;
  --primary: #1d5bd6;
  --primary-hover: #1749ac;
  --primary-ink: #ffffff;
  --danger: #d92d20;
  --danger-hover: #b42318;
  --success: #12a15f;
  --warn: #dc8b0a;
  --ring: rgba(29, 91, 214, .35);
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c111a;
    --surface: #141b27;
    --surface-2: #1a2331;
    --text: #e8ecf3;
    --muted: #93a0b4;
    --line: #263043;
    --primary: #4f86f7;
    --primary-hover: #6b9bfa;
    --primary-ink: #07101f;
    --danger: #e5484d;
    --danger-hover: #f4695e;
    --success: #3dd68c;
    --warn: #f5b13d;
    --ring: rgba(79, 134, 247, .45);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

/* Шапка */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 60px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--success);
  background: color-mix(in srgb, var(--success) 12%, transparent);
}
.badge .ic { width: 15px; height: 15px; }

main { max-width: 1040px; margin: 0 auto; padding: 32px 16px 120px; }

/* Карточка входа */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.lobby { max-width: 520px; margin: 24px auto 0; padding: 32px; }
.lobby h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.02em; }
.lead { margin: 0 0 24px; color: var(--muted); }

.field { margin-bottom: 20px; }
label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; }
.help { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
code { background: var(--surface-2); border: 1px solid var(--line); padding: 0 5px; border-radius: 5px; font-size: 12px; }

input:not([type]), input[type=text], input[readonly], select {
  width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); color: var(--text); font: inherit; min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
input[readonly] { color: var(--muted); text-overflow: ellipsis; }
.input-group { display: flex; gap: 8px; }

.meter { height: 6px; margin-top: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 100%; background: var(--success); border-radius: inherit; transform: scaleX(0); transform-origin: left; transition: transform .08s linear; }

details { margin: 0 0 24px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
summary { padding: 10px 14px; cursor: pointer; font-weight: 600; font-size: 14px; }
details[open] summary { border-bottom: 1px solid var(--line); }
.check { display: flex; align-items: flex-start; gap: 10px; margin: 0; padding: 10px 14px; font-weight: 400; font-size: 14px; cursor: pointer; }
.check input { margin: 3px 0 0; accent-color: var(--primary); width: 16px; height: 16px; flex: none; }
.check small { color: var(--muted); }

.error { min-height: 1.5em; margin: 12px 0 0; color: var(--danger); font-size: 14px; }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 42px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: var(--danger-hover); }
.btn.block { width: 100%; height: 46px; font-size: 16px; }

/* Комната */
.room-head { margin-bottom: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chip .ic { width: 15px; height: 15px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.dot.ok { background: var(--success); }
.dot.bad { background: var(--danger); }
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.bars i { width: 3px; border-radius: 1px; background: var(--line); }
.bars i:nth-child(1) { height: 5px; } .bars i:nth-child(2) { height: 9px; } .bars i:nth-child(3) { height: 14px; }
.q3 .bars i { background: var(--success); }
.q2 .bars i:nth-child(-n+2) { background: var(--warn); }
.q1 .bars i:nth-child(1) { background: var(--danger); }

.chip-select {
  width: auto; height: 32px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer;
}

.grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.pcard {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 28px 16px 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.pcard.speaking { border-color: var(--success); box-shadow: 0 0 0 1px var(--success), var(--shadow); }

.avatar {
  position: relative; width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center;
  font-size: 32px; font-weight: 700; color: #fff; user-select: none;
  transform: scale(calc(1 + var(--lvl, 0) * .1)); transition: transform .08s linear, box-shadow .15s;
}
.pcard.speaking .avatar { box-shadow: 0 0 0 4px var(--surface), 0 0 0 7px var(--success); }
.c0 { background: #2f6fed; } .c1 { background: #0e9384; } .c2 { background: #7a5af8; } .c3 { background: #dd6b20; }
.c4 { background: #c11574; } .c5 { background: #3b7d2d; } .c6 { background: #0b7285; } .c7 { background: #a15c07; }

.mute-badge {
  position: absolute; right: -2px; bottom: -2px; width: 28px; height: 28px; border-radius: 50%; display: none; place-items: center;
  background: var(--danger); color: #fff; border: 3px solid var(--surface);
}
.mute-badge .ic { width: 14px; height: 14px; }
.pcard.muted .mute-badge { display: grid; }

.pname { max-width: 100%; display: flex; align-items: baseline; gap: 6px; font-weight: 600; }
.pname .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pname .me { flex: none; font-size: 12px; font-weight: 600; color: var(--muted); }

.vol { display: flex; align-items: center; gap: 8px; width: 100%; margin: 0; color: var(--muted); font-weight: 400; }
.vol input { flex: 1; min-width: 0; accent-color: var(--primary); }

/* Панель управления */
.controlbar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: 0 8px 32px rgba(16, 24, 40, .18);
}
.round {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  display: grid; place-items: center; cursor: pointer; transition: background .15s;
}
.round:hover { background: var(--line); }
.round .ic { width: 22px; height: 22px; }
.round .off { display: none; }
.round.is-muted { background: var(--danger); border-color: var(--danger); color: #fff; }
.round.is-muted .on { display: none; }
.round.is-muted .off { display: block; }

.toast {
  position: fixed; left: 50%; bottom: 106px; transform: translate(-50%, 12px); opacity: 0; pointer-events: none; z-index: 10;
  padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 14px; font-weight: 600;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 560px) {
  .topbar { padding: 0 16px; }
  .badge { font-size: 12px; padding: 4px 10px; }
  .lobby { padding: 22px 18px; margin-top: 8px; }
  .input-group { flex-wrap: wrap; }
  .input-group > input, .input-group > select { flex: 1 1 100%; }
  .input-group > .btn { flex: 1; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .pcard { padding: 20px 10px 14px; }
  .avatar { width: 68px; height: 68px; font-size: 26px; }
  .controlbar { bottom: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .avatar { transform: none; }
}

/* Режим рации */
#mute { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#mute .lbl { display: none; font-weight: 600; font-size: 15px; white-space: nowrap; }
.controlbar.ptt #mute { width: auto; padding: 0 20px; gap: 10px; border-radius: 999px; }
.controlbar.ptt #mute .lbl { display: inline; }
.controlbar.ptt #mute.talking { background: var(--success); border-color: var(--success); color: #fff; box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 30%, transparent); }
.btn.active { background: color-mix(in srgb, var(--primary) 14%, var(--surface)); border-color: var(--primary); color: var(--primary); }

@media (max-width: 560px) {
  .controlbar .btn span { display: none; }   /* на телефоне у кнопок только иконки */
  .controlbar .btn { padding: 0 12px; }
  .controlbar.ptt { flex-wrap: wrap; justify-content: center; width: calc(100vw - 24px); }
  .controlbar.ptt #mute { flex: 1 1 100%; height: 60px; font-size: 16px; }
  main { padding-bottom: 170px; }
}
.controlbar.ptt #mute { display: flex; align-items: center; justify-content: center; }
@media (max-width: 560px) { .toast { bottom: 180px; } }

/* Вход через Telegram */
.btn.tg { background: #2a9fd8; color: #fff; }
.btn.tg:hover:not(:disabled) { background: #1f86b8; }
.who-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.who-row .who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.who-row .who b, .who-row .who small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-row .who small { color: var(--muted); }
.avatar.sm { width: 36px; height: 36px; font-size: 16px; flex: none; transform: none; }
.vf { display: none; color: var(--primary); }
.verified .vf { display: inline-grid; place-items: center; }
.vf .ic { width: 14px; height: 14px; stroke-width: 3; }
.uname { min-height: 1.2em; margin-top: -8px; font-size: 13px; color: var(--muted); }
.wait { margin: 0 0 10px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font-size: 14px; }
#auth-wait .input-group .btn { flex: 1; text-decoration: none; }
details.alt { margin: 12px 0 0; }
details.alt p { margin: 10px 14px; font-size: 14px; }
details.alt .btn.block { width: auto; height: 42px; margin: 0 14px; display: flex; text-decoration: none; }
details.alt .input-group { margin: 0 14px; }
details.alt .help { margin: 8px 14px 12px; }

/* Список комнат */
.rooms { margin: 0 0 24px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.rooms h2 { margin: 0 0 4px; font-size: 18px; }
.rooms h3 { margin: 16px 0 8px; font-size: 14px; }
.rooms h3 small { display: block; margin-top: 2px; font-weight: 400; color: var(--muted); }
.room-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.room-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.rtext { flex: 1; min-width: 0; }
.rname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rmeta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.ghost-x { background: transparent; color: var(--muted); border: 0; padding: 0 8px; font-size: 22px; line-height: 1; }
.rooms .help { margin: 4px 0 8px; }
.rooms .error { min-height: 0; margin: 6px 0 0; }

/* Форма создания комнаты */
.create { margin: 14px 0 4px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); display: grid; gap: 10px; }
.create h4 { margin: 0; font-size: 14px; }
.create > input { background: var(--surface); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 10px; background: var(--line); }
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; transition: background .15s, color .15s; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, .12); }
.seg .ic { width: 15px; height: 15px; }
.pin-field { position: relative; }
.pin-field input { width: 100%; height: 48px; padding: 0 48px 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; font-size: 20px; letter-spacing: .3em; text-align: center; }
.pin-field input::placeholder { font-size: 15px; letter-spacing: 0; }
.pin-field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.pin-field .eye { position: absolute; right: 4px; top: 4px; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.pin-field .eye:hover { background: var(--surface-2); color: var(--text); }
.pin-field .eye[aria-pressed="true"] { color: var(--primary); }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.rooms .create .block { height: 44px; margin-top: 2px; }
.room-item .pin-in { width: 108px; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; letter-spacing: .25em; text-align: center; }
.room-item .pin-in:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.room-item .pin-ok { height: 36px; padding: 0 14px; }
.rname .lk { display: inline-block; width: 14px; height: 14px; margin-right: 6px; vertical-align: -2px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); }
@media (max-width: 560px) { .room-item { flex-wrap: wrap; } .room-item .pin-in { flex: 1; min-width: 90px; } }
