/* ══════════════════════════════════════════════════════════════════
   ui.css — компоненты дизайн-системы ttt.tg (v1)
   Прототип каждого блока — на демо /demoapp. Требует tokens.css.
   Все классы с префиксом ui- (кроме амбиентного .glow-field),
   чтобы не конфликтовать с существующими классами страниц.

   Подключать ПОСЛЕ tokens.css:
     <link rel="stylesheet" href="/css/tokens.css?v=1">
     <link rel="stylesheet" href="/css/ui.css?v=1">
   ══════════════════════════════════════════════════════════════════ */

/* ────────────────────────────────────────────────────────────────
   §3.1 Глоу-фон (major.bot): гигантское размытое поле, медленный
   оборот 200s, CPU-стоимость ≈ 0. Вставлять внутрь .ambient-bg:
   <div class="glow-field" aria-hidden="true"></div>
   ──────────────────────────────────────────────────────────────── */
.glow-field {
  position: absolute; left: 50%; top: 55%;
  width: 2600px; height: 2600px;
  margin: -1300px 0 0 -1300px;
  border-radius: 42%;
  background:
    radial-gradient(closest-side, rgba(41, 182, 246, .10), transparent 70%),
    conic-gradient(from 0deg,
      transparent 0deg, rgba(41, 182, 246, .13) 55deg, transparent 125deg,
      rgba(175, 82, 222, .09) 215deg, transparent 290deg);
  filter: blur(60px);
  animation: ui-glow-rotate 200s linear infinite;
  pointer-events: none;
}
@keyframes ui-glow-rotate { to { transform: rotate(360deg); } }

/* ────────────────────────────────────────────────────────────────
   §1.2 Цифры балансов: rounded + tabular-nums (major.bot)
   ──────────────────────────────────────────────────────────────── */
