:root {
  --bg: #0b0d12;
  --panel: #151922;
  --panel-2: #1d2330;
  --line: #2a3140;
  --text: #e8ecf3;
  --muted: #8b94a7;
  --accent: #5b8cff;
  --accent-2: #7c5bff;
  --danger: #ff5b6e;
  --ok: #34d399;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 800px at 70% -10%, #182032 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Screens ── */
.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; }

#lobby, #waiting {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: min(440px, 92vw);
  background: linear-gradient(180deg, var(--panel) 0%, #11151d 100%);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 38px 32px;
  text-align: center;
  box-shadow: var(--shadow);
}

.logo { font-size: 30px; font-weight: 800; letter-spacing: -0.5px; }
.tagline { color: var(--muted); margin: 8px 0 28px; font-size: 15px; }

#join-form { display: flex; flex-direction: column; gap: 12px; }

input[type="text"] {
  width: 100%;
  padding: 15px 16px;
  font-size: 16px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

#join-btn {
  padding: 15px 16px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  border-radius: 12px;
  transition: transform .08s, opacity .15s;
}
#join-btn:hover { opacity: .94; }
#join-btn:active { transform: translateY(1px); }
#join-btn:disabled { opacity: .5; cursor: progress; }

.hint { color: var(--muted); font-size: 13px; margin: 22px 0 0; line-height: 1.5; }

.online-pill {
  display: inline-block;
  margin: 18px auto 0;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--ok);
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.25);
  border-radius: 999px;
}

.ghost-btn {
  margin-top: 14px;
  padding: 10px 20px;
  font-size: 14px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: color .15s, border-color .15s;
}
.ghost-btn:hover { color: var(--text); border-color: var(--muted); }

.perm-status {
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 1.5;
}
.perm-status.ok { color: var(--ok); }
.perm-status.err { color: var(--danger); }
.perm-status[hidden] { display: none; }

/* ── Spinner ── */
.spinner {
  width: 46px; height: 46px;
  margin: 0 auto 22px;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.spinner.small { width: 30px; height: 30px; border-width: 3px; margin-bottom: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

#waiting h2 { margin: 0 0 4px; font-size: 21px; }

/* ── Call screen ── */
#call.active { flex-direction: column; height: 100dvh; }

.timer-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  background: rgba(13, 16, 22, 0.8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 22px;
  min-width: 64px;
}
.timer.urgent { color: var(--danger); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.timer-progress {
  flex: 1;
  height: 6px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
}
.timer-progress span {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transform-origin: left;
  transition: transform .25s linear;
}
.partner-name { font-weight: 600; color: var(--muted); max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stage {
  position: relative;
  flex: 1;
  background: #06080c;
  overflow: hidden;
}
#remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #06080c;
}
.remote-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 4px;
}
.remote-placeholder[hidden] { display: none; }

#local-video {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: clamp(120px, 22vw, 220px);
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  background: #11151d;
  box-shadow: var(--shadow);
  transform: scaleX(-1); /* mirror self-view */
  z-index: 2;
}

/* ── Controls ── */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: rgba(13, 16, 22, 0.9);
  border-top: 1px solid var(--line);
}

.ctrl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  min-width: 70px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 12px;
  transition: background .15s, border-color .15s, opacity .15s;
}
button.ctrl:hover { background: #232a39; }
.ctrl-icon { font-size: 20px; line-height: 1; }
.ctrl.off { opacity: .55; }
.ctrl.off .ctrl-icon { filter: grayscale(1); }
.ctrl.danger { background: rgba(255, 91, 110, 0.12); border-color: rgba(255, 91, 110, 0.3); }
.ctrl.danger:hover { background: rgba(255, 91, 110, 0.2); }

.select-ctrl { align-items: stretch; min-width: 150px; }
.select-ctrl label { font-size: 11px; color: var(--muted); text-align: left; }
.select-ctrl select {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: #11151d;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
  max-width: 200px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 14px;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast[hidden] { display: none; }

@media (max-width: 560px) {
  .select-ctrl { min-width: 130px; }
  .partner-name { display: none; }
}
