:root {
  --bg: #0b0c10;
  --panel: #1a1d24;
  --panel-2: #242933;
  --fg: #e6e8ec;
  --fg-dim: #9aa3b2;
  --accent: #4c8bf5;
  --danger: #e5484d;
  --speaking: #4ade80;
  --radius: 12px;
  --gap: 8px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

* { box-sizing: border-box; }

/* The HTML [hidden] attribute is display:none in the UA stylesheet,
   but any user rule with display: (e.g. .screen below) has the same
   specificity and wins the cascade. Force [hidden] to stick. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  touch-action: manipulation;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ── Intro screen ────────────────────────────────────────────────── */

#intro {
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 24px) 20px calc(var(--safe-bottom) + 24px);
}

#intro-form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--panel);
  padding: 24px;
  border-radius: var(--radius);
}

#intro-form h1 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 600;
  text-align: center;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--fg-dim);
}

.field input {
  appearance: none;
  background: var(--panel-2);
  border: 1px solid transparent;
  color: var(--fg);
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus {
  border-color: var(--accent);
}

.intro-toggles {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 4px 0;
}

button.toggle,
button.primary,
button.danger {
  font: inherit;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button.toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

button.toggle:active { transform: scale(0.96); }

button.toggle.off {
  background: var(--danger);
  color: #fff;
}

button.toggle .icon { width: 24px; height: 24px; fill: currentColor; }
button.toggle .icon-off { display: none; }
button.toggle.off .icon-on { display: none; }
button.toggle.off .icon-off { display: block; }

button.primary {
  background: var(--accent);
  color: #fff;
  padding: 14px 20px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  margin-top: 4px;
}

button.primary:disabled {
  opacity: 0.6;
  cursor: default;
}

button.danger {
  width: 64px;
  height: 56px;
  border-radius: 28px;
  background: var(--danger);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button.danger .icon { width: 26px; height: 26px; fill: currentColor; }

.error {
  color: var(--danger);
  font-size: 13px;
  margin: 0;
  text-align: center;
}

/* ── Call screen ────────────────────────────────────────────────── */

#call {
  background: var(--bg);
}

.tiles {
  flex: 1 1 auto;
  display: grid;
  gap: var(--gap);
  padding: calc(var(--safe-top) + 8px) 8px 8px;
  min-height: 0;
  grid-auto-rows: 1fr;
  /* Default grid; refined via JS by participant count. */
  grid-template-columns: 1fr;
}

.tiles.count-2 { grid-template-columns: 1fr; grid-auto-rows: 1fr; }
.tiles.count-3, .tiles.count-4 { grid-template-columns: 1fr 1fr; }
.tiles.count-5, .tiles.count-6 { grid-template-columns: 1fr 1fr; }
.tiles.count-7, .tiles.count-8, .tiles.count-9 { grid-template-columns: 1fr 1fr 1fr; }
.tiles.count-many { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

@media (min-width: 700px) and (orientation: landscape) {
  .tiles.count-2 { grid-template-columns: 1fr 1fr; }
  .tiles.count-3 { grid-template-columns: repeat(3, 1fr); }
}

/* Pinned mode: one huge tile, the rest in a filmstrip below. */
.tiles.pinned-mode {
  grid-template-columns: 1fr !important;
  grid-template-rows: 1fr auto;
  grid-auto-rows: unset;
}

.tiles.pinned-mode .tile { display: none; }
.tiles.pinned-mode .tile.pinned { display: block; grid-row: 1; grid-column: 1; }
.tiles.pinned-mode .filmstrip { display: flex; }

.filmstrip {
  display: none;
  grid-row: 2;
  grid-column: 1;
  gap: var(--gap);
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 2px;
  scroll-snap-type: x proximity;
}

.filmstrip .tile {
  display: block !important;
  flex: 0 0 auto;
  width: 120px;
  height: 90px;
  scroll-snap-align: start;
}

.tile {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  min-height: 0;
  min-width: 0;
  outline: 2px solid transparent;
  transition: outline-color 0.15s;
}

.tile.speaking { outline-color: var(--speaking); }
.tile.local .video-el { transform: scaleX(-1); } /* selfie-mirror */

.video-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.video-el {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.video-wrap:empty::after,
.tile.no-video .video-wrap::after {
  content: attr(data-initials);
  font-size: 36px;
  font-weight: 600;
  color: var(--fg-dim);
  background: var(--panel);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.filmstrip .tile .video-wrap:empty::after,
.filmstrip .tile.no-video .video-wrap::after {
  width: 40px;
  height: 40px;
  font-size: 16px;
}

.name {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border-radius: 6px;
  font-size: 12px;
  max-width: calc(100% - 40px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 24px;
  height: 24px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 12px;
  display: none;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.muted-badge.visible { display: inline-flex; }
.muted-badge svg { width: 14px; height: 14px; fill: currentColor; }

#controls {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 12px 12px calc(var(--safe-bottom) + 12px);
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
}

.banner {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  pointer-events: none;
}
