/* GramSnake — интерфейс поверх WebGL-сцены. Тема (data-theme на <html>) следует Telegram colorScheme. */

/* ---------- Экран «Open in Telegram» (первым: должен работать при любом состоянии остального CSS) ---------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #0b0c0f;
  color: #ffffff;
}

.gate[hidden] {
  display: none !important;
}

.gate__text {
  margin: 0;
  color: #ffffff;
  font: 600 19px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0.01em;
  text-align: center;
}

/* ---------- Токены ---------- */

:root {
  color-scheme: light;

  /* Общие переменные (CONTRACT) */
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #ecebe5;
  --ink: #17181c;
  --ink-soft: #6c6f78;
  --line: rgba(23, 24, 28, 0.08);
  --accent: #1fa463;
  --accent-ink: #ffffff;
  --good: #15955a;
  --bad: #e0464e;
  --radius-card: 28px;
  --radius-chip: 999px;
  --shadow-card: 0 1px 2px rgba(23, 24, 28, 0.04), 0 12px 30px rgba(23, 24, 28, 0.07);
  --nav-h: calc(var(--safe-b) + 92px);

  /* Навигация и капсулы */
  --nav-bg: rgba(255, 255, 255, 0.92);
  --nav-active: #17181c;
  --nav-active-ink: #ffffff;
  --chip-bg: #ffffff;
  --coin-bg: #ffd45c;
  --coin-ink: #5a3d00;

  /* Внутренние (HUD, результат, уведомления) */
  --stage-bg: #e8ecf2;
  --surface-3: #e2e1da;
  --text: var(--ink);
  --text-2: var(--ink-soft);
  --text-3: #9b9ea6;
  --border: var(--line);
  --border-strong: rgba(23, 24, 28, 0.16);
  --accent-hover: #1a925a;
  --accent-soft: rgba(31, 164, 99, 0.12);
  --accent-fill: rgba(31, 164, 99, 0.24);
  --on-accent: var(--accent-ink);
  --danger: var(--bad);
  --danger-soft: rgba(224, 70, 78, 0.11);
  --warn: #b0700a;
  --warn-soft: rgba(220, 150, 20, 0.15);

  --hud-bg: rgba(255, 255, 255, 0.84);
  --hud-border: rgba(23, 24, 28, 0.07);
  --scrim: rgba(236, 235, 229, 0.72);
  --toast-bg: #17181c;
  --toast-text: #f6f5f1;
  --label-text: #1a2130;
  --label-halo: rgba(255, 255, 255, 0.85);
  --joy-base: rgba(15, 20, 32, 0.1);
  --joy-knob: rgba(15, 20, 32, 0.34);
  --map-fill: rgba(15, 20, 32, 0.05);
  --map-ring: rgba(15, 20, 32, 0.3);
  --map-view: rgba(15, 20, 32, 0.22);
  --map-self-ring: #ffffff;

  --shadow-hud: 0 4px 18px rgba(23, 24, 28, 0.08);
  --shadow-pop: 0 22px 60px rgba(23, 24, 28, 0.2);
  --shadow-nav: 0 10px 30px rgba(23, 24, 28, 0.14), 0 2px 6px rgba(23, 24, 28, 0.06);

  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 24px;
  --t-fast: 0.15s;
  --t-theme: 0.3s;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --boost-size: 78px;
  --map-size: 148px;
  --col-w: 520px;

  /* Отступы от вырезов экрана: системные (env) или от Telegram (telegram.js) */
  --safe-t: max(env(safe-area-inset-top, 0px), var(--tg-safe-top, 0px));
  --safe-r: max(env(safe-area-inset-right, 0px), var(--tg-safe-right, 0px));
  --safe-b: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-bottom, 0px));
  --safe-l: max(env(safe-area-inset-left, 0px), var(--tg-safe-left, 0px));

  --font: system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #111215;
  --surface: #1c1d22;
  --surface-2: #26272d;
  --ink: #f3f2ee;
  --ink-soft: #9d9fa8;
  --line: rgba(255, 255, 255, 0.07);
  --accent: #3dd68c;
  --accent-ink: #06170e;
  --good: #3dd68c;
  --bad: #ff6b72;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 14px 34px rgba(0, 0, 0, 0.32);

  --nav-bg: rgba(32, 33, 39, 0.94);
  --nav-active: #f3f2ee;
  --nav-active-ink: #111215;
  --chip-bg: #1f2025;
  --coin-bg: #f2c443;
  --coin-ink: #3d2900;

  --stage-bg: #0d1118;
  --surface-3: #303139;
  --text-3: #6f727c;
  --border-strong: rgba(255, 255, 255, 0.15);
  --accent-hover: #5fe0a2;
  --accent-soft: rgba(61, 214, 140, 0.13);
  --accent-fill: rgba(61, 214, 140, 0.26);
  --danger-soft: rgba(255, 107, 114, 0.14);
  --warn: #f0b23e;
  --warn-soft: rgba(240, 178, 62, 0.15);

  --hud-bg: rgba(24, 25, 30, 0.76);
  --hud-border: rgba(255, 255, 255, 0.08);
  --scrim: rgba(8, 9, 11, 0.7);
  --toast-bg: #f3f2ee;
  --toast-text: #121316;
  --label-text: #f1f4f9;
  --label-halo: rgba(0, 0, 0, 0.7);
  --joy-base: rgba(255, 255, 255, 0.1);
  --joy-knob: rgba(255, 255, 255, 0.4);
  --map-fill: rgba(255, 255, 255, 0.05);
  --map-ring: rgba(255, 255, 255, 0.34);
  --map-view: rgba(255, 255, 255, 0.24);
  --map-self-ring: #0b0e14;

  --shadow-hud: 0 4px 18px rgba(0, 0, 0, 0.3);
  --shadow-pop: 0 22px 60px rgba(0, 0, 0, 0.55);
  --shadow-nav: 0 12px 34px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
}

