/* Цвета берутся из темы Telegram (--tg-theme-*, их выставляет telegram-web-app.js);
   запасные значения — тёмная тема, как у бота. */
:root {
  --bg: var(--tg-theme-bg-color, #0f1720);
  --bg2: var(--tg-theme-secondary-bg-color, #17222e);
  --text: var(--tg-theme-text-color, #eef2f6);
  --hint: var(--tg-theme-hint-color, #8a9bb0);
  --link: var(--tg-theme-link-color, #5aa0ef);
  --accent: var(--tg-theme-button-color, #3f84d6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-section-bg-color, var(--bg2));
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --radius: 14px;
  color-scheme: dark light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -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, input { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }

/* ---------- шапка ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: 10px 12px 6px;
  border-bottom: 1px solid var(--sep);
}
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg2); border-radius: 12px; padding: 0 12px; height: 40px;
  color: var(--hint);
}
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); height: 100%;
}
.search input::placeholder { color: var(--hint); }
.chips {
  display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; border-radius: 999px; padding: 6px 12px;
  background: var(--bg2); color: var(--text); font-size: 13.5px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--accent); color: var(--accent-text); }
.chips.tags .chip { font-size: 12.5px; padding: 5px 10px; color: var(--hint); }
.chips.tags .chip.on { color: var(--accent-text); }

/* ---------- сетка ---------- */
main { padding: 8px 10px calc(24px + env(safe-area-inset-bottom)); }
.mode {
  margin: 4px 2px 8px; padding: 10px 12px; border-radius: 12px; font-size: 13px; line-height: 1.35;
  background: color-mix(in srgb, #e0a030 16%, var(--bg2)); color: var(--text);
}
.mode[hidden] { display: none; }
.status { color: var(--hint); font-size: 13px; text-align: center; padding: 8px 4px; min-height: 1em; }
.status button { margin-top: 8px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 860px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.card {
  display: flex; flex-direction: column; text-align: left;
  border: 0; padding: 0; background: var(--card); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; min-width: 0;
}
.card:active { transform: scale(0.98); }
.thumb { position: relative; aspect-ratio: 1 / 1; background: var(--bg2); }  /* превью Chub квадратные */
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .badge {
  position: absolute; left: 6px; bottom: 6px;
  background: rgba(0, 0, 0, 0.55); color: #fff; border-radius: 999px; padding: 2px 8px; font-size: 12px;
}
.card .meta { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.card .name { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .tagline {
  color: var(--hint); font-size: 12.5px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.6em;
}

.skeleton .thumb { animation: pulse 1.2s ease-in-out infinite; }
.skeleton .meta span { display: block; height: 10px; border-radius: 5px; background: var(--bg2); margin: 3px 0; }
@keyframes pulse { 50% { opacity: 0.55; } }

.btn {
  border: 0; border-radius: 10px; padding: 9px 16px; background: var(--accent); color: var(--accent-text);
  cursor: pointer; font-weight: 600;
}

/* ---------- карточка персонажа ---------- */
.detail { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; }
.detail[hidden] { display: none; }
.detail-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.close {
  position: fixed; top: 10px; left: 10px; z-index: 2; width: 38px; height: 38px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, 0.5); color: #fff; display: grid; place-items: center; cursor: pointer;
}
.in-telegram .close { display: none; }  /* в Telegram — нативная кнопка «Назад» */
.hero { position: relative; background: var(--bg2); }
.hero img { display: block; width: 100%; max-height: 62vh; object-fit: cover; object-position: center 20%; }
.hero::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 90px;
  background: linear-gradient(transparent, var(--bg));
}
.d-body { padding: 0 16px 24px; margin-top: -36px; position: relative; }
.d-body h1 { margin: 0; font-size: 24px; line-height: 1.2; overflow-wrap: anywhere; }
.d-creator { color: var(--hint); font-size: 13.5px; margin-top: 2px; }
.d-tagline { margin: 10px 0 0; overflow-wrap: anywhere; }
.stats { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--hint); font-size: 13px; margin-top: 10px; }
.stats span { display: inline-flex; align-items: center; gap: 4px; }
.stats svg { width: 15px; height: 15px; }
.d-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.d-tags .chip { font-size: 12.5px; padding: 5px 10px; }
.block { margin-top: 18px; background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.block h2 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--hint); }
.text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; }
.text.clamp { max-height: 12.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.more-btn { border: 0; background: none; color: var(--link); padding: 6px 0 0; cursor: pointer; }
.d-status { color: var(--hint); font-size: 13px; text-align: center; padding: 12px 0; }

.pick-bar { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--sep); background: var(--bg); }
.pick {
  display: block; text-align: center; text-decoration: none; font-weight: 600;
  background: var(--accent); color: var(--accent-text); border-radius: 12px; padding: 13px;
}
.in-telegram .pick-bar { display: none; }  /* в Telegram — нативная нижняя кнопка */
button.pick { width: 100%; border: 0; cursor: pointer; font: inherit; font-weight: 600; }

/* ---------- кнопка «Все теги» и полный список ---------- */
.chip.all-tags { background: color-mix(in srgb, var(--accent) 18%, var(--bg2)); color: var(--text); font-weight: 600; }
.chips.tags .chip.all-tags { color: var(--text); }

.sheet { z-index: 30; }
.sheet-head { padding: 10px 12px 8px; border-bottom: 1px solid var(--sep); background: var(--bg); }
.sheet-title { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.sheet-title > div { flex: 1; min-width: 0; }
.sheet-title h1 { margin: 0; font-size: 20px; }
.sheet-sub { color: var(--hint); font-size: 12.5px; }
.sheet-close {
  width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--bg2); color: var(--text);
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.in-telegram .sheet-close { display: none; }  /* в Telegram — нативная «Назад» */
.link-btn { border: 0; background: none; color: var(--link); cursor: pointer; padding: 6px 2px; flex: none; }
.link-btn[hidden] { display: none; }

.tag-list { display: flex; flex-direction: column; padding: 6px 10px 16px; }
.tag-item {
  display: flex; align-items: baseline; gap: 8px; text-align: left;
  border: 0; border-bottom: 1px solid var(--sep); background: none; padding: 11px 6px; cursor: pointer;
}
.tag-item .tag-ru { font-size: 15px; overflow-wrap: anywhere; }
.tag-item .tag-en { color: var(--hint); font-size: 12.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-item .tag-check {
  margin-left: auto; flex: none; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--sep); display: grid; place-items: center; font-size: 13px; line-height: 1; align-self: center;
}
.tag-item.on .tag-ru { font-weight: 600; }
.tag-item.on .tag-check { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
