/* ============ theme ============ */
:root {
  --bg: #f6f7fb; --panel: #ffffff; --panel-2: #f0f2f7; --line: #e4e7ef; --text: #11141b; --muted: #6b7280;
  --accent: #5b5bf7; --accent-2: #8b5cf6; --accent-soft: #ecebff; --theirs: #ffffff;
  --mine: linear-gradient(135deg, #5b5bf7, #7c4dff); --mine-text: #fff;
  --green: #16a34a; --red: #ef4444; --shadow: 0 8px 30px rgba(17, 20, 27, .08);
  --radius: 18px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --panel: #161922; --panel-2: #1d212c; --line: #262b38; --text: #e8eaf0; --muted: #8b93a7;
    --accent-soft: #23234a; --theirs: #1d212c; --shadow: 0 8px 30px rgba(0, 0, 0, .35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #161922; --panel-2: #1d212c; --line: #262b38; --text: #e8eaf0; --muted: #8b93a7;
  --accent-soft: #23234a; --theirs: #1d212c; --shadow: 0 8px 30px rgba(0, 0, 0, .35); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", "Noto Sans Devanagari",
    "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
svg { width: 22px; height: 22px; fill: currentColor; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.screen { position: fixed; inset: 0; }
[dir="rtl"] .flip svg, [dir="rtl"] .back svg, [dir="rtl"] .send svg { transform: scaleX(-1); }

/* ============ logo / splash ============ */
.logo-big { width: 76px; height: 76px; border-radius: 24px; margin: 0 auto;
  background: url("/static/icon.svg") center/cover; box-shadow: 0 12px 40px rgba(91, 91, 247, .35); }
.logo-big.faint { opacity: .35; box-shadow: none; }
.splash { display: grid; place-items: center; }
.splash .logo-big { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.92); opacity: .7; } }

/* ============ auth ============ */
.auth { display: grid; place-items: center; padding: 24px; overflow: auto;
  background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 70%), var(--bg); }
.auth-card { position: relative; width: 100%; max-width: 400px; text-align: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 28px; padding: 32px 24px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 16px 0 4px; font-size: 26px; letter-spacing: -.02em; }
.auth-card form { text-align: start; margin-top: 18px; }
.lang-select { position: absolute; inset-inline-end: 14px; top: 14px; border: 1px solid var(--line);
  background: var(--panel-2); border-radius: 10px; padding: 4px 8px; font-size: 13px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--panel-2); border-radius: 14px; padding: 4px; margin-top: 20px; }
.tab { border: 0; background: none; padding: 9px; border-radius: 10px; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* ============ form controls ============ */
.field { display: block; margin-bottom: 14px; text-align: start; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 4px 6px; }
.field > small { display: block; margin: 4px 4px 0; }
.field input, .field textarea, .field select, .nick-input {
  width: 100%; border: 1px solid var(--line); background: var(--panel-2); border-radius: 14px; padding: 12px 14px;
  outline: none; transition: border-color .15s, box-shadow .15s; }
.field textarea { resize: vertical; min-height: 80px; }
.field input:focus, .field textarea:focus, .nick-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.nick-input { display: flex; align-items: center; gap: 2px; padding: 0 14px; direction: ltr; }
.nick-input b { color: var(--muted); font-weight: 500; }
.nick-input input { border: 0; background: none; padding: 12px 0; box-shadow: none !important; flex: 1; min-width: 0; outline: none; }
.hint { font-size: 13px; background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; margin: 0 0 14px; }
.error { color: var(--red); min-height: 20px; font-size: 14px; margin: 0 0 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line);
  background: var(--panel-2); border-radius: 14px; padding: 11px 16px; font-weight: 600; transition: transform .08s, filter .15s; }
