:root {
  --bg: #0f1117;
  --bg-elevated: #171a23;
  --bg-elevated-2: #1e2230;
  --border: #2a2f3f;
  --text: #e7e9ee;
  --text-dim: #9aa0b0;
  --accent: #7c5cff;
  --accent-2: #5c9dff;
  --bubble-user: #2a3550;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

.hidden { display: none !important; }

/* ---------- Username modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top, #1c2030 0%, #0a0b10 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 32px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal h1 {
  font-size: 1.4rem;
  margin: 0 0 8px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.modal p {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin: 0 0 20px;
}

.modal input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated-2);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 14px;
  outline: none;
}

.modal input:focus {
  border-color: var(--accent);
}

.modal button {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: opacity 0.15s;
}

.modal button:hover { opacity: 0.9; }

.modal-hint {
  margin: 14px 0 0;
  font-size: 0.75rem;
  color: #6b7280;
}

/* ---------- App shell ---------- */

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 10px var(--accent);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.online-count::before {
  content: '●';
  color: #4ade80;
  margin-right: 6px;
}

.my-username {
  padding: 4px 10px;
  background: var(--bg-elevated-2);
  border-radius: 999px;
  border: 1px solid var(--border);
}

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
}

.sidebar h2 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 4px 8px 12px;
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.member {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 0.85rem;
}

.member:hover {
  background: var(--bg-elevated-2);
}

.member-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.member-name {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Chat main ---------- */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 720px;
  animation: msg-in 0.18s ease-out;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  font-weight: 700;
}

.msg-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.msg-name {
  font-weight: 700;
  font-size: 0.88rem;
}

.msg-time {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.msg-bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 13px;
  font-size: 0.92rem;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg.own .msg-bubble {
  background: var(--bubble-user);
}

.msg.system {
  justify-content: center;
}

.msg.system .msg-bubble {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-style: italic;
  padding: 2px;
}

/* ---------- Composer ---------- */

.composer {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.composer input {
  flex: 1;
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated-2);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}

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

.composer button {
  padding: 0 24px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.composer button:hover { opacity: 0.9; }

/* ---------- Scrollbars ---------- */

.messages::-webkit-scrollbar, .sidebar::-webkit-scrollbar {
  width: 8px;
}
.messages::-webkit-scrollbar-thumb, .sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
}

@media (max-width: 720px) {
  .sidebar { display: none; }
}
