@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Sora:wght@500;600;700&display=swap");

:root {
  --bg: #07090c;
  --bg-card: #10151c;
  --bg-elev: #161d27;
  --ink: #f2f6fa;
  --muted: #8b97a8;
  --line: rgba(148, 170, 190, 0.16);
  --teal: #2ee6c5;
  --teal-dim: #1aa890;
  --teal-glow: rgba(46, 230, 197, 0.45);
  --danger: #ff6b7a;
  --danger-dim: rgba(255, 107, 122, 0.18);
  --radius-card: 28px;
  --radius-pill: 999px;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Sora", "Manrope", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

body {
  position: relative;
  isolation: isolate;
  padding:
    env(safe-area-inset-top, 0)
    env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0)
    env(safe-area-inset-left, 0);
}

body.in-call {
  overflow: hidden;
  height: 100dvh;
}

body.in-call .ambient {
  position: fixed;
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
}

.dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 12px var(--teal-glow);
  flex-shrink: 0;
}

.brand-row {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.brand {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: rgba(22, 29, 39, 0.7);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.shell {
  width: min(520px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 1.5rem 1.65rem;
  border-radius: var(--radius-card);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 40%),
    var(--bg-card);
  border: 1px solid var(--line);
  box-shadow:
    0 0 0 1px rgba(46, 230, 197, 0.04),
    0 30px 80px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
}

.shell-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.35rem;
}

h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(1.55rem, 3.5vw, 1.95rem);
  letter-spacing: -0.02em;
  margin: 0 0 0.55rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.lead {
  margin: 0 0 1.4rem;
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.95rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.95rem;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
}

input, select, button {
  font: inherit;
}

input, select {
  appearance: none;
  width: 100%;
  background: var(--bg-elev);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 0.85rem 1.1rem;
  outline: none;
  font-size: 16px; /* iOS: evite zoom auto sur focus */
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 1.15rem) 50%,
    calc(100% - 0.85rem) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2.4rem;
}

input:focus, select:focus {
  border-color: rgba(46, 230, 197, 0.55);
  box-shadow: 0 0 0 3px rgba(46, 230, 197, 0.12), 0 0 24px rgba(46, 230, 197, 0.12);
}

input::placeholder {
  color: #667487;
}

