@import url('https://fonts.googleapis.com/css2?family=Lilita+One&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Палитра в духе Brawl Stars: яркий синий, акценты золото / красный, чёрный контур */
:root {
  --bs-sky: #00a2ff;
  --bs-sky-dim: #0088dd;
  --bs-panel: #007acc;
  --bs-panel-dark: #005a99;
  --bs-red: #e62429;
  --bs-gold: #ffd700;
  --bs-white: #ffffff;
  --bs-black: #000000;
  --paper: #f4fbff;
  --paper-dark: rgba(0, 122, 204, 0.35);
  --ink: #001a33;
  --ink-light: #335577;
  --pencil: var(--bs-black);
  --red: var(--bs-red);
  --green: #2ecc71;
  --blue: var(--bs-panel);
  --yellow: var(--bs-gold);
  --line-color: rgba(255, 255, 255, 0.08);
  --star-gold: var(--bs-gold);
  --ui-outline: 3px solid var(--bs-black);
  --ui-shadow: 4px 4px 0 var(--bs-black);
  --font-display: 'Lilita One', system-ui, sans-serif;
}

html {
  height: 100%;
  overscroll-behavior: none;
  overscroll-behavior-y: contain;
}

/* До применения SDK-локали не показываем русский HTML из разметки (п. 2.14) */
html.inkroll-booting #game-wrapper,
html.inkroll-booting .app-version {
  visibility: hidden;
}

html, body {
  width: 100%;
  height: 100%;
}

body {
  background-color: var(--bs-sky);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  max-height: 100%;
  font-family: var(--font-display);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  position: fixed;
  inset: 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Версия сборки — левый нижний угол */
.app-version {
  position: fixed;
  left: clamp(8px, 2vmin, 14px);
  bottom: clamp(6px, 1.5vmin, 12px);
  z-index: 15;
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(11px, 1.55vmin, 13px);
  font-weight: 400;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.78);
  text-shadow:
    1px 1px 0 var(--bs-black),
    -1px -1px 0 var(--bs-black);
  pointer-events: none;
  user-select: none;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -3;
  background:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.12) 0%, transparent 45%),
    radial-gradient(circle at 80% 70%, rgba(0, 60, 120, 0.2) 0%, transparent 40%);
  pointer-events: none;
}

/* Диагональные «панели» как на постере */
body::after {
  content: '';
  position: fixed;
  inset: -40%;
  z-index: -2;
  background: repeating-linear-gradient(
    124deg,
    transparent 0,
    transparent 70px,
    rgba(0, 74, 140, 0.28) 70px,
    rgba(0, 74, 140, 0.28) 140px
  );
  pointer-events: none;
}

/* Car picker on title screen — carousel (~половина прежнего размера) */
#car-picker {
  position: relative;
  z-index: 1;
  margin-top: 14px;
  width: min(96vw, 390px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(5px, 1.1vmin, 9px);
  padding: clamp(6px, 1.1vmin, 9px);
  border: var(--ui-outline);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--ui-shadow);
  box-sizing: border-box;
  touch-action: pan-y;
}

/* Mobile fallback (без container queries): полоса игры уже по высоте — жмём блок машинки */
@media (max-width: 560px), (pointer: coarse) {
  #car-picker {
    width: min(98%, 280px);
    gap: clamp(4px, 1.5vw, 8px);
    padding: clamp(5px, 1.5vw, 8px);
  }
  .car-carousel-arrow {
    width: clamp(18px, 5vmin, 28px);
    height: clamp(18px, 5vmin, 28px);
    font-size: clamp(11px, 3vmin, 16px);
  }
  .car-pick {
    max-width: min(100%, 46vmin);
    /* Высота от полоски 16×9 (cqh), не от всего экрана — иначе dvh даёт крошечную карточку */
    height: clamp(52px, min(26vw, 88px), 120px);
    height: clamp(52px, min(26vw, 38cqh, 88px), 120px);
    padding: clamp(4px, 1.2vw, 8px);
    border-radius: 10px;
  }
  .car-pick-q {
    font-size: clamp(18px, 8vmin, 34px);
  }
  .car-pick-reward {
    font-size: clamp(8px, 2.4vmin, 11px);
  }
  .car-carousel-meta {
    bottom: 8px;
  }
  .car-carousel-hint {
    font-size: 12px;
  }
}

@media (max-height: 700px) {
  #title-screen #car-picker {
    margin-top: clamp(8px, 2vmin, 16px);
  }
  .car-pick {
    height: clamp(44px, min(22vmin, 78px), 100px);
    height: clamp(44px, min(22vmin, 34cqh, 78px), 100px);
  }
}

.car-carousel-arrow {
  flex: 0 0 auto;
  width: clamp(22px, 3.5vmin, 32px);
  height: clamp(22px, 3.5vmin, 32px);
  border: var(--ui-outline);
  border-radius: 10px;
  background: var(--bs-white);
  box-shadow: 2px 2px 0 var(--bs-black);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: clamp(11px, 2.1vmin, 18px);
  color: var(--bs-black);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.car-carousel-arrow:hover { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--bs-black); }
