/* ==========================================================================
   Components — используют только токены из tokens.css.
   Префикс .ui-  ·  БЭМ-подобно: .ui-block, .ui-block__el, .ui-block--mod
   ========================================================================== */

/* ---------- База ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body {
  font-family: var(--font); font-size: var(--fs-body); line-height: 1.6;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

.ui-page {
  max-width: var(--col); margin-inline: auto;
  padding: var(--s-4) var(--gutter) calc(120px + env(safe-area-inset-bottom, 0px));
}
.ui-stack { display: grid; gap: var(--s-8); }
.ui-stack--tight { gap: var(--s-4); }
.ui-icon { width: 24px; height: 24px; flex: none; }

/* ---------- Типографика ---------- */
.ui-display { font-size: var(--fs-display); line-height: 1.05; font-weight: 700; letter-spacing: -.03em; }
.ui-h1 { font-size: var(--fs-h1); line-height: 1.15; font-weight: 700; letter-spacing: -.02em; text-wrap: balance; }
.ui-h2 { font-size: var(--fs-h2); line-height: 1.2; font-weight: 700; letter-spacing: -.015em; text-wrap: balance; }
.ui-h3 { font-size: var(--fs-h3); line-height: 1.3; font-weight: 600; }
.ui-lead { color: var(--text-2); font-size: 17px; line-height: 1.55; }
.ui-muted { color: var(--text-2); }
.ui-meta { color: var(--text-2); font-size: var(--fs-small); }
.ui-overline { font-size: var(--fs-overline); font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--text-2); }
.ui-link { color: var(--link); font-weight: 600; }
.ui-num { font-variant-numeric: tabular-nums; }

/* ---------- Кнопки ---------- */
.ui-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 40px; padding: 0 18px; border: 0; border-radius: var(--r-pill);
  background: var(--surface); color: var(--text);
  font-size: 16px; font-weight: 600; line-height: 1; white-space: nowrap; cursor: pointer;
  transition: transform .12s ease, background .12s ease, opacity .12s ease;
}
.ui-btn:active { transform: scale(.97); }
.ui-btn .ui-icon { width: 18px; height: 18px; }
.ui-btn--primary { width: 100%; height: 52px; font-size: 17px; background: var(--cta-bg); color: var(--cta-text); }
.ui-btn--accent  { background: var(--accent); color: var(--on-brand); }
.ui-btn--light   { background: #fff; color: #000; }
.ui-btn--glass   { background: rgba(255,255,255,.22); color: #fff; }
.ui-btn--round   { width: 40px; padding: 0; }
.ui-btn--block   { width: 100%; }

/* ---------- Значки и бейджи ---------- */
.ui-ibadge {                                   /* цветной круг с иконкой: «Что внутри», бейдж на аватаре */
  --c: var(--brand);
  width: 32px; height: 32px; flex: none; border-radius: 50%;
  display: grid; place-items: center; background: var(--c); color: #fff;
}
.ui-ibadge .ui-icon { width: 18px; height: 18px; }
.ui-ibadge[data-tone="pink"]   { --c: var(--ds-pink); }
.ui-ibadge[data-tone="purple"] { --c: var(--ds-purple); }
.ui-ibadge[data-tone="green"]  { --c: var(--ds-green); }
.ui-ibadge[data-tone="teal"]   { --c: var(--ds-teal); }
.ui-ibadge[data-tone="dark"]   { --c: var(--ds-ink); }
.ui-badge {
  display: inline-flex; align-items: center; height: 24px; padding: 0 10px;
  border-radius: var(--r-xs); font-size: var(--fs-caption); font-weight: 700; line-height: 1;
  background: var(--ds-yellow); color: var(--ds-ink);
}
.ui-avatar {
  position: relative; width: 48px; height: 48px; flex: none; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: var(--on-brand); font-weight: 700; font-size: 18px;
}
.ui-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.ui-avatar .ui-ibadge {
  position: absolute; right: -5px; bottom: -5px; width: 24px; height: 24px; border: 2px solid var(--bg);
}
.ui-avatar .ui-ibadge .ui-icon { width: 13px; height: 13px; }
.ui-avatar--sm { width: 44px; height: 44px; font-size: 16px; }

/* ---------- Таб-бар (плавающая «таблетка») ---------- */
.ui-tabbar {
  position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  z-index: 20; display: flex; gap: 4px; padding: 6px;
  background: var(--bar-bg); border-radius: var(--r-pill); box-shadow: var(--shadow-float);
}
.ui-tabbar--static { position: static; transform: none; width: max-content; }
.ui-tab {
  height: 48px; min-width: 48px; padding: 0 16px; border-radius: var(--r-pill);
  display: flex; align-items: center; justify-content: center; gap: var(--s-2);
  font-weight: 600; color: var(--text-3); transition: background .15s, color .15s;
}
.ui-tab span { display: none; }
.ui-tab[aria-current="page"] { background: var(--surface); color: var(--text); padding: 0 20px 0 16px; }
.ui-tab[aria-current="page"] span { display: inline; }

/* ---------- Шапка внутренних страниц ---------- */
.ui-topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 15;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-3) 0; margin-bottom: var(--s-2);
  background: linear-gradient(var(--bg) 70%, transparent);
}
.ui-topbar .ui-btn { background: var(--surface); }
.in-tg .ui-topbar .js-back { visibility: hidden; }   /* в Telegram — нативная кнопка «Назад» */

