:root {
  --ink: #050505;
  --muted: #65676B;
  --faint: #8A8D91;
  --soft: #F0F2F5;
  --line: #E4E6EB;
  --accent: #0866FF;
  --accent-soft: #E7F0FF;
  --danger: #C62828;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: #F0F2F5;
  color: var(--ink);
  font: 400 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
img { display: block; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#app {
  max-width: 520px; margin: 0 auto; height: 100dvh; background: #fff;
  position: relative; overflow: hidden; box-shadow: 0 0 0 1px rgba(0,0,0,.04);
}
.screen { display: flex; flex-direction: column; height: 100dvh; padding-top: var(--safe-top); }
.scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

/* Шапка */
.topbar { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; padding: 12px 12px 8px 16px; min-height: 60px; }
.topbar h1 { margin: 0; text-align: center; font-size: 20px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar.small h1 { font-size: 17px; }
.icon-btn { width: 44px; height: 44px; border: 0; background: transparent; display: inline-flex; align-items: center; justify-content: center; padding: 0; color: var(--ink); border-radius: 22px; text-decoration: none; }
.icon-btn:active { background: var(--soft); }
.icon-btn.accent { color: var(--accent); }

/* Аватар */
.avatar { position: relative; flex: 0 0 auto; border-radius: 50%; color: #fff; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; background-size: cover; background-position: center; text-decoration: none; }
.avatar img.photo { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar .badge { position: absolute; right: -3px; bottom: -3px; border-radius: 50%; background: #fff; display: flex; align-items: center; justify-content: center; }
.avatar-pair { position: relative; flex: 0 0 auto; }
.avatar-pair .avatar { position: absolute; }
.avatar-pair .avatar:last-child { right: 0; bottom: 0; box-shadow: 0 0 0 2px #fff; }

/* Поиск */
.search { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; margin: 0 16px; border-radius: 19px; background: var(--soft); color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 16px; color: var(--ink); }

/* Ряд статусов */
.status-row { display: flex; gap: 12px; padding: 16px 16px 8px; overflow-x: auto; scrollbar-width: none; }
.status-row::-webkit-scrollbar { display: none; }
.status-item { flex: 0 0 64px; display: flex; flex-direction: column; align-items: center; gap: 6px; border: 0; background: none; padding: 0; font-size: 12px; color: var(--ink); text-decoration: none; }
.status-item span.label { width: 64px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-item.me span.label { color: var(--muted); }
.plus-circle { width: 58px; height: 58px; border-radius: 50%; background: var(--soft); display: flex; align-items: center; justify-content: center; position: relative; }

/* Карточка-подсказка */
.card { margin: 10px 16px 6px; padding: 14px; border-radius: 16px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06); display: flex; flex-direction: column; gap: 12px; }
.card .head { display: flex; gap: 12px; align-items: flex-start; }
.card .t { font-weight: 700; }
.card .s { font-size: 14px; color: var(--muted); }
.close-btn { width: 28px; height: 28px; border-radius: 14px; border: 0; background: var(--soft); color: var(--muted); display: flex; align-items: center; justify-content: center; padding: 0; flex: 0 0 auto; }

/* Кнопки */
.btn { height: 44px; border-radius: 10px; border: 0; background: var(--accent); color: #fff; font-weight: 600; font-size: 16px; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn.secondary { background: var(--soft); color: var(--ink); }
.btn.small { height: 34px; font-size: 14px; border-radius: 8px; padding: 0 12px; }
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }

/* Списки */
.list { display: flex; flex-direction: column; padding: 4px 8px; }
.row { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 12px; text-decoration: none; color: var(--ink); border: 0; background: none; text-align: left; width: 100%; }
.row:active { background: var(--soft); }
.row .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row .name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.unread .name { font-weight: 700; }
.row.unread .sub { color: var(--ink); font-weight: 600; }
.dot { width: 12px; height: 12px; border-radius: 6px; background: var(--accent); flex: 0 0 auto; }
.section-title { padding: 16px 16px 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.band { height: 8px; background: var(--soft); flex: 0 0 auto; }
.empty { padding: 40px 24px; text-align: center; color: var(--muted); }

/* Нижнее меню */
.tabbar { flex: 0 0 auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 6px 24px calc(8px + var(--safe-bottom)); background: #fff; border-top: 1px solid #EEF0F3; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500; position: relative; }
.tab.active { color: var(--ink); font-weight: 600; }
.tab .count { position: absolute; top: 0; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #E41E3F; color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

/* Чат */
.chat-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 4px; border-bottom: 1px solid #EEF0F3; min-height: 60px; }
.chat-head .info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-head .t { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .s { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messages { padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.day { align-self: center; font-size: 12px; color: var(--muted); padding: 12px 0 6px; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.msg.me { justify-content: flex-end; }
.msg .col { display: flex; flex-direction: column; gap: 3px; max-width: 75%; min-width: 0; }
.msg.me .col { align-items: flex-end; }
.msg .who { font-size: 12px; color: var(--muted); padding: 8px 12px 0; }
.msg .spacer { width: 28px; flex: 0 0 auto; }
.bubble { position: relative; border: 0; text-align: left; background: var(--soft); color: var(--ink); border-radius: 18px; padding: 8px 12px; font-size: 15px; line-height: 1.35; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; max-width: 100%; user-select: text; -webkit-user-select: text; }
.msg.me .bubble { background: var(--accent); color: #fff; }
.bubble.big { background: none !important; font-size: 44px; padding: 0 4px; line-height: 1.1; }
.bubble.photo { padding: 0; overflow: hidden; background: none; }
.bubble.photo img { max-width: 240px; max-height: 320px; border-radius: 18px; object-fit: cover; }
.bubble.photo .cap { padding: 8px 12px; }
.msg.me .bubble.photo.with-cap { background: var(--accent); }
.bubble.photo.with-cap { background: var(--soft); }
.msg.has-rx { margin-bottom: 14px; }
.rx-pill { position: absolute; right: 8px; bottom: -16px; display: flex; align-items: center; gap: 1px; height: 22px; padding: 0 6px 0 3px; border-radius: 11px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.18); font-size: 12px; color: var(--muted); white-space: nowrap; }
.msg.me .rx-pill { right: auto; left: 8px; }
.system { align-self: center; max-width: 85%; text-align: center; font-size: 13px; color: var(--muted); padding: 8px 12px; margin: 6px 0; background: var(--soft); border-radius: 12px; }
.typing { font-size: 12px; color: var(--muted); padding: 2px 16px 6px; min-height: 20px; }

.picker { position: fixed; z-index: 30; display: flex; gap: 2px; padding: 4px 6px; background: #fff; border-radius: 26px; box-shadow: 0 2px 6px rgba(0,0,0,.1), 0 8px 24px rgba(0,0,0,.14); animation: pop .12s ease-out; }
.picker button { width: 44px; height: 44px; border-radius: 22px; border: 0; background: transparent; display: flex; align-items: center; justify-content: center; padding: 0; transition: transform .1s; }
.picker button:active { transform: scale(1.25); }
.picker button.on { background: var(--soft); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }
.scrim { position: fixed; inset: 0; z-index: 25; background: transparent; }

.composer { flex: 0 0 auto; display: flex; align-items: flex-end; gap: 4px; padding: 8px 8px calc(8px + var(--safe-bottom)); border-top: 1px solid #F2F3F5; background: #fff; }
.composer .field { flex: 1; min-width: 0; display: flex; align-items: center; min-height: 38px; padding: 0 14px; border-radius: 19px; background: var(--soft); }
.composer textarea { flex: 1; border: 0; outline: 0; background: transparent; resize: none; font-size: 16px; line-height: 1.3; padding: 9px 0; max-height: 120px; color: var(--ink); }
.preview-strip { display: flex; align-items: center; gap: 8px; padding: 8px 12px 0; }
.preview-strip img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }

/* Лента */
.composer-row { display: flex; align-items: center; gap: 10px; padding: 4px 16px 12px; }
.pill-input { flex: 1; min-width: 0; height: 40px; border: 0; border-radius: 20px; background: var(--soft); padding: 0 16px; font-size: 16px; text-align: left; color: var(--muted); }
.post { display: flex; flex-direction: column; }
.post .head { display: flex; align-items: center; gap: 10px; padding: 12px 16px 8px; }
.post .head .meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.post .head .n { font-size: 15px; }
.post .head .t { font-size: 13px; color: var(--muted); }
.post .text { padding: 0 16px 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.post .thanks { margin: 0 16px 10px; padding: 14px; border-radius: 14px; background: #FFF8E1; display: flex; gap: 10px; align-items: flex-start; white-space: pre-wrap; overflow-wrap: anywhere; }
.post .image { width: 100%; max-height: 420px; object-fit: cover; background: var(--line); }
.post .summary { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; font-size: 13px; color: var(--muted); min-height: 20px; }
.post .summary .icons { display: flex; align-items: center; gap: 6px; }
.rx-stack { display: flex; }
.rx-stack span { width: 20px; height: 20px; border-radius: 10px; background: #fff; display: flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px #fff; }
.rx-stack span + span { margin-left: -4px; }
.actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0 12px; border-top: 1px solid var(--line); }
.actions button { height: 44px; border: 0; background: transparent; display: flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; font-size: 14px; color: var(--muted); border-radius: 8px; }
.actions button:active { background: var(--soft); }
.actions button.on { color: #C2560F; }
.comments { padding: 8px 16px 12px; display: flex; flex-direction: column; gap: 8px; }
.comment { display: flex; gap: 8px; align-items: flex-start; }
.comment .b { background: var(--soft); border-radius: 16px; padding: 6px 12px; font-size: 14px; overflow-wrap: anywhere; white-space: pre-wrap; }
.comment .b b { display: block; font-size: 13px; }
.comment-form { display: flex; gap: 8px; }
.comment-form input { flex: 1; min-width: 0; height: 36px; border: 0; border-radius: 18px; background: var(--soft); padding: 0 14px; font-size: 16px; outline: 0; }

/* Люди и профиль */
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; padding: 2px; margin: 12px 16px 0; border-radius: 10px; background: var(--soft); }
.seg button { height: 32px; border-radius: 8px; border: 0; background: transparent; font-size: 13px; font-weight: 500; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.round-btn { width: 40px; height: 40px; border-radius: 20px; border: 0; background: var(--soft); color: var(--ink); display: flex; align-items: center; justify-content: center; padding: 0; flex: 0 0 auto; }
.profile-top { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 16px 18px; text-align: center; }
.profile-top .n { font-size: 22px; font-weight: 700; margin-top: 6px; }
.profile-top .r { font-size: 14px; color: var(--muted); }
.status-pill { margin-top: 8px; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 4px 14px 4px 8px; border-radius: 20px; background: var(--soft); color: var(--ink); text-decoration: none; font-size: 14px; border: 0; }
.info-list { display: flex; flex-direction: column; padding: 0 16px; }
.info-row { display: flex; align-items: center; gap: 12px; min-height: 52px; border: 0; background: none; padding: 0; text-align: left; width: 100%; color: var(--ink); text-decoration: none; font-size: 15px; }
.info-row .ic { width: 36px; height: 36px; border-radius: 18px; color: #fff; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.info-row .lbl { flex: 1; min-width: 0; }
.info-row .val { font-size: 14px; color: var(--muted); text-align: right; }
.divider { height: 1px; background: var(--line); margin: 8px 0; }
.switch { width: 50px; height: 30px; border-radius: 15px; background: #D8DADF; position: relative; flex: 0 0 auto; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 26px; height: 26px; border-radius: 13px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: left .15s; }
[aria-checked="true"] .switch { background: #31A24C; }
[aria-checked="true"] .switch::after { left: 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips span { font-size: 14px; padding: 6px 12px; border-radius: 16px; background: var(--soft); }
.text-field { width: 100%; min-height: 44px; border: 1px solid #D3D6D0; border-radius: 10px; padding: 10px 12px; font-size: 16px; background: #fff; outline: 0; }
.text-field:focus { border-color: var(--accent); }
label.field-label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }

/* Шторка */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.42); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { width: 100%; max-width: 520px; max-height: 92dvh; overflow-y: auto; background: #fff; border-radius: 16px 16px 0 0; padding: 8px 16px calc(20px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 4px; animation: up .2s ease-out; }
.sheet .handle { align-self: center; width: 36px; height: 5px; border-radius: 3px; background: #CED0D4; }
.sheet h2 { margin: 0; text-align: center; font-size: 17px; padding: 10px 0 8px; }
.choice { display: flex; align-items: center; gap: 12px; min-height: 52px; border: 0; background: transparent; padding: 0; text-align: left; width: 100%; }
.choice .main { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.choice .main b { font-size: 15px; }
.choice .main span { font-size: 13px; color: var(--muted); }
.check { width: 22px; height: 22px; border-radius: 11px; border: 2px solid #CED0D4; flex: 0 0 auto; display: flex; align-items: center; justify-content: center; }
.choice[aria-pressed="true"] .check { border-color: var(--accent); background: var(--accent); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .6; } }

/* Вход */
.auth { padding: 48px 24px; display: flex; flex-direction: column; gap: 14px; }
.auth .logo { width: 64px; height: 64px; border-radius: 18px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }
.auth h1 { margin: 8px 0 0; font-size: 26px; }
.auth p { margin: 0; color: var(--muted); }
.error { color: var(--danger); font-size: 14px; min-height: 18px; }

/* Админка */
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table td { padding: 10px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin-table .muted { color: var(--muted); font-size: 12px; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 6px; background: var(--soft); color: var(--muted); }
.tag.ok { background: #E3F4EA; color: #1E6B3A; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); z-index: 60; background: #1C1E21; color: #fff; padding: 10px 16px; border-radius: 20px; font-size: 14px; max-width: 90vw; animation: fade .15s; }
.viewer { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }

/* Токены, магазин, все реакции */
.coin-chip { display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 10px 0 5px; border-radius: 16px; background: #FFF6D6; color: #6B4E00; font-weight: 700; font-size: 14px; text-decoration: none; white-space: nowrap; }
.btn.dark { background: #050505; color: #fff; }
.rx-pill .tok, .summary .tok { display: inline-flex; align-items: center; gap: 2px; margin-left: 4px; color: #6B4E00; font-weight: 700; }
.rx-group-title { font-size: 13px; font-weight: 600; color: var(--muted); padding: 8px 0 4px; }
.rx-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.rx-grid button { height: 64px; border: 0; border-radius: 14px; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 0; font-size: 11px; color: var(--muted); }
.rx-grid button.on, .rx-grid button:active { background: var(--accent-soft); }
.token-btn { margin-top: 12px; min-height: 56px; border: 0; border-radius: 14px; background: #FFF6D6; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--ink); padding: 6px 12px; }
.token-btn .tb-text { display: flex; flex-direction: column; align-items: flex-start; font-size: 15px; text-align: left; }
.token-btn .tb-text span { font-size: 12px; color: #6B4E00; }
.amount-btn { height: 44px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-weight: 700; font-size: 17px; }
.amount-btn.on { border: 2px solid var(--ink); background: #FFF6D6; }
.amount-btn:disabled { opacity: .35; }
.chip { height: 34px; padding: 0 12px; border-radius: 17px; border: 0; background: var(--soft); font-size: 14px; color: var(--ink); white-space: nowrap; }
.chip.on { background: var(--ink); color: #fff; }
.chips-row { display: flex; gap: 6px; padding: 8px 16px 4px; overflow-x: auto; scrollbar-width: none; }
.chips-row::-webkit-scrollbar { display: none; }
.tok-card { border-radius: 20px; padding: 16px; background: var(--soft); display: flex; flex-direction: column; gap: 10px; }
.tok-card.gold { background: #FFF6D6; }
.tok-bar { height: 8px; border-radius: 4px; background: rgba(107, 78, 0, .15); }
.tok-bar > div { height: 8px; border-radius: 4px; background: #F5B700; }
.num { width: 32px; height: 32px; border-radius: 16px; background: #FFF6D6; color: #6B4E00; font-weight: 800; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.shop-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 10px 16px 0; }
.shop-card { border: 1px solid var(--line); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-height: 180px; }
.shop-card b { font-size: 15px; line-height: 1.25; }
.shop-card .d { font-size: 13px; color: var(--muted); line-height: 1.3; }
.shop-ic { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