.car-carousel-arrow:active { transform: translate(1px,1px); box-shadow: 1px 1px 0 var(--bs-black); }
.car-carousel-arrow:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: 2px 2px 0 var(--bs-black);
}

.car-pick {
  flex: 1 1 auto;
  width: 100%;
  max-width: min(100%, 260px);
  height: clamp(110px, 19vmin, 160px);
  border: var(--ui-outline);
  border-radius: 12px;
  background: var(--bs-white);
  box-shadow: 3px 3px 0 var(--bs-black);
  cursor: pointer;
  overflow: hidden;
  /* Одна ячейка: иначе каждый потомок получает отдельную строку grid и миниатюра сжимается */
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  place-items: center;
  padding: clamp(5px, 1vmin, 8px);
  position: relative;
}
.car-pick > * {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
}
.car-pick:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--bs-black); }
.car-pick.locked {
  cursor: default;
  background: rgba(230, 240, 250, 0.95);
}
.car-pick.locked:hover {
  transform: none;
  box-shadow: 3px 3px 0 var(--bs-black);
}
.car-pick.selected {
  border-color: var(--bs-gold);
  box-shadow:
    0 0 0 2px var(--bs-black),
    0 0 0 4px var(--bs-gold),
    3px 3px 0 var(--bs-black);
}
.car-pick img,
.car-pick-thumb {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center center;
  pointer-events: none;
  user-select: none;
}
.car-pick-thumb.car-pick-thumb-hidden {
  visibility: hidden;
}
.car-pick-lock-layer {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 0.8vmin, 8px);
  padding: clamp(5px, 1vmin, 10px);
  text-align: center;
  background: rgba(255, 255, 255, 0.94);
  pointer-events: none;
  box-sizing: border-box;
}
.car-pick-q {
  font-family: var(--font-display);
  font-size: clamp(28px, 5vmin, 44px);
  line-height: 1;
  color: var(--bs-panel);
  opacity: 0.85;
}
.car-pick-reward {
  font-family: var(--font-display);
  font-size: clamp(8px, 1.5vmin, 11px);
  font-weight: 400;
  color: var(--bs-black);
  line-height: 1.12;
  max-width: 100%;
  overflow-wrap: anywhere;
  hyphens: auto;
}
.car-pick-reward:empty {
  display: none;
}

.car-carousel-meta {
  position: absolute;
  left: 50%;
  bottom: clamp(5px, 1vmin, 10px);
  transform: translateX(-50%);
  z-index: 2;
  width: calc(100% - clamp(16px, 3vmin, 28px));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.8vmin, 14px);
  pointer-events: none;
}
.car-carousel-name {
  font-family: var(--font-display);
  font-size: clamp(16px, 3.2vmin, 26px);
  color: var(--bs-red);
  text-shadow: 2px 2px 0 rgba(0,0,0,0.12);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.car-carousel-hint {
  font-family: var(--font-display);
  font-size: clamp(12px, 2.2vmin, 16px);
  color: rgba(0,0,0,0.68);
  text-shadow: 1px 1px 0 rgba(255,255,255,0.6);
}
.car-carousel-hint:empty { display: none; }

/* Car unlock progress (title screen) */
.car-progress {
  width: min(96vw, 390px);
  margin-top: clamp(8px, 1.8vmin, 14px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.car-progress-bar {
  width: 100%;
  max-width: min(96vw, 260px);
  height: clamp(16px, 2.4vmin, 22px);
  border: 2px solid var(--bs-black);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 2px 2px 0 var(--bs-black);
  overflow: hidden;
  position: relative;
}
.car-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffe066 0%, var(--bs-gold) 55%, #ffaa00 100%);
  border-radius: 999px;
  transition: width 0.25s ease;
}
.car-progress-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: clamp(11px, 2vmin, 14px);
  color: rgba(0, 0, 0, 0.75);
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.7);
  pointer-events: none;
}

@media (max-width: 520px) {
  .car-progress {
    width: min(94vw, 270px);
    margin-top: 8px;
  }
  .car-progress-bar {
    max-width: min(94vw, 210px);
  }
}

/* Make title-screen elements larger */
#title-screen .btn {
  font-size: clamp(22px, 3.2vw, 34px);
  padding: 16px 54px;
}
#title-screen .btn + .btn {
  margin-top: 10px;
}
#title-screen #car-picker {
  margin-top: clamp(10px, 2.5vmin, 18px);
}
#title-screen #car-picker .car-pick {
  /* carousel: base styles live in .car-pick */
}
@media (max-height: 640px) {
  #title-screen .btn {
    font-size: clamp(18px, 3.5vmin, 28px);
    padding: 12px 36px;
  }
}
@media (max-height: 520px) {
  /* carousel handles small heights intrinsically */
}
/* 16:9 "во весь экран"; п. 1.10.2 — overscroll / без лишней прокрутки */
#game-wrapper {
  position: relative;
  z-index: 1;
  isolation: isolate;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  aspect-ratio: 16 / 9;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  /* Размеры карусели на телефоне — от высоты/ширины самой области игры, не от всего экрана */
  container-type: size;
  container-name: game;
}

