/* ═══════════════════════════════════════════════════════════
   LAREK GAMES — базовые стили, каркас, компоненты
   ═══════════════════════════════════════════════════════════ */

/* ── 1. Сброс + запрет «браузерных» жестов ─────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;                 /* скроллит только .screen */
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;        /* нет pull-to-refresh и bounce */
  touch-action: manipulation;       /* убивает зум двойным тапом */
}

body {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;      /* нет меню «Копировать» по долгому тапу */
  -webkit-tap-highlight-color: transparent;
  position: fixed;
  inset: 0;
}

/* Выделение разрешено только там, где оно осмысленно */
input, textarea, [data-selectable] {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

img, svg, canvas { -webkit-user-drag: none; user-drag: none; pointer-events: none; }
button svg, a svg, [data-icon] svg { pointer-events: none; }

button, input, select, textarea {
  font: inherit; color: inherit; background: none; border: 0; outline: none;
  appearance: none; -webkit-appearance: none;
}
button { cursor: pointer; touch-action: manipulation; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

::-webkit-scrollbar { width: 0; height: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── 2. Каркас ─────────────────────────────────────────────── */

.app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
}
.app[hidden] { display: none; }

.screen {
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: var(--sp-4) var(--sp-4) calc(var(--sp-6) + var(--sp-4));
  scroll-behavior: smooth;
}
.screen > * { animation: screen-in var(--t-base) var(--ease-out) both; }

/*
 * Экран во всю площадь — для игр, которые рисуют собственную сцену.
 * Ставится из кода экрана на время его жизни: отступы контейнера и
 * прокрутка мешают такой сцене занять ровно то место, что есть.
 */
.screen.is-fullbleed {
  padding: 0;
  overflow: hidden;
}


@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── 3. Верхняя панель ─────────────────────────────────────── */

/*
 * Панель прижата к правому краю и стала ниже.
 *
 * Раньше её элементы растягивались на всю ширину и занимали слишком
 * много места сверху: на маленьком экране это съедало полосу выше
 * содержимого. Теперь блок компактный, а свободное место уходит влево.
 */
.topbar {
  position: relative;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) var(--sp-3) 0;
  background: linear-gradient(180deg, rgba(12,16,23,.96) 0%, rgba(0,0,0,.86) 100%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--stroke);
}

/* Переключатель языка */
.lang {
  display: flex; align-items: center; gap: 4px;
  height: 30px; padding: 0 8px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--stroke);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .04em;
  color: var(--text-dim);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  flex: 0 0 auto;
}
.lang:active { background: var(--surface-3); }
.lang svg { width: 15px; height: 15px; }

/* Главная синяя кнопка подключения кошелька */
.wallet-btn {
  /* Не растягиваем: панель прижата вправо и должна быть компактной */
  flex: 0 1 auto;
  min-width: 0;
  max-width: 42vw;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  height: 30px; padding: 0 10px;
  border-radius: var(--r-pill);
  background: var(--grad-brand);
  color: var(--text-on-blue);
  font-size: var(--fs-sm); font-weight: 700;
  box-shadow: var(--glow-blue-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.wallet-btn:active { transform: scale(.96); box-shadow: none; }
.wallet-btn svg { width: 16px; height: 16px; flex: 0 0 auto; }
.wallet-btn--connected {
  background: var(--surface-2);
  border: 1px solid var(--stroke-blue);
  color: var(--blue-300);
  box-shadow: none;
}

/* Баланс */
.balance {
  display: flex; align-items: center; gap: 5px;
  height: 34px; padding: 0 11px 0 7px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--stroke);
  font-size: var(--fs-sm); font-weight: 800;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
  transition: background var(--t-fast) var(--ease);
}
.balance:active { background: var(--surface-3); }
.balance__star {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--grad-gold);
  display: grid; place-items: center;
  box-shadow: var(--glow-gold);
}
.balance__star svg { width: 12px; height: 12px; color: #241300; }
.balance.is-bump { animation: bump var(--t-slow) var(--ease-out); }
@keyframes bump {
  0% { transform: none; } 35% { transform: scale(1.14); } 100% { transform: none; }
}

/* Аватар */
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--grad-brand);
  display: grid; place-items: center;
  font-size: var(--fs-sm); font-weight: 800;
  border: 1px solid var(--stroke-2);
  flex: 0 0 auto; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--lg { width: 88px; height: 88px; font-size: 34px; border-width: 2px; }
