:root {
  --bg: #0f1020;
  --bg2: #15172b;
  --panel: #1a1c33;
  --line: #2a2d4a;
  --text: #ecebf7;
  --muted: #9396b4;
  --in: #22253f;
  --accent: #8b6dff;
  --accent2: #ff5c8a;
  --grad: linear-gradient(135deg, #7b61ff 0%, #b14dff 55%, #ff5c8a 100%);
  --ok: #3ddc97;
  --bad: #ff6b6b;
  --warn: #ffb547;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --r: 18px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f4fb; --bg2: #ecebf7; --panel: #ffffff; --line: #e1e0ee; --text: #17182b; --muted: #6c6f8c;
    --in: #ffffff; --shadow: 0 10px 40px rgba(40, 30, 90, .15); color-scheme: light;
  }
}

/* ---------- темы (выбираются в настройках; без выбора — "Авто" по системе) ---------- */
:root[data-theme="midnight"] {
  --bg: #0f1020; --bg2: #15172b; --panel: #1a1c33; --line: #2a2d4a; --text: #ecebf7; --muted: #9396b4; --in: #22253f;
  --accent: #8b6dff; --accent2: #ff5c8a; --grad: linear-gradient(135deg, #7b61ff 0%, #b14dff 55%, #ff5c8a 100%);
  --shadow: 0 10px 40px rgba(0, 0, 0, .45); color-scheme: dark;
}
:root[data-theme="dawn"] {
  --bg: #fff6f2; --bg2: #fbe9e3; --panel: #ffffff; --line: #f1d9d0; --text: #2b1a20; --muted: #8c6f78; --in: #ffffff;
  --accent: #f0546f; --accent2: #ff9a5c; --grad: linear-gradient(135deg, #ff9a5c 0%, #ff5c8a 55%, #c85cff 100%);
  --shadow: 0 10px 40px rgba(120, 50, 40, .14); color-scheme: light;
}
:root[data-theme="ocean"] {
  --bg: #06131d; --bg2: #0c1f2d; --panel: #0f2535; --line: #1c3a4f; --text: #e5f3fb; --muted: #8eb0c4; --in: #12304a;
  --accent: #39c2ff; --accent2: #2de2c2; --grad: linear-gradient(135deg, #2b6bff 0%, #22b8e6 55%, #2de2c2 100%);
  --shadow: 0 10px 40px rgba(0, 0, 0, .5); color-scheme: dark;
}
:root[data-theme="forest"] {
  --bg: #0a130f; --bg2: #0f1e17; --panel: #12241b; --line: #20392c; --text: #e7f5ec; --muted: #92b29f; --in: #163023;
  --accent: #4fd38b; --accent2: #c8e86b; --grad: linear-gradient(135deg, #129a55 0%, #3fc97f 55%, #b5dd5e 100%);
  --shadow: 0 10px 40px rgba(0, 0, 0, .5); color-scheme: dark;
}
:root[data-theme="cherry"] {
  --bg: #150910; --bg2: #200f18; --panel: #25111b; --line: #3c1c2a; --text: #fbe8ef; --muted: #c19aab; --in: #2d1521;
  --accent: #ff4f7b; --accent2: #ff9a5c; --grad: linear-gradient(135deg, #b0124f 0%, #ff4f7b 55%, #ff9a5c 100%);
  --shadow: 0 10px 40px rgba(0, 0, 0, .5); color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); transition: background-color .3s; }
body {
  background:
    radial-gradient(circle at 15% -5%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 45%),
    radial-gradient(circle at 95% 105%, color-mix(in srgb, var(--accent2) 18%, transparent), transparent 45%),
    var(--bg);
}
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
/* Приложение занимает ровно видимую область экрана: на iPhone (иконка на «Домой»,
   прозрачная строка состояния) 100% высоты короче экрана — снизу оставалась пустая полоса.
   --app-h / --app-top выставляет JS по visualViewport (учитывает и клавиатуру). */
