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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Arial Rounded MT Bold', 'Trebuchet MS', Arial, sans-serif;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}

#game { position: fixed; inset: 0; }
#game canvas { display: block; }

/* HUD прозрачен для тапов, интерактив — только у кнопок */
#hud {
  position: fixed; inset: 0;
  pointer-events: none;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
}
#hud button { pointer-events: auto; }

#topbar { display: flex; gap: 10px; align-items: center; }
.stat {
  background: rgba(26, 26, 62, 0.75);
  color: #fff; font-weight: 800; font-size: 17px;
  padding: 8px 14px; border-radius: 14px;
}
#pauseBtn {
  margin-left: auto;
  width: 46px; height: 46px; border-radius: 14px; border: none;
  background: rgba(26, 26, 62, 0.75); color: #fff; font-size: 20px;
  cursor: pointer;
}

#hearts { margin-top: 8px; display: flex; gap: 4px; }
#hearts img { width: 32px; height: 32px; }

#combo {
  margin-top: 6px;
  color: #ffd700; font-weight: 900; font-size: 20px;
  text-shadow: 0 2px 0 #1a1a3e, 0 0 8px rgba(0,0,0,.4);
  min-height: 24px;
}

#hint {
  margin-top: auto; margin-bottom: 6px;
  text-align: center; color: #fff; font-weight: 800; font-size: 17px;
  text-shadow: 0 2px 0 #1a1a3e;
  background: rgba(26, 26, 62, 0.6);
  border-radius: 14px; padding: 8px 12px;
}
#hint:empty { display: none; }

#toast {
  position: fixed; left: 50%; top: 18%;
  transform: translateX(-50%) scale(0.9);
  background: rgba(26, 26, 62, 0.9); color: #fff;
  font-weight: 800; font-size: 16px;
  padding: 10px 18px; border-radius: 16px;
  opacity: 0; transition: opacity .25s, transform .25s;
  pointer-events: none;
  /* Длинные подсказки переносим, а не выпускаем за экран.
     width:max-content обязателен: при left:50% доступная ширина — половина экрана,
     и одного max-width мало (текст ужимался в колонку). */
  width: max-content;
  max-width: min(92vw, 420px);
  text-align: center; line-height: 1.35;
}
#toast.show { opacity: 1; transform: translateX(-50%) scale(1); }

#skipBtn {
  align-self: center;
  border: none; border-radius: 14px;
  background: rgba(255, 255, 255, 0.85); color: #1a1a3e;
  font-weight: 800; font-size: 14px; padding: 9px 16px;
  cursor: pointer;
}

#muteBtn {
  width: 46px; height: 46px; border-radius: 14px; border: none;
  background: rgba(26, 26, 62, 0.75); color: #fff; font-size: 18px;
  cursor: pointer; margin-left: auto;
}
#topbar #pauseBtn { margin-left: 0; }

#feverBadge {
  margin-top: 4px;
  align-self: flex-start;
  background: linear-gradient(90deg, #ff9a00, #ffd700);
  color: #7a2d00; font-weight: 900; font-size: 16px;
  padding: 5px 12px; border-radius: 12px;
  animation: feverPulse .5s infinite alternate;
}
@keyframes feverPulse { from { transform: scale(1); } to { transform: scale(1.08); } }

/* Плашки цели и мутатора — читаемые чипы, как статы в топбаре */
#goal, #mutator {
  margin-top: 6px;
  align-self: flex-start;
  max-width: 92%;
  background: rgba(26, 26, 62, 0.78);
  border-radius: 12px;
  padding: 7px 12px;
  color: #ffd76e; font-weight: 800; font-size: 14px;
  line-height: 1.35;
}
#mutator { color: #bfe3ff; }
#goal:empty, #mutator:empty { display: none; }

#brakeBtn {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(90px, calc(env(safe-area-inset-bottom) + 80px));
  width: 86px; height: 86px; border-radius: 50%;
  border: 5px solid #ffd23e;
  background: radial-gradient(#ff5648, #d22c1e);
  color: #fff; font-weight: 900; font-size: 17px;
  cursor: pointer;
  box-shadow: 0 6px 0 #8f1c12, 0 8px 18px rgba(0,0,0,.35);
}
#brakeBtn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 3px 0 #8f1c12; }
#brakeBtn:disabled { filter: grayscale(.8); opacity: .6; }

