:root {
  --bg: #0e1014;
  --bg-soft: #161a21;
  --card: #1a1f27;
  --line: #272e39;
  --text: #eef1f6;
  --muted: #98a2b3;
  --accent: #7c5cff;
  --accent-2: #22d3a5;
  --danger: #ef4b5c;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #1e2440 0%, var(--bg) 55%) no-repeat, var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(14, 16, 20, 0.7);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 12px var(--accent-2);
}

.net-status {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.net-status[data-state="online"] { color: var(--accent-2); border-color: rgba(34, 211, 165, 0.4); }
.net-status[data-state="offline"] { color: var(--danger); border-color: rgba(239, 75, 92, 0.4); }

/* ---------- правая часть шапки: версия, статус, кнопка выключения ---------- */

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.build-tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  line-height: 1.4;
}

button.mini {
  width: 30px;
  height: 30px;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  border-radius: 999px;
  color: var(--muted);
  border-color: var(--line);
  background: transparent;
}

button.mini:hover {
  color: var(--danger);
  border-color: rgba(239, 75, 92, 0.55);
  background: rgba(239, 75, 92, 0.08);
}

@media (max-width: 520px) {
  .build-tag { display: none; }
}

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

/*
 * Места в сетке закреплены за карточками по имени (grid-template-areas).
 * Даже если между карточками случайно окажется лишний текст или элемент,
 * он не сдвинет их: карточки всегда стоят рядом.
 */
#view-home .grid {
  grid-template-areas: "create join";
}

#card-create { grid-area: create; }
#card-join   { grid-area: join; }

/* посторонние элементы внутри сетки не показываем */
.grid > *:not(.card) { display: none !important; }

@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  #view-home .grid { grid-template-areas: "create" "join"; }
}

.card {
  min-width: 0;
  background: linear-gradient(180deg, var(--card), var(--bg-soft));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}

.card.narrow { max-width: 460px; margin: 0 auto; }

h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0 0 6px; }

