/* ==========================================================================
   PV Message — dark theme
   ========================================================================== */
:root {
  --bg: #0a0d12;
  --panel: #0f141b;
  --panel-2: #151c25;
  --panel-3: #1c2530;
  --border: #212b37;
  --text: #e7edf3;
  --muted: #8a97a6;
  --faint: #5b6876;
  --in: #18212b;
  --accent: #8b7bff;
  --out1: #6550ee;
  --out2: #8d5cf6;
  --read: #a5ffe9;
  --danger: #ff5d6c;
  --online: #3ddc84;
  --radius: 18px;
  --header-h: 62px;
  --drawer-w: 360px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Tahoma, sans-serif;
  --emoji-font: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  color-scheme: dark;
}
[data-accent="teal"]  { --accent: #2dd4bf; --out1: #0e8f84; --out2: #13a99a; }
[data-accent="rose"]  { --accent: #ff6b9a; --out1: #d63c74; --out2: #ec5a8b; }
[data-accent="blue"]  { --accent: #5b9cff; --out1: #2c64d8; --out2: #4a82ee; }
[data-accent="amber"] { --accent: #ffb547; --out1: #c56f1c; --out2: #de8b2c; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
::selection { background: color-mix(in srgb, var(--accent) 45%, transparent); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #ffffff1a; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #ffffff30; }
::-webkit-scrollbar-track { background: transparent; }
svg { display: block; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-grid; place-items: center; flex: none;
  color: var(--muted);
  transition: background .15s, color .15s, transform .15s;
}
.icon-btn:hover { background: #ffffff0d; color: var(--text); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.danger { color: var(--danger); }
.icon-btn svg { width: 22px; height: 22px; }

/* ------------------------------------------------------------------ layout */
.app { display: flex; height: 100dvh; width: 100%; position: relative; }
.chat {
  position: relative; flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  transition: margin-right .3s cubic-bezier(.2,.8,.2,1);
}

/* ------------------------------------------------------------------ header */
.chat-header {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px 0 14px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}
.peer { display: flex; align-items: center; gap: 12px; min-width: 0; text-align: left; padding: 6px 8px 6px 4px; border-radius: 12px; }
.peer:hover { background: #ffffff08; }
.peer-text { display: flex; flex-direction: column; min-width: 0; }
.peer-name { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-status { font-size: 13px; color: var(--muted); white-space: nowrap; display: flex; align-items: center; gap: 6px; transition: color .2s; }
.peer-status.online { color: var(--online); }
.peer-status.typing { color: var(--accent); }
.header-actions { display: flex; gap: 2px; align-items: center; }
.install-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px 0 10px; margin-right: 4px;
  border-radius: 999px; font-size: 13.5px; font-weight: 650; color: #fff;
  background: linear-gradient(135deg, var(--out1), var(--out2));
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent);
  animation: pop .3s ease-out;
}
.install-btn svg { width: 18px; height: 18px; }
.install-note { font-size: 13px; color: var(--muted); margin: 8px 2px 0; line-height: 1.5; }
.install-note b { color: var(--text); }

/* installed app: respect the phone's notch / status bar */
@media (display-mode: standalone) {
  .chat-header { padding-top: env(safe-area-inset-top); height: calc(var(--header-h) + env(safe-area-inset-top)); }
  .drawer-head { padding-top: env(safe-area-inset-top); height: calc(var(--header-h) + env(safe-area-inset-top)); }
}

.avatar-wrap { position: relative; flex: none; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; overflow: hidden;
  font-weight: 700; color: #fff; font-size: 16px; letter-spacing: .5px;
  background: linear-gradient(135deg, #6550ee, #2dd4bf);
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 112px; height: 112px; font-size: 40px; }
.online-dot {
  position: absolute; right: 0; bottom: 0; width: 13px; height: 13px; border-radius: 50%;
  background: var(--online); border: 2.5px solid var(--panel);
  transform: scale(0); transition: transform .25s cubic-bezier(.3,1.6,.5,1);
}
.online-dot.on { transform: scale(1); }

/* typing dots */
.typing-dots { display: inline-flex; gap: 3px; align-items: center; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: dot 1.2s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ------------------------------------------------------------------ search */
.search-panel {
  position: absolute; top: var(--header-h); left: 0; right: 0; z-index: 8;
  background: var(--panel); border-bottom: 1px solid var(--border);
  box-shadow: 0 18px 40px #0008;
  animation: dropIn .2s ease-out;
}
.search-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 16px; }
.search-ico { color: var(--muted); }
.search-ico svg { width: 20px; height: 20px; }
.search-row input { flex: 1; background: transparent; border: 0; outline: 0; font-size: 15px; padding: 8px 0; }
.search-results { max-height: min(60vh, 460px); overflow-y: auto; }
.search-results:empty { display: none; }
.result {
  width: 100%; display: flex; gap: 12px; align-items: center; text-align: left;
  padding: 10px 16px; border-top: 1px solid var(--border);
}
.result:hover { background: #ffffff08; }
.result .avatar { width: 36px; height: 36px; font-size: 14px; }
.result-body { flex: 1; min-width: 0; }
.result-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.result-top b { color: var(--text); font-weight: 600; }
.result-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-text mark { background: color-mix(in srgb, var(--accent) 40%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-empty { padding: 16px; color: var(--muted); text-align: center; border-top: 1px solid var(--border); }

/* ------------------------------------------------------------------ pinned */
.pinned-bar {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 7px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
  z-index: 4; animation: dropIn .25s ease-out;
}
.pinned-bar:hover { background: var(--panel-2); }
.pin-line { width: 3px; align-self: stretch; border-radius: 3px; background: var(--accent); }
.pin-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pin-title { font-size: 13px; color: var(--accent); font-weight: 600; }
.pin-text { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.pin-ico { color: var(--muted); }
.pin-ico svg { width: 18px; height: 18px; }
@keyframes dropIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- messages */
.messages-wrap { position: relative; flex: 1; min-height: 0; }
.messages {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden;
  padding: 10px 0 14px; overscroll-behavior: contain;
}
.app[data-wall="aurora"] .messages-wrap {
  background:
    radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #2dd4bf14, transparent 60%),
    radial-gradient(#ffffff09 1px, transparent 1.2px) 0 0 / 22px 22px,
    var(--bg);
}
.app[data-wall="midnight"] .messages-wrap {
  background:
    linear-gradient(#ffffff05 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, #ffffff05 1px, transparent 1px) 0 0 / 32px 32px,
    #070a0e;
}
.app[data-wall="ember"] .messages-wrap {
  background:
    radial-gradient(900px 500px at 0% 100%, #ff6b3d1c, transparent 60%),
    radial-gradient(800px 500px at 100% 0%, #ff3d8a17, transparent 60%),
    radial-gradient(#ffffff08 1px, transparent 1.2px) 0 0 / 26px 26px,
    #0d0a0c;
}
.app[data-wall="ocean"] .messages-wrap {
  background:
    radial-gradient(1000px 600px at 50% 120%, #1e7bff22, transparent 60%),
    radial-gradient(700px 400px at 0% 0%, #2dd4bf14, transparent 60%),
    #070c14;
}
.app[data-wall="plain"] .messages-wrap { background: var(--bg); }

.msg-list { max-width: 860px; margin: 0 auto; padding: 0 14px; display: flex; flex-direction: column; }
.loader-top { height: 0; display: grid; place-items: center; overflow: hidden; transition: height .2s; }
.loader-top.show { height: 40px; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid #ffffff22; border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); gap: 8px; pointer-events: none; }
.empty-emoji { font: 56px var(--emoji-font); animation: wave 2s ease-in-out infinite; transform-origin: 70% 70%; }
@keyframes wave { 0%, 60%, 100% { transform: rotate(0); } 10%, 30% { transform: rotate(16deg); } 20%, 40% { transform: rotate(-8deg); } }

.day-sep { position: sticky; top: 6px; z-index: 3; align-self: center; margin: 14px 0 6px; pointer-events: none; }
.day-sep span {
  display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 550;
  background: color-mix(in srgb, var(--panel-3) 80%, transparent); backdrop-filter: blur(8px);
  color: var(--text);
}
.unread-sep {
  align-self: stretch; text-align: center; margin: 10px -14px; padding: 5px; font-size: 13px; font-weight: 600;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* --- single message */
.msg { position: relative; display: flex; flex-direction: column; align-items: flex-start; padding: 1.5px 0; border-radius: 12px; }
.msg.out { align-items: flex-end; }
.msg.first { margin-top: 7px; }
.msg-row { display: flex; align-items: center; gap: 6px; width: 100%; }
.msg.out .msg-row { flex-direction: row-reverse; }

.bubble {
  position: relative; max-width: min(540px, 78%);
  padding: 7px 11px 7px 12px; border-radius: var(--radius);
  background: var(--in); color: var(--text);
  overflow-wrap: anywhere; word-break: break-word;
  box-shadow: 0 1px 1.5px #0005;
  transform-origin: left bottom;
}
.msg.out .bubble { background: linear-gradient(135deg, var(--out1), var(--out2)); color: #fff; transform-origin: right bottom; }
.msg.in:not(.first) .bubble { border-top-left-radius: 6px; }
.msg.in:not(.last) .bubble { border-bottom-left-radius: 6px; }
.msg.in.last .bubble { border-bottom-left-radius: 4px; }
.msg.out:not(.first) .bubble { border-top-right-radius: 6px; }
.msg.out:not(.last) .bubble { border-bottom-right-radius: 6px; }
.msg.out.last .bubble { border-bottom-right-radius: 4px; }
.bubble::after { content: ""; display: block; clear: both; }

.text { display: inline; white-space: pre-wrap; unicode-bidi: plaintext; }
.text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.msg.in .text a { color: var(--accent); }
.text code { font-family: ui-monospace, Consolas, monospace; font-size: 13.5px; background: #0000002e; padding: 1px 5px; border-radius: 5px; }
.text .spoiler { background: currentColor; border-radius: 4px; cursor: pointer; transition: background .3s; }
.text .spoiler.shown { background: #ffffff1a; }

.meta {
  float: right; position: relative; top: 5px;
  display: inline-flex; align-items: center; gap: 4px;
  margin: 2px -4px 0 12px; height: 16px;
  font-size: 11.5px; color: var(--muted); user-select: none; white-space: nowrap;
}
.msg.out .meta { color: #ffffffa8; }
.meta .edited { font-style: italic; }
.meta .pin-mark { font-size: 10px; }
.fx-replay { font-size: 12px; line-height: 1; opacity: .8; filter: saturate(1.3); }
.fx-replay:hover { opacity: 1; transform: scale(1.2); }

.ticks { display: inline-flex; color: inherit; }
.ticks svg { height: 11px; width: auto; }
.ticks.read { color: var(--read); }
.ticks.bump { animation: tick .35s cubic-bezier(.3,1.8,.5,1); }
.ticks.pending svg { width: 12px; height: 12px; animation: spin 2s linear infinite; }
.ticks.failed { color: #ffd1d6; }
@keyframes tick { 0% { transform: scale(.4); } 100% { transform: scale(1); } }

/* reply quote inside bubble */
.quote {
  display: flex; flex-direction: column; min-width: 0; cursor: pointer;
  margin: 1px -3px 5px -4px; padding: 4px 10px 5px; border-radius: 8px;
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-size: 13.5px;
}
.msg.out .quote { border-left-color: #fff; background: #ffffff22; }
.quote:hover { filter: brightness(1.15); }
.q-name { font-weight: 650; color: var(--accent); }
.msg.out .q-name { color: #fff; }
.q-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85; }

/* media */
.bubble.has-media { padding: 4px; }
.bubble.has-media .text, .bubble.has-media .quote { margin-left: 6px; margin-right: 6px; }
.bubble.has-media .text { display: inline-block; padding: 4px 0 2px; }
.bubble.has-media .meta { margin-right: 6px; margin-bottom: 4px; }
.media { position: relative; border-radius: 14px; overflow: hidden; background: #0000003a; }
.media img, .media video {
  display: block; max-width: min(360px, 66vw); max-height: 380px; min-width: 140px; min-height: 90px;
  object-fit: cover; cursor: zoom-in;
}
.bubble.has-media { max-width: min(372px, 84%); }
.media video { cursor: default; background: #000; }
.bubble.media-only .meta {
  position: absolute; right: 10px; bottom: 10px; top: auto; margin: 0; float: none;
  background: #0009; color: #fff; padding: 2px 7px; border-radius: 10px; height: 20px;
}
.bubble.media-only::after { display: none; }

.file-card {
  display: flex; align-items: center; gap: 12px; padding: 4px 8px 4px 2px; min-width: 220px; max-width: 320px;
  color: inherit; text-decoration: none;
}
.file-icon {
  width: 46px; height: 46px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-size: 11px; font-weight: 800; letter-spacing: .5px;
  background: color-mix(in srgb, var(--accent) 26%, #0003); color: #fff; position: relative; overflow: hidden;
}
.msg.out .file-icon { background: #ffffff2b; }
.file-icon svg { width: 22px; height: 22px; }
.file-card:hover .file-icon { filter: brightness(1.2); }
.file-info { min-width: 0; }
.file-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 12.5px; opacity: .7; }
.audio-player { width: 260px; max-width: 100%; height: 36px; margin: 4px 0 2px; display: block; }

/* voice message */
.voice { display: flex; align-items: center; gap: 10px; padding: 2px 4px 0 0; min-width: 230px; }
.vplay {
  width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--accent); color: #fff; transition: transform .15s;
}
.msg.out .vplay { background: #fff; color: var(--out1); }
.vplay:active { transform: scale(.9); }
.vplay svg { width: 20px; height: 20px; }
.vmain { flex: 1; min-width: 0; }
.vwave { position: relative; height: 28px; cursor: pointer; }
.vbars { position: absolute; inset: 0; display: flex; align-items: center; gap: 2px; }
.vbars i { flex: 1; border-radius: 2px; background: currentColor; opacity: .35; min-height: 3px; }
.vbars.fill i { opacity: 1; }
.vbars.fill { clip-path: inset(0 100% 0 0); color: var(--accent); }
.msg.out .vbars.fill { color: #fff; }
.vtime { font-size: 12px; opacity: .75; }

/* reactions */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: 3px 4px 1px; max-width: min(540px, 78%); }
.msg.out .reactions { justify-content: flex-end; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; height: 26px;
  border-radius: 999px; background: var(--panel-3); border: 1px solid var(--border);
  font-size: 15px; transition: transform .15s, background .15s;
}
.chip .e { font-family: var(--emoji-font); }
.chip:hover { transform: translateY(-1px); background: #263140; }
.chip.mine { background: color-mix(in srgb, var(--accent) 28%, var(--panel-3)); border-color: color-mix(in srgb, var(--accent) 70%, transparent); }
.chip small { font-size: 12px; color: var(--muted); font-weight: 600; }
.chip.pop { animation: chipPop .45s cubic-bezier(.3,1.8,.5,1); }
@keyframes chipPop { 0% { transform: scale(.3); } 100% { transform: scale(1); } }

/* hover tools */
.msg-tools { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-tools { opacity: 1; }
.msg-tools button {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  color: var(--muted); background: color-mix(in srgb, var(--panel-2) 80%, transparent);
}
.msg-tools button:hover { color: var(--text); background: var(--panel-3); }
.msg-tools svg { width: 17px; height: 17px; }
@media (hover: none) { .msg-tools { display: none; } }

/* deleted / pending / failed */
.msg.deleted .bubble { background: transparent !important; border: 1px dashed var(--border); color: var(--muted); box-shadow: none; }
.deleted-text { display: inline-flex; align-items: center; gap: 6px; font-style: italic; font-size: 14px; }
.deleted-text svg { width: 15px; height: 15px; }
.msg.deleted .meta { color: var(--faint); }
.msg.pending .bubble { opacity: .9; }
.msg.failed .bubble { box-shadow: 0 0 0 2px var(--danger); cursor: pointer; }
.upload-progress { position: absolute; inset: 0; display: grid; place-items: center; background: #0007; border-radius: inherit; }
.ring { width: 48px; height: 48px; position: relative; display: grid; place-items: center; }
.ring svg { position: absolute; inset: 0; width: 48px; height: 48px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3.5; }
.ring .bg { stroke: #ffffff33; }
.ring .fg { stroke: #fff; stroke-linecap: round; stroke-dasharray: 126; stroke-dashoffset: 126; transition: stroke-dashoffset .2s; }
.ring button { width: 30px; height: 30px; display: grid; place-items: center; color: #fff; }
.ring button svg { position: static; width: 16px; height: 16px; transform: none; }
.file-progress { position: relative; }

/* jumbo emoji */
.msg.jumbo .bubble { background: none !important; box-shadow: none; padding: 0 2px; }
.msg.jumbo .text { font: 52px/1.15 var(--emoji-font); display: block; }
.msg.jumbo .meta { float: none; top: 0; margin: 0; align-self: flex-end; padding: 2px 8px; border-radius: 10px; background: #0007; color: #fff; display: inline-flex; }
.msg.jumbo .bubble { display: flex; flex-direction: column; }
.msg.jumbo.out .bubble { align-items: flex-end; }
.msg.jumbo.in .bubble { align-items: flex-start; }
.msg.jumbo-pop .text { animation: jumbo .8s cubic-bezier(.3,1.6,.5,1); }
@keyframes jumbo { 0% { transform: scale(.2) rotate(-25deg); } 55% { transform: scale(1.3) rotate(8deg); } 100% { transform: none; } }

/* highlight (jump to) */
.msg.highlight { animation: hl 1.6s ease-out; }
@keyframes hl { 0%, 35% { background: color-mix(in srgb, var(--accent) 24%, transparent); } 100% { background: transparent; } }

/* appear + vanish */
.msg.appear .bubble { animation: appear .32s cubic-bezier(.2,.9,.3,1.25); }
@keyframes appear { from { opacity: 0; transform: translateY(14px) scale(.92); } to { opacity: 1; transform: none; } }
.msg.vanish .bubble { transition: transform .28s, opacity .28s, filter .28s; transform: scale(.7); opacity: 0; filter: blur(6px); }

/* ---- bubble effects */
.msg.fx-slam .bubble { animation: slam .7s cubic-bezier(.25,.9,.3,1.2) both; z-index: 2; }
@keyframes slam {
  0% { transform: scale(3) translateY(-60px); opacity: 0; filter: blur(3px); }
  50% { transform: scale(.9); opacity: 1; filter: none; }
  70% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
.chat.shake .messages { animation: shake .45s .3s; }
@keyframes shake {
  0%, 100% { transform: none; } 20% { transform: translate(-7px, 4px); } 40% { transform: translate(6px, -4px); }
  60% { transform: translate(-4px, 2px); } 80% { transform: translate(2px, -1px); }
}
.msg.fx-loud .bubble { animation: loud 1.4s cubic-bezier(.3,1.2,.4,1) both; z-index: 2; }
@keyframes loud {
  0% { transform: scale(.5); opacity: 0; }
  20% { transform: scale(1.8); opacity: 1; }
  30% { transform: scale(1.8) rotate(-4deg); }
  40% { transform: scale(1.8) rotate(4deg); }
  50% { transform: scale(1.8) rotate(-3deg); }
  60% { transform: scale(1.75) rotate(0); }
  100% { transform: scale(1); }
}
.msg.fx-gentle .bubble { animation: gentle 2.4s ease-out both; }
@keyframes gentle { 0% { transform: scale(.35); opacity: 0; filter: blur(8px); } 50% { opacity: .85; } 100% { transform: scale(1); opacity: 1; filter: none; } }

.msg.ink .bubble { cursor: pointer; }
.msg.ink .bubble > .text, .msg.ink .bubble > .media, .msg.ink .bubble > .voice, .msg.ink .bubble > .file-card {
  filter: blur(9px) saturate(.4); transition: filter .7s;
}
.msg.ink .bubble::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 1;
  background-image:
    radial-gradient(#ffffffb0 .8px, transparent 1.2px),
    radial-gradient(#ffffff70 .7px, transparent 1.1px);
  background-size: 7px 7px, 11px 11px;
  animation: ink 1.6s linear infinite; transition: opacity .6s;
}
@keyframes ink { to { background-position: 7px -7px, -11px 11px; } }
.msg.ink.revealed .bubble > * { filter: none; }
.msg.ink.revealed .bubble::before { opacity: 0; }

/* typing bubble */
.typing-bubble {
  max-width: 860px; margin: 6px auto 0; padding: 0 14px;
}
.typing-bubble .typing-dots {
  padding: 12px 16px; border-radius: 18px; border-bottom-left-radius: 4px;
  background: var(--in); color: var(--muted); animation: appear .25s ease-out;
}

/* jump to bottom */
.fab {
  position: absolute; right: 18px; bottom: 16px; z-index: 6;
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border); box-shadow: 0 6px 20px #0008;
  transform: translateY(20px) scale(.6); opacity: 0; pointer-events: none;
  transition: transform .25s cubic-bezier(.3,1.5,.5,1), opacity .2s;
}
.fab.show { transform: none; opacity: 1; pointer-events: auto; }
.fab svg { width: 22px; height: 22px; }
.badge {
  position: absolute; top: -6px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 11px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
  display: grid; place-items: center;
}

/* ---------------------------------------------------------------- composer */
.composer {
  position: relative; flex: none; z-index: 5;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.composer-row, .record-row { max-width: 860px; margin: 0 auto; display: flex; align-items: flex-end; gap: 6px; }
.input-wrap {
  flex: 1; min-width: 0; display: flex; align-items: flex-end;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 22px;
  padding-left: 16px; transition: border-color .2s, box-shadow .2s;
}
.input-wrap:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }
#input {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent;
  padding: 10px 0; max-height: 168px; line-height: 1.4; font-size: 15.5px;
  unicode-bidi: plaintext;
}
#input::placeholder { color: var(--faint); }
.fx-btn.armed { color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }

.send-btn {
  position: relative; width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--out1), var(--out2));
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform .15s, box-shadow .3s;
}
.send-btn:active { transform: scale(.9); }
.send-btn svg { width: 22px; height: 22px; }
.send-btn > span { position: absolute; display: grid; place-items: center; transition: transform .25s cubic-bezier(.3,1.5,.5,1), opacity .2s; }
.send-btn .send-ico { transform: scale(.3) rotate(-60deg); opacity: 0; }
.send-btn.has-text .send-ico { transform: none; opacity: 1; }
.send-btn.has-text .mic-ico { transform: scale(.3) rotate(60deg); opacity: 0; }
.send-btn.fx-armed { animation: armed 1.6s ease-in-out infinite; }
@keyframes armed { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 30%, transparent), 0 0 26px var(--accent); } }

.context-bar, .effect-chip { max-width: 860px; margin: 0 auto 8px; }
.context-bar { display: flex; align-items: center; gap: 10px; padding: 0 0 0 6px; animation: dropUp .18s ease-out; }
.ctx-icon { color: var(--accent); }
.ctx-icon svg { width: 22px; height: 22px; }
.ctx-body { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding: 1px 10px; }
.ctx-title { font-size: 13.5px; font-weight: 650; color: var(--accent); }
.ctx-text { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@keyframes dropUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.effect-chip {
  display: flex; width: fit-content; align-items: center; gap: 8px; padding: 5px 6px 5px 12px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, var(--panel-2)); border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
  font-size: 13.5px; font-weight: 600; animation: dropUp .18s ease-out;
}
.effect-chip button { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: #ffffff1a; }
.effect-chip button svg { width: 14px; height: 14px; }

.record-row { align-items: center; padding: 2px 0; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; margin-left: 4px; }
@keyframes blink { 50% { opacity: .2; } }
.rec-time { font-variant-numeric: tabular-nums; min-width: 44px; }
.rec-wave { flex: 1; height: 30px; display: flex; align-items: center; gap: 2px; overflow: hidden; justify-content: flex-end; }
.rec-wave i { width: 3px; flex: none; border-radius: 2px; background: var(--accent); min-height: 3px; }

/* popovers */
.popover {
  position: absolute; bottom: calc(100% + 8px); z-index: 20;
  background: color-mix(in srgb, var(--panel-2) 94%, transparent); backdrop-filter: blur(18px);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 20px 50px #000a;
  animation: pop .18s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }
.emoji-panel { right: max(12px, calc(50% - 430px)); width: min(360px, calc(100vw - 24px)); height: 340px; display: flex; flex-direction: column; overflow: hidden; }
.emoji-cats { display: flex; gap: 2px; padding: 6px; border-bottom: 1px solid var(--border); overflow-x: auto; flex: none; }
.emoji-cats button { width: 36px; height: 34px; border-radius: 10px; font: 19px var(--emoji-font); flex: none; opacity: .6; }
.emoji-cats button.active, .emoji-cats button:hover { background: #ffffff12; opacity: 1; }
.emoji-grid { flex: 1; overflow-y: auto; padding: 6px 8px 10px; }
.emoji-grid h4 { margin: 8px 4px 4px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .6px; }
.emoji-grid .grid { display: grid; grid-template-columns: repeat(8, 1fr); }
.emoji-grid button { height: 38px; border-radius: 10px; font: 24px/1 var(--emoji-font); transition: transform .1s; }
.emoji-grid button:hover { background: #ffffff14; transform: scale(1.18); }

.fx-panel { right: max(60px, calc(50% - 380px)); width: min(340px, calc(100vw - 24px)); padding: 14px; }
.fx-panel h4 { margin: 2px 2px 10px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.fx-panel h4 + .fx-grid { margin-bottom: 14px; }
.fx-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.fx-grid button {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: 14px;
  background: var(--panel-3); border: 1px solid transparent; font-size: 13px; transition: transform .15s, border-color .15s;
}
.fx-grid button span { font: 24px var(--emoji-font); }
.fx-grid button:hover { transform: translateY(-2px); border-color: var(--border); }
.fx-grid button.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--panel-3)); }
.fx-note { font-size: 12px; color: var(--muted); margin: 4px 2px 0; }

/* ------------------------------------------------------------ context menu */
.ctx-menu {
  position: fixed; z-index: 50; min-width: 220px;
  background: color-mix(in srgb, var(--panel-2) 94%, transparent); backdrop-filter: blur(18px);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 24px 60px #000b;
  padding: 6px; animation: pop .15s ease-out;
}
.quick { display: flex; gap: 2px; padding: 2px 2px 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.quick button { width: 36px; height: 36px; border-radius: 50%; font: 22px/1 var(--emoji-font); transition: transform .15s; }
.quick button:hover { transform: scale(1.3); background: #ffffff10; }
.quick button.mine { background: color-mix(in srgb, var(--accent) 30%, transparent); }
.quick .more { font: 600 18px var(--font); color: var(--muted); }
.ctx-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border-radius: 10px; text-align: left; font-size: 14.5px; }
.ctx-item:hover { background: #ffffff0d; }
.ctx-item svg { width: 19px; height: 19px; color: var(--muted); }
.ctx-item.danger, .ctx-item.danger svg { color: var(--danger); }

/* ------------------------------------------------------------------ drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--drawer-w); z-index: 30;
  background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
}
.app.drawer-open .drawer { transform: none; }
@media (min-width: 1100px) { .app.drawer-open .chat { margin-right: var(--drawer-w); } }
@media (max-width: 1099px) { .app.drawer-open .drawer { box-shadow: -20px 0 60px #000a; } }
@media (max-width: 560px) { .drawer { width: 100%; } }
.drawer-head { height: var(--header-h); flex: none; display: flex; align-items: center; gap: 8px; padding: 0 10px; font-weight: 650; font-size: 16px; border-bottom: 1px solid var(--border); }
.tabs { display: flex; padding: 0 6px; border-bottom: 1px solid var(--border); overflow-x: auto; flex: none; }
.tabs button { padding: 12px 10px; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; flex: 1; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; }

.profile { text-align: center; padding: 10px 0 4px; }
.profile .avatar { margin: 0 auto 12px; }
.profile h2 { margin: 0; font-size: 21px; }
.profile .status { color: var(--muted); font-size: 14px; margin-top: 4px; }
.profile .status.online { color: var(--online); }
.info-list { margin-top: 20px; display: flex; flex-direction: column; gap: 2px; text-align: left; }
.info-row { padding: 10px 12px; border-radius: 12px; background: var(--panel-2); }
.info-row small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.stats div { background: var(--panel-2); border-radius: 12px; padding: 10px 6px; text-align: center; }
.stats b { display: block; font-size: 18px; }
.stats span { font-size: 12px; color: var(--muted); }

.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.media-grid button { position: relative; aspect-ratio: 1; overflow: hidden; border-radius: 8px; background: var(--panel-2); }
.media-grid img, .media-grid video { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.media-grid button:hover img, .media-grid button:hover video { transform: scale(1.06); }
.media-grid .play-badge { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; background: #0003; }
.media-grid .play-badge svg { width: 30px; height: 30px; filter: drop-shadow(0 2px 6px #000a); }
.drawer-list { display: flex; flex-direction: column; gap: 6px; }
.drawer-list .file-card, .pin-item {
  padding: 8px 10px; border-radius: 12px; background: var(--panel-2); max-width: none; width: 100%; text-align: left;
}
.drawer-list .file-card:hover, .pin-item:hover { background: var(--panel-3); }
.pin-item { display: block; }
.pin-item small { color: var(--muted); display: block; font-size: 12px; margin-bottom: 2px; }
.pin-item div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.drawer-empty span { display: block; font: 40px var(--emoji-font); margin-bottom: 8px; }

/* settings */
.settings section { margin-bottom: 24px; }
.settings h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); margin: 0 0 10px; font-weight: 650; }
.me-card { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.avatar-edit { position: relative; border-radius: 50%; }
.avatar-edit .avatar { width: 72px; height: 72px; font-size: 26px; }
.avatar-edit::after {
  content: "Change"; position: absolute; inset: 0; border-radius: 50%; display: grid; place-items: center;
  background: #0009; font-size: 12px; font-weight: 600; opacity: 0; transition: opacity .2s;
}
.avatar-edit:hover::after { opacity: 1; }
.me-card .who b { display: block; font-size: 16px; }
.me-card .who span { color: var(--muted); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.field input, .field textarea {
  width: 100%; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); outline: 0; font-size: 15px; resize: vertical;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.btn-primary, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px; border-radius: 12px; font-weight: 650;
  transition: transform .12s, filter .2s, opacity .2s;
}
.btn-primary { width: 100%; color: #fff; background: linear-gradient(135deg, var(--out1), var(--out2)); box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:active, .btn:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn { background: var(--panel-3); border: 1px solid var(--border); }
.btn:hover { background: #263140; }
.btn.danger { color: var(--danger); }
.btn.full { width: 100%; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; outline: 2px solid transparent;
  transition: transform .15s, outline-color .15s;
}
.swatch:hover { transform: scale(1.1); }
.swatch.active { outline-color: var(--text); outline-offset: 2px; }
.walls { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.wall { aspect-ratio: .7; border-radius: 10px; border: 2px solid var(--border); font-size: 10px; color: var(--muted); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 4px; }
.wall.active { border-color: var(--accent); color: var(--text); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 2px; font-size: 14.5px; }
.switch { position: relative; width: 44px; height: 26px; border-radius: 13px; background: var(--panel-3); border: 1px solid var(--border); flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .25s cubic-bezier(.3,1.5,.5,1); }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); }

/* ---------------------------------------------------------------- lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 60; background: #000000eb; backdrop-filter: blur(6px);
  display: flex; flex-direction: column; animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.lb-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; color: #fff; }
.lb-bar .lb-title { flex: 1; min-width: 0; font-size: 14px; }
.lb-bar .lb-title small { display: block; color: #ffffff99; }
.lb-bar .icon-btn { color: #fff; }
.lb-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 16px 24px; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 100%; border-radius: 8px; animation: zoomIn .25s cubic-bezier(.2,.9,.3,1.1); }
@keyframes zoomIn { from { transform: scale(.85); opacity: 0; } }

/* ------------------------------------------------------- drop, modal, toast */
.drop-overlay {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 20px;
  background: #0a0d12cc; backdrop-filter: blur(4px); pointer-events: none;
}
.drop-overlay > div {
  width: min(520px, 100%); height: 240px; border-radius: 24px; border: 2.5px dashed var(--accent);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-size: 18px; font-weight: 600;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.drop-overlay svg { width: 40px; height: 40px; color: var(--accent); }
.modal-backdrop { position: fixed; inset: 0; z-index: 80; background: #0009; display: grid; place-items: center; padding: 20px; animation: fade .15s; }
.modal { width: min(380px, 100%); background: var(--panel-2); border: 1px solid var(--border); border-radius: 18px; padding: 20px; box-shadow: 0 30px 80px #000c; animation: pop .2s; }
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal p { margin: 0 0 18px; color: var(--muted); }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal .btn-primary.danger { background: var(--danger); box-shadow: none; width: auto; }
.toast {
  position: fixed; left: 50%; bottom: 96px; z-index: 90; max-width: calc(100vw - 32px);
  padding: 10px 18px; border-radius: 12px; background: #e7edf3; color: #0a0d12; font-weight: 600; font-size: 14px;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: transform .25s, opacity .25s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

.fx-canvas { position: fixed; inset: 0; z-index: 75; pointer-events: none; }

/* ------------------------------------------------------------------ mobile */
@media (max-width: 640px) {
  .msg-list { padding: 0 8px; }
  .bubble { max-width: 84%; }
  .reactions { max-width: 84%; }
  .composer { padding-left: 6px; padding-right: 6px; }
  .composer-row { gap: 2px; }
  .fx-panel, .emoji-panel { right: 6px; }
  .media img, .media video { max-width: min(280px, 72vw); }
}

/* =================================================================== LOGIN */
.login-page { display: grid; place-items: center; min-height: 100dvh; padding: 20px; overflow: auto; }
.login-bg { position: fixed; inset: 0; overflow: hidden; z-index: -1; }
.login-bg span { position: absolute; border-radius: 50%; filter: blur(80px); opacity: .55; animation: float 16s ease-in-out infinite alternate; }
.login-bg span:nth-child(1) { width: 480px; height: 480px; background: #6550ee; top: -140px; left: -120px; }
.login-bg span:nth-child(2) { width: 420px; height: 420px; background: #13a99a; bottom: -160px; right: -100px; animation-delay: -5s; }
.login-bg span:nth-child(3) { width: 300px; height: 300px; background: #d63c74; top: 40%; left: 55%; opacity: .25; animation-delay: -9s; }
@keyframes float { to { transform: translate(60px, 40px) scale(1.15); } }
.login-card {
  width: min(400px, 100%); padding: 34px 28px 28px; border-radius: 26px;
  background: color-mix(in srgb, var(--panel) 80%, transparent); backdrop-filter: blur(24px);
  border: 1px solid #ffffff14; box-shadow: 0 40px 100px #000b;
  text-align: center; animation: pop .4s cubic-bezier(.2,.9,.3,1.2);
}
.login-card.shake { animation: shakeX .45s; }
.login-card.success { transform: scale(.96); opacity: 0; transition: transform .35s, opacity .35s; }
@keyframes shakeX { 0%, 100% { transform: none; } 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.login-logo { width: 64px; height: 64px; margin-bottom: 10px; border-radius: 18px; box-shadow: 0 10px 30px #6550ee55; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-sub { color: var(--muted); margin: 6px 0 24px; }
.login-card .field { text-align: left; }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 44px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.pw-toggle:hover { color: var(--text); }
.login-error { min-height: 20px; color: var(--danger); font-size: 14px; margin: 2px 0 10px; }
.btn-primary.loading span { opacity: 0; }
.btn-primary.loading { position: relative; }
.btn-primary.loading::after { content: ""; position: absolute; width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid #ffffff55; border-top-color: #fff; animation: spin .8s linear infinite; }
