/* ===== Токены ===== */
:root {
  --bg: #0d0f13;
  --bg-2: #12151b;
  --surface: #191d25;
  --surface-2: #222733;
  --surface-3: #2c3241;
  --border: rgba(255, 255, 255, .08);
  --border-2: rgba(255, 255, 255, .15);
  --text: #eef1f6;
  --text-2: #a9b1c0;
  --text-3: #6f788a;
  --accent: #6c8cff;
  --accent-2: #9b6cff;
  --accent-soft: rgba(108, 140, 255, .16);
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f05252;
  --danger-soft: rgba(240, 82, 82, .16);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 12px 32px rgba(0, 0, 0, .4);
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -.02em; }
.muted { color: var(--text-2); }

.ico { width: 20px; height: 20px; flex: none; display: block; }
i[data-icon] { display: contents; }

/* ===== Экраны ===== */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; overflow: auto; }
.screen-home, .screen-lobby, .screen-left {
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(155, 108, 255, .18), transparent 60%),
    radial-gradient(800px 500px at -10% 110%, rgba(108, 140, 255, .16), transparent 60%),
    var(--bg);
}

.topbar { display: flex; align-items: center; padding: 20px 28px; flex: none; }
.logo { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 18px; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: url("/favicon.svg") center / cover;
  box-shadow: 0 4px 14px rgba(108, 140, 255, .35);
}

