/* ===== Сброс стилей ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ===== CSS-переменные ===== */
:root {
  /* Космическая тема */
  --color-bg-gradient: linear-gradient(180deg, #0a0a1a 0%, #0d1525 50%, #0a1530 100%);
  --color-light-square: #7a8ab0;
  --color-dark-square: #2a3050;
  --color-cell-glow: rgba(100, 150, 255, 0.15);
  --color-piece-shadow: rgba(0, 0, 0, 0.4);
  --color-text: #e8e8e8;

  /* Размеры (адаптивные) */
  --board-size: min(480px, 85vw);
  --cell-size: calc(var(--board-size) / 8);
  --piece-size: calc(var(--cell-size) * 0.85);

  /* Типографика */
  --font-main: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --font-handwritten: 'Caveat', cursive;

  /* Скругления */
  --radius-lg: 16px;

  /* Тени */
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* ===== Базовые стили ===== */
html {
  /* Убирает 300мс-задержку и двойной тап-зум, не мешая прокрутке и pinch-зуму */
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-main);
  background: var(--color-bg-gradient);
  color: var(--color-text);
  min-height: 100vh;
  /* dvh учитывает динамическую адресную строку мобильных браузеров */
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  position: relative;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* Звёздное небо на фоне */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    radial-gradient(2px 2px at 20px 30px, #fff, transparent),
    radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 90px 40px, #fff, transparent),
    radial-gradient(2px 2px at 130px 80px, rgba(255,255,255,0.6), transparent),
    radial-gradient(1px 1px at 160px 120px, #fff, transparent),
    radial-gradient(2px 2px at 200px 50px, rgba(255,255,255,0.9), transparent),
    radial-gradient(1px 1px at 250px 160px, #fff, transparent),
    radial-gradient(2px 2px at 300px 90px, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 350px 200px, #fff, transparent),
    radial-gradient(2px 2px at 400px 60px, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 450px 130px, #fff, transparent),
    radial-gradient(2px 2px at 500px 250px, rgba(255,255,255,0.6), transparent),
    radial-gradient(1px 1px at 80% 30%, #fff, transparent),
    radial-gradient(2px 2px at 70% 60%, rgba(255,255,255,0.9), transparent),
    radial-gradient(1px 1px at 90% 80%, #fff, transparent),
    radial-gradient(2px 2px at 10% 70%, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 50% 90%, #fff, transparent);
  background-repeat: repeat;
  background-size: 550px 250px;
  animation: twinkle 4s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

/* ===== Контейнер ===== */
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 800px;
  width: 100%;
  position: relative;
  z-index: 1;
  /* До старта игры скрыт, чтобы заголовок задачи не мелькал под появляющимся меню */
  opacity: 0;
  transition: opacity 0.8s ease;
}

.container--visible {
  opacity: 1;
}

/* ===== Заголовок ===== */
.header {
  text-align: center;
  margin-bottom: 10px;
}

.header__title {
  font-size: 1.5rem;
  font-weight: 600;
  color: #ffd700;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

/* ===== Игровая область ===== */
.game-area {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  width: 100%;
  justify-content: center;
}

/* ===== Доска ===== */
.board-wrapper {
  flex-shrink: 0;
  position: relative;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: var(--board-size);
  height: var(--board-size);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg), 0 0 30px rgba(100, 150, 255, 0.15);
}

/* ===== Клетки ===== */
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.3s ease;
  user-select: none;
  position: relative;
}

.cell--light {
  background-color: var(--color-light-square);
  box-shadow: inset 0 0 8px var(--color-cell-glow);
}

.cell--dark {
  background-color: var(--color-dark-square);
  box-shadow: inset 0 0 6px rgba(80, 120, 200, 0.1);
}

/* Подсветка при наведении — светлый оверлей вместо filter: brightness()
   (тот же эффект осветления, но без пересчёта filter).
   Только для устройств с курсором: на тач-экранах hover залипает. */
@media (hover: hover) {
  .cell:hover {
    background-image: linear-gradient(rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.08));
  }
}

/* Подсветка выбранной клетки — золотое свечение */
.cell--selected {
  background-color: rgba(255, 200, 50, 0.4) !important;
  box-shadow: 0 0 15px rgba(255, 200, 50, 0.7),
              inset 0 0 8px rgba(255, 215, 0, 0.5) !important;
}

/* Подсветка допустимого хода */
.cell--valid-move::after {
  content: '';
  position: absolute;
  width: 25%;
  height: 25%;
  background: radial-gradient(circle, #00d4ff 0%, #0088ff 100%);
  border-radius: 50%;
  box-shadow: 0 0 10px #00d4ff, 0 0 4px white;
  z-index: 5;
}

/* Подсветка взятия */
.cell--valid-capture {
  background-color: rgba(255, 80, 80, 0.5) !important;
  box-shadow: inset 0 0 0 4px #ff5050 !important;
  z-index: 5;
}

/* ===== Фигуры (SVG) ===== */
.piece {
  width: var(--piece-size);
  height: var(--piece-size);
  line-height: 1;
  transition: transform 0.2s ease;
  filter: drop-shadow(0 2px 3px var(--color-piece-shadow));
}

@media (hover: hover) {
  .piece:hover {
    transform: scale(1.1);
  }
}

/* Кристальные фигуры — космическое свечение */
.piece--white {
  filter: drop-shadow(0 0 8px rgba(100, 200, 255, 0.9))
          drop-shadow(0 0 16px rgba(80, 150, 255, 0.5));
}

.piece--black {
  filter: drop-shadow(0 0 8px rgba(180, 100, 255, 0.9))
          drop-shadow(0 0 16px rgba(150, 80, 255, 0.5));
}

/* ===== Космическое сообщение (всплывающее) ===== */
.cosmic-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  padding: 24px 48px;
  background: rgba(20, 30, 60, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 20px;
  border: 1px solid rgba(100, 180, 255, 0.4);
  box-shadow: 0 0 40px rgba(80, 150, 255, 0.4),
              0 0 80px rgba(80, 150, 255, 0.2),
              inset 0 0 30px rgba(100, 180, 255, 0.1);
  color: #fff;
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s cubic-bezier(0.22, 0.61, 0.36, 1), transform 0.4s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.cosmic-popup--visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: auto;
}

/* ===== Анимации ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes twinkle {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  33% { opacity: 0.9; transform: scale(1.4); }
  66% { opacity: 0.5; transform: scale(1.1); }
}

/* Пульсация для драматической паузы: одна золотая тень вместо двух —
   вдвое меньше пересчётов filter на кадр для всех фигур */
@keyframes piecePulse {
  0%, 100% {
    filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.7));
  }
  50% {
    filter: drop-shadow(0 0 28px rgba(255, 215, 0, 1));
  }
}

.board--pause .piece {
  animation: piecePulse 1.2s ease-in-out infinite;
}

/* ===== Сюрприз: звёздное небо ===== */
.sky {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--color-bg-gradient);
  z-index: 999;
  opacity: 0;
  transition: opacity 3.5s ease;
  pointer-events: none;
}

.sky__stars {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.sky__star {
  position: absolute;
  width: 3px;
  height: 3px;
  background: white;
  border-radius: 50%;
  animation: twinkle 3s ease-in-out infinite;
  box-shadow: 0 0 4px rgba(255, 255, 255, 0.5);
}

/* ===== Сюрприз: переход и частицы ===== */
.surprise-dim {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 50%,
    transparent 280px,
    rgba(0, 0, 15, 0) 55%,
    rgba(0, 0, 15, 0.65) 100%);
  opacity: 0;
  z-index: 49;
  pointer-events: none;
  transition: opacity 1.5s ease;
}

.surprise-dim--visible {
  opacity: 1;
}

/* Искра-частица (создаётся в createSparkles) */
.sparkle {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 1100;
  box-shadow: 0 0 8px currentColor, 0 0 16px currentColor;
}

/* Звезда на месте клетки, сходящаяся к центру доски */
.cell-star {
  position: fixed;
  background: radial-gradient(circle, #fff 0%, #ffd700 40%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 50;
  box-shadow: 0 0 15px #ffd700, 0 0 30px rgba(255, 215, 0, 0.5);
  opacity: 0;
  transform: scale(0);
}

/* В момент взрыва звёзды уходят выше звёздного неба */
.cell-star--burst {
  z-index: 1001;
}

/* ===== Сверхновая перехода к сюрпризу ===== */
.supernova-flash {
  position: fixed;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border-radius: 50%;
  background: radial-gradient(circle,
    #ffffff 0%,
    #ffffff 18%,
    rgba(255, 248, 205, 0.98) 38%,
    rgba(255, 215, 0, 0.62) 60%,
    transparent 76%);
  box-shadow: 0 0 70px 24px rgba(255, 235, 170, 0.9);
  pointer-events: none;
  z-index: 1002;
  animation: supernovaFlash 0.95s ease-out forwards;
}

@keyframes supernovaFlash {
  0% { opacity: 0; transform: scale(0.2); }
  10% { opacity: 1; }
  32% { opacity: 0.95; }
  100% { opacity: 0; transform: scale(26); }
}

.supernova-ring {
  position: fixed;
  width: 80px;
  height: 80px;
  margin: -40px 0 0 -40px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 32px rgba(255, 215, 0, 0.9);
  pointer-events: none;
  z-index: 1001;
  animation: supernovaRing 1.1s ease-out forwards;
}

@keyframes supernovaRing {
  0% { transform: scale(0.2); opacity: 1; }
  100% { transform: scale(12); opacity: 0; }
}

/* Вспышка при появлении котика */
.cat-flash {
  position: fixed;
  width: 160px;
  height: 160px;
  background: radial-gradient(circle, rgba(255, 255, 255, 1) 0%, rgba(255, 215, 0, 0.6) 35%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 1002;
  opacity: 1;
}

/* Сердечко при клике по котику */
.heart-burst {
  position: fixed;
  font-size: 1.5rem;
  pointer-events: none;
  z-index: 1100;
  transition: transform 0.8s ease-out, opacity 0.8s ease-out;
}

/* ===== Слой 1: Котики ===== */
.cats-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
  padding: max(20px, env(safe-area-inset-top, 0px))
           max(20px, env(safe-area-inset-right, 0px))
           max(20px, env(safe-area-inset-bottom, 0px))
           max(20px, env(safe-area-inset-left, 0px));
  overflow-y: auto;
}

/* Котики в ряд под поздравлением */
.cats-stage {
  position: relative;
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 50px;
}

/* Ряд котиков */
.cats-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 30px;
  width: 100%;
}

.cats-layer__greeting {
  font-size: clamp(1.4rem, 6vw, 2rem);
  text-align: center;
  z-index: 10;
  padding: 20px;
  position: relative;
  opacity: 0;
  transform: translateY(-14px) scale(0.9);
  transition: opacity 0.9s ease, transform 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}

.cats-layer__greeting--visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Сияющий золотой градиент с переливом */
.cats-layer__greeting-shimmer {
  background: linear-gradient(90deg,
    #c8901a 0%,
    #fff3b0 25%,
    #ffd700 50%,
    #fff3b0 75%,
    #c8901a 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: #ffd700;
  filter: drop-shadow(0 2px 10px rgba(255, 200, 0, 0.55));
  animation: textShimmer 3s linear infinite;
}

@keyframes textShimmer {
  0% { background-position: 0% center; }
  100% { background-position: 200% center; }
}

/* Сияние при появлении поздравления */
@keyframes greetingGlowIn {
  0% { filter: drop-shadow(0 0 0 rgba(255, 215, 0, 0)); }
  35% {
    filter:
      drop-shadow(0 0 30px rgba(255, 215, 0, 0.95))
      drop-shadow(0 0 60px rgba(255, 180, 0, 0.6));
  }
  100% { filter: drop-shadow(0 2px 10px rgba(255, 200, 0, 0.55)); }
}

.cats-layer__greeting--visible .cats-layer__greeting-shimmer {
  animation: greetingGlowIn 1.2s ease, textShimmer 3s linear infinite;
}

@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
  .cats-layer__greeting-shimmer {
    color: #ffd700;
    -webkit-text-fill-color: #ffd700;
  }
}

/* Котики позиционируются вокруг центра и двигаются */
.cat {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  opacity: 0;
  z-index: 3;
}

@media (hover: hover) {
  .cat:hover {
    transform: scale(1.1) !important;
  }
}

/* Котики в одном ряду (начальное состояние для сборки из звёзд) */
.cat--pos-1,
.cat--pos-2,
.cat--pos-3 {
  position: relative;
  top: auto;
  left: auto;
  right: auto;
  bottom: auto;
  transform-origin: bottom center;
  opacity: 0;
}

/* Появление: прыжок из звезды с приземлением и отскоком.
   fill-mode both: 0% применяется до старта, 100% держится до снятия класса. */
.cat--landing {
  animation: catLand 1.05s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes catLand {
  0%   { transform: translateY(40px) scale(0.15); opacity: 0; }
  30%  { transform: translateY(-34px) scale(1.14); opacity: 1; }
  48%  { transform: translateY(0) scale(1.22, 0.78); }
  64%  { transform: translateY(-14px) scale(0.94, 1.06); }
  80%  { transform: translateY(0) scale(1.06, 0.96); }
  100% { transform: translateY(0) scale(1); }
}

/* Кольцо-ударная волна от приземления */
.cat-ring {
  position: fixed;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 18px rgba(255, 215, 0, 0.8);
  pointer-events: none;
  z-index: 1002;
  animation: catRing 0.7s ease-out forwards;
}

@keyframes catRing {
  0%   { transform: scale(0.2); opacity: 0.9; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* ===== Сборка котиков из звёзд ===== */
.star-assembly {
  position: relative;
  width: 100%;
  height: 0;
  pointer-events: none;
}

.assembly-star {
  position: fixed;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 6px #fff, 0 0 12px rgba(255, 215, 0, 0.6);
  pointer-events: none;
  z-index: 1001;
  opacity: 0;
  animation-name: assemblyStarFly;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  animation-fill-mode: forwards;
}

@keyframes assemblyStarFly {
  0% { opacity: 0; transform: translate(0, 0) scale(1); }
  15% { opacity: 1; }
  75% { opacity: 0.85; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.5); }
}

/* ===== CSS-арт котик ===== */
.cat__body {
  position: relative;
  width: 100px;
  height: 90px;
  border-radius: 50% 50% 45% 45%;
  animation: catSway 3s ease-in-out infinite;
}

/* Светлый живот-«манишка» */
.cat__body::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  width: 42px;
  height: 46px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  pointer-events: none;
}

/* Окрас тела: у всех котиков — пятна */
.cat--orange .cat__body {
  background-color: #f5a623;
  background-image:
    radial-gradient(circle 7px at 20% 34%, rgba(190, 100, 10, 0.42) 99%, transparent 100%),
    radial-gradient(circle 6px at 78% 28%, rgba(190, 100, 10, 0.38) 99%, transparent 100%),
    radial-gradient(circle 8px at 30% 64%, rgba(190, 100, 10, 0.36) 99%, transparent 100%),
    radial-gradient(circle 6px at 72% 70%, rgba(190, 100, 10, 0.32) 99%, transparent 100%);
}

.cat--grey .cat__body {
  background-color: #8e9aaf;
  background-image:
    radial-gradient(circle 6px at 16% 38%, rgba(70, 80, 100, 0.4) 99%, transparent 100%),
    radial-gradient(circle 5px at 84% 30%, rgba(70, 80, 100, 0.35) 99%, transparent 100%),
    radial-gradient(circle 7px at 26% 66%, rgba(70, 80, 100, 0.35) 99%, transparent 100%),
    radial-gradient(circle 5px at 74% 70%, rgba(70, 80, 100, 0.3) 99%, transparent 100%);
}

.cat--pink .cat__body {
  background-color: #ff6b9d;
  background-image:
    radial-gradient(circle 6px at 16% 38%, rgba(255, 255, 255, 0.35) 99%, transparent 100%),
    radial-gradient(circle 5px at 84% 30%, rgba(255, 255, 255, 0.3) 99%, transparent 100%),
    radial-gradient(circle 7px at 26% 66%, rgba(255, 255, 255, 0.28) 99%, transparent 100%),
    radial-gradient(circle 5px at 74% 70%, rgba(255, 255, 255, 0.25) 99%, transparent 100%);
}

.cat__head {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  width: 70px;
  height: 60px;
  border-radius: 50% 50% 45% 45%;
  border: 2px solid rgba(0, 0, 0, 0.15);
  box-sizing: border-box;
}

.cat--orange .cat__head {
  background-color: #f5a623;
  border-color: #d4891a;
  background-image:
    radial-gradient(circle 5px at 30% 24%, rgba(190, 100, 10, 0.42) 99%, transparent 100%),
    radial-gradient(circle 4px at 70% 32%, rgba(190, 100, 10, 0.34) 99%, transparent 100%);
}

.cat--grey .cat__head {
  background-color: #8e9aaf;
  border-color: #6d7a8f;
  background-image: radial-gradient(circle 4px at 32% 22%, rgba(70, 80, 100, 0.4) 99%, transparent 100%);
}

.cat--pink .cat__head {
  background-color: #ff6b9d;
  border-color: #e04d7e;
  background-image: radial-gradient(circle 4px at 32% 22%, rgba(255, 255, 255, 0.35) 99%, transparent 100%);
}

.cat__ear {
  position: absolute;
  top: -12px;
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-bottom: 20px solid;
}

.cat__ear--left { left: 8px; transform: rotate(-15deg); }
.cat__ear--right { right: 8px; transform: rotate(15deg); }

.cat--orange .cat__ear { border-bottom-color: #f5a623; }
.cat--grey .cat__ear { border-bottom-color: #8e9aaf; }
.cat--pink .cat__ear { border-bottom-color: #ff6b9d; }

.cat__ear-inner {
  position: absolute;
  top: 6px;
  left: -6px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 10px solid #ffb3c6;
}

.cat__eye {
  position: absolute;
  top: 20px;
  width: 12px;
  height: 14px;
  background: #333;
  border-radius: 50%;
  animation: catBlink 4s ease-in-out infinite;
}

.cat__eye--left { left: 16px; }
.cat__eye--right { right: 16px; }

/* Реснички над глазом */
.cat__eye::before {
  content: '';
  position: absolute;
  top: -5px;
  left: 1px;
  width: 2px;
  height: 6px;
  background: #333;
  border-radius: 2px;
  transform: rotate(-24deg);
  transform-origin: bottom center;
  box-shadow: 5px -3px 0 0 #333, 9px -1px 0 0 #333;
}

.cat__eye--right::before {
  left: auto;
  right: 1px;
  transform: rotate(24deg);
  box-shadow: -5px -3px 0 0 #333, -9px -1px 0 0 #333;
}

.cat__eye::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 4px;
  height: 4px;
  background: white;
  border-radius: 50%;
}

.cat__nose {
  position: absolute;
  top: 34px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 6px;
  background: #ff9999;
  border-radius: 50% 50% 40% 40%;
}

.cat__mouth {
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 8px;
  border-bottom: 2px solid #333;
  border-radius: 0 0 50% 50%;
}

.cat__whiskers {
  position: absolute;
  top: 36px;
  width: 20px;
  height: 2px;
  background: #333;
}

.cat__whiskers--left { left: -8px; transform: rotate(-5deg); }
.cat__whiskers--right { right: -8px; transform: rotate(5deg); }

.cat__tail {
  position: absolute;
  bottom: 12px;
  right: -22px;
  width: 34px;
  height: 14px;
  border-radius: 50%;
  transform-origin: left center;
  animation: catTailWag 1.2s ease-in-out infinite;
}

/* Пушистые бугорки по всей длине хвоста */
.cat__tail::before {
  content: '';
  position: absolute;
  inset: -7px -4px;
  border-radius: 50%;
  background: inherit;
  filter: brightness(1.07);
}

/* Пушистый кончик */
.cat__tail::after {
  content: '';
  position: absolute;
  right: -13px;
  top: -9px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: inherit;
}

.cat--orange .cat__tail { background: #f5a623; }
.cat--grey .cat__tail { background: #8e9aaf; }
.cat--pink .cat__tail { background: #ff6b9d; }

/* Лапки с подушечками */
.cat__paws {
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  z-index: 2;
}

.cat__paw {
  position: relative;
  width: 30px;
  height: 18px;
  border-radius: 50% 50% 45% 45%;
  background-color: #ffd9a0;
  background-image:
    radial-gradient(circle 3px at 30% 38%, #ff8fab 99%, transparent 100%),
    radial-gradient(circle 3px at 50% 28%, #ff8fab 99%, transparent 100%),
    radial-gradient(circle 3px at 70% 38%, #ff8fab 99%, transparent 100%),
    radial-gradient(ellipse 9px 7px at 50% 74%, #ff8fab 99%, transparent 100%);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}

.cat--orange .cat__paw { background-color: #ffd9a0; }
.cat--grey .cat__paw { background-color: #d7dde8; }
.cat--pink .cat__paw { background-color: #ffc2d9; }

.cat__flowers {
  display: flex;
  gap: 2px;
  margin-top: 4px;
  font-size: 1.2rem;
}

/* Тултип при наведении */
.cat__tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  background: rgba(255, 255, 255, 0.95);
  padding: 6px 14px;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  font-size: 0.85rem;
  color: #5c3d2e;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 10;
}

.cat__tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(255, 255, 255, 0.95);
}

@media (hover: hover) {
  .cat:hover .cat__tooltip {
    opacity: 1;
    transform: translateX(-50%) scale(1);
  }
}

/* Центральная тёмно-звёздная карточка с пожеланием (затемнение фона) */
.cat-dialog {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4, 6, 20, 0.62);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.cat-dialog__content {
  position: relative;
  max-width: 520px;
  width: 100%;
  padding: 38px 34px;
  border-radius: 24px;
  text-align: center;
  background:
    radial-gradient(circle 2px at 12% 22%, rgba(255, 255, 255, 0.95) 99%, transparent 100%),
    radial-gradient(circle 1.5px at 28% 68%, rgba(255, 255, 255, 0.8) 99%, transparent 100%),
    radial-gradient(circle 2.5px at 46% 16%, rgba(255, 255, 255, 0.9) 99%, transparent 100%),
    radial-gradient(circle 1.5px at 62% 42%, rgba(255, 255, 255, 0.7) 99%, transparent 100%),
    radial-gradient(circle 2px at 78% 74%, rgba(255, 255, 255, 0.85) 99%, transparent 100%),
    radial-gradient(circle 1.5px at 90% 30%, rgba(255, 255, 255, 0.8) 99%, transparent 100%),
    radial-gradient(circle 1.5px at 36% 88%, rgba(255, 255, 255, 0.7) 99%, transparent 100%),
    radial-gradient(circle 2px at 70% 12%, rgba(255, 255, 255, 0.75) 99%, transparent 100%),
    radial-gradient(circle at 20% 18%, rgba(120, 150, 255, 0.28) 0%, transparent 45%),
    radial-gradient(circle at 82% 80%, rgba(255, 215, 0, 0.2) 0%, transparent 45%),
    linear-gradient(160deg, #171a33 0%, #0d1024 55%, #14102b 100%);
  border: 1px solid rgba(255, 215, 0, 0.28);
  box-shadow:
    0 18px 60px rgba(0, 0, 0, 0.6),
    0 0 45px rgba(120, 150, 255, 0.18);
  transform: translateY(18px) scale(0.94);
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.cat-dialog--visible .cat-dialog__content {
  transform: translateY(0) scale(1);
}

.cat-dialog__text {
  font-size: 1.3rem;
  color: #fff5e6;
  line-height: 1.6;
  margin: 0;
  font-family: 'Georgia', serif;
}

/* ===== Кнопка «Хочу ещё!» ===== */
.btn-more {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  font-size: 1.15rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #7fd8ff 0%, #4aa3ff 100%);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(74, 163, 255, 0.55);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  margin-top: 10px;
}

@media (hover: hover) {
  .btn-more:hover {
    transform: scale(1.06);
    box-shadow: 0 8px 32px rgba(74, 163, 255, 0.8);
  }
}

.btn-more--visible {
  display: flex;
  animation: btnScaleIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes btnScaleIn {
  from { opacity: 0; transform: scale(0.3); }
  to { opacity: 1; transform: scale(1); }
}

.btn-more__icon {
  font-size: 1.5rem;
}

/* ===== Слой 2: Мини-игра ===== */
.minigame-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1s ease;
  /* Во время забега страница не должна прокручиваться/pull-to-refresh */
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: none;
  padding: 18px 0 max(18px, env(safe-area-inset-bottom, 0px));
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  background:
    radial-gradient(ellipse at 50% 82%,
      rgba(90, 140, 255, 0.20) 0%,
      transparent 62%
    ),
    linear-gradient(180deg,
      #05060f 0%,
      #0a1024 45%,
      #111a38 100%
    );
}

/* Свободная область под заголовком/подсказкой: сцена центрируется в ней,
   а transform: scale уменьшает её, не раздувая layout. */
.minigame-fit {
  flex: 1 1 auto;
  align-self: stretch;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Сцена фиксированного размера целиком уменьшается под экран
   (transform: scale в ensureMinigameStageScale). Эталон 720×360 сохраняется,
   поэтому хитбоксы не «плывут». */
.minigame-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Не позволяем flex-контейнеру сжать сцену: эталон должен остаться 720×360 */
  flex: none;
  transform-origin: center center;
  will-change: transform;
}

/* Заголовок и подсказка не должны сжиматься, когда сцена забирает высоту */
.minigame__title,
.minigame__hint {
  flex-shrink: 0;
}

/* Экранные кнопки прыжка/приседа — только на устройствах с тач-вводом */
.mg-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  display: none;
  justify-content: space-between;
  padding-left: calc(22px + env(safe-area-inset-left, 0px));
  padding-right: calc(22px + env(safe-area-inset-right, 0px));
  pointer-events: none;
  z-index: 15;
}

@media (pointer: coarse) {
  .mg-controls {
    display: flex;
  }
}

/* В ландшафте сцена масштабируется по высоте и по бокам остаётся место —
   переносим кнопки к центру боковых полей, чтобы они не закрывали трек. */
@media (pointer: coarse) and (orientation: landscape) {
  .mg-controls {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
  }
}

.mg-controls__btn {
  pointer-events: auto;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 2px solid rgba(160, 200, 255, 0.55);
  background: rgba(20, 32, 64, 0.55);
  color: #eaf1ff;
  font-size: 2rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45), inset 0 0 18px rgba(90, 140, 255, 0.25);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: transform 0.08s ease, background 0.15s ease;
}

.mg-controls__btn:active {
  transform: scale(0.92);
  background: rgba(40, 70, 130, 0.75);
}

/* Надпись «ФИНИШ» и конфетти-взрыв на финише */
.finish-title {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.4);
  font-size: clamp(2.6rem, 13vw, 4.5rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #ffd700;
  text-shadow:
    0 0 20px rgba(255, 215, 0, 0.85),
    0 0 45px rgba(255, 150, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  transition: opacity 0.5s ease, transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

/* will-change включаем точечно — только на время анимации, чтобы не держать GPU-слои постоянно */
.finish-title--visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  will-change: transform, opacity;
}

.finish-confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 19;
}

.confetti {
  position: absolute;
  left: 50%;
  top: 55%;
  font-size: 1.4rem;
  pointer-events: none;
  animation: confettiBurst ease-out forwards;
}

/* Взрыв конфетти из центра экрана */
@keyframes confettiBurst {
  0% {
    transform: translate(-50%, -50%) translate(0, 0) rotate(0deg) scale(0.5);
    opacity: 0;
  }
  12% { opacity: 1; }
  70% { opacity: 1; }
  100% {
    transform: translate(-50%, -50%) translate(var(--tx), var(--ty)) rotate(var(--rot)) scale(1.1);
    opacity: 0;
  }
}

.minigame__title {
  font-size: 1.4rem;
  color: #eaf1ff;
  margin-bottom: 12px;
  text-align: center;
  text-shadow: 0 2px 14px rgba(90, 140, 255, 0.5);
}

.minigame__hint {
  color: rgba(220, 232, 255, 0.78);
  font-size: 0.95rem;
  margin-bottom: 16px;
  animation: fadeIn 0.5s ease;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

/* Оверлей провала: по центру экрана, затемнение, рестарт кликом по карточке */
.minigame__fail {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  background: rgba(3, 6, 18, 0.68);
}

.minigame__fail-card {
  max-width: 440px;
  padding: 30px 38px;
  text-align: center;
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(22, 32, 64, 0.97) 0%, rgba(10, 16, 36, 0.99) 100%);
  border: 1px solid rgba(255, 90, 90, 0.85);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6), 0 0 46px rgba(255, 70, 70, 0.55);
  transition: transform 0.35s ease, box-shadow 0.35s ease;
}

.minigame__fail-card--ready {
  cursor: pointer;
  animation: failCardReady 1.6s ease-in-out infinite;
}

.minigame__fail-text {
  color: #eaf1ff;
  font-size: 1.15rem;
  line-height: 1.5;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

@keyframes failCardReady {
  0%, 100% { box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6), 0 0 32px rgba(255, 70, 70, 0.4); }
  50% { box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6), 0 0 58px rgba(255, 90, 90, 0.75); }
}

/* Появление карточки провала с ударом */
.minigame__fail-card--impact {
  animation: failCardImpact 0.36s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

@keyframes failCardImpact {
  0% { transform: scale(1.14) translateY(-14px); opacity: 0; }
  60% { transform: scale(1.02) translateY(2px); opacity: 1; }
  100% { transform: scale(1) translateY(0); }
}

/* ===== Полоса препятствий ===== */
.obstacle-game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.obstacle-game__progress {
  position: relative;
  width: 720px;
  height: 20px;
  background: rgba(10, 18, 40, 0.7);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(120, 170, 255, 0.35);
  box-shadow: inset 0 0 12px rgba(80, 130, 255, 0.25);
}

.obstacle-game__progress-fill {
  height: 100%;
  background: linear-gradient(90deg,
    #3a7bff 0%,
    #7fd8ff 55%,
    #ffd700 100%
  );
  border-radius: 10px;
  transform: scaleX(0);
  transform-origin: left center;
  will-change: transform;
}

.obstacle-game__progress-cat {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translate(-50%, -50%);
  font-size: 1.2rem;
  will-change: transform;
}

.obstacle-game__track {
  position: relative;
  width: 720px;
  height: 360px;
  background: linear-gradient(180deg,
    #05060f 0%,
    #0a1024 45%,
    #101a38 78%,
    #16224a 100%
  );
  border-radius: 12px;
  border: 2px solid rgba(120, 160, 255, 0.25);
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.55);
}

/* Параллакс: далёкие звёзды */
.roof__stars {
  position: absolute;
  top: 0;
  left: 0;
  width: 200%;
  height: 62%;
  background-image:
    radial-gradient(1.5px 1.5px at 24px 28px, #fff, transparent),
    radial-gradient(1px 1px at 74px 62px, rgba(255,255,255,0.85), transparent),
    radial-gradient(2px 2px at 128px 40px, #fff, transparent),
    radial-gradient(1px 1px at 178px 84px, rgba(255,255,255,0.7), transparent),
    radial-gradient(1.5px 1.5px at 226px 52px, #fff, transparent),
    radial-gradient(1px 1px at 44px 104px, rgba(255,255,255,0.75), transparent),
    radial-gradient(1.5px 1.5px at 104px 120px, #fff, transparent),
    radial-gradient(1px 1px at 200px 16px, rgba(255,255,255,0.8), transparent);
  background-repeat: repeat-x;
  background-size: 240px 100%;
  opacity: 0.85;
  pointer-events: none;
  will-change: transform;
  animation: roofDrift 40s linear infinite;
}

/* Луна */
.roof__moon {
  position: absolute;
  top: 26px;
  right: 60px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, #fffbe8 0%, #ffe9a8 55%, #e8c96b 100%);
  box-shadow: 0 0 40px rgba(255, 230, 160, 0.55);
  pointer-events: none;
  z-index: 0;
}

/* Параллакс: силуэты ночного города */
.roof__skyline {
  position: absolute;
  left: 0;
  bottom: 46px;
  width: 200%;
  height: 170px;
  background-image:
    linear-gradient(#0b1330, #0b1330),
    linear-gradient(#101838, #101838),
    linear-gradient(#0d1533, #0d1533),
    radial-gradient(circle 1.5px at 18px 22px, rgba(255, 214, 120, 0.85) 99%, transparent 100%),
    radial-gradient(circle 1.5px at 60px 46px, rgba(255, 214, 120, 0.65) 99%, transparent 100%),
    radial-gradient(circle 1.5px at 120px 30px, rgba(150, 200, 255, 0.7) 99%, transparent 100%);
  background-repeat: repeat-x;
  background-size: 240px 110px, 180px 80px, 144px 130px, 120px 170px, 120px 170px, 120px 170px;
  background-position: 0 bottom, 90px bottom, 200px bottom, 0 bottom, 0 bottom, 60px bottom;
  opacity: 0.9;
  pointer-events: none;
  will-change: transform;
  animation: roofDrift 30s linear infinite;
  z-index: 0;
}

.obstacle-game__ground {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 46px;
  background: linear-gradient(180deg,
    #2b3550 0%,
    #1c2540 45%,
    #121a30 100%
  );
  border-top: 2px solid #4a6a9a;
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.45);
  z-index: 1;
}

/* Параллакс: ближняя черепица крыши (быстрый скролл) */
.obstacle-game__ground::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 200%;
  height: 100%;
  background: repeating-linear-gradient(92deg,
    transparent 0 11px,
    rgba(90, 130, 200, 0.18) 11px 12px,
    transparent 12px 24px
  );
  pointer-events: none;
  will-change: transform;
  animation: roofDrift 6s linear infinite;
}

.obstacle-game__cat {
  position: absolute;
  left: 90px;
  bottom: 44px;
  width: 112px;
  height: 80px;
  transform-origin: bottom center;
  pointer-events: none;
  will-change: transform;
  z-index: 2;
}

/* ===== CSS-модель котика-бегуна (профиль, бежит вправо) ===== */
.mg-cat__art {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Хвост */
.mg-cat__tail {
  position: absolute;
  left: -6px;
  bottom: 30px;
  width: 34px;
  height: 10px;
  background: linear-gradient(90deg, #d98a2b 0%, #f5a623 100%);
  border-radius: 6px 2px 2px 6px;
  transform-origin: right center;
  animation: mgTailWag 0.6s ease-in-out infinite alternate;
  z-index: 1;
}

.mg-cat__tail::after {
  content: '';
  position: absolute;
  left: -4px;
  top: -3px;
  width: 12px;
  height: 16px;
  background: #d98a2b;
  border-radius: 50%;
}

/* Тело-«боб» */
.mg-cat__body {
  position: absolute;
  left: 18px;
  bottom: 12px;
  width: 78px;
  height: 38px;
  background: linear-gradient(180deg, #f7b551 0%, #f5a623 55%, #e0911c 100%);
  border-radius: 45% 48% 42% 40% / 65% 65% 40% 40%;
  z-index: 2;
}

/* Полосы на теле */
.mg-cat__body::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(105deg, transparent 0 34%, rgba(190, 100, 10, 0.45) 34% 40%, transparent 40%),
    linear-gradient(105deg, transparent 0 54%, rgba(190, 100, 10, 0.4) 54% 60%, transparent 60%),
    linear-gradient(105deg, transparent 0 74%, rgba(190, 100, 10, 0.35) 74% 80%, transparent 80%);
  border-radius: inherit;
}

/* Голова */
.mg-cat__head {
  position: absolute;
  left: 76px;
  bottom: 24px;
  width: 34px;
  height: 34px;
  background: linear-gradient(180deg, #f7b551 0%, #f5a623 100%);
  border-radius: 48% 52% 50% 50%;
  z-index: 3;
}

/* Ухо */
.mg-cat__ear {
  position: absolute;
  top: -9px;
  left: 5px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 14px solid #e0911c;
  transform: rotate(-12deg);
}

/* Глаз */
.mg-cat__eye {
  position: absolute;
  top: 11px;
  left: 16px;
  width: 7px;
  height: 8px;
  background: #2b2b2b;
  border-radius: 50%;
  animation: mgCatBlink 4.5s ease-in-out infinite;
}

.mg-cat__eye::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  width: 2.5px;
  height: 2.5px;
  background: #fff;
  border-radius: 50%;
}

/* Носик */
.mg-cat__nose {
  position: absolute;
  top: 20px;
  left: 27px;
  width: 6px;
  height: 5px;
  background: #ff9d9d;
  border-radius: 50% 50% 45% 45%;
}

/* Усики */
.mg-cat__whiskers {
  position: absolute;
  top: 20px;
  left: 33px;
  width: 16px;
  height: 2px;
  background: #8a5a20;
  box-shadow: 0 -5px 0 #8a5a20, 0 5px 0 #8a5a20;
  border-radius: 2px;
  opacity: 0.75;
}

/* Лапы */
.mg-cat__leg {
  position: absolute;
  bottom: 2px;
  width: 9px;
  height: 22px;
  background: linear-gradient(180deg, #e0911c 0%, #f5a623 100%);
  border-radius: 4px 4px 3px 3px;
  transform-origin: top center;
  z-index: 2;
}

.mg-cat__leg--back-far { left: 34px; background: #d98a2b; z-index: 1; }
.mg-cat__leg--front-far { left: 78px; background: #d98a2b; z-index: 1; }
.mg-cat__leg--back-near { left: 26px; }
.mg-cat__leg--front-near { left: 86px; }

/* Бег: лапы в антифазе */
.mg-cat__leg--front-near,
.mg-cat__leg--back-far {
  animation: mgLegRun 0.4s ease-in-out infinite alternate;
}

.mg-cat__leg--front-far,
.mg-cat__leg--back-near {
  animation: mgLegRun 0.4s ease-in-out infinite alternate-reverse;
}

@keyframes mgLegRun {
  from { transform: rotate(24deg); }
  to { transform: rotate(-24deg); }
}

@keyframes mgTailWag {
  from { transform: rotate(-8deg); }
  to { transform: rotate(12deg); }
}

@keyframes mgCatBlink {
  0%, 92%, 100% { transform: scaleY(1); }
  96% { transform: scaleY(0.1); }
}

/* Поза прыжка: лапы поджаты, ухо назад, хвост вверх */
.mg-cat--jump .mg-cat__leg { animation: none; }
.mg-cat--jump .mg-cat__leg--front-near,
.mg-cat--jump .mg-cat__leg--front-far { transform: rotate(-58deg); }
.mg-cat--jump .mg-cat__leg--back-near,
.mg-cat--jump .mg-cat__leg--back-far { transform: rotate(58deg); }
.mg-cat--jump .mg-cat__tail { animation: none; transform: rotate(-40deg); }
.mg-cat--jump .mg-cat__ear { transform: rotate(-40deg); }

/* Поза приседа: лапы разведены, голова ниже */
.mg-cat--duck .mg-cat__leg { animation: none; }
.mg-cat--duck .mg-cat__leg--front-near,
.mg-cat--duck .mg-cat__leg--front-far { transform: rotate(30deg); }
.mg-cat--duck .mg-cat__leg--back-near,
.mg-cat--duck .mg-cat__leg--back-far { transform: rotate(-30deg); }
.mg-cat--duck .mg-cat__head { transform: translateY(5px); }
.mg-cat--duck .mg-cat__tail { animation: none; transform: rotate(16deg); }

/* Провал: котик спотыкается и заваливается набок */
.mg-cat--fall {
  animation: mgCatFall 0.55s ease-in forwards;
}

@keyframes mgCatFall {
  0% { transform: rotate(0) translateY(0); }
  35% { transform: rotate(-16deg) translateY(-8px); }
  70% { transform: rotate(-30deg) translateY(2px); }
  100% { transform: rotate(-34deg) translateY(6px); }
}

/* Котик-победитель: прыгает и сияет золотом */
.obstacle-game__cat--win {
  z-index: 3;
  animation: catWin 0.7s ease-in-out infinite;
}

.obstacle-game__cat--win .mg-cat__art,
.obstacle-game__cat--exit .mg-cat__art {
  filter: drop-shadow(0 0 14px rgba(255, 215, 0, 0.95));
}

@keyframes catWin {
  0%, 100% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-26px) scale(1.16); }
  60% { transform: translateY(0) scale(1.05); }
}

/* Котик упрыгивает в сторону, уступая подарку при переходе к письму */
.obstacle-game__cat--exit {
  z-index: 3;
  animation: catExit 1s cubic-bezier(0.4, 0, 0.3, 1) forwards;
  pointer-events: none;
}

@keyframes catExit {
  /* Старт — поза пика catWin, чтобы не было рывка при смене анимации */
  0%   { transform: translate(0, -26px) scale(1.16); opacity: 1; }
  32%  { transform: translate(-62px, -48px) scale(1.05); opacity: 1; }
  66%  { transform: translate(-150px, -8px) scale(0.92); opacity: 0.9; }
  100% { transform: translate(-240px, -18px) scale(0.7); opacity: 0; }
}

.obstacle-game__goal {
  position: absolute;
  left: 0;
  bottom: 38px;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.3s ease;
  will-change: transform;
}

.obstacle-game__goal--visible {
  opacity: 1;
}

/* Финиш: подарочная коробка с лентой и бантом.
   Крышка вынесена отдельно, чтобы открываться на переходе к письму */
.mg-gift {
  position: relative;
  width: 63px;
  height: 58px;
  transition: filter 0.6s ease;
}

.mg-gift__box {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 63px;
  height: 46px;
  background: linear-gradient(180deg, #ff6b9d 0%, #e04d7e 100%);
  border-radius: 6px;
  box-shadow: 0 0 20px rgba(255, 120, 170, 0.65);
}

/* Вертикальная лента на коробке и крышке */
.mg-gift__box::before,
.mg-gift__lid::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 12px;
  margin-left: -6px;
  background: #ffd700;
}

/* Светящаяся щель под приподнятой крышкой */
.mg-gift__box::after {
  content: '';
  position: absolute;
  left: 2px;
  right: 2px;
  top: -6px;
  height: 0;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 100%, rgba(255, 250, 220, 0.95), transparent 72%);
  opacity: 0;
  pointer-events: none;
  transition: height 0.9s ease-in-out, opacity 0.9s ease-in-out;
}

.mg-gift--open .mg-gift__box::after {
  height: 30px;
  opacity: 1;
}

.mg-gift__lid {
  position: absolute;
  left: -2px;
  top: 0;
  width: 67px;
  height: 16px;
  background: linear-gradient(180deg, #ff7fa9 0%, #e04d7e 100%);
  border-radius: 5px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  transform-origin: left bottom;
  transition: transform 1.1s cubic-bezier(0.45, 0, 0.25, 1);
  z-index: 2;
}

/* Бант на крышке */
.mg-gift__lid::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -13px;
  width: 34px;
  height: 16px;
  margin-left: -17px;
  background:
    radial-gradient(circle at 26% 60%, #ffd700 0 46%, transparent 47%),
    radial-gradient(circle at 74% 60%, #ffd700 0 46%, transparent 47%);
}

.mg-gift--open .mg-gift__lid {
  transform: translateY(-30px) rotate(-16deg);
}

/* Подарок «дышит» свечением перед раскрытием */
.mg-gift--glow {
  animation: giftBreath 1.6s ease-in-out infinite;
}

@keyframes giftBreath {
  0%, 100% { filter: drop-shadow(0 0 10px rgba(255, 215, 120, 0.5)); }
  50% { filter: drop-shadow(0 0 26px rgba(255, 228, 150, 0.95)); }
}

/* На раскрытии подарок «выдыхает» — пульсация замирает на ярком свечении */
.mg-gift--glow.mg-gift--open {
  animation: none;
  filter: drop-shadow(0 0 26px rgba(255, 228, 150, 0.95));
}

.obstacle-game__obstacle {
  position: absolute;
  left: 0;
  z-index: 1;
  will-change: transform;
}

.obstacle-game__obstacle--ground {
  bottom: 38px;
}

.obstacle-game__obstacle--air {
  bottom: 84px;
}

/* --- Наземные препятствия (перепрыгнуть) --- */
/* Силуэт каждого равен хитбоксу, чтобы не было попаданий «об воздух» */

.obstacle-game__obstacle--chimney {
  width: 37px;
  height: 52px;
  background: repeating-linear-gradient(0deg,
    #7a4a34 0 11px,
    #8a5740 11px 13px
  );
  border-radius: 3px 3px 0 0;
}

/* Колпак трубы — в границах силуэта */
.obstacle-game__obstacle--chimney::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 11px;
  background: #5c3524;
  border-radius: 3px 3px 0 0;
}

.obstacle-game__obstacle--vent {
  width: 43px;
  height: 49px;
  background-color: #3a4256;
  background-image: repeating-linear-gradient(0deg,
    transparent 0 6px,
    rgba(0, 0, 0, 0.35) 6px 7px
  );
  border-radius: 6px 6px 0 0;
  box-shadow: inset 0 0 0 3px #2a3140;
}

/* Спутниковая тарелка */
.obstacle-game__obstacle--satellite {
  width: 48px;
  height: 46px;
}

.obstacle-game__obstacle--satellite::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 0;
  width: 38px;
  height: 34px;
  border-radius: 50% 50% 48% 52%;
  background: radial-gradient(circle at 38% 34%, #dfe8f7 0%, #9fb2d0 55%, #6f83a6 100%);
  box-shadow: inset 0 0 0 3px #586b8c;
  transform: rotate(-22deg);
}

.obstacle-game__obstacle--satellite::after {
  content: '';
  position: absolute;
  left: 19px;
  bottom: 0;
  width: 9px;
  height: 17px;
  background: #6f83a6;
  border-radius: 2px;
  box-shadow: 0 0 0 3px rgba(60, 74, 100, 0.55);
}

/* --- Воздушные препятствия (пригнуться) --- */

/* Бельевая верёвка */
.obstacle-game__obstacle--laundry {
  width: 84px;
  height: 66px;
}

.obstacle-game__obstacle--laundry::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 4px;
  height: 4px;
  background: #dbe4f2;
  border-radius: 2px;
}

.obstacle-game__obstacle--laundry::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 8px;
  width: 76px;
  height: 58px;
  background: repeating-linear-gradient(90deg,
    #7fd8ff 0 14px,
    transparent 14px 20px,
    #ff9ec4 20px 34px,
    transparent 34px 40px,
    #ffd166 40px 54px,
    transparent 54px 60px,
    #a0e8b0 60px 74px
  );
  border-radius: 0 0 10px 10px;
  box-shadow: inset 0 -6px 10px rgba(0, 0, 0, 0.12);
}

/* Голубь */
.obstacle-game__obstacle--bird {
  width: 52px;
  height: 38px;
  background: radial-gradient(ellipse 18px 13px at 50% 60%, #cdd7ea 99%, transparent 100%);
}

.obstacle-game__obstacle--bird::before,
.obstacle-game__obstacle--bird::after {
  content: '';
  position: absolute;
  top: 8px;
  width: 30px;
  height: 10px;
  background: #cdd7ea;
  border-radius: 50%;
}

.obstacle-game__obstacle--bird::before {
  left: 0;
  transform: rotate(-22deg);
}

.obstacle-game__obstacle--bird::after {
  right: 0;
  transform: rotate(22deg);
}

/* Гирлянда с огоньками — низко висит, надо пригнуться */
.obstacle-game__obstacle--garland {
  width: 92px;
  height: 46px;
}

.obstacle-game__obstacle--garland::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 2px;
  height: 18px;
  border-top: 3px solid #cfd8ea;
  border-radius: 50%;
}

.obstacle-game__obstacle--garland::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 8px;
  height: 26px;
  background:
    radial-gradient(circle 5px at 10px 8px, #ffd166 99%, transparent 100%),
    radial-gradient(circle 5px at 26px 15px, #ff9ec4 99%, transparent 100%),
    radial-gradient(circle 5px at 42px 18px, #7fd8ff 99%, transparent 100%),
    radial-gradient(circle 5px at 58px 18px, #a0e8b0 99%, transparent 100%),
    radial-gradient(circle 5px at 74px 15px, #ffd166 99%, transparent 100%);
  filter: drop-shadow(0 0 5px rgba(255, 214, 120, 0.6));
}

/* Летучая мышь — качается, ловить момент приседа */
.obstacle-game__obstacle--bat {
  width: 48px;
  height: 34px;
  background: radial-gradient(ellipse 12px 10px at 50% 55%, #2f3550 99%, transparent 100%);
}

.obstacle-game__obstacle--bat::before,
.obstacle-game__obstacle--bat::after {
  content: '';
  position: absolute;
  top: 8px;
  width: 22px;
  height: 15px;
  background: #2f3550;
}

.obstacle-game__obstacle--bat::before {
  left: 0;
  border-radius: 62% 22% 40% 40% / 72% 42% 60% 30%;
  transform: rotate(-8deg);
  animation: batWingLeft 0.5s ease-in-out infinite alternate;
  transform-origin: right center;
}

.obstacle-game__obstacle--bat::after {
  right: 0;
  border-radius: 22% 62% 40% 40% / 42% 72% 30% 60%;
  transform: rotate(8deg);
  animation: batWingRight 0.5s ease-in-out infinite alternate;
  transform-origin: left center;
}

@keyframes batWingLeft {
  from { transform: rotate(-16deg) scaleY(1); }
  to { transform: rotate(6deg) scaleY(0.6); }
}

@keyframes batWingRight {
  from { transform: rotate(16deg) scaleY(1); }
  to { transform: rotate(-6deg) scaleY(0.6); }
}

/* --- Бонус-сердечко --- */
.obstacle-game__heart {
  position: absolute;
  left: 0;
  width: 26px;
  height: 26px;
  z-index: 2;
  pointer-events: none;
  will-change: transform;
}

.obstacle-game__heart--ground { bottom: 72px; }
.obstacle-game__heart--air { bottom: 138px; }

.obstacle-game__heart-art {
  display: block;
  font-size: 1.35rem;
  line-height: 26px;
  text-align: center;
  filter: drop-shadow(0 0 8px rgba(255, 210, 90, 0.75));
  animation: heartFloat 1.4s ease-in-out infinite;
}

.obstacle-game__heart--collected .obstacle-game__heart-art {
  animation: heartCollect 0.34s ease-out forwards;
}

@keyframes heartFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-6px) scale(1.08); }
}

@keyframes heartCollect {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.8); opacity: 0; }
}

/* --- Пыль/искры от лап --- */
.mg-dust {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(220, 228, 245, 0.85);
  pointer-events: none;
  z-index: 3;
  will-change: transform, opacity;
  animation: mgDust 0.62s ease-out forwards;
}

@keyframes mgDust {
  0% { transform: translate(0, 0) scale(1); opacity: 0.9; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.3); opacity: 0; }
}

/* ===== Анимации мини-игры: ночные крыши ===== */
@keyframes roofDrift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-50%, 0, 0); }
}

/* ===== Слой 3: Письмо ===== */
.letter-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  overflow-y: auto;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1s ease;
  background:
    radial-gradient(ellipse at 50% 30%,
      rgba(80, 120, 200, 0.08) 0%,
      transparent 60%
    ),
    var(--color-bg-gradient);
  padding: max(20px, env(safe-area-inset-top, 0px))
           max(20px, env(safe-area-inset-right, 0px))
           max(20px, env(safe-area-inset-bottom, 0px))
           max(20px, env(safe-area-inset-left, 0px));
}

/* Тёплый свет, выливающийся из подарка при переходе к письму */
.gift-bloom {
  position: fixed;
  width: 90px;
  height: 90px;
  margin: -45px 0 0 -45px;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(255, 252, 235, 1) 0%,
    rgba(255, 232, 165, 0.96) 28%,
    rgba(255, 208, 105, 0.72) 52%,
    rgba(255, 190, 70, 0.28) 74%,
    transparent 86%);
  pointer-events: none;
  z-index: 2400;
  animation: giftBloom 3s ease-in-out forwards;
}

@keyframes giftBloom {
  0% { opacity: 0; transform: scale(0.25); }
  20% { opacity: 1; transform: scale(5); }
  36% { opacity: 1; transform: scale(26); }
  44% { opacity: 0.94; transform: scale(29); }
  60% { opacity: 0; transform: scale(31); }
  100% { opacity: 0; transform: scale(31); }
}

.letter {
  /* Масштаб письма по высоте окна: крупнее на высоких окнах, мельче на низких */
  --letter-fs: clamp(1.1rem, calc(3.6vh - 5px), 1.85rem);
  max-width: 500px;
  width: 90%;
  background:
    radial-gradient(ellipse at 20% 30%,
      rgba(255, 200, 150, 0.4) 0%, transparent 50%),
    radial-gradient(ellipse at 75% 60%,
      rgba(255, 180, 100, 0.3) 0%, transparent 45%),
    radial-gradient(ellipse at 50% 85%,
      rgba(255, 160, 120, 0.35) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 20%,
      rgba(255, 220, 180, 0.25) 0%, transparent 40%),
    linear-gradient(135deg,
      #FFF5E6 0%,
      #FFECD2 30%,
      #FFE0B2 60%,
      #FFF0DB 100%
    );
  border-radius: 16px;
  padding: 24px 30px;
  box-shadow:
    0 8px 32px rgba(255, 180, 100, 0.25),
    0 2px 8px rgba(200, 150, 80, 0.15),
    0 0 0 1px rgba(255, 200, 150, 0.3);
  position: relative;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

.letter--visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Письмо прилетает из тёплого света подарка.
   --letter-sx/--letter-sy задаёт JS по центру подарка, есть фолбэк */
.letter--from-light {
  opacity: 0;
  transform: translate(var(--letter-sx, -42vw), var(--letter-sy, 24vh)) scale(0.18) rotate(-10deg);
  filter: drop-shadow(0 0 46px rgba(255, 226, 150, 0.95));
  transition: opacity 1.1s ease, transform 1.1s cubic-bezier(0.22, 1, 0.36, 1), filter 1.1s ease;
}

.letter--from-light.letter--visible {
  opacity: 1;
  transform: translate(0, 0) scale(1) rotate(0deg);
  filter: drop-shadow(0 0 0 rgba(255, 226, 150, 0));
}

.letter--leaving {
  opacity: 0;
  transform: translateY(-12px) scale(0.98);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

/* Второе письмо — проза на прохладной бумаге */
.letter--prose {
  max-width: 660px;
  --letter-fs: clamp(1.15rem, calc(3.75vh - 5px), 1.9rem);
  background:
    radial-gradient(ellipse at 25% 20%, rgba(180, 210, 255, 0.35) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 70%, rgba(150, 190, 240, 0.28) 0%, transparent 50%),
    linear-gradient(135deg,
      #eef4ff 0%,
      #dfe9fb 35%,
      #eaf0ff 70%,
      #f4f8ff 100%);
  box-shadow:
    0 8px 32px rgba(120, 150, 220, 0.25),
    0 2px 8px rgba(80, 110, 180, 0.15),
    0 0 0 1px rgba(150, 180, 230, 0.35);
}

.letter--prose .letter__text {
  color: #2e3d5c;
  line-height: 1.65;
}

.letter--prose .letter__line {
  min-height: 1.65em;
}

.letter--prose .letter__line--break {
  min-height: 2.1em;
}

.letter--prose .letter__signature {
  color: #35548a;
}

.letter--prose .letter__cursor {
  background: #2e3d5c;
}

/* На холодной бумаге тёплый floating-декор приглушаем */
.letter-layer--prose .letter-decor {
  opacity: 0.3 !important;
  filter: saturate(0.55) brightness(0.95);
}

/* Кнопка «Открыть второе письмо» под первым письмом */
.letter__more {
  z-index: 1002;
}

.letter__more--leaving {
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Финальный акцент и перезапуск */
.letter-finale {
  position: relative;
  z-index: 1002;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
  max-width: 560px;
  padding: 48px 20px 56px;
  text-align: center;
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
  transition: opacity 1.4s ease, transform 1.4s ease;
}

/* Показ финала: opacity/pointer-events задаёт общее правило .x--visible */
.letter-finale--visible {
  transform: translateY(0);
}

.letter-finale__heart {
  font-size: 3.4rem;
  animation: decorFloat 3s ease-in-out infinite;
}

.letter-finale__text {
  margin: 0;
  font-family: var(--font-handwritten);
  font-size: 2rem;
  color: #fff5e6;
  text-shadow: 0 2px 20px rgba(255, 215, 0, 0.4);
}

.letter-finale__replay {
  z-index: 1006;
}

/* Стих чуть крупнее прозы; карточка шире, чтобы строки не переносились */
.letter:not(.letter--prose) {
  max-width: 560px;
  --letter-fs: clamp(1.15rem, calc(3.9vh - 5px), 1.95rem);
}

/* Первое письмо: колонка стиха центрёна, все строки — по одной левой границе */
.letter:not(.letter--prose) .letter__sheet {
  font-size: var(--letter-fs); /* чтобы em считались от размера письма */
  width: fit-content;          /* ширина = самая длинная строка, переносов не будет */
  min-width: 16em;             /* стабильная ширина с начала печати — без подрагивания */
  max-width: 100%;
  margin-inline: auto;         /* центрирование колонки */
}

.letter__text {
  font-family: var(--font-handwritten);
  font-size: var(--letter-fs);
  line-height: 1.5;
  color: #4a3122;
}

/* Каждая строка мягко проявляется перед печатью */
.letter__line {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.6s ease, transform 0.6s ease;
  min-height: 1.5em;
}

/* Пустая строка-строфа: компактнее обычной строки, строфы держатся вместе */
.letter__line--break {
  min-height: 1.4em;
}

.letter__line--visible {
  opacity: 1;
  transform: translateY(0);
}

/* Первая строка-обращение — чуть крупнее и плотнее */
.letter__line:first-child {
  font-size: 1.08em;
  font-weight: 600;
}

/* Заключительные строки прозы — курсив и глубже цвет */
.letter--prose .letter__line:nth-last-child(-n+2) {
  font-style: italic;
  color: #1f3557;
}

.letter__cursor {
  display: inline-block;
  width: 2px;
  height: 1.2em;
  background: #5c3d2e;
  animation: blink 0.8s step-end infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}

.letter__signature {
  margin-top: 24px;
  text-align: right;
  font-style: italic;
  font-family: var(--font-handwritten);
  font-size: calc(var(--letter-fs) * 1);
  font-weight: 600;
  color: #8a3f1e;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  transform: rotate(-1.5deg);
  transform-origin: right center;
}

/* Тонкая дуга-росчерк под подписью */
.letter__signature::after {
  content: '';
  display: block;
  width: 62%;
  height: 8px;
  margin-left: auto;
  border-bottom: 2px solid currentColor;
  border-radius: 50%;
  opacity: 0.5;
}

@keyframes catSway {
  0%, 100% { transform: rotate(-3deg) scale(1); }
  50% { transform: rotate(3deg) scale(1.025); }
}

@keyframes catBlink {
  0%, 90%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}

@keyframes catTailWag {
  0%, 100% { transform: rotate(-14deg); }
  50% { transform: rotate(18deg); }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ===== Анимации floating-декора письма ===== */
@keyframes decorFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-8px) rotate(5deg); }
  50% { transform: translateY(4px) rotate(-3deg); }
  75% { transform: translateY(-5px) rotate(2deg); }
}

/* ===== Главное меню «Космошахматы» ===== */
.menu-layer {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
  background:
    radial-gradient(circle 2px at 12% 20%, rgba(255, 255, 255, 0.9) 99%, transparent 100%),
    radial-gradient(circle 1.5px at 26% 68%, rgba(255, 255, 255, 0.75) 99%, transparent 100%),
    radial-gradient(circle 2.5px at 44% 14%, rgba(255, 255, 255, 0.85) 99%, transparent 100%),
    radial-gradient(circle 1.5px at 63% 42%, rgba(255, 255, 255, 0.7) 99%, transparent 100%),
    radial-gradient(circle 2px at 78% 72%, rgba(255, 255, 255, 0.8) 99%, transparent 100%),
    radial-gradient(circle 1.5px at 90% 28%, rgba(255, 255, 255, 0.75) 99%, transparent 100%),
    radial-gradient(circle 1.5px at 34% 86%, rgba(255, 255, 255, 0.7) 99%, transparent 100%),
    radial-gradient(circle 2px at 70% 10%, rgba(255, 255, 255, 0.8) 99%, transparent 100%),
    radial-gradient(ellipse at 50% 40%,
      rgba(80, 120, 200, 0.28) 0%,
      transparent 62%
    ),
    linear-gradient(180deg,
      #05060f 0%,
      #0a1024 50%,
      #0a1530 100%
    );
}

.menu {
  text-align: center;
  padding: 40px;
}

.menu__title {
  font-size: clamp(2rem, 9.5vw, 3.4rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 36px;
  background: linear-gradient(90deg,
    #7fd8ff 0%,
    #ffffff 35%,
    #ffd700 55%,
    #ffffff 75%,
    #7fd8ff 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: #7fd8ff;
  filter:
    drop-shadow(0 0 22px rgba(120, 200, 255, 0.55))
    drop-shadow(0 2px 10px rgba(0, 0, 0, 0.5));
  animation: textShimmer 6s linear infinite;
}

.menu__play {
  padding: 16px 54px;
  font-size: 1.3rem;
  font-weight: 600;
  font-family: var(--font-main);
  color: #fff;
  background: linear-gradient(135deg, #7fd8ff 0%, #4aa3ff 100%);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(74, 163, 255, 0.55);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: menuPlayPulse 2.4s ease-in-out infinite;
}

@media (hover: hover) {
  .menu__play:hover {
    transform: scale(1.07);
    box-shadow: 0 10px 40px rgba(74, 163, 255, 0.85);
  }
}

@keyframes menuPlayPulse {
  0%, 100% { box-shadow: 0 8px 30px rgba(74, 163, 255, 0.45); }
  50% { box-shadow: 0 8px 44px rgba(74, 163, 255, 0.85); }
}

@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
  .menu__title {
    color: #7fd8ff;
    -webkit-text-fill-color: #7fd8ff;
  }
}

/* ===== Дебаг-индикатор ===== */
.debug-indicator {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 2000;
  padding: 4px 10px;
  background: rgba(255, 0, 0, 0.7);
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
}

.debug-indicator--visible {
  display: block;
}

/* ===== Пауза анимаций в неактивных слоях ===== */
/* Пока слой скрыт, его бесконечные анимации не крутятся вхолостую */
.cats-layer:not(.cats-layer--visible),
.cats-layer:not(.cats-layer--visible) *,
.cats-layer:not(.cats-layer--visible) *::before,
.cats-layer:not(.cats-layer--visible) *::after,
.minigame-layer:not(.minigame-layer--visible),
.minigame-layer:not(.minigame-layer--visible) *,
.minigame-layer:not(.minigame-layer--visible) *::before,
.minigame-layer:not(.minigame-layer--visible) *::after,
.letter-layer:not(.letter-layer--visible),
.letter-layer:not(.letter-layer--visible) *,
.letter-layer:not(.letter-layer--visible) *::before,
.letter-layer:not(.letter-layer--visible) *::after,
.menu-layer:not(.menu-layer--visible),
.menu-layer:not(.menu-layer--visible) *,
.menu-layer:not(.menu-layer--visible) *::before,
.menu-layer:not(.menu-layer--visible) *::after {
  animation-play-state: paused !important;
}

/* Небо закрыто непрозрачным слоем мини-игры — звёзды можно не анимировать */
.sky--paused .sky__star {
  animation-play-state: paused !important;
}

/* Непрозрачные слои меню/мини-игры/письма перекрывают звёздный фон body —
   не крутим его twinkle вхолостую (слой котиков прозрачный — его не трогаем) */
body.body--stars-paused::before {
  animation-play-state: paused !important;
}

/* Видимые состояния слоёв: показ и кликабельность.
   Правило стоит в конце файла, чтобы перебивать opacity: 0 базовых правил слоёв. */
.sky--visible,
.cats-layer--visible,
.cat-dialog--visible,
.minigame-layer--visible,
.minigame__fail--visible,
.letter-layer--visible,
.letter-finale--visible,
.menu-layer--visible {
  opacity: 1;
  pointer-events: auto;
}

/* ===== Адаптив: узкие экраны (телефоны) ===== */
@media (max-width: 560px) {
  body {
    padding: 12px;
  }

  /* Доска чуть крупнее — клетки удобнее для пальца */
  :root {
    --board-size: min(480px, 92vw);
  }

  .header__title {
    font-size: 1.25rem;
  }

  /* Три котика в ряд не влезают по ширине — уменьшаем ряд, зазор и венок цветов.
     transform не конфликтует с анимацией приземления на самих котиках. */
  .cats-row {
    gap: 14px;
    transform: scale(0.82);
    transform-origin: center bottom;
  }

  .cat__flowers {
    font-size: 0.88rem;
    gap: 0;
  }

  .cats-layer {
    overflow-x: hidden;
  }

  /* Письмо: меньше отступы, стих не должен вылезать за карточку */
  .letter {
    width: 100%;
    padding: 18px 14px;
  }

  .letter:not(.letter--prose) {
    --letter-fs: clamp(0.95rem, 4.6vw, 1.5rem);
  }

  .letter:not(.letter--prose) .letter__sheet {
    min-width: 9em;
  }

  .letter-finale {
    padding: 32px 14px 40px;
  }

  .letter-finale__heart {
    font-size: 2.6rem;
  }

  .letter-finale__text {
    font-size: clamp(1.4rem, 6vw, 2rem);
  }

  .minigame__title {
    font-size: 1.15rem;
    padding: 0 12px;
  }

  .minigame__hint {
    font-size: 0.82rem;
    padding: 0 12px;
    text-align: center;
  }

  .minigame__fail-card {
    max-width: calc(100vw - 32px);
    padding: 24px 22px;
  }

  .cat-dialog__content {
    padding: 28px 20px;
  }

  .cat-dialog__text {
    font-size: 1.1rem;
  }
}

/* Низкие окна (ландшафт телефона): не даём вертикальным отступам съесть сцену */
@media (max-height: 520px) {
  .minigame__title {
    font-size: 1.05rem;
    margin-bottom: 6px;
  }

  .minigame__hint {
    font-size: 0.8rem;
    margin-bottom: 8px;
  }

  .mg-controls__btn {
    width: 64px;
    height: 64px;
    font-size: 1.7rem;
  }
}