.ui-num {
  font-family: var(--font-rounded);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.tnum { font-variant-numeric: tabular-nums; }

/* ────────────────────────────────────────────────────────────────
   §1.3 Кнопки-пилюли (major.bot): filled/tinted/plain/gray/critical
   ──────────────────────────────────────────────────────────────── */
.ui-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; padding: 0 24px; border-radius: 25px;
  font-size: 17px; line-height: 22px; font-weight: 600; color: #fff;
  user-select: none; overflow: hidden; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s ease, filter .15s ease, opacity .15s ease;
}
.ui-btn:active { transform: scale(var(--press-scale, .97)); filter: brightness(1.06); }
.ui-btn[disabled] { opacity: .45; pointer-events: none; }
.ui-btn:focus-visible { outline: 2px solid #80d5ff; outline-offset: 3px; }

.ui-btn-filled {
  background: var(--accent-grad);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 8px 22px -8px var(--accent-glow);
}
.ui-btn-tinted { background: var(--accent-10); color: var(--accent); }
.ui-btn-plain { background: var(--surface-2); color: var(--text); }
.ui-btn-gray { background: rgba(120, 120, 128, .16); color: var(--t70); }
.ui-btn-critical { background: var(--red-10); color: var(--red); }
.ui-btn-green { background: var(--btn-green-grad); color: #0d3a1c; }

.ui-btn-sm { height: 38px; padding: 0 18px; border-radius: 19px; font-size: 15px; line-height: 20px; }
.ui-btn-block { display: flex; width: 100%; }

/* лоадер, не меняющий размер кнопки */
.ui-btn .lbl { transition: opacity .15s ease; }
.ui-btn.is-loading { pointer-events: none; }
.ui-btn.is-loading .lbl { opacity: 0; }
.ui-btn.is-loading::before {
  content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, .3); border-top-color: currentColor;
  animation: ui-btn-spin .7s linear infinite;
}
.ui-btn-tinted.is-loading::before, .ui-btn-gray.is-loading::before {
  border-color: rgba(41, 182, 246, .3); border-top-color: var(--accent);
}
@keyframes ui-btn-spin { to { transform: rotate(360deg); } }

/* ────────────────────────────────────────────────────────────────
   §2.1 Сегмент-контрол со скользящим бегунком (major.bot).
   Совместим с существующими табами market.html:
   <div class="tabs ui-seg" role="tablist">
     <i class="ui-seg-thumb" aria-hidden="true"></i>
     <button class="tab-btn ui-seg-btn" …>
   Позицию бегунка двигает маленький inline-скрипт страницы.
   ──────────────────────────────────────────────────────────────── */
.ui-seg { position: relative; }
.ui-seg-btn {
  position: relative; z-index: 1;
  transition: color .2s ease;
}
.ui-seg-thumb {
  position: absolute; top: 4px; bottom: 4px; left: 0;
  border-radius: 14px;
  background: var(--surface-2);
  box-shadow: var(--shadow-thumb);
  transition: transform .24s ease, width .24s ease;
  will-change: transform, width;
  pointer-events: none;
}
/* автономный сегмент (не поверх .tabs) */
.ui-seg-standalone {
  display: flex; background: rgba(120, 120, 128, .14);
  border-radius: var(--r-m, 18px); padding: 2px;
}
.ui-seg-standalone .ui-seg-btn {
  flex: 1 1 0; height: 44px; padding: 0 10px; border: 0; background: none;
  font-size: 15px; line-height: 20px; font-weight: 600; color: var(--t40);
  border-radius: 16px; cursor: pointer;
}
.ui-seg-standalone .ui-seg-btn.is-active, .ui-seg-standalone .ui-seg-btn.active { color: var(--text); }

/* ────────────────────────────────────────────────────────────────
   §2.2 Карточки-группы iOS (major.bot): r26, ячейки 60px,
   hairline .33px с отступом под иконку. Иконки — пары color/10%.
   ──────────────────────────────────────────────────────────────── */
.ui-group {
  background: var(--surface);
  border: 1px solid var(--stroke-soft);
  border-radius: var(--r-l, 26px);
  padding: 4px 0;
  overflow: hidden;
}
.ui-cell {
  position: relative; display: flex; align-items: center; gap: 12px;
  min-height: 60px; padding: 10px 16px; width: 100%; text-align: left;
  border: 0; background: none; color: inherit; font: inherit;
  transition: background .15s ease;
}
button.ui-cell:active { background: var(--surface); }
.ui-cell + .ui-cell::before {
  content: ""; position: absolute; top: 0; left: 66px; right: 0;
  height: var(--hairline, .33px); background: rgba(255, 255, 255, .10);
}
.ui-cell-ico {
  flex: 0 0 42px; width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
}
.ui-ico-accent { background: var(--accent-10); color: var(--accent); }
.ui-ico-green  { background: var(--green-10);  color: var(--green); }
.ui-ico-amber  { background: var(--amber-10);  color: var(--amber); }
.ui-ico-purple { background: var(--purple-10); color: var(--purple); }
.ui-ico-cyan   { background: var(--cyan-10);   color: var(--cyan); }
.ui-ico-red    { background: var(--red-10);    color: var(--red); }
.ui-cell-title { flex: 1 1 auto; min-width: 0; font-size: 17px; line-height: 22px; }
.ui-cell-title small { display: block; font-size: 13px; line-height: 18px; color: var(--t40); margin-top: 1px; }
.ui-cell-value { font-size: 15px; line-height: 20px; color: var(--t70); font-variant-numeric: tabular-nums; }
.ui-cell-chevron { color: var(--t25); flex: 0 0 auto; }

/* iOS-переключатель */
.ui-switch { position: relative; flex: 0 0 51px; width: 51px; height: 31px; display: inline-block; }
.ui-switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.ui-switch i {
  position: absolute; inset: 0; border-radius: var(--r-pill, 999px);
  background: rgba(120, 120, 128, .32); transition: background .25s ease;
  pointer-events: none;
}
.ui-switch i::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px;
  border-radius: 50%; background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  transition: transform .25s var(--ease-liquid, ease);
}
.ui-switch input:checked + i { background: var(--green); }
.ui-switch input:checked + i::after { transform: translateX(20px); }

/* ────────────────────────────────────────────────────────────────
   §2.3 Bottom-лист (major.bot + portal-market)
   ──────────────────────────────────────────────────────────────── */
.ui-scrim {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0, 0, 0, .55);
  opacity: 0; pointer-events: none; transition: opacity .25s ease;
}
.ui-scrim.open { opacity: 1; pointer-events: auto; }
.ui-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 91;
  background: var(--bg-elev, #14161d);
  border-radius: var(--r-l, 26px) var(--r-l, 26px) 0 0;
  transform: translateY(105%);
  transition: transform .25s var(--ease-liquid, ease);
  max-height: 82vh; overflow: auto;
  padding: 8px 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
  box-shadow: 0 -12px 48px rgba(0, 0, 0, .5);
}
.ui-sheet.open { transform: translateY(0); }
.ui-sheet-grab { width: 36px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .22); margin: 6px auto 14px; }
.ui-sheet-close {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; border: 0;
  background: rgba(118, 118, 128, .16); color: var(--t70);
  transition: transform .15s ease; cursor: pointer;
}
.ui-sheet-close:active { transform: scale(.9); }

/* ────────────────────────────────────────────────────────────────
   §2.4 Скелетоны (major.bot): shimmer
   ──────────────────────────────────────────────────────────────── */
.ui-skel {
  position: relative; overflow: hidden;
  background: rgba(255, 255, 255, .07); border-radius: 8px;
}
.ui-skel::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, .05) 45%, rgba(255, 255, 255, .10) 50%, rgba(255, 255, 255, .05) 55%, transparent 100%);
  animation: ui-skel-shimmer 1.4s ease-out infinite;
}
@keyframes ui-skel-shimmer { to { transform: translateX(100%); } }
.ui-skel-circle { border-radius: 50%; }

