/* Палитра снята с присланного видео: насыщенный индиго-фон, тёмная
   панель поля, кубики со скошенными гранями. Счёт вынесен крупно под
   шапку — в этом жанре он главный элемент экрана, а не служебная цифра
   в углу. */
:root {
  --bg-top:    #5B6CDA;
  --bg-bottom: #3F4CA8;
  --panel:     #262A55;
  --edge:      #3A3F7A;
  --text:      #FFFFFF;
  --hint:      #A9B2E8;
  --gold:      #FFC93C;
  --cta:       #FF6B4A;
  --spring:    cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  touch-action: none;      /* иначе перетаскивание фигуры листает страницу */
  user-select: none;
}

/* --- шапка ------------------------------------------------------------ */

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px calc(2px + env(safe-area-inset-top, 0px));
}

.crown {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 19px;
  font-weight: 800;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.spacer { margin-left: auto; }

.chip {
  padding: 8px 12px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s var(--spring);
}
.chip:active { transform: scale(.93); }

/* --- счёт -------------------------------------------------------------- */

.score-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 58px;
}

#score {
  position: relative;
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .22);
}

/* Счёт подпрыгивает на каждом начислении — это и есть та обратная связь,
   из-за отсутствия которой казалось, что за ход ничего не дают. */
#score.bump { animation: bump .28s var(--spring); }
@keyframes bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.16); }
  100% { transform: scale(1); }
}

/* Вспышка за счётом: включается на очистке и гаснет сама. */
.burst {
  position: absolute;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: radial-gradient(circle, #7FE9FF 0%, rgba(127, 233, 255, 0) 70%);
  transform: rotate(45deg) scale(.4);
  opacity: 0;
  pointer-events: none;
}
.burst.on { animation: burst .5s ease-out; }
@keyframes burst {
  0%   { opacity: .9; transform: rotate(45deg) scale(.4); }
  100% { opacity: 0;  transform: rotate(45deg) scale(1.5); }
}

.combo-badge {
  position: absolute;
  right: 16px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--gold);
  color: #4A3200;
  font-size: 13px;
  font-weight: 800;
  animation: pop .35s var(--spring);
}
.combo-badge[hidden] { display: none; }
@keyframes pop { from { transform: scale(1.4); } }

/* --- страницы и навигация --------------------------------------------- */

main { height: calc(100% - 52px - 58px - 62px); overflow: hidden; }

.page { display: none; height: 100%; }
/* Поле квадратное и упирается в ширину экрана, поэтому по высоте почти
   всегда остаётся запас. Центрируем, иначе игра прижимается к верху и
   под ней зияет пустота. */
.page.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.page.scroll.active { justify-content: flex-start; }
.page.scroll { overflow-y: auto; touch-action: pan-y; }

canvas { display: block; }

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  background: rgba(23, 27, 62, .94);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 4px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--hint);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s var(--spring), color .15s, background .15s;
}
.tab .ico { font-size: 19px; line-height: 1; }
.tab.active { color: #fff; background: rgba(255, 255, 255, .14); }
.tab:active { transform: scale(.94); }

/* --- карточки и кнопки ------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(15, 18, 50, .74);
  backdrop-filter: blur(8px);
  z-index: 20;
}
.overlay[hidden] { display: none; }

.card {
  width: 100%;
  max-width: 340px;
  padding: 28px 22px 22px;
  border: 1px solid var(--edge);
  border-radius: 24px;
  background: linear-gradient(180deg, #2E3468, var(--panel));
  box-shadow: 0 22px 55px rgba(0, 0, 0, .55);
  text-align: center;
  animation: rise .3s var(--spring);
}
@keyframes rise { from { transform: translateY(16px) scale(.95); opacity: 0; } }

.card h1 { margin: 0 0 6px; font-size: 25px; }
.card p  { margin: 0 0 20px; color: var(--hint); font-size: 14px; }

.ov-stats { display: flex; justify-content: space-between; margin: 0 0 20px; }
.ov-stats div { display: flex; flex-direction: column; gap: 3px; }
.ov-stats span { font-size: 10px; letter-spacing: .07em; text-transform: uppercase; color: var(--hint); }
.ov-stats strong { font-size: 20px; font-variant-numeric: tabular-nums; }

button.primary {
  width: 100%;
  padding: 15px;
  border: 0;
  border-radius: 15px;
  background: linear-gradient(180deg, #FF8A6B, var(--cta));
  box-shadow: 0 4px 0 #C63D22;
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .1s var(--spring), box-shadow .1s;
}
button.primary:active { transform: translateY(4px); box-shadow: 0 0 0 #C63D22; }
button.primary:disabled { opacity: .5; }

button.ghost {
  width: 100%;
  margin-top: 9px;
  padding: 12px;
  border: 1px solid var(--edge);
  border-radius: 13px;
  background: transparent;
  color: var(--hint);
  font-size: 14px;
  cursor: pointer;
}
button.ghost[hidden] { display: none; }

/* --- списки: топ и дуэли ---------------------------------------------- */

.panel {
  width: 100%;
  max-width: 420px;
  margin: 10px 0;
  padding: 14px;
  border: 1px solid var(--edge);
  border-radius: 20px;
  background: rgba(31, 35, 73, .78);
}

.panel h2 { margin: 0 0 4px; font-size: 18px; }
.panel .sub { margin: 0 0 12px; color: var(--hint); font-size: 13px; }

.rows { margin: 0; padding: 0; list-style: none; }

.row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 11px;
  border-radius: 12px;
  font-size: 14px;
}
.row + .row { margin-top: 4px; }
.row:nth-child(odd) { background: rgba(255, 255, 255, .06); }
.row.me { background: rgba(255, 201, 60, .2); outline: 1px solid var(--gold); }