.hint, .meta {
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.5;
  margin: 0 0 16px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

input, select {
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  background: #0f1319;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

input:focus, select:focus { border-color: var(--accent); }

.row {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 12px;
}

button {
  font-family: inherit;
  font-size: 14.5px;
  padding: 11px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.06s ease, filter 0.15s ease, background 0.15s ease;
}

button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.primary {
  background: linear-gradient(135deg, var(--accent), #5b3df0);
  color: white;
  font-weight: 600;
  width: 100%;
  margin-top: 4px;
}

.secondary {
  background: #232a35;
  color: var(--text);
  border-color: var(--line);
}

.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(239, 75, 92, 0.45);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.actions button { width: auto; }

.room-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.peer-list {
  list-style: none;
  padding: 0;
  margin: 20px 0 0;
  display: grid;
  gap: 8px;
}

.peer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #131820;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.peer .avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: #2a3140;
  flex: 0 0 auto;
}

.peer .who { flex: 1; min-width: 0; }
.peer .who b { display: block; font-size: 14.5px; }
.peer .who span { font-size: 12.5px; color: var(--muted); }

.badge {
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.badge.host { color: var(--accent-2); border-color: rgba(34, 211, 165, 0.35); }
.badge.muted { color: var(--danger); border-color: rgba(239, 75, 92, 0.35); }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.controls .primary {
  width: auto;
  margin: 0;
}

.device-label {
  margin: 0;
  flex: 1;
  min-width: 180px;
}

.status { font-size: 13px; color: var(--muted); }

.invite-out {
  margin-top: 14px;
  padding: 12px;
  background: #0f1319;
  border: 1px dashed var(--line);
  border-radius: 10px;
  font-size: 13px;
  color: var(--accent-2);
  word-break: break-all;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #232a35;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  max-width: min(92vw, 480px);
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  z-index: 50;
}

.toast[data-kind="error"] { border-color: rgba(239, 75, 92, 0.5); }

/* ------------------------ индикатор речи ------------------------ */

.peer {
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

/* полоска громкости под именем */
.peer .meter {
  height: 3px;
  margin-top: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.peer .meter i {
  display: block;
  height: 100%;
  width: var(--level-pct, 0%);
  border-radius: 999px;
  background: linear-gradient(90deg, #22d3a5, #8df5d3);
  transition: width 0.09s linear;
}

/* человек говорит: подсветка строки, аватара и текста */
.peer.speaking {
  border-color: rgba(34, 211, 165, 0.55);
  background: linear-gradient(90deg, rgba(34, 211, 165, 0.13), #131820 68%);
  box-shadow: 0 0 0 1px rgba(34, 211, 165, 0.22), 0 0 20px rgba(34, 211, 165, 0.10);
}

.peer.speaking .avatar {
  background: linear-gradient(135deg, #22d3a5, #17a673);
  color: #052016;
  transform: scale(calc(1 + var(--level, 0) * 0.08));
  animation: speak-pulse 1.15s ease-in-out infinite;
}

.peer.speaking .who b { color: #dcfff4; }
.peer.speaking .who span { color: var(--accent-2); }

@keyframes speak-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(34, 211, 165, 0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(34, 211, 165, 0.10), 0 0 18px rgba(34, 211, 165, 0.40); }
}

/* у кого микрофон выключен — приглушаем */
.peer.silent-peer .avatar { opacity: 0.55; }

/* ---------- кнопка шумоподавления ---------- */

#denoise {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  margin: 0;
  border-color: var(--line);
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

#denoise .ico { font-size: 15px; line-height: 1; }

#denoise[data-state="on"] {
  background: rgba(34, 211, 165, 0.14);
  border-color: rgba(34, 211, 165, 0.55);
  color: #a9ffe4;
  box-shadow: 0 0 0 1px rgba(34, 211, 165, 0.15);
}

#denoise[data-state="on"] .ico { filter: none; }

#denoise[data-state="off"] {
  background: #1a1f27;
  border-color: var(--line);
  color: var(--muted);
}

#denoise[data-state="off"] .ico { filter: grayscale(1) opacity(0.65); }


/* ---------------------------- доступ по сети ---------------------------- */

.net-card {
  margin-top: 20px;
}

.net-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.net-head h2 { margin: 0; }

.net-body {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  margin-top: 4px;
}

.qr-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 168px;
  height: 168px;
  padding: 8px;
  background: #fff;
  border-radius: 14px;
  box-sizing: border-box;
}

#net-qr {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  border-radius: 6px;
}

.qr-stub {
  font-size: 12px;
  color: #6b7280;
  text-align: center;
  line-height: 1.35;
}

.net-rows {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.net-row {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.net-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.net-value {
  font-size: 14px;
  color: var(--text);
  overflow-wrap: anywhere;
  min-width: 0;
}

.net-value.mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}

.net-value.ok { color: #6ee7b7; }
.net-value.warn { color: #fbbf24; }
.net-value.bad { color: #f87171; }

.net-hint {
  margin-top: 14px;
  margin-bottom: 0;
}

.copy-btn {
  white-space: nowrap;
  width: auto;
  margin: 0;
}

@media (max-width: 720px) {
  .net-body {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
  }
  .net-rows { width: 100%; }
  .net-row { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .net-label { margin-bottom: 2px; }
}


/* ------------------------- громкость участника -------------------------- */

.peer .vol {
  -webkit-appearance: none;
  appearance: none;
  width: 96px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  outline: none;
  margin: 0 4px 0 10px;
  cursor: pointer;
  flex: none;
}

.peer .vol::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--card);
  cursor: pointer;
}

.peer .vol::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--card);
  cursor: pointer;
}

.peer .silence {
  width: auto;
  margin: 0;
  padding: 5px 9px;
  font-size: 12px;
  border-color: var(--line);
  background: var(--bg-soft);
  color: var(--muted);
}

.peer .silence[aria-pressed="true"] {
  background: rgba(239, 75, 92, 0.16);
  border-color: rgba(239, 75, 92, 0.5);
  color: #ffb3bb;
}

.peer.silenced { opacity: 0.55; }

/* --------------------------- тест микрофона ----------------------------- */

.mic-test {
  margin: 14px 0 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-soft);
}

.mic-test-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 13px;
  margin-bottom: 9px;
}

.mic-test-hint {
  font-size: 12px;
  color: var(--muted);
}

.mic-test-bar {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
}

.mic-test-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.08s linear;
}

.mic-test-bar.loud i {
  background: linear-gradient(90deg, #fbbf24, var(--danger));
}

/* ------------------------- светлая тема --------------------------------- */

body[data-theme="light"] {
  --bg: #f3f5fa;
  --bg-soft: #eef1f7;
  --card: #ffffff;
  --line: #dbe1ec;
  --text: #161b24;
  --muted: #5b6577;
  --accent: #5b46e8;
  --accent-2: #0d9c78;
  --danger: #d63045;
  background: radial-gradient(1200px 600px at 20% -10%, #e2e9ff 0%, var(--bg) 55%) no-repeat, var(--bg);
}

body[data-theme="light"] .topbar {
  background: rgba(255, 255, 255, 0.82);
}

body[data-theme="light"] input,
body[data-theme="light"] select,
body[data-theme="light"] textarea {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line);
}

body[data-theme="light"] #denoise[data-state="off"] {
  background: #f0f2f7;
  color: var(--muted);
}

body[data-theme="light"] .badge.host {
  background: rgba(91, 70, 232, 0.12);
  color: #4a37c9;
}

body[data-theme="light"] .net-card .qr-box {
  border: 1px solid var(--line);
}

body[data-theme="light"] .peer .silence[aria-pressed="true"] {
  color: #b3223a;
}

body[data-theme="light"] .mic-test-bar i {
  background: linear-gradient(90deg, #0d9c78, #5b46e8);
}