/* ────────────────────────────────────────────────────────────────
   §2.5 Бейдж «редкости» (portal-market): скошенный -12°, italic
   uppercase, градиентный текст. Пример:
   <span class="ui-rarity" style="--g:var(--g-legendary)"><b>premium</b></span>
   ──────────────────────────────────────────────────────────────── */
.ui-rarity {
  display: inline-flex; align-items: center;
  transform: skewX(-12deg);
  border: 1px solid var(--stroke);
  border-radius: 6px; padding: 4px 10px 4px 8px;
  background: rgba(0, 0, 0, .22);
}
.ui-rarity b {
  transform: skewX(12deg);
  font-size: 11px; line-height: 13px; font-weight: 800; font-style: italic;
  text-transform: uppercase; letter-spacing: .07em;
  background: var(--g, var(--g-common));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
/* пилюля процента */
.ui-pct {
  display: inline-block; font-size: 11px; line-height: 13px; font-weight: 600;
  color: var(--accent); background: var(--accent-10);
  border-radius: 4px; padding: 2px 5px;
  font-variant-numeric: tabular-nums;
}

/* ────────────────────────────────────────────────────────────────
   Доступность: движение только по явному согласию пользователя
   ──────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .glow-field { animation: none; }
  .ui-skel::after { animation: none; opacity: .6; }
  .ui-seg-thumb { transition: none; }
  .ui-sheet { transition: none; }
  .ui-switch i, .ui-switch i::after { transition: none; }
}

/* iOS WebKit: тяжёлые blur-эффекты гасим (как .orb на index) */
@supports (-webkit-touch-callout: none) {
  .glow-field { display: none; }
}


/* ────────────────────────────────────────────────────────────────
   Сезонный промо-баннер (patent portal-market): один компонент —
   темы через data-theme (default | halloween | fest), aspect 508/136,
   ambient-свет 18s, пилюля-бейдж с наклоном -1°. Пример:
   <a class="ui-banner" data-theme="halloween" href="/market">
     <span class="ui-banner-badge">−20%</span>
     <span class="ui-banner-title">Хэллоуин-сезон</span>
     <span class="ui-banner-sub">магические лоты на маркете</span>
   </a>
   ──────────────────────────────────────────────────────────────── */
.ui-banner {
  position: relative; display: block; overflow: hidden;
  aspect-ratio: 508 / 130; border-radius: 20px;
  padding: 14px 16px; text-decoration: none; color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.10);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.10);
}
.ui-banner[data-theme="default"]    { background: radial-gradient(ellipse at 93% 14%, #246eaa, transparent 64%), #0b2340; }
.ui-banner[data-theme="halloween"]  { background: radial-gradient(ellipse at 83% 45%, rgba(165, 89, 52, 0.30), transparent 65%), linear-gradient(110deg, #1a1721, #36222b); }
.ui-banner[data-theme="fest"]       { background: radial-gradient(ellipse at 94% 25%, rgba(173, 102, 233, 0.55), transparent 58%), linear-gradient(105deg, #39205e, #662e9f 58%, #8d49c7); }
.ui-banner::after {
  content: ""; position: absolute; inset: -40%;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.10), transparent 40%);
  animation: ui-banner-ambient 18s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes ui-banner-ambient {
  0% { transform: translate(-12%, -8%) scale(1); }
  100% { transform: translate(14%, 10%) scale(1.15); }
}
.ui-banner-badge {
  position: absolute; right: 14px; top: 50%;
  transform: translateY(-50%) rotate(-1.5deg);
  font-size: 13px; font-weight: 800; letter-spacing: .02em;
  padding: 6px 11px; border-radius: 999px;
  background: linear-gradient(173deg, #91bdff, #63c7f4 39%, #169cff 88%);
  color: #fff; box-shadow: 0 4px 12px rgba(0, 47, 104, 0.45), inset 0 1px 0 rgba(213, 244, 255, 0.4);
}
.ui-banner[data-theme="halloween"] .ui-banner-badge {
  background: linear-gradient(173deg, #ffb05a, #ff7a3c 60%, #f25a2a);
  box-shadow: 0 4px 12px rgba(90, 30, 0, 0.45), inset 0 1px 0 rgba(255, 224, 190, 0.4);
}
.ui-banner-title { display: block; font-size: 19px; font-weight: 800; letter-spacing: -0.3px; max-width: 72%; }
.ui-banner-sub { display: block; margin-top: 4px; font-size: 12.5px; color: rgba(255, 255, 255, 0.65); max-width: 68%; }
.ui-banner:active { transform: scale(0.985); }
@media (prefers-reduced-motion: reduce) { .ui-banner::after { animation: none; } }