/* Оформление под One UI: крупные скругления, капсульные кнопки,
   нейтральные серые и один синий акцент. Тёмная тема — на чистом чёрном. */

/* Цвета, скругления и шрифт задаются переменными: их выставляет theme.js по
   выбранному оформлению, и один выбор меняет вид всего приложения. */
:root {
  --accent: #3478F6;
  --accent-soft: #E8F0FE;
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --surface-alt: #EDEEF2;
  --surface-hi: #E3E5EA;
  --text: #16181C;
  --text-dim: #8B8D94;
  --divider: #E8E8EC;
  --bubble-in: #EDEEF2;
  --bubble-out: #3478F6;
  --bubble-out-text: #FFFFFF;
  --danger: #E5484D;
  --online: #35C759;
  --read: #57E08A;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --font-scale: 1;
  --radius: 22px;
  --bubble-radius: 19px;
  --bar-radius: 999px;
  --density: 1;
  --shadow: 0 8px 22px rgba(0,0,0,.14);
  --wallpaper: none;
  --wallpaper-size: auto;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --keyboard: 0px;
}

/* С открытой клавиатурой запас под жест «домой» не нужен: там уже клавиатура,
   и лишний отступ отодвигал поле ввода вверх. */
:root[data-keyboard="on"] { --safe-bottom: 0px; }

/* Тёмная палитра. data-theme ставит theme.js; медиазапрос нужен только до
   того, как загрузятся настройки, чтобы не мигнуть белым. */
:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #131417;
  --surface-alt: #1D1E22;
  --surface-hi: #2A2C31;
  --text: #F2F3F5;
  --text-dim: #8E9198;
  --divider: #24262B;
  --bubble-in: #232529;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #6FA8FF;
    --accent-soft: #1B2A45;
    --bg: #000000;
    --surface: #131417;
    --surface-alt: #1D1E22;
    --surface-hi: #2A2C31;
    --text: #F2F3F5;
    --text-dim: #8E9198;
    --divider: #24262B;
    --bubble-in: #232529;
  }
}

/* «Ночная» — мягче чистого чёрного, глаза устают меньше. */
:root[data-mood="night"] {
  --bg: #0B1017;
  --surface: #121A24;
  --surface-alt: #182231;
  --surface-hi: #22304260;
  --divider: #1C2836;
  --bubble-in: #1A2532;
}

/* «Тёплая» — бумажный оттенок для чтения при свете лампы. */
:root[data-mood="sepia"] {
  --bg: #F3EADA;
  --surface: #FBF5EA;
  --surface-alt: #EDE0CC;
  --surface-hi: #E2D2B8;
  --text: #3A3226;
  --text-dim: #8A7B63;
  --divider: #E4D7C1;
  --bubble-in: #EDE0CC;
}

/* Анимации можно выключить — на слабом телефоне так заметно быстрее. */
:root[data-animations="off"] *,
:root[data-animations="off"] *::before,
:root[data-animations="off"] *::after {
  animation-duration: .001s !important;
  transition-duration: .001s !important;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  /* dvh учитывает панели браузера, которые на телефоне то появляются, то
     исчезают; с обычными 100% низ экрана оказывался под ними. */
  height: 100dvh;
  overflow: hidden;
  position: fixed;
  inset: 0;
  background: var(--bg);
  color: var(--text);
  font: calc(16px * var(--font-scale))/1.4 var(--font);
  /* Никаких «резинок» при прокрутке — иначе на iPhone страница едет целиком. */
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; }

.grow { flex: 1; min-width: 0; }

.app {
  height: 100%; display: flex; flex-direction: column;
  /* Высоту переопределяет app.js, когда открыта клавиатура. */
  transition: height .16s ease-out;
  transform-origin: top;
}

.boot { height: 100%; display: grid; place-items: center; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2.5px solid var(--divider); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.ico { display: inline-flex; align-items: center; justify-content: center; }
.ico svg { display: block; }

/* ── экраны ──────────────────────────────────────────────────────────── */

/* Высоту приложения задаёт app.js по видимой части окна, поэтому экран просто
   занимает её целиком: шапка вверху, поле ввода над клавиатурой. */
.screen { height: 100%; display: flex; flex-direction: column; overflow: hidden; }

/* Переход между списком и перепиской. Во время него в документе два экрана —
   на время анимации они ложатся друг на друга. */
.app { position: relative; }
.screen.enter-fwd, .screen.exit-fwd,
.screen.enter-back, .screen.exit-back {
  position: absolute; inset: 0; will-change: transform;
}

.screen.enter-fwd { animation: screen-in-right .26s cubic-bezier(.2,.8,.3,1); }
.screen.exit-fwd  { animation: screen-out-left .26s cubic-bezier(.2,.8,.3,1) forwards; }
.screen.enter-back { animation: screen-in-left .26s cubic-bezier(.2,.8,.3,1); }
.screen.exit-back  { animation: screen-out-right .26s cubic-bezier(.2,.8,.3,1) forwards; }

@keyframes screen-in-right {
  from { transform: translateX(100%); }
  to   { transform: none; }
}
@keyframes screen-out-left {
  from { transform: none; opacity: 1; }
  /* Уходит не полностью: так видно, что список остался на месте, а сверху
     легла переписка. */
  to   { transform: translateX(-22%); opacity: .55; }
}
@keyframes screen-in-left {
  from { transform: translateX(-22%); opacity: .55; }
  to   { transform: none; opacity: 1; }
}
@keyframes screen-out-right {
  from { transform: none; }
  to   { transform: translateX(100%); }
}

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 8px) 10px 8px;
  background: var(--bg);
  flex: none;
}
.topbar .title { font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: 13px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub.typing { color: var(--accent); }
.topbar .peer {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
  cursor: pointer; border-radius: 14px; padding: 4px 6px;
}
.topbar .peer:active { background: var(--surface-alt); }

.listbar {
  display: flex; align-items: flex-end; gap: 4px;
  padding: calc(var(--safe-top) + 10px) 14px 6px;
  flex: none;
}
.bigtitle { font-size: 31px; font-weight: 700; letter-spacing: -.6px; padding-left: 8px; }
.bigsub { font-size: 13px; color: var(--text-dim); padding: 2px 0 6px 9px; }

.iconbtn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--text);
  cursor: pointer; flex: none;
}
.iconbtn:active { background: var(--surface-alt); }
.iconbtn.on { color: var(--accent); background: var(--accent-soft); }
.iconbtn:disabled { opacity: .4; }

