:root {
  --bg: #11141c;
  --surface: #181d28;
  --surface-2: #222938;
  --surface-3: #2c3547;
  --accent: #e8a33d;
  --accent-hover: #f5b452;
  --accent-soft: rgba(232, 163, 61, 0.18);
  --accent-glow: rgba(232, 163, 61, 0.4);
  --accent-2: #4fd1c5;
  --text: #f4f2ed;
  --text-muted: #8b95ab;
  --danger: #e0645f;
  --danger-hover: #ea7a76;
  --border: #2d3648;
  --border-focus: #e8a33d;
  --display-font: 'Fraunces', Georgia, serif;
  --body-font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body-font);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Lobby ---------- */

.lobby {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(700px 450px at 50% 115%, rgba(232, 163, 61, 0.12), transparent),
    radial-gradient(500px 300px at 20% 10%, rgba(79, 209, 197, 0.05), transparent),
    var(--bg);
}

.ember {
  position: absolute;
  width: 520px;
  height: 520px;
  left: 50%;
  top: 60%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, var(--accent-soft) 0%, transparent 70%);
  filter: blur(20px);
  animation: emberPulse 7s ease-in-out infinite;
  pointer-events: none;
}

@keyframes emberPulse {
  0%, 100% { opacity: 0.5; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 0.9; transform: translate(-50%, -50%) scale(1.1); }
}

.lobby-card {
  position: relative;
  width: 100%;
  max-width: 450px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.logo-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(232, 163, 61, 0.2), rgba(232, 163, 61, 0.05));
  border: 1px solid rgba(232, 163, 61, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.logo-icon svg {
  width: 24px;
  height: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.lobby-card h1 {
  font-family: var(--display-font);
  font-weight: 500;
  font-size: 24px;
  line-height: 1.2;
  margin: 0;
}

/* ---------- Tabs Navigation ---------- */

.tab-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 22px;
  border: 1px solid var(--border);
}

.tab-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.tab-btn svg {
  width: 16px;
  height: 16px;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* ---------- Form Controls ---------- */

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin: 0 0 8px;
}

.text-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  margin-bottom: 18px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.text-input::placeholder { color: #576077; }

.room-input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.room-input-group .text-input {
  margin-bottom: 0;
  flex: 1;
}

/* ---------- Mode Selector Cards ---------- */

.mode-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 22px;
}

.mode-option {
  cursor: pointer;
}

.mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s ease;
  text-align: center;
}

.mode-card svg {
  width: 22px;
  height: 22px;
  color: var(--text-muted);
  transition: color 0.2s ease;
}

.mode-option:hover .mode-card {
  border-color: #434d65;
  color: var(--text);
}

.mode-option input:checked + .mode-card {
  border-color: var(--accent);
  background: rgba(232, 163, 61, 0.08);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.mode-option input:checked + .mode-card svg {
  color: var(--accent);
}

/* ---------- Buttons ---------- */

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 14.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:active { transform: scale(0.98); }

.btn-large {
  width: 100%;
  padding: 13px 20px;
  font-size: 15px;
}

.btn-primary {
  background: var(--accent);
  color: #161108;
}
.btn-primary:hover { background: var(--accent-hover); }

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

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

.btn-icon {
  padding: 0 14px;
}
.btn-icon svg { width: 16px; height: 16px; }

.btn-switch {
  width: 100%;
  margin-top: 10px;
  font-size: 13px;
  padding: 10px;
}

/* ---------- Invite Banner ---------- */

.invite-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(79, 209, 197, 0.08);
  border: 1px solid rgba(79, 209, 197, 0.25);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
}

.invite-icon {
  font-size: 24px;
}

.invite-title {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.invite-room-code {
  margin: 2px 0 0;
  font-family: var(--display-font);
  font-size: 17px;
  color: var(--accent-2);
  font-weight: 600;
}

.lobby-error {
  margin: 16px 0 0;
  font-size: 13.5px;
  color: var(--danger);
  background: rgba(224, 100, 95, 0.1);
  border: 1px solid rgba(224, 100, 95, 0.25);
  padding: 10px 14px;
  border-radius: 8px;
  text-align: center;
}

/* ---------- Call Screen ---------- */

.call-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.call-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: 12px;
  flex-wrap: wrap;
}

.room-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.2);
}

.room-label {
  font-family: var(--display-font);
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
}