/* Компактный титул внутри узкой 16×9 области (особенно портрет телефона) */
@container game (max-height: 400px) {
  #title-screen #car-picker,
  #car-picker {
    width: min(98cqw, 100%);
    gap: clamp(3px, 1cqw, 6px);
    padding: clamp(3px, 1cqw, 6px);
    margin-top: clamp(4px, 1cqh, 8px);
  }
  #title-screen #car-picker .car-carousel-arrow,
  .car-carousel-arrow {
    width: clamp(16px, 4.5cqw, 22px);
    height: clamp(16px, 4.5cqw, 22px);
    font-size: clamp(9px, 2.5cqw, 12px);
  }
  #title-screen #car-picker .car-pick,
  #car-picker .car-pick {
    max-width: min(100%, 44cqw);
    height: clamp(40px, min(26cqh, 72px), 88px);
    padding: clamp(3px, 1cqw, 6px);
  }
  .car-pick-q {
    font-size: clamp(16px, 8cqw, 28px);
  }
  .car-pick-reward {
    font-size: clamp(6px, 2cqw, 9px);
  }
}

@container game (max-height: 260px) {
  #title-screen #car-picker,
  #car-picker {
    padding: 4px;
    gap: 4px;
    margin-top: 3px;
  }
  #title-screen #car-picker .car-pick,
  #car-picker .car-pick {
    height: clamp(36px, min(28cqh, 52px), 60px);
    padding: 4px;
  }
  #title-screen #car-picker .car-carousel-arrow,
  .car-carousel-arrow {
    width: clamp(14px, 4cqw, 19px);
    height: clamp(14px, 4cqw, 19px);
  }
  .car-pick-q {
    font-size: clamp(13px, 7cqw, 22px);
  }
}

@container game (max-height: 400px) {
  .car-progress {
    width: min(98cqw, 100%);
    margin-top: clamp(4px, 1.6cqh, 10px);
  }
  .car-progress-bar {
    max-width: min(98cqw, 100%);
  }
}

/* Водяной паттерн поверх синего body, под экранами */
#game-wrapper::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.09;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Ccircle cx='28' cy='24' r='16' fill='none' stroke='%23001a33' stroke-width='2'/%3E%3Ccircle cx='22' cy='22' r='3.5' fill='%23001a33'/%3E%3Ccircle cx='34' cy='22' r='3.5' fill='%23001a33'/%3E%3Cpath d='M18 32 Q28 38 38 32' fill='none' stroke='%23001a33' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: 56px 56px;
  pointer-events: none;
}

#game-wrapper img {
  -webkit-user-drag: none;
  user-drag: none;
}

/* SCREENS */
.screen {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(244, 251, 255, 0.97);
  border-radius: 12px;
  border: var(--ui-outline);
  box-shadow: 8px 10px 0 rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.screen.active { display: flex; }

/* Лёгкая сетка на экранах меню (не тетрадь — аккуратный tech-фон) */
.screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--line-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-color) 1px, transparent 1px);
  background-size: 24px 24px;
  border-radius: 12px;
  pointer-events: none;
}

.screen::after {
  display: none;
}

/* TITLE SCREEN */
#title-screen {
  background:
    linear-gradient(180deg, rgba(0, 162, 255, 0.35) 0%, rgba(0, 90, 153, 0.5) 100%),
    url('./assets/main.png') center / cover no-repeat;
  /* Иначе при низкой высоте окна панель машин обрезается — даём прокрутку только титулу */
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Кнопка "Играть" по центру; карусель ниже */
  justify-content: center;
  gap: clamp(8px, 2vmin, 14px);
  padding:
    clamp(10px, 2.5vmin, 22px) clamp(10px, 2vmin, 18px)
    max(clamp(14px, 3vmin, 28px), env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}

#title-screen::before {
  display: none;
}
#title-screen::after { display: none; }

#title-screen .title {
  font-family: var(--font-display);
  font-size: clamp(42px, 6vw, 72px);
  color: var(--bs-white);
  text-shadow:
    3px 3px 0 var(--bs-black),
    -2px -2px 0 var(--bs-black),
    2px -2px 0 var(--bs-black),
    -2px 2px 0 var(--bs-black),
    0 6px 0 rgba(0, 0, 0, 0.25);
  position: relative;
  z-index: 1;
  animation: wobble 3s ease-in-out infinite;
}

