/* SoundChat — тёмная тема */

:root {
  --bg: #131418;
  --bg-2: #1c1e24;
  --bg-3: #262932;
  --fg: #e8eaf0;
  --fg-dim: #9aa0ae;
  --accent: #5865f2;
  --green: #23a55a;
  --red: #f23f43;
  --yellow: #f0b232;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* атрибут hidden должен побеждать любые display: flex и т.п. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

.screen {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---------- комната: две колонки (голос + чат) ---------- */

#screen-room {
  flex-direction: row;
  align-items: stretch;
}

.room-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- текстовый чат ---------- */

.chat-panel {
  width: 320px;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-left: 1px solid #2b2f39;
}

/* на десктопе панель можно спрятать кнопкой 💬 (на мобильном — шторка, см. ниже) */
.chat-panel.closed { display: none; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.msg-avatar {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
}

.msg-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg-head {
  display: flex;
  gap: 6px;
  align-items: baseline;
  font-size: 12px;
  color: var(--fg-dim);
}

.msg-author { font-weight: 600; color: var(--fg); }

.msg-text {
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.msg.own .msg-text { color: #dfe3ff; }

.msg.compact { margin-top: -4px; }
.msg.compact .msg-avatar { visibility: hidden; height: 0; }
.msg.compact .msg-head { display: none; }

.msg-sys {
  text-align: center;
  font-size: 12px;
  color: var(--fg-dim);
  font-style: italic;
}

.chat-jump {
  align-self: center;
  margin: -8px 0 8px;
  padding: 5px 12px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #2b2f39;
}

.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #3a3f4d;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  outline: none;
}

.chat-form input:focus { border-color: var(--accent); }

.chat-form button {
  padding: 0 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

.chat-toggle {
  position: relative;
  margin-left: 10px;
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
}

/* статус прижимается влево от кнопки чата, сама кнопка — крайняя справа */
#conn-chip { margin-left: auto; }

/* панель смайликов */
.emoji-panel {
  position: absolute;
  right: 10px;
  bottom: 62px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  padding: 8px;
  background: var(--bg-3);
  border: 1px solid #3a3f4d;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  z-index: 30;
}

.emoji-panel button {
  border: none;
  background: none;
  font-size: 20px;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.2;
}

.emoji-panel button:hover { background: var(--bg); }

.emoji-btn {
  flex: none;
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px 0 2px;
}

.chat-panel { position: relative; }

.chat-badge {
  position: absolute;
  top: -6px;
  right: -8px;
  min-width: 17px;
  height: 17px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ---------- экран входа ---------- */

#screen-join {
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.join-card {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: min(360px, 100%);
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

.logo { font-size: 48px; }

.join-card h1 {
  margin: 8px 0 2px;
  font-size: 26px;
  letter-spacing: 0.5px;
}

.tagline {
  margin: 0 0 22px;
  color: var(--fg-dim);
  font-size: 14px;
}

#join-form { display: flex; flex-direction: column; gap: 10px; }

#join-form label {
  text-align: left;
  font-size: 13px;
  color: var(--fg-dim);
}

#name-input {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid #3a3f4d;
  background: var(--bg);
  color: var(--fg);
  font-size: 16px;
  outline: none;
}

#name-input:focus { border-color: var(--accent); }

#join-btn {
  padding: 12px;
  margin-top: 4px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

#join-btn:hover { filter: brightness(1.1); }
#join-btn:disabled { opacity: 0.6; cursor: wait; }

/* выбор аватарки */
.avatar-picker {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.avatar-opt {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid transparent;
  background: var(--bg);
  font-size: 26px;
  cursor: pointer;
  transition: transform 100ms, border-color 100ms;
  padding: 0;
  line-height: 1;
}

.avatar-opt:hover { transform: scale(1.12); }

.avatar-opt.selected {
  border-color: var(--accent);
  background: var(--bg-3);
  transform: scale(1.12);
}

.error { color: var(--red); font-size: 13px; margin: 4px 0 0; }

/* ---------- проверка микрофона ---------- */

.mic-test {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}

.secondary-btn {
  padding: 9px 12px;
  border: 1px solid #3a3f4d;
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 13.5px;
  cursor: pointer;
}

.secondary-btn:hover { border-color: var(--accent); }

.mic-test-status {
  margin: 0;
  font-size: 12.5px;
  color: var(--fg-dim);
  text-align: left;
}

.mic-test-status.warn { color: var(--yellow); }

/* окно проверки звука */
.voice-test {
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.voice-test h2 {
  margin: 0 0 2px;
  font-size: 18px;
  text-align: center;
}

.vt-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--fg-dim);
}

.vt-field select {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid #3a3f4d;
  border-radius: 6px;
  padding: 8px 9px;
  font-size: 13.5px;
}

.vt-buttons {
  display: flex;
  gap: 10px;
}

.vt-buttons button {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-radius: 8px;
  font-size: 13.5px;
  cursor: pointer;
}

.vt-buttons button:disabled { opacity: 0.5; cursor: default; }

#vt-start-btn {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

#vt-start-btn.running { background: var(--red); }

#vt-loop-btn {
  background: var(--bg-3);
  color: var(--fg);
}

.vt-note {
  margin: 0;
  font-size: 12px;
  color: var(--fg-dim);
  text-align: center;
}

/* окно выбора клавиши PTT */
.ptt-capture {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.ptt-capture h2 { margin: 0; font-size: 18px; }

.ptt-capture-hint {
  margin: 0;
  font-size: 13px;
  color: var(--fg-dim);
}

.ptt-capture-key {
  padding: 18px 10px;
  border-radius: 10px;
  background: var(--bg);
  border: 2px dashed #3a3f4d;
  font-size: 20px;
  font-weight: 600;
  color: var(--fg);
}

.ptt-capture-key.captured {
  border-color: var(--green);
  border-style: solid;
  color: var(--green);
}

/* индикатор уровня (полоска) */
.meter {
  height: 8px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid #333845;
  overflow: hidden;
}

.meter i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green) 0%, var(--green) 60%, var(--yellow) 80%, var(--red) 100%);
  transition: width 90ms linear;
}

.hint {
  margin: 18px 0 0;
  font-size: 12.5px;
  color: var(--fg-dim);
}

/* ---------- комната ---------- */

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-2);
}

