/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  --bg:          #0d0d12;
  --surface:     #16161f;
  --surface-2:   #1e1e2a;
  --surface-3:   #26263a;
  --border:      #2a2a3e;
  --accent:      #7b6cff;
  --accent-h:    #9487ff;
  --accent-dim:  #3a2f8a;
  --text:        #e4e4f0;
  --text-muted:  #7878a0;
  --text-dim:    #454560;
  --error:       #ff6b6b;
  --success:     #4edda8;
  --warn:        #ffc46b;
  --radius:      8px;
  --radius-lg:   14px;
  --sidebar-w:   220px;
  --header-h:    56px;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Screens ─────────────────────────────────────────────────────────────── */
.screen {
  display: none;
  height: 100vh;
}
.screen.active { display: flex; }

/* ── Inputs ──────────────────────────────────────────────────────────────── */
input[type="text"],
input[type="password"] {
  display: block;
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(123, 108, 255, 0.15);
}

input::placeholder { color: var(--text-dim); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  display: block;
  width: 100%;
  padding: 0.65rem 1rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover  { background: var(--accent-h); }
.btn-primary:active { transform: scale(0.98); }

.btn-ghost {
  padding: 0.4rem 0.75rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn-sm { padding: 0.3rem 0.6rem; font-size: 12px; }

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
}
.btn-icon:hover { color: var(--accent); background: rgba(123,108,255,0.1); }

/* ── Form field ──────────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.optional {
  color: var(--text-dim);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
}

/* ── Status messages ─────────────────────────────────────────────────────── */
.status-msg {
  min-height: 1.3em;
  font-size: 13px;
  text-align: center;
  padding: 0.25rem 0;
}
.status-msg.error   { color: var(--error); }
.status-msg.success { color: var(--success); }
.status-msg.info    { color: var(--warn); }

/* ── ════════════════════════════════════════════════════════════════════════
   AUTH SCREEN
   ═══════════════════════════════════════════════════════════════════════ */
#auth-screen {
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-logo {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.03em;
  text-align: center;
}

.auth-tagline {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: -0.5rem;
}

.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 0.6rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-pane { display: none; flex-direction: column; gap: 0.75rem; }
.tab-pane.active { display: flex; }

/* ── ════════════════════════════════════════════════════════════════════════
   LOBBY SCREEN
   ═══════════════════════════════════════════════════════════════════════ */
#lobby-screen { flex-direction: column; }

.lobby-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.logo-sm {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.lobby-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.greeting {
  font-size: 13px;
  color: var(--text-muted);
}

.lobby-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  gap: 1rem;
}

.lobby-panels {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1.5rem;
  align-items: start;
  width: 100%;
  max-width: 640px;
}

.lobby-or {
  color: var(--text-dim);
  font-size: 13px;
  padding-top: 2.5rem;
  text-align: center;
  user-select: none;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.panel form { display: flex; flex-direction: column; gap: 0.75rem; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.modal-box h3 { font-size: 15px; }
.modal-actions { display: flex; gap: 0.5rem; }
.modal-actions .btn-primary { flex: 1; }
.modal-actions .btn-ghost   { flex: 1; }

/* ── ════════════════════════════════════════════════════════════════════════
   CHAT SCREEN
   ═══════════════════════════════════════════════════════════════════════ */
#chat-screen { display: none; }
#chat-screen.active { display: flex; }

.chat-layout {
  display: flex;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.chat-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-top {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

.sidebar-room {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
}

.room-code-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.room-code-text {
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Mono', monospace;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--accent);
}

.sidebar-members {
  padding: 0.875rem 1rem;
  flex: 1;
  overflow-y: auto;
}

.members-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.members-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.4rem;
  border-radius: var(--radius);
  font-size: 13px;
  overflow: hidden;
}

.members-list li .presence-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.members-list li .member-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.members-list li.is-self .member-name { color: var(--accent); }

/* Chat main */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scroll-behavior: smooth;
}

/* Messages */
.msg-group {
  display: flex;
  flex-direction: column;
  max-width: 72%;
  gap: 2px;
}
.msg-group.own   { align-self: flex-end;   align-items: flex-end; }
.msg-group.other { align-self: flex-start; align-items: flex-start; }

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  margin-bottom: 1px;
}
.msg-author {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}
.msg-time {
  font-size: 10px;
  color: var(--text-dim);
}

.msg-bubble {
  padding: 0.55rem 0.85rem;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.msg-group.own .msg-bubble {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 4px;
}

/* Consecutive messages from same sender */
.msg-bubble.continues { border-radius: 14px; }
.msg-group.own   .msg-bubble.continues { border-bottom-right-radius: 4px; }
.msg-group.other .msg-bubble.continues { border-bottom-left-radius: 4px; }

.system-msg {
  text-align: center;
  color: var(--text-dim);
  font-size: 11px;
  padding: 0.5rem 0;
  font-style: italic;
  user-select: none;
}

.history-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.5rem 0;
  color: var(--text-dim);
  font-size: 11px;
  font-style: italic;
}
.history-divider::before,
.history-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Message input */
.msg-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.msg-form input {
  flex: 1;
  min-width: 0;
}

.btn-send {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.btn-send:hover  { background: var(--accent-h); }
.btn-send:active { transform: scale(0.95); }

/* ── Typing indicator ────────────────────────────────────────────────────── */
.typing-indicator {
  height: 18px;
  padding: 0 1.5rem;
  font-size: 11px;
  font-style: italic;
  color: var(--text-muted);
  flex-shrink: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ── Scrollbars ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .lobby-panels {
    grid-template-columns: 1fr;
  }
  .lobby-or { padding-top: 0; }

  .chat-sidebar { width: 160px; }
  .room-code-text { font-size: 0.85rem; letter-spacing: 0.1em; }
}