#app {
  position: fixed; left: 0; right: 0; top: var(--app-top, 0px);
  height: var(--app-h, 100dvh); transition: filter .15s;
}
body.veil #app { filter: blur(24px); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- иконки ---------- */
.ic { display: inline-flex; width: 22px; height: 22px; flex: none; }
.ic svg { width: 100%; height: 100%; }
.ic.tiny { width: 12px; height: 12px; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 600; font-size: 15px;
  background: var(--bg2); transition: transform .1s, filter .2s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn .ic { width: 18px; height: 18px; }
.btn.primary { background: var(--grad); color: #fff; box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: rgba(255, 107, 107, .12); color: var(--bad); border: 1px solid rgba(255, 107, 107, .35); }
.btn.wide { width: 100%; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 8px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px;
  border-radius: 50%; border: 0; background: transparent; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--bg2); color: var(--text); }
.icon-btn.ok { color: var(--ok); }
.icon-btn.attn { color: var(--warn); }
.field {
  width: 100%; padding: 13px 15px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg2); outline: none; font-size: 16px;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.field.center { text-align: center; letter-spacing: 4px; font-size: 20px; }
.field.mono { font: 13px ui-monospace, Consolas, monospace; }
select.field { appearance: none; }
.lbl { display: grid; gap: 8px; font-size: 14px; color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; margin: 0; font-size: 14px; }
.note { color: var(--muted); font-size: 13.5px; margin: 0; }
.note.warn { color: var(--warn); display: flex; gap: 8px; align-items: flex-start; text-align: left; }
.note.warn .ic { width: 18px; height: 18px; margin-top: 1px; }

/* ---------- онбординг ---------- */
.onb {
  min-height: 100%; max-width: 420px; margin: 0 auto; padding: max(40px, env(safe-area-inset-top)) 24px 32px;
  display: flex; flex-direction: column; align-items: stretch; justify-content: center; gap: 14px; text-align: center;
  overflow-y: auto; height: 100%;
}
.onb h1 { font-size: 34px; margin: 4px 0 0; letter-spacing: -.5px; }
.onb h2 { margin: 4px 0; }
.lead { color: var(--muted); margin: 0 0 8px; font-size: 17px; }
.logo {
  width: 64px; height: 64px; border-radius: 20px; background: var(--grad); color: #fff; margin: 0 auto;
  display: grid; place-items: center; box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 40%, transparent);
}
.logo .ic { width: 32px; height: 32px; }
.logo.big { width: 88px; height: 88px; border-radius: 28px; }
.logo.big .ic { width: 44px; height: 44px; }
.features { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 10px; text-align: left; }
.features li { display: flex; gap: 12px; align-items: center; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; font-size: 14.5px; }
.features .ic { color: var(--accent); }
.actions { display: grid; gap: 10px; margin-top: 6px; }
.paste { display: grid; gap: 10px; }
.lock { gap: 16px; }

