@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Space+Grotesk:wght@500;600;700&family=Fraunces:opsz,wght@9..144,500;9..144,600&family=Nunito:wght@500;700&display=swap');

:root {
  --screen: #15121B; --chatBg: #15121B; --text: #F3EEF7; --meta: #A89DB5; --line: #2E2838;
  --accent: #F5A3C7; --onAccent: #2A1020; --meBubble: #F5A3C7; --meText: #2A1020;
  --themBubble: #241F2D; --themText: #F3EEF7; --font: system-ui, sans-serif;
  --in-radius: 18px 18px 18px 4px; --out-radius: 18px 18px 4px 18px;
  --in-border: 0; --out-border: 0; --in-tail: block; --out-tail: block;
  --avatar-radius: 50%; --dim: 0;
}
* { box-sizing: border-box; min-width: 0; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--screen); color: var(--text); font: 16px/1.45 var(--font); overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }
.sr { position: absolute; left: -9999px; }

#app { height: 100dvh; display: flex; flex-direction: column; position: relative; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--screen); }
.top { display: flex; align-items: center; gap: 6px; padding: max(env(safe-area-inset-top), 14px) 10px 8px; }
.top h1 { margin: 0; flex: 1; font-size: 22px; font-weight: 600; }
.top h1.big { font-size: 30px; font-weight: 700; padding-left: 8px; }
.icon-btn { width: 44px; height: 44px; flex: none; border: 0; border-radius: 22px; background: transparent; color: var(--text); display: grid; place-items: center; padding: 0; }
.icon-btn.filled { background: color-mix(in srgb, var(--text) 8%, transparent); }
.icon-btn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.pill { height: 40px; padding: 0 16px; border-radius: 20px; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 14px; font-weight: 500; }
.pill.on, .btn { background: var(--accent); color: var(--onAccent); border-color: var(--accent); }
.btn { height: 48px; padding: 0 20px; border-radius: 24px; border: 0; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: #FF9DAF; color: #2A0A12; }
.field { width: 100%; height: 48px; padding: 0 16px; border-radius: 16px; border: 1px solid var(--line); background: color-mix(in srgb, var(--text) 6%, transparent); outline: none; font-size: 16px; }
.field:focus { border-color: var(--accent); }
.muted { color: var(--meta); }
.small { font-size: 13px; }
.section-label { font-size: 13px; font-weight: 600; color: var(--meta); margin: 0 0 10px; }

/* avatars */
.av { width: 52px; height: 52px; flex: none; border-radius: var(--avatar-radius); display: grid; place-items: center; font-weight: 600; font-size: 18px; overflow: hidden; background: color-mix(in srgb, var(--accent) 22%, var(--screen)); color: var(--accent); }
.av img { width: 100%; height: 100%; object-fit: cover; }
.av.sm { width: 32px; height: 32px; font-size: 13px; }
.av.md { width: 44px; height: 44px; font-size: 15px; }

/* chat list */
.search-link { margin: 4px 16px 12px; height: 48px; border-radius: 24px; display: flex; align-items: center; gap: 10px; padding: 0 16px; background: color-mix(in srgb, var(--text) 7%, transparent); color: var(--meta); border: 0; width: calc(100% - 32px); text-align: left; }
.pins { display: flex; gap: 14px; padding: 2px 18px 12px; overflow-x: auto; }
.pin { width: 64px; flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px; border: 0; background: transparent; padding: 0; }
.pin .av { width: 58px; height: 58px; font-size: 19px; box-shadow: 0 0 0 2px var(--screen), 0 0 0 4px var(--ring, transparent); }
.pin span { font-size: 12px; max-width: 64px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row { width: 100%; border: 0; background: transparent; display: flex; align-items: center; gap: 14px; padding: 10px 18px; text-align: left; user-select: none; }
.row.sel { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.row .main { flex: 1; }
.row .line1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.row .name { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.unread .name, .row.unread .prev { font-weight: 600; color: var(--text); }
.row .time { font-size: 12px; color: var(--meta); flex: none; }
.row .prev { font-size: 14px; color: var(--meta); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--onAccent); font-size: 12px; font-weight: 600; display: inline-grid; place-items: center; }
.tag { padding: 1px 5px; border-radius: 5px; font-size: 10px; font-weight: 700; background: color-mix(in srgb, var(--text) 10%, transparent); color: var(--meta); margin-left: 6px; vertical-align: 2px; }
.fab { position: absolute; right: 18px; bottom: max(env(safe-area-inset-bottom), 22px); height: 56px; padding: 0 22px; border-radius: 20px; border: 0; background: var(--accent); color: var(--onAccent); font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.35); display: flex; align-items: center; gap: 8px; }
.selbar { display: flex; align-items: center; gap: 4px; padding: max(env(safe-area-inset-top), 14px) 10px 10px; background: color-mix(in srgb, var(--text) 8%, var(--screen)); }
.selbar span { flex: 1; font-size: 19px; font-weight: 600; }
.banner { margin: 0 14px 10px; padding: 10px 12px; border-radius: 14px; font-size: 13px; line-height: 1.4; display: flex; gap: 10px; align-items: flex-start; }
.banner.warn { background: #3A2A12; color: #FFD9A0; }
.banner.info { background: color-mix(in srgb, var(--accent) 18%, var(--screen)); color: var(--text); }
.banner button { margin-left: auto; flex: none; }

/* conversation */
.chat-bg { position: absolute; inset: 0; background: var(--chatBg); overflow: hidden; pointer-events: none; }
.chat-bg img, .chat-bg video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.chat-bg .dim { position: absolute; inset: 0; background: rgba(0,0,0,var(--dim)); }
.fx { position: absolute; inset: 0; overflow: hidden; }
.fx span { position: absolute; line-height: 1; will-change: transform; }
.chat-top { position: relative; z-index: 2; background: color-mix(in srgb, var(--screen) 82%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.chat-top .who { flex: 1; }
.chat-top .who b { display: block; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-top .who small { font-size: 12px; color: var(--meta); }
.msgs { position: relative; z-index: 1; flex: 1; overflow-y: auto; padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 4px; }
.msgs > :first-child { margin-top: auto; }
.bub.media img, .bub.media video { min-width: 120px; min-height: 90px; background: color-mix(in srgb, var(--text) 8%, transparent); }
.day { align-self: center; font-size: 12px; color: var(--meta); margin: 10px 0 6px; }
.m { display: flex; flex-direction: column; max-width: 80%; }
.m.me { align-self: flex-end; align-items: flex-end; }
.m.them { align-self: flex-start; align-items: flex-start; }
.m .sender { font-size: 12px; color: var(--meta); margin: 6px 0 2px 10px; }
.bub { position: relative; padding: 9px 14px; font-size: 15px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; border: 0; text-align: left; }
.me .bub { background: var(--meBubble); color: var(--meText); border-radius: var(--out-radius); border: var(--out-border); }
.them .bub { background: var(--themBubble); color: var(--themText); border-radius: var(--in-radius); border: var(--in-border); }
.bub .tail { position: absolute; bottom: -6px; width: 14px; height: 12px; overflow: visible; }
.me .bub .tail { right: 4px; display: var(--out-tail); fill: var(--meBubble); }
.them .bub .tail { left: 4px; transform: scaleX(-1); display: var(--in-tail); fill: var(--themBubble); }
.m.cont .bub .tail { display: none; }
.bub.media { padding: 0; background: transparent !important; border: 0 !important; overflow: hidden; border-radius: 16px; }
.bub.media img, .bub.media video { display: block; max-width: 260px; max-height: 320px; border-radius: 16px; }
.bub .quote { display: block; font-size: 13px; opacity: .8; border-left: 3px solid currentColor; padding-left: 8px; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.file-chip { display: flex; gap: 8px; align-items: center; padding: 10px 14px; text-decoration: none; color: inherit; }
.reacts { display: flex; gap: 4px; margin-top: -6px; z-index: 1; }
.reacts span { height: 24px; padding: 0 7px; border-radius: 12px; background: color-mix(in srgb, var(--text) 12%, var(--screen)); border: 2px solid var(--chatBg); font-size: 13px; display: inline-flex; align-items: center; gap: 3px; }
.reacts span.mine { border-color: var(--accent); }
.stat { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--meta); margin: 3px 4px 4px; }
.stat svg { width: 14px; height: 14px; }
.typing { align-self: flex-start; display: flex; gap: 4px; padding: 12px 14px; border-radius: 18px 18px 18px 4px; background: var(--themBubble); margin: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 4px; background: var(--meta); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3 } 40% { opacity: 1 } }
.picker { display: flex; flex-direction: column; gap: 6px; margin: 4px 0; }
.picker .emo { display: flex; gap: 2px; padding: 4px; border-radius: 24px; background: color-mix(in srgb, var(--text) 10%, var(--screen)); box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.picker .emo button { width: 40px; height: 40px; border: 0; border-radius: 20px; background: transparent; font-size: 22px; }
.picker .emo button.on { background: color-mix(in srgb, var(--accent) 30%, transparent); }
.picker .acts { display: flex; gap: 6px; }
.picker .acts button { height: 34px; padding: 0 12px; border-radius: 17px; border: 0; background: color-mix(in srgb, var(--text) 10%, var(--screen)); font-size: 13px; }
.compose { position: relative; z-index: 2; padding: 8px 10px max(env(safe-area-inset-bottom), 12px); display: flex; flex-direction: column; gap: 6px; background: color-mix(in srgb, var(--screen) 82%, transparent); backdrop-filter: blur(12px); }
.compose .bar { display: flex; align-items: flex-end; gap: 8px; }
.compose .box { flex: 1; display: flex; align-items: flex-end; min-height: 44px; border-radius: 22px; background: color-mix(in srgb, var(--text) 8%, transparent); padding: 0 4px 0 16px; }
.compose textarea { flex: 1; border: 0; background: transparent; outline: none; resize: none; padding: 11px 0; max-height: 140px; font-size: 16px; line-height: 1.4; }
.send { background: var(--accent) !important; color: var(--onAccent) !important; }
.replybar, .attbar { display: flex; align-items: center; gap: 10px; padding: 8px 6px 8px 12px; border-radius: 14px; background: color-mix(in srgb, var(--text) 8%, transparent); font-size: 13px; }
.replybar { border-left: 3px solid var(--accent); }
.replybar div { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attbar img { width: 48px; height: 48px; object-fit: cover; border-radius: 10px; }

/* full-screen reaction burst */
.burst { position: absolute; inset: 0; z-index: 50; pointer-events: none; overflow: hidden; }
.burst .dimmer { position: absolute; inset: 0; background: rgba(8,6,12,.5); animation: bDim 1.8s ease both; }
.burst .big { position: absolute; inset: 0; display: grid; place-items: center; font-size: 150px; animation: bPop 1.8s cubic-bezier(.2,.8,.2,1) both; }
.burst span.p { position: absolute; bottom: -60px; animation: bFloat var(--d) ease-out var(--dl) both; }
@keyframes bDim { 0% { opacity: 0 } 15%, 75% { opacity: 1 } 100% { opacity: 0 } }
@keyframes bPop { 0% { transform: scale(.2); opacity: 0 } 22% { transform: scale(1.18); opacity: 1 } 40% { transform: scale(1) } 78% { opacity: 1 } 100% { transform: scale(1.5); opacity: 0 } }
@keyframes bFloat { 0% { transform: translateY(0) scale(.6); opacity: 0 } 15% { opacity: 1 } 100% { transform: translateY(-110vh) rotate(25deg); opacity: 0 } }

/* animated backgrounds */
@keyframes fxFall { 0% { transform: translate(0,-30px) rotate(0) } 25% { transform: translate(var(--dx), calc(var(--dist) * .25)) rotate(calc(var(--rot) * .25)) } 50% { transform: translate(calc(var(--dx) * -.6), calc(var(--dist) * .5)) rotate(calc(var(--rot) * .5)) } 75% { transform: translate(calc(var(--dx) * .8), calc(var(--dist) * .75)) rotate(calc(var(--rot) * .75)) } 100% { transform: translate(0, var(--dist)) rotate(var(--rot)) } }
@keyframes fxRise { 0% { transform: translate(0,30px) scale(.7); opacity: 0 } 12% { opacity: var(--op) } 35% { transform: translate(var(--dx), calc(var(--dist) * -.35)) scale(.9) rotate(calc(var(--rot) * .4)) } 70% { transform: translate(calc(var(--dx) * -.7), calc(var(--dist) * -.7)) rotate(calc(var(--rot) * -.3)) } 100% { transform: translate(calc(var(--dx) * .4), calc(var(--dist) * -1)) scale(1.1) rotate(var(--rot)); opacity: 0 } }
@keyframes fxTwinkle { 0%, 100% { opacity: .1; transform: scale(.6) } 50% { opacity: var(--op); transform: scale(1.15) rotate(var(--rot)) } }
@keyframes fxDrift { 0%, 100% { transform: translate(-20%,-10%) scale(1) } 50% { transform: translate(25%,15%) scale(1.25) } }
@media (prefers-reduced-motion: reduce) { .fx span, .burst { animation: none !important; display: none; } }

/* sheets & settings */
.sheet-wrap { position: absolute; inset: 0; z-index: 40; background: rgba(8,6,12,.55); display: flex; align-items: flex-end; }
.sheet { width: 100%; max-height: 90%; overflow-y: auto; background: color-mix(in srgb, var(--text) 6%, var(--screen)); border-radius: 26px 26px 0 0; padding: 18px 16px max(env(safe-area-inset-bottom), 22px); display: flex; flex-direction: column; gap: 10px; }
.sheet h2 { margin: 0 4px 4px; font-size: 21px; }
.sheet .opt { min-height: 52px; border-radius: 16px; border: 0; background: color-mix(in srgb, var(--text) 7%, transparent); text-align: left; padding: 0 16px; font-size: 15px; }
.set { padding: 0 18px 30px; display: flex; flex-direction: column; gap: 22px; }
.seg { display: flex; padding: 4px; border-radius: 22px; border: 1px solid var(--line); }
.seg button { flex: 1; height: 38px; border: 0; border-radius: 18px; background: transparent; font-size: 13px; font-weight: 600; }
.seg button.on { background: var(--accent); color: var(--onAccent); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { height: 40px; padding: 0 14px; border-radius: 12px; border: 2px solid var(--line); background: transparent; font-size: 13px; font-weight: 500; }
.chip.on { border-color: var(--accent); }
.colorrow { display: flex; align-items: center; gap: 10px; min-height: 52px; border-bottom: 1px solid var(--line); }
.colorrow label { flex: 1; font-size: 14px; }
.hex { width: 100px; height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: transparent; font-family: ui-monospace, monospace; font-size: 14px; text-transform: uppercase; outline: none; }
.hex.bad { border-color: #FF6B6B; }
input[type=color] { -webkit-appearance: none; appearance: none; width: 40px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: transparent; }
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: none; border-radius: 9px; }
.slider { display: flex; align-items: center; gap: 12px; }
.slider label { width: 110px; font-size: 14px; }
.slider input { flex: 1; accent-color: var(--accent); }
.switch { width: 52px; height: 32px; border: 0; border-radius: 16px; padding: 3px; background: var(--line); display: flex; }
.switch i { width: 26px; height: 26px; border-radius: 13px; background: #fff; }
.switch.on { background: var(--accent); justify-content: flex-end; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.box { border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.preview { position: relative; margin: 0 16px 12px; height: 180px; border-radius: 22px; overflow: hidden; border: 1px solid var(--line); flex: none; }
.preview .inner { position: absolute; inset: 0; padding: 14px; display: flex; flex-direction: column; justify-content: flex-end; gap: 10px; }
.toast { position: absolute; left: 16px; right: 16px; bottom: max(env(safe-area-inset-bottom), 24px); z-index: 60; padding: 14px 16px; border-radius: 16px; background: var(--text); color: var(--screen); font-size: 14px; font-weight: 500; }
.empty { padding: 70px 30px; text-align: center; color: var(--meta); }
mark { background: var(--accent); color: var(--onAccent); border-radius: 4px; padding: 0 2px; }
.login { margin: auto; width: min(420px, 100%); padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0 0 6px; font-size: 32px; }
