:root {
  --bg: #101216;
  --surface: #191D24;
  --surface-2: #20252E;
  --line: rgba(255,255,255,.06);
  --line-2: rgba(255,255,255,.1);
  --accent: #38D996;
  --accent-soft: rgba(56,217,150,.12);
  --text: #F3F5F7;
  --muted: #8C94A0;
  --danger: #F2736B;
  --danger-soft: rgba(242,115,107,.12);
  --warn: #E9B44C;
  --r-sm: 14px; --r-md: 18px; --r-lg: 20px;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px -12px rgba(0,0,0,.6);
  --ease: cubic-bezier(.2,.7,.2,1);
  --t: 200ms var(--ease);
  --sa-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px));
  --sa-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --tabbar-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { color-scheme: dark; background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-feature-settings: 'cv11', 'ss01'; -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
body::before { content: ''; position: fixed; inset: 0 0 auto 0; height: 320px; pointer-events: none; z-index: -1;
  background: radial-gradient(120% 100% at 50% -20%, rgba(56,217,150,.09), transparent 70%); }
button, input { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; padding: 0; }
a { color: inherit; text-decoration: none; }
.ico { flex: none; display: block; }

#view {
  max-width: 640px; margin: 0 auto;
  padding: calc(var(--sa-top) + 18px) 16px calc(var(--tabbar-h) + var(--sa-bottom) + 28px);
  min-height: 100vh;
}
.view { animation: slideIn 220ms var(--ease) both; }
@keyframes slideIn { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Шапка */
.head { display: flex; align-items: center; gap: 12px; margin: 2px 0 20px; }
.head .back { width: 40px; height: 40px; border-radius: 14px; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); flex: none; transition: transform var(--t), background var(--t); }
.head .back:active { transform: scale(.94); background: var(--surface-2); }
.head .avatar { width: 46px; height: 46px; font-size: 16px; }
h1 { font-size: 26px; line-height: 1.2; font-weight: 700; margin: 0; letter-spacing: -.02em; overflow-wrap: anywhere; }
.sub { color: var(--muted); margin: 3px 0 0; font-size: 13.5px; }
.sub:empty { display: none; }
h2 { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .09em; margin: 26px 4px 10px; }
b, strong { font-weight: 600; }

.card { background: var(--surface); border-radius: var(--r-lg); padding: 16px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.45; }
.card > b { font-weight: 600; font-size: 16px; display: block; margin-bottom: 2px; }

