/*
 * Пузыри — вид игры. Общий игровой язык (фон, кнопки, меню, окно) — в kit/kit.css;
 * здесь своё: виноградный фон, поле-колодец с холстом, черта, счётчик промахов, значок меню.
 * Сами пузыри, пушка и потолок нарисованы на холсте (art.js).
 */

/* ---------- Оттенок игры ---------- */
/* Верх фона (--bg-top) повторён в <meta name="theme-color">. */
:root {
  --bg-top: #8a3fe8;
  --bg-mid: #6a27c9;
  --bg-bottom: #33107c;
  --glow-a: rgba(255, 130, 224, 0.44);
  --glow-b: rgba(80, 150, 255, 0.42);
  --frame: #9058f0;
  --frame-lip: #2a0b66;
  --pit: #1a1458;
  --shade-rgb: 22, 5, 58;
  --deep-rgb: 34, 9, 84;
  --title-hi: #f0dcff;
  --well-pad: 6px;
}

/* ---------- Фон: мыльные пузыри вместо плиток ---------- */

.sky i {
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0) 20%),
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0) 48%, var(--tile-hi, #fff) 100%);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.5);
  opacity: 0.34;
  animation-name: sky-rise;
}

@keyframes sky-rise {
  from { transform: translate(-6px, 14px) scale(0.96); }
  to { transform: translate(8px, -18px) scale(1.04); }
}

/* ---------- Значок в меню: гроздь пузырей и пушка, которая в неё целится ---------- */

.logo.bub-logo {
  display: block;
  position: relative;
  width: 200px;
  height: 236px;
  transform: none;
  animation: none;
}

.bub-logo b {
  position: absolute;
  width: 60px;
  height: 60px;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  filter: drop-shadow(0 6px 5px rgba(var(--shade-rgb), 0.45));
}

.bub-cluster {
  position: absolute;
  left: 0;
  top: 0;
  width: 200px;
  height: 112px;
  transform-origin: 50% 0;
  animation: logo-sway 3s ease-in-out infinite alternate;
}

.bub-cluster b {
  animation: logo-pop 0.5s cubic-bezier(0.3, 1.7, 0.5, 1) both;
}

.bub-cluster b:nth-child(1) { left: 10px; top: 0; }
.bub-cluster b:nth-child(2) { left: 70px; top: 0; animation-delay: 70ms; }
.bub-cluster b:nth-child(3) { left: 130px; top: 0; animation-delay: 140ms; }
.bub-cluster b:nth-child(4) { left: 40px; top: 52px; animation-delay: 210ms; }

/* Один пузырь грозди раз в три секунды лопается и появляется снова. */
.bub-cluster b:nth-child(5) {
  left: 100px;
  top: 52px;
  animation: logo-pop 0.5s 280ms cubic-bezier(0.3, 1.7, 0.5, 1) both, logo-burst 3s 2.4s ease-in-out infinite;
}

.bub-cluster u {
  position: absolute;
  left: 100px;
  top: 52px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 7px #e2a8ff, 0 0 14px 2px rgba(210, 130, 255, 0.8);
  opacity: 0;
  pointer-events: none;
  animation: logo-ring 3s 2.4s ease-out infinite;
}

/* Пушка с пунктиром прицела качается вокруг своей оси — целится. */
.bub-aim {
  position: absolute;
  left: 0;
  top: 112px;
  width: 200px;
  height: 124px;
  transform-origin: 100px 93px;
  animation: logo-aim 3s ease-in-out infinite alternate;
}

.bub-logo em {
  position: absolute;
  left: 95.5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 0 rgba(var(--shade-rgb), 0.4);
  animation: logo-dot 1.2s ease-in-out infinite;
}

.bub-logo em:nth-of-type(1) { top: 5px; animation-delay: 0.15s; }
.bub-logo em:nth-of-type(2) { top: 18px; }

.bub-cannon {
  position: absolute;
  left: 68px;
  top: 28px;
  width: 64px;
  height: 96px;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  filter: drop-shadow(0 6px 5px rgba(var(--shade-rgb), 0.45));
}

@keyframes logo-sway {
  from { transform: rotate(-3deg); }
  to { transform: rotate(3deg); }
}

@keyframes logo-aim {
  from { transform: rotate(-9deg); }
  to { transform: rotate(9deg); }
}

@keyframes logo-pop {
  from { transform: scale(0); }
}

@keyframes logo-burst {
  0%, 8% { transform: scale(1); }
  13% { transform: scale(1.16); }
  16%, 30% { transform: scale(0); }
  40% { transform: scale(1.1); }
  46%, 100% { transform: scale(1); }
}

@keyframes logo-ring {
  0%, 13% { opacity: 0; transform: scale(0.7); }
  15% { opacity: 1; transform: scale(0.8); }
  30%, 100% { opacity: 0; transform: scale(1.5); }
}

