:root {
  --bg: #0b0d12;
  --bg-2: #11141b;
  --card: #151922;
  --card-2: #1c212c;
  --text: #eef1f7;
  --muted: #98a2b3;
  --accent: #6c8cff;
  --accent-2: #8f6cff;
  --danger: #ef5350;
  --ok: #3ddc97;
  --border: rgba(255, 255, 255, 0.09);
  --radius: 18px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(108, 140, 255, 0.22), transparent 60%),
    radial-gradient(700px 400px at 100% 0%, rgba(143, 108, 255, 0.16), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.45;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 650;
  letter-spacing: 0.2px;
}

.logo {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-size: 18px;
  box-shadow: 0 8px 22px rgba(108, 140, 255, 0.35);
}

.room-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(21, 25, 34, 0.7);
  backdrop-filter: blur(8px);
}

.room-caption {
  color: var(--muted);
  font-size: 12px;
}

.room-chip code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 13px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  border: 0;
  background: var(--card-2);
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
}

/* ----------------------------------------------------------------- stage */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px 0;
}

.join-card {
  width: min(520px, 100%);
  margin: auto;
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 10px);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 40%), var(--card);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.join-head h1 {
  margin: 0 0 10px;
  font-size: clamp(30px, 7vw, 44px);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.join-head h1 span {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.join-head p {
  margin: 0 0 24px;
  color: var(--muted);
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 14px 15px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 140, 255, 0.2);
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 13px;
  transition: transform 0.06s, background 0.15s, opacity 0.15s;
}

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

.primary {
  margin-top: 4px;
  padding: 15px 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 650;
  font-size: 16px;
  box-shadow: 0 12px 30px rgba(108, 140, 255, 0.3);
}

.primary:disabled {
  opacity: 0.55;
  cursor: wait;
  box-shadow: none;
}

.hint {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.hint.error {
  color: #ff9a9c;
}

/* ----------------------------------------------------------------- tiles */
.tiles {
  width: 100%;
  max-width: 1500px;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
  gap: 12px;
  align-content: center;
  padding-bottom: 10px;
  position: relative;
}

.tile {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  background: #05070b;
  border: 1px solid var(--border);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

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

.tile.local video {
  transform: scaleX(-1);
}

.tile.local.screen video {
  transform: none;
  object-fit: contain;
  background: #000;
}

.tile.audio-only video {
  visibility: hidden;
}

.tile .label {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: 72%;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(5, 7, 11, 0.7);
  backdrop-filter: blur(8px);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile .badge {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(5, 7, 11, 0.7);
  backdrop-filter: blur(8px);
  color: var(--muted);
  font-size: 12px;
}

.tile .badge.ok {
  color: var(--ok);
}

.tile .badge.warn {
  color: #f7b955;
}

.audio-hint {
  position: absolute;
  z-index: 5;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: #fff;
  color: #111;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

/* --------------------------------------------------------------- controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
}

.control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 15px;
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.control[aria-pressed="false"] {
  background: rgba(239, 83, 80, 0.16);
  border-color: rgba(239, 83, 80, 0.4);
  color: #ffb3b5;
}

.control.danger {
  background: rgba(239, 83, 80, 0.14);
  border-color: rgba(239, 83, 80, 0.35);
  color: #ffb3b5;
}

.status {
  flex-basis: 100%;
  min-height: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 720px) {
  .join-card {
    padding: 22px;
  }

  .controls {
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, transparent, rgba(11, 13, 18, 0.92) 35%);
    padding-top: 20px;
  }

  .control {
    padding: 10px 12px;
  }

  .control .txt {
    display: none;
  }

  .control .ico {
    font-size: 18px;
  }

  .tiles {
    grid-template-columns: 1fr;
    align-content: start;
    padding-top: 4px;
  }

  .tile {
    aspect-ratio: 4 / 3;
  }
}
