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

/* ---------- Оттенок игры ---------- */
/* Верх фона (--bg-top) повторён в <meta name="theme-color">. */
:root {
  --bg-top: #19b88a;
  --bg-mid: #0f977c;
  --bg-bottom: #08595f;
  --glow-a: rgba(204, 255, 110, 0.5);
  --glow-b: rgba(40, 190, 255, 0.36);
  --frame: #27b884;
  --frame-lip: #054439;
  --pit: #0a4b3a;
  --shade-rgb: 2, 36, 30;
  --deep-rgb: 3, 52, 44;
  --title-hi: #e2ffd0;
  --well-pad: 9px;
  --wood: #cf9550;
  --wood-hi: #f3c984;
  --wood-lo: #7d4a1b;
}

/* ---------- Фон: листья и яблоки ---------- */

.sky i.leaf {
  border-radius: 82% 8% 82% 8%;
}

.sky i.fruit {
  border-radius: 50%;
}

/* Листик на плывущем яблоке. */
.sky i.fruit::after {
  content: "";
  position: absolute;
  left: 52%;
  top: -22%;
  width: 42%;
  height: 30%;
  border-radius: 82% 8% 82% 8%;
  background: var(--c3);
}

/* ---------- Значок в меню: маленькое поле, змейка кружит вокруг яблока ---------- */

.logo.logo-snake {
  display: block;
  width: 270px;
  height: 222px;
  margin-top: 6px;
}

.logo-snake canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Название, которое длиннее обычного (туркменское), — мельче. */
.title {
  white-space: nowrap;
}

/* ---------- Меню: режимы, кнопки ---------- */

.menu-actions {
  width: min(292px, 100%);
}

.pick > button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.pick .mode-ico {
  flex: none;
  width: 19px;
  height: 19px;
  stroke-width: 2.6;
}

/* Рекорды режимов: каждый под своей кнопкой. */
.mode-bests {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: -4px 0 -2px;
}

.mode-bests[hidden] {
  display: none;
}

.mode-best {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  margin: 0;
  padding: 0 12px 0 9px;
  border-radius: 13px;
  background: var(--deep);
  font-size: 14.5px;
  font-weight: 800;
  line-height: 26px;
  font-variant-numeric: tabular-nums;
}

.mode-best.none {
  visibility: hidden;
}

.mode-best .ico {
  width: 16px;
  height: 16px;
  color: var(--c4);
}

.lang-btn {
  min-height: 44px;
}

.menu-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.menu-row .toggle {
  flex: 1 1 0;
  min-width: 0;
}

.toggle small {
  white-space: nowrap;
}

.help-btn {
  width: 52px;
  height: auto;
  min-height: 52px;
  padding: 12px;
  border-radius: 19px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.26) 0%, rgba(255, 255, 255, 0.13) 100%);
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.34), 0 4px 0 rgba(var(--deep-rgb), 0.55), 0 9px 14px rgba(var(--shade-rgb), 0.28);
}

.help-btn:active {
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.34), 0 1px 0 rgba(var(--deep-rgb), 0.55);
}

.help-btn .ico {
  width: 28px;
  height: 28px;
  margin: auto;
}

/* ---------- Счёт и метки ---------- */