.participant-badge {
  font-size: 12.5px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 20px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions .btn {
  padding: 8px 14px;
  font-size: 13px;
}
.header-actions .btn svg {
  width: 15px;
  height: 15px;
}

/* ---------- Video & Voice Grid ---------- */

.video-grid {
  flex: 1;
  display: grid;
  gap: 14px;
  padding: 18px;
  grid-template-columns: repeat(1, 1fr);
  align-content: center;
}

.video-grid[data-count="2"] { grid-template-columns: repeat(2, 1fr); }
.video-grid[data-count="3"],
.video-grid[data-count="4"] { grid-template-columns: repeat(2, 1fr); }
.video-grid[data-count="5"],
.video-grid[data-count="6"] { grid-template-columns: repeat(3, 1fr); }

.tile {
  position: relative;
  background: var(--surface);
  border-radius: 16px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.2s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.tile.speaking {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 0 20px 2px var(--accent-glow);
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #000;
}

.tile.is-screen video {
  display: block !important;
  transform: none !important; /* don't mirror screen shares */
  object-fit: contain;
}

.tile.is-screen .voice-avatar-wrapper {
  display: none !important;
}

/* Voice & Camera Off Avatar */
.voice-avatar-wrapper {
  position: absolute;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, var(--surface-2) 0%, var(--surface) 100%);
  pointer-events: none;
}

.tile.no-video .voice-avatar-wrapper,
.tile.voice-only .voice-avatar-wrapper {
  display: flex;
}

.tile.no-video video,
.tile.voice-only video {
  display: none;
}

.avatar-circle {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2d374d, #1c2333);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--display-font);
  font-size: 32px;
  font-weight: 600;
  color: var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  position: relative;
  z-index: 2;
}

.avatar-ripple {
  position: absolute;
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.25s ease;
  z-index: 1;
}

.tile.speaking .avatar-ripple {
  animation: ripplePulse 1.5s cubic-bezier(0.1, 0.8, 0.3, 1) infinite;
}

@keyframes ripplePulse {
  0% { transform: scale(0.9); opacity: 0.8; }
  100% { transform: scale(1.6); opacity: 0; }
}

.audio-waves {
  display: flex;
  gap: 4px;
  margin-top: 14px;
  height: 16px;
  align-items: center;
}

.audio-waves span {
  width: 3px;
  height: 4px;
  background: var(--text-muted);
  border-radius: 2px;
  transition: height 0.15s ease, background 0.2s ease;
}

.tile.speaking .audio-waves span {
  background: var(--accent);
  animation: wavePulse 0.8s ease-in-out infinite alternate;
}

.tile.speaking .audio-waves span:nth-child(1) { animation-delay: 0.1s; height: 14px; }
.tile.speaking .audio-waves span:nth-child(2) { animation-delay: 0.3s; height: 18px; }
.tile.speaking .audio-waves span:nth-child(3) { animation-delay: 0.2s; height: 16px; }
.tile.speaking .audio-waves span:nth-child(4) { animation-delay: 0.4s; height: 10px; }

@keyframes wavePulse {
  0% { transform: scaleY(0.4); }
  100% { transform: scaleY(1.4); }
}

/* Tile bottom bar */
.tile-bottom {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  z-index: 3;
}

.tile-name {
  background: rgba(15, 18, 26, 0.75);
  backdrop-filter: blur(8px);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.08);
  max-width: 75%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-status-icons {
  display: flex;
  gap: 6px;
}

.tile-badge-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(15, 18, 26, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: none;
  align-items: center;
  justify-content: center;
}

.tile-badge-icon svg { width: 14px; height: 14px; color: var(--danger); }

.tile.muted .badge-muted { display: flex; }
.tile.cam-off .badge-cam-off { display: flex; }

/* ---------- Controls Footer ---------- */

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

.control-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.control-btn svg { width: 22px; height: 22px; }
.control-btn:hover { border-color: var(--accent); background: var(--surface-3); }

.control-btn.active {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}
.control-btn.active:hover { background: var(--danger-hover); }

.control-btn.screen-active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #0d2824;
}

.control-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}
.control-danger:hover { background: var(--danger-hover); }

/* ---------- Toast Notifications ---------- */

.toast-container {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  background: rgba(24, 29, 40, 0.95);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 13.5px;
  font-weight: 500;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.25s ease-out forwards;
}

.toast.toast-out {
  animation: toastOut 0.25s ease-in forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-8px) scale(0.95); }
}

/* ---------- Responsive Styles ---------- */

@media (max-width: 640px) {
  .lobby { padding: 16px; }
  .lobby-card { padding: 24px 18px; }
  .call-header { padding: 10px 14px; }
  .room-label { font-size: 16px; }
  .controls { gap: 10px; padding: 12px; }
  .control-btn { width: 46px; height: 46px; }
  .control-btn svg { width: 19px; height: 19px; }
  
  .video-grid[data-count="3"],
  .video-grid[data-count="4"],
  .video-grid[data-count="5"],
  .video-grid[data-count="6"] {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ember, .avatar-ripple, .audio-waves span { animation: none !important; }
  .tile { transition: none; }
}
