:root {
  --bg0: #0b0c10;
  --bg1: #12141c;
  --card: rgba(22, 24, 35, 0.85);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8e9ef;
  --muted: #8b8fa3;
  --accent: #6ee7b7;
  --accent2: #38bdf8;
  --danger: #f87171;
  --radius: 16px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg0);
}

body {
  position: relative;
  overflow-x: hidden;
}

.bg {
  position: fixed;
  inset: 0;
  background: radial-gradient(900px 500px at 20% 10%, rgba(56, 189, 248, 0.12), transparent 60%),
    radial-gradient(800px 400px at 80% 30%, rgba(110, 231, 183, 0.1), transparent 55%),
    linear-gradient(180deg, #0a0b0f, #0b0c10);
  z-index: 0;
  pointer-events: none;
}

.shell {
  position: relative;
  z-index: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
  min-width: 0;
}

.header {
  margin-bottom: 1.75rem;
}

.title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.4rem;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  min-width: 0;
  max-width: 100%;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.field span {
  font-size: 0.9rem;
  color: var(--muted);
}

input[type="text"] {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

input[type="text"]:focus {
  outline: none;
  border-color: rgba(56, 189, 248, 0.45);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  padding: 0.7rem 1.2rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s, opacity 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent2), #22d3ee);
  color: #0b0c10;
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn.danger {
  background: rgba(248, 113, 113, 0.2);
  color: #fecaca;
  border: 1px solid rgba(248, 113, 113, 0.35);
}

.btn.danger:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.3);
}

.btn.icon {
  width: 48px;
  height: 48px;
  padding: 0;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 1.2rem;
}

.btn.icon[aria-pressed="false"] {
  opacity: 0.5;
  background: rgba(248, 113, 113, 0.15);
}

/* Звук с ПК: вкл — подсветка как у старой text-кнопки; выкл — общий стиль «выкл» выше */
#btnSysAudio[aria-pressed="true"] {
  opacity: 1;
  background: rgba(56, 189, 248, 0.2);
  border-color: rgba(56, 189, 248, 0.45);
  color: #e0f2fe;
}

#btnSysAudio {
  position: relative;
}

#btnSysAudio .icon-sys-audio {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: block;
  pointer-events: none;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 1rem 0 0;
  line-height: 1.5;
}

.hint[role="status"]:not([hidden]) {
  color: var(--danger);
  margin-top: 0.75rem;
}

.lobby-step {
  min-width: 0;
}

.lobby-lead {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--text);
}

.lobby-preview-wrap {
  width: 100%;
  max-width: 520px;
  margin: 0 auto 0.5rem;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
  aspect-ratio: 16 / 10;
  min-height: 120px;
}

.lobby-preview-video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  vertical-align: top;
}

.lobby-actions {
  justify-content: center;
  margin-top: 0.5rem;
}

#lobby .hint#lobbyError {
  margin-top: 1rem;
  margin-bottom: 0;
}

/* Call */
.call {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.call-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
}

.call-bar-left {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  min-width: 0;
}

.btn.link-share {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  min-width: 2.2rem;
  padding: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--accent2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.btn.link-share:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.35);
  color: #7dd3fc;
}

.btn.link-share.copied {
  color: var(--accent);
  border-color: rgba(110, 231, 183, 0.45);
  background: rgba(110, 231, 183, 0.12);
  box-shadow: 0 0 0 2px rgba(110, 231, 183, 0.15);
}

.btn.link-share .link-share-icon {
  display: block;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(110, 231, 183, 0.12);
  color: var(--accent);
  border: 1px solid rgba(110, 231, 183, 0.3);
  max-width: 100%;
  word-break: break-all;
}

.status {
  font-size: 0.9rem;
  color: var(--muted);
}

.call-legend {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  line-height: 1.45;
}

.layout-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.6rem;
  margin-bottom: 0.5rem;
}

.layout-toolbar-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.layout-toolbar-sep {
  width: 1px;
  height: 1.1rem;
  background: var(--border);
  margin: 0 0.1rem;
}

.video-stage:fullscreen {
  background: #07080c;
  padding: 0.75rem 1rem 1.25rem;
  box-sizing: border-box;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 100%;
}

.video-stage:fullscreen .video-grid {
  flex: 1;
  min-height: 0;
}

/* Не даём сетке и видео вылезать из карточки (.shell / .card) */
.video-stage {
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

.video-grid {
  display: grid;
  /* auto-fit, не auto-fill: пустые колонки схлопываются — одна/несколько плиток не прилипают влево */
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  align-items: start;
  justify-content: center;
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

/* Фокус: крупно сверху, остальные в ряд снизу */
.video-grid.layout-focus {
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  grid-template-rows: auto auto;
  gap: 0.5rem;
  align-items: stretch;
  justify-content: center;
}

.video-grid.layout-focus .video-wrap.spotlight {
  grid-column: 1 / -1;
  grid-row: 1;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  /* ширина от контейнера, высота от 16:9 — иначе при большой min-height ряда плитка раздувается вширь */
  aspect-ratio: 16 / 9;
  height: auto;
  min-height: 0;
  max-height: min(68vh, 85vw);
  border-color: rgba(56, 189, 248, 0.5);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.15);
}

.video-grid.layout-focus .video-wrap.thumb {
  grid-row: 2;
  min-width: 0;
  min-height: 88px;
  max-height: 200px;
  max-width: 100%;
  aspect-ratio: 16 / 10;
}

.call .video-wrap {
  cursor: pointer;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.call .video-wrap:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.remotes {
  display: contents;
}

@media (max-width: 640px) {
  .video-grid {
    grid-template-columns: 1fr;
  }
}

.video-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--border);
  min-width: 0;
  max-width: 100%;
}

.video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Свой кадр — зеркально (как в зеркале). Что уходит собеседникам, не трогаем. */
.video-wrap.self video {
  transform: scaleX(-1);
}

.video-wrap .label {
  position: absolute;
  left: 0.5rem;
  bottom: 0.5rem;
  max-width: calc(100% - 1rem);
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 6px;
  color: #fff;
}

.label.label-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
}

.label-name {
  line-height: 1.2;
}

.q-meter {
  font-size: 0.65rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.01em;
  white-space: normal;
  word-break: break-word;
}

.q-meter.q-ok {
  color: #6ee7b7;
}
.q-meter.q-mid {
  color: #fcd34d;
}
.q-meter.q-bad {
  color: #fca5a5;
}
.q-meter.q-wait {
  color: #94a3b8;
  font-weight: 500;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding-top: 0.5rem;
}

.btn.text-btn {
  padding: 0.55rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.text-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

.btn.text-btn[aria-pressed="true"] {
  background: rgba(56, 189, 248, 0.2);
  border-color: rgba(56, 189, 248, 0.45);
  color: #e0f2fe;
}

.toolbar-hint {
  margin: 0 0 0.5rem;
  text-align: center;
}

video.keepalive {
  position: fixed;
  left: 0;
  top: 0;
  width: 2px;
  height: 2px;
  opacity: 0;
  pointer-events: none;
}