@keyframes logo-dot {
  0%, 100% { opacity: 0.6; transform: scale(0.82); }
  50% { opacity: 1; transform: scale(1.12); }
}

/* Рекорд и уровень — в одну строку. */
.menu-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 34px;
  margin-top: 22px;
}

.menu-row .menu-best {
  margin: 0;
}

.menu-level {
  display: flex;
  align-items: center;
  height: 34px;
  margin: 0;
  padding: 0 14px;
  border-radius: 17px;
  background: var(--deep);
  font-size: 16px;
  font-weight: 800;
  white-space: nowrap;
}

.menu-level[hidden],
.menu-best[hidden] {
  display: none;
}

.menu-stars {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 10px;
  padding-left: 10px;
  border-left: 2px solid rgba(255, 255, 255, 0.18);
  color: #ffd84a;
}

.menu-stars .ico {
  width: 17px;
  height: 17px;
  filter: drop-shadow(0 1.5px 0 #a35a00);
}

/* «Начать с 1 уровня»: тихая кнопка под главными. */
.menu-fresh {
  min-height: 44px;
  font-size: 15px;
}

.menu-fresh[hidden] {
  display: none;
}

/* ---------- Строка под счётом: уровень, запас промахов, множитель ---------- */

.pips {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 9px 0 8px;
  border-radius: 12px;
  background: var(--deep);
}

/* Значок «потолок едет вниз»: маленький потолок с зубцами и стрелка. Картинку ставит app.js. */
.pips i {
  width: 16px;
  height: 16px;
  margin-right: 2px;
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

.pips b {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  box-shadow: inset 0 1px 2px rgba(var(--shade-rgb), 0.7);
}

.pips b.on {
  background: radial-gradient(circle at 34% 28%, #fff 0%, #fff 12%, #ffe27a 32%, #ffb81f 74%, #c97b00 100%);
  box-shadow: 0 1.5px 0 #96540a;
  animation: pip-in 0.3s cubic-bezier(0.3, 1.8, 0.5, 1);
}

.pips.last b.on {
  background: radial-gradient(circle at 34% 28%, #fff 0%, #fff 12%, #ffa3ad 32%, #ff3b55 74%, #b3202f 100%);
  box-shadow: 0 1.5px 0 #7a1020, 0 0 8px rgba(255, 60, 90, 0.85);
  animation: pip-warn 0.55s ease-in-out infinite alternate;
}

@keyframes pip-in {
  from { transform: scale(0.3); }
}

@keyframes pip-warn {
  from { transform: scale(1); }
  to { transform: scale(1.3); }
}

/* ---------- Поле ---------- */
/* --fit-w и --fit-h пишет kit.fit() на .app; запасные значения — если скрипт не запустился. */

.board {
  width: var(--fit-w, 280px);
  height: var(--fit-h, 432px);
  border-radius: 20px;
  overflow: hidden;
  background: #1c1566;
  cursor: crosshair;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.board canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Глубина колодца: тень от рамки ложится на поле сверху. */
.board::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  border-radius: inherit;
  pointer-events: none;
  box-shadow:
    inset 0 5px 9px rgba(var(--shade-rgb), 0.7),
    inset 0 0 0 1.5px rgba(255, 255, 255, 0.08),
    inset 0 -3px 6px rgba(var(--shade-rgb), 0.35);
}

/* Новый уровень: по полю пробегает блик. */
.board::before {
  content: "";
  position: absolute;
  top: -10%;
  bottom: -10%;
  left: 0;
  z-index: 2;
  width: 46%;
  background: linear-gradient(100deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.22) 50%, rgba(255, 255, 255, 0) 100%);
  opacity: 0;
  pointer-events: none;
  transform: translateX(-120%) skewX(-14deg);
}

.board.sweep::before {
  animation: board-sweep 0.9s 0.35s ease-in-out both;
}

@keyframes board-sweep {
  0% { opacity: 1; transform: translateX(-120%) skewX(-14deg); }
  100% { opacity: 1; transform: translateX(340%) skewX(-14deg); }
}

/* Потолок встал: поле коротко проседает. */
.board.slam {
  animation: board-slam 0.3s ease-out;
}

@keyframes board-slam {
  25% { transform: translateY(5px); }
  60% { transform: translateY(-2px); }
}

/* Потолок вот-вот поедет: рамка поля краснеет. (Свечение черты и звёзды рисуются на холсте.) */
.board::after {
  transition: box-shadow 0.18s ease-out;
}

.board.warn::after {
  box-shadow:
    inset 0 0 0 3px #ff5273,
    inset 0 0 24px rgba(255, 60, 90, 0.6),
    inset 0 5px 9px rgba(var(--shade-rgb), 0.7);
}

/* Запасной пузырь: сам он нарисован на холсте, поверх — прозрачная кнопка. */
.swap {
  position: absolute;
  z-index: 3;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.swap:active {
  background: rgba(255, 255, 255, 0.14);
}

/* Подсказка внутри поля — на низких экранах, где строки под полем нет. */
.tip {
  position: absolute;
  left: 8px;
  right: 8px;
  top: calc(var(--u, 33px) * 9.22);
  z-index: 1;
  display: none;
  margin: 0;
  color: rgba(255, 255, 255, 0.88);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  text-shadow: 0 1px 0 rgba(8, 4, 44, 0.9), 0 0 6px rgba(8, 4, 44, 0.9);
  pointer-events: none;
}

.app.low .tip:not([hidden]) {
  display: block;
}

.is-over .tip {
  display: none !important;
}

/* Сумма за группу вместе с упавшими — крупнее обычных очков. */
.gain.gain-big {
  font-size: 38px;
  color: #fff3b8;
}

/* Рука первой подсказки: ведёт по полю, пушка следит. Положение задаёт app.js. */
.hand {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  width: 0;
  height: 0;
  pointer-events: none;
  will-change: transform, opacity;
}

.hand[hidden] {
  display: none;
}

.hand::before {
  content: "";
  position: absolute;
  left: -19px;
  top: -19px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  box-shadow: inset 0 0 0 2.5px rgba(255, 255, 255, 0.85);
}

.hand i {
  position: absolute;
  left: -15px;
  top: -3px;
  width: 54px;
  height: 62px;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  filter: drop-shadow(0 4px 3px rgba(var(--shade-rgb), 0.5));
}

.is-over .hand {
  display: none;
}

/* ---------- Окно итога: звёзды ---------- */

.stars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  height: 58px;
  margin: 8px 0 -4px;
}

.stars .ico {
  width: 44px;
  height: 44px;
  margin-bottom: 2px;
  color: rgba(255, 255, 255, 0.16);
}

.stars .ico:nth-child(1) {
  transform: rotate(-12deg);
}

.stars .ico:nth-child(3) {
  transform: rotate(12deg);
}

.stars .ico:nth-child(2) {
  width: 58px;
  height: 58px;
  margin-bottom: 6px;
}

.stars .ico.on {
  color: var(--c4);
  filter: drop-shadow(0 3px 0 #a35a00) drop-shadow(0 0 8px rgba(255, 204, 26, 0.6));
  animation: star-in 0.5s cubic-bezier(0.3, 1.9, 0.5, 1) both;
  animation-delay: calc(var(--i) * 160ms + 240ms);
}

@keyframes star-in {
  from { transform: scale(0) rotate(-50deg); opacity: 0; }
}

/* ---------- Правила: строки с картинками ---------- */

.howto {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 14px;
  text-align: left;
}

.howto-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 12px 7px 7px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.1);
}

.howto-ico {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 13px;
  background-color: rgba(var(--shade-rgb), 0.6);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  box-shadow: inset 0 2px 4px rgba(var(--shade-rgb), 0.7);
}

.howto-row p {
  font-size: 14.5px;
  font-weight: 650;
  line-height: 19px;
  color: rgba(255, 255, 255, 0.86);
  text-wrap: pretty;
}

/* ---------- Низкие экраны ---------- */

/* Низкий экран (класс ставит app.js): счёт переезжает в шапку на место рекорда, строки под полем нет —
   поле получает около 65 px высоты, пузыри крупнее. */
.app.low .top .pill,
.app.low .foot {
  display: none;
}

.app.low .top .score {
  flex: 1 1 0;
  min-width: 0;
  height: 44px;
  padding: 0 6px;
  font-size: 31px;
  line-height: 44px;
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 3px 0 rgba(var(--deep-rgb), 0.55);
}

.app.low .top .score.score-long {
  font-size: 21px;
}

.app.low .sub {
  margin-top: 0;
}

@media (max-height: 620px) {
  .logo.bub-logo {
    margin: -36px 0;
    transform: scale(0.7);
  }

  .menu-fresh {
    min-height: 44px;
    margin-top: -2px;
  }

  .menu-row {
    margin-top: 14px;
  }

  .howto {
    gap: 6px;
    margin-top: 10px;
  }

  .howto-row {
    padding: 5px 10px 5px 5px;
  }

  .howto-row p {
    font-size: 13.5px;
    line-height: 17px;
  }

  .foot {
    height: 18px;
    font-size: 12.5px;
    line-height: 16px;
  }

  .stars {
    height: 44px;
    margin-top: 2px;
  }

  .stars .ico {
    width: 34px;
    height: 34px;
  }

  .stars .ico:nth-child(2) {
    width: 44px;
    height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sky i,
  .bub-cluster,
  .bub-logo em,
  .bub-aim,
  .bub-cluster b,
  .bub-cluster u,
  .pips.last b.on {
    animation: none !important;
  }

  .board.slam,
  .board.sweep::before {
    animation: none;
  }
}