/* ---------- Основа ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
p,
dl,
dd,
ol,
ul {
  margin: 0;
  padding: 0;
}

ol,
ul {
  list-style: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

input {
  user-select: text;
  -webkit-user-select: text;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.unit {
  font-size: 0.5em;
  font-weight: 650;
  letter-spacing: 0.04em;
  color: var(--text-2);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* Иконки из спрайта index.html (HUD, результат). Иконки ui/icons.js задают размер и обводку атрибутами сами. */
svg.icon:not([viewBox]) {
  width: 1.15em;
  height: 1.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon {
  flex: none;
}

.icon--gram {
  color: var(--accent);
}

.logo-bg {
  fill: var(--accent);
}

.logo-body {
  fill: none;
  stroke: var(--on-accent);
  stroke-width: 3.6;
  stroke-linecap: round;
}

.logo-head {
  fill: var(--on-accent);
}

.logo-eye {
  fill: var(--accent);
}

/* На время смены темы цвета всех элементов переезжают плавно (класс ставит ui/theme.js). */
.theme-anim,
.theme-anim *,
.theme-anim *::before,
.theme-anim *::after {
  transition: background-color var(--t-theme) ease, color var(--t-theme) ease, border-color var(--t-theme) ease,
    fill var(--t-theme) ease, stroke var(--t-theme) ease, box-shadow var(--t-theme) ease !important;
}

/* ---------- Каркас ---------- */

.app {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

@supports (height: 100dvh) {
  .app {
    height: var(--tg-vh, 100dvh);
  }
}

.stage {
  position: absolute;
  inset: 0;
  background: var(--stage-bg);
  touch-action: none;
  overflow: hidden;
}

.stage__canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}

.labels,
.touch {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

/* ---------- Общие элементы ---------- */

.card,
.soft-card {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.panel {
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-hud);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
}

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: var(--radius-chip);
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
  transition: background-color var(--t-fast) ease, transform var(--t-fast) ease, opacity var(--t-fast) ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--nav-active);
  color: var(--nav-active-ink);
}

.btn--soft {
  background: var(--surface-2);
  color: var(--ink);
}

.btn--ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--ink);
}

@media (hover: hover) {
  .btn--primary:hover:not(:disabled) {
    opacity: 0.9;
  }

  .btn--soft:hover:not(:disabled),
  .btn--ghost:hover:not(:disabled) {
    background: var(--surface-3);
  }
}

.btn .spinner,
.pill-btn .spinner,
.arena-card__play .spinner {
  display: none;
}

.btn.is-busy .spinner,
.pill-btn.is-busy .spinner,
.arena-card__play.is-busy .spinner {
  display: inline-block;
}

.btn.is-busy .btn__label {
  opacity: 0.65;
}