/* ---------- чат ---------- */
.chat {
  height: 100%; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; position: relative; isolation: isolate;
  background:
    radial-gradient(circle at 12% 8%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 42%),
    radial-gradient(circle at 88% 85%, color-mix(in srgb, var(--accent2) 13%, transparent), transparent 46%),
    var(--bg);
}
/* Узор фона: SVG-маска, окрашенная в цвет темы. */
.chat::before, .wall-prev {
  -webkit-mask-repeat: repeat; mask-repeat: repeat; -webkit-mask-size: 150px; mask-size: 150px;
  background: linear-gradient(160deg, var(--accent), var(--accent2));
}
.chat::before { content: ""; position: absolute; inset: 0; z-index: -1; opacity: .075; pointer-events: none; }
:root[data-wall="none"] .chat::before { display: none; }
:root:not([data-wall]) .chat::before, :root[data-wall="hearts"] .chat::before, .wall-prev[data-w="hearts"] {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='150' height='150'%3E%3Cg%3E%3Cpath transform='translate(14 16) scale(1.1) rotate(-14 12 12)' d='M12 21.2 10.6 20C5.4 15.4 2 12.3 2 8.5 2 5.4 4.4 3 7.5 3c1.7 0 3.4.8 4.5 2.1C13.1 3.8 14.8 3 16.5 3 19.6 3 22 5.4 22 8.5c0 3.8-3.4 6.9-8.6 11.5z'/%3E%3Cpath transform='translate(92 30) scale(.7) rotate(18 12 12)' d='M12 21.2 10.6 20C5.4 15.4 2 12.3 2 8.5 2 5.4 4.4 3 7.5 3c1.7 0 3.4.8 4.5 2.1C13.1 3.8 14.8 3 16.5 3 19.6 3 22 5.4 22 8.5c0 3.8-3.4 6.9-8.6 11.5z'/%3E%3Cpath transform='translate(56 82) scale(.9) rotate(8 12 12)' d='M12 21.2 10.6 20C5.4 15.4 2 12.3 2 8.5 2 5.4 4.4 3 7.5 3c1.7 0 3.4.8 4.5 2.1C13.1 3.8 14.8 3 16.5 3 19.6 3 22 5.4 22 8.5c0 3.8-3.4 6.9-8.6 11.5z'/%3E%3Cpath transform='translate(112 104) scale(.55) rotate(-22 12 12)' d='M12 21.2 10.6 20C5.4 15.4 2 12.3 2 8.5 2 5.4 4.4 3 7.5 3c1.7 0 3.4.8 4.5 2.1C13.1 3.8 14.8 3 16.5 3 19.6 3 22 5.4 22 8.5c0 3.8-3.4 6.9-8.6 11.5z'/%3E%3Cpath transform='translate(8 108) scale(.5) rotate(25 12 12)' d='M12 21.2 10.6 20C5.4 15.4 2 12.3 2 8.5 2 5.4 4.4 3 7.5 3c1.7 0 3.4.8 4.5 2.1C13.1 3.8 14.8 3 16.5 3 19.6 3 22 5.4 22 8.5c0 3.8-3.4 6.9-8.6 11.5z'/%3E%3C/g%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='150' height='150'%3E%3Cg%3E%3Cpath transform='translate(14 16) scale(1.1) rotate(-14 12 12)' d='M12 21.2 10.6 20C5.4 15.4 2 12.3 2 8.5 2 5.4 4.4 3 7.5 3c1.7 0 3.4.8 4.5 2.1C13.1 3.8 14.8 3 16.5 3 19.6 3 22 5.4 22 8.5c0 3.8-3.4 6.9-8.6 11.5z'/%3E%3Cpath transform='translate(92 30) scale(.7) rotate(18 12 12)' d='M12 21.2 10.6 20C5.4 15.4 2 12.3 2 8.5 2 5.4 4.4 3 7.5 3c1.7 0 3.4.8 4.5 2.1C13.1 3.8 14.8 3 16.5 3 19.6 3 22 5.4 22 8.5c0 3.8-3.4 6.9-8.6 11.5z'/%3E%3Cpath transform='translate(56 82) scale(.9) rotate(8 12 12)' d='M12 21.2 10.6 20C5.4 15.4 2 12.3 2 8.5 2 5.4 4.4 3 7.5 3c1.7 0 3.4.8 4.5 2.1C13.1 3.8 14.8 3 16.5 3 19.6 3 22 5.4 22 8.5c0 3.8-3.4 6.9-8.6 11.5z'/%3E%3Cpath transform='translate(112 104) scale(.55) rotate(-22 12 12)' d='M12 21.2 10.6 20C5.4 15.4 2 12.3 2 8.5 2 5.4 4.4 3 7.5 3c1.7 0 3.4.8 4.5 2.1C13.1 3.8 14.8 3 16.5 3 19.6 3 22 5.4 22 8.5c0 3.8-3.4 6.9-8.6 11.5z'/%3E%3Cpath transform='translate(8 108) scale(.5) rotate(25 12 12)' d='M12 21.2 10.6 20C5.4 15.4 2 12.3 2 8.5 2 5.4 4.4 3 7.5 3c1.7 0 3.4.8 4.5 2.1C13.1 3.8 14.8 3 16.5 3 19.6 3 22 5.4 22 8.5c0 3.8-3.4 6.9-8.6 11.5z'/%3E%3C/g%3E%3C/svg%3E");
}
:root[data-wall="stars"] .chat::before, .wall-prev[data-w="stars"] {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='150' height='150'%3E%3Cpath transform='translate(10 12)' d='M12 2l2.2 7.8L22 12l-7.8 2.2L12 22l-2.2-7.8L2 12l7.8-2.2z'/%3E%3Cpath transform='translate(96 40) scale(.6)' d='M12 2l2.2 7.8L22 12l-7.8 2.2L12 22l-2.2-7.8L2 12l7.8-2.2z'/%3E%3Cpath transform='translate(52 92) scale(.8)' d='M12 2l2.2 7.8L22 12l-7.8 2.2L12 22l-2.2-7.8L2 12l7.8-2.2z'/%3E%3Ccircle cx='70' cy='26' r='2'/%3E%3Ccircle cx='130' cy='96' r='2.5'/%3E%3Ccircle cx='24' cy='120' r='1.8'/%3E%3Ccircle cx='118' cy='140' r='1.5'/%3E%3Cpath transform='translate(118 2) scale(.45)' d='M12 2l2.2 7.8L22 12l-7.8 2.2L12 22l-2.2-7.8L2 12l7.8-2.2z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='150' height='150'%3E%3Cpath transform='translate(10 12)' d='M12 2l2.2 7.8L22 12l-7.8 2.2L12 22l-2.2-7.8L2 12l7.8-2.2z'/%3E%3Cpath transform='translate(96 40) scale(.6)' d='M12 2l2.2 7.8L22 12l-7.8 2.2L12 22l-2.2-7.8L2 12l7.8-2.2z'/%3E%3Cpath transform='translate(52 92) scale(.8)' d='M12 2l2.2 7.8L22 12l-7.8 2.2L12 22l-2.2-7.8L2 12l7.8-2.2z'/%3E%3Ccircle cx='70' cy='26' r='2'/%3E%3Ccircle cx='130' cy='96' r='2.5'/%3E%3Ccircle cx='24' cy='120' r='1.8'/%3E%3Ccircle cx='118' cy='140' r='1.5'/%3E%3Cpath transform='translate(118 2) scale(.45)' d='M12 2l2.2 7.8L22 12l-7.8 2.2L12 22l-2.2-7.8L2 12l7.8-2.2z'/%3E%3C/svg%3E");
}
:root[data-wall="dots"] .chat::before, .wall-prev[data-w="dots"] {
  -webkit-mask-image: radial-gradient(circle, #000 2.2px, transparent 2.6px); mask-image: radial-gradient(circle, #000 2.2px, transparent 2.6px);
  -webkit-mask-size: 22px 22px; mask-size: 22px 22px;
}
.wall-prev[data-w="none"] { background: transparent; }
@media (min-width: 900px) { .chat { border-left: 1px solid var(--line); border-right: 1px solid var(--line); } }
.bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px; padding-top: max(8px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line); z-index: 2;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--grad); color: #fff; flex: none; position: relative;
  display: grid; place-items: center; font-weight: 700; font-size: 17px;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent);
}
.avatar.online::after {
  content: ""; position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--ok); border: 2.5px solid var(--panel); animation: popIn .25s ease-out;
}
@keyframes popIn { from { transform: scale(0); } }
.dots { display: inline-flex; gap: 3px; margin-left: 5px; vertical-align: middle; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: dot 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.avatar .ic { width: 20px; height: 20px; }
.avatar.big { width: 76px; height: 76px; font-size: 30px; margin: 0 auto; }
.avatar.big .ic { width: 34px; height: 34px; }
.who { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 2px 4px; }
.who .name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.accent { color: var(--accent); }
.status.bad { color: var(--bad); }

.msgs {
  flex: 1; overflow-y: auto; padding: 8px 10px 10px; display: flex; flex-direction: column;
  overscroll-behavior: contain;
}
.day { position: sticky; top: 4px; z-index: 1; }
.day { align-self: center; margin: 10px 0 6px; }
.day > span, .sys > span {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted);
  background: color-mix(in srgb, var(--panel) 85%, transparent); padding: 4px 11px; border-radius: 12px; border: 1px solid var(--line);
}
.sys { align-self: center; text-align: center; max-width: 88%; margin: 6px 0; }
.sys > span { line-height: 1.35; }
.sys .ic { width: 15px; height: 15px; }
.sys.secure > span { color: var(--ok); }
.sys.warn > span { color: var(--warn); }