.btn:active { transform: scale(.98); }
.btn.wide { display: flex; width: 100%; margin-top: 8px; }
.btn.primary { border: 0; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { filter: grayscale(.4) opacity(.6); cursor: progress; }
.btn.danger { color: var(--red); }
.btn.danger-solid { background: var(--red); border: 0; color: #fff; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.row-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.row-btns .btn { flex: 1; }

.toggle { display: flex; align-items: center; gap: 12px; padding: 12px 4px; cursor: pointer; }
.toggle-text { flex: 1; display: flex; flex-direction: column; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: inset-inline-start .2s; }
.toggle input:checked + .switch { background: var(--accent); }
.toggle input:checked + .switch::after { inset-inline-start: 21px; }
.toggle input:focus-visible + .switch { outline: 3px solid var(--accent-soft); }

.segmented { display: flex; background: var(--panel-2); border-radius: 12px; padding: 3px; margin: 0 14px 10px; }
.seg { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--muted); font-size: 14px; }
.seg.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* ============ avatar ============ */
.avatar { --c1: #5b5bf7; --c2: #8b5cf6; width: 44px; height: 44px; border-radius: 50%; flex: none; display: grid;
  place-items: center; color: #fff; font-weight: 700; font-size: 16px; position: relative; overflow: visible;
  background: linear-gradient(135deg, var(--c1), var(--c2)); text-transform: uppercase; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar svg { width: 55%; height: 55%; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }
.avatar.lg { width: 64px; height: 64px; font-size: 24px; }
.avatar.xl { width: 96px; height: 96px; font-size: 36px; }
.avatar.online::after { content: ""; position: absolute; inset-inline-end: 1px; bottom: 1px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--green); border: 2px solid var(--panel); }

/* ============ layout ============ */
.app { display: grid; grid-template-columns: 380px 1fr; }
.sidebar { background: var(--panel); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column;
  min-height: 0; padding-top: var(--safe-t); position: relative; }
.pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pane-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 8px; }
.pane-head h2 { margin: 0; font-size: 22px; letter-spacing: -.02em; flex: 1; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.conn.on { background: var(--green); }
.conn.off { background: var(--red); animation: pulse 1s infinite; }

/* desktop: news and profile use the full width, centered like a phone column */
@media (min-width: 761px) {
  .app[data-tab="news"], .app[data-tab="profile"] { grid-template-columns: 1fr; }
  .app[data-tab="news"] .chat, .app[data-tab="profile"] .chat { display: none; }
  .app[data-tab="news"] .pane, .app[data-tab="profile"] .pane { width: 100%; max-width: 680px; margin: 0 auto; }
  .app[data-tab="news"] .sidebar, .app[data-tab="profile"] .sidebar { border: 0; background: var(--bg); }
  .app[data-tab="news"] .tabbar, .app[data-tab="profile"] .tabbar { max-width: 680px; margin: 0 auto; width: 100%;
    border-radius: 20px 20px 0 0; border: 1px solid var(--line); border-bottom: 0; }
}

.tabbar { display: flex; justify-content: space-around; align-items: flex-end; background: var(--panel);
  border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--safe-b)); }
.tabbtn { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); padding: 4px; border-radius: 12px; position: relative; font-size: 11px; font-weight: 600; }
.tabbtn.active { color: var(--accent); }
.tabbtn .ic svg { width: 24px; height: 24px; }
.tabbtn.center .ic { width: 52px; height: 52px; margin-top: -26px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 6px 20px rgba(91,91,247,.45);
  border: 4px solid var(--panel); }
.tabbtn.center:not(.active) .ic { filter: saturate(.8); }
.tabbtn .dot { position: absolute; top: 2px; inset-inline-end: calc(50% - 18px); width: 9px; height: 9px; border-radius: 50%; background: var(--red); }

.search { margin: 4px 14px 8px; display: flex; align-items: center; gap: 8px; background: var(--panel-2);
  border-radius: 14px; padding: 0 12px; border: 1px solid transparent; }
.search:focus-within { border-color: var(--accent); }
.search svg { width: 18px; height: 18px; color: var(--muted); }
.search input { flex: 1; border: 0; background: none; padding: 10px 0; outline: none; min-width: 0; }