.btn.is-busy:disabled {
  opacity: 0.8;
}

.spinner {
  display: inline-block;
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
}

/* ---------- Аватар (ui/avatar.js) ---------- */

.avatar {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
}

.avatar-face {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  color: #ffffff;
}

.avatar-initials {
  font-weight: 750;
  line-height: 1;
  letter-spacing: 0.01em;
}

.avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.avatar-face.has-photo .avatar-img {
  opacity: 1;
}

.avatar-face.has-photo .avatar-initials {
  visibility: hidden;
}

.avatar-ring {
  position: absolute;
  inset: 0;
  overflow: visible;
}

.avatar-ring-track {
  stroke: var(--surface-2);
}

.avatar-ring-bar {
  stroke: var(--accent);
  transition: stroke-dasharray 0.6s var(--ease-out);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 17px;
  transition: background-color var(--t-fast) ease;
}

.icon-btn--bare {
  width: 32px;
  height: 32px;
  border-color: transparent;
  background: transparent;
  color: inherit;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.3;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge--muted {
  background: var(--surface-2);
  color: var(--text-2);
}

.input {
  width: 100%;
  min-width: 0;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  /* 16px — иначе iOS увеличивает страницу при фокусе. */
  font-size: 16px;
  transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}

.input::placeholder {
  color: var(--text-3);
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chip {
  min-width: 44px;
  height: 46px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  transition: background-color var(--t-fast) ease;
}

/* ---------- Главное меню: каркас ---------- */

.shell {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  max-width: calc(var(--col-w) + var(--safe-l) + var(--safe-r));
  margin: 0 auto;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 16px) 10px calc(var(--safe-l) + 16px);
}

.capsule {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  height: 48px;
  border: 0;
  border-radius: var(--radius-chip);
  background: var(--chip-bg);
  color: var(--ink);
  transition: transform var(--t-fast) ease, background-color var(--t-fast) ease;
}

.capsule:active {
  transform: scale(0.97);
}

.profile-chip {
  flex: 0 1 auto;
  gap: 9px;
  padding: 0 16px 0 7px;
  text-align: left;
}

.profile-chip__avatar {
  display: grid;
  flex: none;
}

.profile-chip__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
}

.profile-chip__name {
  overflow: hidden;
  line-height: 1.2;
  max-width: 100%;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.005em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wallet-chip {
  flex: none;
  gap: 8px;
  padding: 0 8px 0 16px;
}

.wallet-chip__logo {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
}

.wallet-chip__value {
  display: inline-block;
  font-size: 16.5px;
  font-weight: 780;
  letter-spacing: -0.01em;
}

.wallet-chip__value[data-size="m"] {
  font-size: 15px;
}

.wallet-chip__value[data-size="s"] {
  font-size: 13.5px;
}

.wallet-chip__value.is-bump {
  animation: bump 0.45s var(--ease-out);
}

@keyframes bump {
  0% {
    transform: scale(1.14);
    color: var(--accent);
  }
}

.screens {
  position: relative;
  flex: 1;
  min-height: 0;
}

.screen {
  position: absolute;
  inset: 0;
  overflow-x: hidden;
  overflow-y: auto;
  /* По бокам — колонка не шире --col-w по центру (планшет, Telegram Desktop), но не меньше 16 px отступа. */
  padding: 6px max(calc(var(--safe-r) + 16px), calc((100% - var(--col-w)) / 2)) calc(var(--nav-h) + 12px)
    max(calc(var(--safe-l) + 16px), calc((100% - var(--col-w)) / 2));
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  /* Содержимое мягко уходит под шапку, а не обрезается по линейке. */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 12px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 12px);
}

.screen::-webkit-scrollbar {
  display: none;
}

.screen.is-entering {
  animation: screen-in 0.26s var(--ease-out);
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 18vh;
  color: var(--ink-soft);
  font-size: 15px;
  text-align: center;
}

/* ---------- Нижняя навигация ---------- */

.tabbar {
  position: absolute;
  bottom: calc(var(--safe-b) + 14px);
  left: 50%;
  z-index: 3;
  display: flex;
  width: min(calc(100% - 32px - var(--safe-l) - var(--safe-r)), 380px);
  height: 66px;
  padding: 7px;
  border-radius: var(--radius-chip);
  background: var(--nav-bg);
  box-shadow: var(--shadow-nav);
  transform: translateX(-50%);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
}