@keyframes wobble {
  0%, 100% { transform: rotate(-1deg); }
  50% { transform: rotate(1deg); }
}

#title-screen .subtitle {
  font-size: clamp(16px, 2.2vw, 22px);
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 2px 2px 0 var(--bs-black);
  margin-top: 8px;
  position: relative;
  z-index: 1;
}

#title-screen .deco-car {
  font-size: clamp(32px, 4.5vw, 48px);
  position: relative;
  z-index: 1;
  margin: 20px 0;
  animation: drive 2s ease-in-out infinite;
}

@keyframes drive {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-6px) rotate(2deg); }
}

.btn {
  font-family: var(--font-display);
  font-size: clamp(16px, 2.4vw, 24px);
  font-weight: 400;
  letter-spacing: 0.02em;
  padding: 12px 36px;
  border: var(--ui-outline);
  border-radius: 12px;
  background: var(--bs-white);
  color: var(--bs-black);
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: transform 0.12s, box-shadow 0.12s;
  box-shadow: var(--ui-shadow);
  margin-top: 16px;
  text-shadow:
    1px 1px 0 rgba(255, 255, 255, 0.4),
    -1px -1px 0 rgba(0, 0, 0, 0.08);
}

.btn:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 var(--bs-black);
}
.btn:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--bs-black);
}

/* Золото — главный CTA */
.btn.green {
  background: linear-gradient(180deg, #ffe566 0%, var(--bs-gold) 45%, #e6ac00 100%);
  border-color: var(--bs-black);
  box-shadow: var(--ui-shadow);
  color: #1a1200;
}
.btn.green:hover {
  box-shadow: 6px 6px 0 var(--bs-black);
}

/* Красный акцент — вторичные действия */
.btn.blue {
  background: linear-gradient(180deg, #ff4d52 0%, var(--bs-red) 50%, #b01018 100%);
  border-color: var(--bs-black);
  box-shadow: var(--ui-shadow);
  color: var(--bs-white);
  text-shadow:
    2px 2px 0 rgba(0, 0, 0, 0.35),
    -1px -1px 0 rgba(0, 0, 0, 0.2);
}
.btn.blue:hover {
  box-shadow: 6px 6px 0 var(--bs-black);
}

/* GAME SCREEN */
#game-screen {
  padding: 0;
  overflow: hidden;
  background: transparent;
  border: none;
  box-shadow: none;
}

#game-screen::before,
#game-screen::after {
  display: none;
}

#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 54px;
  background: linear-gradient(180deg, var(--bs-panel) 0%, var(--bs-panel-dark) 100%);
  border-bottom: var(--ui-outline);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 16px;
  z-index: 10;
  font-size: 18px;
  color: var(--bs-white);
  text-shadow:
    2px 2px 0 var(--bs-black),
    -1px -1px 0 var(--bs-black),
    1px -1px 0 var(--bs-black),
    -1px 1px 0 var(--bs-black);
  overscroll-behavior: none;
  touch-action: none;
}

#level-label {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(16px, 2.2vmin, 22px);
}

#ink-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

#ink-icon { font-size: 22px; }

#ink-bar-bg {
  flex: 1;
  height: 16px;
  border: 2px solid var(--bs-black);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  overflow: hidden;
  max-width: 180px;
}

#ink-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #ffe066 0%, var(--bs-gold) 40%, #ffaa00 100%);
  border-radius: 6px;
  transition: width 0.1s linear;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

#ink-pct {
  font-size: 15px;
  min-width: 40px;
  color: var(--bs-white);
  text-shadow: 1px 1px 0 var(--bs-black);
}

#btn-ink-refill.hud-btn-ink {
  flex: 0 1 auto;
  font-size: clamp(11px, min(1.9vmin, 2.6vw), 16px);
  padding: clamp(2px, 0.7vmin, 4px) clamp(6px, 1.4vmin, 10px);
  line-height: 1.05;
  white-space: nowrap;
}

@media (max-width: 520px) {
  #btn-ink-refill.hud-btn-ink {
    font-size: clamp(10px, 2.7vw, 14px);
    padding: 2px 6px;
  }
}
#btn-ink-refill.hud-btn-ink:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
}
#btn-ink-refill.hud-btn-ink:not(:disabled):hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--bs-black);
}

#hud-hint {
  font-size: clamp(12px, 1.6vmin, 16px);
  color: rgba(255, 255, 255, 0.95);
  font-style: normal;
  flex: 2;
  text-align: center;
  min-width: 0;
  text-shadow: 1px 1px 0 var(--bs-black);
  opacity: 0.95;
}
#hud-hint:empty {
  display: none;
}

#hud-tr {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
#btn-hud-leaderboard.hud-btn-lb {
  font-size: clamp(14px, 1.85vmin, 18px);
  padding: 3px 10px;
}