.scroll {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Пустая обёртка для сменных частей экрана: закреплённое, ответ, поле ввода.
   Нужна, чтобы обновлять их по отдельности и не трогать соседей. */
.slot { display: contents; }

.name-line { display: inline-flex; align-items: center; gap: .28em; min-width: 0; }
.name-line > :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Размер — от шрифта соседнего текста, чтобы значок не приходилось подбирать
   на каждом экране отдельно. Сдвиг вниз потому, что центр строки проходит
   выше центра самих букв: без него значок выглядит приподнятым. */
.verified {
  flex: none; width: 1.05em; height: 1.05em;
  position: relative; top: .04em; cursor: pointer;
}

.tooltip {
  position: fixed; z-index: 120; max-width: 240px;
  background: #26282D; color: #fff;
  padding: 7px 12px; border-radius: 12px; font-size: 13px;
  box-shadow: 0 6px 18px rgba(0,0,0,.28);
  opacity: 0; transform: translateY(-4px); transition: .18s;
  pointer-events: none;
}
.tooltip.shown { opacity: 1; transform: none; }
.tooltip::after {
  content: ''; position: absolute; left: 50%; margin-left: -5px;
  border: 5px solid transparent; border-bottom-color: #26282D; top: -10px;
}
.tooltip.above::after { top: auto; bottom: -10px; border-bottom-color: transparent; border-top-color: #26282D; }

/* ── список чатов ────────────────────────────────────────────────────── */

.search {
  margin: 2px 16px 6px; padding: 12px 18px;
  background: var(--surface-alt); border: 0; border-radius: var(--bar-radius);
  color: var(--text); font: inherit; font-size: 16px; width: calc(100% - 32px);
}
.search:focus { outline: 2px solid var(--accent); }

.chat-row {
  display: flex; align-items: center; gap: 14px;
  padding: calc(9px * var(--density)) 20px; cursor: pointer;
}
.chat-row:active { background: var(--surface-alt); }
.chat-row .name { font-weight: 500; display: flex; }
.chat-row .preview, .chat-row .time {
  font-size: 13px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-row .preview.typing { color: var(--accent); }
.chat-row .draft { color: var(--danger); }
.chat-row.pinned { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.chat-row .time { display: flex; align-items: center; gap: 3px; justify-content: flex-end; }
.bubble .author { cursor: pointer; }
.chat-row .meta {
  margin-left: auto; text-align: right; flex: none;
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
}

.avatar {
  width: 54px; height: 54px; border-radius: 50%; flex: none;
  display: grid; place-items: center; position: relative;
  color: #fff; font-weight: 600; background: #5B8DEF;
  overflow: hidden; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 40px; height: 40px; font-size: 14px; }
.avatar .dot {
  position: absolute; right: 1px; bottom: 1px;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--online); border: 2.5px solid var(--bg);
}

.badge {
  display: inline-block; min-width: 20px; padding: 1px 7px;
  border-radius: 999px; background: var(--accent); color: #fff;
  font-size: 12px; font-weight: 600; text-align: center;
}

.fab {
  position: fixed; right: 18px; bottom: calc(var(--safe-bottom) + 20px);
  width: 60px; height: 60px; border-radius: var(--radius); border: 0;
  background: var(--accent); color: #fff; cursor: pointer;
  display: grid; place-items: center;
  box-shadow: var(--shadow);
}
:root[data-skin="ios"] .fab, :root[data-skin="material"] .fab { border-radius: 50%; }
.fab:active { transform: scale(.94); }

/* ── переписка ───────────────────────────────────────────────────────── */

.messages {
  display: flex; flex-direction: column; gap: calc(2px * var(--density));
  padding: calc(8px * var(--density)) 12px calc(6px * var(--density));
}

/* Фон переписки рисуется на всём экране чата, а не внутри прокрутки: внутри
   он занимал бы только первый экран и уезжал вместе с сообщениями. */
.screen.with-wallpaper {
  background-image: var(--wallpaper);
  background-size: var(--wallpaper-size);
  background-position: center;
  background-repeat: no-repeat;
}
.screen.with-wallpaper .scroll { background: transparent; }

.day, .system {
  align-self: center; padding: 4px 14px; border-radius: 999px;
  background: var(--surface-alt); color: var(--text-dim); font-size: 12px;
}
.day { margin: 12px 0 6px; }
.system { margin: 6px 0; font-size: 13px; text-align: center; }

.bubble {
  max-width: min(78%, 460px);
  padding: calc(6px * var(--density)) calc(11px * var(--density)) calc(5px * var(--density));
  border-radius: var(--bubble-radius); position: relative;
  word-wrap: break-word; overflow-wrap: anywhere;
}
/* Анимация только у сообщения, которое появилось прямо сейчас: экран
   перерисовывается на каждое событие, и общая анимация мигала бы вся разом. */
.bubble.pop { animation: pop .2s ease-out; }
@keyframes pop {
  from { transform: translateY(7px) scale(.96); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.bubble.in  { align-self: flex-start; background: var(--bubble-in); }
.bubble.out { align-self: flex-end; background: var(--bubble-out); color: var(--bubble-out-text); }
.bubble.in.first  { border-top-left-radius: 8px; }
.bubble.out.first { border-top-right-radius: 8px; }
.bubble.in  + .bubble.in  { margin-top: 0; }
.bubble.bare { background: none !important; padding: 0; }
.bubble.flash { animation: flash 1.1s ease-out; }
@keyframes flash {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  25%      { box-shadow: 0 0 0 4px var(--accent-soft); }
}

.bubble .photo { max-width: 100%; border-radius: 14px; display: block; margin: 2px 0; cursor: pointer; }
.bubble .sticker-img { width: 148px; max-width: 60vw; display: block; }
.bubble .caption { margin-top: 4px; }
.bubble .deleted { opacity: .7; }

.bubble .meta {
  float: right; margin: 6px 0 0 10px;
  font-size: 11px; opacity: .78; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 3px;
}
.bubble.bare .meta {
  float: none; position: absolute; right: 6px; bottom: 4px;
  background: rgba(0,0,0,.42); color: #fff; opacity: 1;
  border-radius: 999px; padding: 1px 7px; margin: 0;
}
.bubble .author { font-size: 12px; font-weight: 600; margin-bottom: 2px; color: var(--accent); }

/* ── разметка сообщений ──────────────────────────────────────────────── */

.md-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .92em; background: rgba(127,127,127,.18);
  padding: 1px 5px; border-radius: 6px;
}
pre.md-code {
  display: block; padding: 8px 10px; margin: 4px 0;
  white-space: pre-wrap; overflow-x: auto;
}
.md-quote {
  display: inline-block; border-left: 3px solid currentColor;
  padding-left: 8px; opacity: .85;
}
/* Спойлер скрыт, пока по нему не нажали. */
.md-spoiler {
  background: currentColor; border-radius: 4px; cursor: pointer;
  transition: .2s;
}
.md-spoiler:not(.shown) > * { visibility: hidden; }
.md-spoiler.shown { background: transparent; }
.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.bubble.in a { color: var(--accent); }

.reply-quote {
  border-left: 3px solid currentColor; padding: 2px 0 2px 8px;
  margin-bottom: 4px; opacity: .88; font-size: 13px; cursor: pointer;
}
.reply-author { font-weight: 600; font-size: 12px; }
.reply-text {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; opacity: .9;
}

.file-card {
  display: flex; gap: 10px; align-items: center;
  cursor: pointer; padding: 4px 0; min-width: 190px;
}
.file-ico {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  display: grid; place-items: center;
  background: rgba(255,255,255,.22);
}
.bubble.in .file-ico { background: var(--surface-hi); }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.file-size { font-size: 12px; opacity: .8; }
.file-track {
  height: 3px; border-radius: 3px; background: rgba(255,255,255,.3);
  margin-top: 5px; display: none;
}
.file-card.loading .file-track { display: block; }
.bubble.in .file-track { background: var(--surface-hi); }
.file-fill { height: 100%; border-radius: 3px; background: currentColor; transition: width .15s linear; }

.pack-card { display: flex; gap: 10px; align-items: center; cursor: pointer; padding: 2px 0; }

/* ── голосовое сообщение ─────────────────────────────────────────────── */

.voice { display: flex; align-items: center; gap: 10px; min-width: 200px; padding: 3px 0; }
.voice-play {
  width: 38px; height: 38px; border-radius: 50%; border: 0; flex: none;
  display: grid; place-items: center; cursor: pointer;
  background: rgba(255,255,255,.24); color: #fff;
}
.bubble.in .voice-play { background: var(--accent); color: #fff; }
.voice-bars {
  display: flex; align-items: center; gap: 2px; height: 30px; cursor: pointer;
}
.voice-bars i {
  flex: 1; min-width: 2px; border-radius: 2px;
  background: currentColor; opacity: .38;
}
.voice-bars i.on { opacity: 1; }
.bubble.in .voice-bars i.on { color: var(--accent); }

/* Собеседник послушал — полоска зеленеет, как галочки прочтения. */
.voice.heard .voice-bars i { background: var(--read); opacity: .55; }
.voice.heard .voice-bars i.on { opacity: 1; }

/* ── лента канала ────────────────────────────────────────────────────── */

.messages.feed { padding: 10px 10px 6px; }
.bubble.post {
  max-width: 100%; width: 100%;
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px 14px 10px;
  margin-bottom: 8px;
}
.bubble.post .meta { float: none; display: flex; justify-content: flex-end; margin-top: 8px; }
.bubble.post .views { display: inline-flex; align-items: center; gap: 3px; margin-right: 8px; }
.bubble.post .photo { max-width: 100%; }
.voice-time { font-size: 12px; opacity: .8; margin-top: 3px; }

.record {
  flex: none; display: flex; align-items: center; gap: 12px;
  padding: 10px 12px calc(var(--safe-bottom) + 10px);
  background: var(--surface); border-top: 1px solid var(--divider);
}
.record-cancel {
  width: 40px; height: 40px; border-radius: 50%; border: 0; flex: none;
  display: grid; place-items: center; cursor: pointer;
  background: transparent; color: var(--danger);
}
.record-dot { position: relative; width: 14px; height: 14px; flex: none; }
.record-level {
  position: absolute; inset: 0; border-radius: 50%;
  background: var(--danger); transition: transform .05s linear;
}
.record-time {
  font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 600; flex: none;
}
.record-hint { font-size: 13px; color: var(--text-dim); }

.readonly {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 16px 16px calc(var(--safe-bottom) + 16px);
  background: var(--surface); border-top: 1px solid var(--divider);
  color: var(--text-dim); font-size: 14px;
}

.avatar.special { color: #fff; }
.avatar.special.saved { background: linear-gradient(140deg,#F0A22E,#E8721C); }
.avatar.special.channel { background: linear-gradient(140deg,#4E8CFF,#2F5FD8); }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; clear: both; }
.reaction {
  border: 0; border-radius: 999px; padding: 2px 9px; font-size: 13px; cursor: pointer;
  background: var(--surface-alt); color: var(--text);
}
.bubble.out .reaction { background: rgba(255,255,255,.22); color: #fff; }
.reaction.mine { background: var(--accent); color: #fff; }
.bubble.out .reaction.mine { background: #fff; color: var(--accent); }

.dots { display: inline-flex; gap: 3px; align-items: center; margin-left: 4px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .85; }
.dots.read i { background: var(--read); opacity: 1; }
.dots.compact i { background: var(--text-dim); }
.dots.compact.read i { background: var(--read); }

.pinbar {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  margin: 0 12px 4px; padding: 7px 12px; border-radius: 16px;
  background: var(--surface-alt); color: var(--text);
}
.pin-title { font-size: 12px; font-weight: 600; color: var(--accent); }
.pin-text { font-size: 13px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.reply-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--surface);
  border-top: 1px solid var(--divider); color: var(--accent);
}
.reply-bar .reply-text { color: var(--text-dim); }

.upload {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  margin: 8px 12px; padding: 10px 14px; border-radius: 16px;
  background: var(--surface-alt);
}
.upload-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-track { height: 4px; border-radius: 4px; background: var(--surface-hi); margin-top: 6px; }
.upload-fill { height: 100%; width: 0; border-radius: 4px; background: var(--accent); transition: width .15s linear; }
.upload-hint { font-size: 12px; color: var(--text-dim); flex: none; }

/* ── ввод ────────────────────────────────────────────────────────────── */

.composer {
  flex: none; display: flex; align-items: flex-end; gap: 4px;
  padding: 7px 6px calc(var(--safe-bottom) + 7px);
  background: var(--surface); border-top: 1px solid var(--divider);
}
.composer textarea {
  flex: 1; resize: none; max-height: 120px; min-height: 42px;
  padding: 10px 16px; border: 0; border-radius: 21px;
  background: var(--surface-alt); color: var(--text);
  font: inherit; font-size: 16px; /* меньше 16px — Safari зумит при фокусе */
}
.composer textarea:focus { outline: none; }
.send {
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; cursor: pointer; flex: none;
  display: grid; place-items: center;
  transition: transform .12s, background .15s;
}
.send:active { transform: scale(.9); }
.send:disabled { background: var(--surface-hi); color: var(--text-dim); }

/* ── панель эмодзи и стикеров ────────────────────────────────────────── */

.panel {
  flex: none; height: min(46vh, 340px); display: flex; flex-direction: column;
  background: var(--surface); border-top: 1px solid var(--divider);
  padding-bottom: var(--safe-bottom);
  animation: rise .2s ease-out;
}
@keyframes rise { from { transform: translateY(14px); opacity: .4; } to { transform: none; opacity: 1; } }

.panel-tabs { display: flex; align-items: center; gap: 4px; padding: 6px 8px; flex: none; }
.panel-tab {
  display: flex; align-items: center; gap: 6px;
  border: 0; background: transparent; color: var(--text-dim);
  border-radius: 999px; padding: 7px 12px; font-size: 14px; cursor: pointer;
}
.panel-tab.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.panel-body { flex: 1; overflow-y: auto; padding: 0 10px 10px; }
.panel-group { font-size: 12px; color: var(--text-dim); padding: 8px 6px 4px; }
.panel-actions { display: flex; align-items: center; gap: 8px; padding: 4px 4px 8px; }

.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }
.emoji {
  border: 0; background: none; font-size: 26px; line-height: 1;
  padding: 6px 0; cursor: pointer; border-radius: 12px;
}
.emoji:active { background: var(--surface-alt); }

.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; }
.sticker-grid.big { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); padding: 12px 16px; }
.sticker-cell {
  border: 0; background: none; padding: 6px; cursor: pointer; border-radius: 16px;
  position: relative; aspect-ratio: 1;
}
.sticker-cell:active { background: var(--surface-alt); }
.sticker-cell img { width: 100%; height: 100%; object-fit: contain; }
.sticker-emoji { position: absolute; right: 4px; bottom: 2px; font-size: 15px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  border: 0; border-radius: 999px; padding: 7px 13px; cursor: pointer;
  background: var(--surface-alt); color: var(--text); font-size: 14px;
}

/* ── формы ───────────────────────────────────────────────────────────── */

.auth { max-width: 420px; margin: 0 auto; padding: 36px 24px 60px; width: 100%; }
.auth-logo { width: 92px; display: block; margin: 0 auto; border-radius: 24px; }
.auth h1 { text-align: center; font-size: 29px; margin: 14px 0 4px; }
.auth p.hint { text-align: center; color: var(--text-dim); margin: 0 0 22px; }

.field {
  width: 100%; padding: 14px 18px; margin-bottom: 10px;
  border: 0; border-radius: 18px; background: var(--surface);
  color: var(--text); font: inherit; font-size: 16px;
  display: block;
}
.field:focus { outline: 2px solid var(--accent); }
.field.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 1px; }
.field-hint { color: var(--text-dim); margin: -4px 0 12px; font-size: 13px; padding: 0 4px; }
textarea.field { resize: none; }

.btn {
  width: 100%; padding: 15px; border: 0; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 600;
  cursor: pointer;
}
.btn:disabled { opacity: .45; }
.btn.ghost { background: var(--surface-alt); color: var(--text); font-weight: 500; }
.btn.danger { background: var(--danger); }

.tabs { display: flex; background: var(--surface-alt); border-radius: 999px; padding: 4px; margin-bottom: 18px; }
.tabs button {
  flex: 1; padding: 10px; border: 0; border-radius: 999px;
  background: transparent; color: var(--text-dim); font: inherit; cursor: pointer;
}
.tabs button.on { background: var(--surface); color: var(--text); font-weight: 600; }

.error { color: var(--danger); text-align: center; margin: 8px 0; font-size: 14px; }
.empty { text-align: center; color: var(--text-dim); padding: 50px 30px; }
.empty p { margin: 4px 0; }

.banner {
  margin: 4px 16px; padding: 9px 16px; border-radius: 999px;
  background: var(--surface-alt); color: var(--text-dim); font-size: 13px; text-align: center;
}
.banner.warn {
  background: rgba(229,72,77,.14); color: var(--danger);
  border-radius: 16px; line-height: 1.35;
}

/* ── окна поверх (листы, страницы, просмотр) ─────────────────────────── */

#overlay { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
#overlay > * { pointer-events: auto; }

/* Появление задаётся анимацией, а не переключением класса: класс пришлось бы
   ставить в следующем кадре, а в фоновой вкладке кадры не идут — окно так и
   осталось бы за краем экрана. */
@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes slide-up   { from { transform: translateY(100%); } to { transform: none; } }
@keyframes slide-down { from { transform: none; } to { transform: translateY(100%); } }
@keyframes slide-in   { from { transform: translateX(100%); } to { transform: none; } }
@keyframes slide-out  { from { transform: none; } to { transform: translateX(100%); } }

.scrim {
  position: absolute; inset: 0; background: rgba(0,0,0,.45);
  animation: fade-in .22s ease-out;
}
.scrim.closing { animation: fade-out .2s ease-in forwards; }

.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88%; overflow-y: auto;
  background: var(--surface); color: var(--text);
  border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(var(--safe-bottom) + 18px);
  max-width: 560px; margin: 0 auto;
  animation: slide-up .24s cubic-bezier(.2,.8,.3,1);
}
.sheet.closing { animation: slide-down .2s ease-in forwards; }
.sheet::before {
  content: ''; display: block; width: 38px; height: 4px; border-radius: 4px;
  background: var(--surface-hi); margin: 4px auto 12px;
}
.sheet-title { font-size: 17px; font-weight: 600; padding: 2px 4px 10px; }
.sheet-text { color: var(--text-dim); font-size: 14px; margin: 0 4px 14px; }
.sheet-actions { display: flex; flex-direction: column; }
.sheet-item {
  display: flex; align-items: center; gap: 14px;
  border: 0; background: none; text-align: left;
  padding: 13px 4px; cursor: pointer; border-radius: 14px; font-size: 16px;
}
.sheet-item:active { background: var(--surface-alt); }
.sheet-item.danger { color: var(--danger); }
.sheet-buttons { display: flex; gap: 10px; margin-top: 14px; }

.reaction-bar {
  display: flex; gap: 4px; justify-content: space-between;
  background: var(--surface-alt); border-radius: 999px; padding: 6px; margin-bottom: 10px;
}
.reaction-pick {
  border: 0; background: none; font-size: 27px; line-height: 1;
  padding: 4px 6px; cursor: pointer; border-radius: 50%; flex: 1;
}
.reaction-pick:active { transform: scale(1.25); }

.page {
  position: absolute; inset: 0; background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
  animation: slide-in .24s cubic-bezier(.2,.8,.3,1);
}
.page.closing { animation: slide-out .22s ease-in forwards; }
.page .scroll { padding-bottom: calc(var(--safe-bottom) + 24px); }

.viewer {
  position: absolute; inset: 0; background: rgba(0,0,0,.94);
  display: flex; align-items: center; justify-content: center;
  color: #fff; animation: fade-in .2s ease-out;
}
.viewer.closing { animation: fade-out .18s ease-in forwards; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer > .iconbtn, .viewer > a {
  position: absolute; top: calc(var(--safe-top) + 12px); color: #fff;
  display: grid; place-items: center; width: 44px; height: 44px;
  border-radius: 50%; background: rgba(255,255,255,.15);
}
.viewer > .iconbtn { left: 14px; border: 0; cursor: pointer; }
.viewer > a { right: 14px; }

#toasts {
  position: fixed; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 84px);
  z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 20px;
}
.toast {
  background: #26282D; color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: 14px; max-width: 100%; text-align: center;
  opacity: 0; transform: translateY(12px); transition: .22s;
}
.toast.shown { opacity: 1; transform: none; }
.toast.error { background: var(--danger); }

/* ── строки списков (настройки, профиль, админка) ────────────────────── */

.list-head {
  font-size: 13px; color: var(--text-dim); font-weight: 600;
  padding: 18px 24px 6px;
}
.list-section {
  background: var(--surface); border-radius: var(--radius); margin: 0 14px 10px;
  overflow: hidden;
}
.row {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 13px 16px; border: 0; background: none; text-align: left;
  cursor: pointer; color: var(--text);
}
.row + .row { border-top: 1px solid var(--divider); }
.row:active { background: var(--surface-alt); }
.row.danger { color: var(--danger); }
.row-icon {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  display: grid; place-items: center; background: var(--surface-alt); overflow: hidden;
}
.row-icon.accent { background: var(--accent); color: #fff; }
.row-icon.danger { background: rgba(229,72,77,.14); color: var(--danger); }
.row-icon img { width: 100%; height: 100%; object-fit: contain; }
.row-title { font-weight: 500; display: flex; align-items: center; gap: 6px; min-width: 0; }
.row-title.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 1px; }
.row-title.dim { opacity: .5; text-decoration: line-through; }
.row-sub {
  font-size: 13px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row > .ico:last-child { color: var(--text-dim); transform: scaleX(-1); }

.tag {
  font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); flex: none;
}
.tag.red { background: rgba(229,72,77,.16); color: var(--danger); }

.profile-head { text-align: center; padding: 20px 24px 8px; }
.profile-avatar { position: relative; width: 108px; margin: 0 auto 14px; cursor: pointer; }
.profile-avatar .avatar { width: 108px; height: 108px; font-size: 34px; }
.profile-cam {
  position: absolute; right: -2px; bottom: -2px;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; border: 3px solid var(--bg);
}
.profile-name { font-size: 22px; font-weight: 600; display: flex; justify-content: center; }
.profile-username { color: var(--text-dim); font-size: 14px; margin-top: 2px; }
.profile-bio { color: var(--text-dim); font-size: 14px; margin-top: 8px; }

.profile-quick { display: flex; gap: 10px; padding: 14px 14px 4px; }
.quick {
  flex: 1; border: 0; border-radius: 20px; padding: 14px 8px; cursor: pointer;
  background: var(--surface); color: var(--accent);
  display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 13px;
}
.quick:active { background: var(--surface-alt); }

.pick-list { max-height: 42vh; overflow-y: auto; margin-top: 6px; }
.pick-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.pick-chips .chip { cursor: pointer; }

.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px; padding: 4px 14px;
}
.stat { background: var(--surface); border-radius: 20px; padding: 16px; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.stat-label { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

/* ── карточки обмена и список изменений ──────────────────────────────── */

.share-card {
  display: flex; gap: 14px; align-items: center;
  background: var(--surface-alt); border-radius: var(--radius); padding: 14px;
  margin-bottom: 14px;
}
.share-swatch { width: 52px; height: 52px; border-radius: 50%; flex: none; }
.share-row { display: flex; justify-content: space-between; font-size: 14px; padding: 2px 0; }
.share-row span { color: var(--text-dim); }
.share-link { font-size: 13px; letter-spacing: 0; word-break: break-all; }

.whatsnew-head { display: flex; align-items: center; gap: 14px; padding-bottom: 12px; }
.whatsnew-badge {
  width: 52px; height: 52px; border-radius: 18px; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 17px;
}
.whatsnew-group { margin-bottom: 12px; }
.whatsnew-head-row {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 600; color: var(--accent); padding: 4px 0;
}
.whatsnew-group ul { margin: 4px 0 0; padding-left: 20px; }
.whatsnew-group li { font-size: 14px; line-height: 1.45; margin-bottom: 5px; }

.live-note {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-dim); padding: 0 24px 10px;
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--online);
  animation: blink 1.8s ease-in-out infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* Изменившееся число коротко подсвечивается — иначе движение цифр
   на экране легко пропустить. */
.bump { animation: bump .5s ease-out; }
@keyframes bump {
  0%   { color: var(--accent); transform: scale(1.14); }
  100% { color: inherit; transform: none; }
}

.invite-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 24px; letter-spacing: 2px; text-align: center;
  background: var(--surface-alt); border-radius: 18px; padding: 18px; margin-bottom: 14px;
  user-select: all;
}

/* ── обрезка картинки ────────────────────────────────────────────────── */

.cropper {
  position: absolute; inset: 0; background: #0B0C0E; color: #fff;
  display: flex; flex-direction: column;
  animation: fade-in .2s ease-out;
}
.cropper.closing { animation: fade-out .18s ease-in forwards; }
.cropper .topbar { background: transparent; }
.cropper .iconbtn { color: #fff; }
.crop-stage { flex: 1; display: grid; place-items: center; padding: 16px; }
.crop-frame {
  width: min(78vw, 340px); aspect-ratio: 1; overflow: hidden;
  background: #000; touch-action: none; cursor: grab;
  box-shadow: 0 0 0 2px rgba(255,255,255,.85), 0 0 0 4000px rgba(0,0,0,.55);
  border-radius: 18px;
}
.crop-frame.circle { border-radius: 50%; }
.crop-canvas { display: block; }
.crop-controls { padding: 0 28px calc(var(--safe-bottom) + 26px); text-align: center; }
.crop-hint { font-size: 13px; color: var(--text-dim); }
.crop-zoom { width: 100%; margin-top: 12px; accent-color: var(--accent); }

/* ── звонок ──────────────────────────────────────────────────────────── */

.call {
  position: fixed; inset: 0; z-index: 50;
  background: #0A0B0D; color: #fff;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--safe-top) + 8px) 12px calc(var(--safe-bottom) + 22px);
}
.call-head { display: flex; align-items: center; width: 100%; flex: none; }
.call .iconbtn { color: #fff; }
.call-name { font-size: 19px; font-weight: 600; }
.call-stage { font-size: 13px; opacity: .7; margin-top: 2px; }

.call .tiles {
  flex: 1; width: 100%; display: grid; gap: 6px; padding: 10px 0;
  grid-template-columns: 1fr; min-height: 0;
}
.call .tiles.n2 { grid-template-rows: 1fr 1fr; }
.call .tiles.n3, .call .tiles.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.tile { position: relative; border-radius: 18px; overflow: hidden; background: #15171B; min-height: 0; }
/* Вписываем целиком, а не обрезаем: с обрезкой у собеседника пропадали
   верх и низ кадра — как раз то место, где обычно голова. */
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile video.mirror { transform: scaleX(-1); }
.tile-label {
  position: absolute; left: 8px; bottom: 8px;
  background: rgba(0,0,0,.5); border-radius: 999px;
  padding: 3px 10px; font-size: 12px;
}

.call-idle { flex: 1; display: grid; place-items: center; }
.call-pulse {
  width: 128px; height: 128px; border-radius: 50%;
  background: rgba(255,255,255,.12);
  animation: pulse 1.8s ease-in-out infinite;
  display: grid; place-items: center;
}
.call-pulse .avatar { width: 128px; height: 128px; font-size: 42px; }
@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,255,255,.18); }
  50%      { transform: scale(1.06); box-shadow: 0 0 0 26px rgba(255,255,255,0); }
}
.call-hint { position: absolute; bottom: 30%; font-size: 13px; opacity: .7; }

.call-controls { display: flex; gap: 14px; margin-top: 6px; flex: none; }
.cbtn {
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.18); color: #fff; cursor: pointer;
  display: grid; place-items: center;
}
.cbtn.on { background: #fff; color: #16181C; }
.hangup {
  width: 68px; height: 68px; border-radius: 50%; border: 0;
  background: var(--danger); color: #fff; margin-top: 16px; cursor: pointer;
  display: grid; place-items: center;
}
.call-answer { display: flex; gap: 46px; }
.answer {
  width: 68px; height: 68px; border-radius: 50%; border: 0;
  background: var(--online); color: #fff; margin-top: 16px; cursor: pointer;
  display: grid; place-items: center;
  animation: shake 1.6s ease-in-out infinite;
}
@keyframes shake {
  0%, 60%, 100% { transform: rotate(0); }
  70% { transform: rotate(-12deg); }
  80% { transform: rotate(12deg); }
  90% { transform: rotate(-8deg); }
}

.call-bar {
  position: fixed; left: 10px; right: 10px; top: calc(var(--safe-top) + 8px);
  z-index: 55; display: flex; align-items: center; gap: 10px;
  background: var(--online); color: #fff;
  border-radius: 18px; padding: 10px 12px; cursor: grab;
  box-shadow: 0 8px 20px rgba(0,0,0,.22);
  touch-action: none; user-select: none;
  max-width: 420px;
}
.call-bar.dragging { cursor: grabbing; box-shadow: 0 14px 30px rgba(0,0,0,.3); }
.call-bar-end {
  width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: var(--danger); color: #fff; cursor: pointer;
  display: grid; place-items: center; flex: none;
}

/* ── заставка ────────────────────────────────────────────────────────── */

.intro {
  position: fixed; inset: 0; z-index: 200;
  background: #05070C; color: #fff;
  display: flex; flex-direction: column;
  animation: fade-in .3s ease-out;
}
.intro.closing { animation: fade-out .4s ease-in forwards; }

.intro-stage {
  flex: 1; position: relative; display: grid; place-items: center;
  overflow: hidden;
}
.intro-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
}

.intro-slide {
  text-align: center; padding: 0 30px; max-width: 460px;
  animation: slide-fade .45s ease-out;
}
@keyframes slide-fade {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: none; }
}
.intro-icon { font-size: 62px; line-height: 1; margin-bottom: 18px; }
.intro-slide h2 { font-size: 26px; margin: 0 0 10px; }
.intro-slide p { font-size: 16px; line-height: 1.5; color: rgba(255,255,255,.72); margin: 0; }

.intro-bottom {
  flex: none; padding: 0 24px calc(var(--safe-bottom) + 26px);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.intro-dots { display: flex; gap: 7px; height: 8px; }
.intro-dots i {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(255,255,255,.28); transition: .25s;
}
.intro-dots i.on { background: #fff; width: 20px; border-radius: 4px; }

/* Кнопка проявляется, когда ролик отыграл, — до этого её нет вовсе. */
.intro-next {
  max-width: 420px; opacity: 0; transform: translateY(10px);
  transition: opacity .5s ease-out, transform .5s ease-out;
  pointer-events: none;
}
.intro-next.shown { opacity: 1; transform: none; pointer-events: auto; }

.intro-skip {
  border: 0; background: none; color: rgba(255,255,255,.55);
  font-size: 14px; cursor: pointer; padding: 4px 10px;
  opacity: 0; transition: opacity .4s; pointer-events: none;
}
.intro-skip.shown { opacity: 1; pointer-events: auto; }

/* ── экран оформления ────────────────────────────────────────────────── */

.theme-preview {
  margin: 12px 14px 4px; border-radius: var(--radius); overflow: hidden;
  background-color: var(--bg); border: 1px solid var(--divider);
}
.theme-preview.with-wallpaper {
  background-image: var(--wallpaper);
  background-size: cover; background-position: center;
}
.theme-preview .bubble { max-width: 82%; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 4px; }
.chip.on { background: var(--accent); color: #fff; }

.swatches {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 10px; padding: 2px 16px 4px;
}
.swatch {
  aspect-ratio: 1; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--swatch); color: #fff;
  display: grid; place-items: center;
}
.swatch.on { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--swatch); }

.walls {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px; padding: 2px 16px 4px;
}
.wall {
  aspect-ratio: 3/4; border: 0; border-radius: 14px; cursor: pointer;
  background: var(--surface-alt); color: var(--text-dim);
  display: grid; place-items: center; font-size: 12px;
}
.wall.on { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--accent); }
.wall.own { background: var(--surface-alt); color: var(--accent); }

.pref-range { width: 100%; margin-top: 8px; accent-color: var(--accent); }

.switch {
  width: 46px; height: 27px; border-radius: 999px; flex: none;
  background: var(--surface-hi); position: relative; transition: background .18s;
}
.switch i {
  position: absolute; top: 3px; left: 3px; width: 21px; height: 21px;
  border-radius: 50%; background: #fff; transition: transform .18s;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch.on { background: var(--accent); }
.switch.on i { transform: translateX(19px); }

/* ── стили интерфейса ────────────────────────────────────────────────── */

/* iOS: заголовок по центру и тонкие разделители под шапкой. */
:root[data-skin="ios"] .bigtitle { font-size: 27px; letter-spacing: -.3px; }
:root[data-skin="ios"] .topbar { border-bottom: 1px solid var(--divider); }
:root[data-skin="ios"] .topbar .title { font-size: 16px; }
:root[data-skin="ios"] .list-section { box-shadow: none; }
:root[data-skin="ios"] .bubble.in.first,
:root[data-skin="ios"] .bubble.out.first { border-radius: var(--bubble-radius); }
:root[data-skin="ios"] .send { border-radius: 50%; }

/* Material: заголовок обычного размера, кнопки плоские и прямоугольнее. */
:root[data-skin="material"] .bigtitle { font-size: 23px; font-weight: 500; letter-spacing: 0; }
:root[data-skin="material"] .btn { border-radius: 12px; text-transform: none; }
:root[data-skin="material"] .search { border-radius: var(--bar-radius); }
:root[data-skin="material"] .avatar { border-radius: 50%; }

/* Строгий: почти без скруглений, плотнее строки — больше текста на экране. */
:root[data-skin="square"] .bigtitle { font-size: 24px; font-weight: 600; }
:root[data-skin="square"] .btn,
:root[data-skin="square"] .search,
:root[data-skin="square"] .field { border-radius: 8px; }
:root[data-skin="square"] .avatar { border-radius: 10px; }
:root[data-skin="square"] .fab { border-radius: 10px; }

/* На широком экране мессенджер держим по центру — иначе на компьютере
   переписка растягивается на всю ширину и читать её неудобно. */
@media (min-width: 720px) {
  #app { max-width: 720px; margin: 0 auto; height: 100%; box-shadow: 0 0 0 1px var(--divider); }
  .fab { right: max(18px, calc(50vw - 342px)); }
}
