/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0d1a;
  --bg2: #13132b;
  --bg3: #1a1a35;
  --bg4: #20204a;
  --accent: #7c3aed;
  --accent2: #a855f7;
  --accent3: #c084fc;
  --gold: #f59e0b;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #2d2d5e;
  --msg-mine: #4c1d95;
  --msg-other: #1e1e3f;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(124,58,237,.25);
  --font: 'Segoe UI', system-ui, sans-serif;
  --sidebar-w: 270px;
}

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); overflow: hidden; }

/* ===== SCREENS ===== */
.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: flex; }

/* ===== AUTH ===== */
#auth-screen {
  align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, #2d1b6b 0%, #0d0d1a 60%);
  position: relative; overflow: hidden;
}
#auth-screen::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%237c3aed' fill-opacity='0.07'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.auth-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 20px;
  padding: 2.5rem 2rem; width: 100%; max-width: 420px; position: relative; z-index: 1;
  box-shadow: 0 8px 48px rgba(124,58,237,.35), 0 0 0 1px rgba(168,85,247,.15);
  max-height: calc(100vh - 2rem); overflow-y: auto;
}
.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.logo-icon { font-size: 3rem; display: block; margin-bottom: .5rem; filter: drop-shadow(0 0 12px #a855f7); }
.auth-logo h1 { font-size: 2rem; font-weight: 800; letter-spacing: -1px; background: linear-gradient(135deg, #a855f7, #f59e0b); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.logo-dot { -webkit-text-fill-color: var(--gold); }
.tagline { color: var(--text-muted); font-size: .85rem; margin-top: .25rem; }

.auth-tabs { display: flex; gap: .5rem; margin-bottom: 1.25rem; background: var(--bg3); border-radius: var(--radius-sm); padding: 4px; }
.tab-btn { flex: 1; padding: .5rem; border: none; background: transparent; color: var(--text-muted); border-radius: 6px; cursor: pointer; font-size: .9rem; transition: all .2s; }
.tab-btn.active { background: var(--accent); color: #fff; font-weight: 600; box-shadow: 0 2px 8px rgba(124,58,237,.4); }

.auth-form { display: none; flex-direction: column; gap: .75rem; }
.auth-form.active { display: flex; }
.auth-form input { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .7rem 1rem; color: var(--text); font-size: .95rem; outline: none; transition: border .2s; }
.auth-form input:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(168,85,247,.15); }

.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border: none; border-radius: var(--radius-sm); padding: .75rem; font-size: 1rem; font-weight: 700; cursor: pointer; transition: transform .15s, box-shadow .15s; box-shadow: var(--shadow); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(124,58,237,.4); }
.btn-primary:active { transform: translateY(0); }

.auth-error { color: var(--red); font-size: .82rem; min-height: 1em; text-align: center; }
.auth-subtitle { text-align: center; color: var(--text-muted); font-size: .88rem; margin: -.5rem 0 1rem; }
.oauth-btns { display: flex; flex-direction: column; gap: .65rem; }
.btn-microsoft { background: var(--bg3); color: var(--text); }
.btn-microsoft:hover { background: rgba(255,255,255,.08); }
.avatar-picker-row label { font-size: .82rem; color: var(--text-muted); margin-bottom: .25rem; display: block; }
.avatar-options { display: flex; flex-wrap: wrap; gap: .4rem; }
.avatar-opt { font-size: 1.5rem; cursor: pointer; padding: .2rem .3rem; border-radius: 6px; border: 2px solid transparent; transition: border .15s; }
.avatar-opt.selected { border-color: var(--accent2); background: rgba(168,85,247,.15); }

/* ===== APP LAYOUT ===== */
#app-screen { flex-direction: row; height: 100vh; overflow: hidden; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  transition: transform .3s; z-index: 10;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .65rem 1rem; border-bottom: 1px solid var(--border); background: var(--bg3);
  min-height: 52px; flex-shrink: 0;
}
.logo-small { font-weight: 800; font-size: 1.05rem; background: linear-gradient(135deg, #a855f7, #f59e0b); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

.me-card { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border); background: rgba(124,58,237,.08); flex-shrink: 0; }
.me-avatar-btn { position: relative; background: none; border: none; cursor: pointer; padding: 0; border-radius: 50%; transition: transform .15s; flex-shrink: 0; }
.me-avatar-btn:hover { transform: scale(1.1); }
.me-avatar-btn:hover .me-avatar-edit { opacity: 1; }
.me-avatar { font-size: 1.8rem; display: block; line-height: 1; }
.me-avatar-edit { position: absolute; bottom: -2px; right: -4px; font-size: .65rem; background: var(--accent); border-radius: 50%; width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .15s; pointer-events: none; }
.me-info .me-name { font-weight: 700; font-size: .93rem; }
.me-name-row { display: flex; align-items: center; gap: .25rem; }
.me-name-edit-btn { font-size: .65rem; padding: .15rem .2rem; opacity: 0; transition: opacity .15s; }
.me-card:hover .me-name-edit-btn { opacity: 1; }
.me-info .me-status { font-size: .73rem; color: var(--green); margin-top: 1px; }
.rename-hint { font-size: .74rem; color: var(--text-muted); margin: -.25rem 0 .25rem; }
.rename-error { font-size: .78rem; color: var(--red); min-height: 1.1em; }

/* Sidebar Tabs */
.sidebar-tabs { display: flex; background: var(--bg3); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.stab { flex: 1; padding: .6rem; background: none; border: none; color: var(--text-muted); font-size: .85rem; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; transition: color .2s, border-color .2s; position: relative; }
.stab.active { color: var(--accent3); border-color: var(--accent2); }
.stab-badge { background: var(--red); color: #fff; font-size: .6rem; font-weight: 700; border-radius: 999px; padding: 1px 4px; position: absolute; top: 5px; right: 16px; min-width: 16px; text-align: center; }
.stab-badge.hidden { display: none; }

.stab-panel { display: none; flex: 1; overflow-y: auto; flex-direction: column; }
.stab-panel.active { display: flex; }

/* ── Room Browser ── */
.room-search-wrap { padding: .5rem .75rem .3rem; flex-shrink: 0; }
.room-search-wrap input {
  width: 100%; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .45rem .75rem; color: var(--text); font-size: .83rem; outline: none; transition: border .2s;
}
.room-search-wrap input:focus { border-color: var(--accent2); }
.rb-section-label { font-size: .68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; padding: .5rem .9rem .2rem; }
.rb-recent-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .4rem .9rem .4rem 1rem; cursor: pointer; font-size: .84rem;
  transition: background .15s; color: var(--text-muted);
}
.rb-recent-item:hover { background: rgba(124,58,237,.15); color: var(--text); }
.rb-recent-cat { font-size: .7rem; color: var(--text-muted); margin-left: auto; white-space: nowrap; flex-shrink: 0; }
.rb-star-btn { background: none; border: none; cursor: pointer; font-size: .9rem; color: var(--text-muted); padding: 2px 4px; border-radius: 4px; transition: color .15s, opacity .15s; opacity: 0; flex-shrink: 0; }
.rb-recent-item:hover .rb-star-btn { opacity: 1; }
.rb-star-btn.active { color: var(--gold); opacity: 1; }
.rb-star-btn:hover { color: var(--gold); opacity: 1 !important; }
#topbar-star-btn { font-size: 1rem; color: var(--text-muted); opacity: 1; }
#topbar-star-btn.active { color: var(--gold); }
.topbar-leave-btn { font-size: .85rem; color: var(--text-muted); }
.topbar-leave-btn:hover { color: var(--red) !important; background: rgba(239,68,68,.12) !important; }
#favorite-rooms-section { border-bottom: 1px solid var(--border); padding-bottom: .25rem; margin-bottom: .25rem; }
#recent-rooms-section { border-bottom: 1px solid var(--border); padding-bottom: .25rem; margin-bottom: .25rem; }
#room-browser { display: flex; flex-direction: column; padding: .5rem 0; }
.rb-category { border-bottom: 1px solid var(--border); }
.rb-cat-header {
  display: flex; align-items: center; gap: .5rem;
  padding: .55rem .9rem; cursor: pointer; transition: background .15s; font-size: .88rem;
  user-select: none;
}
.rb-cat-header:hover { background: rgba(124,58,237,.15); }
.rb-cat-icon { font-size: 1rem; width: 20px; text-align: center; }
.rb-cat-name { flex: 1; font-weight: 600; }
.rb-cat-count { font-size: .72rem; color: var(--green); background: rgba(34,197,94,.12); border-radius: 999px; padding: 1px 6px; }
.rb-cat-arrow { font-size: .65rem; color: var(--text-muted); transition: transform .2s; }
.rb-category.open .rb-cat-arrow { transform: rotate(90deg); }
.rb-subs { display: none; padding-left: 0; }
.rb-category.open .rb-subs { display: block; }
.rb-sub-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem .9rem .45rem 2.1rem; cursor: pointer; font-size: .84rem;
  transition: background .15s; color: var(--text-muted);
}
.rb-sub-item:hover { background: rgba(124,58,237,.15); color: var(--text); }
.rb-sub-item.active { background: rgba(124,58,237,.25); color: var(--accent3); }
.rb-sub-icon { font-size: .9rem; }
.rb-sub-name { flex: 1; }
.rb-sub-count { font-size: .7rem; color: var(--green); }

/* Friends tab */
.friend-panel-actions { padding: .6rem .8rem; flex-shrink: 0; }
.friend-list { list-style: none; padding: 0 0 .5rem; }
.friend-list li {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem 1rem; cursor: pointer; transition: background .15s; font-size: .88rem;
}
.friend-list li:hover { background: rgba(124,58,237,.18); }
.friend-list li.active { background: rgba(124,58,237,.3); }
.friend-avatar { font-size: 1.3rem; }
.friend-info { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.friend-name { font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friend-meta { font-size: .7rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friend-status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.friend-status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.unread-badge { background: var(--red); color: #fff; font-size: .65rem; font-weight: 700; border-radius: 999px; padding: 1px 5px; min-width: 18px; text-align: center; }
.friend-unfriend-btn { opacity: 0; background: none; border: none; color: var(--red); font-size: .7rem; cursor: pointer; padding: 2px 6px; border-radius: 4px; transition: opacity .15s, background .15s; flex-shrink: 0; }
.friend-list li:hover .friend-unfriend-btn { opacity: 1; }
.friend-unfriend-btn:hover { background: rgba(239,68,68,.15); }
.friend-info-btn { opacity: 0; background: none; border: none; color: var(--accent3); font-size: .7rem; cursor: pointer; padding: 2px 6px; border-radius: 4px; transition: opacity .15s; flex-shrink: 0; }
.friend-list li:hover .friend-info-btn { opacity: 1; }
.friend-info-btn:hover { background: rgba(124,58,237,.15); }
.friend-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

.friend-requests-banner {
  margin: 4px 8px; background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.3);
  border-radius: var(--radius-sm); padding: .5rem .75rem; font-size: .82rem;
  cursor: pointer; color: var(--gold); transition: background .15s;
}
.friend-requests-banner:hover { background: rgba(245,158,11,.22); }
.friend-requests-banner.hidden { display: none; }

/* ===== MAIN AREA ===== */
.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem 1rem; background: var(--bg2); border-bottom: 1px solid var(--border);
  min-height: 52px; flex-shrink: 0;
}
.breadcrumb { display: flex; align-items: center; gap: .4rem; flex: 1; flex-wrap: wrap; overflow: hidden; }
.bc-item { font-size: .82rem; color: var(--text-muted); cursor: pointer; padding: .2rem .4rem; border-radius: 4px; white-space: nowrap; transition: color .15s; }
.bc-item:hover { color: var(--accent3); }
.bc-item.bc-current { color: var(--text); font-weight: 600; cursor: default; }
.bc-sep { color: var(--border); font-size: .75rem; }
.bc-home { color: var(--accent3) !important; }
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.online-pill { background: rgba(34,197,94,.15); border: 1px solid rgba(34,197,94,.3); color: var(--green); font-size: .72rem; font-weight: 700; border-radius: 999px; padding: .2rem .65rem; white-space: nowrap; }

/* ===== VIEWS ===== */
.view { display: none; flex: 1; overflow-y: auto; flex-direction: column; }
.view.active { display: flex; }
.view::-webkit-scrollbar { width: 6px; }
.view::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.view-header { padding: 1.25rem 1.5rem .75rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.view-header h2 { font-size: 1.15rem; margin-bottom: .2rem; }
.view-header p { font-size: .82rem; color: var(--text-muted); }

/* ── Lobby / Category Grid ── */
.lobby-header {
  text-align: center; padding: 1.5rem 1.5rem 1.25rem;
  background: radial-gradient(ellipse at 50% 0%, rgba(124,58,237,.2) 0%, transparent 70%);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.lobby-logo { font-size: 3rem; margin-bottom: .75rem; filter: drop-shadow(0 0 16px #a855f7); }
.lobby-header h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: .5rem; }
.lobby-header p { color: var(--text-muted); font-size: .9rem; margin-bottom: 1rem; }
.grad-text { background: linear-gradient(135deg, #a855f7, #f59e0b); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

/* Lobby two-column body */
.lobby-body {
  display: flex; flex: 1; min-height: 0; overflow: hidden;
}
.lobby-friends-panel {
  width: 240px; flex-shrink: 0; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.lobby-rooms-panel {
  flex: 1; overflow-y: auto; min-width: 0;
}
.lobby-panel-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem; min-height: 40px; font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.lobby-room-search {
  flex: 1; background: var(--bg1); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: .82rem; padding: .25rem .6rem;
  margin-left: .75rem; outline: none; min-width: 0;
}
.lobby-room-search:focus { border-color: var(--accent); }
.lobby-room-search::placeholder { color: var(--text-muted); }
.lobby-search-results { padding: .75rem 1.25rem; display: flex; flex-direction: column; gap: .4rem; }
.lobby-search-result-item {
  display: flex; align-items: center; gap: .5rem; padding: .45rem .75rem;
  border-radius: 6px; cursor: pointer; font-size: .86rem;
  background: var(--bg2); border: 1px solid var(--border); transition: border-color .15s;
}
.lobby-search-result-item:hover { border-color: var(--accent); }
.lobby-search-result-icon { font-size: 1.1rem; }
.lobby-search-result-name { flex: 1; font-weight: 600; }
.lobby-search-result-cat { font-size: .73rem; color: var(--text-muted); }
.lobby-search-result-count { font-size: .73rem; color: var(--green); }
.lobby-search-results.hidden { display: none; }
#category-grid.hidden { display: none; }
/* Lobby DM panel — row list (same structure as sidebar) */
.lobby-friends-panel .friend-list {
  flex: 1; overflow-y: auto; padding: .3rem 0;
}
.lobby-friends-panel .friend-list li {
  padding: .5rem .9rem;
}
.lobby-friends-panel .friend-list li:hover { background: rgba(124,58,237,.18); }
.lobby-friends-panel .friend-list li.active { background: rgba(124,58,237,.28); }
/* Non-friend DM contact: subtle amber tint */
.lobby-friends-panel .friend-list li.lobby-dm-nonfriend,
.friend-list li.dm-nonfriend { border-left: 2px solid rgba(245,158,11,.5); }
.lobby-friends-panel .friend-list li.lobby-dm-nonfriend .friend-name,
.friend-list li.dm-nonfriend .friend-name { color: rgba(245,158,11,.9); }
.lobby-friends-panel .friend-list li.lobby-dm-nonfriend .friend-meta,
.friend-list li.dm-nonfriend .friend-meta { color: rgba(245,158,11,.6); }
@media (max-width: 720px) {
  .lobby-body { flex-direction: column; overflow-y: auto; }
  .lobby-friends-panel { width: 100%; border-right: none; border-bottom: 1px solid var(--border); max-height: 240px; }
}

.category-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem; padding: 1.25rem 1.5rem;
}
.cat-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem 1rem; cursor: pointer; transition: transform .2s, border-color .2s, box-shadow .2s;
  text-align: center;
}
.cat-card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 8px 24px rgba(124,58,237,.25); }
.cat-card-icon { font-size: 2rem; margin-bottom: .5rem; display: block; }
.cat-card-name { font-size: .92rem; font-weight: 700; margin-bottom: .25rem; }
.cat-card-count { font-size: .75rem; color: var(--green); }
.cat-card-subs { font-size: .72rem; color: var(--text-muted); margin-top: .2rem; }

/* ── Subcategory Grid ── */
.subcat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .85rem; padding: 1.25rem 1.5rem; }
.subcat-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 1rem; cursor: pointer; transition: transform .15s, border-color .2s;
  display: flex; flex-direction: column; align-items: center; gap: .4rem; text-align: center;
}
.subcat-card:hover { transform: translateY(-2px); border-color: var(--accent2); }
.subcat-card-icon { font-size: 1.6rem; }
.subcat-card-name { font-size: .88rem; font-weight: 600; }
.subcat-card-count { font-size: .72rem; color: var(--green); }

/* ── Room Table ── */
.room-table-wrap { padding: 1rem 1.5rem; overflow-x: auto; }
.room-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.room-table th { text-align: left; padding: .5rem .75rem; color: var(--text-muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--border); }
.room-table td { padding: .6rem .75rem; border-bottom: 1px solid rgba(45,45,94,.5); vertical-align: middle; }
.room-table tr:hover td { background: rgba(124,58,237,.08); cursor: pointer; }
.room-name-cell { display: flex; align-items: center; gap: .5rem; }
.room-num-badge { background: var(--bg4); border: 1px solid var(--border); border-radius: 6px; padding: .15rem .45rem; font-size: .75rem; font-weight: 700; color: var(--text-muted); }
.room-overflow-tag { font-size: .68rem; background: rgba(245,158,11,.15); color: var(--gold); border-radius: 999px; padding: 1px 6px; }
.status-open { color: var(--green); font-size: .78rem; }
.status-full { color: var(--red); font-size: .78rem; }
.btn-enter { background: var(--accent); color: #fff; border: none; border-radius: 6px; padding: .3rem .75rem; font-size: .8rem; font-weight: 700; cursor: pointer; transition: opacity .15s; }
.btn-enter:hover { opacity: .85; }
.btn-enter.full { background: var(--bg4); color: var(--text-muted); }

/* ── Chat View ── */
#view-chat { overflow: hidden; display: none; flex-direction: column; }
#view-chat.active { display: flex; }
.messages-area {
  flex: 1; overflow-y: auto; padding: .85rem 1rem; display: flex; flex-direction: column;
  gap: .5rem; scroll-behavior: smooth;
}
.messages-area::-webkit-scrollbar { width: 6px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.msg { display: flex; align-items: flex-start; gap: .6rem; max-width: 75%; animation: fadeUp .2s ease; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg.system { align-self: center; max-width: 100%; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.msg-avatar { font-size: 1.4rem; flex-shrink: 0; margin-top: 2px; }
.msg-bubble { background: var(--msg-other); border-radius: 0 var(--radius) var(--radius) var(--radius); padding: .5rem .85rem; max-width: 100%; }
.msg.mine .msg-bubble { background: var(--msg-mine); border-radius: var(--radius) 0 var(--radius) var(--radius); box-shadow: 0 2px 8px rgba(124,58,237,.3); }
.msg-header { display: flex; align-items: baseline; gap: .5rem; margin-bottom: .15rem; }
.msg-name { font-size: .75rem; font-weight: 700; color: var(--accent3); }
.msg.mine .msg-name { color: var(--gold); }
.msg-time { font-size: .65rem; color: var(--text-muted); }
.msg-text { font-size: .9rem; line-height: 1.5; word-break: break-word; }
.msg-link { color: var(--accent3); text-decoration: underline; word-break: break-all; }
.msg-link:hover { color: #fff; }
.system-msg { background: rgba(124,58,237,.1); border: 1px solid rgba(124,58,237,.2); border-radius: 999px; padding: .3rem 1rem; font-size: .75rem; color: var(--text-muted); text-align: center; }

/* Reply bar above input */
.reply-bar { display: flex; align-items: center; gap: .5rem; padding: .3rem .75rem; background: rgba(124,58,237,.12); border-left: 3px solid var(--accent2); margin-bottom: .35rem; min-width: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.reply-bar.hidden { display: none; }
.reply-bar-label { font-size: .74rem; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.reply-bar-label strong { color: var(--accent3); }
.reply-to-snippet { font-size: .74rem; color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.reply-cancel { font-size: .7rem; flex-shrink: 0; }
/* Reply quote bubble inside a message */
.reply-quote { background: rgba(0,0,0,.25); border-left: 3px solid var(--accent2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: .25rem .55rem; margin-bottom: .35rem; cursor: pointer; transition: background .15s; }
.reply-quote:hover { background: rgba(168,85,247,.2); }
.msg.highlight-flash { animation: flashHighlight .5s ease 2; }
@keyframes flashHighlight { 0%,100% { box-shadow: none; } 50% { box-shadow: 0 0 0 3px var(--accent2); border-radius: var(--radius); } }
.reply-quote-name { font-size: .68rem; font-weight: 700; color: var(--accent3); display: block; }
.reply-quote-text { font-size: .74rem; color: var(--text-muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
/* Reply button on message hover */
.msg-reply-btn, .msg-unsend-btn {
  background: none; border: none; font-size: .72rem; color: var(--text-muted);
  cursor: pointer; padding: 0 .2rem; opacity: 0; transition: opacity .15s;
  border-radius: 4px; margin-left: auto;
}
.msg:hover .msg-reply-btn,
.msg:hover .msg-unsend-btn { opacity: 1; }
.msg-reply-btn:hover { color: var(--text); background: rgba(255,255,255,.1); }
.msg-unsend-btn:hover { color: var(--red); background: rgba(239,68,68,.12); }
/* Block button in RUP */
.rup-btn-block { background: var(--bg4); color: var(--text-muted); }
.rup-btn-block.blocked { background: rgba(239,68,68,.18); color: var(--red); }

/* ===== REACTIONS ===== */
.reaction-bar { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .5rem; align-items: center; min-height: 1.4rem; }
.reaction-chip {
  display: inline-flex; align-items: center; gap: .25rem;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.28);
  border-radius: 999px; padding: .18rem .55rem; font-size: .82rem; cursor: pointer;
  transition: background .15s, border-color .15s; color: var(--text); user-select: none;
}
.reaction-chip:hover { background: rgba(168,85,247,.3); border-color: var(--accent2); }
.reaction-chip.mine { background: rgba(168,85,247,.4); border-color: var(--accent2); box-shadow: 0 0 0 1px var(--accent2); }
.reaction-chip span { font-size: .76rem; font-weight: 700; color: var(--text); }
.reaction-add-btn {
  background: none; border: 1px dashed rgba(255,255,255,.25); border-radius: 999px;
  padding: .1rem .42rem; font-size: .8rem; cursor: pointer; color: var(--text-muted);
  opacity: 0; transition: opacity .15s;
}
.msg:hover .reaction-add-btn { opacity: 0.65; }
.reaction-add-btn:hover { opacity: 1 !important; border-color: var(--accent2); }

.typing-indicator { padding: .35rem 1rem; font-size: .78rem; color: var(--text-muted); min-height: 22px; display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }
.typing-indicator.hidden { visibility: hidden; }
.typing-dots { display: flex; gap: 3px; }
.typing-dots span { width: 5px; height: 5px; background: var(--accent3); border-radius: 50%; animation: bounce 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-5px); } }

.input-bar { padding: .65rem .9rem; background: var(--bg2); border-top: 1px solid var(--border); flex-shrink: 0; }
.emoji-row { display: none; flex-wrap: wrap; gap: .3rem; padding: .4rem 0; max-height: 90px; overflow-y: auto; }
.emoji-row.open { display: flex; }
.emoji-btn { font-size: 1.3rem; cursor: pointer; background: none; border: none; padding: .1rem; border-radius: 4px; transition: transform .1s; }
.emoji-btn:hover { transform: scale(1.3); }
.input-row { display: flex; align-items: center; gap: .5rem; }
#msg-input { flex: 1; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem 1rem; color: var(--text); font-size: .93rem; outline: none; transition: border .2s; }
#msg-input:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(168,85,247,.12); }
.btn-send { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border: none; border-radius: var(--radius); padding: .6rem 1.1rem; font-size: .88rem; font-weight: 700; cursor: pointer; white-space: nowrap; transition: transform .15s, box-shadow .15s; }
.btn-send:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-send:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ===== ICON BUTTONS ===== */
.icon-btn { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 1.05rem; padding: .3rem; border-radius: 6px; transition: color .15s, background .15s; line-height: 1; }
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,.08); }

/* ===== MODALS ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 100; animation: fadeIn .2s; }
#confirm-modal { z-index: 200; }
.modal-overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal { background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; padding: 1.5rem; width: 100%; max-width: 400px; box-shadow: 0 16px 48px rgba(0,0,0,.5); animation: slideUp .25s ease; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.modal-header h3 { font-size: 1.05rem; font-weight: 700; }
.modal input { width: 100%; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .65rem .9rem; color: var(--text); font-size: .9rem; outline: none; margin-bottom: .5rem; }
.modal input:focus { border-color: var(--accent2); }
.section-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }

.search-results { list-style: none; max-height: 200px; overflow-y: auto; }
.search-results li { display: flex; align-items: center; gap: .75rem; padding: .6rem .5rem; border-radius: var(--radius-sm); transition: background .15s; }
.search-results li:hover { background: rgba(124,58,237,.18); cursor: pointer; }
.result-avatar { font-size: 1.5rem; }
.result-info { flex: 1; min-width: 0; }
.result-name { font-size: .9rem; font-weight: 600; }
.result-user { font-size: .75rem; color: var(--text-muted); }
.result-status { font-size: .72rem; }
.result-status.online { color: var(--green); }
.result-actions { display: flex; gap: .3rem; flex-shrink: 0; }
.btn-sm { font-size: .78rem; padding: .3rem .65rem; border-radius: 6px; border: none; cursor: pointer; font-weight: 600; transition: opacity .15s; background: var(--bg3); color: var(--text); }
.btn-accept { background: var(--green); color: #fff; }
.btn-reject { background: var(--red); color: #fff; }
.btn-add { background: var(--accent); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm:hover { opacity: .85; }
.confirm-modal { max-width: 340px; }
.already-friends { font-size: .72rem; color: var(--text-muted); }

/* ===== PROFILE MODAL ===== */
.profile-modal { max-width: 400px; width: 100%; }
.profile-avatar-row { text-align: center; font-size: 3.5rem; margin: .5rem 0 1.25rem; }
.profile-fields { display: grid; grid-template-columns: auto 1fr; gap: .45rem 1rem; margin-bottom: 1.5rem; }
.profile-fields dt { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; align-self: center; }
.profile-fields dd { font-size: .9rem; color: var(--text); margin: 0; word-break: break-all; }
.profile-danger-zone { border-top: 1px solid rgba(239,68,68,.3); padding-top: 1rem; display: flex; flex-direction: column; gap: .6rem; }
.profile-extra-section { border-top: 1px solid var(--border); padding-top: .9rem; margin-top: .2rem; display: flex; flex-direction: column; gap: .6rem; }
.profile-extra-title { font-size: .8rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.profile-extra-hint { font-size: .7rem; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--accent); margin-left: .4rem; }
.profile-extra-fields { display: flex; gap: .75rem; flex-wrap: wrap; }
.profile-extra-label { display: flex; flex-direction: column; gap: .25rem; font-size: .78rem; color: var(--text-muted); flex: 1; min-width: 110px; }
.profile-extra-input { background: var(--bg1); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: .85rem; padding: .35rem .55rem; outline: none; width: 100%; }
.profile-extra-input:focus { border-color: var(--accent); }
.profile-extra-input option { background: var(--bg2); }
.profile-danger-label { font-size: .75rem; color: var(--red); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; margin: 0 0 .25rem; }
/* Friend profile popup */
.friend-profile-modal { max-width: 340px; width: 100%; }
.fp-avatar-row { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; }
.fp-fields { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0; }
.fp-fields span { font-size: .82rem; color: var(--text-muted); background: var(--bg); border: 1px solid var(--border); border-radius: 99px; padding: .15rem .65rem; }
/* hide the info/unfriend btns in lobby cards (too small) */
/* lobby dm list has no info/unfriend buttons */

/* ===== RESPONSIVE ===== */
.sidebar-toggle { display: none; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 9; }
.sidebar-overlay.active { display: block; }
@media (max-width: 720px) {
  .sidebar-toggle { display: flex; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); box-shadow: 4px 0 24px rgba(0,0,0,.5); z-index: 10; }
  .sidebar.open { transform: translateX(0); }
  .category-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

/* ===== CHAT LAYOUT (messages + users panel) ===== */
.chat-layout { display: flex; flex: 1; min-height: 0; overflow: hidden; }
.chat-main { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }

/* ===== ROOM USERS PANEL ===== */
.room-users-panel { width: 200px; flex-shrink: 0; background: var(--bg1); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; transition: width .2s ease; }
.room-users-panel.collapsed { width: 36px; }
.rup-header { display: flex; align-items: center; justify-content: space-between; padding: .6rem .75rem; border-bottom: 1px solid var(--border); gap: .5rem; min-height: 42px; }
.rup-header #rup-count { font-size: .75rem; font-weight: 700; color: var(--text-muted); white-space: nowrap; overflow: hidden; }
.room-users-panel.collapsed .rup-header #rup-count { display: none; }
.rup-toggle { font-size: .7rem; color: var(--text-muted); flex-shrink: 0; padding: .2rem .3rem; }
.room-users-panel.collapsed .rup-toggle { transform: rotate(180deg); }
.rup-list { list-style: none; flex: 1; overflow-y: auto; padding: .4rem 0; }
.room-users-panel.collapsed .rup-list { display: none; }
.rup-item { display: flex; align-items: center; gap: .5rem; padding: .4rem .75rem; border-radius: var(--radius-sm); transition: background .15s; cursor: default; position: relative; }
.rup-item:hover { background: rgba(124,58,237,.15); }
.rup-item .rup-avatar { font-size: 1.2rem; flex-shrink: 0; }
.rup-item .rup-name { font-size: .8rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rup-item .rup-name.is-me { color: var(--accent2); font-weight: 700; }
.rup-actions { display: none; position: absolute; right: .4rem; top: 50%; transform: translateY(-50%); gap: .25rem; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .2rem .3rem; z-index: 10; }
.rup-item:hover .rup-actions { display: flex; }
.rup-action-btn { font-size: .7rem; padding: .2rem .45rem; border-radius: 4px; border: none; cursor: pointer; font-weight: 700; white-space: nowrap; transition: opacity .15s; }
.rup-action-btn:hover { opacity: .8; }
.rup-btn-dm { background: var(--accent); color: #fff; }
.rup-btn-add { background: var(--green); color: #fff; }
.rup-btn-add.sent { background: var(--text-muted); cursor: default; }

@media (max-width: 720px) {
  .room-users-panel { width: 160px; }
  .room-users-panel.collapsed { width: 32px; }
}

/* Scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ===== SOCIAL AUTH ===== */
.social-divider { display: flex; align-items: center; gap: .75rem; color: var(--text-muted); font-size: .78rem; margin: .25rem 0; }
.social-divider::before, .social-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.social-btns { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.btn-social { display: flex; align-items: center; justify-content: center; gap: .5rem; padding: .6rem .75rem; border-radius: var(--radius-sm); font-size: .88rem; font-weight: 600; cursor: pointer; transition: opacity .15s, transform .1s; border: 1px solid var(--border); }
.btn-social:hover { opacity: .85; transform: translateY(-1px); }
.btn-social:active { transform: translateY(0); }
.social-icon { width: 18px; height: 18px; flex-shrink: 0; }
.btn-yahoo  { background: #6001D2; color: #fff; border-color: #6001D2; }
.btn-google { background: #fff; color: #3c4043; border-color: #dadce0; }
.btn-google:hover { background: #f8f8f8; opacity: 1; }
.btn-social:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-social-unconfigured { opacity: .65; }
.btn-social-unconfigured::after { content: ' (setup needed)'; font-size: .7rem; opacity: .8; }

/* ===== AVATAR PICKER MODAL ===== */
.avatar-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; padding: .25rem 0 .5rem; }
.avatar-grid-opt { font-size: 1.9rem; cursor: pointer; padding: .35rem; border-radius: 10px; border: 2px solid transparent; text-align: center; transition: border-color .15s, background .15s, transform .1s; background: var(--bg3); }
.avatar-grid-opt:hover { border-color: var(--accent2); transform: scale(1.12); }
.avatar-grid-opt.selected { border-color: var(--accent2); background: rgba(168,85,247,.2); }
.avatar-modal-hint { font-size: .75rem; color: var(--text-muted); text-align: center; margin-top: .25rem; }


