:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #252540;
  --accent: #4ecca3;
  --accent-hover: #3ab88d;
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --text: #e8e8f0;
  --text-muted: #8888aa;
  --radius: 12px;
  --transition: 0.2s ease;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── Join screen ─────────────────────────────────── */
#join-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 2rem;
  padding: 2rem;
  text-align: center;
}

#join-screen.hidden { display: none; }

.logo {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--accent);
}

.tagline {
  color: var(--text-muted);
  font-size: 1rem;
}

#btn-join {
  padding: 1.1rem 3.5rem;
  font-size: 1.25rem;
  font-weight: 600;
  border: none;
  border-radius: 50px;
  background: var(--accent);
  color: #0f0f1a;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 0 32px rgba(78, 204, 163, 0.35);
}

#btn-join:hover { background: var(--accent-hover); transform: translateY(-2px); box-shadow: 0 0 40px rgba(78, 204, 163, 0.5); }
#btn-join:active { transform: translateY(0); }
#btn-join:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

#error-msg {
  color: var(--danger);
  font-size: 0.9rem;
  min-height: 1.2em;
  max-width: 320px;
}

/* ── Call screen ─────────────────────────────────── */
#call-screen {
  display: none;
  flex-direction: column;
  height: 100vh;
}

#call-screen.active { display: flex; }

/* Status bar */
#status-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  font-size: 0.8rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--surface2);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.status-dot.connecting { background: #f39c12; animation: pulse 1.2s infinite; }
.status-dot.connected  { background: var(--accent); }
.status-dot.error      { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Video grid */
#video-grid {
  flex: 1;
  display: grid;
  gap: 4px;
  background: var(--bg);
  overflow: hidden;
  position: relative;
  padding: 4px;
}

/* Grid layouts by participant count */
#video-grid[data-count="0"] { grid-template-columns: 1fr; }
#video-grid[data-count="1"] { grid-template-columns: 1fr; }
#video-grid[data-count="2"] { grid-template-columns: 1fr 1fr; }
#video-grid[data-count="3"],
#video-grid[data-count="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
#video-grid[data-count="5"],
#video-grid[data-count="6"] { grid-template-columns: repeat(3, 1fr); grid-template-rows: 1fr 1fr; }

.video-tile {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.video-tile .peer-label {
  position: absolute;
  bottom: 0.5rem; left: 0.5rem;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  color: var(--text);
}

.video-tile.muted-video video { display: none; }
.video-tile.muted-video::after {
  content: '📷';
  font-size: 2.5rem;
  opacity: 0.4;
}

/* Empty state */
#waiting-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.95rem;
  pointer-events: none;
}

#waiting-msg.hidden { display: none; }

/* Local video PiP — sits above the controls bar including iOS safe area */
#local-pip {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px)); right: 16px;
  width: 140px; height: 100px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface2);
  border: 2px solid var(--surface2);
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

#local-pip video {
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

/* Controls bar — padding-bottom accounts for iOS home bar */
#controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--surface2);
}

.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px; height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--surface2);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.ctrl-btn:hover { background: #333355; transform: scale(1.05); }
.ctrl-btn.active { background: var(--danger); }
.ctrl-btn:active { transform: scale(0.95); }

#btn-leave {
  padding: 0 1.5rem;
  border-radius: 50px;
  background: var(--danger);
  font-size: 0.9rem;
  font-weight: 600;
  color: white;
  width: auto;
}
#btn-leave:hover { background: var(--danger-hover); }

/* Responsive */
@media (max-width: 600px) {
  #local-pip { width: 100px; height: 72px; bottom: 72px; right: 8px; }
  .ctrl-btn { width: 44px; height: 44px; font-size: 1.1rem; }
  #btn-leave { padding: 0 1rem; }
  .logo { font-size: 2rem; }
}