/* Статус */
.card.hero { position: relative; overflow: hidden; border-color: rgba(56,217,150,.18);
  background: radial-gradient(130% 160% at 0% 0%, rgba(56,217,150,.16), transparent 55%), linear-gradient(180deg, #1B2028, var(--surface)); }
.card.hero.off { border-color: rgba(242,115,107,.2); background: radial-gradient(130% 160% at 0% 0%, rgba(242,115,107,.14), transparent 55%), linear-gradient(180deg, #1B2028, var(--surface)); }
.status { display: flex; gap: 14px; align-items: center; }
.status .badge { width: 52px; height: 52px; border-radius: 18px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); box-shadow: 0 0 0 1px rgba(56,217,150,.22) inset, 0 6px 20px -6px rgba(56,217,150,.45); position: relative; }
.status.on .badge::after { content: ''; position: absolute; inset: -1px; border-radius: inherit; box-shadow: 0 0 0 0 rgba(56,217,150,.4); animation: pulse 2.6s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(56,217,150,.4); } 70%, 100% { box-shadow: 0 0 0 12px rgba(56,217,150,0); } }
.status.off .badge { background: var(--danger-soft); color: var(--danger); box-shadow: 0 0 0 1px rgba(242,115,107,.25) inset; }
.status b { display: block; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.status span { color: var(--muted); font-size: 13px; display: block; margin-top: 2px; line-height: 1.4; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 12px 12px; box-shadow: var(--shadow); }
.stat .n { font-size: 26px; line-height: 1.1; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stat.red .n { color: var(--danger); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; display: flex; flex-direction: column; gap: 16px; min-height: 100px; box-shadow: var(--shadow); transition: transform var(--t), background var(--t), border-color var(--t); }
.tile .ib { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.tile:active, .item:active, .dcard:active { transform: scale(.98); background: var(--surface-2); }
.tile span { font-weight: 600; letter-spacing: -.005em; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 20px; border-radius: var(--r-sm); background: var(--accent); color: #07140E; font-weight: 600; transition: transform var(--t), opacity var(--t), background var(--t); box-shadow: 0 8px 20px -10px rgba(56,217,150,.7); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: var(--surface-2); color: var(--text); font-weight: 500; box-shadow: none; border: 1px solid var(--line); }
.btn.danger { background: var(--danger-soft); color: var(--danger); box-shadow: none; border: 1px solid rgba(242,115,107,.25); }
.btn.block { display: flex; width: 100%; }
.btn.sm { min-height: 38px; padding: 0 14px; font-size: 14px; }

/* Списки и stagger */
.list { display: flex; flex-direction: column; gap: 8px; }
.list > *, .msgs > * { animation: fadeUp 260ms var(--ease) both; }
.list > :nth-child(2), .msgs > :nth-child(2) { animation-delay: 30ms; }
.list > :nth-child(3), .msgs > :nth-child(3) { animation-delay: 60ms; }
.list > :nth-child(4), .msgs > :nth-child(4) { animation-delay: 90ms; }
.list > :nth-child(5), .msgs > :nth-child(5) { animation-delay: 120ms; }
.list > :nth-child(n+6), .msgs > :nth-child(n+6) { animation-delay: 150ms; }
.stats > *, .tiles > * { animation: fadeUp 280ms var(--ease) both; }
.stats > :nth-child(2), .tiles > :nth-child(2) { animation-delay: 40ms; }
.stats > :nth-child(3), .tiles > :nth-child(3) { animation-delay: 80ms; }
.tiles > :nth-child(4) { animation-delay: 120ms; } .tiles > :nth-child(5) { animation-delay: 160ms; } .tiles > :nth-child(6) { animation-delay: 200ms; }

.item { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; box-shadow: var(--shadow); transition: transform var(--t), background var(--t); }
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 15px; letter-spacing: .01em; flex: none; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.25); box-shadow: 0 0 0 1px rgba(255,255,255,.1) inset, 0 4px 12px -4px rgba(0,0,0,.5); }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .side { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.item .side .meta { font-size: 12px; font-variant-numeric: tabular-nums; }
.count { display: inline-block; min-width: 26px; padding: 1px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.more { display: flex; justify-content: center; margin: 14px 0; }

/* Ссылка на автора */
.author { font-weight: 700; color: var(--text); letter-spacing: -.005em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; display: inline-flex; align-items: center; gap: 5px; cursor: pointer; transition: color var(--t); }
a.author:active, button.author:active { color: var(--accent); }
.author .ico { width: 13px; height: 13px; color: var(--muted); }
button.author { text-align: left; }

/* Карточка удалённого / результата поиска */
.dcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px; box-shadow: var(--shadow); transition: transform var(--t), background var(--t); }
.dcard.del { border-color: rgba(242,115,107,.22); background: linear-gradient(180deg, rgba(242,115,107,.06), transparent 60px), var(--surface); }
.dhead { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.dhead .who { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 1px; }
.dhead .where { color: var(--muted); font-size: 12.5px; display: flex; gap: 6px; align-items: center; min-width: 0; }
.dhead .where a { color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dhead .where time { font-variant-numeric: tabular-nums; flex: none; }
.dcard .quote { background: var(--bg); border: 1px solid var(--line); border-radius: 14px 14px 14px 5px; padding: 10px 12px; }
.dcard .delmark { margin: 0 0 8px; }

/* Сообщения */
.msgs { display: flex; flex-direction: column; gap: 8px; }
.msg { display: flex; flex-direction: column; max-width: 88%; align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 18px 18px 18px 6px; padding: 9px 12px 8px; min-width: 0; max-width: 100%; box-shadow: var(--shadow); }
.msg.out .bubble { background: linear-gradient(180deg, #1F3631, #1A2D29); border-color: rgba(56,217,150,.2); border-radius: 18px 18px 6px 18px; }
.msg.del .bubble { border-color: rgba(242,115,107,.3); }
.text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.text.ph { color: var(--muted); font-style: italic; }
mark { background: rgba(56,217,150,.28); color: var(--text); border-radius: 4px; padding: 0 2px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 7px; align-items: center; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; line-height: 1.3; padding: 2px 8px 2px 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid transparent; }
.tag .ico { width: 13px; height: 13px; }
.tag.del { background: var(--danger-soft); color: var(--danger); border-color: rgba(242,115,107,.28); font-weight: 500; }
.tag.del b { font-weight: 700; font-variant-numeric: tabular-nums; }
.tag.burn { background: rgba(233,180,76,.14); color: var(--warn); border-color: rgba(233,180,76,.3); font-weight: 500; }
.tag.edit { background: var(--accent-soft); color: var(--accent); }
.foot { font-size: 11.5px; color: var(--muted); margin-top: 5px; font-variant-numeric: tabular-nums; }
.msg.out .foot { text-align: right; }
.edits-btn { margin-top: 6px; font-size: 12.5px; font-weight: 500; color: var(--accent); display: inline-flex; align-items: center; gap: 4px; }
.edits-btn .ico { width: 14px; height: 14px; transition: transform var(--t); }
.edits-btn[aria-expanded="true"] .ico { transform: rotate(90deg); }
.edits { display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows var(--t), opacity var(--t); }
.edits.open { grid-template-rows: 1fr; opacity: 1; }
.edits > div { overflow: hidden; }
.edit-row { position: relative; background: rgba(0,0,0,.2); border-radius: 12px; padding: 8px 10px 8px 14px; margin-top: 8px; font-size: 13.5px; color: #C5CAD2; }
.edit-row::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--accent); opacity: .6; }
.edit-row .foot { margin-top: 3px; }
.edit-row .foot b { font-weight: 600; color: var(--muted); }

.att { margin-top: 8px; }
.att img, .att video { display: block; max-width: 100%; max-height: 340px; border-radius: 12px; background: var(--surface-2); }
.att audio { width: 100%; max-width: 260px; }
.att .note { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.att .ph-box { min-height: 120px; min-width: 160px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-size: 13px; }

/* Поиск */
.field { position: relative; }
.field .ico { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.field input { width: 100%; height: 50px; border-radius: var(--r-md); border: 1px solid var(--line-2); background: var(--surface); padding: 0 14px 0 46px; outline: none; transition: border-color var(--t), box-shadow var(--t); }
.field input:focus { border-color: rgba(56,217,150,.55); box-shadow: 0 0 0 4px rgba(56,217,150,.1); }
.field input::placeholder { color: var(--muted); }
#results { margin-top: 16px; }

/* Настройки */
.seg { position: relative; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--bg); padding: 4px; border-radius: var(--r-sm); margin-top: 14px; border: 1px solid var(--line); isolation: isolate; }
.seg .thumb { position: absolute; z-index: -1; top: 4px; bottom: 4px; left: 4px; width: calc((100% - 8px) / 5); border-radius: 11px; background: var(--accent); box-shadow: 0 6px 16px -6px rgba(56,217,150,.7); transform: translateX(calc(var(--idx, 0) * 100%)); transition: transform 240ms var(--ease); }
.seg button { height: 40px; border-radius: 11px; font-size: 13px; font-weight: 500; color: var(--muted); transition: color var(--t); font-variant-numeric: tabular-nums; }
.seg button[aria-checked="true"] { color: #07140E; font-weight: 700; }
.switch { width: 52px; height: 32px; border-radius: 999px; background: var(--surface-2); position: relative; flex: none; transition: background var(--t); border: 1px solid var(--line-2); }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--text); box-shadow: 0 2px 6px rgba(0,0,0,.4); transition: transform var(--t), background var(--t); }
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); background: #07140E; }
.card.danger-zone { border-color: rgba(242,115,107,.4); background: linear-gradient(180deg, rgba(242,115,107,.05), transparent), var(--surface); }
.danger-zone h3 { margin: 0 0 4px; color: var(--danger); font-size: 15px; font-weight: 700; }

/* Инструкция */
.steps { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; counter-reset: s; position: relative; }
.steps li { counter-increment: s; display: flex; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; box-shadow: var(--shadow); animation: fadeUp 280ms var(--ease) both; position: relative; }
.steps li:nth-child(2) { animation-delay: 40ms; } .steps li:nth-child(3) { animation-delay: 80ms; } .steps li:nth-child(4) { animation-delay: 120ms; } .steps li:nth-child(5) { animation-delay: 160ms; } .steps li:nth-child(6) { animation-delay: 200ms; }
.steps li::before { content: counter(s); width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 14px; flex: none; box-shadow: 0 0 0 1px rgba(56,217,150,.25) inset; font-variant-numeric: tabular-nums; }
.steps li:last-child::before { background: var(--accent); color: #07140E; }
.steps b { font-weight: 600; display: block; margin-bottom: 1px; }
.steps span { color: var(--muted); font-size: 13.5px; line-height: 1.45; display: block; }

/* Состояния */
.empty { text-align: center; padding: 44px 24px; color: var(--muted); animation: fadeUp 300ms var(--ease) both; }
.empty .ib { width: 84px; height: 84px; border-radius: 28px; margin: 0 auto 18px; display: grid; place-items: center; color: var(--accent); background: radial-gradient(circle at 30% 20%, rgba(56,217,150,.22), rgba(56,217,150,.06)); border: 1px solid rgba(56,217,150,.2); box-shadow: 0 14px 30px -14px rgba(56,217,150,.5); }
.empty.err .ib { color: var(--danger); background: radial-gradient(circle at 30% 20%, rgba(242,115,107,.22), rgba(242,115,107,.06)); border-color: rgba(242,115,107,.25); box-shadow: 0 14px 30px -14px rgba(242,115,107,.5); }
.empty b { display: block; color: var(--text); font-weight: 700; font-size: 17px; margin-bottom: 6px; }
.empty .btn { margin-top: 18px; }
.sk-item { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; height: 70px; }
.sk-item.tall { height: 104px; border-radius: var(--r-lg); }
.sk-b { background: linear-gradient(90deg, var(--surface-2) 0%, #2A303B 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: 8px; }
.sk-av { width: 44px; height: 44px; border-radius: 50%; flex: none; }
.tall .sk-av { width: 52px; height: 52px; border-radius: 18px; }
.sk-l { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.sk-l .sk-b { height: 11px; } .sk-l .sk-b:first-child { width: 55%; } .sk-l .sk-b:last-child { width: 80%; height: 9px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Таб-бар */
#tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center; background: rgba(16,18,22,.86); backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4); border-top: 1px solid var(--line); padding-bottom: var(--sa-bottom); }
#tabbar .inner { display: flex; width: 100%; max-width: 640px; position: relative; }
#tabbar a { flex: 1; height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 10.5px; font-weight: 500; color: var(--muted); transition: color var(--t); }
#tabbar a.active { color: var(--accent); font-weight: 600; }
#tabbar a:active .ico { transform: scale(.88); }
#tabbar .ico { transition: transform var(--t); }
#tabbar .ind { position: absolute; top: 0; left: 0; width: 20%; height: 100%; display: flex; justify-content: center; pointer-events: none; transform: translateX(calc(var(--idx, 0) * 100%)); transition: transform 260ms var(--ease), opacity var(--t); }
#tabbar .ind::before { content: ''; width: 28px; height: 3px; border-radius: 0 0 4px 4px; background: var(--accent); box-shadow: 0 2px 14px 1px rgba(56,217,150,.7); }
#tabbar .ind::after { content: ''; position: absolute; top: 0; width: 56px; height: 100%; background: radial-gradient(60% 70% at 50% 0%, rgba(56,217,150,.14), transparent); }
#tabbar .ind.none { opacity: 0; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--sa-bottom) + 16px); transform: translate(-50%, 12px); background: var(--surface-2); border: 1px solid var(--line-2); padding: 11px 18px; border-radius: var(--r-sm); font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity var(--t), transform var(--t); z-index: 20; max-width: calc(100vw - 32px); text-align: center; box-shadow: 0 12px 30px -10px rgba(0,0,0,.7); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
