/* ==========================================================================
   Связь — стили интерфейса
   ========================================================================== */

:root {
  --bg: #0a0f1e;
  --bg-2: #101a33;
  --panel: rgba(20, 30, 55, 0.72);
  --panel-solid: #141e37;
  --border: rgba(140, 170, 255, 0.16);
  --text: #eaf0ff;
  --muted: #9aa8c7;
  --accent: #4c8dff;
  --accent-2: #32d6a0;
  --danger: #ff4d5e;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 15% -10%, rgba(76, 141, 255, 0.22), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(50, 214, 160, 0.14), transparent 55%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.hidden { display: none !important; }

.screen { min-height: 100dvh; }

/* ---------------------------------------------------------------- иконки */
[data-icon] {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  background-color: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
[data-icon="mic"] {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='2' width='6' height='12' rx='3'/%3E%3Cpath d='M5 11a7 7 0 0 0 14 0'/%3E%3Cpath d='M12 18v4'/%3E%3C/svg%3E");
}
[data-icon="mic-off"] {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='2' width='6' height='12' rx='3'/%3E%3Cpath d='M5 11a7 7 0 0 0 14 0'/%3E%3Cpath d='M12 18v4'/%3E%3Cpath d='M3 3l18 18'/%3E%3C/svg%3E");
}
[data-icon="cam"] {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='6' width='14' height='12' rx='2'/%3E%3Cpath d='M16 10.5l6-3.5v10l-6-3.5'/%3E%3C/svg%3E");
}
[data-icon="cam-off"] {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='6' width='14' height='12' rx='2'/%3E%3Cpath d='M16 10.5l6-3.5v10l-6-3.5'/%3E%3Cpath d='M3 3l18 18'/%3E%3C/svg%3E");
}
[data-icon="screen"] {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='4' width='20' height='13' rx='2'/%3E%3Cpath d='M8 21h8'/%3E%3Cpath d='M12 17v4'/%3E%3C/svg%3E");
}
[data-icon="hangup"] {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 5.5C4 4.7 4.7 4 5.5 4h2c.7 0 1.3.5 1.5 1.2l.7 2.8c.1.6-.1 1.2-.6 1.5l-1.2.8a12 12 0 0 0 5.8 5.8l.8-1.2c.4-.5 1-.7 1.5-.6l2.8.7c.7.2 1.2.8 1.2 1.5v2c0 .8-.7 1.5-1.5 1.5A16.5 16.5 0 0 1 4 5.5Z'/%3E%3Cpath d='M2 2l20 20'/%3E%3C/svg%3E");
}
[data-icon="link"] {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.5.5l2-2a5 5 0 0 0-7-7l-1 1'/%3E%3Cpath d='M14 11a5 5 0 0 0-7.5-.5l-2 2a5 5 0 0 0 7 7l1-1'/%3E%3C/svg%3E");
}
[data-icon="chat"] {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 11.5a8.5 8.5 0 0 1-12.3 7.7L3 21l1.8-5.7A8.5 8.5 0 1 1 21 11.5Z'/%3E%3C/svg%3E");
}
[data-icon="lock"] {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='10' width='16' height='11' rx='2'/%3E%3Cpath d='M8 10V7a4 4 0 0 1 8 0v3'/%3E%3C/svg%3E");
}
[data-icon="download"] {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3v12'/%3E%3Cpath d='M7 11l5 5 5-5'/%3E%3Cpath d='M4 21h16'/%3E%3C/svg%3E");
}
[data-icon="settings"] {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6h16'/%3E%3Cpath d='M4 12h16'/%3E%3Cpath d='M4 18h16'/%3E%3Ccircle cx='9' cy='6' r='2'/%3E%3Ccircle cx='15' cy='12' r='2'/%3E%3Ccircle cx='8' cy='18' r='2'/%3E%3C/svg%3E");
}

/* ---------------------------------------------------------- общие кнопки */
.btn {
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn.primary {
  background: linear-gradient(135deg, #4c8dff, #3f6ff0);
  border-color: transparent;
  box-shadow: 0 10px 26px rgba(76, 141, 255, 0.32);
}
.btn.primary:hover { filter: brightness(1.07); }

.btn.ghost { background: rgba(255, 255, 255, 0.05); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.big { width: 100%; padding: 15px; font-size: 16px; border-radius: 14px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

/* ------------------------------------------------------------ экран входа */
.join-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.join-card {
  width: min(440px, 100%);
  /* margin:auto вместо центрирования гридом: на низких экранах карточка
     не обрезается сверху, а просто прокручивается. */
  margin: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 26px 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  animation: rise 0.35s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.brand-mark {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 15px;
  overflow: hidden;
  color: #fff;
  background: linear-gradient(135deg, #4c8dff, #32d6a0);
  box-shadow: 0 8px 22px rgba(76, 141, 255, 0.35);
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-mark svg { width: 26px; height: 26px; }
.brand h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
.brand p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.join-fields { display: grid; gap: 14px; margin-bottom: 18px; }

.field { display: grid; gap: 7px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.field input {
  font: inherit;
  font-size: 15.5px;
  color: var(--text);
  background: rgba(8, 13, 27, 0.65);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}
.field input::placeholder { color: #64719a; }
.field input:focus {
  outline: none;
  border-color: rgba(76, 141, 255, 0.75);
  box-shadow: 0 0 0 3px rgba(76, 141, 255, 0.16);
}

.pre-toggles { display: flex; gap: 10px; margin-bottom: 18px; }

.pill {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 15px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  flex: 1;
  justify-content: center;
  transition: all 0.15s ease;
}
.pill[aria-pressed="true"] {
  color: var(--text);
  background: rgba(76, 141, 255, 0.14);
  border-color: rgba(76, 141, 255, 0.5);
}
.pill[aria-pressed="false"] { color: #8593b5; }

.error {
  margin: 14px 0 0;
  font-size: 13.5px;
  line-height: 1.45;
  color: #ffb3ba;
  background: rgba(255, 77, 94, 0.12);
  border: 1px solid rgba(255, 77, 94, 0.34);
  border-radius: 11px;
  padding: 10px 12px;
}

.hint { margin: 16px 0 0; font-size: 12.5px; line-height: 1.5; color: #7d8bad; text-align: center; }

/* Установка на домашний экран */
.install-box { margin-top: 16px; display: grid; gap: 10px; }
.ios-share {
  display: inline-block;
  min-width: 18px;
  padding: 0 4px;
  margin: 0 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 12px;
  line-height: 17px;
  text-align: center;
}

/* ----------------------------------------------------------- экран звонка */
.call-screen {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(10, 15, 30, 0.92), rgba(10, 15, 30, 0));
  position: relative;
  z-index: 5;
}
.top-left, .top-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
#roomLabel {
  font-size: 15px;
  max-width: 32vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.live-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 0 rgba(50, 214, 160, 0.6);
  animation: pulse 2.2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(50, 214, 160, 0.55); }
  70% { box-shadow: 0 0 0 9px rgba(50, 214, 160, 0); }
  100% { box-shadow: 0 0 0 0 rgba(50, 214, 160, 0); }
}
.chip {
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}
.badge {
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
}

.stage { position: relative; overflow: hidden; display: flex; }

.grid {
  flex: 1;
  display: grid;
  gap: 10px;
  padding: 4px 14px 8px;
  align-content: center;
  justify-content: center;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
  overflow-y: auto;
  overflow-x: hidden;
}
.grid[data-count="1"] { grid-template-columns: minmax(0, 1fr); max-width: 900px; margin: 0 auto; width: 100%; }
.grid[data-count="2"] { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }

.tile {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: #0d1526;
  border: 1px solid var(--border);
  aspect-ratio: 16 / 9;
  min-height: 120px;
  isolation: isolate;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  transition: box-shadow 0.18s ease, border-color 0.18s ease;
}
.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #0d1526;
  transform: translateZ(0);
}
.tile.self video { transform: scaleX(-1); }
.tile.sharing video { object-fit: contain; background: #000; }
.tile.self.sharing video { transform: none; }
.tile.no-video video { visibility: hidden; }

.tile.sharing::before {
  content: "экран";
  position: absolute;
  top: 9px;
  left: 9px;
  z-index: 2;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #06210f;
  background: rgba(50, 214, 160, 0.92);
  border-radius: 7px;
  padding: 2px 7px;
}

.avatar {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, rgba(76, 141, 255, 0.22), rgba(13, 21, 38, 0.95) 70%);
}
.tile:not(.no-video) .avatar { display: none; }
.avatar span {
  width: clamp(46px, 22%, 92px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: clamp(18px, 4.5vw, 34px);
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #4c8dff, #7b5cff);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.32);
  text-transform: uppercase;
  user-select: none;
}

.tile-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 26px 11px 9px;
  background: linear-gradient(180deg, transparent, rgba(4, 8, 18, 0.86));
  font-size: 12.5px;
  pointer-events: none;
}
.tile-name {
  font-weight: 600;
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}
.tile-mic {
  width: 17px;
  height: 17px;
  margin-left: auto;
  color: #ff7c88;
  display: none;
}
.tile.mic-off .tile-mic { display: inline-block; }

.tile-tag {
  position: absolute;
  top: 9px; left: 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 7px;
  background: rgba(76, 141, 255, 0.9);
  color: #fff;
  text-transform: uppercase;
}

.tile.speaking { border-color: rgba(50, 214, 160, 0.85); box-shadow: 0 0 0 2px rgba(50, 214, 160, 0.32), 0 8px 24px rgba(0, 0, 0, 0.3); }
.tile.self::after {
  content: "вы";
  position: absolute;
  top: 9px; right: 9px;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #cfe0ff;
  background: rgba(10, 15, 30, 0.66);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px 7px;
}

.waiting {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 4px;
  text-align: center;
  color: var(--muted);
  padding: 20px;
  pointer-events: none;
}
.waiting-art { font-size: 40px; margin-bottom: 6px; }
.waiting p { margin: 2px 0; font-size: 14px; }
.waiting strong { color: var(--text); font-size: 15px; }

/* ------------------------------------------------------------- управление */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(10, 15, 30, 0.96), rgba(10, 15, 30, 0.4));
  position: relative;
  z-index: 5;
}
.ctl-group { display: flex; gap: 10px; }

.ctl {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-radius: 15px;
  min-width: 66px;
  padding: 9px 12px 8px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.ctl:hover { background: rgba(255, 255, 255, 0.14); }
.ctl:active { transform: scale(0.96); }
.ctl:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ctl-icon { width: 21px; height: 21px; }
.ctl-text { white-space: nowrap; }

.ctl.on { background: rgba(76, 141, 255, 0.2); border-color: rgba(76, 141, 255, 0.55); }
.ctl.off { background: rgba(255, 77, 94, 0.16); border-color: rgba(255, 77, 94, 0.5); color: #ffc2c7; }
.ctl.danger {
  background: var(--danger);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 22px rgba(255, 77, 94, 0.32);
}
.ctl.danger:hover { filter: brightness(1.08); }
.ctl:disabled { opacity: 0.5; cursor: not-allowed; }

/* ------------------------------------------------------- окно приглашения */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 8, 18, 0.74);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade 0.18s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  width: min(380px, 100%);
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-hint { margin: 8px 0 12px; font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.modal-hint.small { margin: 12px 0 0; font-size: 11.5px; text-align: center; }

.invite-link { display: flex; gap: 8px; }
.invite-link input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: rgba(8, 13, 27, 0.7);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.invite-link input:focus { outline: none; border-color: rgba(76, 141, 255, 0.7); }

.qr-wrap { margin-top: 16px; display: grid; place-items: center; }
.qr-wrap canvas {
  width: min(230px, 62vw);
  height: auto;
  border-radius: 12px;
  background: #fff;
  padding: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

/* --------------------------------------------------------------- настройки */
.settings-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: grid;
  /* minmax(0, 1fr) обязателен: иначе длинное имя устройства распирает панель */
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-content: start;
}
.settings-body > * { min-width: 0; }
.field select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: rgba(8, 13, 27, 0.65);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  appearance: none;
  -webkit-appearance: none;
}
.field select:focus { outline: none; border-color: rgba(76, 141, 255, 0.75); }
.field input[type="range"] { width: 100%; accent-color: var(--accent); margin: 4px 0; }
.field .field-value { color: var(--text); font-weight: 700; }

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
}
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }

/* --------------------------------------------------------------------- чат */
.chat {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(360px, 100vw);
  max-width: 100vw;
  overflow: hidden;
  background: rgba(13, 20, 38, 0.97);
  backdrop-filter: blur(20px);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 30;
  animation: slideIn 0.22s ease both;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  border-bottom: 1px solid var(--border);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg { max-width: 86%; align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.msg-who { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg-body {
  font-size: 14px;
  line-height: 1.4;
  padding: 8px 12px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.08);
  overflow-wrap: anywhere;
}
.msg.mine .msg-body { background: linear-gradient(135deg, #4c8dff, #3f6ff0); }
.msg.system { align-self: center; max-width: 100%; }
.msg.system .msg-body {
  font-size: 12px;
  color: var(--muted);
  background: transparent;
  padding: 2px;
}
.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.chat-form input {
  flex: 1;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: rgba(8, 13, 27, 0.7);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 13px;
  min-width: 0;
}
.chat-form input:focus { outline: none; border-color: rgba(76, 141, 255, 0.7); }

/* ---------------------------------------------------------------- тосты */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 40;
  pointer-events: none;
  width: max-content;
  max-width: min(92vw, 460px);
}
.toast {
  font-size: 13.5px;
  line-height: 1.4;
  background: rgba(24, 34, 58, 0.96);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.42);
  animation: toastIn 0.22s ease both;
  text-align: center;
}
.toast.err { border-color: rgba(255, 77, 94, 0.5); color: #ffc9ce; }
.toast.ok { border-color: rgba(50, 214, 160, 0.5); color: #b8ffe6; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* -------------------------------------------------------------- мобильные */
@media (max-width: 720px) {
  .hide-xs { display: none; }
  .grid { padding: 2px 10px 6px; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); }
  .grid[data-count="1"] { grid-template-columns: 1fr; }
  .tile { aspect-ratio: 4 / 3; }
  .ctl { min-width: 58px; padding: 8px 9px 7px; }
  .ctl-text { font-size: 10.5px; }
  .call-screen { height: 100dvh; }
  #roomLabel { max-width: 26vw; }
  .join-card { padding: 22px 18px; }
  .toasts { bottom: calc(84px + env(safe-area-inset-bottom)); }
  /* Чат на телефоне — на всю ширину: left+right вместо width, чтобы
     не зависеть от разницы layout/visual viewport */
  .chat { left: 0; width: auto; border-left: none; }
}

/* Узкие экраны: кнопка «Копировать» уходит под ссылку, чтобы её не обрезало */
@media (max-width: 430px) {
  .invite-link { flex-direction: column; }
  .invite-link .btn { width: 100%; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .topbar { padding-top: 6px; padding-bottom: 6px; }
  .controls { padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .ctl-text { display: none; }
  .ctl { min-width: 48px; border-radius: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