.row .place { min-width: 24px; font-weight: 800; color: var(--hint); font-variant-numeric: tabular-nums; }
.row.gold   .place { color: var(--gold); }
.row.silver .place { color: #D8DEF5; }
.row.bronze .place { color: #FF9E5E; }

.row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .pts  { font-weight: 800; font-variant-numeric: tabular-nums; }

.empty { padding: 26px 16px; text-align: center; color: var(--hint); font-size: 14px; }

/* --- дуэли ------------------------------------------------------------- */

.stakes { display: flex; gap: 8px; margin: 4px 0 12px; }

.stake {
  flex: 1;
  padding: 12px 6px;
  border: 1px solid var(--edge);
  border-radius: 13px;
  background: rgba(255, 255, 255, .06);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}
.stake.active { background: var(--gold); border-color: var(--gold); color: #4A3200; }

.duel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .06);
  font-size: 14px;
}
.duel + .duel { margin-top: 6px; }
.duel .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.duel .tag { padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.duel .tag.win  { background: rgba(75, 201, 75, .25); color: #8CE88C; }
.duel .tag.lose { background: rgba(240, 85, 78, .25); color: #FF9E97; }
.duel .tag.draw { background: rgba(255, 255, 255, .14); color: var(--hint); }
.duel .tag.wait { background: rgba(255, 201, 60, .22); color: var(--gold); }

/* --- профиль ----------------------------------------------------------- */

.wallet {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 201, 60, .12);
}
.wallet-sum { font-size: 30px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 12px;
  margin-bottom: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .06);
  font-size: 14px;
  cursor: pointer;
}

/* Нативный чекбокс подменяется ползунком: системный на тёмном фоне
   выглядит чужеродно почти во всех браузерах. */
.switch input { appearance: none; width: 46px; height: 26px; margin: 0;
  border-radius: 999px; background: rgba(255, 255, 255, .22);
  position: relative; cursor: pointer; transition: background .18s; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform .18s var(--spring); }
.switch input:checked { background: var(--gold); }
.switch input:checked::after { transform: translateX(20px); }

/* --- гейт после проигрыша --------------------------------------------- */

.gate-options { display: flex; flex-direction: column; gap: 9px; margin: 4px 0 12px; }

.gate-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  margin-top: 0;
  padding: 12px 14px;
  text-align: center;
}

.gate-title { font-size: 15px; font-weight: 800; }

/* Подпись живёт внутри кнопки: цена и остаток нужны до нажатия, иначе
   игрок жмёт наугад и злится на списание. */
.gate-hint { font-size: 12px; font-weight: 500; opacity: .8; }

button.primary.gate-option .gate-hint { color: rgba(255, 255, 255, .9); }

.gate-note { min-height: 18px; margin: 0 0 14px; font-size: 13px; color: var(--gold); }