/* ============ stories bar ============ */
.stories { display: flex; gap: 12px; overflow-x: auto; padding: 6px 14px 10px; scrollbar-width: none; flex: none; }
.stories::-webkit-scrollbar { display: none; }
.story-chip { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: 64px; flex: none; padding: 0; }
.story-ring { padding: 2.5px; border-radius: 50%; background: conic-gradient(from 200deg, #f59e0b, #ec4899, #8b5cf6, #5b5bf7, #f59e0b); position: relative; }
.story-ring.seen { background: var(--line); }
.story-ring.none { background: transparent; }
.story-ring .avatar { width: 56px; height: 56px; border: 3px solid var(--panel); }
.story-chip small { font-size: 11px; max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.story-add { position: absolute; inset-inline-end: -2px; bottom: -2px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center; border: 2px solid var(--panel); }
.story-add svg { width: 14px; height: 14px; }

/* ============ chat list ============ */
.list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.list-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 10px 6px; }
.list-empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 10px; border: 0; background: none;
  border-radius: 14px; text-align: start; }
.item:hover { background: var(--panel-2); }
.item.active { background: var(--accent-soft); }
.item-main { flex: 1; min-width: 0; }
.item-top, .item-bottom { display: flex; align-items: center; gap: 6px; }
.item-top b { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 4px; }
.item-top b svg { width: 15px; height: 15px; color: var(--muted); }
.item-top time { font-size: 12px; color: var(--muted); }
.item-bottom .preview { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 12px; font-weight: 700; flex: none;
  min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center; }

/* ============ chat ============ */
.chat { position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: radial-gradient(800px 400px at 100% 0, var(--accent-soft), transparent 60%), var(--bg); }
.chat-empty { margin: auto; text-align: center; padding: 24px; }
.chat-empty p { margin: 14px 0 0; }
.chat-body { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 2px; padding: calc(8px + var(--safe-t)) 8px 8px;
  background: color-mix(in srgb, var(--panel) 85%, transparent); backdrop-filter: blur(16px); border-bottom: 1px solid var(--line); }
.peer { flex: 1; display: flex; align-items: center; gap: 10px; border: 0; background: none; text-align: start;
  padding: 4px; border-radius: 12px; min-width: 0; }
.peer .avatar { width: 40px; height: 40px; font-size: 15px; }
.peer-text { display: flex; flex-direction: column; min-width: 0; }
.peer-text b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-text small.online { color: var(--green); }
.icon-btn { border: 0; background: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  color: var(--accent); flex: none; }
.icon-btn:hover { background: var(--panel-2); }
.back { display: none; }

.key-warning { background: #fef3c7; color: #78350f; padding: 10px 14px; font-size: 14px; }
.key-warning .btn { margin-top: 8px; }
.messages { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 3px; overscroll-behavior: contain; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); padding: 4px 12px;
  border-radius: 999px; margin: 10px 0; border: 1px solid var(--line); }
.msg { max-width: min(78%, 560px); padding: 7px 12px 6px; border-radius: var(--radius); position: relative;
  white-space: pre-wrap; overflow-wrap: anywhere; animation: pop .18s ease-out; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }
.msg.theirs { align-self: flex-start; background: var(--theirs); border-end-start-radius: 6px; }
.msg.mine { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-end-end-radius: 6px; }
.msg.mine a { color: #fff; }
.msg.cont.theirs { border-start-start-radius: 6px; }
.msg.cont.mine { border-start-end-radius: 6px; }
.msg .who { display: block; font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.msg .meta { float: inline-end; margin-block: 6px -2px; margin-inline-start: 10px; font-size: 11px; opacity: .7;
  display: inline-flex; gap: 3px; align-items: center; }
.msg .meta svg { width: 15px; height: 15px; }
.msg.pending { opacity: .6; }
.msg.failed { outline: 2px solid var(--red); }
.msg.system { align-self: center; background: none; box-shadow: none; color: var(--muted); font-size: 13px; text-align: center; }
.typing { align-self: flex-start; color: var(--muted); font-size: 13px; padding: 4px 8px; }

.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px calc(8px + var(--safe-b));
  background: color-mix(in srgb, var(--panel) 85%, transparent); backdrop-filter: blur(16px); border-top: 1px solid var(--line); }
.compose-box { flex: 1; display: flex; flex-direction: column; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 22px; overflow: hidden; }
.compose-box:focus-within { border-color: var(--accent); }
.composer textarea { resize: none; border: 0; background: none; padding: 11px 16px; outline: none; max-height: 160px; line-height: 1.35; }
.attach-preview { position: relative; padding: 8px 8px 0; }
.attach-preview img { max-height: 120px; border-radius: 14px; display: block; }
.attach-preview button { position: absolute; top: 12px; inset-inline-start: 12px; width: 26px; height: 26px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; }
.attach-preview button svg { width: 16px; height: 16px; }
.send { width: 46px; height: 46px; border-radius: 50%; border: 0; color: #fff; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); transition: transform .1s; flex: none; }
.send:active { transform: scale(.92); }
.send:disabled { opacity: .5; }
.join-bar { padding: 10px 14px calc(10px + var(--safe-b)); background: var(--panel); border-top: 1px solid var(--line); text-align: center; }

/* ============ posts (channels + news feed) ============ */
.feed { flex: 1; overflow-y: auto; padding: 4px 12px 16px; display: flex; flex-direction: column; gap: 12px; }
.post { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 14px; box-shadow: var(--shadow);
  width: 100%; max-width: 640px; align-self: center; animation: pop .2s ease-out; }
.messages .post { box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.post-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.post-head .who { flex: 1; min-width: 0; border: 0; background: none; padding: 0; text-align: start; display: flex; flex-direction: column; }
.post-head .who b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.post-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.post-img { display: block; width: calc(100% + 28px); margin: 10px -14px; max-height: 520px; object-fit: cover; background: var(--panel-2); cursor: zoom-in; }
.post-text + .post-img { margin-top: 10px; }
.post-foot { display: flex; align-items: center; gap: 6px; margin-top: 8px; color: var(--muted); font-size: 13px; }
.post-foot .grow { flex: 1; }
.like { border: 0; background: var(--panel-2); border-radius: 999px; padding: 6px 12px; display: inline-flex; gap: 6px;
  align-items: center; color: var(--muted); font-weight: 600; }
.like svg { width: 18px; height: 18px; }
.like.on { color: #ef4444; background: color-mix(in srgb, #ef4444 12%, var(--panel)); }
.like.on svg { animation: beat .3s; }
@keyframes beat { 50% { transform: scale(1.3); } }
.feed-empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* ============ profile ============ */
.profile { flex: 1; overflow-y: auto; padding: 18px 14px 24px; }
.profile-card { text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 24px 16px 18px;
  box-shadow: var(--shadow); }
.avatar-wrap { position: relative; display: block; width: fit-content; margin: 0 auto 8px; border: 0; background: none; padding: 0; }
.avatar-wrap .avatar { margin: 0; }
.cam { position: absolute; inset-inline-end: -4px; bottom: -4px; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center; border: 3px solid var(--panel); }
.cam svg { width: 16px; height: 16px; }
.profile-card h2 { margin: 12px 0 2px; font-size: 22px; }
.profile-card .bio { margin: 10px auto 0; max-width: 420px; white-space: pre-wrap; overflow-wrap: anywhere; }
.profile-card .facts { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin-top: 10px; color: var(--muted); font-size: 14px; }
.profile-card .facts span { display: inline-flex; align-items: center; gap: 4px; }
.profile-card .facts svg { width: 16px; height: 16px; }
.profile-actions { display: flex; gap: 8px; margin-top: 14px; justify-content: center; flex-wrap: wrap; }
.settings { margin-top: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 6px 14px; }
.settings h4 { margin: 12px 4px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.set-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 4px; border: 0; background: none;
  text-align: start; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row > svg { color: var(--accent); }
.set-row span { flex: 1; }
.set-row em { font-style: normal; color: var(--muted); font-size: 14px; }
.set-row.danger, .set-row.danger > svg { color: var(--red); }
.version { text-align: center; color: var(--muted); font-size: 12px; margin-top: 16px; }

/* ============ sheets (dialogs) ============ */
dialog.sheet { border: 0; border-radius: 24px; padding: 0; width: min(460px, calc(100% - 20px)); max-height: 88vh;
  background: var(--panel); color: var(--text); box-shadow: var(--shadow); display: flex; flex-direction: column; }
dialog.sheet:not([open]) { display: none; }
dialog::backdrop { background: rgba(0,0,0,.45); backdrop-filter: blur(3px); }
.sheet-head { display: flex; align-items: center; padding: 14px 10px 4px 20px; padding-inline: 20px 10px; }
.sheet-head h3 { flex: 1; margin: 0; font-size: 18px; }
.sheet-body { padding: 8px 20px 20px; overflow-y: auto; }
.center-col { text-align: center; }
.center-col .avatar { margin: 0 auto 8px; }
.safety { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; font: 600 16px ui-monospace, Menlo, Consolas, monospace;
  background: var(--panel-2); padding: 14px; border-radius: 14px; text-align: center; letter-spacing: .04em; direction: ltr; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); border-radius: 999px; padding: 4px 6px 4px 4px;
  border: 0; font-size: 14px; }
.chip svg { width: 14px; height: 14px; }
.pick-list { max-height: 260px; overflow-y: auto; margin: 0 -8px; }
.member { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.member .grow { flex: 1; min-width: 0; }
.member .role { font-size: 12px; color: var(--accent); font-weight: 600; }
.lang-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.lang-list button { border: 1px solid var(--line); background: var(--panel-2); border-radius: 12px; padding: 12px; text-align: start; }
.lang-list button.active { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.bg-choices { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.bg-choices button { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; }
.bg-choices button.active { border-color: var(--text); }
.story-preview { width: 100%; aspect-ratio: 9/14; max-height: 46vh; border-radius: 18px; display: grid; place-items: center;
  padding: 20px; color: #fff; font-size: 22px; font-weight: 700; text-align: center; white-space: pre-wrap; overflow: hidden;
  background-size: cover; background-position: center; }
.story-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; }

/* story backgrounds (shared by preview and viewer) */
.bg-sunset { background: linear-gradient(160deg, #f97316, #ec4899 60%, #8b5cf6); }
.bg-ocean { background: linear-gradient(160deg, #06b6d4, #3b82f6 60%, #6366f1); }
.bg-forest { background: linear-gradient(160deg, #22c55e, #14b8a6 60%, #0f766e); }
.bg-night { background: linear-gradient(160deg, #1e1b4b, #4c1d95 60%, #0f172a); }
.bg-candy { background: linear-gradient(160deg, #f472b6, #a78bfa 60%, #60a5fa); }
.bg-gold { background: linear-gradient(160deg, #f59e0b, #eab308 50%, #b45309); }

/* ============ story viewer ============ */
.story-view { position: fixed; inset: 0; z-index: 60; background: #000; display: grid; place-items: center; }
.story-frame { position: relative; width: min(100vw, calc(100vh * 9 / 16)); height: 100%; max-height: 100vh; overflow: hidden;
  color: #fff; display: grid; place-items: center; }
.story-frame > img { width: 100%; height: 100%; object-fit: contain; }
.story-frame .story-text { padding: 28px; font-size: clamp(20px, 5vw, 30px); font-weight: 700; text-align: center; white-space: pre-wrap;
  overflow-wrap: anywhere; text-shadow: 0 2px 10px rgba(0,0,0,.35); }
.story-frame .caption { position: absolute; bottom: calc(70px + var(--safe-b)); inset-inline: 16px; text-align: center;
  font-size: 17px; text-shadow: 0 1px 6px rgba(0,0,0,.8); white-space: pre-wrap; }
.story-top { position: absolute; top: 0; inset-inline: 0; padding: calc(10px + var(--safe-t)) 12px 30px; z-index: 2;
  background: linear-gradient(rgba(0,0,0,.55), transparent); }
.story-bars { display: flex; gap: 4px; margin-bottom: 10px; }
.story-bars i { flex: 1; height: 3px; border-radius: 3px; background: rgba(255,255,255,.35); overflow: hidden; }
.story-bars i b { display: block; height: 100%; width: 0; background: #fff; }
.story-bars i.done b { width: 100%; }
.story-who { display: flex; align-items: center; gap: 10px; }
.story-who .grow { flex: 1; display: flex; flex-direction: column; }
.story-who small { opacity: .8; }
.story-who .icon-btn { color: #fff; }
.story-nav { position: absolute; top: 0; bottom: 0; width: 35%; z-index: 1; border: 0; background: none; }
.story-nav.prev { inset-inline-start: 0; }
.story-nav.next { inset-inline-end: 0; width: 65%; }
.story-bottom { position: absolute; bottom: 0; inset-inline: 0; z-index: 2; display: flex; justify-content: center; gap: 10px;
  padding: 14px 14px calc(14px + var(--safe-b)); background: linear-gradient(transparent, rgba(0,0,0,.6)); }
.story-bottom .btn { background: rgba(255,255,255,.16); border: 0; color: #fff; backdrop-filter: blur(8px); }

/* ============ call ============ */
.call { position: fixed; inset: 0; z-index: 50; background: radial-gradient(circle at 50% 30%, #2a2a5e, #0b0c12); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(40px + var(--safe-t)) 20px calc(36px + var(--safe-b)); }
.call .muted { color: rgba(255,255,255,.7); }
.remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.local-video { position: absolute; inset-inline-end: 16px; top: calc(16px + var(--safe-t)); width: 110px; aspect-ratio: 3/4;
  object-fit: cover; border-radius: 16px; background: #222; box-shadow: 0 6px 24px rgba(0,0,0,.5); z-index: 2; transform: scaleX(-1); }
.call-info { position: relative; z-index: 1; text-align: center; margin-top: 30px; }
.call-info h2 { margin: 16px 0 4px; font-size: 26px; }
.call-info .avatar { margin: 0 auto; }
.call.has-video .call-info { margin-top: 0; text-shadow: 0 1px 6px rgba(0,0,0,.6); }
.call.has-video .call-info .avatar { display: none; }
.call-controls { position: relative; z-index: 1; display: flex; gap: 18px; }
.round { width: 64px; height: 64px; border-radius: 50%; border: 0; display: grid; place-items: center; color: #fff;
  background: rgba(255,255,255,.16); backdrop-filter: blur(10px); transition: transform .1s, background .15s; }
.round svg { width: 28px; height: 28px; }
.round:active { transform: scale(.92); }
.round.off { background: #fff; color: #111; }
.round.green { background: var(--green); }
.round.red { background: var(--red); }
.round.ringing { animation: ring 1.2s ease-in-out infinite; }
@keyframes ring { 0%, 100% { transform: rotate(0); } 10%, 30% { transform: rotate(-14deg); } 20%, 40% { transform: rotate(14deg); } 50% { transform: rotate(0); } }

.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.92); display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 100vw; max-height: 100vh; object-fit: contain; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); z-index: 99;
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; box-shadow: var(--shadow); }

/* ============ phone ============ */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .chat { display: none; }
  body.in-chat .sidebar { display: none; }
  body.in-chat .chat { display: flex; position: fixed; inset: 0; }
  .back { display: grid; }
  .msg { max-width: 86%; }
}

/* ============ v1.2: profile stats, market, collections, live, AI ============ */
@media (min-width: 761px) {
  .app[data-tab="contacts"], .app[data-tab="market"] { grid-template-columns: 1fr; }
  .app[data-tab="contacts"] .chat, .app[data-tab="market"] .chat { display: none; }
  .app[data-tab="contacts"] .pane, .app[data-tab="market"] .pane { width: 100%; max-width: 760px; margin: 0 auto; }
  .app[data-tab="contacts"] .sidebar, .app[data-tab="market"] .sidebar { border: 0; background: var(--bg); }
  .app[data-tab="contacts"] .tabbar, .app[data-tab="market"] .tabbar { max-width: 760px; margin: 0 auto; width: 100%;
    border-radius: 20px 20px 0 0; border: 1px solid var(--line); border-bottom: 0; }
}
.tabbtn small { white-space: nowrap; }
.progress { height: 6px; border-radius: 6px; background: var(--panel-2); overflow: hidden; margin: 10px 0; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .2s; }
.attach-preview video { max-height: 160px; border-radius: 14px; display: block; max-width: 100%; }
.post-img.is-video { cursor: default; background: #000; max-height: 560px; }
.new-post-btn { margin-top: 0 !important; flex: none; }
.feed > * { flex-shrink: 0; }

.profile-social { margin-top: 14px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 12px 6px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat small { color: var(--muted); }
.profile-posts { padding: 0; overflow: visible; }
dialog .profile-actions { margin-bottom: 8px; }

.wallet-chip { border: 0; background: linear-gradient(135deg, #f59e0b, #f97316); color: #fff; font-weight: 700;
  border-radius: 999px; padding: 7px 14px; box-shadow: 0 4px 14px rgba(245, 158, 11, .35); }
.market { flex: 1; overflow-y: auto; padding: 0 12px 16px; }
.market-intro { margin: 0 4px 10px; }
.filter-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.fchip { flex: none; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; }
.fchip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.market-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.market-card { border: 1px solid var(--line); background: var(--panel); border-radius: 18px; padding: 8px 8px 10px; text-align: start;
  display: flex; flex-direction: column; gap: 3px; transition: transform .12s; }
.market-card:hover { transform: translateY(-2px); }
.mc-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 4px; }
.mc-price { font-weight: 700; font-size: 14px; }
.mc-price em { font-style: normal; color: var(--muted); font-weight: 500; font-size: 12px; }
.nft { --b1: #6366f1; --b2: #0ea5e9; position: relative; aspect-ratio: 1; border-radius: 14px; display: grid; place-items: center;
  background: radial-gradient(circle at 30% 25%, rgba(255,255,255,.35), transparent 45%), linear-gradient(145deg, var(--b1), var(--b2));
  overflow: hidden; width: 100%; }
.center-col .nft { width: 180px; margin: 0 auto; }
.nft::after { content: ""; position: absolute; inset: 0; background: linear-gradient(115deg, transparent 35%, rgba(255,255,255,.28) 50%, transparent 65%);
  transform: translateX(-100%); animation: shine 4s ease-in-out infinite; }
@keyframes shine { 60%, 100% { transform: translateX(100%); } }
.nft-emoji { font-size: clamp(42px, 9vw, 64px); filter: drop-shadow(0 6px 10px rgba(0,0,0,.3)); }
.center-col .nft-emoji { font-size: 92px; }
.nft.small .nft-emoji { font-size: 34px; }
.nft-tier { position: absolute; top: 7px; inset-inline-start: 7px; font-size: 10px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .04em; color: #fff; background: rgba(0,0,0,.28); padding: 2px 7px; border-radius: 999px; }
.nft-tier.legendary { background: linear-gradient(90deg, #f59e0b, #fde047); color: #451a03; }
.nft-tier.mythic { background: linear-gradient(90deg, #ec4899, #a855f7); }
.nft.small .nft-tier { display: none; }
.nft-serial { position: absolute; bottom: 6px; inset-inline-end: 7px; font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.5); }
.nft.sold { filter: grayscale(.8) opacity(.6); }
.big-price { font-size: 24px; font-weight: 800; margin: 8px 0; }
.pkg-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pkg { border: 1px solid var(--line); background: var(--panel-2); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.pkg b { font-size: 17px; }
.pkg span { color: var(--muted); }
.plus { color: var(--green); }
.minus { color: var(--red); }
.collection-total { margin: 0 4px 8px; }
.collection-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.col-item { border: 0; background: none; padding: 0; display: flex; flex-direction: column; gap: 3px; align-items: center; font-weight: 600; font-size: 12px; }

.live-strip { flex: none; display: flex; gap: 12px; overflow-x: auto; padding: 4px 2px 8px; }
.live-chip { position: relative; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 4px; width: 72px; flex: none; }
.live-chip small { font-size: 11px; max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-chip .story-ring { background: linear-gradient(135deg, #ef4444, #f97316); }
.live-badge { background: #ef4444; color: #fff; font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 6px; letter-spacing: .05em; }
.live-chip .live-badge { position: absolute; top: 46px; }
.live { position: fixed; inset: 0; z-index: 55; background: #000; color: #fff; }
.live-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.live-top { position: absolute; top: 0; inset-inline: 0; display: flex; align-items: center; gap: 10px; padding: calc(12px + var(--safe-t)) 12px 30px;
  background: linear-gradient(rgba(0,0,0,.6), transparent); }
.live-top .grow { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.live-top .icon-btn { color: #fff; }
.live-count { font-size: 13px; background: rgba(0,0,0,.4); padding: 3px 8px; border-radius: 8px; }
.live-bottom { position: absolute; bottom: 0; inset-inline: 0; padding: 30px 12px calc(12px + var(--safe-b)); background: linear-gradient(transparent, rgba(0,0,0,.7)); }
.live-chat { max-height: 34vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; mask-image: linear-gradient(transparent, #000 25%); }
.live-msg { font-size: 14px; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.live-input { display: flex; gap: 8px; align-items: center; }
.live-input input { flex: 1; min-width: 0; border: 0; border-radius: 999px; padding: 11px 16px; background: rgba(255,255,255,.18); color: #fff; outline: none; }
.live-input input::placeholder { color: rgba(255,255,255,.7); }

.ai-avatar { background: linear-gradient(135deg, #a855f7, #ec4899 60%, #f59e0b); font-size: 20px; }
.ai-item { margin-bottom: 4px; }

/* ============ v1.3: replies, reactions, attachments, voice, communities ============ */
.msg { cursor: pointer; }
.quote { display: block; width: 100%; text-align: start; border: 0; border-inline-start: 3px solid currentColor; background: rgba(127,127,127,.15);
  border-radius: 8px; padding: 4px 8px; margin: 2px 0 6px; color: inherit; font-size: 13px; }
.quote b { display: block; font-size: 12px; }
.quote span { display: block; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fwd { font-size: 12px; opacity: .75; font-style: italic; margin-bottom: 2px; }
.msg-img { display: block; max-width: 100%; max-height: 360px; border-radius: 12px; margin: 2px 0 4px; background: rgba(0,0,0,.2); }
.file-chip { display: flex; align-items: center; gap: 10px; border: 0; background: rgba(127,127,127,.15); color: inherit;
  border-radius: 12px; padding: 8px 10px; text-align: start; margin: 2px 0 4px; min-width: 200px; }
.file-chip > span:first-child { font-size: 24px; }
.voice { display: flex; align-items: center; gap: 6px; min-width: 230px; }
.voice-audio { height: 36px; max-width: 220px; }
.translation { margin-top: 6px; padding-top: 6px; border-top: 1px dashed rgba(127,127,127,.4); }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: -1px 0 4px; max-width: min(78%, 560px); }
.reactions.mine { align-self: flex-end; justify-content: flex-end; }
.reactions.theirs { align-self: flex-start; }
.react-chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 2px 8px; font-size: 13px; }
.react-chip.mine { border-color: var(--accent); background: var(--accent-soft); }
.quick-reacts { display: flex; justify-content: space-between; gap: 4px; margin-bottom: 8px; }
.quick-reacts button { border: 0; background: var(--panel-2); border-radius: 12px; font-size: 24px; width: 46px; height: 46px; }
.set-row .menu-emoji { flex: none; width: 22px; text-align: center; }
.reply-bar { display: flex; align-items: center; gap: 8px; padding: 8px 6px 0 14px; border-inline-start: 3px solid var(--accent); margin: 6px 8px 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mic { color: var(--accent); }
.rec-bar { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: pulse 1s infinite; }
.search-field { margin-bottom: 8px; }
.post.community .post-text { margin-top: 2px; }

/* ============ v1.4: help & support, moderation ============ */
.faq { display: grid; gap: 8px; margin-bottom: 18px; }
.faq-item { background: var(--panel-2); border-radius: 14px; padding: 2px 14px; }
.faq-item summary { cursor: pointer; padding: 11px 0; font-weight: 600; list-style: none; display: flex; gap: 8px; align-items: center; }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: "+"; margin-inline-start: auto; color: var(--accent); font-size: 20px; line-height: 1; transition: transform .2s; }
.faq-item[open] summary::after { transform: rotate(45deg); }
.faq-item p { margin: 0 0 12px; color: var(--muted); }
.mod-stats { grid-template-columns: repeat(4, 1fr); margin-bottom: 12px; }
.mod-tabs { margin: 0 0 12px; }
.mod-list { display: grid; gap: 10px; }
.mod-card { border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; background: var(--panel); display: grid; gap: 4px; }
.mod-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.mod-head .chip { padding: 3px 10px; font-size: 12px; font-weight: 600; color: var(--accent); }
.mod-text { margin: 4px 0 0; white-space: pre-wrap; word-break: break-word; }
.mod-card .row-btns { margin-top: 8px; }
.center { text-align: center; }

/* ============ v1.4: design polish ============ */
/* active tab: a soft pill behind the icon */
.tabbtn:not(.center) .ic { display: grid; place-items: center; width: 54px; height: 30px; border-radius: 999px;
  transition: background .2s ease, transform .2s ease; }
.tabbtn.active:not(.center) .ic { background: var(--accent-soft); }
.tabbtn:active .ic { transform: scale(.9); }
.tabbtn.center .ic { transition: transform .2s ease, box-shadow .2s ease; }
.tabbtn.center:hover .ic { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(91,91,247,.55); }

/* buttons and rows react to the finger */
.btn, .item, .set-row, .col-item, .seg, .tab { transition: background .15s ease, transform .12s ease, box-shadow .15s ease, color .15s ease; }
.btn:active, .col-item:active { transform: scale(.97); }
.btn.primary:hover { box-shadow: 0 6px 18px rgba(91,91,247,.35); }
.item { border-radius: 14px; }

/* keyboard users always see where they are */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 10px; }

/* bottom sheets slide up */
dialog.sheet[open] { animation: sheet-in .22s cubic-bezier(.2, .8, .2, 1); }
dialog.sheet::backdrop { backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }

/* message bubbles: a little depth */
.msg.theirs { box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.msg.mine { box-shadow: 0 2px 10px rgba(91, 91, 247, .25); }

/* feed cards lift slightly */
.post { transition: transform .2s ease, box-shadow .2s ease; }
@media (hover: hover) { .post:hover { transform: translateY(-2px); box-shadow: 0 14px 40px rgba(17, 20, 27, .12); } }

/* world news: bold headline, link as a button */
.post-text.news { white-space: normal; }
.news-title { display: block; font-size: 17px; line-height: 1.35; letter-spacing: -.01em; margin-bottom: 6px; }
.post-text.news p { margin: 0 0 10px; color: var(--muted); white-space: pre-wrap; }
.news-link { display: inline-flex; align-items: center; gap: 4px; padding: 7px 14px; border-radius: 999px; font-weight: 600;
  font-size: 13px; text-decoration: none; background: var(--accent-soft); color: var(--accent); }
.news-link:hover { filter: brightness(1.08); }

/* collection tiles shine on hover */
.col-item .nft, .market-card .nft { transition: transform .2s ease; }
@media (hover: hover) { .col-item:hover .nft, .market-card:hover .nft { transform: translateY(-3px) rotate(-1deg); } }

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============ v2.0: Premium, two-step sign-in, bots, AI tools, disappearing messages ============ */
.premium-star { margin-inline-start: 4px; font-size: .85em; filter: drop-shadow(0 0 4px rgba(245, 158, 11, .5)); }
.premium-btn { background: linear-gradient(135deg, #f59e0b, #ec4899); color: #fff; border: 0; }
.premium-row em { color: #f59e0b !important; font-weight: 600; }
.premium-hero { display: grid; justify-items: center; gap: 4px; text-align: center; padding: 18px 12px; margin-bottom: 12px;
  border-radius: 20px; color: #fff; background: linear-gradient(135deg, #f59e0b, #ec4899 55%, #8b5cf6); }
.premium-hero b { font-size: 18px; }
.premium-hero small { opacity: .9; }
.premium-big { font-size: 44px; line-height: 1; animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-4px) rotate(6deg); } }
.perks { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 10px; }
.perks li { display: flex; gap: 12px; align-items: center; }
.perk-ic { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); flex: none; }
.accent-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 6px 0 10px; }
.accent-dot { aspect-ratio: 1; border-radius: 50%; border: 4px solid var(--panel); box-shadow: 0 0 0 2px var(--line); }
.accent-dot.on { box-shadow: 0 0 0 3px var(--text); }
.steps { padding-inline-start: 20px; display: grid; gap: 10px; margin: 8px 0 14px; }
.secret-box { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; padding: 10px 12px;
  border-radius: 12px; background: var(--panel-2); }
.secret-box code { flex: 1; font-size: 14px; word-break: break-all; letter-spacing: .04em; }
.code-sample { white-space: pre-wrap; word-break: break-all; font-size: 12px; background: var(--panel-2); padding: 10px 12px; border-radius: 12px; }
.tfa-on { font-weight: 600; color: var(--green); }
.ai-out { white-space: pre-wrap; line-height: 1.55; margin: 0; }
.suggest-list { display: grid; gap: 8px; }
.suggest { text-align: start; border: 1px solid var(--line); background: var(--panel-2); padding: 12px 14px; border-radius: 16px;
  transition: background .15s, border-color .15s; }
.suggest:hover { border-color: var(--accent); background: var(--accent-soft); }
.ttl-ico { margin-inline-end: 3px; font-size: 10px; }
.bot-avatar { background: linear-gradient(135deg, #64748b, #0ea5e9) !important; }
a.btn { text-decoration: none; }