.row { display: flex; margin-top: 8px; }
.row.cont { margin-top: 2px; } /* сообщения подряд от одного человека — плотной группой */
.row.out { justify-content: flex-end; }
.row.flash .bubble { animation: flash 1.2s; }
@keyframes flash { 30% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 55%, transparent); } }
.bubble {
  position: relative; max-width: min(78%, 520px); padding: 7px 11px 6px; border-radius: var(--r);
  background: var(--in); border: 1px solid var(--line); word-wrap: break-word; overflow-wrap: anywhere;
  user-select: text; -webkit-user-select: text;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
}
@keyframes pop { from { transform: translateY(6px) scale(.98); opacity: 0; } }
@keyframes popOut { from { transform: translate(10px, 12px) scale(.92); opacity: 0; } }
@keyframes popIn2 { from { transform: translate(-10px, 8px) scale(.95); opacity: 0; } }
.row.new.out .bubble, .row.new.out .circle-box { animation: popOut .3s cubic-bezier(.2, .9, .25, 1.15); transform-origin: bottom right; }
.row.new.in .bubble, .row.new.in .circle-box { animation: popIn2 .3s cubic-bezier(.2, .9, .25, 1.1); transform-origin: bottom left; }
.row.in .bubble { border-radius: 18px 18px 18px 6px; }
.row.in.cont .bubble { border-top-left-radius: 6px; }
.row.out .bubble {
  background: var(--grad); color: #fff; border: 0; border-radius: 18px 18px 6px 18px;
  box-shadow: 0 2px 10px color-mix(in srgb, var(--accent) 22%, transparent);
}
.row.out.cont .bubble { border-top-right-radius: 6px; }
.row.out .bubble a { color: #fff; }
.bubble a { color: var(--accent); }
.text { white-space: pre-wrap; display: inline; }
.text.jumbo { font-size: 44px; line-height: 1.15; }
.meta {
  float: right; display: inline-flex; align-items: center; gap: 3px; margin: 6px 0 -2px 10px;
  font-size: 11.5px; opacity: .7; position: relative; top: 3px;
}
.tick { width: 16px; height: 16px; }
.tick.read { color: #b7ffe0; opacity: 1; }
.row.out .tick.read { filter: drop-shadow(0 0 2px rgba(0, 0, 0, .25)); }
.tick.bad { color: var(--bad); }
.bubble.media { padding: 3px; }
.bubble.media .meta {
  position: absolute; right: 9px; bottom: 9px; margin: 0; top: auto; float: none; opacity: 1;
  background: rgba(0, 0, 0, .45); color: #fff; padding: 2px 7px; border-radius: 10px;
}
.media-box { border-radius: 15px; overflow: hidden; background: rgba(127, 127, 127, .15); display: grid; place-items: center; max-width: 100%; margin-bottom: 4px; }
.bubble.media .media-box { margin: 0; }
.media-box img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.quote {
  display: grid; gap: 1px; text-align: left; width: 100%; border: 0; margin: 2px 0 5px; padding: 5px 9px;
  border-left: 3px solid var(--accent); border-radius: 8px; background: rgba(127, 127, 127, .14); font-size: 13.5px;
}
.row.out .quote { border-left-color: #fff; background: rgba(255, 255, 255, .18); }
.quote b { font-size: 13px; }
.quote span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85; }

/* ---------- кружки ---------- */
.vid-msg { display: grid; justify-items: end; gap: 5px; max-width: min(78%, 520px); position: relative; }
.row.in .vid-msg { justify-items: start; }
.vid-msg .quote { max-width: 240px; background: color-mix(in srgb, var(--panel) 90%, transparent); border: 1px solid var(--line); }
.circle-box {
  position: relative; width: min(60vw, 230px); aspect-ratio: 1; border-radius: 50%; overflow: hidden; cursor: pointer;
  background: #000; box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
  -webkit-user-select: none; user-select: none;
}
.circle-video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.circle-na { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; }
.ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); pointer-events: none; }
.ring circle {
  fill: none; stroke: rgba(255, 255, 255, .95); stroke-width: 2.6; stroke-linecap: round;
  stroke-dasharray: 100; stroke-dashoffset: 100; transition: stroke-dashoffset .25s linear;
}
.circle-dur {
  position: absolute; left: 50%; bottom: 10%; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 4px;
  background: rgba(0, 0, 0, .5); color: #fff; font-size: 12px; padding: 3px 9px; border-radius: 11px; backdrop-filter: blur(6px);
}
.vid-meta {
  float: none; position: static; margin: 0; opacity: .9; color: var(--muted);
  background: color-mix(in srgb, var(--panel) 85%, transparent); border: 1px solid var(--line); padding: 2px 8px; border-radius: 10px;
}
.vid-msg .reacts { margin: 0; }