.brand { font-weight: 600; }

.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--fg-dim);
}

.chip-ok { color: var(--green); }
.chip-warn { color: var(--yellow); }
.chip-bad { color: var(--red); }
.chip-ptt { color: var(--accent); }

.tiles {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  overflow-y: auto;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 140px;
  user-select: none;
}

.avatar {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--bg-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 600;
  color: #fff;
  border: 3px solid transparent;
  transition: border-color 120ms;
}

/* зелёное кольцо «говорит» */
.tile.speaking .avatar { border-color: var(--green); }

/* большой аватар на своей плитке — отдельный элемент, поверх ничего не затирает */
.avatar-glyph {
  font-size: inherit;
  line-height: 1;
}

/* кнопка своего микрофона на своей плитке (симметрично динамику у собеседников) */
.self-mute-btn {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 2px solid var(--bg-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
  transition: transform 100ms, background 100ms;
}

.self-mute-btn:hover { transform: scale(1.15); }

.self-mute-btn.muted { background: var(--red); }

/* кнопка «выключить звук собеседника» на его плитке */
.peer-mute-btn {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 2px solid var(--bg-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
  transition: transform 100ms, background 100ms;
}

.peer-mute-btn:hover { transform: scale(1.15); }

.peer-mute-btn.muted {
  background: var(--red);
}

.tile .meter { width: 100%; margin-top: 2px; }

.tile .name {
  font-size: 14px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile .status {
  font-size: 11.5px;
  color: var(--fg-dim);
  display: flex;
  align-items: center;
  gap: 5px;
}

.tile .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--yellow);
}

.tile .dot.ok { background: var(--green); }
.tile .dot.bad { background: var(--red); }

.tile .muted-mark { font-size: 13px; }

/* ---------- панель управления ---------- */

.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 12px 16px 6px;
  background: var(--bg-2);
}

.ctl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 86px;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: var(--bg-3);
  color: var(--fg);
  font-size: 12px;
  cursor: pointer;
}

.ctl:hover { filter: brightness(1.15); }

.ctl-ico { font-size: 21px; }

.ctl-danger { color: var(--red); }

.ctl.active {
  background: var(--red);
  color: #fff;
}

.settings {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 8px 16px 12px;
  background: var(--bg-2);
  font-size: 12.5px;
  color: var(--fg-dim);
}

