/* ====== CSS RESET & BASE ====== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0f0f14;
  --bg-secondary: #16161e;
  --bg-card: #1a1a26;
  --bg-card-hover: #1f1f2e;
  --bg-input: #13131a;
  --bg-control: #1e1e2a;
  --bg-control-hover: #2a2a3a;
  --border: #2a2a3a;
  --border-light: #333344;
  --text-primary: #e8e8f0;
  --text-secondary: #9898a8;
  --text-muted: #5e5e72;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --danger: #ef4444;
  --danger-hover: #f87171;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.1);
  --warning: #f59e0b;
  --speaking-ring: #22c55e;
  --speaking-pulse: rgba(34, 197, 94, 0.3);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --transition: 0.2s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ====== VIEWS ====== */
.view {
  display: none;
  height: 100%;
  flex-direction: column;
}
.view.active {
  display: flex;
}

/* ====== LOBBY ====== */
.lobby-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  max-width: 440px;
  width: 100%;
  margin: 0 auto;
}

.logo {
  text-align: center;
  margin-bottom: 2.5rem;
}

.logo-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
}

.logo-icon svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 20px var(--accent-glow));
}

.logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo .tagline {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  width: 100%;
  box-shadow: var(--shadow);
}

.card label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.card input[type="text"] {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.card input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.card input[type="text"]::placeholder {
  color: var(--text-muted);
}

.name-section {
  margin-bottom: 1.25rem;
}

.divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.25rem 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ====== BUTTONS ====== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), #8b5cf6);
  box-shadow: 0 4px 20px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1.25rem;
}

.btn-accent:hover {
  background: var(--accent-hover);
}

.btn-full {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.join-section {
  margin-top: 0.25rem;
}

.join-row {
  display: flex;
  gap: 0.5rem;
}

.join-row input {
  flex: 1;
  text-transform: uppercase;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 1.1rem;
  letter-spacing: 0.15em;
  text-align: center;
  font-weight: 600;
}

/* ====== ERROR BANNER ====== */
.error-banner {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--danger-bg);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 0.85rem;
  text-align: center;
  width: 100%;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ====== ROOM VIEW ====== */
.room-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Room Header */
.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.room-header-left,
.room-header-right {
  min-width: 40px;
}

.room-header-left {
  display: flex;
  justify-content: flex-start;
}

.room-header-right {
  display: flex;
  justify-content: flex-end;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--bg-control-hover);
  color: var(--text-primary);
}

.room-code-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.room-code-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.room-code-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1.2rem;
  background: var(--bg-card);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  box-shadow: 0 0 12px var(--accent-glow);
}

.room-code-badge:hover {
  border-color: var(--accent-hover);
  box-shadow: 0 0 20px var(--accent-glow);
  transform: scale(1.02);
}

.room-code-badge:active {
  transform: scale(0.98);
}

.code-label {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.code-value {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--accent);
}

.room-code-badge svg {
  color: var(--accent);
  flex-shrink: 0;
}

/* ====== CONNECTION INFO PANEL ======*/
.connection-info-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0.5rem 0.75rem;
  overflow: hidden;
  transition: all var(--transition);
}

.conn-info-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.conn-info-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.btn-icon-sm {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.btn-icon-sm:hover {
  background: var(--bg-control-hover);
  color: var(--text-primary);
}

.connection-info-list {
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.conn-info-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  padding: 0.35rem 0.5rem;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

.conn-info-name {
  font-weight: 600;
  color: var(--text-primary);
  min-width: 80px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conn-info-type {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  white-space: nowrap;
}

.conn-type-direct {
  background: rgba(74, 222, 128, 0.15);
  color: #4ade80;
}

.conn-type-stun {
  background: rgba(96, 165, 250, 0.15);
  color: #60a5fa;
}

.conn-type-turn {
  background: rgba(251, 146, 60, 0.15);
  color: #fb923c;
}

.conn-type-unknown {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
}

.conn-type-disconnected {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
}

.conn-info-addr {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-left: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

@media (max-width: 480px) {
  .code-value {
    font-size: 1.8rem;
  }
  .room-code-badge {
    padding: 0.75rem 1.5rem;
  }
}

.participant-count {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
}

/* Participants Area */
.participants-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.participants-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  max-width: 800px;
  margin: 0 auto;
}

/* Participant Card */
.participant-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1rem;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.participant-card.speaking {
  border-color: var(--speaking-ring);
  box-shadow: 0 0 20px var(--speaking-pulse), inset 0 0 20px rgba(34, 197, 94, 0.05);
}

.participant-card.speaking::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--speaking-ring), transparent);
  animation: speaking-bar 1.5s ease-in-out infinite;
}