.avatar--sm { width: 26px; height: 26px; font-size: var(--fs-xs); }

/* ── 4. Нижняя навигация (5 вкладок, «Главная» — третья) ───── */

.tabbar {
  position: relative;
  z-index: var(--z-tabbar);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: linear-gradient(180deg, rgba(12,16,23,.94) 0%, rgba(0,0,0,.98) 100%);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--stroke);
}

.tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: var(--text-mute);
  font-size: 10px; font-weight: 600; letter-spacing: .01em;
  transition: color var(--t-base) var(--ease);
}
.tab svg { width: 23px; height: 23px; transition: transform var(--t-base) var(--ease-out); }
.tab:active svg { transform: scale(.88); }

/* Активная вкладка подсвечивается синим */
.tab.is-active { color: var(--blue-400); }
.tab.is-active svg { filter: drop-shadow(0 0 8px rgba(47,123,255,.7)); }
.tab.is-active::before {
  content: '';
  position: absolute; top: 0; left: 50%;
  width: 30px; height: 2.5px;
  transform: translateX(-50%);
  border-radius: 0 0 3px 3px;
  background: var(--grad-brand);
  box-shadow: var(--glow-blue-sm);
  animation: tab-mark var(--t-base) var(--ease-out) both;
}
@keyframes tab-mark { from { width: 0; opacity: 0; } to { width: 30px; opacity: 1; } }

