/* Цвета берутся из темы Telegram (--tg-theme-*), снаружи Telegram — запасные значения */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f7);
  --text: var(--tg-theme-text-color, #111318);
  --hint: var(--tg-theme-hint-color, #8a8f9c);
  --link: var(--tg-theme-link-color, #2b7cff);
  --btn: var(--tg-theme-button-color, #2b7cff);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-section-bg-color, var(--bg));
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --danger: #e5484d;
  --ok: #2bb673;
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #101216; --bg2: #181b21; --text: #f1f2f5; --hint: #8a909c; --card: #1c2027;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: Manrope, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg2);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input { font: inherit; }

#app { padding-bottom: calc(76px + var(--safe-bottom)); min-height: 100vh; }

.loader { display: grid; place-items: center; height: 80vh; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--sep); border-top-color: var(--btn);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.view { animation: viewIn .28s ease both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Каталог ---------- */
.hero {
  position: relative; overflow: hidden;
  margin: 12px 16px 0; padding: 22px 20px 20px;
  border-radius: 24px;
  color: #fff;
  background: radial-gradient(120% 140% at 0% 0%, #7a5cfa 0%, #3d5afe 45%, #0b1b4d 100%);
}
.hero h1 { max-width: 250px; margin: 0 0 6px; font-size: 24px; line-height: 1.15; font-weight: 800; letter-spacing: -.02em; }
.hero p { margin: 0; opacity: .85; font-size: 14px; max-width: 240px; }
.hero .floaters { position: absolute; right: -6px; top: 8px; font-size: 34px; }
.hero .floaters span { position: absolute; animation: float 4s ease-in-out infinite; }
.hero .floaters span:nth-child(1) { right: 18px; top: 4px; }
.hero .floaters span:nth-child(2) { right: 70px; top: 46px; font-size: 26px; animation-delay: -1.3s; }
.hero .floaters span:nth-child(3) { right: 14px; top: 78px; font-size: 30px; animation-delay: -2.6s; }
@keyframes float { 50% { transform: translateY(-8px) rotate(6deg); } }

.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 14px 16px 6px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 8px 14px; border-radius: 999px;
  background: var(--card); font-weight: 600; font-size: 14px;
  transition: background .2s, color .2s, transform .1s;
}
.chip:active { transform: scale(.96); }
.chip.active { background: var(--btn); color: var(--btn-text); }

.section-title { margin: 14px 16px 10px; font-size: 13px; font-weight: 700; color: var(--hint); text-transform: uppercase; letter-spacing: .06em; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 0 16px; }
.card {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  text-align: left; display: flex; flex-direction: column;
  animation: viewIn .35s ease both;
  transition: transform .15s;
}
.card:active { transform: scale(.97); }
.cover {
  --accent: #3d5afe;
  position: relative; aspect-ratio: 1 / .82; display: grid; place-items: center;
  background:
    radial-gradient(80% 80% at 80% 10%, color-mix(in srgb, var(--accent) 40%, #fff) 0%, transparent 60%),
    linear-gradient(150deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #000));
  overflow: hidden;
}
.cover .emoji { font-size: 52px; filter: drop-shadow(0 6px 12px rgba(0,0,0,.25)); animation: float 5s ease-in-out infinite; }
.cover::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,.06) 0 2px, transparent 2px 14px);
}
.tag {
  position: absolute; z-index: 1; top: 8px; left: 8px;
  padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700;
  background: rgba(0,0,0,.35); color: #fff; backdrop-filter: blur(6px);
}
.tag.sale { left: auto; right: 8px; background: #ffd23f; color: #222; }
.tag.owned { background: var(--ok); }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card .title { font-weight: 700; font-size: 14px; line-height: 1.25; }
.card .sub { color: var(--hint); font-size: 12px; line-height: 1.3; flex: 1; }
.price { display: flex; align-items: baseline; gap: 6px; margin-top: 4px; }
.price b { font-size: 16px; font-weight: 800; }
.price s { color: var(--hint); font-size: 12px; }

.empty { text-align: center; color: var(--hint); padding: 48px 24px; }
.empty .big { font-size: 48px; margin-bottom: 8px; }

/* ---------- Карточка товара ---------- */
.product-cover { aspect-ratio: auto; height: 210px; border-radius: 0 0 28px 28px; }
.product-cover .emoji { font-size: 84px; }
.product { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.product h2 { margin: 0; font-size: 22px; line-height: 1.2; font-weight: 800; letter-spacing: -.01em; }
.product .lead { color: var(--hint); margin: 4px 0 0; }
.panel { background: var(--card); border-radius: var(--radius); padding: 14px 16px; }
.panel h3 { margin: 0 0 8px; font-size: 15px; }
.features { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.features li { display: flex; gap: 10px; }
.features li::before { content: "✓"; color: var(--ok); font-weight: 800; }

.preview-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.link-btn { color: var(--link); font-weight: 600; font-size: 14px; }
.phone {
  position: relative; height: 380px; border-radius: 22px; overflow: hidden;
  border: 6px solid #111; background: #000;
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.phone iframe { width: 100%; height: 100%; border: 0; background: #fff; }

/* ---------- Корзина / заказы ---------- */
.page-title { margin: 18px 16px 12px; font-size: 24px; font-weight: 800; }
.list { margin: 0 16px; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.row + .row { border-top: 1px solid var(--sep); }
.thumb {
  --accent: #3d5afe; flex: none; width: 46px; height: 46px; border-radius: 12px;
  display: grid; place-items: center; font-size: 24px;
  background: linear-gradient(150deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #000));
}
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 700; font-size: 14px; }
.row .meta { color: var(--hint); font-size: 13px; }
.icon-btn { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--bg2); color: var(--hint); }
.small-btn { padding: 7px 12px; border-radius: 10px; background: color-mix(in srgb, var(--btn) 14%, transparent); color: var(--btn); font-weight: 700; font-size: 13px; }

.field { margin: 16px; }
.field label { display: block; font-size: 13px; color: var(--hint); margin: 0 0 6px 4px; }
.field input {
  width: 100%; padding: 13px 14px; border-radius: 14px; border: 2px solid transparent;
  background: var(--card); color: var(--text); outline: none; transition: border-color .2s;
}
.field input:focus { border-color: var(--btn); }
.field .hint { font-size: 12px; color: var(--hint); margin: 6px 4px 0; }

.summary { margin: 0 16px; display: flex; justify-content: space-between; font-weight: 800; font-size: 17px; }

.order { margin: 0 16px 12px; }
.order-head { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 6px; font-size: 13px; color: var(--hint); }
.status { padding: 2px 8px; border-radius: 999px; font-weight: 700; font-size: 11px; }
.status.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.status.wait { background: color-mix(in srgb, #f5a623 20%, transparent); color: #c98200; }

/* ---------- Нижняя кнопка действия ---------- */
.action-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg2) 85%, transparent);
  backdrop-filter: blur(12px);
}
.main-btn {
  width: 100%; padding: 15px; border-radius: 14px;
  background: var(--btn); color: var(--btn-text);
  font-weight: 800; font-size: 16px;
  transition: transform .1s, opacity .2s;
}
.main-btn:active { transform: scale(.98); }
.main-btn:disabled { opacity: .55; }
.main-btn.secondary { background: color-mix(in srgb, var(--btn) 14%, transparent); color: var(--btn); }
.has-action #app { padding-bottom: calc(90px + var(--safe-bottom)); }
.has-action .tabbar { display: none; }

/* ---------- Таббар ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--sep);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px; font-size: 11px; font-weight: 600; color: var(--hint); }
.tabbar button.active { color: var(--btn); }
.tabbar .ti { position: relative; font-size: 22px; line-height: 1; transition: transform .2s; }
.tabbar button.active .ti { transform: translateY(-2px); }
.badge {
  position: absolute; top: -4px; right: -10px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 800;
  display: grid; place-items: center; font-style: normal;
}
.badge.pop { animation: pop .35s ease; }
@keyframes pop { 40% { transform: scale(1.4); } }

.web-back {
  position: fixed; top: 12px; left: 12px; z-index: 30;
  padding: 7px 12px; border-radius: 999px; font-weight: 700; font-size: 14px;
  background: rgba(0,0,0,.45); color: #fff; backdrop-filter: blur(8px);
}

/* ---------- Демо на весь экран ---------- */
.demo-full { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; animation: viewIn .25s ease; }
.demo-full-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 10px 16px; font-weight: 700; border-bottom: 1px solid var(--sep); }
.demo-full iframe { flex: 1; border: 0; width: 100%; background: #fff; }

/* ---------- Тост ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); z-index: 60;
  transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 14px;
  background: rgba(20, 22, 28, .92); color: #fff; font-weight: 600; font-size: 14px; text-align: center;
  animation: viewIn .25s ease;
}

/* ---------- Успешная оплата ---------- */
.success { text-align: center; padding: 48px 24px 16px; }
.success .big { font-size: 72px; animation: pop .6s ease; }
.success h2 { margin: 8px 0; font-size: 24px; }
.success p { color: var(--hint); margin: 0 auto; max-width: 300px; }
.stub-note {
  margin: 16px; padding: 12px 14px; border-radius: 14px; font-size: 13px;
  background: color-mix(in srgb, #f5a623 16%, transparent); color: color-mix(in srgb, #c98200 80%, var(--text));
}
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