/* ---------- Hero-карточка программы (тёмная, с синей кнопкой) ---------- */
.ui-hero {
  position: relative; aspect-ratio: 4 / 3; border-radius: var(--r-xl); overflow: hidden;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(var(--hero-from), var(--hero-to));
}
.ui-hero__play {
  width: 60px; height: 60px; border-radius: 50%; background: var(--brand); color: var(--on-brand);
  display: grid; place-items: center; box-shadow: 0 0 0 14px rgba(255,255,255,.045);
}
.ui-hero__play .ui-icon { width: 28px; height: 28px; }
.ui-hero__foot {
  position: absolute; inset: auto 20px 20px; display: flex; align-items: center; justify-content: space-between;
  color: rgba(255,255,255,.85);
}
.ui-hero__foot .ui-icon { width: 20px; height: 20px; }

/* ---------- Секция ---------- */
.ui-section { display: grid; gap: var(--s-4); }
.ui-section > .ui-h2 { margin-bottom: 0; }

/* ---------- Чек-лист «Кому это нужно» ---------- */
.ui-checklist { display: grid; gap: var(--s-5); list-style: none; padding: 0; }
.ui-checklist li { display: grid; grid-template-columns: 24px 1fr; column-gap: var(--s-3); }
.ui-checklist .ui-icon { width: 22px; height: 22px; color: var(--ds-green); margin-top: 2px; stroke-width: 2.4; }
.ui-checklist b { display: block; font-size: 18px; line-height: 1.4; font-weight: 600; }
.ui-checklist p { color: var(--text-2); font-size: 17px; line-height: 1.55; }

