:root {
  --visible-h: 100dvh;
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #151515;
  --elevated: #1d1d1d;
  --hairline: #303030;
  --text: #f5f5f5;
  --muted: #a3a3a3;
  --radius: 18px;

  /* Единая сетка отступов: 4 / 8 / 12 / 16 / 24 */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-6: 24px;

  /* Единые метрики кнопок */
  --btn-h: 44px;
  --btn-pad-x: var(--sp-4);
  --btn-font: 0.95rem;
  --btn-radius: 12px;

  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
}

/* Скроллбары скрыты везде, но сама прокрутка работает. */
*, *::before, *::after {
  box-sizing: border-box;
  scrollbar-width: none;       /* Firefox */
  -ms-overflow-style: none;    /* старый Edge */
}
*::-webkit-scrollbar { display: none; width: 0; height: 0; } /* Chrome / Safari */

body { margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; }

/* Все кнопки: без рамок, обводок, focus-ring и теней.
   Исключение — плавающий «+», у него тень задаётся ниже классом. */
button {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  border: 0;
  outline: none;
  box-shadow: none;
  background: none;
  color: inherit;
  font: inherit;
}
button::-moz-focus-inner { border: 0; padding: 0; }
button:focus, button:focus-visible,
input:focus, input:focus-visible,
textarea:focus, textarea:focus-visible,
.settings-row:focus, .settings-row:focus-visible { outline: none; }

/* Одинаковая высота/отступ/шрифт у всех кнопок действий и строк. */
.primary, .secondary, .link, .tab, .settings-row,
.segmented button, .stack button, .auth-card button, .reply-composer button {
  min-height: var(--btn-h);
  padding: 0 var(--btn-pad-x);
  font-size: var(--btn-font);
  line-height: 1;
  border: 0;
  outline: none;
  box-shadow: none;
}
.primary, .secondary, .link, .tab,
.segmented button, .stack button, .auth-card button, .reply-composer button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.muted { color: var(--muted); font-size: 0.8rem; }
.error { color: var(--text); font-size: 0.85rem; font-weight: 600; }

