:root {
  --bg: #202124;
  --panel: #3c4043;
  --fg: #e8eaed;
  --muted: #9aa0a6;
  --accent: #8ab4f8;
  --danger: #ea4335;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, sans-serif;
}
h1, h2 { margin: 0; font-weight: 500; }
.muted { color: var(--muted); margin: 0; }
button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  background: var(--panel);
  color: var(--fg);
}
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: #202124; font-weight: 600; }
input {
  font: inherit;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid #5f6368;
  background: transparent;
  color: var(--fg);
  min-width: 0;
}

/* Главная */
body.home { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.home-card { width: 100%; max-width: 420px; display: grid; gap: 16px; }
.home-card form { display: flex; gap: 8px; }
.home-card input { flex: 1; }

/* Лобби */
#lobby { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.lobby-card { width: min(640px, 100%); display: grid; gap: 14px; }
#preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #000;
  border-radius: 12px;
  transform: scaleX(-1);
}
#roomCode { color: var(--muted); }

/* Звонок */
#call { position: fixed; inset: 0; display: flex; flex-direction: column; }
#grid {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 8px;
  padding: 8px;
  grid-template-columns: repeat(var(--cols, 1), 1fr);
  grid-auto-rows: 1fr;
}
.tile {
  position: relative;
  min-height: 0;
  background: var(--panel);
  border-radius: 12px;
  overflow: hidden;
}
.tile video { width: 100%; height: 100%; object-fit: cover; background: #000; display: block; }
.tile.self video { transform: scaleX(-1); }
.tile.self.rear video { transform: none; }
.tile .avatar { position: absolute; inset: 0; display: none; place-items: center; background: var(--panel); }
.tile.cam-off .avatar { display: grid; }
.avatar span {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: #5f6368;
  display: grid; place-items: center;
  font-size: 30px;
}
.tile .label {
  position: absolute;
  left: 8px; bottom: 8px;
  max-width: calc(100% - 16px);
  padding: 2px 8px;
  border-radius: 6px;
  background: #000a;
  font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile .status {
  position: absolute;
  top: 8px; left: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  background: #000a;
  font-size: 12px;
  color: var(--muted);
  display: none;
}
.tile.connecting .status { display: block; }

/* Двое: собеседник на весь экран, себя — в углу */
#grid.duo { display: block; position: relative; }
#grid.duo .tile { position: absolute; inset: 8px; }
#grid.duo .tile.self {
  inset: auto 16px 16px auto;
  width: 30%;
  max-width: 240px;
  aspect-ratio: 3 / 4;
  z-index: 2;
  box-shadow: 0 4px 16px #0009;
}
@media (orientation: landscape) {
  #grid.duo .tile.self { aspect-ratio: 16 / 9; }
}

#controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
}
#controls button { width: 52px; height: 52px; padding: 0; font-size: 20px; display: grid; place-items: center; }
#controls button.off { background: var(--danger); }
#controls #leaveBtn { background: var(--danger); width: 64px; }

#toast {
  position: fixed;
  left: 50%; bottom: 96px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 8px;
  background: #e8eaed;
  color: #202124;
  z-index: 10;
}

#unmute {
  position: fixed;
  left: 50%; top: 16px;
  transform: translateX(-50%);
  z-index: 5;
  white-space: nowrap;
}

.row { display: flex; gap: 8px; }
.grow { flex: 1; }
.small { font-size: 13px; }
button.icon { width: 36px; height: 36px; padding: 0; background: transparent; font-size: 18px; }
h3 { margin: 0; font-size: 18px; font-weight: 500; }

/* Сетка + панель участников рядом */
#main { flex: 1; min-height: 0; display: flex; }
#main #grid { flex: 1; min-width: 0; }

#people {
  width: 320px;
  margin: 8px 8px 0 0;
  padding: 16px;
  border-radius: 12px;
  background: #2d2e31;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
}
#people header, #settings header { display: flex; align-items: center; justify-content: space-between; }
#peopleList { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
#peopleList li { display: flex; align-items: center; gap: 12px; padding: 6px 4px; }
#peopleList .ava {
  flex: none;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: #5f6368;
  display: grid; place-items: center;
}
#peopleList .who { flex: 1; min-width: 0; }
#peopleList .who div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#peopleList .sub { font-size: 12px; color: var(--muted); }
#peopleList .icons { flex: none; display: flex; gap: 6px; font-size: 15px; }

/* На телефоне панель — поверх видео */
@media (max-width: 700px) {
  #people { position: fixed; inset: 0 0 auto 0; bottom: calc(76px + env(safe-area-inset-bottom)); width: auto; margin: 8px; z-index: 4; }
}

#peopleBtn { position: relative; }
.badge {
  position: absolute;
  top: -2px; right: -2px;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--accent);
  color: #202124;
  font-size: 12px; font-weight: 700;
  line-height: 20px;
}
#controls button.active { background: #8ab4f833; outline: 1px solid var(--accent); }
@media (max-width: 420px) {
  #controls { gap: 8px; }
  #controls button { width: 46px; height: 46px; font-size: 18px; }
  #controls #leaveBtn { width: 56px; }
}

/* Настройки устройств */
#settings {
  width: min(440px, calc(100% - 32px));
  padding: 20px;
  border: 0;
  border-radius: 16px;
  background: #2d2e31;
  color: var(--fg);
}
#settings::backdrop { background: #000a; }
#settings form { display: grid; gap: 14px; }
#settings label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
select {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #5f6368;
  background: #202124;
  color: var(--fg);
}
.meter { height: 6px; margin-top: -6px; border-radius: 3px; background: #5f6368; overflow: hidden; }
#micLevel { height: 100%; width: 0; background: #34a853; transition: width .08s linear; }