.hud-btn {
  font-family: var(--font-display);
  font-size: clamp(13px, 1.6vmin, 17px);
  padding: 4px 12px;
  border: 2px solid var(--bs-black);
  border-radius: 10px;
  background: var(--bs-white);
  color: var(--bs-black);
  cursor: pointer;
  transition: all 0.1s;
  box-shadow: 2px 2px 0 var(--bs-black);
}
.hud-btn:hover { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--bs-black); }
.hud-btn:active { transform: translate(1px,1px); box-shadow: 1px 1px 0 var(--bs-black); }

/* Область игры: канвас + HTML-машинка (как миниатюры на титуле — тот же object-fit) */
.game-canvas-wrap {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: 0 0 4px 4px;
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  cursor: crosshair;
  touch-action: none;
  /* Линии/сетка — чёткие; спрайт машинки рисуется отдельным <img> */
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Декор — как машинка: отдельные img + object-fit, поверх канваса, под машиной */
.game-decor-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

.game-decor-layer .game-decor-sprite {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
  user-select: none;
  display: none;
  image-rendering: auto;
  -webkit-user-drag: none;
  transform-origin: center bottom;
}

.game-flag-sprite {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  object-fit: contain;
  object-position: left top;
  pointer-events: none;
  user-select: none;
  z-index: 1;
  display: none;
  image-rendering: auto;
  -webkit-user-drag: none;
}

/* Та же отрисовка, что у .car-pick img на титульном экране */
.game-car-sprite {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
  user-select: none;
  z-index: 2;
  display: none;
  /* Как у обычного img в браузере (не crisp-edges с канваса) */
  image-rendering: auto;
}

/* FLOATING START BUTTON — centered, scales down on small viewports */
#bottom-controls {
  position: absolute;
  left: 50%;
  bottom: clamp(6px, 1.8vmin, 18px);
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.5vmin, 16px);
  width: max-content;
  max-width: calc(100% - clamp(12px, 4vmin, 28px));
  box-sizing: border-box;
  pointer-events: none; /* allow only buttons to catch taps */
}
#bottom-controls > button {
  pointer-events: auto;
  flex: 0 1 auto;
  min-width: 0;
}

#btn-start-float {
  position: relative;
  font-family: var(--font-display);
  font-size: clamp(14px, 2.7vmin, 24px);
  font-weight: 400;
  padding: clamp(8px, 1.35vmin, 14px) clamp(16px, 2.6vmin, 28px);
  border: 3px solid var(--bs-black);
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe566 0%, var(--bs-gold) 45%, #e6ac00 100%);
  color: #1a1200;
  cursor: pointer;
  box-shadow:
    0 clamp(3px, 0.55vmin, 5px) 0 var(--bs-black),
    0 clamp(5px, 0.9vmin, 8px) clamp(10px, 1.6vmin, 18px) rgba(0,0,0,0.25);
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  gap: clamp(4px, 0.9vmin, 8px);
  animation: pulse-btn 1.8s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.35);
}
#btn-start-float:active {
  transform: translateY(clamp(2px, 0.4vmin, 3px));
  box-shadow:
    0 clamp(1px, 0.2vmin, 2px) 0 var(--bs-black),
    0 clamp(2px, 0.4vmin, 4px) clamp(5px, 1vmin, 8px) rgba(0,0,0,0.15);
}
#btn-start-float.hidden { display: none; }
#btn-start-float.running-mode {
  background: linear-gradient(180deg, #fff0a8 0%, #ffc107 100%);
  border-color: var(--bs-black);
  color: #3d2200;
  box-shadow:
    0 clamp(3px, 0.55vmin, 4px) 0 var(--bs-black),
    0 clamp(4px, 0.9vmin, 6px) clamp(8px, 1.6vmin, 16px) rgba(0,0,0,0.2);
  animation: none;
  font-size: clamp(12px, 2.3vmin, 19px);
  padding: clamp(6px, 1.1vmin, 10px) clamp(12px, 2vmin, 20px);
}

@keyframes pulse-btn {
  0%, 100% {
    transform: scale(1);
    box-shadow:
      0 clamp(3px, 0.55vmin, 5px) 0 var(--bs-black),
      0 clamp(5px, 0.9vmin, 8px) clamp(10px, 1.6vmin, 18px) rgba(0,0,0,0.22);
  }
  50% {
    transform: scale(1.03);
    box-shadow:
      0 clamp(3px, 0.55vmin, 5px) 0 var(--bs-black),
      0 clamp(6px, 1vmin, 10px) clamp(12px, 2vmin, 26px) rgba(255, 215, 0, 0.45);
  }
}