.tag-apples {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-left: 6px;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.tag-apples canvas {
  display: block;
  width: 20px;
  height: 20px;
}

.tag-apples.pop {
  animation: tag-pop 0.3s cubic-bezier(0.3, 1.7, 0.5, 1);
}

@keyframes tag-pop {
  40% { transform: scale(1.22); }
}

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

.app {
  touch-action: none;
}

.well {
  --shard: 9px;
}

/* Лужайка в деревянном бортике: светлая кромка сверху, тёмная снизу — бортик выше травы. */
.board {
  width: var(--fit-w, 312px);
  height: var(--fit-h, 408px);
  border-radius: 11px;
  background: #25945b;
  box-shadow:
    0 0 0 5px var(--wood),
    0 -1.5px 0 5px var(--wood-hi),
    0 3px 0 5px var(--wood-lo);
}

/* Холст шире поля на полклетки с каждой стороны (размер и сдвиг ставит app.js): эффекты вылетают за бортик. */
.board canvas {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Очки, вылетающие из яблока, — соразмерно клетке. */
.well .gain {
  font-size: 21px;
}

/* Глубина: тень от рамки ложится на луг сверху. */
.board::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  border-radius: inherit;
  box-shadow:
    inset 0 2px 0 rgba(70, 36, 6, 0.5),
    inset 0 0 0 1px rgba(70, 36, 6, 0.45);
  pointer-events: none;
}

/* Без стен бортика нет: край поля — светящаяся кромка, за неё можно. */
.app.is-wrap .board {
  box-shadow:
    0 0 0 2px rgba(226, 255, 170, 0.85),
    0 0 14px 4px rgba(190, 255, 120, 0.45);
}

.app.is-wrap .board::after {
  box-shadow: none;
}

/* Очки за бонус — золотые и крупнее. */
.well .gain.gain-gold {
  color: #ffd83a;
  font-size: 30px;
  text-shadow:
    0 2px 0 #8a4b00,
    0 0 12px rgba(255, 200, 40, 0.65);
}

/* Подпись под полем — подсказка первого запуска: крупно и ясно. */
.foot {
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  line-height: 18px;
  text-shadow: 0 2px 0 rgba(var(--deep-rgb), 0.55);
}

/* Без стен рамка поля светится — за край можно. */
.app.is-wrap .well {
  box-shadow:
    inset 0 3px 8px rgba(var(--shade-rgb), 0.6),
    0 0 0 4px #7fdc55,
    0 -1px 0 5px rgba(255, 255, 255, 0.32),
    0 9px 0 4px var(--frame-lip),
    0 20px 30px rgba(var(--shade-rgb), 0.5),
    0 0 26px 6px rgba(190, 255, 120, 0.28);
}

/* ---------- Обратный отсчёт ---------- */

.count {
  position: absolute;
  left: 50%;
  top: 28%;
  z-index: 2;
  color: var(--c4);
  font-size: min(124px, 32vw);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow:
    0 3px 0 #fff3b8,
    0 8px 0 #a35a00,
    0 16px 26px rgba(var(--shade-rgb), 0.7);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.count.tick {
  animation: count-pop 0.56s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

@keyframes count-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-10deg); }
  22% { opacity: 1; transform: translate(-50%, -50%) scale(1.16) rotate(3deg); }
  40% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  78% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.3); }
}

/* ---------- Подсказка первого запуска: рука проводит по полю, за пальцем — светящийся след ---------- */

/* Стоит справа от столбца, по которому ползёт змейка, — рука её не закрывает. */
.swipe-tip {
  position: absolute;
  left: calc(50% + var(--cell, 24px) * 0.5 + 5px);
  top: 56%;
  z-index: 2;
  width: 132px;
  height: 76px;
  pointer-events: none;
}

.swipe-tip[hidden] {
  display: none;
}

/* След. */
.swipe-tip b {
  position: absolute;
  left: 21px;
  top: 2px;
  width: 84px;
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(90deg, rgba(214, 255, 110, 0) 0%, rgba(214, 255, 110, 0.55) 45%, #e9ff8a 100%);
  box-shadow: 0 0 10px rgba(214, 255, 110, 0.5);
  transform-origin: 0 50%;
  animation: swipe-trail 1.6s linear infinite;
}

/* Рука: кончик указательного пальца — в точке касания. */
.swipe-tip i {
  position: absolute;
  left: 0;
  top: 4px;
  width: 50px;
  height: 62px;
  animation: swipe-go 1.6s linear infinite;
}

.swipe-tip svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 4px 0 rgba(var(--shade-rgb), 0.45));
}

.swipe-tip .hand-out * {
  fill: #0a5238;
  stroke: #0a5238;
  stroke-width: 5;
  stroke-linejoin: round;
}

.swipe-tip .hand-in * {
  fill: #fff;
}

.swipe-tip .hand-line {
  fill: none;
  stroke: rgba(10, 82, 56, 0.3);
  stroke-width: 2;
  stroke-linecap: round;
}

/* 0,6 с движения из 1,6 с цикла. */
@keyframes swipe-go {
  0% { transform: translateX(0) scale(1.15); opacity: 0; animation-timing-function: ease-out; }
  10% { transform: translateX(0) scale(1); opacity: 1; animation-timing-function: cubic-bezier(0.45, 0, 0.2, 1); }
  48% { transform: translateX(84px) scale(1); opacity: 1; }
  62% { transform: translateX(84px) scale(1.08); opacity: 1; }
  74%, 100% { transform: translateX(84px) scale(1.15); opacity: 0; }
}