button {
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
  border-radius: var(--radius-pill);
  padding: 0.75rem 1.2rem;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

button:hover {
  border-color: rgba(46, 230, 197, 0.35);
}

button:active {
  transform: translateY(1px);
}

button.primary {
  background: linear-gradient(135deg, #39f0cf 0%, #1fc9a8 55%, #18b89b 100%);
  color: #04241c;
  border: none;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 0.9rem 1.4rem;
}

button.primary.glow,
button.glow {
  box-shadow:
    0 0 0 1px rgba(46, 230, 197, 0.25),
    0 0 28px var(--teal-glow),
    0 12px 28px rgba(0, 0, 0, 0.35);
}

button.primary:hover {
  box-shadow:
    0 0 0 1px rgba(46, 230, 197, 0.4),
    0 0 36px rgba(46, 230, 197, 0.55),
    0 14px 32px rgba(0, 0, 0, 0.4);
}

.lobby-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 0;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.35rem;
}

.lobby-actions .primary {
  width: 100%;
}

.error {
  color: #ffb0b8;
  font-size: 0.88rem;
  margin: 0;
  padding: 0.65rem 0.9rem;
  border-radius: 14px;
  background: var(--danger-dim);
  border: 1px solid rgba(255, 107, 122, 0.35);
}

.hint-card {
  margin-top: 0.4rem;
  padding: 1rem 1.05rem;
  border-radius: 18px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
}

.hint-label {
  margin: 0 0 0.55rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--teal);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hint {
  margin: 0;
  overflow-x: auto;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.page-home {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 0;
}

/* —— Stage / call —— */
.stage {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 9, 12, 0.72);
  backdrop-filter: blur(14px);
}

.room-id {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.stage-body {
  position: relative;
  min-height: 0;
  display: grid;
}

.grid {
  display: grid;
  gap: 0.85rem;
  padding: 1rem 1.1rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  align-content: center;
  min-height: 0;
}

.tile {
  position: relative;
  background: #05070a;
  border-radius: 20px;
  overflow: hidden;
  aspect-ratio: 16 / 10;
  border: 1px solid var(--line);
  box-shadow: 0 0 0 1px rgba(46, 230, 197, 0.04), 0 18px 40px rgba(0, 0, 0, 0.35);
}

.self-pip {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 5;
  width: min(28vw, 220px);
  pointer-events: auto;
}

.self-pip[hidden],
.self-pip.is-shut {
  display: none !important;
}

.tile-local {
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 280px;
  border-radius: 14px;
  border-color: rgba(46, 230, 197, 0.45);
  box-shadow:
    0 0 0 1px rgba(46, 230, 197, 0.2),
    0 12px 28px rgba(0, 0, 0, 0.45);
}

.pip-shut {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(7, 9, 12, 0.75);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}

.pip-shut:hover {
  border-color: rgba(255, 107, 122, 0.55);
  color: #ffb0b8;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #05070a;
  display: block;
}

/* un seul flux visible par tuile */
.tile video:nth-of-type(n + 2) {
  display: none !important;
}

.tile .label {
  position: absolute;
  left: 0.75rem;
  bottom: 0.7rem;
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-pill);
  background: rgba(7, 9, 12, 0.72);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  font-size: 0.75rem;
  font-weight: 600;
}

.controls {
  padding: 0.85rem 1rem 1.35rem;
  display: flex;
  justify-content: center;
  border-top: 1px solid var(--line);
  background: rgba(7, 9, 12, 0.78);
  backdrop-filter: blur(14px);
}

.controls-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.45rem;
  border-radius: var(--radius-pill);
  background: rgba(16, 21, 28, 0.9);
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.ctrl {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 7.2rem;
  justify-content: center;
  background: transparent;
  border-color: transparent;
  font-weight: 600;
  font-size: 0.88rem;
}

.ctrl:hover {
  background: rgba(46, 230, 197, 0.08);
}

.ctrl[aria-pressed="true"] {
  border-color: rgba(46, 230, 197, 0.55);
  box-shadow: 0 0 18px rgba(46, 230, 197, 0.22);
  background: rgba(46, 230, 197, 0.08);
}

.ctrl[aria-pressed="false"] .ctrl-dot {
  background: #667487;
  box-shadow: none;
}

.ctrl-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 10px var(--teal-glow);
}

.ctrl.danger {
  color: #ffb0b8;
  border-color: rgba(255, 107, 122, 0.35);
  background: var(--danger-dim);
}

.ctrl.danger:hover {
  border-color: rgba(255, 107, 122, 0.55);
  box-shadow: 0 0 18px rgba(255, 107, 122, 0.2);
}

@media (max-width: 640px) {
  .shell {
    width: calc(100% - 1rem);
    padding: 1.15rem;
    border-radius: 22px;
  }
  .lobby-wrap {
    align-items: stretch;
    padding: 1rem 0 calc(1rem + env(safe-area-inset-bottom, 0));
  }
  .lead { font-size: 0.9rem; }
  .grid {
    grid-template-columns: 1fr;
    padding: 0.6rem;
    gap: 0.55rem;
  }
  .tile {
    aspect-ratio: 4 / 3;
    border-radius: 16px;
  }
  .self-pip {
    right: 0.65rem;
    bottom: 0.65rem;
    width: min(34vw, 140px);
  }
  .tile-local {
    aspect-ratio: 3 / 4;
    max-height: 180px;
    border-radius: 12px;
  }
  .pip-shut {
    width: 1.9rem;
    height: 1.9rem;
  }
  .stage {
    min-height: 100dvh;
    grid-template-rows: auto 1fr auto;
  }
  .topbar {
    padding: 0.75rem 0.85rem;
  }
  .controls {
    position: sticky;
    bottom: 0;
    padding: 0.65rem 0.75rem calc(0.85rem + env(safe-area-inset-bottom, 0));
  }
  .controls-inner {
    width: 100%;
    gap: 0.4rem;
  }
  .ctrl {
    min-width: 0;
    flex: 1 1 0;
    min-height: 48px;
    padding: 0.7rem 0.5rem;
    font-size: 0.82rem;
  }
  button.primary {
    min-height: 52px;
    font-size: 1rem;
  }
}

@media (max-width: 640px) and (orientation: landscape) {
  .tile { aspect-ratio: 16 / 9; }
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