.settings label {
  display: flex;
  align-items: center;
  gap: 7px;
}

.settings select {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid #3a3f4d;
  border-radius: 6px;
  padding: 5px 7px;
  font-size: 12.5px;
  max-width: 200px;
}

.ptt-label { cursor: pointer; }
.settings input[type="checkbox"] { accent-color: var(--accent); }

/* ---------- оверлеи ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.overlay-card {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 26px 30px;
  text-align: center;
  max-width: 420px;
}

#unblock-btn {
  margin-top: 14px;
  padding: 10px 22px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- лобби ---------- */

.lobby-main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.lobby-grid {
  max-width: 780px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

#lobby-rooms-card,
.lobby-error {
  grid-column: 1 / -1;
}

.lobby-error { margin: 0; }

.lobby-card {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.lobby-card h2 {
  margin: 0 0 12px;
  font-size: 15.5px;
}

.lobby-empty {
  margin: 0;
  color: var(--fg-dim);
  font-size: 13.5px;
  font-style: italic;
}

/* строка комнаты в списке/истории */
.room-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid #3a3f4d;
  background: var(--bg);
  border-radius: 8px;
  cursor: pointer;
  color: var(--fg);
  font-size: 14px;
}

.room-row + .room-row { margin-top: 8px; }

.room-row:hover { border-color: var(--accent); }

.room-row .room-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.room-row .room-count {
  flex: none;
  color: var(--fg-dim);
  font-size: 12.5px;
}

.room-row .room-count.empty { font-style: italic; }

#history-clear-btn {
  margin-top: 10px;
  width: 100%;
}

/* форма создания */
#create-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

#create-form label {
  font-size: 13px;
  color: var(--fg-dim);
}

#create-password-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.line-input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #3a3f4d;
  background: var(--bg);
  color: var(--fg);
  font-size: 14.5px;
  outline: none;
  width: 100%;
}

.line-input:focus { border-color: var(--accent); }

.mode-row { display: flex; gap: 8px; }

.mode-btn {
  flex: 1;
  padding: 10px 8px;
  border: 2px solid #3a3f4d;
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg-dim);
  font-size: 13.5px;
  cursor: pointer;
}

.mode-btn.selected {
  border-color: var(--accent);
  color: var(--fg);
  background: var(--bg-3);
}

.remember-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--fg-dim);
  cursor: pointer;
}

.remember-label input { accent-color: var(--accent); }

#create-btn {
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

#create-btn:hover { filter: brightness(1.1); }
#create-btn:disabled { opacity: 0.6; cursor: wait; }

/* шапка лобби и комнаты */
.lobby-header { gap: 8px; row-gap: 6px; flex-wrap: wrap; }

#lobby-user { margin-left: 2px; }

#lobby-voice-test-btn { margin-left: auto; }

.to-rooms-btn {
  border: none;
  background: none;
  color: var(--fg-dim);
  font-size: 13.5px;
  cursor: pointer;
  padding: 5px 9px;
  border-radius: 8px;
}

.to-rooms-btn:hover { background: var(--bg-3); color: var(--fg); }

.room-name-chip {
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* окно пароля комнаты */
.room-pass {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.room-pass h2 {
  margin: 0;
  font-size: 18px;
  text-align: center;
}

.room-pass-name {
  margin: -6px 0 0;
  text-align: center;
  color: var(--fg-dim);
  font-size: 14px;
}

#room-pass-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.vt-primary {
  background: var(--accent) !important;
  color: #fff !important;
  font-weight: 600;
}

/* ---------- мобильная версия ---------- */

@media (max-width: 760px) {
  /* чат — выдвижная шторка справа */
  .chat-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(85vw, 320px);
    z-index: 50;
    transform: translateX(105%);
    transition: transform 200ms ease;
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.5);
  }

  .chat-panel.mobile-open { transform: none; }
  .chat-panel.closed { display: flex; } /* управляется transform, не display */

  .tiles { gap: 12px; padding: 14px; }
  .tile { width: 104px; }
  .avatar { width: 66px; height: 66px; font-size: 27px; }
  .ctl { min-width: 72px; }

  /* лобби — колонкой */
  .lobby-grid { grid-template-columns: 1fr; }
  .room-header { flex-wrap: wrap; row-gap: 6px; }
  .room-name-chip { max-width: 60vw; }
}
