:root {
  /* Restrained, flat color palette - Zero purple, zero neon glows */
  --bg-canvas: #0b0d13;
  --bg-surface: #12151e;
  --bg-surface-elevated: #181d29;
  --bg-input: #0e1118;
  --border-line: #1e2433;
  --border-active: #3b82f6;

  /* Typography Colors */
  --text-bright: #f4f4f7;
  --text-muted: #8c96a8;
  --text-tertiary: #586274;

  /* Restrained Accents */
  --accent-primary: #2563eb;
  --accent-primary-hover: #1d4ed8;
  --bubble-self: #1e40af;
  --bubble-peer: #151923;

  /* Functional Status */
  --status-live: #10b981;
  --status-pending: #f59e0b;
  --status-dead: #ef4444;

  /* Radii & Layout Metrics */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, .brand-text h1, .room-code-badge {
  font-family: 'Urbanist', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: -0.015em;
}

body {
  background: var(--bg-canvas);
  color: var(--text-bright);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* SCREEN MANAGEMENT */
.screen {
  display: none;
  width: 100%;
  height: 100%;
}

.screen.active {
  display: flex;
}

.hidden {
  display: none !important;
}

/* ============================================================
   SCREEN 1: LOBBY
============================================================ */
#lobby-screen {
  justify-content: center;
  align-items: center;
  padding: 16px;
  background: var(--bg-canvas);
}

.lobby-panel {
  width: 100%;
  max-width: 360px;
  background: var(--bg-surface);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-bright);
  line-height: 1.2;
}

.tagline {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Segmented Control */
.segmented-control {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

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

.tab-btn.active {
  background: var(--bg-surface-elevated);
  color: var(--text-bright);
}

/* Auth Forms */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
}

.field input {
  background: var(--bg-input);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-bright);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s;
}

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

.field-composite {
  display: flex;
  gap: 6px;
}

.field-composite input {
  flex: 1;
}

.btn-addon {
  background: var(--bg-input);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-addon:hover {
  color: var(--text-bright);
  border-color: var(--text-tertiary);
}

.primary-btn {
  background: var(--accent-primary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: #fff;
  font-size: 0.84rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  margin-top: 4px;
  transition: background 0.15s;
}

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

.primary-btn:focus-visible {
  outline: 2px solid var(--border-active);
  outline-offset: 2px;
}

.lobby-meta {
  text-align: center;
  font-size: 0.69rem;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

/* ============================================================
   SCREEN 2: ACTIVE CHAT
============================================================ */
#chat-screen {
  flex-direction: column;
  background: var(--bg-canvas);
  max-width: 820px;
  border-left: 1px solid var(--border-line);
  border-right: 1px solid var(--border-line);
  position: relative;
}

/* Action Bar */
.chat-header {
  height: 48px;
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
}

.header-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  height: 30px;
  width: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.nav-btn:hover {
  color: var(--text-bright);
  border-color: var(--text-tertiary);
}

.nav-btn.compact {
  height: 24px;
  width: 24px;
  font-size: 0.8rem;
}

.count-pill {
  width: auto;
  padding: 0 8px;
  gap: 5px;
}

.count-pill span {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-bright);
}

.room-descriptor {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.room-identifier {
  display: flex;
  align-items: center;
  gap: 6px;
}

.muted-prefix {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.room-code-badge {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-bright);
}

.btn-text-action {
  background: transparent;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 1px 6px;
  font-size: 0.68rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-text-action:hover {
  color: var(--text-bright);
  border-color: var(--text-tertiary);
}

.telemetry-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.68rem;
  color: var(--text-tertiary);
}

.status-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
}

.status-indicator.live {
  background: var(--status-live);
}

.status-indicator.pending {
  background: var(--status-pending);
}

/* Messages Stream */
.messages-stream {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg-row {
  display: flex;
  gap: 8px;
  max-width: 82%;
}

.msg-row.self {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-row.peer {
  align-self: flex-start;
}

.msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.msg-bubble-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.msg-row.self .msg-bubble-wrap {
  align-items: flex-end;
}

.msg-meta {
  font-size: 0.68rem;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 5px;
}

.msg-bubble {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 0.86rem;
  line-height: 1.42;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-row.self .msg-bubble {
  background: var(--bubble-self);
  color: #fff;
}

.msg-row.peer .msg-bubble {
  background: var(--bubble-peer);
  color: var(--text-bright);
  border: 1px solid var(--border-line);
}

.system-pill {
  align-self: center;
  padding: 3px 10px;
  font-size: 0.68rem;
  color: var(--text-tertiary);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-line);
  margin: 4px 0;
}

/* Composer Footer */
.chat-footer {
  padding: 10px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-line);
}

.composer-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.composer-form input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-bright);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s;
}

.composer-form input:focus {
  border-color: var(--border-active);
}

.btn-send {
  background: var(--accent-primary);
  border: none;
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}

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

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Participants Drawer (Clean, borderless list layout) */
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 20;
}

.participants-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 250px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-line);
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 14px;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-line);
}

.drawer-header h2 {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-bright);
}

.member-list {
  list-style: none;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-bright);
  padding: 3px 0;
}

.member-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.you-tag {
  font-size: 0.64rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-line);
  color: var(--text-muted);
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.toast {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-line);
  color: var(--text-bright);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  animation: toastFade 2.4s forwards;
}

@keyframes toastFade {
  0% { opacity: 0; transform: translateY(-4px); }
  10% { opacity: 1; transform: translateY(0); }
  85% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-4px); }
}
