/* Хаб мини-приложения. Цвета берутся из Telegram.WebApp.themeParams (hub.js
   переписывает переменные ниже), здесь только запасные значения.
   Скругления: карточки 16px, кнопки 12px, чипы и переключатели полностью круглые. */
:root {
  --bg: #f1f2f5;
  --surface: #ffffff;
  --text: #16181d;
  --hint: #6b7280;
  --link: #2a7de1;
  --btn: #2a7de1;
  --btn-text: #ffffff;
  --line: rgba(22, 24, 29, .09);
  --danger: #d93a3a;
  --coin: #b7791f;
  --rare: #2f6fe0;
  --legendary: #c58209;
  --shade: rgba(20, 24, 33, .08);
  --tabs-h: 64px;
  --ease: cubic-bezier(.16, 1, .3, 1);
}
:root[data-scheme="dark"] {
  --bg: #121418;
  --surface: #1c1f25;
  --text: #eef0f3;
  --hint: #9aa1ad;
  --link: #5aa2ff;
  --btn: #3d8bfd;
  --btn-text: #ffffff;
  --line: rgba(238, 240, 243, .08);
  --danger: #ff6b6b;
  --coin: #f2bb4a;
  --rare: #6ea2ff;
  --legendary: #f5b937;
  --shade: rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--btn); outline-offset: 2px; }
[hidden] { display: none !important; }

#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- верхняя полоса ---------- */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.bar h1 { margin: 0; font-size: 24px; line-height: 1.2; font-weight: 750; letter-spacing: -.02em; }
.wallet {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px 6px 10px; border-radius: 999px;
  background: var(--surface); box-shadow: 0 1px 2px var(--shade);
  font-weight: 700; font-variant-numeric: tabular-nums;
}
.wallet.bump { animation: bump .5s var(--ease); }
@keyframes bump { 40% { transform: scale(1.14); } }

main { flex: 1; padding: 4px 16px calc(var(--tabs-h) + 28px + env(safe-area-inset-bottom)); outline: none; }
.view-in { animation: viewIn .35s var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } }

/* ---------- нижняя навигация ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  min-height: var(--tabs-h);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabs button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; border-radius: 12px; color: var(--hint); font-size: 16px; font-weight: 600;
  transition: color .2s, transform .15s;
}
.tabs button span { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .7; transition: filter .2s, opacity .2s, transform .3s var(--ease); }
.tabs button[aria-current="page"] { color: var(--btn); }
.tabs button[aria-current="page"] span { filter: none; opacity: 1; transform: translateY(-1px) scale(1.08); }
.tabs button:active { transform: scale(.94); }

/* ---------- общее ---------- */
.section-h { margin: 28px 0 12px; font-size: 20px; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
.section-h:first-child { margin-top: 12px; }
.hint { color: var(--hint); }
.card { background: var(--surface); border-radius: 16px; box-shadow: 0 1px 2px var(--shade); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  background: var(--btn); color: var(--btn-text); font-weight: 650; white-space: nowrap;
  transition: transform .15s var(--ease), opacity .2s, background .2s;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; }
.btn.ghost { background: color-mix(in srgb, var(--btn) 13%, transparent); color: var(--btn); }
.btn.plain { background: color-mix(in srgb, var(--text) 7%, transparent); color: var(--hint); }
.btn.confirm { background: var(--coin); color: #1b1404; }
.btn.wide { width: 100%; min-height: 50px; font-size: 17px; }
.num { font-variant-numeric: tabular-nums; }
.boost { color: var(--coin); }

/* ---------- игры ---------- */
.games { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 8px; }
.game {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 16px 14px 14px; text-align: left; min-height: 172px;
  transition: transform .18s var(--ease), box-shadow .2s;
}
.game:active { transform: scale(.97); }
.game .ico {
  display: grid; place-items: center; width: 52px; height: 52px; border-radius: 14px;
  font-size: 30px; background: color-mix(in srgb, var(--btn) 11%, transparent);
}
.game .t { font-size: 18px; font-weight: 700; line-height: 1.25; }
.game .d { color: var(--hint); font-size: 16px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.game .best { margin-top: auto; font-weight: 650; font-variant-numeric: tabular-nums; }
.game .best.none { color: var(--hint); font-weight: 500; }
.game.loading { opacity: .6; pointer-events: none; }
.game.loading .ico { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.9); } }

/* ---------- профиль ---------- */
.me { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; padding: 18px 16px; margin-top: 8px; }
.avatar {
  position: relative; width: 76px; height: 76px; border-radius: 50%;
  display: grid; place-items: center; font-size: 30px; font-weight: 750; color: #fff;
  background: linear-gradient(140deg, var(--btn), color-mix(in srgb, var(--btn) 55%, #000));
  box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--frame, transparent);
}
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar .badge {
  position: absolute; right: -6px; bottom: -6px; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; font-size: 18px; background: var(--surface); box-shadow: 0 1px 3px var(--shade);
}
.me .name { font-size: 22px; font-weight: 750; line-height: 1.2; word-break: break-word; }
.me .title-chip { display: inline-block; margin-top: 6px; padding: 2px 10px; border-radius: 999px; font-weight: 650; background: color-mix(in srgb, var(--legendary) 16%, transparent); color: var(--legendary); }
.me .title-chip.none { background: color-mix(in srgb, var(--text) 6%, transparent); color: var(--hint); font-weight: 500; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.stat { padding: 14px 16px; }
.stat .v { font-size: 24px; font-weight: 750; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .k { color: var(--hint); }
.stat.boosted { grid-column: span 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: color-mix(in srgb, var(--coin) 14%, var(--surface)); }
.stat.boosted .v { color: var(--coin); }

.daily { margin-top: 12px; padding: 18px 16px; display: grid; gap: 14px; position: relative; overflow: hidden; }
.daily .drow { display: flex; align-items: center; gap: 14px; }
.daily .big { font-size: 36px; line-height: 1; }
.daily .t { font-size: 18px; font-weight: 700; }
.streak { display: flex; gap: 6px; }
.streak i { flex: 1; height: 8px; border-radius: 999px; background: color-mix(in srgb, var(--text) 9%, transparent); }
.streak i.on { background: var(--coin); }
.streak i.gift { background: color-mix(in srgb, var(--rare) 35%, transparent); }
.streak i.gift.on { background: var(--rare); }

.chests { padding: 4px 0; }
.chest { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px 14px; }
.chest + .chest { border-top: 1px solid var(--line); }
.chest .e { font-size: 36px; line-height: 1; text-align: center; }
.chest .n { display: block; font-weight: 650; }
.chest .c { color: var(--hint); font-variant-numeric: tabular-nums; }
.chest .btn { min-height: 40px; padding: 0 16px; }
.chest.empty .e { filter: grayscale(1); opacity: .45; }
.chest.rare .n { color: var(--rare); }
.chest.legendary .n { color: var(--legendary); }

.quest { margin-top: 12px; padding: 18px 16px; display: grid; gap: 10px; border: 1px dashed color-mix(in srgb, var(--legendary) 55%, transparent); background: color-mix(in srgb, var(--legendary) 7%, var(--surface)); }
.quest .t { font-size: 18px; font-weight: 700; }

/* ---------- магазин ---------- */
.seg {
  display: flex; gap: 4px; padding: 4px; border-radius: 999px; margin-top: 8px;
  background: color-mix(in srgb, var(--text) 7%, transparent);
  overflow-x: auto; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: 1 0 auto; min-height: 40px; padding: 0 14px; border-radius: 999px; font-weight: 600; color: var(--hint); transition: background .2s, color .2s; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px var(--shade); }
.sticky-seg { position: sticky; top: 60px; z-index: 5; padding-bottom: 4px; background: var(--bg); }

.items { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.item { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.item .pv { height: 84px; border-radius: 12px; display: grid; place-items: center; background: color-mix(in srgb, var(--text) 5%, transparent); }
.item .nm { font-weight: 650; line-height: 1.3; }
.item .rar { color: var(--hint); }
.item.rare .rar { color: var(--rare); }
.item.legendary .rar { color: var(--legendary); }
.item .btn { margin-top: auto; width: 100%; padding: 0 8px; }
/* легендарный скин игры: третий в группе, во всю ширину, чтобы не оставлять пустую ячейку */
.item.wide { grid-column: span 2; display: grid; grid-template-columns: 132px minmax(0, 1fr); grid-template-rows: auto 1fr; column-gap: 14px; }
.item.wide .pv { grid-row: span 2; height: 100%; min-height: 96px; }
.item.wide .chest-only, .item.wide .btn { place-items: center start; text-align: left; }
.item.equipped { box-shadow: 0 0 0 2px var(--btn); }
.chest-only { margin-top: auto; min-height: 44px; display: grid; place-items: center; text-align: center; color: var(--legendary); font-weight: 600; line-height: 1.25; }

.swatch { width: 100%; height: 100%; border-radius: 12px; position: relative; overflow: hidden; }
.swatch .p { position: absolute; left: 18%; top: 22%; width: 38%; aspect-ratio: 1; border-radius: 50%; }
.swatch .a { position: absolute; right: 14%; bottom: 18%; width: 34%; height: 18%; border-radius: 999px; }
.ring { width: 56px; height: 56px; border-radius: 50%; border: 5px solid; background: var(--surface); }
.pv .emo { font-size: 42px; }
.pv .ttl { padding: 4px 12px; border-radius: 999px; font-weight: 700; background: color-mix(in srgb, var(--legendary) 16%, transparent); color: var(--legendary); }

/* ---------- рейтинг ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; margin: 8px -16px 0; padding: 2px 16px 4px; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: 0 0 auto; scroll-snap-align: start; min-height: 40px; padding: 0 14px; border-radius: 999px;
  background: var(--surface); box-shadow: 0 1px 2px var(--shade); font-weight: 600; white-space: nowrap;
}
.chips button[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); }
.scope { margin-top: 12px; }
.board { margin-top: 12px; padding: 4px 0; }
.row {
  display: grid; grid-template-columns: 36px auto minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 10px 14px; min-height: 60px;
}
.row + .row { border-top: 1px solid var(--line); }
.row .pl { text-align: center; font-weight: 700; color: var(--hint); font-variant-numeric: tabular-nums; }
.row .pl.medal { font-size: 24px; }
.row .av { position: relative; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: color-mix(in srgb, var(--btn) 70%, #000); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--frame, transparent); }
.row .av .badge { position: absolute; right: -6px; bottom: -6px; font-size: 16px; line-height: 1; }
.row .who { min-width: 0; }
.row .who b { display: block; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .who span { color: var(--hint); }
.row .sc { font-weight: 750; font-variant-numeric: tabular-nums; }
.row.me { background: color-mix(in srgb, var(--btn) 12%, transparent); border-radius: 12px; }
.row.me + .row, .row + .row.me { border-top-color: transparent; }
.mine { position: sticky; bottom: calc(var(--tabs-h) + 12px + env(safe-area-inset-bottom)); margin-top: 12px; box-shadow: 0 6px 24px var(--shade); }

/* ---------- состояния ---------- */
.empty-state { padding: 32px 20px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.empty-state .e { font-size: 44px; }
.empty-state .t { font-size: 18px; font-weight: 700; }
.sk { border-radius: 16px; background: linear-gradient(90deg, var(--surface) 0%, color-mix(in srgb, var(--surface) 60%, var(--bg)) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.gate { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 12px; padding: 24px 16px; text-align: center; }
.gate .e { font-size: 56px; }
.gate h2 { margin: 0; font-size: 24px; }
.gate p { margin: 0; color: var(--hint); max-width: 30ch; }

/* ---------- тост ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); z-index: 40;
  margin: 0 auto; max-width: 420px; padding: 12px 16px; border-radius: 14px;
  background: color-mix(in srgb, var(--text) 92%, transparent); color: var(--bg); font-weight: 600; text-align: center;
  opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .25s, transform .35s var(--ease);
}
.toast.show { opacity: 1; transform: none; }

/* ---------- монеты летят в кошелёк ---------- */
.fly { position: fixed; z-index: 50; font-size: 24px; pointer-events: none; will-change: transform, opacity; }

/* ---------- окно сундука ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: end center;
  background: rgba(8, 10, 14, .55); animation: fade .25s;
}
@keyframes fade { from { opacity: 0; } }
.sheet-body {
  width: 100%; max-width: 480px; padding: 28px 20px calc(20px + env(safe-area-inset-bottom));
  border-radius: 24px 24px 0 0; background: var(--surface);
  display: grid; justify-items: center; gap: 12px; text-align: center;
  animation: up .4s var(--ease);
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.box { position: relative; font-size: 92px; line-height: 1; height: 120px; display: grid; place-items: center; }
.box.shake { animation: shake .9s ease-in-out; }
@keyframes shake {
  10%, 50%, 90% { transform: rotate(-8deg) scale(1.02); }
  30%, 70% { transform: rotate(8deg) scale(1.04); }
  100% { transform: scale(1.18); }
}
.box.pop { animation: pop .35s var(--ease) forwards; }
@keyframes pop { to { transform: scale(1.6); opacity: 0; } }
.burst { position: absolute; inset: 0; border-radius: 50%; background: radial-gradient(circle, var(--glow, var(--coin)) 0%, transparent 65%); opacity: 0; transform: scale(.4); }
.burst.go { animation: burst .7s var(--ease) forwards; }
@keyframes burst { 30% { opacity: .9; } to { opacity: 0; transform: scale(2.4); } }
.reveal { width: 100%; display: grid; justify-items: center; gap: 8px; animation: reveal .5s var(--ease); }
@keyframes reveal { from { opacity: 0; transform: scale(.85) translateY(10px); } }
.reveal .pv { width: 140px; height: 110px; border-radius: 16px; display: grid; place-items: center; background: color-mix(in srgb, var(--text) 5%, transparent); }
.reveal .rar { font-weight: 700; }
.reveal .rar.common { color: var(--hint); }
.reveal .rar.rare { color: var(--rare); }
.reveal .rar.legendary { color: var(--legendary); }
.reveal .nm { font-size: 22px; font-weight: 750; }
.sheet-actions { width: 100%; display: grid; gap: 8px; margin-top: 8px; }

@media (min-width: 560px) {
  main { max-width: 640px; margin: 0 auto; width: 100%; }
  .bar { max-width: 640px; margin: 0 auto; width: 100%; }
  .games, .items { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .item.wide { grid-column: auto; display: flex; }
  .item.wide .pv { height: 84px; min-height: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
