:root {
  --bg: #111317;
  --surface: #1c1f26;
  --surface-2: #262a33;
  --text: #f2f4f8;
  --muted: #a2a9b6;
  --accent: #2f6df6;
  --danger: #e5484d;
  --speaking: #3ddc84;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }

/* Accueil : un champ, un bouton */
.lobby {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
#lobby-form {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.pill {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 999px;
  padding: 6px 6px 6px 22px;
  min-height: 60px;
  transition: border-color .15s, box-shadow .15s;
}
.pill:focus-within { border-color: rgba(47, 109, 246, .7); box-shadow: 0 0 0 4px rgba(47, 109, 246, .15); }
.pill input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  outline: none;
  font-size: 17px;
  padding: 10px 0;
}
.pill input::placeholder { color: #6f7685; }
#join-btn {
  flex: none;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  margin-left: 8px;
  transition: background .15s, opacity .15s;
}
#join-btn:hover:not(:disabled) { background: #3f7bff; }
#join-btn:disabled { opacity: .5; cursor: default; }
#join-btn svg { width: 20px; height: 20px; }
.lobby .error { background: none; border: 0; padding: 0 22px; font-size: 14px; }

/* Écrans attente / fin */
.card-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}
.card {
  width: min(400px, 100%);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: center;
}
.card h1, .card h2 { margin: 0; letter-spacing: -.01em; }
.card h1 { font-size: 24px; font-weight: 650; }
.card h2 { font-size: 20px; font-weight: 600; }
.muted { color: var(--muted); margin: 0; font-size: 15px; }
.error {
  color: #ffb4b6;
  background: rgba(229, 72, 77, .12);
  border: 1px solid rgba(229, 72, 77, .3);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0;
  font-size: 14px;
  text-align: left;
}

.field { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.field span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 12px;
  padding: 13px 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input::placeholder { color: #6f7685; }
.field input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 109, 246, .25);
}

.primary, .secondary {
  border: 0;
  border-radius: 12px;
  padding: 14px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.primary { background: var(--accent); color: #fff; }
.primary:hover:not(:disabled) { background: #3f7bff; }
.primary:active:not(:disabled) { transform: translateY(1px); }
.primary:disabled { opacity: .6; cursor: default; }
.secondary { background: var(--surface-2); }
.secondary:hover { background: #2f3440; }

.spinner {
  width: 44px; height: 44px; margin: 0 auto;
  border-radius: 50%;
  border: 4px solid var(--surface-2);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Appel */
#call {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #000;
}
#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 8px;
  padding: 8px;
  padding-top: max(8px, env(safe-area-inset-top));
}
#banner {
  background: #6b4b00;
  color: #fff;
  text-align: center;
  padding: 6px 12px;
  font-size: 14px;
}

.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  outline: 3px solid transparent;
  outline-offset: -3px;
  transition: outline-color .15s;
}
.tile.speaking { outline-color: var(--speaking); }
/* Les vidéos ne sont jamais rognées : on voit toujours l'image entière. */
.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.tile.mirror video { transform: scaleX(-1); }
.tile .avatar {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}
.tile .avatar span {
  width: min(96px, 40%);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-size: clamp(18px, 4vw, 36px);
  font-weight: 600;
}
.tile.has-video .avatar { display: none; }
.tile .label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .55);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile .label svg { width: 15px; height: 15px; flex: none; color: #ff8f93; }
.tile .actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity .15s;
}
.tile:hover .actions, .tile.show-actions .actions { opacity: 1; }
.tile.no-actions .actions { display: none; }
.tile .actions button {
  width: 36px; height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .65);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background .15s;
}
.tile .actions button:hover { background: var(--danger); }
.tile .actions button svg { width: 18px; height: 18px; }

/* Vignette perso flottante quand on est deux */
.tile.floating {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: clamp(110px, 22vw, 260px);
  aspect-ratio: var(--ar, 16 / 9);
  max-height: 40%;
  z-index: 2;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
}

#controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg);
}
.ctl {
  width: 52px; height: 52px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.ctl svg { width: 24px; height: 24px; }
.ctl.off { background: #fff; color: #111; }
.ctl.active { background: var(--accent); color: #fff; }
.ctl.danger { background: var(--danger); color: #fff; width: 64px; border-radius: 26px; }
@media (max-width: 480px) {
  #controls { gap: 8px; }
  .ctl { width: 46px; height: 46px; }
  .ctl.danger { width: 58px; }
}

.popover {
  position: absolute;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, calc(100% - 32px));
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 5;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.floating-cta {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
}

#toasts {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
  width: min(420px, calc(100% - 32px));
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 14px;
  text-align: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .4);
  animation: fade 4s forwards;
}
@keyframes fade { 0%, 85% { opacity: 1; } 100% { opacity: 0; } }

/* Mode incrustation (Document Picture-in-Picture) */
body.pip-body {
  background: #000;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
body.pip-body #pip-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 4px;
  padding: 4px;
}
body.pip-body .tile { border-radius: 8px; }
body.pip-body .tile .label { font-size: 11px; left: 4px; bottom: 4px; padding: 2px 6px; }
body.pip-body #pip-controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 6px;
  background: var(--bg);
}
body.pip-body .ctl { width: 38px; height: 38px; }
body.pip-body .ctl svg { width: 18px; height: 18px; }
body.pip-body .ctl.danger { width: 48px; }

/* Vidéo technique pour l'incrustation de secours (Safari, Firefox…) */
#pip-fallback {
  position: fixed;
  width: 2px;
  height: 2px;
  bottom: 0;
  right: 0;
  opacity: 0.01;
  pointer-events: none;
}