@keyframes swipe-trail {
  0%, 10% { transform: scaleX(0); opacity: 1; animation-timing-function: cubic-bezier(0.45, 0, 0.2, 1); }
  48% { transform: scaleX(1); opacity: 1; }
  74%, 100% { transform: scaleX(1); opacity: 0; }
}

/* ---------- «Коснитесь, чтобы начать»: партия ждёт человека ---------- */

.tap-start {
  position: absolute;
  left: 0;
  right: 0;
  top: 40%;
  z-index: 2;
  display: flex;
  justify-content: center;
  padding: 0 10px;
  pointer-events: none;
}

.tap-start[hidden] {
  display: none;
}

.tap-start span {
  padding: 10px 18px 11px;
  border-radius: 19px;
  background: linear-gradient(180deg, #ffe066 0%, #ffbf1f 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.6), 0 4px 0 #c97b00, 0 10px 16px rgba(var(--shade-rgb), 0.4);
  color: #5a3100;
  font-size: 17px;
  font-weight: 900;
  line-height: 21px;
  text-align: center;
  text-wrap: balance;
  animation: tap-pulse 1.1s ease-in-out infinite;
}

@keyframes tap-pulse {
  50% { transform: scale(1.06); }
}

/* ---------- Кнопки-стрелки под полем (включаются в меню) ---------- */

.dpad {
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, 68px);
  grid-template-rows: repeat(2, 50px);
  gap: 7px;
  justify-content: center;
  height: 107px;
  padding-bottom: 4px;
}

.dpad[hidden] {
  display: none;
}

/* С кнопками подсказка под полем не нужна — её место отдано полю. */
.has-dpad .foot {
  display: none;
}

.key {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 17px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.32) 0%, rgba(255, 255, 255, 0.15) 100%);
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.38), 0 4px 0 rgba(var(--deep-rgb), 0.62), 0 8px 12px rgba(var(--shade-rgb), 0.25);
  color: #fff;
  touch-action: none;
  transition: transform 0.05s ease-out, box-shadow 0.05s ease-out;
}

