:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --ink: #12141c;
  --muted: #6b7280;
  --border: #e5e7ee;
  --beam-cyan: #06b6d4;
  --beam-violet: #7c6cf6;
  --beam: linear-gradient(90deg, var(--beam-cyan), var(--beam-violet));
  --danger: #e23b4d;
  --shadow: 0 1px 2px rgba(18, 20, 28, 0.04), 0 12px 32px -12px rgba(18, 20, 28, 0.12);
}

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

html {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

h1, h2 { font-family: 'Space Grotesk', system-ui, sans-serif; }

.screen {
  display: none;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem;
  border-radius: 20px;
  width: min(380px, 90vw);
  text-align: center;
  overflow: hidden;
}

/* signature: a beam of light sweeping the join card on load */
.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: -60%;
  width: 40%;
  height: 100%;
  background: linear-gradient(100deg, transparent, rgba(124, 108, 246, 0.08), rgba(6, 182, 212, 0.14), transparent);
  animation: beam-sweep 2.4s ease-out 0.2s 1;
  pointer-events: none;
}

@keyframes beam-sweep {
  to { left: 130%; }
}

.wordmark {
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 1.5rem;
  background: var(--beam);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.card h2 { margin-bottom: 0.35rem; font-weight: 600; }
.card p { color: var(--muted); margin-bottom: 1rem; font-size: 0.9rem; }

.card label { display: block; text-align: left; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.4rem; font-weight: 500; }

input, select {
  width: 100%;
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font-size: 1.05rem;
  text-align: center;
  letter-spacing: 0.2em;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--beam-violet);
  box-shadow: 0 0 0 3px rgba(124, 108, 246, 0.15);
}

#name-input { text-align: left; letter-spacing: normal; font-size: 0.95rem; }
select { text-align: left; letter-spacing: normal; font-size: 0.95rem; }

button {
  padding: 0.7rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

button:hover { border-color: var(--beam-violet); }
button:active { transform: scale(0.98); }

button.primary {
  background: var(--beam);
  border: none;
  color: #fff;
  width: 100%;
  font-weight: 600;
  box-shadow: 0 8px 20px -8px rgba(124, 108, 246, 0.55);
}
button.primary:hover { filter: brightness(1.05); }

button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger:hover { filter: brightness(1.08); }

button.active-off {
  background: rgba(226, 59, 77, 0.1);
  border-color: var(--danger);
  color: var(--danger);
}

.error { color: var(--danger); margin-top: 0.75rem; font-size: 0.9rem; }
.hidden { display: none; }

/* --- GREEN ROOM --- */
.green-stage {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 0;
  width: min(960px, 95vw);
  height: min(560px, 85vh);
  height: min(560px, 85dvh);
  margin: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 20px;
  overflow: hidden;
}

.preview-pane {
  position: relative;
  background: #000;
  min-width: 0;
  min-height: 0;
}

#preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem;
  background: linear-gradient(to top, rgba(10, 11, 16, 0.65), transparent);
}

.room-chip {
  color: #fff;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  white-space: nowrap;
}
.room-chip strong { letter-spacing: 0.05em; }

.preview-overlay .btn-row button {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
  border-color: rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 0.85rem;
  white-space: nowrap;
}
.preview-overlay .btn-row button:hover { background: rgba(255, 255, 255, 0.22); }
.preview-overlay .btn-row button.active-off {
  background: rgba(226, 59, 77, 0.35);
  border-color: transparent;
  color: #fff;
}

.green-controls {
  padding: 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  text-align: left;
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.green-controls h2 { margin-bottom: 0.5rem; }
.green-controls label { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.btn-row { display: flex; gap: 0.5rem; }
.btn-row button { flex: 1; }

.volume-row { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.25rem; }
.volume-row input[type="range"] { margin: 0; width: 100%; padding: 0; }
#volume-label { min-width: 42px; font-size: 0.85rem; text-align: right; color: var(--muted); }

.mic-level-track {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 0.25rem;
}
#mic-level-bar {
  width: 0%;
  height: 100%;
  background: var(--beam);
  transition: width 0.1s ease;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 4px;
  background: var(--border);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--beam-violet);
  cursor: pointer;
  box-shadow: 0 0 0 4px rgba(124, 108, 246, 0.15);
}

/* --- LIVE CALL SCREEN --- */
#call-room { padding: 1rem; overflow: hidden; }

.call-stage {
  position: relative;
  width: 100%;
  max-width: 1400px;
  height: 100%;
  margin: 0 auto;
}

.video-grid {
  display: grid;
  gap: 0.75rem;
  width: 100%;
  height: 100%;
  min-height: 0;
  /* grid-template-columns/rows set inline per participant count, see updateGrid() in app.js */
}

/* a lone tile left over in the last row spans the full width instead of sitting off to one side */
.video-grid.odd-last .tile:last-child {
  grid-column: span var(--odd-last-span, 1);
  max-width: calc(100% / var(--odd-last-span, 1));
  margin: 0 auto;
  width: 100%;
}

.tile {
  position: relative;
  background: #10121a;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

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

.tile .label {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(18, 20, 28, 0.55);
  backdrop-filter: blur(6px);
  color: #fff;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 2;
}

.call-bar {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.6rem;
  background: rgba(18, 20, 28, 0.55);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  width: max-content;
  z-index: 3;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.call-bar.idle {
  opacity: 0;
  pointer-events: none;
}

.call-bar button {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
  color: #fff;
}
.call-bar button:hover { background: rgba(255, 255, 255, 0.2); }
.call-bar button.active-off { background: rgba(226, 59, 77, 0.4); border-color: transparent; }
.call-bar button.danger { background: var(--danger); border-color: transparent; }
.call-bar button.danger:hover { filter: brightness(1.1); }

/* --- RESPONSIVE MEDIA QUERIES --- */
@media (max-width: 700px) {
  body { overflow: auto; }

  .screen { height: auto; min-height: 100vh; min-height: 100dvh; }

  .green-stage {
    grid-template-columns: 1fr;
    grid-template-rows: 45vh 1fr;
    grid-template-rows: 45dvh 1fr;
    height: auto;
    min-height: 100%;
    margin: 1rem;
  }

  .green-controls { border-left: none; border-top: 1px solid var(--border); }

  #call-room {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .call-stage {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    height: 100%;
    min-height: 0;
  }

  .video-grid {
    flex: 1;
    gap: 0.5rem;
    height: auto;
    min-height: 0;
  }

  .call-bar {
    flex-shrink: 0;
    position: static;
    transform: none;
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
  }

  .call-bar button {
    background: var(--surface);
    border-color: var(--border);
    color: var(--ink);
  }
  .call-bar button:hover { border-color: var(--beam-violet); background: var(--surface); }
  .call-bar button.active-off {
    background: rgba(226, 59, 77, 0.1);
    border-color: var(--danger);
    color: var(--danger);
  }
  .call-bar button.danger { background: var(--danger); color: #fff; }
}

@media (prefers-reduced-motion: reduce) {
  .card::before { animation: none; }
}