/* Меню */
.menu { display: flex; flex-direction: column; align-items: center; gap: 4px; width: min(320px, 80vw); }
#menuLogo { width: 100%; max-width: 300px; filter: drop-shadow(0 10px 24px rgba(0,0,0,.35)); margin-bottom: 10px; }
.menu .btn { width: 100%; font-size: 20px; }
.btn.zen { background: linear-gradient(#7fd6c4, #4bb3a0); box-shadow: 0 4px 0 #368576; }
.btn.zen:disabled { background: linear-gradient(#c2ccd8, #97a4b4); box-shadow: 0 4px 0 #6d7a8a; opacity: .75; }
.btn.ghost { background: transparent; color: #666; box-shadow: none; font-size: 15px; padding: 8px; }

/* Сетка уровней */
#levelsGrid {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 10px; margin: 14px 0;
}
.levelBtn {
  aspect-ratio: 1; border: none; border-radius: 14px;
  background: linear-gradient(#ffd76e, #f0a92d);
  box-shadow: 0 3px 0 #b57a10;
  font-size: 18px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #5a3800; font-weight: 900;
}
.levelBtn span { font-size: 11px; letter-spacing: 1px; }
.levelBtn.locked { background: #cfd4dc; box-shadow: 0 3px 0 #9aa1ab; cursor: default; }

/* Результаты уровня */
#resStars { font-size: 44px; color: #f0a92d; letter-spacing: 6px; margin: 6px 0; }
#resStars.fail { color: #d22c1e; }

/* Меню: нижний ряд + бейдж */
.menuRow { display: flex; gap: 8px; width: 100%; margin-top: 6px; }
.btn.mini { flex: 1; font-size: 15px; padding: 11px 8px; background: linear-gradient(#7db9e8, #4a90c2); box-shadow: 0 4px 0 #2f6489; position: relative; }
.badge {
  position: absolute; top: -6px; right: -6px;
  background: #ff4444; color: #fff; border-radius: 50%;
  width: 22px; height: 22px; font-size: 14px; line-height: 22px;
}

/* Магазин */
.panel.wide { width: min(400px, 92vw); max-height: 86vh; overflow-y: auto; }
.coinsTag { font-size: 16px; color: #b57a10; }
#shopContent h3 { color: #1a1a3e; font-size: 17px; margin: 14px 0 6px; text-align: left; }
.shopRow {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 12px; padding: 9px 12px; margin: 6px 0;
  text-align: left;
}
.shopInfo { flex: 1; color: #333; font-size: 14px; }
.shopInfo small { color: #888; }
.pips { color: #f0a92d; letter-spacing: 2px; }
.buyBtn {
  border: none; border-radius: 10px; padding: 9px 12px;
  background: linear-gradient(#8ce04a, #57b820); color: #fff;
  font-weight: 900; font-size: 14px; cursor: pointer;
  box-shadow: 0 3px 0 #3d8815; white-space: nowrap;
}
.buyBtn:disabled { filter: grayscale(.7); opacity: .6; }
.chipRow { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid #e0c9a0; border-radius: 20px; padding: 8px 12px;
  background: #fff; color: #5a3800; font-weight: 800; font-size: 13px;
  cursor: pointer;
}
.chip.active { background: linear-gradient(#ffd76e, #f0a92d); border-color: #b57a10; }
.chip:disabled { opacity: .55; }

/* Тестовая кнопка монет (CONFIG.debug.freeCoins) */
.debugBtn {
  margin-top: 16px;
  background: linear-gradient(#b9a7ff, #7f66d9);
  box-shadow: 0 4px 0 #574399;
  font-size: 15px;
}

/* Daily */
.dailyStrip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 12px; }
.dailyCell {
  background: #fff; border-radius: 10px; padding: 8px 2px;
  font-size: 12px; color: #666;
  display: flex; flex-direction: column; gap: 2px;
}
.dailyCell.done { background: #d8f3c8; color: #3d8815; }
.dailyCell.now { outline: 3px solid #f0a92d; background: #fff4d8; }
.challengeCard {
  margin-top: 14px; background: #fff; border-radius: 14px; padding: 12px;
  color: #333; font-size: 14px;
}
.challengeCard.done { background: #d8f3c8; }
.challengeCard p { margin: 4px 0; }

/* Вкладки городов */
#worldTabs { display: flex; gap: 6px; margin-bottom: 10px; }
.worldTab {
  flex: 1; border: none; border-radius: 10px; padding: 9px 4px;
  background: #e8e0d0; color: #7a6a4a; font-weight: 800; font-size: 13px;
  cursor: pointer;
}
.worldTab.active { background: linear-gradient(#ffd76e, #f0a92d); color: #5a3800; }
.worldTab:disabled { opacity: .55; cursor: default; }

/* Альбом */
#albumContent h3 { color: #1a1a3e; font-size: 17px; margin: 12px 0 6px; text-align: left; }
.albumGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.albumCell {
  background: #fff; border-radius: 12px; padding: 8px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 12px; color: #444;
}
.albumCell img { height: 52px; object-fit: contain; }
.albumCell b { color: #b57a10; font-size: 11px; }
.albumCell.unseen img { filter: brightness(0) opacity(.35); }
.albumCell.unseen { color: #999; }
.albumNote { margin-top: 12px; text-align: center; font-weight: 800; color: #b57a10; font-size: 14px; }
.albumNote .coinIcon { width: 16px; height: 16px; vertical-align: -3px; }

/* Настройки */
.setRow {
  display: flex; align-items: center; justify-content: space-between;
  margin: 10px 0; color: #333; font-weight: 800; font-size: 15px;
}
.setLink { display: block; margin: 12px 0; color: #3a7abf; font-weight: 700; font-size: 14px; }
.setVersion { color: #999; font-size: 12px; margin-top: 12px; }
#ageYear {
  font-size: 18px; padding: 10px 16px; border-radius: 12px;
  border: 2px solid #e0c9a0; margin: 10px 0; width: 60%;
}

/* UI-кит из сгенерённого арта (13.9) */
.coinIcon { width: 20px; height: 20px; vertical-align: -4px; }
.uiIcon { width: 22px; height: 22px; vertical-align: -5px; }
.starIcon { width: 42px; height: 42px; margin: 0 3px; }
.starIcon.small { width: 13px; height: 13px; margin: 0 1px; }
.lockIcon { width: 30px; height: 30px; }
.giftIcon { width: 30px; height: 30px; vertical-align: -8px; margin-right: 6px; }

/* Панели на 9-slice рамке из арта (специфичность выше базового .panel ниже по файлу) */
.overlay .panel {
  border: 26px solid transparent;
  border-image: url('assets/ui-panel.png') 160 fill stretch;
  border-radius: 0;
  background: none;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  padding: 14px 10px;
  width: min(370px, 94vw);
}
.levelBtn span { display: flex; justify-content: center; }

/* Кнопка тормоза — арт из кита */
#brakeBtn {
  background: url('assets/ui-brake.png') center / contain no-repeat;
  border: none; box-shadow: none; border-radius: 0;
  width: 96px; height: 96px;
}
#brakeBtn:active:not(:disabled) { transform: translateY(3px) scale(0.96); box-shadow: none; }
#brakeCount {
  position: absolute; right: -4px; top: -4px;
  background: #ffd23e; color: #7a2d00;
  border: 3px solid #fff; border-radius: 12px;
  font-size: 15px; font-weight: 900; padding: 2px 7px;
}

/* Кнопки rewarded и рекламная заглушка (§10.3) */
.btn.ad { background: linear-gradient(#66c7ff, #2f8fd8); box-shadow: 0 4px 0 #1e6396; }
.overlay.ad { background: rgba(10, 10, 25, 0.88); z-index: 20; }
.adPanel .adBox {
  display: block; background: #1a1a3e; border-radius: 16px;
  margin: 12px 0; overflow: hidden;
}
.adPanel .adBox img { display: block; width: 100%; }
#adTimer { min-height: 20px; color: #666; }

/* Баннер старта уровня — заметный момент перехода */
#levelIntro {
  position: fixed; inset: 0; z-index: 15;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; pointer-events: none; opacity: 0;
}
#levelIntro.show { animation: levelIntroAnim 1.8s ease-out; }
#levelIntroTitle {
  font-size: 54px; font-weight: 900; color: #ffd23e;
  text-shadow: 0 4px 0 #1a1a3e, 0 0 22px rgba(0,0,0,.5);
  letter-spacing: 2px;
}
#levelIntroGoal {
  font-size: 22px; font-weight: 800; color: #fff;
  background: rgba(26,26,62,.82); padding: 10px 22px; border-radius: 16px;
  text-align: center; max-width: 86%;
}
@keyframes levelIntroAnim {
  0% { opacity: 0; transform: scale(1.3); }
  15% { opacity: 1; transform: scale(1); }
  75% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.9); }
}

/* Красная вспышка при Miss (§11.3) */
#flash {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(255, 40, 40, 0.55));
  opacity: 0;
}
#flash.on { animation: flashAnim .45s ease-out; }
@keyframes flashAnim { 0% { opacity: 1; } 100% { opacity: 0; } }

/* Оверлеи */
.overlay {
  position: fixed; inset: 0;
  background: rgba(20, 20, 50, 0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
}
.panel {
  background: #fff8e8;
  border: 6px solid #ff6b5e;
  border-radius: 24px;
  padding: 28px 36px;
  text-align: center;
  min-width: 260px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
}
.panel h2 { color: #1a1a3e; font-size: 28px; margin-bottom: 12px; }
.panel p { color: #444; margin: 6px 0; font-size: 16px; }
.panel .big { font-size: 22px; font-weight: 900; color: #1a1a3e; }
.panel .record { color: #e8a000; font-weight: 900; font-size: 18px; }

.btn {
  display: block; width: 100%;
  margin-top: 14px; padding: 13px 22px;
  border: none; border-radius: 16px;
  background: linear-gradient(#8ce04a, #57b820);
  color: #fff; font-size: 18px; font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 0 #3d8815;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #3d8815; }
.btn.secondary { background: linear-gradient(#ffb84a, #f08a1d); box-shadow: 0 4px 0 #b56410; }

.hidden { display: none !important; }
