:root {
  --bg: #0a0b0f;
  --bg-elev-1: #14161c;
  --bg-elev-2: #1c1f27;
  --bg-elev-3: #262a35;
  --border: #2a2d38;
  --border-strong: #3a3e4b;
  --text: #e8ebf1;
  --text-muted: #8a8f9c;
  --text-faint: #5a5f6b;
  --accent: #5b8def;
  --accent-hover: #4a7ce0;
  --accent-glow: rgba(91, 141, 239, 0.25);
  --host: #b087f5;
  --host-glow: rgba(176, 135, 245, 0.2);
  --speaking: #3fbf6f;
  --speaking-glow: rgba(63, 191, 111, 0.35);
  --danger: #e04646;
  --warning: #ffa13b;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  background-image: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(91, 141, 239, 0.08), transparent 70%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ====== Layout ====== */

.shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

.join-shell {
  max-width: 520px;
  margin: 0 auto;
  padding: 64px 24px 40px;
}

/* ====== Header ====== */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 4px 28px;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.topbar .brand .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.topbar .spacer { flex: 1; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
  background: var(--bg-elev-1);
  color: var(--text-muted);
}
.status-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.status-pill.active { color: var(--speaking); border-color: rgba(63, 191, 111, 0.4); background: rgba(63, 191, 111, 0.08); }
.status-pill.pending { color: var(--warning); border-color: rgba(255, 161, 59, 0.4); background: rgba(255, 161, 59, 0.08); }
.status-pill.ended { color: var(--danger); border-color: rgba(224, 70, 70, 0.4); background: rgba(224, 70, 70, 0.08); }

/* ====== Cards & panels ====== */

.card {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
}

.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 0 0 12px;
}

/* ====== Join form ====== */

.join-header {
  text-align: center;
  margin-bottom: 32px;
}
.join-header h1 {
  font-size: 26px;
  font-weight: 650;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.join-header p {
  color: var(--text-muted);
  margin: 0;
  font-size: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 18px;
}
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

input, select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 120ms, background 120ms;
}
input:hover, select:hover { background: var(--bg-elev-3); }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-elev-2);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ====== Mic preview ====== */

.mic-preview {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
}
.mic-preview .icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-elev-3);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  flex-shrink: 0;
}
.mic-preview.active .icon-wrap { color: var(--speaking); background: rgba(63, 191, 111, 0.12); }
.mic-preview .meter-col { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.mic-preview .meter-label { font-size: 12px; color: var(--text-muted); }

/* ====== VU meter (horizontal) ====== */

.vu {
  width: 100%;
  height: 5px;
  background: var(--bg-elev-3);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.vu > .bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--speaking) 0%, var(--speaking) 70%, var(--warning) 85%, var(--danger) 100%);
  border-radius: 999px;
  transition: width 60ms linear;
}

/* ====== Buttons ====== */

button {
  cursor: pointer;
  border: 0;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-weight: 550;
  letter-spacing: 0.01em;
  transition: background 120ms, transform 60ms, box-shadow 120ms;
}
button:active { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: 0.5; }

.btn-primary {
  background: var(--accent);
  color: white;
  width: 100%;
  padding: 14px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.12) inset, 0 4px 16px var(--accent-glow);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-elev-2); color: var(--text); }

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  display: grid;
  place-items: center;
}
.btn-icon:hover { background: var(--bg-elev-3); }
.btn-icon.active {
  background: var(--bg-elev-3);
  color: var(--accent);
  border-color: var(--accent);
}
.btn-icon.danger {
  background: var(--danger);
  color: white;
  border-color: transparent;
}
.btn-icon.danger:hover { background: #c93e3e; }
.btn-icon.muted {
  background: rgba(224, 70, 70, 0.15);
  color: var(--danger);
  border-color: rgba(224, 70, 70, 0.4);
}

/* ====== Errors / messages ====== */

.toast {
  margin-top: 16px;
  padding: 10px 14px;
  background: rgba(224, 70, 70, 0.08);
  border: 1px solid rgba(224, 70, 70, 0.3);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 13px;
  min-height: 0;
}
.toast:empty { display: none; }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ====== Room: peer grid ====== */

.peers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 8px;
}

.peer {
  position: relative;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: border-color 200ms, box-shadow 300ms;
  min-height: 170px;
}
.peer.is-local { background: linear-gradient(180deg, var(--bg-elev-2), var(--bg-elev-1)); }
.peer.is-speaking {
  border-color: var(--speaking);
  box-shadow: 0 0 0 1px var(--speaking), 0 0 24px var(--speaking-glow);
}

.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg-elev-3);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 18px;
  color: var(--text);
  border: 2px solid var(--border);
  transition: border-color 200ms;
}
.peer.is-host .avatar {
  border-color: var(--host);
  background: linear-gradient(135deg, rgba(176,135,245,0.2), rgba(176,135,245,0.05));
  color: var(--host);
}
.peer.is-speaking .avatar { border-color: var(--speaking); }

.peer .name {
  font-weight: 550;
  font-size: 14px;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.peer .badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--text-muted);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
}
.peer.is-host .badge {
  color: var(--host);
  background: rgba(176,135,245,0.1);
  border-color: rgba(176,135,245,0.3);
}
.peer.is-local .badge {
  color: var(--accent);
  background: rgba(91,141,239,0.1);
  border-color: rgba(91,141,239,0.3);
}

.peer .mic-state {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-elev-2);
  display: grid;
  place-items: center;
  color: var(--text-faint);
}
.peer.is-speaking .mic-state { color: var(--speaking); background: rgba(63,191,111,0.15); }
.peer .mic-state.muted { color: var(--danger); background: rgba(224,70,70,0.12); }

.peer .vu {
  width: 72%;
  height: 3px;
}

/* ====== Bottom control bar ====== */

.controls {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: rgba(20, 22, 28, 0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 10;
}

.controls .sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 2px;
}

/* ====== Settings drawer ====== */

.settings {
  position: fixed;
  top: 0;
  right: -400px;
  width: 380px;
  max-width: 95vw;
  height: 100vh;
  background: var(--bg-elev-1);
  border-left: 1px solid var(--border);
  padding: 32px 24px;
  transition: right 220ms cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
  z-index: 20;
  box-shadow: -8px 0 32px rgba(0,0,0,0.3);
}
.settings.open { right: 0; }

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}
.settings-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.settings-close {
  background: transparent;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  line-height: 0;
}
.settings-close:hover { background: var(--bg-elev-2); color: var(--text); }

.settings-group {
  margin-bottom: 24px;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms;
  z-index: 15;
}
.backdrop.visible { opacity: 1; pointer-events: auto; }

/* ====== Icon helpers ====== */

.icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ====== Animations ====== */

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.pulse-dot::before { animation: pulse-dot 1.8s ease-in-out infinite; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.peer { animation: fade-in 200ms ease-out; }
