:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f3f8);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #121e3e);
  --hint: var(--tg-theme-hint-color, #6b7386);
  --link: var(--tg-theme-link-color, #0057b7);
  --accent: var(--tg-theme-button-color, #0057b7);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --chip: color-mix(in srgb, var(--hint) 13%, transparent);
  --yellow: #ffd500;
  --star: #f5a800;
  --good: #1a9b52;
  --bad: #d9483b;
  --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));
  --page-gutter: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #101521;
    --card: #1b2231;
    --text: #eef1f7;
    --hint: #98a1b5;
    --link: #6ab2ff;
    --accent: #2f8cf0;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.38 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
img { display: block; }
h1, h2, h3, p { margin: 0; }
a { color: var(--link); }

#app { padding-bottom: calc(68px + var(--safe-bottom)); min-height: 100vh; }
#app.no-tabs { padding-bottom: calc(24px + var(--safe-bottom)); }

/* Верх каталога */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(10px + var(--safe-top)) var(--page-gutter) 6px; }
.brand { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.brand h1 { font-size: 19px; font-weight: 800; letter-spacing: -.2px; white-space: nowrap; }
.brand .sub { font-size: 11.5px; line-height: 1.2; color: var(--hint); margin-left: auto; text-align: right; min-width: 0; }
.flagline { height: 3px; width: 26px; border-radius: 2px; background: linear-gradient(90deg, #0057b7 50%, var(--yellow) 50%); flex: none; }
.search { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 12px; padding: 0 12px; height: 40px; }
.search svg { flex: none; color: var(--hint); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; font-size: 16px; }
.search input::placeholder { color: var(--hint); }
.search .clear { color: var(--hint); font-size: 18px; line-height: 1; padding: 4px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px var(--page-gutter) 0; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 34px; padding: 0 12px; border-radius: 17px; background: var(--card); font-size: 14px; font-weight: 500; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.chips.sort { padding-top: 2px; }
.result-note { padding: 10px var(--page-gutter) 6px; font-size: 13px; color: var(--hint); display: flex; justify-content: space-between; gap: 10px; }
.result-note button { color: var(--link); font-size: 13px; flex: none; }

/* Сетка товаров */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 0 var(--page-gutter); }
@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 { position: relative; display: flex; flex-direction: column; text-align: left; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.card .ph { aspect-ratio: 1; width: 100%; height: auto; object-fit: cover; background: var(--chip); }
.card .fav-dot { position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 13px; background: rgba(0,0,0,.45); color: var(--yellow); display: flex; align-items: center; justify-content: center; font-size: 14px; }
.card .rank { position: absolute; top: 6px; left: 6px; min-width: 26px; height: 26px; padding: 0 7px; border-radius: 13px; background: rgba(0,0,0,.6); color: #fff; font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.card .rank.warn { background: var(--bad); }
.card .pic { position: relative; }
.card .play { top: auto; left: 6px; bottom: 6px; }
.card .body { padding: 8px 9px 10px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.card .price { font-size: 16px; font-weight: 800; }
.card .price small { font-size: 12px; font-weight: 500; color: var(--hint); }
.card .name { font-size: 13.5px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.5em; }
.card .meta { font-size: 12.5px; color: var(--hint); margin-top: auto; padding-top: 3px; display: flex; flex-wrap: wrap; gap: 0 6px; }
.card .meta b { color: var(--star); font-weight: 700; }
.card .meta .bad { color: var(--bad); font-weight: 600; }

.empty { padding: 48px 28px; text-align: center; color: var(--hint); }
.empty .big { font-size: 36px; margin-bottom: 8px; }

/* Нижние вкладки */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--sep); padding-bottom: var(--safe-bottom); }
.tabs[hidden] { display: none; }
.tabs button { flex: 1; min-width: 0; padding: 7px 2px 6px; display: flex; flex-direction: column; align-items: center; gap: 1px; color: var(--hint); font-size: 11px; font-weight: 500; }
.tabs button .i { font-size: 20px; line-height: 24px; filter: grayscale(1) opacity(.75); }
.tabs button.on { color: var(--accent); font-weight: 700; }
.tabs button.on .i { filter: none; }

/* Подборки */
.page-title { padding: calc(14px + var(--safe-top)) var(--page-gutter) 10px; font-size: 21px; font-weight: 800; }
.page-sub { padding: 0 var(--page-gutter) 12px; color: var(--hint); font-size: 14px; margin-top: -6px; }
.coll { display: block; width: calc(100% - 2 * var(--page-gutter)); margin: 0 var(--page-gutter) 10px; background: var(--card); border-radius: var(--radius); overflow: hidden; text-align: left; }
.coll .strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; }
.coll .strip img { aspect-ratio: 1; width: 100%; object-fit: cover; background: var(--chip); }
.coll .txt { padding: 10px 12px 12px; }
.coll h3 { font-size: 16px; font-weight: 700; }
.coll p { color: var(--hint); font-size: 13.5px; margin-top: 2px; }

/* Страница товара */
.gallery { position: relative; background: #000; }
.gallery .track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.gallery .track::-webkit-scrollbar { display: none; }
.gallery .slide { flex: 0 0 100%; scroll-snap-align: center; aspect-ratio: 1; max-height: 62vh; width: 100%; }
.gallery .slide img { width: 100%; height: 100%; object-fit: contain; }
.gallery .count { position: absolute; right: 10px; bottom: 10px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 11px; }
.gallery .credit { position: absolute; left: 10px; bottom: 10px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 3px 8px; border-radius: 11px; }

.block { background: var(--card); border-radius: var(--radius); margin: 10px var(--page-gutter) 0; padding: 12px 13px; }
.block h2 { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.ptitle { font-size: 19px; font-weight: 800; line-height: 1.22; letter-spacing: -.1px; }
.phook { color: var(--hint); margin-top: 4px; font-size: 14.5px; }
.pprice { margin-top: 10px; font-size: 24px; font-weight: 800; }
.pprice small { font-size: 14px; font-weight: 500; color: var(--hint); }
.pdate { font-size: 12.5px; color: var(--hint); margin-top: 1px; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions button { flex: 1; height: 40px; border-radius: 11px; background: var(--chip); font-weight: 600; font-size: 14px; }
.actions button.on { color: #b98600; background: color-mix(in srgb, var(--yellow) 25%, transparent); }
.buy-inline { display: block; width: 100%; height: 46px; margin-top: 10px; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 15px; }

.score { display: flex; gap: 14px; align-items: center; }
.score .num { font-size: 38px; font-weight: 800; line-height: 1; }
.score .stars { color: var(--star); font-size: 14px; letter-spacing: 1px; margin-top: 3px; }
.score .of { font-size: 12.5px; color: var(--hint); margin-top: 2px; }
.bars { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.bar { display: grid; grid-template-columns: 22px 1fr 40px; gap: 6px; align-items: center; font-size: 12px; color: var(--hint); }
.bar .tr { height: 7px; border-radius: 4px; background: var(--chip); overflow: hidden; }
.bar .fl { height: 100%; background: var(--star); border-radius: 4px; }
.bar.low .fl { background: var(--bad); }
.bar span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.kpis { display: flex; gap: 6px; margin-top: 10px; }
.kpi { flex: 1; min-width: 0; background: var(--chip); border-radius: 10px; padding: 7px 8px; }
.kpi b { display: block; font-size: 16px; }
.kpi span { font-size: 11.5px; color: var(--hint); line-height: 1.2; display: block; }
.kpi.warn b { color: var(--bad); }
.kpi.ok b { color: var(--good); }
.glob { font-size: 12.5px; color: var(--hint); margin-top: 8px; }

.theme { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--sep); }
.theme:first-of-type { border-top: 0; padding-top: 0; }
.theme .n { flex: none; font-size: 12.5px; font-weight: 600; color: var(--good); white-space: nowrap; align-self: flex-start; padding-top: 1px; }
.cons .theme .n { color: var(--bad); }
.hint-small { font-size: 12.5px; color: var(--hint); margin-top: 8px; }

.quote { border-top: 1px solid var(--sep); padding: 10px 0; }
.quote:first-of-type { border-top: 0; padding-top: 0; }
.quote:last-child { padding-bottom: 0; }
.quote .q { font-size: 14.5px; }
.quote .qm { font-size: 12.5px; color: var(--hint); margin-top: 3px; }
.quote .qm b { color: var(--star); letter-spacing: 1px; font-weight: 400; }
.vids { display: flex; gap: 8px; }
.vids button { flex: 1; height: 42px; border-radius: 11px; background: var(--chip); font-weight: 600; }

.tagline { display: flex; flex-wrap: wrap; gap: 6px; }
.tagline button { font-size: 13.5px; color: var(--link); background: var(--chip); border-radius: 13px; padding: 4px 10px; }

/* Как считаем */
.prose { padding: 0 var(--page-gutter); }
.prose .block { margin-left: 0; margin-right: 0; }
.prose p { font-size: 14.5px; margin-bottom: 8px; }
.prose p:last-child { margin-bottom: 0; }
.formula { background: var(--chip); border-radius: 10px; padding: 9px 11px; font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 13px; margin: 8px 0; overflow-x: auto; white-space: nowrap; }

/* Просмотр фото */
.lightbox { position: fixed; inset: 0; z-index: 20; background: #000; display: flex; overflow-x: auto; scroll-snap-type: x mandatory; }
.lightbox[hidden] { display: none; }
.lightbox .lb { flex: 0 0 100%; scroll-snap-align: center; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100%; max-height: 100%; }