.overlay.recorder { background: rgba(6, 6, 16, .94); backdrop-filter: blur(10px); }
.ring { opacity: 0; transition: opacity .2s; }
.circle-box.playing .ring, .recording .ring.rec { opacity: 1; }
.rec-wrap { display: grid; justify-items: center; gap: 18px; width: 100%; }
.rec-circle {
  position: relative; width: min(80vw, 340px); aspect-ratio: 1; border-radius: 50%; overflow: hidden; background: #000;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, .08), 0 20px 60px rgba(0, 0, 0, .6);
}
.rec-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.mirror { transform: scaleX(-1); }
.ring.rec circle { stroke: var(--accent2); stroke-width: 3.2; transition: stroke-dashoffset .2s linear; }
.rec-time { color: #fff; font: 600 17px ui-monospace, Consolas, monospace; min-height: 1.4em; }
.recording .rec-time::before { content: "● "; color: #ff4d6d; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.rec-actions { display: flex; gap: 30px; align-items: center; }
.rec-btn { width: 54px; height: 54px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgba(255, 255, 255, .13); color: #fff; }
.rec-btn.main { width: 76px; height: 76px; background: var(--grad); box-shadow: 0 8px 30px color-mix(in srgb, var(--accent) 50%, transparent); }
.rec-btn.main .ic { width: 28px; height: 28px; margin-left: -3px; }
.rec-dot { width: 28px; height: 28px; border-radius: 50%; background: #fff; }
.rec-hint { color: rgba(255, 255, 255, .55); font-size: 13px; margin: 0; text-align: center; }

.card {
  align-self: center; width: min(100%, 420px); margin: auto 0; padding: 22px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow);
  display: grid; gap: 12px;
}
.card h3 { margin: 0; }
.card p { margin: 0; color: var(--muted); font-size: 14.5px; }
.row-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.waiting { display: flex; gap: 10px; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; }
.empty { margin: auto; text-align: center; color: var(--muted); }
.wave { font-size: 48px; animation: wave 2s infinite; transform-origin: 70% 70%; display: inline-block; }
@keyframes wave { 0%, 60%, 100% { transform: rotate(0); } 10%, 30% { transform: rotate(14deg); } 20% { transform: rotate(-8deg); } }
.spinner {
  width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; margin: 0 auto; flex: none;
}
.waiting .spinner { margin: 0; width: 18px; height: 18px; }
@keyframes spin { to { transform: rotate(360deg); } }

.composer {
  padding: 8px 8px max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
}
.crow { display: flex; align-items: flex-end; gap: 6px; }
.input {
  flex: 1; resize: none; border: 1px solid var(--line); background: var(--bg2); border-radius: 22px;
  padding: 10px 15px; max-height: 160px; outline: none; line-height: 1.35; font-size: 16px;
}
.input:focus { border-color: var(--accent); }
.send-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--grad); color: #fff; flex: none;
  display: grid; place-items: center; box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 40%, transparent);
}
.send-btn .ic { width: 20px; height: 20px; margin-left: -2px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 44px; padding: 0 10px; border-radius: 22px;
  border: 1px solid var(--line); background: transparent; color: var(--accent); font-size: 13px; font-weight: 600;
}
.chip .ic { width: 16px; height: 16px; }
.replybar { display: flex; align-items: center; gap: 10px; padding: 4px 4px 8px 10px; color: var(--accent); }
.rb-text { flex: 1; min-width: 0; display: grid; border-left: 3px solid var(--accent); padding-left: 9px; }
.rb-text b { font-size: 13px; }
.rb-text span { color: var(--text); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- оверлеи ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(5, 5, 15, .55); z-index: 50; display: flex; align-items: flex-end;
  justify-content: center; opacity: 0; transition: opacity .2s; backdrop-filter: blur(3px);
}
.overlay.show, .overlay.center { opacity: 1; }
.overlay.center { align-items: center; padding: 20px; }
.sheet {
  width: min(100%, 560px); max-height: 92%; overflow-y: auto; background: var(--panel); border-radius: 24px 24px 0 0;
  padding: 8px 18px max(18px, env(safe-area-inset-bottom)); transform: translateY(30px); transition: transform .2s;
  box-shadow: var(--shadow);
}
.overlay.show .sheet { transform: none; }
.grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.menu { display: grid; gap: 2px; }
.react-row { display: flex; justify-content: space-between; gap: 6px; padding: 4px 0 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.react-btn { font-size: 28px; background: var(--bg2); border: 0; border-radius: 50%; width: 50px; height: 50px; transition: transform .1s; }
.react-btn:active { transform: scale(1.2); }
.react-btn.on { background: color-mix(in srgb, var(--accent) 30%, transparent); }
.menu-item { display: flex; gap: 14px; align-items: center; padding: 13px 10px; border: 0; background: none; border-radius: 12px; text-align: left; font-size: 16px; }
.menu-item:hover { background: var(--bg2); }
.menu-item .ic { color: var(--muted); }
.menu-item.danger, .menu-item.danger .ic { color: var(--bad); }
.dialog { background: var(--panel); border-radius: 22px; padding: 22px; width: min(100%, 380px); box-shadow: var(--shadow); }
.dialog h3 { margin: 0 0 8px; }
.dialog p { margin: 0 0 18px; color: var(--muted); font-size: 15px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }
.viewer { background: rgba(0, 0, 0, .92); align-items: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-bar { position: absolute; top: max(10px, env(safe-area-inset-top)); right: 10px; display: flex; gap: 6px; }
.viewer-bar .icon-btn { background: rgba(255, 255, 255, .12); color: #fff; }

.settings { display: grid; gap: 14px; }
.set-head { text-align: center; display: grid; gap: 4px; }
.set-head h3 { margin: 8px 0 0; font-size: 21px; }
.set-head p { margin: 0; }
.settings section { background: var(--bg2); border-radius: 18px; padding: 14px; display: grid; gap: 10px; }
.settings section .card { box-shadow: none; background: transparent; border: 0; padding: 4px; width: 100%; }
.settings h4 { margin: 0; display: flex; gap: 8px; align-items: center; font-size: 15.5px; }
.settings h4 .ic { color: var(--accent); width: 19px; height: 19px; }
.settings p { margin: 0; font-size: 13.5px; }
.safety {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 12px; border-radius: 14px;
  background: var(--panel); font: 600 16px ui-monospace, Consolas, monospace; text-align: center; letter-spacing: 1px;
}
.switch { display: flex; gap: 12px; align-items: center; font-size: 15px; cursor: pointer; }
.switch input { appearance: none; width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; flex: none; transition: background .2s; cursor: pointer; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }
.how { background: var(--bg2); border-radius: 18px; padding: 14px; font-size: 14px; color: var(--muted); }
.how summary { cursor: pointer; color: var(--text); font-weight: 600; }
.how p { margin: 10px 0 0; line-height: 1.5; }
.settings .danger-zone { background: transparent; padding: 0; }
.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.swatch {
  display: grid; gap: 6px; justify-items: center; padding: 8px 6px 7px; border-radius: 14px; font-size: 12.5px;
  border: 2px solid transparent; background: var(--panel); color: var(--text); transition: border-color .15s, transform .1s;
}
.swatch:active { transform: scale(.96); }
.swatch.on { border-color: var(--accent); }
.swatch-prev { width: 100%; height: 38px; border-radius: 10px; position: relative; overflow: hidden; display: block; }
.swatch-prev b { position: absolute; right: 7px; bottom: 7px; width: 42%; height: 11px; border-radius: 6px; }
.swatch-prev s { position: absolute; left: 7px; top: 7px; width: 34%; height: 9px; border-radius: 5px; opacity: .9; }
.wall-prev { width: 100%; height: 38px; border-radius: 10px; display: block; -webkit-mask-size: 70px; mask-size: 70px; opacity: .8; }
.wall-box { width: 100%; border-radius: 10px; background: var(--bg); overflow: hidden; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-size: 14px; z-index: 100;
  opacity: 0; transition: opacity .25s, transform .25s; max-width: calc(100% - 32px); text-align: center; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- реакции (несколько от каждого) ---------- */
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; clear: both; }
.rchip {
  position: relative; display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px 2px 6px; border-radius: 14px;
  border: 1px solid transparent; background: rgba(127, 127, 127, .2); font-size: 15px; line-height: 1.4; color: inherit;
  transition: transform .25s cubic-bezier(.3, 1.6, .5, 1), background .2s;
}
.rchip:active { transform: scale(.88); }
.rchip.mine { background: color-mix(in srgb, var(--accent) 30%, transparent); border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.row.out .rchip { background: rgba(255, 255, 255, .22); }
.row.out .rchip.mine { background: rgba(255, 255, 255, .38); border-color: rgba(255, 255, 255, .6); }
.rchip small { font-size: 11.5px; font-weight: 700; }
.rchip.fresh .remo { display: inline-block; animation: reactPop .55s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes reactPop { 0% { transform: scale(0); } 60% { transform: scale(1.5) rotate(-10deg); } 100% { transform: scale(1); } }
.burst {
  position: absolute; left: 50%; top: 40%; font-style: normal; font-size: 16px; pointer-events: none; opacity: 0;
  animation: burst .9s ease-out forwards;
}
@keyframes burst {
  0% { transform: translate(-50%, 0) scale(.4); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), var(--dy)) scale(1.1) rotate(25deg); opacity: 0; }
}
.react-row { flex-wrap: nowrap; }
.react-btn.more { font-size: 22px; color: var(--muted); }
.react-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; padding: 0 0 12px; margin-bottom: 6px;
  border-bottom: 1px solid var(--line); justify-items: center;
}
.react-grid .react-btn { width: 46px; height: 46px; font-size: 25px; }
.text.jumbo { display: inline-block; animation: jumbo 2.4s ease-in-out infinite; transform-origin: 50% 80%; }
@keyframes jumbo { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.12) rotate(-4deg); } 30% { transform: scale(1); } }

