@font-face {
  font-family: 'Russo One';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(../fonts/russo-one-cyrillic-400-normal.woff2) format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Russo One';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(../fonts/russo-one-latin-400-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #0b0d12;
  --panel: rgba(16, 19, 26, 0.78);
  --panel-solid: #141820;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f4f5f7;
  --muted: #9aa1ad;
  --accent: #ffd400;
  --accent-2: #ff9e00;
  --ink: #15130a;
  --danger: #ff4d55;
  --good: #3ddc84;
  --display: 'Russo One', system-ui, sans-serif;
  --body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --safe-top: max(env(safe-area-inset-top, 0px), calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --gutter: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
}

svg { width: 1em; height: 1em; flex: none; }

.muted { color: var(--muted); }

/* ---------------------------------------------------------------- экраны */

.screen, .overlay, .sheet {
  position: fixed;
  inset: 0;
  display: none;
  pointer-events: none;
}
.screen.is-active { display: flex; }
.screen > * { pointer-events: auto; }

.overlay {
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 16px) var(--gutter) calc(var(--safe-bottom) + 16px);
  background: rgba(5, 6, 9, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: auto;
}
.overlay.is-active { display: flex; animation: fade 0.25s ease; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }

/* ---------------------------------------------------------------- логотип и загрузка */

.logo {
  font-family: var(--display);
  font-size: 40px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-sm { font-size: 22px; gap: 8px; }
.logo-flag {
  width: 1.05em;
  height: 0.75em;
  border-radius: 3px;
  background:
    conic-gradient(var(--text) 25%, #1b1e24 0 50%, var(--text) 0 75%, #1b1e24 0) 0 0 / 0.35em 0.375em;
  box-shadow: 0 0 0 2px var(--accent);
  transform: skewX(-10deg);
}

#loading {
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 40%, #1a1e27, var(--bg) 70%);
}
.loading-box { text-align: center; width: min(320px, 80vw); }
.progress {
  height: 6px;
  margin: 28px 0 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.progress i {
  display: block;
  height: 100%;
  width: 8%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.3s ease;
}

/* ---------------------------------------------------------------- гараж */

#garage { flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) var(--gutter) 8px;
  background: linear-gradient(var(--bg), rgba(11, 13, 18, 0));
}
.topbar-right { display: flex; align-items: center; gap: 8px; }

.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-family: var(--display);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.pill svg { color: var(--accent); font-size: 18px; }
.pill b { font-weight: 400; }

.btn-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 22px;
}
.btn-icon:active { transform: scale(0.94); }

.garage-drag { flex: 1; touch-action: none; }

.garage-bottom {
  padding: 0 var(--gutter) calc(var(--safe-bottom) + 16px);
  background: linear-gradient(rgba(11, 13, 18, 0), rgba(11, 13, 18, 0.92) 30%);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.car-switch {
  display: flex;
  align-items: center;
  gap: 10px;
}
.car-info { flex: 1; min-width: 0; text-align: center; }
.car-count { color: var(--muted); font-size: 13px; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; }
.car-name {
  font-family: var(--display);
  font-size: clamp(22px, 7vw, 30px);
  line-height: 1.15;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.car-tag {
  min-height: 20px;
  margin-top: 4px;
  font-size: 14px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.car-tag .owned { color: var(--good); }
.car-tag .locked { color: var(--accent); }

.btn-round {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 26px;
}
.btn-round:active { transform: scale(0.92); background: rgba(255, 212, 0, 0.18); }

.dots { display: flex; justify-content: center; gap: 5px; flex-wrap: wrap; }
.dots i {
  width: 6px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.18);
  transition: width 0.2s ease, background 0.2s ease;
}
.dots i.is-active { width: 18px; background: var(--accent); }

.btn-primary {
  height: 58px;
  border-radius: 16px;
  background: linear-gradient(180deg, #ffe23d, var(--accent) 45%, #f2b600);
  color: var(--ink);
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: 0.06em;
  box-shadow: 0 8px 28px rgba(255, 196, 0, 0.28), inset 0 -3px 0 rgba(0, 0, 0, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
}
.btn-primary:active { transform: translateY(1px) scale(0.99); }
.btn-primary[disabled] { opacity: 0.55; }
.btn-primary svg { font-size: 22px; }

.btn-ghost {
  height: 46px;
  padding: 0 16px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
}
.btn-ghost svg { color: var(--accent); font-size: 18px; }
.btn-ghost:active { transform: scale(0.97); }
.btn-ghost.wide { width: 100%; }

.row { display: flex; align-items: center; gap: 10px; }
.row > .btn-ghost { flex: 1; }
.rank-note { flex: 1; color: var(--muted); font-size: 14px; text-align: right; }
.rank-note b { color: var(--text); font-family: var(--display); font-weight: 400; }
.rank-note:empty { display: none; }

.guest-note { margin: 0; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------------------------------------------------------------- HUD */

#hud { flex-direction: column; pointer-events: none; }
#hud > * { pointer-events: none; }
#hud .touch-zone, #hud .hud-pause { pointer-events: auto; }

.touch-zone { position: absolute; inset: 0; display: flex; touch-action: none; }
.touch-half { flex: 1; display: flex; align-items: flex-end; padding-bottom: calc(var(--safe-bottom) + 40px); }
.touch-half.left { justify-content: flex-start; padding-left: 24px; }
.touch-half.right { justify-content: flex-end; padding-right: 24px; }
.touch-hint {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: rgba(10, 12, 16, 0.25);
  font-size: 34px;
  color: rgba(255, 255, 255, 0.7);
  transition: transform 0.1s ease, background 0.1s ease, opacity 0.6s ease;
}
.touch-half.is-down .touch-hint { transform: scale(0.9); background: rgba(255, 212, 0, 0.35); color: #fff; }
#hud.is-desktop .touch-hint { opacity: 0; }

.hud-top {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: calc(var(--safe-top) + 10px) var(--gutter) 0;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
}
.hud-label { font-size: 12px; letter-spacing: 0.14em; color: rgba(255, 255, 255, 0.75); font-weight: 700; }
.hud-value {
  font-family: var(--display);
  font-size: clamp(30px, 9vw, 42px);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.hud-sub { font-size: 14px; color: rgba(255, 255, 255, 0.8); font-variant-numeric: tabular-nums; margin-top: 2px; }
.hud-speed { text-align: right; }
.hud-pause { position: absolute; left: 50%; transform: translateX(-50%); top: calc(var(--safe-top) + 12px); }
.hud-combo {
  margin-top: 6px;
  display: inline-block;
  padding: 3px 10px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--ink);
  font-family: var(--display);
  font-size: 16px;
  text-shadow: none;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.hud-combo.is-on { opacity: 1; transform: scale(1); }

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 120px;
  color: #fff;
  text-shadow: 0 6px 30px rgba(0, 0, 0, 0.6);
}
.countdown span { animation: pop 0.9s ease forwards; }
.countdown span.go { color: var(--accent); font-size: 64px; }
@keyframes pop {
  0% { transform: scale(1.8); opacity: 0; }
  20% { transform: scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: scale(0.9); opacity: 0; }
}

.popups { position: absolute; left: 0; right: 0; top: 34%; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.popup {
  font-family: var(--display);
  font-size: 26px;
  color: var(--accent);
  text-shadow: 0 3px 14px rgba(0, 0, 0, 0.6);
  animation: float 1.1s ease forwards;
  white-space: nowrap;
}
.popup small { display: block; text-align: center; font-size: 15px; color: #fff; }
@keyframes float {
  0% { transform: translateY(10px) scale(0.7); opacity: 0; }
  15% { transform: translateY(0) scale(1.08); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translateY(-36px) scale(1); opacity: 0; }
}

.controls-hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 120px);
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(10, 12, 16, 0.6);
  font-size: 14px;
  white-space: nowrap;
  transition: opacity 0.6s ease;
}
.controls-hint.is-hidden { opacity: 0; }

.flash {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle, rgba(255, 80, 60, 0) 30%, rgba(255, 40, 40, 0.55));
  pointer-events: none;
  animation: flash 0.7s ease forwards;
}
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

/* ---------------------------------------------------------------- карточки */

.card {
  width: min(420px, 100%);
  padding: 24px 20px 20px;
  border-radius: 22px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: rise 0.3s ease;
}
.card h2 { margin: 0 0 6px; font-family: var(--display); font-weight: 400; font-size: 28px; text-align: center; }

.over-card { text-align: center; }
.over-label { color: var(--danger); font-family: var(--display); letter-spacing: 0.2em; font-size: 15px; }
.over-score { font-family: var(--display); font-size: clamp(48px, 15vw, 64px); line-height: 1; font-variant-numeric: tabular-nums; }
.badge {
  align-self: center;
  padding: 5px 12px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--ink);
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: 0.06em;
  animation: pulse 1.2s ease infinite;
}
@keyframes pulse { 50% { transform: scale(1.06); } }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 6px 0; }
.stats div { padding: 10px 4px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); }
.stats b { display: block; font-family: var(--display); font-weight: 400; font-size: 18px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 11px; color: var(--muted); }
.over-rank { margin: 0; color: var(--muted); font-size: 14px; min-height: 18px; }
.over-rank b { color: var(--text); }

/* ---------------------------------------------------------------- рейтинг */

.sheet {
  flex-direction: column;
  background: var(--bg);
  pointer-events: auto;
  padding-top: var(--safe-top);
}
.sheet.is-active { display: flex; animation: rise 0.25s ease; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px var(--gutter) 8px; }
.sheet-head h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 26px; }

.tabs { display: flex; gap: 6px; margin: 4px var(--gutter) 10px; padding: 4px; border-radius: 14px; background: var(--panel-solid); }
.tab { flex: 1; height: 38px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--muted); }
.tab.is-active { background: rgba(255, 212, 0, 0.14); color: var(--accent); }

.board-list {
  list-style: none;
  margin: 0;
  padding: 0 var(--gutter) 16px;
  overflow-y: auto;
  flex: 1;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}
.board-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  margin-bottom: 6px;
  background: var(--panel-solid);
}
.board-row.is-me { outline: 1.5px solid var(--accent); }
.board-place { width: 30px; text-align: center; font-family: var(--display); font-size: 17px; color: var(--muted); font-variant-numeric: tabular-nums; }
.board-row:nth-child(1) .board-place { color: #ffd400; }
.board-row:nth-child(2) .board-place { color: #d5dbe3; }
.board-row:nth-child(3) .board-place { color: #e09a5a; }
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  background: #2b3140 center / cover no-repeat;
}
.board-who { flex: 1; min-width: 0; }
.board-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-car { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-score { font-family: var(--display); font-size: 17px; font-variant-numeric: tabular-nums; }
.board-empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.board-me { padding: 8px var(--gutter) calc(var(--safe-bottom) + 12px); border-top: 1px solid var(--line); }
.board-me .board-row { margin: 0; outline: 1.5px solid var(--accent); }

.car-loading {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.car-loading i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.credits-note { margin: 0 var(--gutter) 12px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.credit { padding: 10px 12px; border-radius: 14px; margin-bottom: 6px; background: var(--panel-solid); }
.credit-cars { font-weight: 600; font-size: 15px; }
.credit-what { font-size: 13px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.credit-what a { color: var(--accent); text-decoration: none; }

/* ---------------------------------------------------------------- уведомления */

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 64px);
  transform: translate(-50%, -20px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(20, 24, 32, 0.95);
  border: 1px solid var(--line);
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 20;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) and (min-height: 500px) {
  .garage-bottom { width: 440px; align-self: center; border-radius: 24px; }
  .hud-value { font-size: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
