:root {
  --bg: #0b0d12;
  --bg-2: #11141c;
  --card: rgba(255, 255, 255, 0.04);
  --stroke: rgba(255, 255, 255, 0.09);
  --text: #eef1f6;
  --muted: #8b93a7;
  --accent: #5b8cff;
  --accent-2: #7c6bff;
  --danger: #ff4d5e;
  --ok: #2ee6a6;
  --radius: 18px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background:
    radial-gradient(1200px 800px at 15% -10%, rgba(91, 140, 255, 0.18), transparent 55%),
    radial-gradient(1000px 700px at 110% 110%, rgba(124, 107, 255, 0.16), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- Lobby ---------- */
.lobby {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lobby-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 34px 30px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 22px;
}
.brand i { font-style: normal; color: var(--text); }
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(91, 140, 255, 0.18);
}

.lobby-card h1 {
  font-size: 30px;
  letter-spacing: -0.03em;
  margin-bottom: 26px;
}
.sub { color: var(--muted); font-size: 14.5px; line-height: 1.5; margin-bottom: 26px; }

.field { display: block; margin-bottom: 18px; }
.field span {
  display: block;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}
.field input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(91, 140, 255, 0.15);
}

.lobby-actions { display: flex; gap: 10px; align-items: stretch; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  padding: 14px 18px;
  transition: transform 0.12s, filter 0.2s, background 0.2s;
  color: #fff;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 18px; height: 18px; fill: currentColor; }

.btn-primary {
  flex: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 24px rgba(91, 140, 255, 0.3);
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--stroke);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.btn-ghost:hover { color: var(--text); }

.hint { margin-top: 20px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.hint.error { color: var(--danger); }

.lobby-foot { margin-top: 22px; color: rgba(139, 147, 167, 0.6); font-size: 12px; }

/* ---------- Call ---------- */
.call { position: fixed; inset: 0; display: flex; flex-direction: column; }

.stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #05060a;
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #05060a;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  color: var(--muted);
  background:
    radial-gradient(700px 500px at 50% 40%, rgba(91, 140, 255, 0.12), transparent 60%),
    #05060a;
}
.placeholder p { font-size: 15px; }
.room-tag { font-size: 13px; color: rgba(139, 147, 167, 0.7); }
.room-tag b { color: var(--text); }

.spinner {
  width: 42px; height: 42px;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.remote-cam-off {
  position: absolute;
  inset: 0;
  z-index: 2; /* above remote video, below local PiP / topbar / controls */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background:
    radial-gradient(700px 500px at 50% 42%, rgba(91, 140, 255, 0.1), transparent 60%),
    #07090e;
  color: var(--muted);
}
.remote-cam-off p { font-size: 15px; }
.cam-off-icon {
  width: 88px; height: 88px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--stroke);
}
.cam-off-icon svg { width: 40px; height: 40px; fill: var(--muted); }

.local-wrap {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 168px;
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  background: #0b0d12;
  transition: transform 0.2s, opacity 0.2s;
  z-index: 5;
}
.local-wrap:hover { transform: scale(1.02); }
#local-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror self-view */
}
.local-wrap.cam-off #local-video { opacity: 0; }
.local-wrap.cam-off::after {
  content: "Камера выкл.";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--muted);
}
.local-label {
  position: absolute;
  left: 8px; bottom: 8px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
}

.topbar {
  position: absolute;
  top: 16px; left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 10px;
  z-index: 6;
  pointer-events: none;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 13px;
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.6);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(14px);
  color: var(--text);
}
.conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  transition: background 0.3s;
}
.pill.connecting .conn-dot { background: #f5a623; animation: pulse 1.2s infinite; }
.pill.connected .conn-dot { background: var(--ok); }
.pill.failed .conn-dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.4));
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 6;
}

.ctrl {
  width: 58px; height: 58px;
  border-radius: 50%;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(14px);
  transition: transform 0.12s, background 0.2s;
}
.ctrl:active { transform: scale(0.92); }
.ctrl:hover { background: rgba(255, 255, 255, 0.16); }
.ctrl svg { width: 24px; height: 24px; fill: currentColor; }

.ctrl .i-off { display: none; }
.ctrl.off { background: rgba(255, 255, 255, 0.04); color: var(--muted); }
.ctrl.off .i-on { display: none; }
.ctrl.off .i-off { display: block; }

.ctrl.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 20px rgba(91, 140, 255, 0.35);
}
.ctrl.active .i-on { display: none; }
.ctrl.active .i-off { display: block; }
.ctrl[disabled] { opacity: 0.4; pointer-events: none; }

.ctrl-end { background: var(--danger); border-color: transparent; width: 64px; height: 64px; }
.ctrl-end:hover { background: #ff3548; }

/* Devices button carries a small chevron badge over the mic glyph. */
#devices-btn { position: relative; }
#devices-btn .chev {
  position: absolute;
  width: 14px; height: 14px;
  right: 7px; bottom: 7px;
  padding: 1px;
  border-radius: 50%;
  background: var(--bg-2);
}
#devices-btn.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; }

/* Microphone picker popover */
.device-menu {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  width: min(320px, calc(100vw - 32px));
  background: rgba(14, 17, 24, 0.96);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  padding: 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  animation: rise 0.2s ease;
  z-index: 20;
}
.device-menu-title {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 4px 10px 8px;
}
.device-list { display: flex; flex-direction: column; gap: 2px; max-height: 240px; overflow-y: auto; }
.device-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 10px;
  border-radius: 9px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  background: none;
  border: 0;
  width: 100%;
  transition: background 0.15s;
}
.device-item:hover { background: rgba(255, 255, 255, 0.06); }
.device-item .check {
  width: 18px; height: 18px;
  flex-shrink: 0;
  fill: var(--accent);
  opacity: 0;
}
.device-item.selected .check { opacity: 1; }
.device-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-empty { padding: 10px; font-size: 13px; color: var(--muted); }
.device-menu-sep { height: 1px; background: var(--stroke); margin: 8px 4px; }

/* Toggle switch */
.toggle {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  cursor: pointer;
  user-select: none;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track {
  flex-shrink: 0;
  width: 40px; height: 23px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  transition: background 0.2s;
  position: relative;
}
.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 19px; height: 19px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(17px); }
.toggle-text { font-size: 14px; color: var(--text); line-height: 1.3; }
.toggle-text i { display: block; font-style: normal; font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* Self-view shows the shared screen un-mirrored, fit to frame. */
.local-wrap.sharing { aspect-ratio: 16 / 9; width: 220px; }
.local-wrap.sharing #local-video { transform: none; object-fit: contain; background: #000; }
.local-wrap.sharing .local-label::after { content: " · экран"; }
@media (max-width: 520px) {
  .local-wrap.sharing { width: 150px; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  background: rgba(10, 12, 18, 0.92);
  border: 1px solid var(--stroke);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  backdrop-filter: blur(14px);
  z-index: 50;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease;
}

@media (max-width: 520px) {
  .local-wrap { width: 116px; right: 12px; bottom: 12px; }
  .ctrl { width: 54px; height: 54px; }
  .ctrl-end { width: 60px; height: 60px; }
}