.key:active,
.key.down {
  transform: translateY(3px);
  background: linear-gradient(180deg, #ffe066 0%, #ffbf1f 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.65), 0 1px 0 #c97b00;
  color: #5a3100;
}

.key .ico {
  width: 30px;
  height: 30px;
  stroke-width: 3.2;
}

.key-up { grid-column: 2; grid-row: 1; }
.key-left { grid-column: 1; grid-row: 2; }
.key-down { grid-column: 2; grid-row: 2; }
.key-right { grid-column: 3; grid-row: 2; }

.key-right .ico { transform: rotate(90deg); }
.key-down .ico { transform: rotate(180deg); }
.key-left .ico { transform: rotate(-90deg); }

/* ---------- Итог: звёзды и яблоки ---------- */

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

.stars span {
  position: relative;
  width: 38px;
  height: 38px;
}

.stars span:nth-child(2) {
  width: 46px;
  height: 46px;
}

.stars .ico {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  color: rgba(255, 255, 255, 0.15);
}

.stars .ico.on {
  color: var(--c4);
  filter: drop-shadow(0 3px 0 #a35a00);
  animation: star-in 0.5s cubic-bezier(0.3, 1.8, 0.5, 1) both;
  animation-delay: calc(0.25s + var(--i) * 0.16s);
}

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

/* Портрет змейки над заголовком окна. */
.card .face {
  display: block;
  flex: none;
  margin: 0 0 6px;
  filter: drop-shadow(0 5px 6px rgba(var(--shade-rgb), 0.45));
  animation: face-in 0.5s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

.card .face-dead {
  animation-name: face-dizzy;
  animation-duration: 0.7s;
}

@keyframes face-in {
  from { transform: scale(0.3) rotate(-18deg); }
}

@keyframes face-dizzy {
  0% { transform: scale(0.3) rotate(-18deg); }
  45% { transform: scale(1.06) rotate(10deg); }
  70% { transform: rotate(-6deg); }
  100% { transform: rotate(0deg); }
}

/* До первой звезды: цель вместо пустого ряда серых звёзд. */
.card .to-star {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 700;
  line-height: 18px;
}

.to-star .ico {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--c4);
}

/* Тихие кнопки окна — не ниже 44 px под палец. */
.over-actions .btn-ghost {
  min-height: 44px;
}

.over-apples {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  margin-top: 6px;
  padding: 0 12px 0 7px;
  border-radius: 14px;
  background: var(--deep);
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.over-apples canvas {
  display: block;
  width: 22px;
  height: 22px;
}

.over-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

.over-chips .over-note {
  margin-top: 6px;
}

/* ---------- Справка: строки с картинками ---------- */

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

.card .help-row {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 48px;
  padding: 5px 12px 5px 6px;
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.1), 0 2px 0 rgba(var(--shade-rgb), 0.35);
  color: #fff;
  font-size: 14.5px;
  font-weight: 700;
  line-height: 18px;
  text-wrap: pretty;
}

.help-row .pic {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 13px;
  background: rgba(var(--shade-rgb), 0.5);
  box-shadow: inset 0 2px 3px rgba(var(--shade-rgb), 0.6);
  color: #d9ffb0;
}

.help-row canvas {
  display: block;
  width: 34px;
  height: 34px;
}

.help-row .ico {
  width: 22px;
  height: 22px;
  stroke-width: 2.5;
}

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

@media (max-height: 620px) {
  .logo.logo-snake {
    width: 196px;
    height: 160px;
    margin-top: 0;
  }

  .mode-bests {
    margin: -3px 0 -3px;
  }

  .mode-best {
    height: 22px;
    font-size: 13px;
    line-height: 22px;
  }

  /* Кнопки режимов — не ниже 44 px под палец. */
  .pick > button {
    min-height: 44px;
  }

  .help-list {
    gap: 5px;
    margin-top: 8px;
  }

  .card .help-row {
    min-height: 38px;
    padding: 3px 10px 3px 4px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 16px;
  }

  .help-row .pic {
    width: 32px;
    height: 32px;
    border-radius: 11px;
  }

  .help-row canvas {
    width: 28px;
    height: 28px;
  }

  /*
   * Счёт переезжает в шапку (между домиком и паузой), плашка рекорда уступает ему место:
   * вся высота достаётся полю, клетки остаются крупными. Рекорд виден в меню и в окне итога.
   */
  .top .pill {
    display: none;
  }

  /* Строка счёта поднята отрицательным отступом ровно на шапку: где бы шапка ни оказалась, счёт — в ней. */
  .tally {
    position: relative;
    z-index: 1;
    width: auto;
    height: 44px;
    margin-top: calc(-44px - var(--stack));
    flex-direction: row;
    align-items: center;
    gap: 7px;
    transform: translateX(-26px);
    pointer-events: none;
  }

  .tally .score {
    height: 44px;
    font-size: 36px;
    line-height: 44px;
  }

  .tally .sub {
    margin: 0;
  }

  #modeTag {
    display: none;
  }

  .foot {
    height: 20px;
    font-size: 15px;
    line-height: 18px;
  }

  .help-btn {
    width: 46px;
    min-height: 46px;
    padding: 10px;
    border-radius: 17px;
  }

  /* Кнопки-стрелки — в один ряд: влево, вверх, вниз, вправо. */
  .dpad {
    grid-template-columns: repeat(4, 72px);
    grid-template-rows: 50px;
    gap: 8px;
    height: 54px;
  }

  .key-left { grid-column: 1; grid-row: 1; }
  .key-up { grid-column: 2; grid-row: 1; }
  .key-down { grid-column: 3; grid-row: 1; }
  .key-right { grid-column: 4; grid-row: 1; }

  .card .face {
    margin-bottom: 3px;
  }

  .card .to-star {
    margin-top: 5px;
    font-size: 13px;
  }

  .stars {
    height: 36px;
    margin-top: 0;
  }

  .stars span {
    width: 30px;
    height: 30px;
  }

  .stars span:nth-child(2) {
    width: 36px;
    height: 36px;
  }

  .swipe-tip {
    top: 54%;
  }
}

@media (prefers-reduced-motion: reduce) {
  /* Без движения рука стоит в конце пути, след виден целиком. */
  .swipe-tip i {
    animation: none !important;
    transform: translateX(84px);
  }

  .swipe-tip b,
  .tap-start span,
  .card .face {
    animation: none !important;
  }

  .count.tick {
    animation: none !important;
    opacity: 1;
  }
}
