:root {
  --bg: #0b0b1a;
  --card: #17142f;
  --card-2: #262150;
  --text: #fff;
  --muted: #b7b0dc;
  --blue: #2aabee;
  --blue-dark: #1379b3;
  --gold: #ffc61a;
  --line: rgba(255, 255, 255, 0.1);
  /* отступы под «чёлку» и панели Telegram в полноэкранном режиме */
  --st: calc(max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  --sb: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Rubik', system-ui, -apple-system, 'Segoe UI', sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.3s; }
body.ready #ui { opacity: 1; }
.hidden { display: none !important; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }

/* ---------- общие элементы ---------- */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  padding: calc(12px + var(--st)) 16px calc(16px + var(--sb));
  pointer-events: auto;
}
.screen-solid { background: linear-gradient(180deg, rgba(11, 11, 26, 0.9), rgba(11, 11, 26, 0.97)); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.topbar h2 { flex: 1; font-size: 24px; font-weight: 900; }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px; border-radius: 999px;
  background: rgba(10, 8, 24, 0.66); border: 1px solid var(--line);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums;
}
.pill small { font-size: 12px; font-weight: 500; opacity: 0.7; margin-left: -3px; }

/* внутриигровая монета (класс исторически называется .gem) */
.gem {
  display: inline-block; flex: none; width: 18px; height: 18px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='11.5' fill='%23f2cf6b'/%3E%3Ccircle cx='12' cy='12' r='10.35' fill='%23eebc40' stroke='%23e2a847' stroke-width='1.1'/%3E%3Cg fill='none' stroke-linejoin='round' stroke-linecap='round' stroke-width='2.3'%3E%3Cpath d='M4.6 7.75H19.4L12 20.55ZM12 7.75V20.55' stroke='%23d99a2e' transform='translate(.5 .5)'/%3E%3Cpath d='M4.6 7.75H19.4L12 20.55ZM12 7.75V20.55' stroke='%23f8f8f8'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
}

.icon-btn {
  width: 44px; height: 44px; flex: none; border-radius: 14px;
  display: grid; place-items: center; font-size: 20px;
  background: rgba(10, 8, 24, 0.66); border: 1px solid var(--line);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 54px; padding: 0 16px; border-radius: 18px;
  font-weight: 700; font-size: 17px;
  background: var(--card-2); box-shadow: 0 5px 0 #0e0b22;
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #0e0b22; }
.btn-primary {
  min-height: 64px; font-size: 22px; font-weight: 900; letter-spacing: 0.03em; text-transform: uppercase;
  background: linear-gradient(180deg, #4cc2ff, var(--blue)); box-shadow: 0 5px 0 var(--blue-dark);
}
.btn-primary:active { box-shadow: 0 1px 0 var(--blue-dark); }
.btn-gold { background: linear-gradient(180deg, #ffd84a, #ffb300); color: #2a1b00; box-shadow: 0 5px 0 #a86f00; }
.btn-gold:active { box-shadow: 0 1px 0 #a86f00; }
.btn-ghost { background: transparent; box-shadow: none; color: var(--muted); min-height: 44px; }
.btn-ghost:active { box-shadow: none; }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.chip { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); }

.bar { height: 8px; border-radius: 99px; background: rgba(0, 0, 0, 0.45); overflow: hidden; }
.bar-fill { width: 100%; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #37b6ff, #9fe3ff); transform-origin: left; transform: scaleX(0); }

.screen-note { margin-top: 12px; color: var(--muted); font-size: 14px; line-height: 1.4; }

/* ---------- меню ---------- */
#screen-menu {
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(11, 11, 26, 0.5) 0%, rgba(11, 11, 26, 0) 28%, rgba(11, 11, 26, 0) 58%, rgba(11, 11, 26, 0.88) 100%);
}
.menu-head { text-align: center; margin-top: 3vh; }
.logo {
  font-size: clamp(50px, 16vw, 84px); font-weight: 900; font-style: italic; line-height: 0.88; letter-spacing: -0.02em;
  background: linear-gradient(180deg, #fff 10%, #bfeaff 50%, #2aabee 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 #0d4f78) drop-shadow(0 12px 22px rgba(0, 0, 0, 0.45));
}
.tagline { margin-top: 14px; font-weight: 500; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.75); }
.menu-foot { display: flex; flex-direction: column; gap: 12px; margin-top: auto; }
.btn-row { display: flex; gap: 12px; }

/* ---------- уровни ---------- */
.level-list { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; overflow-y: auto; padding-bottom: 12px; }
.level-card {
  position: relative; overflow: hidden; text-align: left;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 150px; padding: 14px 16px; border-radius: 22px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}
.level-card.lv-paris { background: linear-gradient(170deg, #5e9ad6 0%, #f3c9a4 70%, #8a6f5c 100%); }
.level-card.lv-ocean { background: linear-gradient(170deg, #1a6fa8 0%, #0b2f5c 70%, #071a36 100%); }
.level-card::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 25%, rgba(0, 0, 0, 0.6)); }
.level-card > * { position: relative; z-index: 1; }
.level-card:active { transform: translateY(3px); }
.lv-head { display: flex; align-items: center; gap: 10px; }
.lv-num { min-width: 44px; font-size: 44px; font-weight: 900; font-style: italic; line-height: 1; padding-right: 4px; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); }
.lv-title { flex: 1; min-width: 0; font-size: clamp(20px, calc((100vw - 156px) / 9.2), 27px); font-weight: 900; line-height: 1.1; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35); }
.lv-state { font-size: 22px; font-weight: 900; }
.lv-stats { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-top: auto; }
.lv-dist { font-size: 20px; font-weight: 900; }
.lv-best { font-size: 15px; font-weight: 700; text-align: right; }
.lv-best i { font-style: normal; font-weight: 500; opacity: 0.8; margin-right: 4px; }
.lv-rare { font-size: 13px; font-weight: 500; opacity: 0.85; padding-top: 8px; border-top: 1px solid rgba(255, 255, 255, 0.18); }
.lv-gift { margin-right: 0.55em; }
.level-card.locked { min-height: 0; }
.level-card.locked .lv-rare { border-top: 0; padding-top: 0; }
.level-card.locked { filter: saturate(0.5) brightness(0.6); pointer-events: none; }

/* ---------- магазин ---------- */
.shop-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; overflow-y: auto; padding-bottom: 12px; }
.shop-card { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 20px; background: rgba(38, 33, 80, 0.75); border: 1px solid var(--line); }
.shop-icon { width: 52px; height: 52px; flex: none; border-radius: 16px; display: grid; place-items: center; font-size: 26px; background: color-mix(in srgb, var(--c) 22%, #14112b); border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); }
.shop-info { flex: 1; min-width: 0; }
.shop-name { font-weight: 900; font-size: 17px; }
.shop-desc { color: var(--muted); font-size: 12.5px; line-height: 1.3; margin: 2px 0 6px; }
.shop-level { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 700; }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 12px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.16); }
.pips i.on { background: var(--blue); }
.btn-buy { width: auto; flex: none; min-width: 84px; min-height: 46px; font-size: 15px; background: linear-gradient(180deg, #4cc2ff, var(--blue)); box-shadow: 0 4px 0 var(--blue-dark); }
.btn-buy:active { box-shadow: 0 1px 0 var(--blue-dark); }
.btn-buy.poor { background: var(--card-2); box-shadow: 0 4px 0 #0e0b22; color: var(--muted); }
.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* ---------- коллекция ---------- */
.collection-head { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; font-weight: 700; }
.collection-head .bar-fill { background: linear-gradient(90deg, #b26bff, #ffb800); }
.item-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; overflow-y: auto; padding-bottom: 12px; }
.item-card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 14px 6px 12px; border-radius: 18px; text-align: center;
  background: color-mix(in srgb, var(--c) 16%, #14112b); border: 1.5px solid color-mix(in srgb, var(--c) 70%, transparent);
}
.item-icon { font-size: 38px; line-height: 1.15; }
.item-name { font-weight: 700; font-size: 13px; }
.item-rarity { font-size: 11px; font-weight: 700; color: var(--c); text-transform: uppercase; letter-spacing: 0.04em; }
.item-count { position: absolute; top: 6px; right: 8px; font-size: 12px; font-weight: 900; }
.item-card.missing { background: rgba(255, 255, 255, 0.04); border-style: dashed; border-color: color-mix(in srgb, var(--c) 40%, transparent); }
.item-card.missing .item-icon { font-weight: 900; color: rgba(255, 255, 255, 0.25); }
.item-card.missing .item-name { color: var(--muted); }

/* ---------- окна ---------- */
.modal { justify-content: center; align-items: center; background: rgba(6, 5, 16, 0.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.card {
  width: min(100%, 360px); padding: 24px 20px 14px; border-radius: 28px; text-align: center;
  display: flex; flex-direction: column; gap: 12px;
  background: linear-gradient(180deg, #1f1a45, #141130);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.card h2 { font-size: 28px; font-weight: 900; }
.sub { color: var(--muted); font-size: 14px; line-height: 1.4; }
.sub:empty { display: none; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stats div { display: flex; flex-direction: column; gap: 4px; padding: 12px 8px; border-radius: 16px; background: rgba(255, 255, 255, 0.06); }
.stats span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stats b { font-size: 24px; font-weight: 900; font-variant-numeric: tabular-nums; }
.badge { width: 64px; height: 64px; margin: -4px auto 0; border-radius: 50%; display: grid; place-items: center; font-size: 34px; color: #2a1b00; background: linear-gradient(180deg, #ffe680, #ffb300); box-shadow: 0 4px 0 #a86f00; }

.jet-short { margin-top: -4px; font-size: 13px; font-weight: 700; color: #ffb4b4; }
#btn-fly:disabled { opacity: 0.5; filter: grayscale(0.4); }
/* затемнение экрана: герой садится в истребитель */
.fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity 0.35s ease; z-index: 30; }
.fade.on { opacity: 1; }

.rare-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 16px; text-align: left; background: color-mix(in srgb, var(--c) 18%, #14112b); border: 1.5px solid var(--c); }
.rare-icon { font-size: 34px; line-height: 1; }
.rare-name { font-weight: 900; font-size: 17px; }
.rare-rarity { font-size: 11px; font-weight: 700; color: var(--c); text-transform: uppercase; letter-spacing: 0.05em; }
.rare-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.8; }

/* ---------- игровой интерфейс ---------- */
#hud { position: absolute; inset: 0; padding: calc(10px + var(--st)) 12px 0; }
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; }
.hud-left { display: flex; gap: 8px; }
#btn-pause { pointer-events: auto; }
.hud-level { display: none; }
/* название раунда в начале забега: появляется и через 3 секунды исчезает */
.round-title {
  position: absolute; left: 16px; right: 16px; top: 27%; text-align: center; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25), 0 6px 24px rgba(0, 0, 0, 0.45);
  opacity: 0; transform: scale(0.92);
}
.round-title b { font-size: clamp(30px, 9vw, 44px); font-weight: 900; line-height: 1.05; letter-spacing: 0.01em; }
.round-title span { font-size: clamp(16px, 4.6vw, 20px); font-weight: 700; color: #fff3c4; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6); }
.round-title span:empty { display: none; }
.round-title.show { animation: round-title 3s ease forwards; }
@keyframes round-title {
  0% { opacity: 0; transform: scale(0.92); }
  12%, 80% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.04); }
} /* шкала прогресса и название уровня в забеге убраны по просьбе пользователя */
.hud-level-name { font-size: 12px; font-weight: 700; margin-bottom: 5px; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8); }
.hud-boosts { position: absolute; left: 12px; top: calc(118px + var(--st)); display: flex; flex-direction: column; gap: 8px; }
.power { display: none; align-items: center; gap: 8px; width: 118px; padding: 6px 10px; border-radius: 14px; background: rgba(10, 8, 24, 0.66); border: 1px solid var(--line); font-size: 18px; }
.power.on { display: flex; }
.power .bar { flex: 1; height: 6px; }
.power .bar-fill { transform: scaleX(1); }

.toast {
  position: absolute; left: 50%; top: calc(118px + var(--st)); transform: translate(-50%, -8px);
  padding: 9px 16px; border-radius: 999px; white-space: nowrap;
  background: rgba(10, 8, 24, 0.78); border: 1px solid var(--line); font-weight: 700; font-size: 15px;
  opacity: 0; transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.rare-toast {
  position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%) scale(0.7);
  display: flex; align-items: center; gap: 14px; padding: 16px 22px; border-radius: 22px; white-space: nowrap;
  background: color-mix(in srgb, var(--c, #ffb800) 22%, #14112b); border: 2px solid var(--c, #ffb800);
  box-shadow: 0 0 40px color-mix(in srgb, var(--c, #ffb800) 60%, transparent);
  opacity: 0; transition: opacity 0.25s, transform 0.3s cubic-bezier(0.2, 1.6, 0.4, 1);
}
.rare-toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.rare-toast .rare-icon { font-size: 46px; }
.rare-toast .rare-name { font-size: 20px; }

.hint {
  position: absolute; left: 16px; right: 16px; bottom: calc(28px + var(--sb));
  padding: 14px; border-radius: 20px; text-align: center;
  background: rgba(10, 8, 24, 0.78); border: 1px solid var(--line);
}
.hint-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hint-grid div { display: flex; flex-direction: column; gap: 2px; }
.hint-grid b { font-size: 22px; font-weight: 900; }
.hint-grid span { font-size: 12px; color: var(--muted); }
.hint p { margin-top: 10px; font-size: 13px; font-weight: 500; }

.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: 130px; font-weight: 900; font-style: italic; text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 0 40px rgba(0, 0, 0, 0.5); }

/* если следующей локации ещё нет — главной становится кнопка «Пробежать ещё раз» */
#btn-next.hidden + #btn-complete-again { min-height: 64px; font-size: 20px; font-weight: 900; text-transform: uppercase; background: linear-gradient(180deg, #4cc2ff, var(--blue)); box-shadow: 0 5px 0 var(--blue-dark); }

/* финал уровня: плашка сверху, стикер героя перед истребителем, выбор внизу; сцена под ними видна */
.jet-screen { justify-content: space-between; align-items: center; pointer-events: none; }
.jet-screen > * { pointer-events: auto; }
.jet-banner {
  margin-top: 6px; padding: 12px 24px; border-radius: 22px; text-align: center;
  background: linear-gradient(180deg, rgba(31, 26, 69, 0.94), rgba(20, 17, 48, 0.94));
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  animation: jet-pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.jet-banner b { display: block; font-size: 26px; font-weight: 900; }
.jet-banner span { color: var(--muted); font-size: 14px; }
.jet-hero { position: absolute; pointer-events: none !important; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35)); }
.jet-panel {
  width: min(100%, 380px); display: flex; flex-direction: column; gap: 8px; padding: 12px 16px 6px;
  border-radius: 26px; text-align: center;
  background: linear-gradient(180deg, rgba(31, 26, 69, 0.95), rgba(20, 17, 48, 0.97));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.jet-wallet { color: var(--muted); font-size: 14px; }
.jet-wallet b { color: #fff; margin-left: 6px; }
#btn-fly { display: flex; flex-direction: column; gap: 1px; padding-top: 9px; padding-bottom: 9px; line-height: 1.15; }
.jet-main { font-size: 21px; font-weight: 900; }
.jet-small { font-size: 13px; font-weight: 700; opacity: 0.78; }
@keyframes jet-pop { from { transform: translateY(-24px) scale(0.8); opacity: 0; } to { transform: none; opacity: 1; } }
#btn-next { display: flex; flex-direction: column; gap: 1px; padding-top: 9px; padding-bottom: 9px; line-height: 1.15; }
#btn-next.hidden { display: none; }

/* ---------- тапалка: шкалы поверх колбы (сама колба — в loading.css) ---------- */
.tap-panel {
  position: relative; z-index: 1; pointer-events: none;
  padding: 10px 14px 12px; border-radius: 18px;
  background: rgba(10, 8, 24, 0.66); border: 1px solid var(--line);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.tap-top { margin-top: 10px; }
.tap-bottom { margin-top: auto; }
.tap-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 15px; font-weight: 700; }
.tap-row b { font-size: 20px; font-weight: 900; }
.tap-bar { height: 10px; margin-top: 8px; border-radius: 5px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.tap-bar i { display: block; width: 0; height: 100%; border-radius: 5px; background: linear-gradient(90deg, #5fe0d4, #d8fbf6); transition: width 0.15s; }
.tap-bar.energy i { background: linear-gradient(90deg, #ffb020, #ffe07a); }
.tap-hint { margin-top: 8px; font-size: 13px; color: var(--muted); text-align: center; }
.tap-hint:empty { display: none; }
.tap-timer { font-size: 13px; font-weight: 500; color: var(--muted); }
.tap-panel.deny { animation: tap-deny 0.3s; }
@keyframes tap-deny { 0%, 100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.tap-done {
  position: relative; z-index: 1; align-self: center; margin-top: auto; pointer-events: none; /* внизу: наверху висит лампа */
  padding: 12px 22px; border-radius: 20px; text-align: center;
  background: rgba(10, 8, 24, 0.72); border: 1px solid var(--line);
  animation: jet-pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.tap-done b { display: block; font-size: 24px; font-weight: 900; }
.tap-done span { color: var(--muted); font-size: 14px; }
.tap-fx { position: absolute; inset: 0; z-index: 2; overflow: hidden; pointer-events: none; }
.tap-plus {
  position: absolute; font-size: 26px; font-weight: 900; color: #fff; white-space: nowrap;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 12px rgba(130, 255, 240, 0.8);
}
.tap-flash {
  position: absolute; inset: 0; z-index: 3; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 50%, #fff, rgba(200, 255, 250, 0.6) 40%, transparent 75%);
}
/* верхняя строка не должна перехватывать тап по лампе */
#screen-tap .topbar { pointer-events: none; }
#screen-tap .topbar > * { pointer-events: auto; }
.tap-plus.big { font-size: 40px; color: #ffe07a; text-shadow: 0 3px 10px rgba(0, 0, 0, 0.6), 0 0 18px rgba(255, 200, 80, 0.9); }
