/* Цвета берём из темы Telegram (SDK выставляет --tg-theme-*),
   фолбэки — для отладки в обычном браузере. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111214);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2b7bd6);
  --accent: var(--tg-theme-button-color, #2b7bd6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --sep: var(--tg-theme-section-separator-color, rgba(127, 127, 127, .18));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --heart: #ff3b5c;
  --radius: 14px;
  --safe-top: var(--tg-content-safe-area-inset-top, 0px);
  --safe-bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
}

@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #101113;
    --card: #1b1c1f;
    --text: #eceef1;
    --hint: #7d828b;
    --link: #5ea8ff;
    --accent: #3d8bf2;
    --sep: rgba(255, 255, 255, .08);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--link); text-decoration: none; }
[hidden] { display: none !important; }
.muted { color: var(--hint); }
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }

/* ---------- верхняя панель ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
}
.tabs { display: flex; gap: 4px; }
.tab {
  padding: 7px 14px; border-radius: 999px;
  font-weight: 600; color: var(--hint);
  transition: background-color .2s, color .2s;
}
.tab.is-active { background: var(--card); color: var(--text); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-grid; place-items: center; color: var(--hint);
}
.icon-btn:active { background: var(--sep); }

/* ---------- экраны ---------- */
.screen { min-height: 60vh; padding-bottom: calc(24px + var(--safe-bottom)); }
#screen-loading, #screen-error { min-height: 100vh; padding: 24px; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2.5px solid var(--sep); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  padding: 11px 20px; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
  transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; }
.btn-wide { width: 100%; padding: 14px; }
.btn-ghost { background: var(--card); color: var(--text); }

/* ---------- темы ---------- */
.topics-head { padding: calc(28px + var(--safe-top)) 20px 8px; }
.topics-head h1 { margin: 0 0 6px; font-size: 24px; line-height: 1.2; letter-spacing: -.01em; }
.topics-head p { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 20px 24px; }
.chip {
  padding: 9px 15px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--sep);
  font-weight: 500;
  transition: background-color .15s, color .15s, border-color .15s;
}
.chip.is-on { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 8px 20px; }
.hidden-list { list-style: none; margin: 0 12px 24px; padding: 0; background: var(--card); border-radius: var(--radius); }
.hidden-list li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.hidden-list li + li { border-top: 1px solid var(--sep); }
.hidden-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden-list button { color: var(--link); font-weight: 500; }
.bottom-bar {
  position: sticky; bottom: 0;
  padding: 12px 20px calc(12px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.tg-main-button .bottom-bar { display: none; }

/* ---------- лента ---------- */
.list { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 0; }
.sentinel { height: 1px; }
.end { padding: 40px 24px; }
.end p { margin: 0; max-width: 280px; }

.post {
  background: var(--card);
  padding: 12px 0 4px;
  overflow: hidden;
  animation: appear .35s ease-out both;
}
@media (min-width: 600px) {
  .list { max-width: 560px; margin: 0 auto; padding: 4px 12px 0; }
  .post { border-radius: var(--radius); }
}
@keyframes appear { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .post { animation: none; } }

.post-head { display: flex; align-items: center; gap: 10px; padding: 0 8px 10px 14px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; background: var(--sep); flex: none; }
.post-meta { flex: 1; min-width: 0; }
.post-channel { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post-sub { font-size: 13px; }

.post-text { padding: 0 14px; overflow-wrap: anywhere; }
.post-text:empty { display: none; }
.post-text.is-clamped { display: -webkit-box; -webkit-line-clamp: 9; -webkit-box-orient: vertical; overflow: hidden; }
.post-text blockquote { margin: 6px 0; padding: 2px 0 2px 10px; border-left: 3px solid var(--accent); }
.post-text pre, .post-text code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.post-text pre { white-space: pre-wrap; background: var(--bg); padding: 8px 10px; border-radius: 8px; }
.spoiler { filter: blur(5px); background: var(--sep); border-radius: 4px; cursor: pointer; transition: filter .2s; }
.spoiler.is-open { filter: none; background: none; }
.post-expand { padding: 4px 14px 0; color: var(--link); font-weight: 500; }

.post-media { position: relative; margin-bottom: 10px; }
.post-media:empty { display: none; }
.media-track {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.media-track::-webkit-scrollbar { display: none; }
.media-item {
  flex: 0 0 100%; scroll-snap-align: center; position: relative;
  background: var(--bg); aspect-ratio: 4 / 5; max-height: 72vh;
}
.media-item.is-single { aspect-ratio: auto; max-height: 72vh; }
.media-item img, .media-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-item.is-single img, .media-item.is-single video { height: auto; max-height: 72vh; object-fit: contain; margin: 0 auto; }
.media-counter {
  position: absolute; top: 10px; right: 10px;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: rgba(0, 0, 0, .55); color: #fff;
}
.play-badge {
  position: absolute; inset: 0; margin: auto; width: 54px; height: 54px; border-radius: 50%;
  display: grid; place-items: center; pointer-events: none;
  background: rgba(0, 0, 0, .5); color: #fff;
}
.media-item.is-playing .play-badge { display: none; }
.duration {
  position: absolute; left: 10px; bottom: 10px; padding: 1px 7px; border-radius: 6px;
  font-size: 12px; background: rgba(0, 0, 0, .55); color: #fff;
}

.link-preview {
  display: flex; gap: 10px; margin: 10px 14px 0; padding: 8px 10px;
  border-left: 3px solid var(--accent); border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--text);
}
.lp-image { flex: none; width: 64px; height: 64px; border-radius: 6px; background: center / cover no-repeat var(--sep); }
.lp-image:not([style]) { display: none; }
.lp-body { min-width: 0; font-size: 14px; }
.lp-site { color: var(--link); font-weight: 600; font-size: 13px; }
.lp-title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lp-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.post-actions { display: flex; align-items: center; gap: 4px; padding: 6px 6px 4px; }
.action { display: inline-flex; align-items: center; gap: 5px; padding: 8px; border-radius: 10px; font-size: 14px; }
.action.open { margin-left: auto; color: var(--link); font-weight: 500; padding: 8px 10px; }
.like .heart { fill: none; stroke: var(--hint); stroke-width: 1.8; transition: fill .15s, stroke .15s; }
.like.is-on .heart { fill: var(--heart); stroke: var(--heart); }
.like.is-on { color: var(--heart); }
.like.pop svg { animation: pop .3s ease-out; }
@keyframes pop { 40% { transform: scale(1.25); } }
.views { pointer-events: none; }

.post.is-hidden { padding: 14px; animation: none; }
.post.is-hidden > * { display: none; }
.post.is-hidden::before { content: attr(data-hidden-text); color: var(--hint); font-size: 14px; }

/* ---------- шит ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .35);
  display: flex; align-items: flex-end;
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; margin: 0 auto;
  padding: 8px 10px calc(10px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 6px;
  animation: slide .2s ease-out;
}
@keyframes slide { from { transform: translateY(30px); } }
.sheet-item { background: var(--card); padding: 15px; border-radius: 12px; font-weight: 500; text-align: center; }
.sheet-item.danger { color: var(--danger); }
.sheet-cancel { margin-top: 4px; font-weight: 600; }
