:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, var(--accent));
  --sep: rgba(127, 127, 140, .16);
  --soft: rgba(127, 127, 140, .12);
  --gold: #f2b01e; --silver: #9aa6b4; --bronze: #cd7f45;
  --boom: #e5484d; --ok: #2a9d3c;
  --r: 18px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 20px rgba(0,0,0,.05);
}
html[data-dark="1"] {
  --bg: var(--tg-theme-secondary-bg-color, #0f1115);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1b1e25));
  --text: var(--tg-theme-text-color, #f2f3f5);
  --hint: var(--tg-theme-hint-color, #8d939c);
  --shadow: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
.screen {
  max-width: 560px; margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- общие элементы ---------- */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); }
.section-title {
  margin: 24px 4px 10px; font-size: 13px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--hint);
  display: flex; align-items: center; justify-content: space-between;
}
.section-title a { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--link); text-decoration: none; }
.btn {
  border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 600;
  background: var(--soft); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(.97); opacity: .85; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.block { width: 100%; }
.muted { color: var(--hint); }

.ava {
  --s: 40px; width: var(--s); height: var(--s); flex: 0 0 var(--s); border-radius: 50%;
  position: relative; overflow: hidden; display: grid; place-items: center;
  font-weight: 700; font-size: calc(var(--s) * .42); color: #fff;
  background: linear-gradient(135deg, hsl(var(--h, 210) 70% 62%), hsl(calc(var(--h, 210) + 40) 70% 50%));
}
.ava img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.seg {
  display: flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--soft);
}
.seg button {
  flex: 1; border: 0; background: none; padding: 8px 6px; border-radius: 9px;
  font-size: 13px; font-weight: 600; color: var(--hint); transition: background .15s, color .15s;
  white-space: nowrap;
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.skel { border-radius: 12px; background: linear-gradient(90deg, var(--soft) 25%, rgba(127,127,140,.2) 50%, var(--soft) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: rgba(20, 20, 24, .92); color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 500; transition: opacity .2s, transform .2s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- главная ---------- */
.hello { display: flex; align-items: center; gap: 14px; padding: 4px 4px 0; }
.hello h1 { margin: 0; font-size: 22px; line-height: 1.2; }
.hello .sub { margin-top: 3px; font-size: 14px; color: var(--hint); }
.brand { font-size: 28px; font-weight: 800; letter-spacing: -.02em; margin: 4px 4px 0; }
.notice { margin-top: 16px; padding: 14px 16px; display: flex; gap: 12px; align-items: center; }
.notice .ico { font-size: 26px; }

.game-card { padding: 16px; }
.game-head { display: flex; gap: 14px; align-items: center; }
.game-icon {
  width: 60px; height: 60px; flex: 0 0 60px; border-radius: 16px; display: grid; place-items: center;
  font-size: 32px; background: linear-gradient(135deg, var(--a, #5b8def), color-mix(in srgb, var(--a, #5b8def) 60%, #7a2cf0));
  box-shadow: 0 6px 16px color-mix(in srgb, var(--a, #5b8def) 35%, transparent);
}
.beta {
  margin-left: 8px; padding: 2px 7px; border-radius: 6px; vertical-align: 3px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; background: #f59e0b; color: #fff;
}
.game-head h3 { margin: 0; font-size: 18px; }
.game-head p { margin: 3px 0 0; font-size: 13px; color: var(--hint); }
.bests { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin: 14px 0; }
.best { background: var(--soft); border-radius: 12px; padding: 8px 10px; }
.best .l { font-size: 11px; color: var(--hint); }
.best .v { font-weight: 700; font-size: 15px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.game-actions { display: flex; gap: 8px; }
.game-actions .btn.primary { flex: 1; }
.soon {
  margin-top: 12px; padding: 16px; border-radius: var(--r); border: 1.5px dashed var(--sep);
  display: flex; gap: 12px; align-items: center; color: var(--hint); font-size: 14px;
}
.soon .ico { font-size: 24px; filter: grayscale(.3); }

/* ---------- рейтинг ---------- */
.top-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 4px 14px; }
.top-head h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.filters { display: grid; gap: 8px; }
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 8px; margin: 22px 0 6px; }
.pod { text-align: center; min-width: 0; }
.pod .ava { margin: 0 auto 6px; border: 3px solid var(--c); }
.pod .name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod .score { font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums; margin-top: 1px; }
.pod .step {
  margin-top: 8px; border-radius: 14px 14px 6px 6px; background: var(--card); box-shadow: var(--shadow);
  display: grid; place-items: center; font-size: 22px; font-weight: 800; color: var(--c);
}
.pod.p1 { --c: var(--gold); } .pod.p1 .step { height: 92px; font-size: 28px; }
.pod.p2 { --c: var(--silver); } .pod.p2 .step { height: 68px; }
.pod.p3 { --c: var(--bronze); } .pod.p3 .step { height: 52px; }
.pod.empty { visibility: hidden; }
.pod.me .name { color: var(--link); }

.list { margin-top: 12px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 64px; right: 0; height: 1px; background: var(--sep); }
.row .rank { width: 26px; text-align: center; font-weight: 700; color: var(--hint); font-variant-numeric: tabular-nums; }
.row .who { flex: 1; min-width: 0; }
.row .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .un { font-size: 12px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sc { font-weight: 700; font-variant-numeric: tabular-nums; }
.row.me { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.empty-state { text-align: center; padding: 36px 20px; }
.empty-state .big { font-size: 46px; }
.empty-state p { color: var(--hint); margin: 8px 0 18px; }
.me-bar {
  position: sticky; bottom: calc(10px + env(safe-area-inset-bottom)); margin-top: 14px;
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px;
  background: var(--accent); color: var(--accent-text); box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.me-bar .rank { font-weight: 800; font-size: 17px; }
.me-bar .who { flex: 1; font-weight: 600; }
.me-bar .sc { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- нижние вкладки ---------- */
.screen.tabbed { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--sep);
}
.tabbar button {
  flex: 1; max-width: 140px; border: 0; background: none; padding: 6px 4px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 600; color: var(--hint); transition: color .15s, background .15s;
}
.tabbar .ti { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .6; transition: filter .15s, opacity .15s, transform .15s; }
.tabbar button.on { color: var(--accent); }
.tabbar button.on .ti { filter: none; opacity: 1; transform: scale(1.08); }
.screen.tabbed .me-bar { bottom: calc(80px + env(safe-area-inset-bottom)); }

/* ---------- сетка игр ---------- */
.grid-games { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.game-tile {
  border: 0; text-align: left; padding: 14px; border-radius: var(--r); background: var(--card); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px; min-height: 150px; transition: transform .12s ease;
}
.game-tile:active { transform: scale(.97); }
.game-tile .game-icon { width: 52px; height: 52px; flex-basis: 52px; font-size: 28px; border-radius: 14px; margin-bottom: 8px; }
.gt-title { font-weight: 700; font-size: 16px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.gt-title .beta { margin-left: 0; vertical-align: 0; }
.gt-sub { font-size: 12.5px; color: var(--hint); }
.gt-resume { font-size: 12.5px; font-weight: 700; color: var(--accent); }
.game-tile.paused { box-shadow: var(--shadow), inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent); }
.soon-tile { background: none; box-shadow: none; border: 1.5px dashed var(--sep); }
.soon-icon { background: var(--soft) !important; box-shadow: none !important; }
.search {
  width: 100%; margin: 0 0 12px; padding: 11px 14px; border-radius: 12px; border: 0;
  background: var(--card); color: var(--text); font: inherit; outline: none; box-shadow: var(--shadow);
}

/* ---------- лента выбора игры ---------- */
.strip {
  display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 12px; padding: 2px 16px 4px;
  scrollbar-width: none; scroll-snap-type: x proximity;
}
.strip::-webkit-scrollbar { display: none; }
.chip-game {
  flex: 0 0 auto; scroll-snap-align: start; border: 0; border-radius: 999px; padding: 6px 14px 6px 6px;
  display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px;
  background: var(--card); color: var(--text); box-shadow: var(--shadow); transition: background .15s, color .15s;
}
.chip-game .ci {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 16px;
  background: color-mix(in srgb, var(--a, #5b8def) 22%, transparent);
}
.chip-game.on { background: var(--accent); color: var(--accent-text); }
.chip-game.on .ci { background: rgba(255,255,255,.25); }

/* ---------- профиль ---------- */
.profile { padding: 22px 16px 16px; text-align: center; }
.profile .ava { margin: 0 auto 10px; }
.profile h1 { margin: 0; font-size: 22px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.stat { background: var(--soft); border-radius: 14px; padding: 10px 6px; }
.stat .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--hint); }
.row.place { width: 100%; border: 0; background: none; text-align: left; font: inherit; color: inherit; }
.row.place + .row.place::before { left: 64px; }
.game-icon.mini { width: 38px; height: 38px; flex: 0 0 38px; font-size: 20px; border-radius: 11px; box-shadow: none; }
.ranks { text-align: right; }
.ranks .r1 { font-weight: 700; font-size: 14px; }
.ranks .r2 { font-size: 12px; color: var(--hint); }

/* ---------- общий каркас экрана игры (стили самих игр — в /games/*.css) ---------- */
.play {
  height: var(--tg-viewport-stable-height, 100dvh); min-height: 0;
  display: flex; flex-direction: column; max-width: 980px; margin: 0 auto;
  padding: 10px 0 env(safe-area-inset-bottom);
}
.play .seg { margin: 0 12px; }
.hint { text-align: center; color: var(--hint); font-size: 12px; padding: 0 12px 8px; min-height: 22px; }
.tools { display: flex; gap: 8px; padding: 0 12px 12px; }
.tools .btn { flex: 1; padding: 12px 8px; }
.tools .btn.sq { flex: 0 0 52px; }
.tools .btn.on { background: var(--accent); color: var(--accent-text); }

.overlay {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,.45); padding: 12px; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.sheet {
  width: 100%; max-width: 420px; background: var(--card); border-radius: 24px; padding: 22px 20px calc(18px + env(safe-area-inset-bottom));
  text-align: center; transform: translateY(30px); transition: transform .25s cubic-bezier(.2,.9,.3,1.2);
}
.overlay.show .sheet { transform: none; }
.sheet .em { font-size: 52px; line-height: 1; }
.sheet h2 { margin: 10px 0 4px; font-size: 24px; }
.sheet .time { font-size: 40px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin: 4px 0; }
.sheet .msg { color: var(--hint); margin: 4px 0 0; }
.sheet .msg.good { color: var(--ok); font-weight: 600; }
.chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 14px 0 4px; }
.chip { background: var(--soft); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; }
.sheet .actions { display: grid; gap: 8px; margin-top: 18px; }