@keyframes speaking-bar {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.participant-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 0.75rem;
  position: relative;
  transition: all var(--transition);
  flex-shrink: 0;
}

.participant-card.speaking .participant-avatar {
  box-shadow: 0 0 0 3px var(--speaking-ring), 0 0 20px var(--speaking-pulse);
  animation: avatar-pulse 1.5s ease-in-out infinite;
}

@keyframes avatar-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.participant-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.participant-status {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.35rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.participant-status .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

.participant-status .status-dot.disconnected {
  background: var(--danger);
}

.participant-status .status-dot.connecting {
  background: var(--warning);
  animation: blink 1s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Muted indicator on avatar */
.mute-indicator {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-card);
}

.mute-indicator svg {
  width: 12px;
  height: 12px;
  color: #fff;
}

/* Connection Bar */
.connection-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.4rem;
  font-size: 0.75rem;
  font-weight: 500;
  flex-shrink: 0;
  transition: all var(--transition);
}

.connection-bar.connecting {
  background: rgba(245, 158, 11, 0.08);
  color: var(--warning);
}

.connection-bar.connected {
  background: rgba(34, 197, 94, 0.08);
  color: var(--success);
}

.connection-bar.disconnected {
  background: rgba(239, 68, 68, 0.08);
  color: var(--danger);
}

.conn-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.connection-bar.connecting .conn-dot {
  animation: blink 1s ease-in-out infinite;
}

/* Room Controls Footer */
.room-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem 1.5rem 1.5rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-control {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.6rem 1.25rem;
  background: var(--bg-control);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  min-width: 70px;
}

.btn-control:hover {
  background: var(--bg-control-hover);
  border-color: var(--border-light);
}

.btn-control.active {
  background: var(--danger-bg);
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--danger);
}

.btn-control.active:hover {
  background: rgba(239, 68, 68, 0.15);
}

.btn-control .btn-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.btn-leave {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.6rem 1.25rem;
  background: var(--danger-bg);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-md);
  color: var(--danger);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  min-width: 70px;
}

.btn-leave:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--danger);
}

.btn-leave .btn-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ====== TOAST NOTIFICATIONS ====== */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  padding: 0.75rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  color: var(--text-primary);
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.7s forwards;
  pointer-events: auto;
  max-width: 320px;
}

.toast.success {
  border-left: 3px solid var(--success);
}

.toast.error {
  border-left: 3px solid var(--danger);
}

.toast.info {
  border-left: 3px solid var(--accent);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(20px); }
}

/* ====== SCROLLBAR ====== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* ====== RESPONSIVE ====== */
@media (max-width: 600px) {
  .lobby-container {
    padding: 1.5rem 1rem;
  }

  .card {
    padding: 1.25rem;
  }

  .participants-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.75rem;
    padding: 0;
  }

  .participants-area {
    padding: 1rem;
  }

  .participant-card {
    padding: 1rem 0.75rem;
  }

  .participant-avatar {
    width: 48px;
    height: 48px;
    font-size: 1.1rem;
  }

  .room-controls {
    gap: 0.5rem;
    padding: 0.75rem 1rem 1rem;
  }

  .btn-control,
  .btn-leave {
    padding: 0.5rem 0.75rem;
    min-width: 56px;
  }
}

@media (max-width: 380px) {
  .participants-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ====== AVATAR COLORS ====== */
.avatar-color-0 { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.avatar-color-1 { background: linear-gradient(135deg, #ec4899, #f43f5e); }
.avatar-color-2 { background: linear-gradient(135deg, #14b8a6, #06b6d4); }
.avatar-color-3 { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.avatar-color-4 { background: linear-gradient(135deg, #22c55e, #84cc16); }
.avatar-color-5 { background: linear-gradient(135deg, #3b82f6, #6366f1); }
.avatar-color-6 { background: linear-gradient(135deg, #a855f7, #ec4899); }
.avatar-color-7 { background: linear-gradient(135deg, #06b6d4, #22c55e); }