/* ERASE BUTTON */
#btn-erase-float {
  position: relative;
  font-family: var(--font-display);
  font-size: clamp(13px, 2.4vmin, 21px);
  font-weight: 400;
  padding: clamp(6px, 1.2vmin, 12px) clamp(12px, 2.2vmin, 22px);
  border: 3px solid var(--bs-black);
  border-radius: 999px;
  background: linear-gradient(180deg, #ff6b6f 0%, var(--bs-red) 50%, #9e0a12 100%);
  color: var(--bs-white);
  cursor: pointer;
  box-shadow:
    0 clamp(3px, 0.55vmin, 4px) 0 var(--bs-black),
    0 clamp(4px, 0.9vmin, 6px) clamp(8px, 1.5vmin, 16px) rgba(0,0,0,0.22);
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  gap: clamp(3px, 0.75vmin, 6px);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35);
}
#btn-erase-float:active {
  transform: translateY(clamp(2px, 0.4vmin, 3px));
  box-shadow: 0 clamp(1px, 0.2vmin, 2px) 0 var(--bs-black);
}
#btn-erase-float.hidden { display: none; }

/* OVERLAY MESSAGES */
#overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 26, 51, 0.82);
  z-index: 20;
  flex-direction: column;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top, 0px))
    max(10px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    max(10px, env(safe-area-inset-left, 0px));
  box-sizing: border-box;
  overflow: auto;
  overscroll-behavior: contain;
}
#overlay.show { display: flex; }
#overlay-title {
  font-family: var(--font-display);
  font-size: clamp(36px, 7vmin, 52px);
  color: var(--bs-white);
  text-shadow:
    3px 3px 0 var(--bs-black),
    -1px -1px 0 var(--bs-black),
    1px -1px 0 var(--bs-black);
  animation: popIn 0.4s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popIn {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
#overlay-sub {
  font-size: clamp(16px, 2.5vmin, 22px);
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 2px 2px 0 var(--bs-black);
}

.overlay-win-lb {
  display: none;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  max-width: min(92vw, 420px);
  width: 100%;
  padding: 12px 14px;
  border: var(--ui-outline);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--ui-shadow);
}
.overlay-win-lb-cap {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 20px;
  color: var(--bs-black);
  text-align: center;
}
.overlay-win-lb-body {
  font-size: 17px;
  max-height: min(38vh, 220px);
  overflow-y: auto;
}
.overlay-win-lb-foot {
  font-size: 17px;
  color: var(--ink-light);
  text-align: center;
  display: none;
}

.lb-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid rgba(0, 60, 120, 0.15);
}
.lb-row:last-child { border-bottom: none; }
.lb-rank {
  font-family: var(--font-display);
  font-weight: 400;
  min-width: 1.5em;
  color: var(--bs-red);
}
.lb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-score { font-variant-numeric: tabular-nums; }

#overlay-btns.overlay-btns {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
  align-items: center;
  width: 100%;
  max-width: min(94vw, 440px);
}
.overlay-btn-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}
.overlay-btn-row .btn.blue {
  min-width: min(260px, 88vw);
  font-size: clamp(22px, 4vmin, 30px);
  padding: 12px 24px;
}

@media (max-height: 640px) {
  #overlay {
    gap: 8px;
  }
  #overlay-title {
    font-size: clamp(26px, 6vmin, 40px);
  }
  #overlay-sub {
    font-size: clamp(13px, 2.4vmin, 18px);
  }
  .overlay-win-lb {
    padding: 10px 12px;
  }
  .overlay-win-lb-body {
    max-height: min(30vh, 160px);
    font-size: 15px;
  }
  #overlay-btns.overlay-btns {
    gap: 8px;
    margin-top: 6px;
  }
  .overlay-btn-row {
    gap: 8px;
  }
  .overlay-btn-row .btn {
    font-size: clamp(16px, 3.6vmin, 22px);
    padding: 10px 18px;
  }
  .overlay-btn-row .btn.blue {
    min-width: min(220px, 88vw);
  }
}

@media (max-height: 520px) {
  #overlay-title {
    font-size: clamp(22px, 6vmin, 34px);
  }
  .overlay-win-lb {
    max-width: min(92vw, 380px);
  }
  .overlay-win-lb-body {
    max-height: 24vh;
  }
  .overlay-btn-row .btn.blue {
    min-width: min(200px, 92vw);
  }
}

/* SDK-style modals: лидерборд и оценка */
.sdk-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px;
  box-sizing: border-box;
}
.sdk-modal.show { display: flex; }
.sdk-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 26, 51, 0.72);
}
.sdk-modal-panel {
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.98);
  border: var(--ui-outline);
  border-radius: 14px;
  box-shadow: var(--ui-shadow);
  padding: 22px 20px 18px;
  max-width: min(96vw, 440px);
  width: 100%;
  box-sizing: border-box;
}
.sdk-modal-panel--lb {
  max-width: min(96vw, 480px);
  max-height: min(85vh, 560px);
  display: flex;
  flex-direction: column;
}
.sdk-modal-x {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 38px;
  height: 38px;
  border: 2px solid transparent;
  background: transparent;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  color: var(--bs-black);
  border-radius: 8px;
}
.sdk-modal-x:hover { background: rgba(0, 122, 204, 0.12); }
.sdk-modal-title {
  font-family: var(--font-display);
  font-size: clamp(26px, 4vmin, 36px);
  margin: 0 28px 8px 0;
  color: var(--bs-black);
}
.sdk-modal-text {
  font-size: clamp(17px, 2.2vmin, 22px);
  margin: 0 0 16px;
  color: var(--ink);
}
.sdk-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.lb-modal-list {
  flex: 1;
  overflow-y: auto;
  margin-top: 6px;
  min-height: 120px;
}
.sdk-modal-foot {
  margin-top: 10px;
  font-size: 16px;
  color: var(--ink-light);
  text-align: center;
}

