/* =====================================================================
   GupShup-X - styles
   1. Design tokens   2. Base   3. Components   4. Entry page
   5. Chat layout     6. Messages   7. Sidebar   8. Private messages
   9. Popup / dialogs / toasts   10. Mobile   11. Accessibility
   ===================================================================== */

/* ---------- 1. Design tokens ---------- */
:root {
  --bg: #0b1020;
  --bg-2: #0f162b;
  --surface: #131b33;
  --surface-2: #1a2442;
  --surface-3: #222e52;
  --border: #263256;
  --text: #e8ecf8;
  --muted: #97a1c0;
  --faint: #6b7596;

  --primary: #7c5cff;
  --primary-2: #d946ef;
  --grad: linear-gradient(135deg, #7c5cff 0%, #d946ef 100%);
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #f43f5e;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow: 0 12px 32px rgba(2, 4, 12, 0.45);

  --font: Inter, "Segoe UI", system-ui, -apple-system, "Noto Sans Devanagari", "Nirmala UI", sans-serif;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-base: 0.9375rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.5rem;
  --fs-2xl: clamp(1.7rem, 4vw, 2.1rem);

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;

  --topbar-h: 58px;
  --tabbar-h: 62px;
  --sidebar-w: 300px;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-base) / 1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
h1, h2, h3, p { margin: 0; }
a { color: #a99bff; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
ul { list-style: none; margin: 0; padding: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.ic { display: block; flex: none; }
[data-icon], [data-logo] { display: inline-flex; align-items: center; justify-content: center; }

.view { height: 100dvh; width: 100%; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }

/* ---------- 3. Components ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 800; font-size: 1.35rem; letter-spacing: -0.02em; }
.brand-x { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-sm .brand-name { font-size: 1.1rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--radius);
  padding: 11px 18px; font-weight: 600; background: var(--surface-2);
  transition: transform .12s, background .15s, box-shadow .15s, opacity .15s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--grad); color: #fff; box-shadow: 0 8px 22px rgba(124, 92, 255, .35); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: rgba(244, 63, 94, .14); color: #ff8da1; border-color: rgba(244, 63, 94, .4); }
.btn.danger:hover { background: rgba(244, 63, 94, .24); }
.btn.small { padding: 7px 12px; font-size: var(--fs-sm); border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled, .send-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .4); border-top-color: #fff; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; color: var(--muted);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.send-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 42px; height: 42px; border-radius: 12px; border: 0; color: #fff; background: var(--grad);
  transition: transform .12s, filter .15s;
}
.send-btn:not(:disabled):hover { filter: brightness(1.1); }
.send-btn:not(:disabled):active { transform: scale(.95); }

.badge {
  position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1;
}
.chip {
  background: var(--surface-2); color: var(--muted); border-radius: 999px;
  padding: 2px 10px; font-size: var(--fs-xs); font-weight: 700;
}

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 var(--sp-4); padding: 0; border: 0; min-width: 0; }
.field label, .field legend { font-size: var(--fs-sm); font-weight: 600; color: var(--muted); padding: 0; }
.optional { font-weight: 400; color: var(--faint); }
input[type="text"], input[type="search"], textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 11px 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input[type="text"]:focus, input[type="search"]:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124, 92, 255, .25);
}
input.invalid { border-color: var(--danger); }
input[type="text"]:focus-visible, input[type="search"]:focus-visible, textarea:focus-visible { outline: none; }
textarea { resize: none; }
.field-error { color: #ff8da1; font-size: var(--fs-sm); min-height: 0; }
.field-error:empty { display: none; }
.form-error { margin-bottom: var(--sp-3); }

.check, .radio { display: flex; gap: 10px; align-items: flex-start; font-size: var(--fs-sm); color: var(--text); cursor: pointer; }
.check input, .radio input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--primary); flex: none; }
.reasons { gap: 10px; }
.reasons .radio { color: var(--text); font-weight: 400; font-size: var(--fs-base); }

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-size: var(--fs-base); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.slider { position: relative; flex: none; width: 44px; height: 26px; background: var(--surface-3); border-radius: 999px; transition: background .2s; }
.slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::after { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid #fff; outline-offset: 2px; }

/* avatars: colour classes av-0 .. av-7 */
.avatar {
  position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none;
  border-radius: 50%; color: #fff; font-weight: 700; user-select: none; border: 0; padding: 0;
}
.av-sm { width: 30px; height: 30px; font-size: 13px; }
.av-md { width: 38px; height: 38px; font-size: 15px; }
.av-lg { width: 64px; height: 64px; font-size: 26px; }
.av-0 { background: linear-gradient(135deg, #7c5cff, #d946ef); }
.av-1 { background: linear-gradient(135deg, #3b82f6, #06b6d4); }
.av-2 { background: linear-gradient(135deg, #10b981, #84cc16); }
.av-3 { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.av-4 { background: linear-gradient(135deg, #ec4899, #f43f5e); }
.av-5 { background: linear-gradient(135deg, #8b5cf6, #3b82f6); }
.av-6 { background: linear-gradient(135deg, #14b8a6, #3b82f6); }
.av-7 { background: linear-gradient(135deg, #f97316, #eab308); }

.status-dot {
  position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--surface); background: var(--faint);
}
.status-dot.online { background: var(--ok); }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { position: relative; }
.swatch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.swatch .avatar { width: 34px; height: 34px; font-size: 0; box-shadow: 0 0 0 2px transparent; transition: box-shadow .15s, transform .15s; }
.swatch input:checked + .avatar { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px #fff; transform: scale(1.08); }
.swatch input:focus-visible + .avatar { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--primary); }

/* ---------- 4. Entry page + splash ---------- */
.splash { display: grid; place-items: center; }
.splash-card { display: flex; flex-direction: column; align-items: center; gap: 16px; color: var(--muted); }
.splash .logo { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); opacity: .8; } }

.entry {
  display: grid; place-items: center; padding: 20px; overflow-y: auto;
  background:
    radial-gradient(600px 400px at 15% 10%, rgba(124, 92, 255, .28), transparent 70%),
    radial-gradient(520px 380px at 90% 90%, rgba(217, 70, 239, .22), transparent 70%),
    var(--bg);
}
.entry-card {
  width: 100%; max-width: 440px; margin: auto;
  background: rgba(19, 27, 51, .88); border: 1px solid var(--border); border-radius: 24px;
  padding: 32px 28px; box-shadow: var(--shadow); backdrop-filter: blur(8px);
}
.entry-card .brand { margin-bottom: 22px; }
.entry-card h1 { font-size: var(--fs-2xl); line-height: 1.15; letter-spacing: -0.02em; }
.lead { margin: 8px 0 24px; }
.entry-preview { display: flex; gap: 14px; align-items: flex-start; margin-bottom: var(--sp-3); }
.entry-preview .avatar { margin-top: 24px; }
.entry-foot { margin-top: 18px; font-size: var(--fs-xs); text-align: center; line-height: 1.6; }

/* ---------- 5. Chat layout ---------- */
.chat {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-w);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas: "top top" "room side";
  background: var(--bg-2);
}
.topbar {
  grid-area: top; display: flex; align-items: center; gap: var(--sp-4);
  padding: 0 var(--sp-4); background: var(--surface); border-bottom: 1px solid var(--border); z-index: 5;
}
.room-title { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; padding-left: var(--sp-4); border-left: 1px solid var(--border); }
.room-title h2 { font-size: var(--fs-base); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.conn { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-xs); font-weight: 600; color: var(--muted); padding: 5px 10px; border-radius: 999px; background: var(--bg-2); }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.conn[data-state="reconnecting"] .dot { background: var(--warn); animation: blink 1s infinite; }
.conn[data-state="offline"] .dot { background: var(--danger); }
@keyframes blink { 50% { opacity: .25; } }

.room { grid-area: room; position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.feed { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--sp-4) var(--sp-5); outline: none; }
.feed-top { display: flex; justify-content: center; margin-bottom: var(--sp-3); }
.feed-list { display: flex; flex-direction: column; gap: 14px; }

.new-msgs {
  position: absolute; left: 50%; bottom: 112px; transform: translateX(-50%); z-index: 4;
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; border: 0;
  background: var(--grad); color: #fff; font-weight: 600; font-size: var(--fs-sm); box-shadow: var(--shadow);
}

.mute-banner {
  display: flex; gap: 12px; align-items: flex-start; margin: 0 var(--sp-4) var(--sp-2); padding: 12px 14px;
  border-radius: var(--radius); background: rgba(245, 158, 11, .12); border: 1px solid rgba(245, 158, 11, .45); color: #fcd9a0;
}
.mute-banner > div { display: flex; flex-direction: column; gap: 2px; }
.mute-banner [data-icon] { margin-top: 2px; color: var(--warn); }
.mute-banner strong { color: #ffe4b8; }

.composer { padding: var(--sp-2) var(--sp-4) var(--sp-3); border-top: 1px solid var(--border); background: var(--surface); }
.composer-box { display: flex; align-items: flex-end; gap: 6px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 16px; padding: 6px; transition: border-color .15s, box-shadow .15s; }
.composer-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124, 92, 255, .22); }
.composer-box textarea { border: 0; background: transparent; box-shadow: none !important; padding: 10px 8px; max-height: 120px; min-height: 42px; line-height: 1.4; }
.composer-box.disabled { opacity: .6; }
.composer-meta { display: flex; justify-content: space-between; padding: 4px 6px 0; min-height: 20px; }
.composer-meta .small { font-size: var(--fs-xs); }

/* ---------- 6. Messages ---------- */
.msg { display: flex; gap: 12px; align-items: flex-start; animation: rise .18s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg .avatar { cursor: pointer; transition: transform .12s; }
.msg .avatar:hover { transform: scale(1.06); }
.msg-body { min-width: 0; max-width: min(720px, 100%); }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-name { background: none; border: 0; padding: 0; font-weight: 700; color: var(--text); font-size: var(--fs-base); }
.msg-name:hover { text-decoration: underline; }
.msg-time { font-size: var(--fs-xs); color: var(--faint); }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; color: #dde3f6; }
.msg.own .msg-name { color: #c9bdff; }
.msg.own .msg-text { color: #fff; }
.you-tag { font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--primary-2); }

.sys {
  display: flex; align-items: center; justify-content: center; gap: 8px; align-self: center;
  font-size: var(--fs-xs); color: var(--muted); background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 12px; max-width: 100%; animation: rise .18s ease-out;
}
.sys .sys-text { overflow-wrap: anywhere; }
.sys-join .ic { color: var(--ok); }
.sys-leave .ic { color: var(--faint); }
.sys.notice {
  border-radius: var(--radius); align-self: stretch; justify-content: flex-start; align-items: flex-start;
  padding: 10px 14px; font-size: var(--fs-sm); line-height: 1.5;
  background: rgba(245, 158, 11, .1); border-color: rgba(245, 158, 11, .4); color: #fcd9a0;
}
.sys.notice .ic { color: var(--warn); margin-top: 2px; }
.sys.info { border-radius: var(--radius); }

/* ---------- 7. Online sidebar ---------- */
.sidebar { grid-area: side; display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--border); }
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 14px var(--sp-4) 8px; }
.sidebar-head h3 { font-size: var(--fs-base); font-weight: 700; }
.sidebar-head .icon-btn { margin-left: auto; }
.search { position: relative; margin: 4px var(--sp-4) var(--sp-3); }
.search > [data-icon] { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search input { padding-left: 36px; padding-top: 9px; padding-bottom: 9px; }
.user-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 var(--sp-2) var(--sp-4); }
.user-item { display: flex; align-items: center; gap: 4px; border-radius: var(--radius); }
.user-item:hover { background: var(--surface-2); }
.user-row { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 8px 10px; text-align: left; border-radius: var(--radius); }
.user-info { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.user-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-sub { font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-item .icon-btn { width: 34px; height: 34px; margin-right: 4px; }
.user-item.is-blocked .user-name { text-decoration: line-through; color: var(--faint); }
.empty { padding: var(--sp-5) var(--sp-4); text-align: center; color: var(--muted); font-size: var(--fs-sm); display: flex; flex-direction: column; gap: 6px; }
.unread-pill { background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px; margin-right: 4px; }

/* ---------- 8. Private messages ---------- */
.dm-panel {
  position: fixed; right: calc(var(--sidebar-w) + 16px); bottom: 108px; z-index: 40;
  width: 350px; height: min(480px, calc(100dvh - var(--topbar-h) - 108px - 16px));
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden;
}
.dm-panel.min { height: auto; }
.dm-panel.min .dm-body { display: none; }
.dm-head { display: flex; align-items: center; gap: 6px; padding: 10px 10px 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); flex: none; }
.dm-head-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.dm-head h3 { font-size: var(--fs-base); }
.dm-peer { display: flex; align-items: center; gap: 10px; min-width: 0; }
button.dm-peer { background: none; border: 0; padding: 2px 6px 2px 0; text-align: left; color: inherit; border-radius: 10px; }
button.dm-peer:hover { background: var(--surface-3); }
.dm-peer .user-info { line-height: 1.15; }
.dm-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.dm-list { overflow-y: auto; padding: var(--sp-2); }
.dm-item { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px; border: 0; border-radius: var(--radius); background: none; }
.dm-item:hover { background: var(--surface-2); }
.dm-item .user-info { flex: 1; }
.dm-item.unread .user-sub { color: var(--text); font-weight: 600; }
.dm-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; background: var(--bg-2); }
.bubble { max-width: 82%; padding: 8px 12px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.4; animation: rise .15s ease-out; }
.bubble.them { align-self: flex-start; background: var(--surface-3); border-bottom-left-radius: 5px; }
.bubble.me { align-self: flex-end; background: var(--grad); color: #fff; border-bottom-right-radius: 5px; }
.bubble time { display: block; font-size: 10px; opacity: .7; margin-top: 2px; text-align: right; }
.bubble-status { align-self: flex-end; font-size: 11px; color: var(--faint); margin-top: -2px; }
.dm-note { padding: 8px 14px; background: rgba(244, 63, 94, .1); color: #ff8da1; border-top: 1px solid rgba(244, 63, 94, .3); }
.dm-note.info { background: rgba(245, 158, 11, .1); color: #fcd9a0; border-color: rgba(245, 158, 11, .35); }
.dm-composer { display: flex; align-items: flex-end; gap: 4px; padding: 8px; border-top: 1px solid var(--border); background: var(--surface); }
.dm-composer textarea { max-height: 100px; min-height: 40px; padding: 9px 12px; border-radius: 14px; }
.dm-composer .send-btn { width: 40px; height: 40px; }
.dm-empty-thread { margin: auto; text-align: center; color: var(--muted); font-size: var(--fs-sm); padding: 20px; }

/* ---------- 9. Popup, emoji, dialogs, toasts ---------- */
.scrim { position: fixed; inset: 0; background: rgba(5, 8, 18, .6); z-index: 25; }
.popup-scrim { z-index: 55; background: transparent; }
.popup {
  position: fixed; z-index: 60; width: 300px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 18px; animation: pop .14s ease-out;
}
@keyframes pop { from { opacity: 0; transform: scale(.97); } }
.popup-close { position: absolute; top: 8px; right: 8px; width: 34px; height: 34px; }
.popup-head { display: flex; gap: 14px; align-items: center; padding-right: 26px; }
.popup-name { font-size: var(--fs-lg); font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.popup-status { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--muted); margin-top: 2px; }
.popup-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.popup-status .dot.online { background: var(--ok); }
.tag { font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; background: var(--surface-3); color: var(--muted); padding: 2px 7px; border-radius: 6px; margin-left: 4px; }
.popup-about { margin: 14px 0; padding: 10px 12px; background: var(--bg-2); border-radius: var(--radius); font-size: var(--fs-sm); color: #cfd6ee; overflow-wrap: anywhere; white-space: pre-wrap; }
.popup-about.none { color: var(--faint); font-style: italic; }
.popup-actions { display: flex; flex-direction: column; gap: 8px; }
.popup-actions .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.emoji-picker {
  position: fixed; z-index: 70; width: 296px; max-height: 232px; overflow-y: auto; padding: 8px;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.emoji-picker button { border: 0; background: none; border-radius: 8px; font-size: 21px; line-height: 1; padding: 6px 0; }
.emoji-picker button:hover { background: var(--surface-3); }

dialog { padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--text); width: calc(100% - 24px); max-width: 520px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(5, 8, 18, .72); backdrop-filter: blur(3px); }
dialog[open] { animation: pop .16s ease-out; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 16px 8px 22px; }
.dialog-head h2 { font-size: var(--fs-lg); }
.dialog-body { padding: 8px 22px 18px; max-height: min(70dvh, 560px); overflow-y: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 22px 18px; border-top: 1px solid var(--border); }
.dialog-body > p.muted { margin-bottom: 14px; }
.prose h3 { font-size: var(--fs-base); margin: 16px 0 6px; }
.prose h3:first-child { margin-top: 4px; }
.prose p, .prose li { color: #cfd6ee; font-size: var(--fs-sm); line-height: 1.6; }
.prose ul { list-style: disc; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.set-section { padding: 14px 0; border-bottom: 1px solid var(--border); }
.set-section:last-child { border-bottom: 0; }
.set-section h3 { font-size: var(--fs-base); margin-bottom: 10px; }
.set-profile { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.blocked-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.blocked-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius); background: var(--bg-2); }
.blocked-list .grow { font-weight: 600; overflow-wrap: anywhere; }

.toasts { position: fixed; top: calc(var(--topbar-h) + 12px); right: 14px; z-index: 100; display: flex; flex-direction: column; gap: 10px; width: min(360px, calc(100vw - 28px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--radius); box-shadow: var(--shadow); animation: slide-in .22s ease-out;
}
@keyframes slide-in { from { opacity: 0; transform: translateX(24px); } }
.toast.warn { border-left-color: var(--warn); }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--ok); }
.toast.clickable { cursor: pointer; }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 700; font-size: var(--fs-sm); }
.toast-text { font-size: var(--fs-sm); color: var(--muted); overflow-wrap: anywhere; }
.toast-x { background: none; border: 0; color: var(--faint); padding: 2px; border-radius: 6px; }
.toast-x:hover { color: var(--text); }

/* ---------- 10. Mobile / tablet ---------- */
.mobile-only { display: none !important; }

@media (max-width: 900px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: inline-flex !important; }

  .chat {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--topbar-h) minmax(0, 1fr) var(--tabbar-h);
    grid-template-areas: "top" "room" "tabs";
  }
  .tabbar.mobile-only { display: grid !important; }
  .tabbar {
    grid-area: tabs; grid-template-columns: repeat(4, 1fr); background: var(--surface);
    border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  .tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: none; border: 0; color: var(--faint); font-size: 11px; font-weight: 600; }
  .tab.active { color: #fff; }
  .tab.active [data-icon] { color: var(--primary); }
  .tab-icon { position: relative; display: inline-flex; }
  .tab-icon .badge { top: -6px; right: -10px; }

  .room-title { border-left: 0; padding-left: 0; }
  .brand-sm .brand-name { display: none; }
  .feed { padding: var(--sp-3); }
  .new-msgs { bottom: 100px; }

  .sidebar {
    position: fixed; top: var(--topbar-h); right: 0; bottom: var(--tabbar-h); width: min(88vw, 360px);
    z-index: 30; transform: translateX(105%); transition: transform .25s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }

  .dm-panel {
    inset: 0; width: auto; height: auto; border: 0; border-radius: 0; z-index: 45;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .dm-panel.min { height: auto; }

  .popup-scrim { background: rgba(5, 8, 18, .55); }
  .popup {
    left: 0 !important; right: 0; top: auto !important; bottom: 0; width: auto;
    border-radius: 20px 20px 0 0; padding-bottom: calc(18px + env(safe-area-inset-bottom)); animation: sheet .2s ease-out;
  }
  @keyframes sheet { from { transform: translateY(40px); opacity: 0; } }
  .toasts { top: auto; bottom: calc(var(--tabbar-h) + 10px); right: 14px; left: 14px; width: auto; }
  .emoji-picker { width: min(296px, calc(100vw - 16px)); }
}

@media (max-width: 480px) {
  .entry-card { padding: 26px 20px; border-radius: 20px; }
  .swatches { gap: 8px; }
  .swatch .avatar { width: 30px; height: 30px; }
  .conn #conn-text { display: none; }
  .conn { padding: 6px; }
  .topbar { gap: var(--sp-2); }
}

/* ---------- 11. Accessibility ---------- */
:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.btn:focus-visible, .icon-btn:focus-visible, .send-btn:focus-visible { outline-color: var(--primary); box-shadow: 0 0 0 4px rgba(124, 92, 255, .35); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- 9. Home page, wheel loader, profile photos, server status (added) ---------- */
.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.btn.big { padding: 14px 26px; font-size: 1rem; border-radius: 999px; }

.home {
  overflow-y: auto; overflow-x: hidden; height: 100dvh; scroll-behavior: smooth;
  background:
    radial-gradient(700px 480px at 12% 4%, rgba(124, 92, 255, .30), transparent 70%),
    radial-gradient(600px 460px at 92% 30%, rgba(217, 70, 239, .20), transparent 70%),
    var(--bg);
}
.home-nav {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px clamp(16px, 5vw, 56px); background: rgba(11, 16, 32, .82); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.home-nav .brand { text-decoration: none; color: inherit; }
.home-links { display: flex; gap: clamp(12px, 3vw, 28px); }
.home-links a { color: var(--text); text-decoration: none; font-weight: 600; font-size: var(--fs-sm); opacity: .85; }
.home-links a:hover { opacity: 1; color: #fff; }

.home-hero {
  position: relative; text-align: center; padding: clamp(56px, 12vh, 120px) 20px clamp(48px, 9vh, 90px);
  max-width: 920px; margin: 0 auto;
}
.home-hero h1 { font-size: clamp(2.2rem, 7vw, 4.2rem); line-height: 1.08; letter-spacing: -0.03em; font-weight: 800; }
.hero-lead { margin: 18px auto 28px; max-width: 560px; color: var(--muted); font-size: clamp(1rem, 2.4vw, 1.15rem); }
.hero-actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.hero-actions .btn { text-decoration: none; }
.age-pill {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 30px; padding: 10px 18px; border-radius: 999px;
  background: rgba(244, 63, 94, .12); border: 1px solid rgba(244, 63, 94, .4); color: #ffb3c0; font-size: var(--fs-sm); font-weight: 600;
}
.hero-bubbles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.hb {
  position: absolute; padding: 8px 14px; border-radius: 16px 16px 16px 4px; background: rgba(34, 46, 82, .75);
  border: 1px solid var(--border); color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; animation: floaty 7s ease-in-out infinite;
}
.hb2 { border-radius: 16px 16px 4px 16px; background: rgba(124, 92, 255, .35); color: #fff; }
.hb1 { left: 3%; top: 16%; } .hb2 { right: 4%; top: 26%; animation-delay: -2s; }
.hb3 { left: 6%; bottom: 14%; animation-delay: -4s; } .hb4 { right: 6%; bottom: 20%; animation-delay: -1s; }
@keyframes floaty { 50% { transform: translateY(-12px); } }
@media (max-width: 760px) { .hb { opacity: .35; } .hb3, .hb4 { display: none; } }

.home-section { max-width: 1060px; margin: 0 auto; padding: clamp(36px, 7vh, 70px) 20px; text-align: center; }
.home-section h2 { font-size: clamp(1.6rem, 4.5vw, 2.3rem); letter-spacing: -0.02em; font-weight: 800; }
.section-sub { margin: 8px 0 30px; }
.feature-grid, .room-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); text-align: center; }
.feature, .room-card {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 26px 20px; transition: transform .18s, border-color .18s, box-shadow .18s;
}
.feature::before, .room-card::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; border-radius: 18px 18px 0 0; background: var(--grad); }
.feature:hover, .room-card:hover { transform: translateY(-4px); border-color: var(--primary); box-shadow: var(--shadow); }
.f-ico { display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 16px; background: rgba(124, 92, 255, .16); color: #b9a7ff; margin-bottom: 12px; }
.feature h3, .room-card h3 { font-size: 1.05rem; margin-bottom: 6px; }
.feature p, .room-card p { color: var(--muted); font-size: var(--fs-sm); }
.tag { display: inline-block; margin-top: 14px; padding: 3px 12px; border-radius: 999px; background: var(--surface-3); color: var(--muted); font-size: var(--fs-xs); font-weight: 700; }
.tag-live { background: rgba(34, 197, 94, .16); color: #6ee79b; }
.room-card.live { border-color: rgba(124, 92, 255, .6); }

.home-guide { max-width: 720px; }
.tick-list { list-style: none; margin: 22px 0 28px; padding: 0; text-align: left; display: grid; gap: 12px; }
.tick-list li { position: relative; padding-left: 28px; color: var(--muted); }
.tick-list li::before { content: "\2665"; position: absolute; left: 0; color: var(--primary-2); }
.tick-list strong { color: var(--text); }
.home-foot { display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; padding: 26px 20px calc(30px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border); }
.home-foot a { color: var(--muted); }

/* wheel loader (Home -> nickname page, nickname -> chat) */
.wheel { width: 56px; height: 56px; border-radius: 50%; border: 5px solid var(--surface-3); border-top-color: var(--primary-2); border-right-color: var(--primary); animation: spin .85s linear infinite; }
#view-loading .splash-card { gap: 22px; }

/* profile photos inside avatars */
.avatar.has-pic { background: var(--surface-3); overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; pointer-events: none; }
.photo-pick { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.photo-pick .btn { display: inline-flex; align-items: center; gap: 8px; }

/* "Server: Active" line at the bottom of the chat */
.server-status {
  display: flex; align-items: center; justify-content: center; gap: 8px; padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
  font-size: var(--fs-xs); font-weight: 600; color: var(--muted); border-top: 1px solid var(--border); background: var(--surface);
}
.s-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.s-dot[data-state="reconnecting"] { background: var(--warn); box-shadow: 0 0 0 3px rgba(245, 158, 11, .18); }
.s-dot[data-state="offline"] { background: var(--danger); box-shadow: 0 0 0 3px rgba(244, 63, 94, .18); }
.s-wheel { display: inline-flex; color: var(--primary); animation: spin 1.6s linear infinite; }
@media (prefers-reduced-motion: reduce) { .hb { animation: none; } }