/* ---------- зажатие сообщения: «вдавливается», отпускание — пружинит ---------- */
.bubble, .vid-msg {
  transition: transform .42s cubic-bezier(.3, 1.8, .45, 1), filter .3s ease;
  -webkit-touch-callout: none;
}
.row.out .bubble, .row.out .vid-msg { transform-origin: 85% 60%; }
.row.in .bubble, .row.in .vid-msg { transform-origin: 15% 60%; }
.bubble.pressing, .vid-msg.pressing {
  transform: scale(.93);
  filter: brightness(.88) saturate(1.15);
  transition: transform .45s cubic-bezier(.2, .7, .3, 1), filter .45s ease;
}

.dialog.perm { text-align: center; }
.dialog.perm .dialog-actions { justify-content: center; }
.perm-ic {
  width: 64px; height: 64px; border-radius: 20px; background: var(--grad); color: #fff; margin: 0 auto 14px;
  display: grid; place-items: center; box-shadow: 0 8px 26px color-mix(in srgb, var(--accent) 40%, transparent);
}
.perm-ic .ic { width: 30px; height: 30px; }
.perm-status { font-size: 12.5px; }
.perm-status.ok { color: var(--ok); }
.ios-haptic { position: fixed; left: -100px; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; overflow: hidden; }