/* LEVEL SELECT — full area, 10×10 grid (100 levels), no inner scroll */
#levelselect-screen {
  background:
    linear-gradient(165deg, rgba(0, 162, 255, 0.42) 0%, rgba(0, 90, 153, 0.55) 100%),
    url('./assets/main.png') center / cover no-repeat;
  justify-content: flex-start;
  align-items: stretch;
  padding: 8px 10px 10px;
  box-sizing: border-box;
  gap: 6px;
}
#levelselect-screen::before,
#levelselect-screen::after {
  display: none;
}
#levelselect-screen .ls-title {
  font-family: var(--font-display);
  font-size: clamp(22px, 3.4vmin, 36px);
  color: var(--bs-white);
  text-shadow:
    2px 2px 0 var(--bs-black),
    -1px -1px 0 var(--bs-black),
    1px -1px 0 var(--bs-black);
  position: relative;
  z-index: 1;
  margin: 4px 0 2px;
  text-align: center;
  flex: 0 0 auto;
}
#levelselect-screen #level-grid {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  gap: clamp(2px, 0.45vmin, 6px);
  padding: 4px 2px;
  position: relative;
  z-index: 1;
  overflow: visible;
  box-sizing: border-box;
}
#levelselect-screen .levelselect-back {
  flex: 0 0 auto;
  align-self: center;
  margin-top: 4px;
  font-size: clamp(17px, 2.4vmin, 22px);
  padding: 8px 28px;
}
.level-btn {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border: 2px solid var(--bs-black);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: clamp(11px, 2.4vmin, 20px);
  font-weight: 400;
  color: var(--bs-black);
  box-shadow: 2px 2px 0 var(--bs-black);
  transition: all 0.12s;
  position: relative;
  box-sizing: border-box;
}
.level-btn:hover { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--bs-black); }
.level-btn .lv-stars {
  font-size: clamp(6px, 1.35vmin, 10px);
  letter-spacing: 0.5px;
  line-height: 1;
  margin-top: 1px;
  color: var(--bs-gold);
  text-shadow: 1px 1px 0 var(--bs-black);
}
.level-btn.locked {
  opacity: 0.45;
  cursor: not-allowed;
  background: rgba(0, 40, 80, 0.25);
  color: rgba(255, 255, 255, 0.75);
}
.level-btn.locked:hover { transform: none; box-shadow: 2px 2px 0 var(--bs-black); }
.level-btn.done {
  background: linear-gradient(180deg, #fff9e0 0%, #ffe066 55%, var(--bs-gold) 100%);
  border-color: var(--bs-black);
  box-shadow: 3px 3px 0 var(--bs-black);
}

/* WIN SCREEN */
#win-screen .win-title {
  font-family: var(--font-display);
  font-size: clamp(40px, 8vmin, 54px);
  color: var(--bs-red);
  text-shadow:
    3px 3px 0 var(--bs-black),
    -2px -2px 0 var(--bs-black),
    2px -2px 0 var(--bs-black);
  position: relative; z-index: 1;
  animation: wobble 2s infinite;
}
#win-stars {
  font-size: clamp(36px, 7vmin, 48px);
  position: relative;
  z-index: 1;
  margin: 12px 0;
  filter: drop-shadow(2px 2px 0 var(--bs-black));
}
#win-sub {
  font-size: clamp(17px, 2.5vmin, 22px);
  color: var(--bs-black);
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.6);
  position: relative;
  z-index: 1;
}

