:root {
  --bg: #0f141b; --panel: #161d27; --panel2: #1c2531;
  --border: #2a3542; --text: #e8edf3; --muted: #8b98a9;
  --accent: #4f9cf9; --accent-dim: #2b5f9e;
  --me: #1e3a5f; --danger: #e5484d; --sys: #6b7688;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
}
.hidden { display: none !important; }

/* ---------- join screen ---------- */
.join-screen {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: radial-gradient(ellipse at 50% 30%, #1a2433 0%, var(--bg) 70%);
}
.join-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 36px 30px;
  text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.logo { font-size: 34px; font-weight: 800; margin-bottom: 10px; }
.logo.small { font-size: 20px; margin: 0; }
.tagline { color: var(--muted); font-size: 14px; line-height: 1.5; margin-bottom: 22px; }
.join-card input {
  width: 100%; padding: 13px 14px; font-size: 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  margin-bottom: 12px; outline: none;
}
.join-card input:focus { border-color: var(--accent); }
.join-card button {
  width: 100%; padding: 13px; font-size: 16px; font-weight: 700; border: none;
  border-radius: 10px; background: var(--accent); color: #fff; cursor: pointer;
}
.join-card button:hover { background: #3b8bf0; }
.hint { color: var(--muted); font-size: 12px; margin-top: 12px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* join/register profile fields */
.auth-row { display: flex; gap: 8px; }
.auth-row .auth-field { flex: 1; min-width: 0; }
.auth-field.age { flex: 0 0 110px; }
.join-card select.auth-field {
  width: 100%; padding: 13px 14px; font-size: 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  margin-bottom: 12px; outline: none; cursor: pointer;
}
.join-card select.auth-field:focus { border-color: var(--accent); }
/* hide number-input spinners for the age field */
.join-card input[type="number"]::-webkit-inner-spin-button { opacity: 1; }

/* age gate + legal */
.fine { color: var(--muted); font-size: 13px; line-height: 1.6; margin-bottom: 14px; }
.fine.small { font-size: 12px; margin: 12px 0 0; text-align: center; }
.fine a, .legal-links a, .ack a { color: var(--accent); }
.ack {
  display: flex; align-items: flex-start; gap: 10px; text-align: left;
  font-size: 14px; line-height: 1.5; margin-bottom: 12px; cursor: pointer;
}
.ack input { width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; accent-color: var(--accent); cursor: pointer; }
#agegate .cta:disabled { opacity: 0.4; cursor: not-allowed; }
.legal-links { margin-top: 18px; font-size: 12px; color: var(--muted); }

/* random chat match dialog */
.random-btn { width: 100%; margin-bottom: 6px; }
.random-btn.searching { background: var(--danger); }
.form-label { display: block; text-align: left; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.form-label select {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; cursor: pointer;
}
.form-label select:disabled { opacity: 0.5; cursor: not-allowed; }
.form-label.inline { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.form-label.inline select { margin-top: 0; flex: 1; }
.form-row { margin-bottom: 4px; }
#match-popup .cta { width: 100%; }
#match-filter-note a { color: var(--accent); }

/* auth tabs on the join screen */
.auth-tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.auth-tab {
  flex: 1; padding: 9px 0; font-size: 14px; font-weight: 600;
  background: var(--panel2); color: var(--muted); border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer;
}
.auth-tab.active { background: var(--accent-dim); color: #fff; border-color: var(--accent); }
.auth-pane input[type="password"] { font-family: inherit; }

/* friends */
.side-empty { color: var(--muted); font-size: 12px; line-height: 1.6; padding: 4px 2px 8px; }
.friend-req {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 6px; font-size: 13px;
}
.friend-req span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-btn {
  padding: 4px 10px; font-size: 12px; font-weight: 600; border: none; border-radius: 6px;
  background: var(--accent); color: #fff; cursor: pointer; white-space: nowrap;
}
.mini-btn.ghost { background: var(--panel2); color: var(--muted); border: 1px solid var(--border); }
.user-list li.offline { opacity: 0.55; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 8px; flex-shrink: 0; }
.dot.on { background: #3ddc84; box-shadow: 0 0 6px #3ddc84; }
.dot.off { background: var(--sys); }

/* ---------- app layout ---------- */
.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.me { margin-left: auto; color: var(--muted); font-size: 13px; }
.me strong { color: var(--text); }
.badge {
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 20px; margin-left: 6px; text-transform: uppercase;
}
.icon-btn {
  background: none; border: none; color: var(--muted); font-size: 18px;
  cursor: pointer; padding: 6px; border-radius: 8px;
}
.icon-btn:hover { background: var(--panel2); color: var(--text); }

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 260px; background: var(--panel); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 20px;
}
.sidebar h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); margin-bottom: 8px;
}
.sidebar h3 span { color: var(--accent); }
.room-list, .user-list { list-style: none; }
.room-list li, .user-list li {
  padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.room-list li:hover, .user-list li:hover { background: var(--panel2); }
.room-list li.active { background: var(--me); }
.room-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-topic { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.room-users { font-size: 11px; color: var(--muted); background: var(--panel2); padding: 2px 8px; border-radius: 12px; flex-shrink: 0; }
.user-list .nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-list .nick.mod { color: #7ee2a8; }
.user-list .nick.admin { color: #ff9d6b; }
.create-room { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.create-room input, .composer input {
  padding: 9px 10px; font-size: 13px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text); outline: none;
}
.create-room input:focus, .composer input:focus { border-color: var(--accent); }
#user-search {
  width: 100%; box-sizing: border-box; margin: 6px 0 4px;
  padding: 8px 10px; font-size: 13px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text); outline: none;
}
#user-search:focus { border-color: var(--accent); }
.search-meta { color: var(--muted); font-size: 12px; margin-left: 6px; }
.name-sug { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.sug-chip {
  padding: 4px 10px; font-size: 13px; border-radius: 999px; cursor: pointer;
  background: var(--panel2); color: var(--accent); border: 1px solid var(--accent-dim);
}
.sug-chip:hover { border-color: var(--accent); }
.create-room button {
  padding: 9px; font-size: 13px; font-weight: 600; border-radius: 8px; cursor: pointer;
  background: var(--panel2); color: var(--accent); border: 1px dashed var(--accent-dim);
}
.create-room button:hover { background: var(--me); }

/* ---------- chat ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tabs { display: flex; gap: 4px; padding: 8px 12px 0; background: var(--bg); overflow-x: auto; }
.tab {
  padding: 9px 14px; font-size: 13px; font-weight: 600; border-radius: 10px 10px 0 0;
  background: var(--panel); color: var(--muted); cursor: pointer; border: none;
  white-space: nowrap; display: flex; gap: 8px; align-items: center;
}
.tab.active { background: var(--panel2); color: var(--text); }
.tab .close { font-size: 12px; opacity: .6; }
.tab .close:hover { opacity: 1; color: var(--danger); }
.tab .unread {
  background: var(--accent); color: #fff; font-size: 10px; min-width: 18px; height: 18px;
  border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px;
}
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 4px; background: var(--bg); }
.msg { padding: 6px 10px; border-radius: 10px; font-size: 14px; line-height: 1.45; max-width: 85%; word-wrap: break-word; }
.msg .who { font-weight: 700; font-size: 12px; margin-right: 8px; cursor: pointer; }
.msg .who:hover { text-decoration: underline; }
.msg .time { font-size: 10px; color: var(--muted); margin-left: 8px; }
.msg.other { background: var(--panel2); align-self: flex-start; }
.msg.me { background: var(--me); align-self: flex-end; }
.msg .who { color: var(--accent); }
.msg.me .who { color: #9cc8ff; }
.msg.system {
  align-self: center; background: none; color: var(--sys); font-size: 12px;
  font-style: italic; max-width: 100%; text-align: center;
}
.msg.dm-in { border-left: 3px solid #b48cf2; }
.typing { min-height: 22px; padding: 2px 16px; font-size: 12px; color: var(--muted); font-style: italic; }
.composer { display: flex; gap: 8px; padding: 12px 16px; background: var(--panel); border-top: 1px solid var(--border); }
.composer input { flex: 1; font-size: 14px; padding: 12px; }
.composer button {
  padding: 0 22px; font-size: 14px; font-weight: 700; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.composer button:hover { background: #3b8bf0; }

/* ---------- popup ---------- */
.popup {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.popup-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 22px; width: 280px; position: relative; text-align: center;
}
.popup-card h4 { margin-bottom: 14px; font-size: 17px; }
.popup-card .icon-btn { position: absolute; top: 8px; right: 8px; }
#popup-actions { display: flex; flex-direction: column; gap: 8px; }
#popup-actions button {
  padding: 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); cursor: pointer; font-size: 13px; font-weight: 600;
}
#popup-actions button:hover { border-color: var(--accent); }
#popup-actions button.danger { color: var(--danger); border-color: #5a2b2d; }
#popup-actions button.danger:hover { background: #2b1a1b; }

/* ---------- mobile ---------- */
#menu-btn { display: none; }
@media (max-width: 760px) {
  #menu-btn { display: block; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
    transform: translateX(-100%); transition: transform .2s; width: 270px;
    box-shadow: 8px 0 30px rgba(0,0,0,.5);
  }
  .sidebar.open { transform: none; }
  .msg { max-width: 92%; }
  /* 16px+ inputs prevent iOS Safari from auto-zooming on focus */
  .composer input, .create-room input { font-size: 16px; }
}
.popup-card { max-width: calc(100vw - 32px); }

/* ---------- ads ---------- */
.ad-slot { overflow: hidden; text-align: center; }
.ad-top {
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 8px; min-height: 60px;
  display: flex; align-items: center; justify-content: center;
}
.ad-sidebar { margin-top: auto; padding-top: 12px; }

/* ---------- premium ---------- */
.badge.gold { background: linear-gradient(135deg, #b8860b, #f5c542); color: #231a03; }
.upgrade-btn {
  background: linear-gradient(135deg, #b8860b, #f5c542); color: #231a03;
  border: none; border-radius: 20px; padding: 7px 14px; font-size: 12px;
  font-weight: 800; cursor: pointer; white-space: nowrap;
}
.upgrade-btn:hover { filter: brightness(1.1); }
.user-list .nick.premium { color: #f5c542; }
.room-list li.locked { opacity: .65; }
.perks { list-style: none; text-align: left; margin: 6px 0 14px; display: flex; flex-direction: column; gap: 9px; font-size: 14px; }
.perks li { background: var(--panel2); border-radius: 8px; padding: 9px 12px; }
.price { font-size: 20px; font-weight: 800; color: #f5c542; margin-bottom: 12px; }
.popup-card.wide { width: 340px; }
.cta {
  width: 100%; padding: 12px; font-size: 15px; font-weight: 800; border: none;
  border-radius: 10px; cursor: pointer; color: #231a03;
  background: linear-gradient(135deg, #b8860b, #f5c542); margin-bottom: 8px;
}
.cta:hover { filter: brightness(1.1); }
.ghost-btn {
  width: 100%; padding: 10px; font-size: 13px; font-weight: 600; border-radius: 8px;
  background: none; border: 1px solid var(--border); color: var(--muted); cursor: pointer;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent); }
.profile-line { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.profile-line strong, .profile-line span { color: var(--text); }
#color-row { display: flex; align-items: center; justify-content: space-between; margin: 12px 0; font-size: 14px; }
#color-row.hidden { display: none; }
#color-input { width: 52px; height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel2); cursor: pointer; padding: 2px; }
#profile-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
#profile-actions:empty { display: none; }