.splash, .auth { min-height: 100dvh; display: grid; place-items: center; padding: var(--sp-6); }
.brand-chain { display: flex; gap: var(--sp-2); justify-content: center; }
.splash .brand { font-size: 40px; letter-spacing: 0; }
.brand span { display: inline-block; opacity: 1; }
.auth-card {
  position: relative;
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 44px var(--sp-6) var(--sp-6);
  text-align: center;
}
.auth-card p { margin: 0; line-height: 1.4; }
.auth-card > .back-btn,
.auth-modal > .auth-close {
  position: absolute;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  background: var(--elevated);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  transition: background .15s ease, transform .15s ease;
}
.auth-card > .back-btn:hover,
.auth-modal > .auth-close:hover { background: #2a2a2d; }
.auth-card > .back-btn:active,
.auth-modal > .auth-close:active { transform: scale(.94); }
.auth-card > .back-btn svg,
.auth-modal > .auth-close svg {
  width: 20px;
  height: 20px;
  display: block;
}
.auth-card > .back-btn { top: 12px; left: 12px; }
.otp-wrap {
  display: grid;
  gap: 8px;
  margin: 2px 0;
}
.otp-boxes {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  width: min(100%, 320px);
  margin: 0 auto;
}
.otp-boxes .otp-box {
  width: 100%;
  height: 52px;
  padding: 0;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  border-radius: 14px;
  background: var(--elevated);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--hairline);
  caret-color: var(--text);
  transition: transform .16s cubic-bezier(.2,.8,.2,1), background .16s ease, box-shadow .16s ease;
}
.otp-boxes .otp-box:focus {
  background: #262626;
  transform: translateY(-2px) scale(1.04);
  box-shadow: inset 0 0 0 2px var(--text), 0 6px 18px #0006;
}
.otp-boxes .otp-box.filled {
  background: #222224;
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--text) 42%, transparent);
  animation: otp-pop .2s cubic-bezier(.2,.8,.2,1);
}
.otp-boxes.shake {
  animation: otp-shake .36s cubic-bezier(.36,.07,.19,.97);
}
.otp-boxes.shake .otp-box {
  box-shadow: inset 0 0 0 1.5px #ff5a5f;
}
.otp-emoji-bar {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  width: min(100%, 320px);
  margin: 0 auto;
}
.otp-emoji-bar .otp-emoji-btn {
  width: 100%;
  height: 34px;
  min-height: 34px;
  padding: 0;
  margin: 0;
  border-radius: 10px;
  background: var(--elevated);
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .12s ease, background .12s ease;
}
.otp-emoji-bar .otp-emoji-btn:hover { background: #2a2a2d; }
.otp-emoji-bar .otp-emoji-btn:active { transform: scale(.9); }
@keyframes otp-pop {
  0% { transform: scale(.86); }
  60% { transform: scale(1.07); }
  100% { transform: scale(1); }
}
@keyframes otp-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.brand { display: flex; gap: var(--sp-2); justify-content: center; font-size: 26px; letter-spacing: 0; }
.auth h1 { margin: 0 0 var(--sp-3); font-size: 26px; }
.segmented {
  display: flex; gap: var(--sp-2); background: var(--elevated);
  border-radius: var(--btn-radius); padding: var(--sp-1); margin: var(--sp-6) 0;
}
.segmented button {
  flex: 1; background: transparent; color: var(--muted); border-radius: var(--sp-2);
}
.segmented button.selected { background: var(--hairline); color: var(--text); }
.stack { display: grid; gap: var(--sp-3); }
input, textarea {
  width: 100%; background: var(--elevated); color: var(--text);
  border: 0; outline: none; border-radius: var(--btn-radius); padding: var(--sp-3);
}
textarea { resize: none; min-height: 72px; max-height: 180px; overflow-y: auto; }
input:focus, textarea:focus { background: #262626; }
input::placeholder, textarea::placeholder { color: var(--muted); }
.primary { border-radius: var(--btn-radius); background: var(--text); color: var(--bg); font-weight: 600; }
.secondary { border-radius: var(--btn-radius); background: var(--elevated); color: var(--text); font-weight: 600; }

/* Обе кнопки экрана приветствия и major-CTA авторизации — одинаковых размеров.
   Раньше только .primary внутри .auth-card получал фиксированную ширину/отступ,
   а .secondary растягивался grid-ом на всю колонку — «Создать аккаунт» выглядел
   больше и выше, чем «Уже есть аккаунт — Войти». Высота/padding/шрифт/радиус
   уже одинаковы из общего правила выше; здесь выравниваем display/width/margin. */
.auth-card .primary,
.auth-card .secondary,
.welcome-actions .primary,
.welcome-actions .secondary {
  display: block;
  width: min(100%, 320px);
  margin: var(--sp-2) auto 0;
}
.primary.compact { display: block; width: min(100%, 320px); margin: var(--sp-4) auto var(--sp-2); }
.primary:disabled, .secondary:disabled { opacity: 0.5; }
.link { background: none; color: var(--muted); }
.welcome-actions { margin-top: var(--sp-6); }
.auth-tagline { margin-top: 6px; font-size: 0.85rem; }
.step-progress { margin: 16px 0 8px; font-weight: 600; color: var(--text); font-size: 0.95rem; }
.auth-subtitle { color: var(--text); font-size: 0.9rem; }
.auth-hint { color: var(--muted); font-size: 0.8rem; }

.shell { max-width: 1400px; margin: 0 auto; min-height: 100dvh; position: relative; }
.main-col { width: min(100%, 640px); margin: 0 auto; }
.rail { display: none; }
.topbar {
  position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center;
  /* Горизонтальный отступ совпадает с .content (16px), чтобы логотип и карточки
     сидели на одной сетке. */
  padding: var(--sp-3) var(--sp-4); background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(16px); z-index: 2;
}
/* overflow остаётся — скрыта только визуальная полоса. */
.content { padding: var(--sp-2) var(--sp-4) 96px; height: calc(100dvh - 60px); overflow-y: auto; }
/* Chain owns its own scroll area: the outer scroller is disabled here. */
.thread-open .content { height: var(--visible-h, 100dvh); overflow: hidden; padding: 0; }
/* Guest chains have no composer to publish --visible-h; the root default
   keeps the same single geometry source and avoids nested scrolling. */
main.content:has(.guest-chain) { height: calc(var(--visible-h, 100dvh) - 60px); overflow: hidden; padding: 0; }
main.content:has(.guest-chain) .chain { height: 100%; }
.main-col.thread-open .floating-plus, .main-col.thread-open .bottombar { display: none; }
/* Карточки: единый радиус 18px (--radius) у ленты, композера и identity. */
.composer, .post, .identity {
  background: var(--surface); border-radius: var(--radius);
  padding: var(--sp-4); margin-bottom: var(--sp-3);
}
.composer-row { display: flex; align-items: center; justify-content: space-between; margin-top: var(--sp-2); }
.post-head { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.post-user-link { display: flex; align-items: center; gap: 12px; flex: 1 1 auto; min-width: 0; text-align: left; padding: 0; }
.post-menu { position: relative; margin-left: auto; align-self: flex-start; }
.post-menu-button { border: 0; background: transparent; color: var(--muted); font-size: 28px; width: 40px; height: 40px; line-height: 1; }
.popup-backdrop { position: fixed; inset: 0; z-index: 4; background: transparent; }
.post-menu-popup { position: absolute; right: 0; top: 100%; z-index: 5; padding: 4px; background: var(--elevated); border-radius: 12px; box-shadow: 0 6px 22px #0008; }
.post-menu-popup button { border: 0; background: transparent; color: var(--text); padding: 10px 16px; white-space: nowrap; transition: color .15s ease; }
.post-menu-popup button.menu-copied { color: #4ade80; animation: menu-copied-pop .22s cubic-bezier(.2, .9, .25, 1.2) both; }
@keyframes menu-copied-pop {
  0% { transform: scale(.9); opacity: .4; }
  100% { transform: scale(1); opacity: 1; }
}
.post-author { display: flex; align-items: baseline; gap: 6px; flex: 1 1 auto; min-width: 0; overflow: hidden; }
.post-author strong, .post-author .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.post-author strong { flex: 0 0 auto; max-width: 75%; font-size: .9rem; }
.post-author .muted { flex: 0 1 auto; }
.post-follow { flex: none; font-weight: 600; font-size: .8rem; padding: 8px 0; }
.post-follow:disabled { opacity: .55; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--elevated);
  display: grid; place-items: center; font-size: 15px; font-weight: 700; color: var(--muted); overflow: hidden; flex: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.post-items { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: var(--sp-2); padding: var(--sp-4) 0; }
.emoji { font-size: 56px; line-height: 1.1; }
.sticker {
  width: 148px; height: 148px; object-fit: contain;
  border-radius: 12px; background: transparent;
}
/* A chain with fewer items gets noticeably larger art. */
.post-items:has(> :nth-child(1):last-child) .sticker { width: 260px; height: 260px; }
.post-items:has(> :nth-child(2):nth-last-child(1)) .sticker { width: 200px; height: 200px; }
.composer-mode {
  display: inline-flex; gap: 6px; padding: 5px; margin: 10px 0 18px;
  border-radius: 999px; background: var(--elevated);
}
.mode-tab {
  min-height: 38px; padding: 0 22px; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted); font-size: 14px;
}
.mode-tab.active { background: var(--surface, #2a2a2a); color: var(--text); }
.sticker-picker { margin-top: 14px; }
.stickers-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; position: relative; }
.stickers-head > .link {
  margin-left: auto; width: 44px; height: 44px; border-radius: 50%;
  background: var(--elevated); color: var(--text); font-size: 20px;
}
.stickers-head > .link[aria-expanded="true"] { background: var(--surface, #333); }
.pack-edit-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 5;
  display: flex; flex-direction: column; align-items: stretch; gap: 2px;
  min-width: 210px; background: var(--elevated); border-radius: 14px; padding: 6px;
  box-shadow: 0 12px 36px #000a;
}
.pack-edit-menu button {
  border: 0; background: none; color: var(--text);
  padding: 10px 12px; min-height: 40px; border-radius: 8px;
  text-align: left; width: 100%; display: flex; align-items: center;
  white-space: nowrap; transition: background .14s ease, color .14s ease;
}
.pack-edit-menu button:hover { background: rgba(255, 255, 255, .07); }
.pack-edit-menu button.menu-danger { color: #ff6b6b; }
.pack-edit-menu button.menu-danger:hover { background: rgba(255, 107, 107, .12); }
.sticker-remove {
  width: 28px; height: 28px; min-height: 28px; padding: 0;
  border: 0; border-radius: 50%;
  background: var(--elevated); color: var(--muted); font-size: 13px; line-height: 1;
  display: inline-grid; place-items: center;
  transition: background .14s ease, color .14s ease;
}
.sticker-remove:hover { background: rgba(255, 107, 107, .18); color: #ff6b6b; }
.sticker-tile-wrap.editing .sticker-tile { cursor: grab; }
.sticker-grid-preview { margin-top: 18px; gap: 14px; align-items: start; }
.sticker-placeholder {
  width: 96px; height: 96px; border-radius: 16px; display: inline-grid; place-items: center;
  background: var(--elevated); color: var(--muted); font-size: 34px;
}
.post-actions {
  display: flex; flex-wrap: nowrap; justify-content: space-between; align-items: center;
  gap: 12px; padding-top: var(--sp-3); min-width: 0;
}
.post-actions-left, .post-actions-right { display: flex; align-items: center; gap: 6px; min-width: 0; }
.post-actions-right { position: relative; flex: none; }
.reply-count { font-variant-numeric: tabular-nums; }
.reaction-add {
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: var(--elevated); color: var(--muted); font-size: 20px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
  transition: background .15s ease, color .15s ease;
}
.reaction-add:hover, .reaction-add.open { color: var(--text); background: #282828; }
.reaction-popup {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 5;
  display: flex; flex-wrap: nowrap; gap: 2px; width: 280px; max-width: 78vw;
  overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-width: none;
  padding: 6px; border-radius: 14px; background: var(--elevated, #1c1c1c);
  box-shadow: 0 8px 28px #0009;
}
.reaction-popup::-webkit-scrollbar { display: none; }
.reaction-popup .reaction { flex: none; margin: 0; padding: 6px; font-size: 22px; opacity: .75; }
.reaction-popup .reaction:hover, .reaction-popup .reaction.active { opacity: 1; }
.post-replies { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; flex: none; }
.reaction-summary { display: inline-flex; align-items: center; gap: 4px; flex: none; }
.reaction-chip {
  display: inline-flex; align-items: center; gap: 3px; height: 24px; padding: 0 8px;
  border: 0; border-radius: 999px; background: var(--elevated);
  color: var(--text); font-size: 12px; line-height: 1; white-space: nowrap;
  animation: chip-in .18s cubic-bezier(.2, .8, .2, 1) both;
}
.reaction-chip .chip-emoji { font-size: 14px; }
.reaction-chip .chip-count { font-variant-numeric: tabular-nums; color: var(--muted); }
.reaction-chip.active { background: rgba(255, 255, 255, .16); }
.reaction-chip.active .chip-count { color: var(--text); }
@keyframes chip-in { from { opacity: 0; transform: translateY(4px) scale(.94); } to { opacity: 1; transform: none; } }
.comment-icon { width: 18px; height: 18px; }
.reactions { display: flex; align-items: center; gap: var(--sp-1); }
.share-feedback {
  margin-left: 8px; white-space: nowrap;
  animation: share-feedback-in .18s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes share-feedback-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}
.post-feedback { grid-column: 2; }
.reaction { border: 0; background: none; font-size: 20px; opacity: 0.45; padding: var(--sp-1); }
.reaction.active { opacity: 1; transform: scale(1.15); }
/* The iOS feed uses a left avatar column with content and actions aligned to
   the author, rather than a large filled card. */
.feed .post { display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: 12px; background: transparent; border-radius: 0; padding: 18px 0 26px; margin: 0 0 12px; }
.feed .post-head { grid-column: 1 / -1; }
.feed .post-items, .feed .post-actions { grid-column: 2; }
.feed .post-items { padding: 12px 0 8px; }
.feed .segmented { background: transparent; border-radius: 0; padding: 0; margin: 16px 0 28px; }
.feed .segmented button { position: relative; background: transparent; color: var(--muted); }
.feed .segmented button.selected { background: transparent; color: var(--text); font-weight: 600; }
.feed .segmented button.selected::after { content: ""; position: absolute; width: 42px; height: 2px; border-radius: 2px; background: var(--text); bottom: 0; }
.skeleton-stack { display: grid; gap: var(--sp-3); }
.skeleton { height: 96px; border-radius: var(--radius); background: var(--surface); }
.bottombar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(620px, 100%); display: flex; justify-content: space-around;
  padding: var(--sp-2) var(--sp-4) calc(var(--sp-2) + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--elevated) 90%, transparent);
  backdrop-filter: blur(18px);
}
.tab { border: 0; background: none; color: var(--muted); }
.tab.active { color: var(--text); }
.bottombar.hidden { transform: translateY(120%); opacity: 0; pointer-events: none; }
.floating-plus {
  position: fixed; right: max(20px, calc((100vw - 640px) / 2 - 64px)); bottom: 28px;
  width: 54px; height: 54px; border-radius: 50%; border: 0;
  background: var(--text); color: var(--bg); font-size: 28px; line-height: 1;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); z-index: 5;
}
/* Шапка Настроек: единая строка — «Назад» слева (приглушённый, с отступом),
   заголовок рядом, «На главную» справа. Одинаковая высота и вертикальное
   выравнивание, без обводок и focus-ring. */
.settings-head {
  display: flex; align-items: center; gap: var(--sp-2);
  min-height: var(--btn-h);
}
/* .screen h2 даёт margin снизу — в хедере он не нужен, иначе заголовок «провисает». */
.settings-head h2 {
  margin: 0; font-size: 20px; font-weight: 700; line-height: 1.2;
}
.settings-head .link { padding: 0 var(--sp-2); }
/* Заголовки во всех хедерах — одна типографика и одна сетка отступов. */
.brand-home {
  border: 0; background: none; color: var(--text);
  font-size: 20px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em;
  padding: 0; margin: 0; display: inline-flex; align-items: center;
}
.header-logo { width: 140px; height: auto; display: block; }
.auth-logo { width: min(260px, 80%); height: auto; margin: 8px auto 0; display: block; }
.home-link { margin-left: auto; }
.share-btn { font-size: 0.8rem; white-space: nowrap; }
.pack-chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.pack-chip { border: 0; background: var(--elevated); color: var(--text); padding: 8px 12px; border-radius: 12px; }
.upload-sticker {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; padding: 0 16px; border: 0; border-radius: 999px;
  background: var(--elevated); color: var(--text); font-size: 14px; cursor: pointer;
}
.upload-sticker:hover { background: #262626; }
.upload-sticker input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.sticker-tile-wrap { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.sticker-tile-controls {
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.sticker-tile-controls button {
  width: 28px; height: 28px; min-width: 28px; min-height: 28px; padding: 0;
  border: 0; border-radius: 50%;
  background: var(--elevated); color: var(--muted); font-size: 13px;
  display: inline-grid; place-items: center;
}
.sticker-tile-controls button:hover { color: var(--text); background: #282828; }
.sticker-grid-preview { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sticker-tile { width: 100%; border: 0; background: transparent; aspect-ratio: 1; display: grid; place-items: center; border-radius: 14px; }
.sticker-tile img { width: 82%; height: 82%; object-fit: contain; }
.sticker-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.9); display: grid; place-items: center; z-index: 20; }
.sticker-preview { display: grid; justify-items: center; gap: 12px; }
.sticker-preview img { width: 220px; height: 220px; object-fit: contain; }
/* Строки настроек — такие же карточки, как .post (в разметке class="post settings-row"). */
.settings-row {
  width: 100%; text-align: left; color: var(--text); cursor: pointer;
  background: var(--surface); border: 0; border-radius: var(--radius);
  box-shadow: none; outline: none;
}
.palette-emoji img {
  width: 34px; height: 34px; object-fit: cover; border-radius: 0;
}
.nav-svg { width: 26px; height: 26px; display: block; }
.plus-coin { color: var(--text); }

@media (min-width: 1000px) {
  .rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-6);
    position: fixed;
    left: max(12px, calc((100vw - 1400px) / 2));
    top: 0;
    width: 72px;
    height: 100dvh;
    padding: var(--sp-6) 0;
  }
  .rail-items { display: grid; gap: var(--sp-3); }
  .rail-btn {
    width: 52px; height: 52px; border: 0; border-radius: 16px;
    background: transparent; color: var(--muted);
    display: grid; place-items: center;
  }
  .rail-btn.active { background: var(--elevated); color: var(--text); }
  .rail-btn.logout { margin-top: auto; font-size: 20px; color: var(--muted); }
  .bottombar { display: none; }
}

@media (max-width: 999px) {
  .shell { max-width: 620px; }
}
.screen { padding: var(--sp-2) 0 var(--sp-6); }
.screen h2 {
  font-size: 20px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em;
  margin: 0 0 var(--sp-3);
}
.chain {
  height: var(--visible-h, 100dvh); min-height: 0; overflow: hidden;
  display: flex; flex-direction: column;
}
/* Universal back affordance: icon-only chevron, always at the left edge. */
.back-btn {
  width: 40px; height: 40px; min-height: 40px; flex: none; justify-self: start;
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: 0; padding: 0; border: 0; background: none; color: var(--text);
  border-radius: 50%; cursor: pointer;
}
.back-btn:hover { background: var(--elevated); }
.back-btn svg { width: 22px; height: 22px; display: block; }
.chain-head, .settings-head { display: flex; align-items: center; gap: var(--sp-4); min-height: 44px; }
.chain-head h2, .settings-head h2 { margin: 0; }
.chain-head { display: grid; grid-template-columns: 1fr auto 1fr; }
.chain-head > button:first-child { justify-self: start; padding-left: 0; }
.chain-back { gap: 3px; }
.chain-back > span:first-child { font-size: 30px; line-height: 1; }
.chain-share { justify-self: end; padding: 8px; color: var(--muted); }
.chain-share svg, .palette-toggle svg { display: block; width: 24px; height: 24px; }
.chain-root { margin: 8px 0 16px; }
/* Read-only guest chain: no composer, no reactions, no share/follow controls. */
.guest-chain-notice {
  display: flex; flex-direction: column; align-items: stretch; gap: var(--sp-2);
  margin-top: var(--sp-6); padding-top: var(--sp-4); border-top: 1px solid var(--hairline);
}
.guest-chain-notice p { margin: 0; text-align: center; }
.guest-chain-login { width: 100%; }
.chain-root-head { display: flex; align-items: center; gap: 12px; }
.chain-root .post-items { margin-left: 48px; padding: 8px 0; gap: 10px; }
.chain-root .sticker { width: 160px; height: 160px; }
.post-items.clickable { cursor: pointer; }
.post-items.small { padding: var(--sp-1) 0; }
.emoji.small { font-size: 40px; }
.reply-sticker,
.reply .post-items .sticker,
.reply .post-items:has(> :nth-child(1):last-child) .sticker,
.reply .post-items:has(> :nth-child(2):nth-last-child(1)) .sticker { width: 88px; height: 88px; }
.reply { position: relative; padding: var(--sp-2) 0 var(--sp-2) var(--sp-3); border-left: 1px solid var(--hairline); margin-bottom: var(--sp-2); }
.reply.selected { background: #ffffff0a; }
.reply-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.reply-dot { position: absolute; left: -4px; top: 16px; color: var(--muted); }
.reply-user { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .78rem; font-weight: 600; min-width: 0; }
.reply-avatar { width: 28px; height: 28px; font-size: 11px; }
.branch { margin-left: 8px; color: var(--muted); white-space: nowrap; font-size: .76rem; padding: 6px 0; }
/* Reply dock: a normal flex child. The visual keyboard occupies reserved
   space inside this same dock, so only .reply-tree scrolls. */
.reply-composer {
  flex: none; display: flex; flex-direction: column; gap: 6px;
  padding: var(--sp-2) 0 var(--sp-3); position: relative; margin-top: 0;
  z-index: auto; background: var(--bg);
}
.reply-recipient { display: flex; align-items: center; justify-content: flex-start; gap: 8px; min-height: 28px; padding: 0 48px 0 2px; }
.reply-recipient label { max-width: min(70vw, 320px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .74rem; }
.reply-recipient .reply-count { flex: none; margin-left: 4px; }
.reply-composer .reply-cancel { min-height: 28px; width: 28px; padding: 0; color: var(--muted); font-size: 13px; }
/* One thin pill. The keyboard icon sits on the recipient row above it;
   the field itself stays quiet until the user adds something. */
.reply-composer-field {
  position: static; display: flex; align-items: center; gap: 6px; cursor: text;
  margin-top: 12px; min-height: 52px;
  border: 1px solid var(--hairline); border-radius: 999px;
  padding: 8px 18px 8px 8px; background: transparent;
}
.reply-composer-field .visual-composer { flex: 1 1 auto; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; }
.reply-composer-field .visual-composer-items { flex: 1 1 120px; min-height: 34px; padding: 0; }
.reply-composer .visual-hint { color: var(--muted); font-size: 22px; opacity: .55; }
/* Keyboard icon lives at the far right of the recipient/count line.
   Positioning is against .reply-composer (sticky), not the items area. */
.reply-composer-field .visual-composer { position: static; }
.reply-composer .visual-composer-tools {
  position: absolute; top: 12px; right: 25px; margin: 0; flex: none; z-index: 3;
}
.reply-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.reply-count { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.reply-composer .reply-send {
  width: 34px; height: 34px; min-height: 34px; padding: 0; border: 0;
  background: transparent; color: var(--muted);
}
.reply-composer .reply-send:not(:disabled) { color: var(--text); }
.reply-send svg { width: 22px; height: 22px; display: block; }
.reply-composer .reply-send { animation: composer-pop .2s cubic-bezier(.2,.9,.3,1.3) backwards; }
.reply-composer .reply-send:disabled { opacity: .55; }
.reply-composer .palette-toggle {
  width: 20px; height: 20px; min-height: 20px; padding: 0; border: 0;
  background: transparent; color: var(--muted);
}
.reply-composer .palette-toggle svg { width: 16px; height: 16px; display: block; }
.reply-composer button.composer-remove, .reply-composer button.bio-remove {
  min-height: 18px; width: 18px; height: 18px; padding: 0;
}
/* Touch uses the Backspace key in the visual keyboard, not per-item X. */
@media (hover: none) {
  .composer-remove, .bio-remove { display: none; }
}
.picker-head-actions .picker-backspace {
  min-height: 44px; width: 44px; padding: 0; color: var(--muted); font-size: 17px;
}
.reply-composer-field.multiline { border-radius: 18px; }
.reply-tree {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding-bottom: var(--sp-2);
}
.reply-tree .reply-children { margin-left: 6px; border-left: 1px solid var(--hairline); }
.reply-collapse { margin-left: 8px; color: var(--muted); font-size: .72rem; white-space: nowrap; padding: 6px 0; }
.load-more-replies { min-height: 40px; margin: 8px 0; color: var(--muted); }
@media (max-width: 480px) {
  .reply-tree .reply[data-depth="2"], .reply-tree .reply[data-depth="3"], .reply-tree .reply[data-depth="4"] { margin-left: 28px !important; }
}
@media (max-width: 999px) { .chain-back-label { display: none; } }
.palette { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.sticker-picker, .selected-stickers { display: flex; flex-wrap: wrap; gap: 8px; }
.sticker-choice { border: 0; background: transparent; padding: 4px; }
.sticker-choice img { width: 56px; height: 56px; object-fit: contain; }
.selected-stickers .sticker { width: 56px; height: 56px; }
/* Только сам эмодзи: крупный (как в профиле), без заливки, бордера и скругления. */
.palette-emoji {
  border: 0; background: transparent; border-radius: 0;
  min-width: 44px; min-height: 44px; padding: var(--sp-2);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 30px; line-height: 1;
  outline: none; box-shadow: none;
}
/* В ответе .reply-composer button перебивает обычный .palette-emoji —
   поднимаем специфичность, чтобы эмодзи оставались крупными. */
.reply-composer .palette-emoji {
  min-width: 44px; min-height: 44px; padding: var(--sp-2);
  font-size: 30px; line-height: 1;
  border: 0; background: transparent; border-radius: 0;
  outline: none; box-shadow: none;
}
.profile { text-align: center; display: grid; justify-items: center; gap: var(--sp-2); padding-top: var(--sp-4); }
.profile-head {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
}
/* Шестерёнка: кликабельная зона 40px, иконка ~22px, по правому краю, без рамок и заливки. */
.profile-head .link {
  width: 40px; height: 40px; min-height: 40px; margin-left: auto; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 22px; line-height: 1;
  border: 0; background: none; outline: none; box-shadow: none;
  cursor: pointer;
}
.avatar.big { width: 72px; height: 72px; font-size: 40px; }
.profile-stats { display: flex; gap: var(--sp-6); margin: var(--sp-2) 0; font-size: 0.9rem; }
.follow-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; }
.follow-person { display: flex; align-items: center; gap: 12px; text-align: left; background: transparent; border: 0; color: var(--text); }
.grid-title { font-size: 16px; margin: var(--sp-6) 0 var(--sp-2); }
.post-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-1); width: 100%; }
.grid-cell {
  position: relative; aspect-ratio: 1; border: 0; background: var(--surface);
  border-radius: var(--radius);
  display: flex; flex-wrap: wrap; align-content: center; justify-content: center;
  gap: var(--sp-1); padding: var(--sp-1); overflow: hidden;
}
/* Явно фиксируем радиус 18px у карточек профиля и identity — как у ленты. */
.identity, .post.settings-row { border-radius: var(--radius); }
.cell-badge {
  position: absolute; bottom: var(--sp-1); right: var(--sp-1); background: rgba(0,0,0,.7);
  border-radius: var(--sp-2); padding: 2px var(--sp-1); font-size: 11px; color: var(--text);
  display: inline-flex; align-items: center; gap: 3px;
}
.cell-badge .comment-icon { width: 12px; height: 12px; }
.grid-cell .sticker.small { width: clamp(84px, 26vw, 132px); height: clamp(84px, 26vw, 132px); object-fit: contain; }
.tile-reactions {
  position: absolute; left: var(--sp-1); bottom: var(--sp-1);
  display: flex; gap: 3px; max-width: 78%; overflow: hidden;
}
.tile-chip {
  display: inline-flex; align-items: center; gap: 2px; flex: none;
  padding: 2px 5px; border-radius: 999px; background: rgba(0,0,0,.62);
  font-size: 11px; color: var(--text);
}
.tile-chip .chip-emoji { font-size: 13px; }
.tile-chip .chip-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
}
.section-caption { text-transform: uppercase; letter-spacing: 1px; margin: var(--sp-4) 0 var(--sp-2); }
.settings-logout { width: 100%; margin-top: var(--sp-6); }

/* The feed remains mounted beneath the modal. */
.guest-login { margin-left: auto; white-space: nowrap; }
.auth-overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  padding: 20px; background: rgba(0,0,0,.58);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  animation: auth-overlay-in .24s ease-out both;
}
.auth-modal {
  position: relative; width: min(100%, 420px); max-height: calc(100dvh - 40px);
  overflow-y: auto; background: var(--surface); border-radius: var(--radius);
  padding: 20px 16px; box-shadow: 0 24px 80px #000a;
  animation: auth-modal-in .3s cubic-bezier(.2,.8,.2,1) both;
}
.auth-modal .auth { min-height: 0; padding: 0; }
.auth-modal .auth-card { width: 100%; padding: 36px 8px 8px; }
.auth-modal .auth-card > .back-btn { top: -8px; left: -4px; }
.auth-reason {
  margin: 0 0 var(--sp-2); padding: var(--sp-2) var(--sp-3);
  background: var(--elevated); border-radius: var(--btn-radius);
  text-align: center; color: var(--text);
}
.auth-close { top: 12px; right: 12px; }
@keyframes auth-overlay-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes auth-modal-in { from { opacity: 0; transform: translateY(18px) scale(.96); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .splash-chain span { animation: none; }
  .reaction.active { transform: none; }
  .auth-overlay, .auth-modal { animation: none; }
  .share-feedback { animation: none; }
  .post-menu-popup button.menu-copied { animation: none; }
  .reaction-chip { animation: none; }
  .otp-boxes .otp-box { transition: none; }
  .otp-boxes .otp-box:focus { transform: none; }
  .otp-boxes .otp-box.filled, .otp-boxes.shake { animation: none; }
  .otp-emoji-bar .otp-emoji-btn, .auth-card > .back-btn, .auth-modal > .auth-close { transition: none; }
}

/* Sticker studio: direct pointer reorder, rename and destructive confirmations. */
.sticker-tile-wrap { user-select: none; transition: transform 120ms ease, opacity 120ms ease; }
.sticker-tile-wrap.editing { cursor: grab; touch-action: none; }
.sticker-tile-wrap.dragging { transform: scale(1.06); opacity: .7; cursor: grabbing; z-index: 4; }
.rename-pack { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.rename-pack input { flex: 1; min-width: 0; }
.confirm-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.72); display: grid; place-items: center; z-index: 100; }
.confirm-card { background: #181818; border: 0; border-radius: 16px; padding: 20px; max-width: 360px; width: calc(100% - 32px); box-shadow: 0 24px 80px #000a; }
.confirm-card h3 { margin: 0 0 8px; font-size: 17px; }
.confirm-card p { margin: 0 0 16px; font-size: 14px; line-height: 1.4; }
.confirm-actions { display: flex; gap: 8px; justify-content: flex-end; }
.sticker-move {
  width: 28px; height: 28px; min-height: 28px; padding: 0;
  border-radius: 50%; border: 0;
  background: var(--elevated); color: var(--text); line-height: 1; cursor: pointer;
  display: inline-grid; place-items: center;
}

/* Instagram-style horizontal profile identity (own and other profile). */
.screen.profile {
  display: block; text-align: left; width: 100%; max-width: 640px;
  margin: 0 auto; padding-top: var(--sp-3);
}
.profile-head { width: 100%; margin-bottom: var(--sp-2); }
.profile-head-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.profile-head-actions .link { margin-left: 0; }
.profile-share-btn {
  width: 36px; height: 36px; min-height: 36px; padding: 0;
  border: 0; border-radius: 50%;
  background: var(--elevated); color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .15s ease, background .15s ease;
}
.profile-share-btn:hover { color: var(--text); background: #282828; }
.profile-share-btn svg { width: 17px; height: 17px; display: block; }
.profile-share-btn.copied { color: #4ade80; background: rgba(74, 222, 128, .14); }
.profile-share-btn .share-ok { font-size: 14px; font-weight: 700; line-height: 1; }
.profile-head .brand { font-weight: 800; font-size: 20px; letter-spacing: -0.5px; }
.profile-identity { display: flex; align-items: center; gap: 18px; width: 100%; }
.profile-identity .avatar.big { width: 88px; height: 88px; font-size: 44px; flex: none; }
.identity-details { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.identity-title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.profile-identity h2 { margin: 0; font-size: 20px; line-height: 1.2; }
.identity-handle { margin: 0; }
.identity-bio { margin: 2px 0; min-height: 24px; }
.profile-stats { display: flex; gap: 20px; margin: 2px 0 0; justify-content: flex-start; }
.grid-title { text-align: center; margin-top: var(--sp-6); }
@media (max-width: 480px) {
  .profile-identity { gap: 12px; }
  .profile-identity .avatar.big { width: 64px; height: 64px; font-size: 32px; }
  .profile-identity h2 { font-size: 18px; }
  .profile-stats { gap: 14px; font-size: 0.85rem; }
}

/* Status/empty/error lines stay centered in the horizontal profile. */
.screen.profile > p.muted, .screen.profile > p.error { width: 100%; text-align: center; }

@keyframes composer-pop {
  from { opacity: 0; transform: scale(.6); }
  to { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .visual-item.just-added, .reply-composer .reply-send { animation: none; }
}

/* ONE visual composer: the ordered items are plain glyphs and images.
   No capsule, border, background or permanent X — only the focus caret;
   deletion comes from the keyboard (Backspace/Delete/beforeinput). */
.composer-items, .visual-composer-items {
  position: relative;
  display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start;
  align-items: center; padding: 8px 0; min-height: 48px;
}
.composer-item, .visual-item {
  position: relative; display: inline-flex; align-items: center; gap: 2px;
  min-height: 36px; padding: 2px; background: transparent;
  border: 0; border-radius: 0; overflow: visible;
}
.composer-item .sticker { width: 40px; height: 40px; object-fit: contain; background: transparent; border-radius: 0; }
.composer-item .emoji { font-size: 30px; line-height: 1.1; }
.visual-item.just-added { animation: composer-pop .18s cubic-bezier(.2,.9,.3,1.3) backwards; }
.composer-item.selected { opacity: .55; }
.composer-remove, .bio-remove {
  position: absolute; top: -2px; right: -6px;
  width: 18px; height: 18px; border: 0; border-radius: 50%;
  background: var(--elevated); color: var(--muted); font-size: 10px; line-height: 1;
  display: grid; place-items: center; opacity: 0; transition: opacity .12s ease;
}
.composer-item:hover .composer-remove, .composer-item:focus-within .composer-remove,
.bio-chip:hover .bio-remove, .bio-chip:focus-within .bio-remove { opacity: 1; }
.visual-composer { min-width: 0; }
.visual-caret {
  width: 12px; min-width: 12px; min-height: 36px; padding: 0;
  background: transparent !important; border: 0; border-radius: 0;
  caret-color: var(--text); font-size: 16px; line-height: 1;
  box-shadow: none; outline: none;
}
/* Hint is an overlay at the caret's own X: it never occupies flow space. */
.visual-hint {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  font-size: .8rem; padding-left: 0; pointer-events: none;
}
.visual-composer-tools { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.visual-recent { flex-wrap: nowrap !important; overflow-x: auto; gap: 4px !important; padding: 4px 0 8px; margin-bottom: 12px; }
.palette-toggle {
  min-height: 36px; padding: 0 14px; border: 0; border-radius: 999px;
  background: var(--elevated); color: var(--muted); font-size: 13px;
}
.composer .palette { display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 4px; padding: 6px 0; }
.composer .palette-emoji { flex: none; min-width: 44px; min-height: 44px; font-size: 26px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.post-menu-popup .menu-danger { color: #ff6b6b; }
button.danger { background: #c83c3c; color: #fff; }

.chain-actions { display: flex; align-items: center; gap: 4px; justify-self: end; position: relative; }

.popup_backdrop,.confirm_backdrop{position:fixed;inset:0;z-index:4;background:transparent;display:grid;place-items:center}
.post_menu_popup{position:absolute;right:0;top:100%;z-index:5;padding:4px;background:var(--elevated);border-radius:12px;box-shadow:0 6px 22px #0008}
.menu_danger{color:#ff6b6b}
.confirm_card{background:#181818;border:0;border-radius:16px;padding:20px;max-width:360px;width:calc(100% - 32px);box-shadow:0 24px 80px #000a}
.confirm_actions{display:flex;gap:8px;justify-content:flex-end}

/* Shared avatar: cached sticker art on top, glyph underneath while loading,
   and the glyph stays when the sticker is missing, deleted or undecodable. */
.avatar { position: relative; }
.avatar .avatar-sticker {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; border-radius: 50%; background: transparent;
}
.avatar img[src=""] { display: none; }
.avatar.avatar-failed .avatar-sticker { display: none; }
.profile-stat strong { font-weight: 700; font-variant-numeric: tabular-nums; margin-left: 4px; }
.profile-edit {
  border-radius: var(--btn-radius); background: var(--elevated); color: var(--text);
  font-weight: 600; white-space: nowrap; font-size: 12px; min-height: 32px; padding: 0 10px;
}

/* Compact profile editor: fixed toolbar, no permanently open emoji grid. */
.screen.profile-editor {
  display: block; text-align: left; width: 100%; max-width: 640px;
  margin: 0 auto; padding: var(--sp-3) 0 var(--sp-6);
}
.editor-head { position: sticky; top: 0; z-index: 2; background: var(--bg); }
.editor-head h2 { flex: 1; min-width: 0; font-size: clamp(13px, 4.2vw, 17px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.editor-done { margin-left: auto; font-weight: 600; font-size: clamp(12px, 3.6vw, 14px); white-space: nowrap; }
.editor-done:disabled { opacity: .5; }
.editor-avatar-row { display: flex; align-items: center; gap: 16px; margin: var(--sp-3) 0; }
.avatar.editor-avatar { width: 84px; height: 84px; font-size: 40px; }
.bio-editor { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
/* Bio uses its own visual scale: independent of feed / post item sizes. */
.profile-bio {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start;
  gap: 4px; padding: 4px 0; min-height: 32px;
}
.profile-bio .emoji { font-size: 26px; line-height: 1.1; }
.profile-bio .sticker { width: 32px; height: 32px; object-fit: contain; background: transparent; border-radius: 0; }
.profile-bio-editor .bio-chip {
  position: relative; display: inline-flex; align-items: center;
  padding: 2px; background: transparent; border-radius: 0;
}
.profile-bio-editor .bio-chip .sticker { width: 36px; height: 36px; }
.profile-bio-editor .bio-chip .emoji { font-size: 28px; }
.bio-add {
  width: 40px; height: 40px; border-radius: 999px;
  background: var(--elevated); color: var(--text); font-size: 20px; line-height: 1;
}
.bio-add:disabled { opacity: .4; }
.editor-preview {
  display: flex; align-items: center; gap: 12px; margin-top: var(--sp-4);
  padding: var(--sp-3); background: var(--surface); border-radius: var(--radius);
}
.editor-preview .identity-details { min-width: 0; }

/* Pickers are overlays opened on click: bounded height, their own scroll, and
   a bottom sheet on phones. */
.picker-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.6); }
.picker-sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 31;
  width: min(100%, 520px); max-height: 72dvh; overflow-y: auto;
  background: var(--surface); border-radius: 16px 16px 0 0; padding: var(--sp-4);
}
.picker-head { display: flex; align-items: center; justify-content: space-between; }
.picker-head h3 { margin: 0; font-size: 17px; }
.picker-tabs { display: flex; gap: 8px; margin: var(--sp-2) 0; }
.picker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 6px; max-height: 34dvh; overflow-y: auto;
}
.picker-grid .palette-emoji { min-width: 44px; min-height: 44px; font-size: 26px; }
.picker-grid .palette-emoji.selected { background: var(--elevated); }
.picker-pack { margin-bottom: var(--sp-3); }
.sticker-choice { border-radius: 10px; }
.sticker-choice.selected { background: var(--elevated); }
.sticker-choice img.avatar-sticker { width: 48px; height: 48px; object-fit: contain; }
@media (min-width: 1000px) {
  .picker-sheet { bottom: 50%; transform: translate(-50%, 50%); border-radius: 16px; }
}

/* Visual keyboard. It is part of the editor shell, never a modal dialog:
   no backdrop, no dimming, and only one scroll area. */
.visual-composer { position: relative; }
.visual-composer > .picker-sheet {
  position: absolute; left: calc(100% + 12px); top: 0; bottom: auto;
  width: min(360px, calc(100vw - 32px)); max-height: min(62dvh, 520px);
  transform: translate(var(--picker-dx, 0px), var(--picker-dy, 0px));
  overflow: hidden; border: 0; border-radius: 16px; box-shadow: 0 18px 56px #000b;
  padding: 4px 10px 10px; z-index: 12;
  display: flex; flex-direction: column;
}
.picker-handle {
  height: 18px; flex: none; display: grid; place-items: center;
  cursor: ns-resize; touch-action: none; margin-bottom: 2px;
}
.picker-handle-bar { width: 36px; height: 4px; border-radius: 999px; background: var(--hairline); }
.picker-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 34px; flex: none; }
.picker-head h3 { margin: 0; font-size: 17px; }
.picker-tabs { flex: 1 1 auto; gap: 4px; margin: 0; }
.picker-tabs .mode-tab { min-height: 32px; padding: 0 14px; font-size: 13px; }
.picker-head-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.picker-head-actions .picker-collapse { min-height: 34px; width: 34px; padding: 0; color: var(--muted); }
.picker-collapse .collapse-icon { width: 18px; height: 18px; display: block; }
.visual-composer > .picker-sheet .picker-head .link { min-height: 32px; padding: 0 8px; font-size: 14px; }
.picker-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-top: 6px; }
.visual-composer > .picker-sheet.collapsed .picker-body { display: none; }
.picker-grid.emoji-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 2px; max-height: none; overflow: visible;
}
.picker-grid.emoji-grid .palette-emoji { width: 100%; min-width: 0; aspect-ratio: 1; min-height: 0; padding: 2px; font-size: 26px; }
.pack-strip { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 6px; }
.pack-tab {
  flex: none; width: 56px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 2px; border: 0; border-radius: 10px; background: transparent; color: var(--muted);
}
.pack-tab.active { background: var(--elevated); color: var(--text); }
.pack-cover, .pack-cover-empty { width: 40px; height: 40px; object-fit: contain; display: grid; place-items: center; }
.pack-cover { border-radius: 8px; background: transparent; }
.pack-cover-empty { color: var(--muted); font-size: 22px; }
.pack-name { max-width: 52px; font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-active-pack { margin: 2px 0 6px; font-size: .75rem; }
.picker-sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; }
.picker-sticker-grid .sticker-choice { width: 100%; aspect-ratio: 1; padding: 4px; border: 0; border-radius: 0; background: transparent; display: grid; place-items: center; }
.picker-sticker-grid .sticker-choice img.picker-sticker-img { width: 100%; height: 100%; object-fit: contain; background: transparent; border-radius: 0; }
/* While open, the host reserves exactly the visible sheet height. */
@media (max-width: 999px) {
  .visual-composer > .picker-sheet {
    position: fixed; left: 0; right: 0; top: auto; bottom: 0;
    width: 100%; height: var(--picker-h, 46dvh); max-height: 80dvh;
    transform: none; border-radius: 16px 16px 0 0;
    border: 0; box-shadow: 0 -12px 40px #000a;
    padding: 4px 12px calc(10px + env(safe-area-inset-bottom));
  }
  .visual-composer > .picker-sheet.collapsed { height: 66px; }
  .screen:has(.visual-picker) { padding-bottom: calc(var(--picker-h, 46dvh) + var(--sp-4)); }
  .screen:has(.visual-picker) .reply-composer { bottom: calc(var(--picker-h, 46dvh) + 8px); }
}
@media (min-width: 1000px) {
  .screen:has(.visual-picker) { padding-bottom: var(--sp-6); }
  .screen:has(.visual-picker) .reply-composer { bottom: 0; }
}
@media (min-width: 1000px) {
  /* Reserve the side-panel space for the whole editor screen, so toggling
     the picker does not resize or move the content under the pointer. */
  .shell:has(.visual-composer) .main-col {
    width: min(640px, calc(100vw - 480px));
    margin-left: max(84px, min(calc((100% - min(640px, 100vw - 480px)) / 2), calc(100% - 380px - min(640px, 100vw - 480px))));
    margin-right: auto;
  }
  .picker-handle { cursor: move; }
  .visual-composer > .picker-sheet {
    position: fixed; left: auto; right: 12px; top: 76px; bottom: auto;
    transform: translate(var(--picker-dx, 0px), var(--picker-dy, 0px));
  }
}
/* Chain dock: on phones the visual keyboard lives in the same bottom block
   as the editor. Only .reply-tree scrolls; no fixed/sticky offsets here. */
@media (max-width: 999px) {
  .screen.chain:has(.visual-picker) { padding-bottom: 0; }
  .screen.chain:has(.visual-picker) .reply-composer { bottom: auto; }
  .reply-composer:has(.visual-picker) { padding-bottom: calc(var(--picker-h, 46dvh) + var(--sp-3)); }
  .reply-composer .picker-sheet {
    position: absolute; left: 0; right: 0; top: auto; bottom: 0;
    width: 100%; height: var(--picker-h, 46dvh); max-height: none;
    transform: none; border: 0; box-shadow: 0 -12px 40px #000a;
    border-radius: 16px 16px 0 0; z-index: 4;
    padding: 4px 12px calc(10px + env(safe-area-inset-bottom));
  }
  .reply-composer .picker-sheet.collapsed { height: 66px; }
}

/* ---------- Telegram-style Sticker Pack Sheet, Search, Notifications & UI Polish ---------- */
.post-sticker-btn {
  padding: 0; border: 0; background: transparent;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px; cursor: pointer;
  transition: transform .14s ease, opacity .14s ease;
}
.post-sticker-btn:hover { transform: scale(1.03); }
.post-sticker-btn:active { transform: scale(0.97); }

.post-share-btn {
  width: 34px; height: 34px; min-height: 34px; padding: 0;
  border: 0; border-radius: 50%;
  background: var(--elevated); color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .15s ease, background .15s ease;
}
.post-share-btn:hover { color: var(--text); background: #282828; }
.post-share-btn svg { width: 16px; height: 16px; display: block; }
.post-share-btn.copied { color: #4ade80; background: rgba(74, 222, 128, .14); }
.post-share-btn .share-ok { font-size: 14px; font-weight: 700; line-height: 1; }

.empty-state {
  display: grid; justify-items: center; gap: var(--sp-3);
  padding: var(--sp-6) var(--sp-4); text-align: center;
  background: var(--surface); border-radius: var(--radius); margin-top: var(--sp-2);
}

.topbar-search-btn {
  width: 40px; height: 40px; min-height: 40px; padding: 0;
  border-radius: 50%; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s ease, color .15s ease;
}
.topbar-search-btn:hover, .topbar-search-btn.active { background: var(--elevated); color: var(--text); }
.topbar-search-btn svg { width: 20px; height: 20px; display: block; }

.search-drawer {
  margin: 0 var(--sp-4) var(--sp-3); padding: var(--sp-3);
  background: var(--surface); border: 0; border-radius: var(--radius);
  box-shadow: 0 12px 32px #0006;
  display: grid; gap: var(--sp-3);
}
.search-form { display: flex; gap: var(--sp-2); align-items: center; }
.search-form input { flex: 1; min-width: 0; border: 0; outline: none; box-shadow: none; }
.search-form .secondary.compact { border: 0; min-height: 40px; padding: 0 14px; border-radius: var(--btn-radius); }
.search-form .link { min-width: 36px; padding: 0 8px; }
.search-list { display: grid; gap: 6px; }
.search-result-row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 8px 10px; border-radius: 12px; text-align: left;
  background: var(--elevated); color: var(--text);
  transition: background .15s ease;
}
.search-result-row:hover { background: #262626; }
.search-result-meta { display: grid; gap: 2px; min-width: 0; }
.search-result-meta strong, .search-result-meta .muted {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.nav-glyph-wrap { position: relative; display: inline-flex; align-items: center; justify-content: center; }
.nav-unread-dot {
  position: absolute; top: -2px; right: -2px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text); box-shadow: 0 0 0 2px var(--bg);
}

.notif-list { display: grid; gap: var(--sp-2); }
.notif-skel { height: 68px; }
.notif-row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); color: var(--text); text-align: left;
  transition: background .15s ease;
}
.notif-row:hover:not(:disabled) { background: var(--elevated); }
.notif-row.unread { background: var(--elevated); }
.notif-body { flex: 1; min-width: 0; display: grid; gap: 3px; }
.notif-line { font-size: 0.92rem; line-height: 1.35; }
.notif-time { font-size: 0.76rem; }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text); flex: none; }

.pack-chip { transition: background .15s ease, color .15s ease; }
.pack-chip.active { background: var(--text); color: var(--bg); font-weight: 600; }
.pack-search-item { display: inline-flex; align-items: center; gap: 4px; }
.pack-chip.secondary-chip { background: var(--elevated); border: 0; color: var(--text); }
.pack-chip.secondary-chip:hover { background: #282828; }

.settings-row-danger { flex-direction: column; align-items: stretch; gap: var(--sp-3); }
.settings-row-top { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.confirm-inline { display: grid; gap: var(--sp-2); width: 100%; }
.confirm-inline-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; }
.confirm-inline-actions .compact { min-height: 38px; padding: 0 14px; }

.pack-sheet-backdrop {
  position: fixed; inset: 0; z-index: 95;
  display: grid; align-items: end; justify-items: center;
  background: rgba(0, 0, 0, .62);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  animation: auth-overlay-in .2s ease-out both;
}
.pack-sheet {
  width: min(100%, 480px); max-height: 82dvh;
  background: var(--surface); border: 0;
  border-radius: 20px 20px 0 0;
  padding: 8px var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: var(--sp-3);
  box-shadow: 0 24px 80px #000c;
  animation: auth-modal-in .24s cubic-bezier(.2, .8, .2, 1) both;
}
.pack-sheet-handle { display: grid; place-items: center; padding: 2px 0 4px; }
.pack-sheet-handle span { width: 36px; height: 4px; border-radius: 999px; background: rgba(255, 255, 255, .18); }
.pack-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.pack-sheet-title-wrap { min-width: 0; display: grid; gap: 2px; }
.pack-sheet-title-wrap h3 {
  margin: 0; font-size: 1.1rem; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pack-sheet-close { min-width: 36px; min-height: 36px; padding: 0; color: var(--muted); }
.pack-sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: grid; gap: var(--sp-3); padding-right: 2px; }
.pack-sheet-author {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 12px; background: var(--elevated); color: var(--text); text-align: left;
}
.pack-sheet-author:hover { background: #262626; }
.pack-sheet-avatar { width: 34px; height: 34px; font-size: 13px; }
.pack-sheet-author-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.pack-sheet-author-text strong, .pack-sheet-author-text .muted {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pack-sheet-spotlight {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: 10px 12px; border-radius: 14px; background: var(--elevated);
}
.pack-sheet-spot-img { width: 72px; height: 72px; object-fit: contain; flex: none; }
.pack-sheet-use {
  min-height: 38px; padding: 0 14px; white-space: nowrap;
  background: rgba(255, 255, 255, .1); border-radius: 999px;
}
.pack-sheet-use:hover { background: rgba(255, 255, 255, .16); }
.pack-sheet-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.pack-sheet-cell {
  aspect-ratio: 1; border-radius: 14px; padding: 6px;
  background: transparent; border: 0; outline: none; box-shadow: none;
  display: grid; place-items: center;
  transition: background .14s ease, transform .14s ease;
}
.pack-sheet-cell:hover { background: rgba(255, 255, 255, .05); transform: scale(1.04); }
.pack-sheet-cell.active { background: rgba(255, 255, 255, .09); }
.pack-sheet-sticker { width: 100%; height: 100%; object-fit: contain; }
.pack-sheet-actions { flex: none; padding-top: var(--sp-1); }
.pack-sheet-cta { width: 100%; margin: 0; }
.pack-sheet-skel { height: 220px; }

@media (min-width: 1000px) {
  .pack-sheet-backdrop { align-items: center; padding: 20px; }
  .pack-sheet { border-radius: var(--radius); max-height: 78dvh; padding: 14px 18px 18px; }
  .pack-sheet-handle { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .pack-sheet-backdrop, .pack-sheet, .post-sticker-btn { animation: none; transition: none; }
}