/* Награда: новая машинка (~2× ширина обычного оверлея победы) */
.skin-reward-modal {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: none;
  align-items: center;
  justify-content: center;
  padding:
    max(clamp(10px, 2vmin, 20px), env(safe-area-inset-top, 0px))
    max(clamp(10px, 2vmin, 20px), env(safe-area-inset-right, 0px))
    max(clamp(10px, 2vmin, 20px), env(safe-area-inset-bottom, 0px))
    max(clamp(10px, 2vmin, 20px), env(safe-area-inset-left, 0px));
  box-sizing: border-box;
}
.skin-reward-modal.show {
  display: flex;
}
.skin-reward-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 26, 51, 0.9);
}
.skin-reward-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: min(96vw, 880px);
  max-height: min(92vh, 780px);
  padding: clamp(18px, 3vmin, 36px) clamp(16px, 3vmin, 32px);
  border: var(--ui-outline);
  border-radius: 18px;
  background: rgba(244, 251, 255, 0.98);
  box-shadow: var(--ui-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.5vmin, 14px);
  overflow: auto;
  overscroll-behavior: contain;
}
.skin-reward-title {
  font-family: var(--font-display);
  font-size: clamp(26px, 5vmin, 52px);
  color: var(--bs-black);
  text-align: center;
  margin: 0;
  line-height: 1.1;
}
.skin-reward-sub {
  font-size: clamp(14px, 2.2vmin, 22px);
  color: var(--ink-light);
  text-align: center;
  margin: 0;
}
.skin-reward-stage {
  position: relative;
  width: 100%;
  max-width: 560px;
  min-height: clamp(150px, 34vmin, 300px);
  max-height: min(46vh, 360px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.skin-reward-fireworks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.28s ease;
  z-index: 3;
}
.skin-reward-fireworks.skin-reward-fw-active {
  opacity: 1;
}
.skin-fw-particle {
  position: absolute;
  left: 50%;
  top: 44%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  opacity: 0;
  animation: skinFwBurst 1.05s ease-out forwards;
  animation-delay: var(--delay);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
}
@keyframes skinFwBurst {
  0% {
    transform: translate(-50%, -50%) scale(0.15);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.55);
    opacity: 0;
  }
}
.skin-reward-car-wrap {
  position: relative;
  z-index: 2;
  width: min(48vmin, 260px);
  height: min(48vmin, 260px);
  display: grid;
  place-items: center;
}
.skin-reward-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(4px 6px 0 rgba(0, 0, 0, 0.35));
}
.phase-spin .skin-reward-img {
  animation: skinRewardSpin 2.48s linear forwards;
}
.phase-reveal .skin-reward-img {
  animation: skinRewardPop 0.72s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes skinRewardSpin {
  from {
    transform: rotate(0deg) scale(0.68);
    filter: brightness(0.16) contrast(1.08);
  }
  to {
    transform: rotate(720deg) scale(0.84);
    filter: brightness(0.42) contrast(1.05);
  }
}
@keyframes skinRewardPop {
  from {
    transform: rotate(720deg) scale(0.84);
    filter: brightness(0.42);
  }
  to {
    transform: rotate(0deg) scale(1);
    filter: brightness(1) contrast(1)
      drop-shadow(4px 6px 0 rgba(0, 0, 0, 0.35));
  }
}
.skin-reward-shadow-floor {
  position: absolute;
  bottom: 6%;
  left: 50%;
  transform: translateX(-50%);
  width: 58%;
  height: 16%;
  background: radial-gradient(
    ellipse at center,
    rgba(0, 0, 0, 0.48) 0%,
    transparent 72%
  );
  z-index: 1;
  pointer-events: none;
}
.skin-reward-name {
  font-family: var(--font-display);
  font-size: clamp(17px, 2.8vmin, 28px);
  color: var(--bs-red);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.12);
  margin: 0;
}
.skin-reward-name:empty { display: none; }
.skin-reward-btn {
  font-size: clamp(16px, 2.5vmin, 26px);
  padding: clamp(12px, 2vmin, 16px) clamp(22px, 4vmin, 40px);
  margin-top: 4px;
}
.skin-reward-btn:disabled {
  opacity: 0.46;
  cursor: wait;
  pointer-events: none;
}

@media (max-height: 640px) {
  .skin-reward-panel {
    max-height: 94vh;
    padding: clamp(12px, 2.2vmin, 22px) clamp(12px, 2.2vmin, 22px);
    gap: clamp(6px, 1.2vmin, 10px);
  }
  .skin-reward-stage {
    min-height: clamp(120px, 30vmin, 220px);
    max-height: min(42vh, 280px);
  }
  .skin-reward-car-wrap {
    width: min(44vmin, 220px);
    height: min(44vmin, 220px);
  }
  .skin-reward-btn {
    font-size: clamp(14px, 2.6vmin, 20px);
    padding: clamp(10px, 2vmin, 14px) clamp(16px, 3.2vmin, 28px);
  }
}

@media (max-height: 520px) {
  .skin-reward-stage {
    min-height: 110px;
    max-height: 36vh;
  }
  .skin-reward-car-wrap {
    width: min(40vmin, 190px);
    height: min(40vmin, 190px);
  }
}

/* Скринкаст: скрыть весь текст в интерфейсе (game.js — INKROLL_SCREENCAST_HIDE_TEXT). Канвас: текст отключён в коде. */
body.inkroll-screencast-hide-text #game-wrapper *:not(canvas):not(img) {
  font-size: 0 !important;
  line-height: 0 !important;
  color: transparent !important;
  text-shadow: none !important;
}

