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

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --border: #333;
  --text: #eee;
  --text-muted: #888;
  --accent: #4a9eff;
  --accent-hover: #3a8eef;
  --danger: #e54;
  --danger-hover: #d43;
  --radius: 10px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Landing Page ---------- */

.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 1.5rem 1.5rem env(safe-area-inset-bottom, 1.5rem);
  gap: 1.25rem;
}

.landing h1 {
  font-size: 1.75rem;
  font-weight: 700;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-appearance: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  max-width: 320px;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #252525; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  padding: 0;
  font-size: 1.4rem;
}

.divider {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 320px;
  gap: 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.join-form {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  max-width: 320px;
}

.join-form input {
  flex: 1;
  min-width: 0;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  text-align: center;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  outline: none;
}
.join-form input:focus {
  border-color: var(--accent);
}

/* ---------- Room Page ---------- */

.room {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.room-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 15;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  border: none;
  color: var(--text);
}

.room-code {
  font-weight: 700;
  letter-spacing: 0.1em;
}

/* ---------- Video Grid ---------- */

.video-grid {
  position: relative;
  flex: 1;
  display: grid;
  gap: 4px;
  padding: 4px;
  background: var(--bg);
  min-height: 0;
}

/* Adaptive grid based on participant count */
.video-grid[data-count="1"] {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.video-grid[data-count="2"] {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 1fr;
}

.video-grid[data-count="3"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}
.video-grid[data-count="3"] .video-container:first-child {
  grid-column: 1 / -1;
}

.video-grid[data-count="4"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

/* Landscape orientation: side by side for 2 */
@media (orientation: landscape) {
  .video-grid[data-count="2"] {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
  }
}

.video-container {
  position: relative;
  background: #111;
  border-radius: 8px;
  overflow: hidden;
  min-height: 0;
}

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

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

.video-label {
  position: absolute;
  bottom: 6px;
  left: 8px;
  font-size: 0.75rem;
  background: rgba(0,0,0,0.6);
  padding: 2px 8px;
  border-radius: 4px;
}

.video-muted-icon {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 1rem;
  background: rgba(0,0,0,0.6);
  padding: 2px 6px;
  border-radius: 4px;
  display: none;
}

/* ---------- Controls Bar ---------- */

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.75rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.controls .btn-icon.active {
  background: var(--accent);
}

.controls .btn-icon.muted {
  background: #555;
}

/* ---------- Status messages ---------- */

.status-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 10;
  font-size: 1.1rem;
  color: var(--text-muted);
}

.status-overlay.hidden { display: none; }

/* ---------- Utility ---------- */

.hidden { display: none !important; }

/* Safe area for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
  .controls {
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
  }
  .room-header {
    padding-top: calc(0.5rem + env(safe-area-inset-top));
  }
}