/* ===== Кнопки и поля ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  background: var(--surface-2); color: var(--text); font-weight: 600; text-decoration: none;
  transition: background .15s, transform .1s, box-shadow .15s, opacity .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 6px 20px rgba(108, 140, 255, .3); }
.btn-primary:hover { background: linear-gradient(135deg, #7d9aff, #a77cff); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #f46a6a; }
.btn-lg { height: 50px; padding: 0 22px; border-radius: 14px; font-size: 16px; }
.btn-sm { height: 30px; padding: 0 12px; border-radius: 9px; font-size: 13px; }
.btn-block { width: 100%; }

.input {
  width: 100%; height: 40px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--border-2); background: var(--bg-2); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-lg { height: 50px; border-radius: 14px; font-size: 16px; }
textarea.input { height: auto; padding: 10px 14px; resize: none; line-height: 1.4; }

.select {
  position: relative; display: flex; align-items: center; gap: 8px; min-width: 0;
  height: 40px; padding: 0 30px 0 12px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2);
}
.select::after {
  content: ""; position: absolute; right: 13px; top: 50%; width: 7px; height: 7px; margin-top: -5px;
  border: solid var(--text-3); border-width: 0 2px 2px 0; transform: rotate(45deg); pointer-events: none;
}
.select .ico { width: 18px; height: 18px; }
.select select {
  appearance: none; flex: 1; min-width: 0; height: 100%; border: 0; background: transparent;
  color: var(--text); outline: none; text-overflow: ellipsis; cursor: pointer;
}
.select select option { background: var(--surface); color: var(--text); }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none;
  border-radius: 10px; border: 0; background: transparent; color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn-accent { background: var(--accent); color: #fff; }
.icon-btn-accent:hover { background: #7d9aff; color: #fff; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 600;
}
button.chip:hover { background: var(--surface-2); }
.chip .ico { width: 16px; height: 16px; }
.chip-warn { color: var(--warn); border-color: rgba(251, 191, 36, .3); background: rgba(251, 191, 36, .08); }

.form-error { color: #ff8a8a; font-size: 14px; margin: 12px 0 0; }

.spinner {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Круглые кнопки управления (используются в лобби и во встрече) */
.ctrl {
  position: relative; display: inline-grid; place-items: center; flex: none;
  width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: var(--surface-3); color: var(--text);
  transition: background .15s, color .15s, transform .1s;
}
.ctrl:hover { background: #384056; }
.ctrl:active { transform: scale(.96); }
.ctrl .ico { width: 22px; height: 22px; }
.ctrl.off { background: var(--danger); color: #fff; }
.ctrl.off:hover { background: #f46a6a; }
.ctrl.active { background: var(--accent); color: #fff; }
.ctrl.active:hover { background: #7d9aff; }
.ctrl:disabled { opacity: .45; cursor: default; }

/* Аватар с инициалами */
.avatar {
  --c: #5b6b8c;
  display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%;
  background: var(--c); color: #fff; font-weight: 700; font-size: 15px; letter-spacing: .02em;
  text-transform: uppercase; user-select: none;
}
.avatar-xl { width: 96px; height: 96px; font-size: 34px; }

/* ===== Главная ===== */
.home {
  flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 4vh 28px 48px;
  display: flex; flex-direction: column; justify-content: center; gap: 56px;
}
.home h1 { font-size: clamp(38px, 6vw, 64px); font-weight: 800; }
.grad { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lead { max-width: 600px; margin: 20px 0 32px; color: var(--text-2); font-size: 18px; }
.home-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.join-form { display: flex; gap: 8px; flex: 1; min-width: 280px; max-width: 460px; }
.features { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.features li {
  display: flex; gap: 14px; padding: 20px; border-radius: var(--radius);
  background: rgba(25, 29, 37, .7); border: 1px solid var(--border);
}
.features .ico { width: 24px; height: 24px; color: var(--accent); margin-top: 2px; }
.features b { display: block; margin-bottom: 4px; }
.features span { color: var(--text-2); font-size: 14px; }

/* ===== Лобби ===== */
.lobby {
  flex: 1; width: 100%; max-width: 1120px; margin: 0 auto; padding: 2vh 28px 40px;
  display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 48px; align-items: center;
}
.preview-box {
  position: relative; aspect-ratio: 16 / 9; border-radius: 20px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.preview-box video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
video.mirror { transform: scaleX(-1); }
.preview-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: var(--text-2); background: var(--surface); text-align: center; padding: 20px;
}
.preview-controls { position: absolute; left: 0; right: 0; bottom: 18px; display: flex; justify-content: center; gap: 14px; }
.preview-controls .ctrl { width: 52px; height: 52px; background: rgba(44, 50, 65, .85); backdrop-filter: blur(8px); }
.preview-controls .ctrl.off { background: var(--danger); }
.preview-meter { position: absolute; left: 16px; bottom: 30px; }
.meter { display: flex; align-items: flex-end; gap: 3px; height: 18px; }
.meter i { width: 4px; height: 6px; border-radius: 2px; background: rgba(255, 255, 255, .35); transition: height .08s, background .08s; }
.meter i.on { background: var(--ok); }
.meter i:nth-child(2).on, .meter i:nth-child(4).on { height: 12px; }
.meter i:nth-child(3).on { height: 18px; }
.device-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.lobby-join { display: flex; flex-direction: column; gap: 12px; }
.lobby-join h2 { font-size: 30px; font-weight: 750; }
.lobby-join p { margin: 0; }
.lobby-people { color: var(--text-2); font-size: 14px; min-height: 20px; margin-bottom: 8px !important; }
.lobby-join .input { margin-top: 4px; }

/* ===== Экран после выхода ===== */
.screen-left { align-items: center; justify-content: center; padding: 24px; }
.left-box { text-align: center; max-width: 440px; }
.left-icon {
  width: 72px; height: 72px; margin: 0 auto 20px; border-radius: 50%; display: grid; place-items: center;
  background: var(--danger-soft); color: var(--danger);
}
.left-icon .ico { width: 30px; height: 30px; transform: rotate(135deg); }
.left-box h2 { font-size: 28px; }
.left-box p { margin: 10px 0 26px; }
.left-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ===== Диалог настроек ===== */
.dialog {
  width: min(480px, calc(100vw - 32px)); padding: 0; border-radius: 20px;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(5, 7, 10, .6); backdrop-filter: blur(4px); }
.dialog-body { display: flex; flex-direction: column; gap: 14px; padding: 20px 22px 22px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.dialog-head h3 { font-size: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); }
.field .select { background: var(--bg-2); }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 6px; }

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-ui {
  position: relative; width: 40px; height: 24px; flex: none; border-radius: 999px;
  background: var(--surface-3); transition: background .15s;
}
.switch-ui::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
.switch input:checked + .switch-ui { background: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-ui { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ===== Уведомления ===== */
.toasts {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); z-index: 50;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  display: flex; align-items: center; gap: 10px; max-width: 100%; padding: 10px 16px; border-radius: 12px;
  background: rgba(34, 39, 51, .96); border: 1px solid var(--border-2); box-shadow: var(--shadow);
  font-size: 14px; pointer-events: auto; animation: toast-in .2s ease-out;
}
.toast .ico { width: 18px; height: 18px; color: var(--accent); }
.toast.warn .ico { color: var(--warn); }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity .25s, transform .25s; }
.toast-text { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ===== Адаптив ===== */
@media (max-width: 900px) {
  .features { grid-template-columns: 1fr; }
  .lobby { grid-template-columns: 1fr; gap: 28px; align-items: start; }
}
@media (max-width: 560px) {
  .topbar { padding: 16px; }
  .home, .lobby { padding-left: 16px; padding-right: 16px; }
  .home { gap: 36px; justify-content: flex-start; }
  .lead { font-size: 16px; }
  .home-actions { flex-direction: column; }
  .join-form { min-width: 0; max-width: none; }
  .device-row { grid-template-columns: 1fr; }
  .preview-box { aspect-ratio: 4 / 3; }
  .lobby-join h2 { font-size: 24px; }
}