/* ---------- удаление: сообщение рассыпается песком ---------- */
.dust-layer { position: fixed; z-index: 40; pointer-events: none; overflow: visible; }
.dust-row { position: absolute !important; inset: 0; display: block !important; margin: 0 !important; height: auto !important; }
.dust-piece {
  position: absolute !important; left: 0; top: 0; margin: 0 !important; max-width: none !important;
  animation: dust 1.05s cubic-bezier(.25, .6, .35, 1) both !important; will-change: transform, opacity, filter;
}
@keyframes dust {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; filter: blur(0); }
  25% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; filter: blur(3px); }
}
.dust-grain {
  position: absolute; width: 3px; height: 3px; border-radius: 50%; opacity: 0;
  animation: grain 1s ease-out both;
}
@keyframes grain {
  0% { transform: translate(0, 0) scale(1); opacity: .9; }
  100% { transform: translate(var(--dx), var(--dy)) scale(.3); opacity: 0; }
}
.row.collapsing { height: 0 !important; margin-top: 0 !important; transition: height .26s ease, margin-top .26s ease; }

/* ---------- стикеры ---------- */
.stk-msg .stk-holder { width: 140px; height: 140px; display: grid; place-items: center; }
.stk-own { width: 140px; height: 140px; object-fit: contain; display: block; -webkit-user-drag: none; }
.row.new .stk-holder { animation: stkIn .5s cubic-bezier(.25, 1.6, .45, 1); }
@keyframes stkIn { from { transform: scale(.3) rotate(-12deg); opacity: 0; } }
.stk-btn { width: 40px; height: 44px; }
.stk-panel { display: grid; gap: 10px; }
.stk-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.stk-tabs::-webkit-scrollbar { display: none; }
.stk-tab {
  display: inline-flex; align-items: center; gap: 6px; flex: none; border: 1px solid var(--line); border-radius: 16px;
  padding: 6px 12px; background: var(--bg2); font-size: 14px; font-weight: 600; color: var(--text);
}
.stk-tab.on { background: var(--grad); color: #fff; border-color: transparent; }
.stk-tab-ic { width: 22px; height: 22px; display: inline-flex; }
.stk-tab-ic svg { width: 100%; height: 100%; }
.stk-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-height: 52vh; overflow-y: auto; padding: 2px; }
.stk-cell {
  aspect-ratio: 1; border: 0; border-radius: 16px; background: transparent; padding: 4px; display: grid; place-items: center;
  transition: transform .3s cubic-bezier(.3, 1.7, .45, 1), background .2s;
}
.stk-cell:hover { background: var(--bg2); }
.stk-cell:active { transform: scale(.88); }
.stk-cell .stk.small, .stk-cell img { width: 100%; height: 100%; max-width: 76px; max-height: 76px; object-fit: contain; }
.stk-cell.add { border: 2px dashed var(--line); color: var(--muted); display: grid; align-content: center; gap: 2px; }
.stk-cell.add span { font-size: 26px; line-height: 1; }
.stk-cell.add small { font-size: 11.5px; }
.stk-hint { grid-column: 1 / -1; font-size: 13.5px; margin: 6px 4px; }