/* ── 5. Компоненты ─────────────────────────────────────────── */

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: 48px; padding: 0 var(--sp-5);
  border-radius: var(--r-md);
  font-size: var(--fs-body); font-weight: 700;
  transition: transform var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  width: 100%;
}
.btn:active:not(:disabled) { transform: scale(.975); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn svg { width: 18px; height: 18px; }

.btn--primary { background: var(--grad-brand); color: var(--text-on-blue); box-shadow: var(--glow-blue); }
.btn--primary:active:not(:disabled) { box-shadow: var(--glow-blue-sm); }
.btn--ghost   { background: var(--surface-2); color: var(--text); border: 1px solid var(--stroke); }
.btn--outline { background: transparent; color: var(--blue-400); border: 1px solid var(--stroke-blue); }
.btn--gold    { background: var(--grad-gold); color: #241300; box-shadow: var(--glow-gold); }
.btn--danger  { background: rgba(255,77,94,.14); color: var(--danger); border: 1px solid rgba(255,77,94,.3); }
.btn--sm      { height: 38px; padding: 0 var(--sp-4); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn--auto    { width: auto; }

/* Карточки */
.card {
  background: var(--surface-1);
  border: 1px solid var(--stroke);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
}
.card--glow { background: var(--surface-1) var(--grad-surface) no-repeat; border-color: var(--stroke-blue); }
.card--flat { background: var(--surface-2); border-radius: var(--r-md); }

/* Заголовки секций */
.sec { margin: var(--sp-6) 0 var(--sp-3); display: flex; align-items: center; justify-content: space-between; }
.sec:first-child { margin-top: 0; }
.sec__title { font-size: var(--fs-h3); font-weight: 800; letter-spacing: -.01em; }
.sec__link { font-size: var(--fs-sm); font-weight: 600; color: var(--blue-400); }

/* Сегментированный переключатель (Общий / PvP, Звёзды / Подарки) */
.seg {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--stroke);
  border-radius: var(--r-pill);
}
.seg__item {
  flex: 1; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  font-size: var(--fs-sm); font-weight: 700;
  color: var(--text-dim);
  transition: color var(--t-base) var(--ease), background var(--t-base) var(--ease);
}
.seg__item.is-active {
  background: var(--grad-brand);
  color: var(--text-on-blue);
  box-shadow: var(--glow-blue-sm);
}

/* Чипы */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 30px; padding: 0 12px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  border: 1px solid var(--stroke);
  font-size: var(--fs-xs); font-weight: 700;
  color: var(--text-dim);
  transition: all var(--t-fast) var(--ease);
}
.chip.is-active { background: var(--surface-4); border-color: var(--stroke-blue); color: var(--blue-300); }

/* Звезда — валюта */
.star { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; font-variant-numeric: tabular-nums; }
.star svg { width: 13px; height: 13px; color: var(--gold); }
.star--lg svg { width: 18px; height: 18px; }

/* Индикатор редкости */
.rar { --c: var(--rar-common); }
.rar[data-rar="uncommon"] { --c: var(--rar-uncommon); }
.rar[data-rar="rare"]     { --c: var(--rar-rare); }
.rar[data-rar="epic"]     { --c: var(--rar-epic); }
.rar[data-rar="legend"]   { --c: var(--rar-legend); }
.rar[data-rar="mythic"]   { --c: var(--rar-mythic); }

/* Пустое состояние */
.empty { padding: var(--sp-7) var(--sp-4); text-align: center; color: var(--text-mute); }
.empty svg { width: 46px; height: 46px; opacity: .3; margin-bottom: var(--sp-3); }
.empty p { font-size: var(--fs-sm); }

/* Скелетон */
.skel {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 220% 100%;
  animation: skel 1.2s linear infinite;
  border-radius: var(--r-sm);
}
@keyframes skel { from { background-position: 220% 0; } to { background-position: -220% 0; } }

/* ── 6. Загрузчик ──────────────────────────────────────────── */

.boot {
  position: fixed; inset: 0; z-index: var(--z-boot);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-4);
  background: var(--bg);
}
.boot[hidden] { display: none; }
.boot__logo {
  width: 74px; height: 74px; border-radius: 24px;
  background: var(--grad-brand);
  display: grid; place-items: center;
  box-shadow: var(--glow-blue);
  animation: boot-pulse 1.8s var(--ease) infinite;
}
.boot__mark { font-size: 38px; font-weight: 900; color: #fff; }
@keyframes boot-pulse {
  0%,100% { transform: scale(1); box-shadow: var(--glow-blue); }
  50%     { transform: scale(1.05); box-shadow: var(--glow-cyan); }
}
.boot__name { font-size: 15px; font-weight: 800; letter-spacing: .22em; color: var(--text-dim); }
.boot__name span { color: var(--blue-400); }
.boot__bar { width: 130px; height: 3px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.boot__bar i { display: block; height: 100%; width: 40%; border-radius: 3px; background: var(--grad-brand); animation: boot-bar 1.1s var(--ease) infinite; }
@keyframes boot-bar { 0% { transform: translateX(-120%); } 100% { transform: translateX(340%); } }

/* ── 7. Блокировка сессии ──────────────────────────────────── */

.lock {
  position: fixed; inset: 0; z-index: var(--z-lock);
  display: grid; place-items: center;
  padding: var(--sp-5);
  background: rgba(0,0,0,.9);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.lock[hidden] { display: none; }
.lock__card {
  width: 100%; max-width: 330px;
  background: var(--surface-1);
  border: 1px solid var(--stroke-2);
  border-radius: var(--r-xl);
  padding: var(--sp-6) var(--sp-5);
  text-align: center;
  box-shadow: var(--sh-3);
}
.lock__icon {
  width: 62px; height: 62px; margin: 0 auto var(--sp-4);
  border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(47,123,255,.12);
  border: 1px solid var(--stroke-blue);
  color: var(--blue-400);
}
.lock__card h2 { font-size: var(--fs-h2); font-weight: 800; margin-bottom: var(--sp-2); }
.lock__card p  { font-size: var(--fs-sm); color: var(--text-dim); margin-bottom: var(--sp-5); }

/* ── 8. Модалки / шторки ───────────────────────────────────── */

.layer { position: fixed; inset: 0; z-index: var(--z-layer); pointer-events: none; }
.layer:empty { display: none; }

.sheet-bg {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.66);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  pointer-events: auto;
  animation: fade-in var(--t-base) var(--ease) both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88%;
  display: flex; flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--stroke-2);
  border-bottom: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-5) + var(--safe-bottom));
  pointer-events: auto;
  box-shadow: var(--sh-3);
  animation: sheet-in var(--t-slow) var(--ease-out) both;
}
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
.sheet.is-out { animation: sheet-out var(--t-base) var(--ease) both; }
@keyframes sheet-out { to { transform: translateY(100%); } }
.sheet__grip { width: 38px; height: 4px; border-radius: 4px; background: var(--surface-4); margin: 0 auto var(--sp-4); flex: 0 0 auto; }
.sheet__title { font-size: var(--fs-h2); font-weight: 800; margin-bottom: var(--sp-4); flex: 0 0 auto; }
.sheet__body { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

/* ── 9. Тосты ──────────────────────────────────────────────── */

.toasts {
  position: fixed; z-index: var(--z-toast);
  left: 0; right: 0; top: calc(var(--safe-top) + var(--topbar-h) + 8px);
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  padding: 0 var(--sp-4);
  pointer-events: none;
}
.toast {
  max-width: 100%;
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 11px 16px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  border: 1px solid var(--stroke-2);
  box-shadow: var(--sh-2);
  font-size: var(--fs-sm); font-weight: 600;
  animation: toast-in var(--t-base) var(--ease-out) both;
}
.toast.is-out { animation: toast-out var(--t-base) var(--ease) both; }
.toast svg { width: 16px; height: 16px; flex: 0 0 auto; }
.toast--ok    { border-color: rgba(36,201,138,.4); color: var(--ok); }
.toast--err   { border-color: rgba(255,77,94,.4); color: var(--danger); }
.toast--info  { border-color: var(--stroke-blue); color: var(--blue-300); }
@keyframes toast-in  { from { opacity: 0; transform: translateY(-14px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(-10px) scale(.96); } }

/* ── 10. Слой частиц ───────────────────────────────────────── */

.fx { position: fixed; inset: 0; z-index: var(--z-toast); pointer-events: none; }

/* ── Розыгрыши: действия и карточки истории ───────────────── */

.gw-actions {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: var(--sp-3);
  margin: var(--sp-3) 0 var(--sp-2);
}
.gw-actions .btn { gap: var(--sp-2); }

.gw-mine {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.gw-mine__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}
.gw-mine .btn { width: 100%; margin-top: var(--sp-3); }

/* ── Плинко ───────────────────────────────────────────────── */

.pk {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.pk__scene { width: 100%; display: block; }

.pk__peg { fill: var(--text-mute); opacity: .5; }

.pk__ball {
  fill: #fff;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, .8));
}

.pk__slot rect { fill: var(--surface-2); stroke: var(--line); stroke-width: .6; }
.pk__slot text {
  fill: var(--text);
  text-anchor: middle;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.pk__slot.is-cold rect { fill: #14324f; }
.pk__slot.is-warm rect { fill: #1d4f6b; }
.pk__slot.is-hot  rect { fill: #8a3b12; }
.pk__slot.is-hit  rect {
  stroke: var(--accent, #2F7BFF);
  stroke-width: 2;
  animation: pk-pop .45s var(--ease);
}

@keyframes pk-pop {
  0%   { transform: translateY(0); }
  35%  { transform: translateY(3px); }
  100% { transform: translateY(0); }
}

.pk__hist {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-top: var(--sp-2);
  min-height: 24px;
  scrollbar-width: none;
}
.pk__hist::-webkit-scrollbar { display: none; }

.pk__chip {
  flex: none;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--line);
}
.pk__chip.is-win { color: #24C98A; border-color: rgba(36, 201, 138, .5); }

/* ── Кейсы: бесплатный, лента открытия ────────────────────── */

.free-case {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.free-case__art { font-size: 40px; line-height: 1; flex: none; }
.free-case__body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.free-case__body b { font-size: var(--fs-body); }
.free-case__body span { font-size: var(--fs-sm); color: var(--text-dim); }
.free-case__tickets { color: var(--accent, #2F7BFF) !important; font-weight: 600; }
.free-case .btn { flex: none; width: auto; padding: 10px 18px; }

.reel {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  margin-bottom: var(--sp-4);
  padding: var(--sp-3) 0;
}
.reel__mark {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  transform: translateX(-50%);
  background: var(--grad-brand, #2F7BFF);
  box-shadow: 0 0 12px rgba(47, 123, 255, .8);
  z-index: 2;
}
.reel__strip { display: flex; gap: 8px; will-change: transform; }

.reel-card {
  flex: 0 0 76px;
  height: 88px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.reel-card__art { font-size: 30px; line-height: 1; }
.reel-card__val { font-size: 10px; }
.reel-card.is-win { border-color: var(--accent, #2F7BFF); }

/* Нулевая лунка в центре: явно «мимо», а не просто холодный цвет */
.pk__slot.is-zero rect { fill: #2a2f38; stroke: #3a414d; }
.pk__slot.is-zero text { fill: var(--text-mute); }

/* Отсчёт до розыгрыша: моноширинные цифры не «прыгают» каждую секунду */
.gw__time {
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.gw__time.is-soon { color: #FF4D5E; font-weight: 700; }

/* Прокрут колеса розыгрыша: длиннее, чем в PvP — 15 секунд */
.gw-wheel.is-spinning .pvp-wheel__svg {
  transition: transform 15s var(--ease-spin);
}