.tabbar__indicator {
  position: absolute;
  top: 7px;
  bottom: 7px;
  left: 0;
  width: 0;
  border-radius: var(--radius-chip);
  background: var(--nav-active);
  /* Положение ставит ui/shell.js каждый кадр, пока кнопки меняют ширину. */
  will-change: transform, width;
}

.tabbar__btn {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-chip);
  background: transparent;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 700;
  transition: color 0.25s ease, flex-grow 0.38s var(--ease-out);
}

/* Активная кнопка шире: в капсуле помещаются иконка и подпись. */
.tabbar__btn.is-active {
  flex-grow: 1.75;
  color: var(--nav-active-ink);
}

.tabbar__icon {
  display: grid;
  flex: none;
  transition: transform 0.25s var(--ease-out);
}

.tabbar__btn:active .tabbar__icon {
  transform: scale(0.88);
}

.tabbar__label {
  overflow: hidden;
  max-width: 0;
  opacity: 0;
  white-space: nowrap;
  transition: max-width 0.3s var(--ease-out), opacity 0.2s ease;
}

.tabbar__btn.is-active .tabbar__label {
  max-width: 120px;
  opacity: 1;
}

@media (hover: hover) {
  .tabbar__btn:not(.is-active):hover {
    color: var(--ink);
  }
}

/* Кошелёк (ui/wallet.js) рисует свой лист поверх меню. */
.wallet-root {
  position: relative;
  z-index: 40;
}

/* ---------- Главная ---------- */

.home-head {
  padding: 8px 4px 16px;
}

.home-head__title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.1;
}

.home-head__sub {
  margin-top: 6px;
  color: var(--ink-soft);
  font-size: 14.5px;
  line-height: 1.4;
  text-wrap: pretty;
}

.notice {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px 12px 12px 14px;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  font-size: 14px;
}

.notice__icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-2);
}

.notice__text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.notice__text strong {
  font-size: 15px;
  font-weight: 750;
}

.notice__text span {
  color: var(--ink-soft);
}

@media (max-width: 479.98px) {
  .notice--accent {
    flex-wrap: wrap;
  }

  .notice--accent .pill-btn {
    flex: 1 1 100%;
    justify-content: center;
    height: 46px;
  }
}

.notice--accent .notice__icon {
  background: var(--accent-soft);
  color: var(--accent);
}

.notice--muted {
  color: var(--ink-soft);
}

.notice--warn .notice__icon {
  background: var(--warn-soft);
  color: var(--warn);
}

.notice--warn .notice__text {
  font-weight: 650;
}

.pill-btn {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-chip);
  background: var(--nav-active);
  color: var(--nav-active-ink);
  font-size: 14px;
  font-weight: 700;
  transition: transform var(--t-fast) ease, opacity var(--t-fast) ease;
}

.pill-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.pill-btn:disabled {
  opacity: 0.55;
}

/* ---------- Карточки арен ---------- */

.arena-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.arena-card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 318px;
  padding: 22px 22px 0;
  border-radius: var(--radius-card);
  background: radial-gradient(120% 90% at 100% 100%, var(--card-bg-deep, #ddd) 0%, transparent 62%), var(--card-bg, var(--surface));
  color: var(--card-ink, var(--ink));
}

/* Карточки плоские: без теней. В тёмной теме графитовая карточка отделяется от фона тонкой рамкой. */
:root[data-theme="dark"] .arena-card {
  outline: 1px solid rgba(255, 255, 255, 0.07);
  outline-offset: -1px;
}

.arena-card--skeleton {
  background: var(--surface);
  animation: skeleton 1.4s ease-in-out infinite alternate;
}

@keyframes skeleton {
  to {
    opacity: 0.55;
  }
}

.arena-card__art {
  position: absolute;
  right: -6px;
  bottom: -4px;
  left: 0;
  z-index: -1;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  height: 58%;
  pointer-events: none;
}

.arena-card__art > svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Ставка: текст строго по центру капсулы — по горизонтали и вертикали (фиксированная высота, line-height 1). */
.arena-card__badge {
  position: absolute;
  top: 18px;
  right: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  height: 32px;
  padding: 0 14px;
  border-radius: 16px;
  background: var(--card-badge-bg, var(--surface));
  color: var(--card-badge-ink, var(--ink));
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
  white-space: nowrap;
}

.arena-card__body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 78%;
}