/* ---------- Ряд-«рельса» (сториз-карточки) ---------- */
.ui-rail {
  display: flex; gap: var(--s-3); overflow-x: auto; scroll-snap-type: x mandatory;
  margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter); scroll-padding-inline: var(--gutter); scrollbar-width: none;
}
.ui-rail::-webkit-scrollbar { display: none; }
.ui-rail > * { scroll-snap-align: start; flex: none; }
.ui-story {
  width: 44%; min-width: 150px; aspect-ratio: 9 / 16; border-radius: var(--r-l); padding: var(--s-4);
  display: flex; flex-direction: column; justify-content: center; gap: var(--s-3);
  background: var(--ds-ink); color: #fff; font-size: 17px; font-weight: 600; line-height: 1.25;
}
.ui-story--warm { background: linear-gradient(160deg, #EE6A34 0%, #F6A25A 100%); }
.ui-story small { font-size: 12px; font-weight: 500; opacity: .7; }
.ui-story__chip {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 12px;
  background: rgba(255,255,255,.1); font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden;
}

/* ---------- Карточка-статистика ---------- */
.ui-stat { background: var(--surface); border-radius: var(--r-xl); padding: 22px; display: grid; gap: var(--s-3); }
.ui-stat__value { font-size: 44px; line-height: 1; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.ui-stat__label { color: var(--text-2); font-size: 17px; }
.ui-seg { display: flex; gap: 3px; height: 8px; margin-block: var(--s-1); }
.ui-seg i { display: block; border-radius: 4px; }
.ui-legend { display: flex; gap: var(--s-8); flex-wrap: wrap; }
.ui-legend > div { display: grid; gap: 2px; }
.ui-legend b { display: flex; align-items: center; gap: var(--s-2); font-size: 28px; line-height: 1.1; font-weight: 600; font-variant-numeric: tabular-nums; }
.ui-legend b::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--dot, var(--accent)); }
.ui-legend span { color: var(--text-2); font-size: var(--fs-small); }

/* ---------- Список «Что внутри» ---------- */
.ui-features { display: grid; gap: var(--s-5); list-style: none; padding: 0; }
.ui-features li { display: grid; grid-template-columns: 32px 1fr; column-gap: var(--s-3); align-items: start; }
.ui-features b { display: block; font-size: 18px; line-height: 32px; font-weight: 600; }
.ui-features p { grid-column: 2; color: var(--text-2); font-size: 17px; line-height: 1.55; }

/* ---------- Плашка-врезка (Что понадобится / совет) ---------- */
.ui-callout { background: var(--surface); border-radius: var(--r-xl); padding: 22px; display: grid; gap: var(--s-3); }
.ui-callout > b { font-size: 16px; font-weight: 600; }
.ui-callout p { color: var(--text-2); }
.ui-callout .ui-features { gap: var(--s-4); }
.ui-callout .ui-ibadge { width: 28px; height: 28px; }

/* ---------- Карточка «Закрытый чат» + пузырь-сообщение ---------- */
.ui-chatcard { background: var(--surface); border-radius: var(--r-xl); padding: 22px; display: grid; gap: var(--s-4); }
.ui-chatcard__head { display: flex; align-items: center; gap: var(--s-3); }
.ui-chatcard__head b { display: block; font-size: 20px; line-height: 1.2; font-weight: 600; }
.ui-chatcard__head span { color: var(--text-2); font-size: var(--fs-small); }
.ui-chatcard > p { font-size: 20px; line-height: 1.4; font-weight: 500; }
.ui-bubbles { display: flex; gap: var(--s-3); align-items: flex-start; }
.ui-bubble { background: var(--bubble); border-radius: var(--r-m); padding: 14px 16px; display: grid; gap: 4px; font-size: 14px; line-height: 1.45; }
.ui-bubble b { font-size: 15px; color: var(--ds-ink); }
[data-theme="dark"] .ui-bubble b, .on-dark .ui-bubble b { color: var(--text); }
.ui-bubble a { color: var(--ds-link); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Лента: карточка материала ---------- */
.ui-feed { display: grid; }
.ui-feed-item {
  display: grid; grid-template-columns: 48px minmax(0, 1fr); column-gap: var(--s-3);
  padding-block: 22px; border-bottom: 1px solid var(--line);
}
.ui-feed-item:last-child { border-bottom: 0; }
.ui-feed-item__body { display: grid; gap: var(--s-3); justify-items: start; min-width: 0; }
.ui-feed-item__meta { display: flex; flex-wrap: wrap; gap: 0 var(--s-2); align-items: baseline; }
.ui-feed-item__meta b { font-size: 18px; font-weight: 600; }
.ui-feed-item__meta span { color: var(--text-2); font-size: 17px; }
.ui-feed-item__title { font-size: var(--fs-h3); line-height: 1.3; font-weight: 500; text-wrap: balance; }
.ui-cover {
  width: 100%; aspect-ratio: 1.55; border-radius: var(--r-l); overflow: hidden;
  display: grid; place-items: center; background: linear-gradient(160deg, var(--surface), var(--surface-2));
}
.ui-cover svg { width: 62%; height: auto; }
.ui-cover--wide { aspect-ratio: 16 / 10; }

/* ---------- Уроки (тёмный список) ---------- */
.ui-progress-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); color: var(--text-2); font-size: var(--fs-small); font-weight: 500; }
.ui-module { display: grid; gap: var(--s-3); }
.ui-module__head { display: flex; align-items: baseline; gap: var(--s-2); }
.ui-module__head b { font-size: 20px; line-height: 1.2; font-weight: 700; }
.ui-module__head span { color: var(--text-2); font-size: var(--fs-small); }
.ui-lesson {
  display: grid; gap: var(--s-3); padding: 16px 18px; border-radius: var(--r-l);
  background: var(--surface); border: 1.5px solid transparent; transition: border-color .15s, transform .12s;
}
.ui-lesson:active { transform: scale(.985); }
.ui-lesson__row { display: grid; grid-template-columns: 32px 1px minmax(0, 1fr) 28px; align-items: center; column-gap: var(--s-3); }
.ui-lesson__n { font-size: 24px; font-weight: 500; text-align: center; line-height: 1; font-variant-numeric: tabular-nums; }
.ui-lesson__sep { align-self: stretch; background: rgba(255,255,255,.14); }
.ui-lesson__txt { display: grid; gap: 1px; min-width: 0; }
.ui-lesson__txt small { font-size: var(--fs-overline); font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--text-2); }
.ui-lesson__txt b { font-size: 17px; line-height: 1.3; font-weight: 600; }
.ui-lesson__state { width: 26px; height: 26px; color: var(--text-2); }
.ui-lesson.is-done .ui-lesson__state { color: #0d2b18; background: var(--ok); border-radius: 50%; padding: 5px; }
.ui-lesson.is-active { border-color: rgba(255,255,255,.28); }
.ui-lesson.is-locked { cursor: default; }

/* ---------- Оплата ---------- */
.ui-logos { display: flex; }
.ui-logos > * {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; margin-left: -8px;
  background: #0d0d0d; color: #fff; border: 1.5px solid rgba(255,255,255,.22);
}
.ui-logos > *:first-child { margin-left: 0; }
.ui-logos .ui-icon { width: 22px; height: 22px; }
.ui-perk { background: var(--surface); border-radius: var(--r-l); padding: 18px 20px; display: flex; align-items: center; gap: var(--s-4); min-width: 78%; }
.ui-perk .ui-icon { width: 30px; height: 30px; }
.ui-perk > i { width: 1px; align-self: stretch; background: rgba(255,255,255,.14); }
.ui-perk small { display: block; color: var(--text-2); font-size: var(--fs-small); }
.ui-perk b { display: block; font-size: 22px; line-height: 1.15; font-weight: 700; }
.ui-perk span { display: block; color: var(--text-2); font-size: var(--fs-small); }
.ui-dots { display: flex; justify-content: center; gap: 6px; }
.ui-dots i { width: 6px; height: 6px; border-radius: 3px; background: var(--text-3); }
.ui-dots i.is-on { width: 26px; background: var(--text); }
.ui-plan {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  background: var(--surface); border-radius: var(--r-l); padding: 18px 20px;
  border: 1.5px dashed transparent;
}
.ui-plan.is-selected { border-color: transparent; }
.ui-plan__name { display: flex; align-items: center; gap: var(--s-2); font-size: 18px; font-weight: 600; }
.ui-plan__price { font-size: 32px; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.ui-plan__price small { font-size: var(--fs-body); font-weight: 500; color: var(--text-2); letter-spacing: 0; margin-left: 4px; }
.ui-plan__check { width: 28px; height: 28px; border-radius: 50%; background: #fff; color: #000; display: grid; place-items: center; }
.ui-plan__check .ui-icon { width: 16px; height: 16px; stroke-width: 3; }
.ui-field { display: grid; gap: var(--s-2); }
.ui-field label { font-size: var(--fs-small); color: var(--text-2); }
.ui-input {
  width: 100%; height: 56px; padding: 0 20px; border: 0; border-radius: var(--r-m);
  background: var(--surface); font-size: 17px; outline: 0;
}
.ui-input::placeholder { color: var(--text-3); }
.ui-input:focus { box-shadow: 0 0 0 2px var(--accent); }

/* ---------- Липкая нижняя кнопка ---------- */
.ui-cta-bar {
  position: fixed; inset: auto 0 0; z-index: 18;
  padding: 44px var(--gutter) calc(14px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to bottom, transparent, var(--bg) 46%);
  pointer-events: none;
}
.ui-cta-bar > * { pointer-events: auto; max-width: var(--col); margin-inline: auto; }

/* ---------- Статья (.ui-prose) ---------- */
.ui-article-head { display: grid; gap: var(--s-4); margin-bottom: var(--s-6); }
.ui-byline { display: flex; align-items: center; gap: var(--s-3); }
.ui-byline b { display: block; font-size: 17px; line-height: 1.25; }
.ui-byline span { color: var(--text-2); font-size: var(--fs-small); }
.ui-prose { font-size: 17px; line-height: 1.7; }
.ui-prose > * + * { margin-top: var(--s-5); }
.ui-prose h2 { font-size: var(--fs-h2); line-height: 1.2; font-weight: 700; letter-spacing: -.015em; margin-top: var(--s-10); text-wrap: balance; }
.ui-prose h3 { font-size: var(--fs-h3); line-height: 1.3; font-weight: 600; margin-top: var(--s-8); }
.ui-prose p, .ui-prose li { color: var(--text); }
.ui-prose a { color: var(--link); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
.ui-prose ul, .ui-prose ol { padding-left: 1.25em; display: grid; gap: var(--s-2); }
.ui-prose ul li::marker { color: var(--brand); }
.ui-prose ol li::marker { color: var(--text-2); font-weight: 700; }
.ui-prose strong { font-weight: 700; }
.ui-prose hr { border: 0; height: 1px; background: var(--line); margin-block: var(--s-8); }
.ui-prose img { border-radius: var(--r-l); }
.ui-prose code { font-family: var(--font-mono); font-size: .88em; background: var(--surface); padding: .12em .4em; border-radius: 8px; }
.ui-prose pre {
  font-family: var(--font-mono); font-size: 13.5px; line-height: 1.6; overflow-x: auto;
  background: var(--ds-ink); color: #F4F4F4; padding: 18px 20px; border-radius: var(--r-m);
}
.ui-prose pre code { background: none; padding: 0; font-size: inherit; }
.ui-prose blockquote { background: var(--surface); border-radius: var(--r-l); padding: 18px 20px; color: var(--text-2); }
.ui-prose blockquote p { color: inherit; }
.ui-note { display: grid; grid-template-columns: 32px 1fr; gap: var(--s-3); background: var(--surface); border-radius: var(--r-l); padding: 18px 20px; }
.ui-note > div > * + * { margin-top: var(--s-2); }
.ui-note strong { display: block; }
.ui-more { display: grid; gap: var(--s-2); margin-top: var(--s-10); }
.ui-more a {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: 16px 18px; border-radius: var(--r-l); background: var(--surface); font-weight: 600; line-height: 1.3;
}
.ui-more a small { color: var(--text-2); font-weight: 400; display: block; }
.ui-more .ui-icon { color: var(--text-3); }

/* ---------- Стайлгайд ---------- */
.sg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s-3); }
.sg-sw { border-radius: var(--r-m); overflow: hidden; background: var(--surface); }
.sg-sw i { display: block; height: 64px; }
.sg-sw div { padding: 10px 12px; font-size: 12px; line-height: 1.4; }
.sg-sw b { display: block; font-size: 13px; }
.sg-sw code { font-family: var(--font-mono); color: var(--text-2); }
.sg-specimen { display: grid; gap: var(--s-4); padding-block: var(--s-4); border-top: 1px solid var(--line); }
.sg-row { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }
.sg-icons { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: var(--s-2); }
.sg-icons figure { display: grid; justify-items: center; gap: 6px; padding: 14px 4px; background: var(--surface); border-radius: var(--r-m); font-size: 11px; color: var(--text-2); }
.sg-wrap { max-width: 720px; margin-inline: auto; padding: var(--s-6) var(--gutter) 80px; display: grid; gap: var(--s-10); }
.sg-phone { max-width: 400px; width: 100%; }
.sg-dark { background: var(--bg); color: var(--text); border-radius: var(--r-xl); padding: var(--s-5); display: grid; gap: var(--s-4); }

/* Тёмные «острова» на всю страницу (оплата, уроки): красим и подложку под overscroll */
html:has(body.on-dark) { background: #000; color-scheme: dark; }
.ui-demo { text-align: center; color: var(--text-2); font-size: var(--fs-caption); padding-top: var(--s-6); }
.ui-story__chip .ui-icon { width: 14px; height: 14px; }
.ui-lesson__sep { background: rgba(128,128,128,.32); }
