/* ===== Игра «Корона» =====
   Отдельный файл, но подключается вместе с оболочкой страницы: так экран
   имеет финальную геометрию ещё до первого открытия и ничего не прыгает. */

/* --- Превью на вкладке --- */
/* Поле-заглушка с кнопкой «Играть». Сама игра открывается на весь экран,
   поэтому здесь только картинка-приглашение фиксированной пропорции. */
.game-box {
  position: relative;
  margin: 14px 0 18px;
  height: 168px;
  border-radius: 16px;
  overflow: hidden;
  background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  user-select: none;
}
.game-box__logo { width: 54px; height: 54px; opacity: .9; }
.game-box .btn { min-width: 170px; }
.game-box__hint { margin: 0; font-size: 13px; color: var(--text-2); text-align: center; padding: 0 16px; }

/* Заголовок и срок текущего рейтинга стоят в одной строке. */
.game-board__heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.game-board__heading .h3 { margin-right: auto; }
.game-board__ends {
  flex: 0 0 auto;
  min-width: 132px;
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}

/* --- Строка рейтинга --- */
.game-row { display: flex; align-items: center; gap: 9px; min-height: 54px; }
.game-row__place {
  flex-shrink: 0;
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  font-size: 13px; font-weight: 700; color: var(--text-2);
}
.game-row__place--gold,
.game-row__place--silver,
.game-row__place--bronze { border-radius: 50%; }
.game-row__place--gold   { background: #f5c518; color: #3a2c00; }
.game-row__place--silver { background: #c9ccd4; color: #2b2e35; }
.game-row__place--bronze { background: #d69657; color: #3a2100; }
.game-row__avatar {
  position: relative;
  width: 34px; height: 34px; flex: 0 0 34px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--surface-2);
}
.game-row__avatar img {
  position: absolute; inset: 0; z-index: 1;
  width: 100%; height: 100%;
  display: block; object-fit: cover;
}
.game-row__avatar-fallback {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 750;
  color: var(--text-2);
}
.game-row__identity {
  min-width: 0; flex: 1 1 auto;
  display: flex; align-items: center; gap: 6px;
}
.game-row__name {
  min-width: 0; flex: 0 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.game-row__prize {
  flex: 0 0 auto;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 10px; font-weight: 800; line-height: 1;
  letter-spacing: .01em;
}
.game-row__prize--king { color: #6d4d00; background: #ffe48a; }
.game-row__prize--pro { color: #075aa8; background: #d8ebff; }
.game-row__score { margin-left: auto; font-weight: 700; font-size: 14px; color: var(--text); white-space: nowrap; }
/* Спокойные заглушки рейтинга: меняется только прозрачность, геометрия
   полностью совпадает с настоящей строкой и поэтому ничего не сдвигается. */
.game-row--skeleton { pointer-events: none; }
.game-skeleton {
  display: block;
  flex: 0 0 auto;
  background: var(--surface-2);
  animation: game-skeleton-pulse 1.2s ease-in-out infinite alternate;
}
.game-skeleton--place { width: 26px; height: 26px; border-radius: 50%; }
.game-skeleton--avatar { width: 34px; height: 34px; border-radius: 50%; }
.game-skeleton--name { width: 96px; height: 12px; border-radius: 999px; }
.game-skeleton--score { width: 36px; height: 12px; margin-left: auto; border-radius: 999px; }
@keyframes game-skeleton-pulse {
  from { opacity: .55; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .game-skeleton { animation: none; opacity: .75; }
}

/* --- Полноэкранная игра --- */
/* Оверлей во весь экран: на карточке в ленте поле выходило мелким и прыгать
   было неудобно. z-index выше дока (30), чтобы таббар не перекрывал поле. */
.gm {
  position: fixed;
  top: 0; bottom: 0; left: 50%;
  width: 100%; max-width: 430px;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--bg);
  /* В Telegram Desktop окно Mini App бывает очень широким. Оставляем самой
     игре мобильную ширину, а фон по бокам закрываем тем же цветом. */
  box-shadow: 0 0 0 100vmax var(--bg);
  overflow: hidden;
  display: flex; flex-direction: column;
  touch-action: manipulation;   /* тап = прыжок, без задержки двойного тапа */
  user-select: none;
}
/* Пока игра открыта — гасим скролл страницы под ней. */
body.gm-open { overflow: hidden; }

.gm__bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-top, 0px)) 16px 6px;
  flex-shrink: 0;
}
.gm__score { display: inline-flex; align-items: baseline; gap: 10px; font-variant-numeric: tabular-nums; }
.gm__score b { font-size: 22px; font-weight: 800; color: var(--text); }
.gm__best { font-size: 13px; font-weight: 600; color: var(--text-2); }
.gm__close {
  width: 36px; height: 36px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
}
.gm__close:active { opacity: .6; }

/* Канвас занимает всё оставшееся место — отсюда «большое окно» при старте. */
.gm__canvas { flex: 1 1 auto; width: 100%; display: block; }

.gm__hint {
  position: absolute; left: 0; right: 0; bottom: calc(28px + var(--safe-bot, 0px));
  text-align: center; font-size: 14px; color: var(--text-2);
  pointer-events: none;
}

/* Экран «заезд окончен» — по центру поверх поля. */
.gm__over {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(3px);
}
.gm__over-title { font-size: 15px; color: var(--text-2); }
.gm__over-score { font-size: 52px; font-weight: 800; color: var(--text); line-height: 1; font-variant-numeric: tabular-nums; }
.gm__over-rec { font-size: 14px; font-weight: 700; color: var(--accent); }
.gm__over-actions {
  width: min(210px, calc(100% - 48px));
  margin-top: 10px;
  display: grid;
  gap: 8px;
}
.gm__again, .gm__exit { width: 100%; }
.gm__exit {
  background: var(--surface-2);
  color: var(--text);
}

@media (max-width: 360px) {
  .game-box { height: 148px; }
  .gm__over-score { font-size: 44px; }
  .game-row { gap: 7px; }
  .game-row__avatar { width: 32px; height: 32px; flex-basis: 32px; }
  .game-skeleton--avatar { width: 32px; height: 32px; }
  .game-row__prize { padding-inline: 6px; }
}