.arena-card__title {
  padding-right: 6px;
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 850;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.arena-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.arena-card__stat {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 10px 0 8px;
  border-radius: var(--radius-chip);
  background: color-mix(in srgb, var(--card-ink, #000) 9%, transparent);
  color: var(--card-ink, var(--ink));
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1;
}

.arena-card__row {
  display: flex;
  flex-direction: column;   /* подпись — всегда под кнопкой, а не рядом: справа от кнопки начинается иллюстрация */
  align-items: flex-start;
  gap: 8px;
  margin-top: 16px;
}

.arena-card__play {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 50px;
  padding: 0 6px 0 22px;
  border: 0;
  line-height: 1;
  border-radius: var(--radius-chip);
  background: var(--card-btn-bg, var(--nav-active));
  color: var(--card-btn-ink, var(--nav-active-ink));
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.005em;
  transition: transform var(--t-fast) ease, opacity var(--t-fast) ease;
}

.arena-card__play:active:not(:disabled) {
  transform: scale(0.96);
}

.arena-card__play:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.arena-card__play.is-busy:disabled {
  opacity: 0.85;
}

.arena-card__play-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--card-btn-ink, #fff);
  color: var(--card-btn-bg, #000);
}

.arena-card__tag {
  padding: 5px 11px;
  border-radius: var(--radius-chip);
  background: color-mix(in srgb, var(--card-bg, #fff) 70%, #ffffff);
  color: var(--card-ink, var(--ink));
  font-size: 12.5px;
  font-weight: 700;
}

.arena-card.is-full .arena-card__tag {
  background: color-mix(in srgb, var(--bad) 16%, var(--card-bg, #fff));
}

@media (hover: hover) {
  .arena-card__play:hover:not(:disabled) {
    opacity: 0.92;
  }
}

/* ---------- Узкие и широкие экраны ---------- */

@media (max-width: 359.98px) {
  .topbar {
    gap: 8px;
    padding-right: calc(var(--safe-r) + 12px);
    padding-left: calc(var(--safe-l) + 12px);
  }

  .screen {
    padding-right: calc(var(--safe-r) + 12px);
    padding-left: calc(var(--safe-l) + 12px);
  }

  .profile-chip {
    padding-right: 12px;
  }

  .wallet-chip {
    padding-left: 12px;
  }

  .arena-card {
    min-height: 300px;
    padding: 18px 18px 0;
  }

  .arena-card__title {
    font-size: 24px;
  }

  .arena-card__body {
    max-width: 84%;
  }
}

@media (min-width: 600px) {
  .topbar {
    padding-top: calc(var(--safe-t) + 18px);
  }

  .arena-card {
    min-height: 340px;
    padding: 26px 26px 0;
  }

  .arena-card__title {
    font-size: 30px;
  }

  .arena-card__body {
    max-width: 66%;
  }
}

/* Телефон в альбомной ориентации: высоты мало. */
@media (orientation: landscape) and (max-height: 520px) {
  .arena-card {
    min-height: 260px;
  }

  .tabbar {
    bottom: calc(var(--safe-b) + 8px);
    height: 58px;
  }

  :root {
    --nav-h: calc(var(--safe-b) + 76px);
  }
}

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hud__live {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "tl conn tr"
    ".  .    . "
    ".  cash . ";
  gap: 8px;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 12px);
}

.hud-tl {
  display: flex;
  grid-area: tl;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  align-self: start;
  justify-self: start;
  min-width: 0;
}

.hud-balance {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 8px 14px 9px 12px;
}

.hud-balance__label {
  color: var(--text-2);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hud-balance__row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 23px;
  font-weight: 760;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.hud-balance__row .icon {
  width: 0.8em;
  height: 0.8em;
}

.hud-balance.is-up .hud-balance__value {
  animation: balance-up 0.45s ease;
}

@keyframes balance-up {
  0% {
    color: var(--accent);
    transform: scale(1.07);
  }

  100% {
    color: inherit;
    transform: none;
  }
}

.hud-balance__value {
  display: inline-block;
  transform-origin: left center;
}

.hud-net {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 4px;
  color: var(--label-text);
  font-size: 11.5px;
  font-weight: 600;
  text-shadow: 0 0 4px var(--label-halo), 0 0 2px var(--label-halo);
}

.hud-net__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
}

.hud-net__dot.is-good {
  background: var(--accent);
}

.hud-net__dot.is-ok {
  background: var(--warn);
}

.hud-net__dot.is-bad {
  background: var(--danger);
}

.hud-net__sep {
  opacity: 0.6;
}

.hud-tr {
  display: flex;
  grid-area: tr;
  flex-direction: row-reverse;
  align-items: flex-start;
  gap: 8px;
  align-self: start;
  justify-self: end;
  min-width: 0;
}

.hud-board {
  width: 218px;
  padding: 9px 12px 8px;
  font-size: 12.5px;
}

.hud-board__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  color: var(--text-2);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hud-board__players {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  letter-spacing: 0;
}

.hud-board__players .icon {
  width: 12px;
  height: 12px;
}

.board-row {
  display: grid;
  grid-template-columns: 1.4em minmax(0, 1fr) auto;
  gap: 6px;
  align-items: baseline;
  padding: 2.5px 0;
  line-height: 1.3;
}

.board-row__rank {
  color: var(--text-3);
  font-weight: 650;
}

.board-row__name {
  overflow: hidden;
  font-weight: 550;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-row__bal {
  font-weight: 650;
}

.board-row.is-own .board-row__rank,
.board-row.is-own .board-row__name,
.board-row.is-own .board-row__bal {
  color: var(--accent);
  font-weight: 750;
}

.board-row--own {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed var(--border-strong);
}

/* Карта лежит в левой колонке (так она встаёт под баланс на телефоне), а на экране с мышью
   выносится в правый нижний угол: .hud-tl не позиционирован, отсчёт идёт от .hud__live. */
.hud-map {
  position: absolute;
  right: calc(var(--safe-r) + 12px);
  bottom: calc(var(--safe-b) + 12px);
  width: var(--map-size);
  height: var(--map-size);
  padding: 5px;
  border-radius: 50%;
}

.minimap {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.hud-conn {
  display: flex;
  grid-area: conn;
  align-items: center;
  gap: 9px;
  align-self: start;
  justify-self: center;
  max-width: 100%;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--warn);
  color: #ffffff;
  font-size: 13px;
  font-weight: 650;
  box-shadow: var(--shadow-hud);
}

:root[data-theme="dark"] .hud-conn {
  color: #1b1403;
}

.hud-conn .spinner {
  width: 14px;
  height: 14px;
}

.hud-conn__warn {
  display: none;
}

.hud-conn.is-offline {
  background: var(--danger);
}

.hud-conn.is-offline .spinner {
  display: none;
}

.hud-conn.is-offline .hud-conn__warn {
  display: block;
}

.hud-cashout {
  grid-area: cash;
  align-self: end;
  justify-self: center;
}

.cashout-btn {
  position: relative;
  display: block;
  min-width: 232px;
  height: 54px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--hud-border);
  border-radius: 16px;
  background: var(--hud-bg);
  color: var(--text);
  box-shadow: var(--shadow-hud);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  pointer-events: auto;
  touch-action: none;
  transition: transform var(--t-fast) ease, border-color var(--t-fast) ease;
}

.cashout-btn.is-pressed,
.cashout-btn.is-charging {
  border-color: var(--accent);
}

.cashout-btn.is-pressed {
  transform: scale(0.97);
}

.cashout-btn__fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, var(--accent) 0, var(--accent) 4px, var(--accent-fill) 4px);
  transform: scaleX(0);
  transform-origin: left center;
  /* Прогресс приходит раз в тик (25 Гц) — короткий переход сглаживает ступеньки. */
  transition: transform 0.08s linear;
}

.cashout-btn__content {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  height: 100%;
  padding: 0 12px 0 16px;
}

.cashout-btn__content > .icon {
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.cashout-btn__text {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  line-height: 1.2;
}

.cashout-btn__label {
  font-size: 15px;
  font-weight: 720;
}

.cashout-btn__hint {
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 550;
  white-space: nowrap;
}

.cashout-btn__key {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 8px;
  background: var(--surface);
  font: 700 13px/1 var(--font);
}

/* Узкое окно с мышью: кнопке вывода и карте не хватает нижнего ряда на троих. */
@media (max-width: 640px) {
  :root {
    --map-size: 104px;
  }

  .hud__live {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "tl   tr  "
      "conn conn"
      ".    .   "
      "cash .   ";
  }

  .hud-cashout {
    justify-self: start;
  }

  .cashout-btn {
    min-width: 0;
  }

  .hud-board {
    width: min(46vw, 184px);
    padding: 8px 10px 7px;
    font-size: 12px;
  }

  .hud-balance__row {
    font-size: 20px;
  }
}

/* Сенсорная раскладка (класс ставит модуль ввода): нижний правый угол отдан большому пальцу,
   мини-карта уезжает наверх под баланс. */
html.is-touch {
  --map-size: 96px;
}

html.is-touch .hud__live {
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas:
    "tl   tr  "
    "conn conn"
    ".    .   "
    ".    cash";
}

html.is-touch .hud-tr {
  flex-direction: column;
  align-items: flex-end;
}

html.is-touch .hud-map {
  position: static;
}

html.is-touch .hud-cashout {
  justify-self: end;
  margin-bottom: calc(var(--boost-size) + 22px);
}

html.is-touch .cashout-btn {
  min-width: 0;
  height: 50px;
}

html.is-touch .cashout-btn__key {
  display: none;
}

html.is-touch .cashout-btn__content {
  padding-right: 16px;
}

@media (orientation: landscape) and (max-height: 540px) {
  html.is-touch {
    --map-size: 84px;
    --boost-size: 72px;
  }

  html.is-touch .hud__live {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "tl  conn tr  "
      ".   .    .   "
      ".   .    cash";
  }

  html.is-touch .hud-cashout {
    margin-right: calc(var(--boost-size) + 18px);
    margin-bottom: 22px;
  }

  .hud-board {
    width: 190px;
    padding: 7px 10px 6px;
    font-size: 11.5px;
  }

  .board-row {
    padding: 1.5px 0;
  }

  .hud-balance__row {
    font-size: 20px;
  }
}

/* ---------- Сенсорные элементы ---------- */

.joystick {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  will-change: transform;
}

.joystick__base,
.joystick__knob {
  position: absolute;
  border-radius: 50%;
}

.joystick__base {
  top: -60px;
  left: -60px;
  width: 120px;
  height: 120px;
  border: 1.5px solid var(--joy-knob);
  background: var(--joy-base);
}

.joystick__knob {
  top: -27px;
  left: -27px;
  width: 54px;
  height: 54px;
  background: var(--joy-knob);
  will-change: transform;
}

.boost-btn {
  position: absolute;
  right: calc(var(--safe-r) + 18px);
  bottom: calc(var(--safe-b) + 22px);
  display: grid;
  place-items: center;
  width: var(--boost-size);
  height: var(--boost-size);
  padding: 0;
  border: 1.5px solid var(--hud-border);
  border-radius: 50%;
  background: var(--hud-bg);
  color: var(--accent);
  font-size: 30px;
  box-shadow: var(--shadow-hud);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  pointer-events: auto;
  touch-action: none;
  transition: transform var(--t-fast) ease, background-color var(--t-fast) ease, color var(--t-fast) ease;
}

.boost-btn.is-pressed {
  background: var(--accent);
  color: var(--on-accent);
  transform: scale(0.94);
}

/* ---------- Подписи имён ---------- */

.name-label {
  position: absolute;
  top: 0;
  left: 0;
  max-width: 170px;
  overflow: hidden;
  color: var(--label-text);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.2;
  text-overflow: ellipsis;
  text-shadow: 0 0 3px var(--label-halo), 0 0 6px var(--label-halo);
  white-space: nowrap;
  will-change: transform;
}

.name-label.is-off {
  opacity: 0.45;
}

/* ---------- Экраны результата ---------- */

.result {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 16px) calc(var(--safe-l) + 16px);
  overflow-y: auto;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  pointer-events: auto;
  animation: fade-in 0.25s ease;
}

.result:focus {
  outline: none;
}

.result__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(100%, 400px);
  padding: 30px 22px 20px;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  text-align: center;
  animation: pop-in 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.result__icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 14px;
  border-radius: 50%;
  font-size: 28px;
}

.result__icon .icon {
  stroke-width: 2.4;
}

.result__icon--dead {
  background: var(--danger-soft);
  color: var(--danger);
}

.result__icon--cashed {
  background: var(--accent-soft);
  color: var(--accent);
}

.result__title {
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 820;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.result__sub {
  margin-top: 6px;
  color: var(--text-2);
  font-size: 14.5px;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.result__hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  margin-top: 18px;
  padding: 16px 12px;
  border-radius: 22px;
  background: var(--surface-2);
}

.result__hero-label {
  color: var(--text-2);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.result__hero-value {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 2px 8px;
  max-width: 100%;
  font-size: clamp(26px, 8vw, 34px);
  font-weight: 780;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.result__hero-value .icon {
  align-self: center;
  width: 0.76em;
  height: 0.76em;
}

.result__hero-value .num {
  min-width: 0;
  overflow-wrap: anywhere;
}

.result__hero--cashed {
  background: var(--accent-soft);
}

.result__hero--cashed .result__hero-value > .num {
  color: var(--accent);
}

.result__hero--dead .icon--gram {
  color: var(--text-3);
}

.result__rows {
  width: 100%;
  margin-top: 6px;
}

.result__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px;
  font-size: 14.5px;
}

.result__row + .result__row {
  border-top: 1px solid var(--border);
}

.result__row dt {
  color: var(--text-2);
  text-align: left;
}

.result__row dd {
  font-weight: 650;
}

.result__error {
  width: 100%;
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 600;
}

.result__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 18px;
}

.result__actions .btn {
  width: 100%;
  white-space: normal;
}

@media (max-height: 460px) {
  .result__card {
    padding: 16px 20px 14px;
  }

  .result__icon {
    display: none;
  }

  .result__hero {
    margin-top: 10px;
    padding: 8px 12px;
  }

  .result__row {
    padding: 6px 2px;
  }

  .result__card {
    width: min(100%, 480px);
  }

  .result__actions {
    flex-direction: row;
    margin-top: 12px;
  }

  .result__actions .btn--primary {
    flex: 1.7;
  }

  .result__actions .btn--ghost {
    flex: 1;
  }
}

/* ---------- Загрузка, заглушка, уведомления ---------- */

.boot,
.fatal {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 16px) calc(var(--safe-l) + 16px);
  background: var(--bg);
  color: var(--text-2);
}

.boot {
  z-index: 20;
}

.boot__mark {
  width: 64px;
  height: 64px;
}

.fatal__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 420px;
  padding: 30px 24px;
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  color: var(--text);
  text-align: center;
}

.fatal__card .brand__mark {
  width: 48px;
  height: 48px;
}

.fatal__title {
  font-size: 21px;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.fatal__text {
  color: var(--text-2);
  text-wrap: pretty;
}
.fatal__card .btn {
  min-width: 180px;
  margin-top: 4px;
}
.fatal__hint {
  min-height: 1.4em;
  font-size: 13px;
}

.toasts {
  position: absolute;
  /* В игре hud.js опускает уведомления под верхние панели HUD (--toast-top). */
  top: var(--toast-top, calc(var(--safe-t) + 64px));
  left: 50%;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100% - 32px);
  pointer-events: none;
  transform: translateX(-50%);
}

.toast {
  max-width: 100%;
  padding: 11px 18px;
  border-radius: 22px;
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-pop);
  text-align: center;
  animation: pop-in 0.25s ease;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast--error {
  background: var(--danger);
  color: #ffffff;
}

:root[data-theme="dark"] .toast--error {
  color: #2a0509;
}

.toast--success {
  background: var(--accent);
  color: var(--on-accent);
}

/* В меню уведомления — над плавающей панелью навигации, в игре — под верхними панелями HUD. */
.shell:not([hidden]) ~ .toasts {
  top: auto;
  bottom: calc(var(--nav-h) + 6px);
}

.shell:not([hidden]) ~ .toasts .toast.is-leaving {
  transform: translateY(6px);
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(-6px);
}

/* ---------- Меньше движения ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .theme-anim,
  .theme-anim *,
  .theme-anim *::before,
  .theme-anim *::after {
    transition: none !important;
  }

  .result,
  .result__card,
  .toast,
  .hud-balance.is-up .hud-balance__value,
  .arena-card--skeleton,
  .screen.is-entering,
  .wallet-chip__value.is-bump {
    animation: none;
  }

  .spinner {
    animation-duration: 1.6s;
  }

  .btn:active:not(:disabled),
  .cashout-btn.is-pressed,
  .boost-btn.is-pressed {
    transform: none;
  }
}