/* ---------- «Жидкое стекло» (переключается в «Оформлении») ---------- */
:root[data-glass="on"] {
  --glass: color-mix(in srgb, var(--panel) 52%, transparent);
  --glass-strong: color-mix(in srgb, var(--panel) 72%, transparent);
  --glass-edge: rgba(255, 255, 255, .16);
  --glass-hi: rgba(255, 255, 255, .28);
  --glass-shadow: 0 10px 34px rgba(0, 0, 0, .28);
}
:root[data-glass="on"][data-theme="dawn"] { --glass-edge: rgba(255, 255, 255, .75); --glass-hi: rgba(255, 255, 255, .9); --glass-shadow: 0 10px 30px rgba(120, 50, 40, .14); }
@media (prefers-color-scheme: light) {
  :root[data-glass="on"]:not([data-theme]) { --glass-edge: rgba(255, 255, 255, .75); --glass-hi: rgba(255, 255, 255, .9); --glass-shadow: 0 10px 30px rgba(40, 30, 90, .14); }
}
/* общий рецепт: полупрозрачная подложка + размытие с насыщенностью + световой кант + блик */
:root[data-glass="on"] :is(.bar, .composer, .sheet, .dialog, .toast, .day > span, .sys > span, .chip, .vid-meta) {
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(185%); backdrop-filter: blur(22px) saturate(185%);
  border: 1px solid var(--glass-edge);
  box-shadow: inset 0 1px 0 var(--glass-hi), inset 0 -1px 0 rgba(255, 255, 255, .04), var(--glass-shadow);
}
:root[data-glass="on"] .sheet, :root[data-glass="on"] .dialog { background: var(--glass-strong); }
:root[data-glass="on"] .toast { color: var(--text); }
/* шапка и поле ввода парят над перепиской */
:root[data-glass="on"] .bar {
  position: absolute; z-index: 3; left: 8px; right: 8px; top: max(8px, env(safe-area-inset-top));
  border-radius: 26px; padding: 6px 6px 6px 8px;
}
:root[data-glass="on"] .composer {
  position: absolute; z-index: 3; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom));
  border-radius: 28px; padding: 6px;
}
:root[data-glass="on"] .composer .input { background: color-mix(in srgb, var(--bg) 35%, transparent); border-color: var(--glass-edge); }
:root[data-glass="on"] .msgs {
  padding-top: calc(max(8px, env(safe-area-inset-top)) + 72px);
  padding-bottom: calc(var(--ch, 62px) + max(8px, env(safe-area-inset-bottom)) + 14px);
  scroll-padding-bottom: calc(var(--ch, 62px) + 24px);
}
/* входящие пузыри — матовое стекло, исходящие — глянец поверх градиента */
:root[data-glass="on"] .row.in .bubble {
  background: color-mix(in srgb, var(--in) 70%, transparent);
  -webkit-backdrop-filter: blur(12px) saturate(160%); backdrop-filter: blur(12px) saturate(160%);
  border-color: var(--glass-edge); box-shadow: inset 0 1px 0 var(--glass-hi), 0 2px 10px rgba(0, 0, 0, .12);
}
:root[data-glass="on"] .row.out .bubble { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), inset 0 -2px 6px rgba(0, 0, 0, .08), 0 4px 16px color-mix(in srgb, var(--accent) 28%, transparent); }
:root[data-glass="on"] .row.out .bubble::before,
:root[data-glass="on"] :is(.send-btn, .btn.primary, .avatar, .logo, .rec-btn.main)::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(170deg, rgba(255, 255, 255, .34) 0%, rgba(255, 255, 255, .08) 38%, transparent 55%, rgba(255, 255, 255, .06) 100%);
}
:root[data-glass="on"] :is(.send-btn, .btn.primary, .logo, .rec-btn.main) { position: relative; overflow: hidden; }
:root[data-glass="on"] .avatar::before { z-index: 0; }
/* «жидкое» упругое нажатие */
:root[data-glass="on"] :is(.send-btn, .icon-btn, .btn, .react-btn, .swatch, .menu-item) { transition: transform .35s cubic-bezier(.3, 1.7, .45, 1), background .2s; }
:root[data-glass="on"] :is(.send-btn, .icon-btn, .btn, .react-btn, .swatch):active { transform: scale(.9); }
:root[data-glass="on"] .rchip { -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
