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

/* ---------- Оттенок игры ---------- */
/*
 * Это небо у земли — рассвет. С высотой scene.js меняет небо, а app.js вслед за ним — эти же переменные
 * и <meta name="theme-color">: голубой день, закат, ночь. Верх фона (--bg-top) повторён в theme-color.
 */
:root {
  --bg-top: #f46e40;
  --bg-mid: #fb8c45;
  --bg-bottom: #ffc45f;
  --glow-a: rgba(255, 236, 170, 0.3);
  --glow-b: rgba(255, 120, 96, 0.3);
  --frame: #ff8a3d;
  --frame-lip: #7e2414;
  --pit: #b5412a;
  --shade-rgb: 92, 26, 34;
  --deep-rgb: 138, 44, 34;
  --title-hi: #ffe7c2;
}

/* ---------- Холст: небо и башня под меню и игрой ---------- */

.scene {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 0;
  pointer-events: none;
}

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

.app {
  z-index: 1;
}

/* Сцена прозрачная: башня — на холсте под ней. Касание работает по всему экрану. */
.stage {
  cursor: pointer;
  outline: none;
  touch-action: none;
}

/* С клавиатуры фокус на сцене виден: белая рамка внутри её границ. */
.stage:focus-visible {
  border-radius: 22px;
  box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 6px rgba(var(--deep-rgb), 0.55);
}

.app,
.tw-fx {
  touch-action: none;
}

/* Кнопки шапки — с тёмной подложкой: их видно и на белом облаке, и на ночном небе. */
.top .hud-btn {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.12)),
    rgba(var(--deep-rgb), 0.36);
}

.top .pill {
  background: rgba(var(--deep-rgb), 0.62);
}

/* Счёт читается и на белом облаке: тёмная обводка со всех сторон и мягкая тень-подложка за цифрами. */
.tally {
  position: relative;
}

.tally::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -22px;
  width: 250px;
  height: 126px;
  margin-left: -125px;
  background: radial-gradient(closest-side, rgba(var(--deep-rgb), 0.46) 0%, rgba(var(--deep-rgb), 0.26) 45%, rgba(var(--deep-rgb), 0) 100%);
  pointer-events: none;
}

.score,
.sub {
  position: relative;
}

.score {
  text-shadow:
    2px 0 0 rgba(var(--deep-rgb), 0.9),
    -2px 0 0 rgba(var(--deep-rgb), 0.9),
    0 -2px 0 rgba(var(--deep-rgb), 0.9),
    1.5px 1.5px 0 rgba(var(--deep-rgb), 0.9),
    -1.5px 1.5px 0 rgba(var(--deep-rgb), 0.9),
    1.5px -1.5px 0 rgba(var(--deep-rgb), 0.9),
    -1.5px -1.5px 0 rgba(var(--deep-rgb), 0.9),
    0 5px 0 rgba(var(--deep-rgb), 0.9),
    0 10px 18px rgba(var(--shade-rgb), 0.4);
}

.foot {
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  text-shadow: 0 2px 0 rgba(var(--shade-rgb), 0.6);
}

/* Итог показан: счёт и подпись уходят, чтобы башню было видно целиком. */
.tally,
.foot {
  transition: opacity 0.3s ease-out;
}

.tw-over .tally,
.tw-over .foot {
  opacity: 0;
}

/* ---------- Значок в меню: башня строит сама себя ---------- */

.tw-logo {
  flex: none;
  width: 210px;
  height: 200px;
  margin-bottom: -4px;
}

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

.menu .title {
  margin-top: 0;
}

.menu .menu-actions {
  margin-top: 34px;
}

@media (max-height: 620px) {
  .tw-logo {
    width: 160px;
    height: 150px;
    margin-bottom: -4px;
  }

  .menu .menu-actions {
    margin-top: 22px;
  }
}

/* ---------- Слой надписей поверх игры ---------- */

.tw-fx {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: hidden;
  pointer-events: none;
}

/* Похвала — между счётом и башней, чтобы не закрывать блок. */
.tw-fx .praise {
  top: 38%;
  font-size: min(36px, 9.6vw);
}

/* «+N» — жёлтое с тёмной обводкой: видно и на светлой крыше блока. */
.tw-fx .gain {
  color: #ffd23a;
  font-size: 34px;
  text-shadow:
    2px 0 0 #5a2c00,
    -2px 0 0 #5a2c00,
    0 -2px 0 #5a2c00,
    1.5px 1.5px 0 #5a2c00,
    -1.5px 1.5px 0 #5a2c00,
    1.5px -1.5px 0 #5a2c00,
    -1.5px -1.5px 0 #5a2c00,
    0 4px 0 #5a2c00,
    0 8px 12px rgba(var(--shade-rgb), 0.5);
}

/* Новая часть неба: плашка со значком выезжает под счётом. */
.tw-banner {
  position: absolute;
  left: 50%;
  top: 25%; /* точное место ставит app.js: сразу под счётом и меткой серии */
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px 0 12px;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff, #e9f1ff);
  box-shadow: inset 0 -3px 0 rgba(20, 40, 120, 0.16), 0 4px 0 rgba(var(--shade-rgb), 0.55), 0 12px 20px rgba(var(--shade-rgb), 0.35);
  color: #1b2a6b;
  font-size: 18px;
  font-weight: 900;
  white-space: nowrap;
  transform: translate(-50%, 0);
  animation: tw-banner 2.1s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}

.tw-banner svg {
  width: 24px;
  height: 24px;
}

.tw-banner.z1 svg { fill: #2f8fee; }
.tw-banner.z2 svg { fill: #e0559a; }
.tw-banner.z3 svg { fill: #5a4fd0; }
.tw-banner.z4 svg { fill: #f2a80c; }

@keyframes tw-banner {
  0% { opacity: 0; transform: translate(-50%, 18px) scale(0.6); }
  12% { opacity: 1; transform: translate(-50%, 0) scale(1.08); }
  20% { transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, 6px) scale(0.9); }
}

/* Меньше движения: плашка просто показывается на полторы секунды (k-hold — из набора). */
@media (prefers-reduced-motion: reduce) {
  .tw-banner {
    animation: k-hold 1.6s linear both !important;
  }
}

/* Подсказка первого запуска: рука касается экрана, от пальца расходятся круги. */
.tw-hand {
  position: absolute;
  /* Место ставит app.js: справа от башни, под краем плиты. */
  left: 70%;
  top: 78%;
  width: 72px;
  height: 72px;
  opacity: 0;
  transition: opacity 0.25s ease-out;
}

.tw-hint .tw-hand {
  opacity: 1;
}

.tw-hand i {
  position: absolute;
  left: 9px;
  top: -6px;
  width: 44px;
  height: 44px;
  border: 3px solid #fff;
  border-radius: 50%;
  opacity: 0;
}

.tw-hint .tw-hand i {
  animation: tw-ripple 1.4s ease-out infinite;
}

.tw-hint .tw-hand i + i {
  animation-delay: 0.18s;
}

.tw-hand svg {
  position: absolute;
  left: 12px;
  top: 10px;
  width: 54px;
  height: 54px;
  fill: #fff;
  stroke: rgba(var(--shade-rgb), 0.85);
  stroke-width: 1.1;
  stroke-linejoin: round;
  filter: drop-shadow(0 3px 0 rgba(var(--shade-rgb), 0.5));
  transform-origin: 40% 0;
}

.tw-hint .tw-hand svg {
  animation: tw-press 1.4s ease-in-out infinite;
}

@keyframes tw-press {
  0%, 46%, 100% { transform: translateY(6px); }
  14% { transform: translateY(0) scale(0.92); }
  26% { transform: translateY(0) scale(0.92); }
}

@keyframes tw-ripple {
  0%, 14% { opacity: 0; transform: scale(0.25); }
  22% { opacity: 0.95; }
  62%, 100% { opacity: 0; transform: scale(1.45); }
}

@media (max-height: 620px) {
  /* На низком экране похвала ниже, чтобы не задевать плашку части неба. */
  .tw-fx .praise {
    top: 45%;
  }

  .tw-hand {
    transform: scale(0.82);
    transform-origin: 50% 0;
  }
}

/* ---------- Окно итога: карточка внизу, над ней — вся башня ---------- */

.over.tw-result {
  align-items: flex-end;
  background: linear-gradient(180deg, rgba(var(--shade-rgb), 0) 0%, rgba(var(--shade-rgb), 0.1) 34%, rgba(var(--shade-rgb), 0.62) 100%);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.over.tw-result .card {
  margin-bottom: 10px;
  padding: 16px 16px 18px;
  animation: tw-card 0.5s cubic-bezier(0.2, 1.25, 0.4, 1) both;
}

@keyframes tw-card {
  from { opacity: 0; transform: translateY(70px) scale(0.92); }
}

.tw-result .over-score {
  font-size: min(64px, 17vw);
}

.tw-result .over-actions {
  margin-top: 14px;
}

.tw-stats {
  display: flex;
  gap: 8px;
  width: 100%;
  margin-top: 12px;
}

.tw-stats div {
  flex: 1 1 0;
  min-width: 0;
  padding: 7px 4px 6px;
  border-radius: 15px;
  background: rgba(var(--shade-rgb), 0.42);
  box-shadow: inset 0 2px 4px rgba(var(--shade-rgb), 0.55), 0 1px 0 rgba(255, 255, 255, 0.14);
}

.tw-stats b {
  display: block;
  font-size: 21px;
  font-weight: 900;
  line-height: 23px;
  font-variant-numeric: tabular-nums;
}

.tw-stats span {
  display: block;
  overflow: hidden;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
  line-height: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Пять частей неба: пройденные — цветные фишки, остальные — пустые лунки. */
.tw-zones {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: 13px;
}

.tw-zones i {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(var(--shade-rgb), 0.45);
  box-shadow: inset 0 2px 4px rgba(var(--shade-rgb), 0.6), 0 1px 0 rgba(255, 255, 255, 0.14);
}

.tw-zones svg {
  width: 20px;
  height: 20px;
  fill: rgba(255, 255, 255, 0.24);
}

.tw-zones i.on {
  background:
    radial-gradient(70% 55% at 32% 18%, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0) 70%),
    linear-gradient(170deg, var(--z-hi), var(--z-lo));
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5), inset 0 -3px 0 rgba(0, 0, 0, 0.18), 0 3px 0 var(--z-lip);
}

.tw-zones i.on svg {
  fill: #fff;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.2));
}

.tw-zones .z0 { --z-hi: #ffc84a; --z-lo: #ff8a2a; --z-lip: #b3520c; }
.tw-zones .z1 { --z-hi: #5cc8ff; --z-lo: #2a8cf0; --z-lip: #0c50a8; }
.tw-zones .z2 { --z-hi: #ff8a9a; --z-lo: #c9409e; --z-lip: #7a1c66; }
.tw-zones .z3 { --z-hi: #8a7cf0; --z-lo: #4a3cc0; --z-lip: #261a78; }
.tw-zones .z4 { --z-hi: #4a4f9a; --z-lo: #1a1d58; --z-lip: #080a2c; }

.tw-zones .z4.on svg {
  fill: #ffd84a;
}

.tw-zones i.now {
  animation: tw-zone 0.6s 0.45s cubic-bezier(0.3, 1.8, 0.5, 1) both;
}

@keyframes tw-zone {
  from { transform: scale(0.3); }
}

/* Часть неба, до которой дошли, — с подписью: фишка вытянута в плашку. */
.tw-zones i.now {
  width: auto;
  padding: 0 12px 0 8px;
  border-radius: 18px;
  gap: 5px;
}

.tw-zones i span {
  color: #fff;
  font-size: 13.5px;
  font-style: normal;
  font-weight: 800;
  line-height: 18px;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

/* Кнопки окна и кнопка языка — не меньше 44 px: в них попадают пальцем. */
.tw-result .over-actions .btn-ghost {
  height: 44px;
  padding: 0 16px;
}

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

@media (max-height: 620px) {
  .over.tw-result .card {
    padding: 10px 16px 14px;
  }

  .tw-result .over-score {
    font-size: 44px;
  }

  /* Башне над окном нужно место: «Рекорд N» скрыт (он есть в шапке), остаётся только золотая плашка нового рекорда. */
  .tw-result .over-note:not(.record) {
    display: none;
  }

  .tw-stats {
    margin-top: 6px;
  }

  /* Число и подпись — в одну строку. */
  .tw-stats div {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 5px;
    padding: 4px 4px;
  }

  .tw-stats b {
    font-size: 17px;
    line-height: 22px;
  }

  .tw-zones {
    gap: 7px;
    margin-top: 8px;
  }

  .tw-zones i {
    width: 28px;
    height: 28px;
  }

  .tw-zones svg {
    width: 16px;
    height: 16px;
  }

  .tw-result .over-title {
    font-size: 16px;
    line-height: 19px;
  }

  .tw-result .over-actions {
    gap: 8px 8px;
    margin-top: 10px;
  }

  .tw-result .over-actions .btn-gold {
    height: 50px;
    margin-bottom: 2px;
  }
}

/* Широкий экран: окно итога справа, башня слева во всю высоту. */
@media (min-width: 860px) and (min-height: 520px) {
  .over.tw-result {
    align-items: center;
    justify-content: flex-end;
    padding-right: max(56px, 11vw);
    background: linear-gradient(90deg, rgba(var(--shade-rgb), 0) 30%, rgba(var(--shade-rgb), 0.5) 100%);
  }

  .over.tw-result .card {
    margin-bottom: 0;
    animation-name: tw-card-side;
  }
}

@keyframes tw-card-side {
  from { opacity: 0; transform: translateX(70px) scale(0.92); }
}

/* ---------- Правила: три сценки и подписи ---------- */

.over.tw-help {
  background: rgba(var(--shade-rgb), 0.5);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.tw-diagram {
  display: block;
  width: 100%;
  height: 118px;
  margin: 14px 0 0;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(var(--shade-rgb), 0.55), rgba(var(--shade-rgb), 0.3));
  box-shadow: inset 0 3px 6px rgba(var(--shade-rgb), 0.6), 0 1px 0 rgba(255, 255, 255, 0.16);
}

.tw-steps {
  display: flex;
  width: 100%;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.tw-steps li {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 0 3px;
}

.tw-steps b {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffe066, #ffbf1f);
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.6), 0 2px 0 #c97b00;
  color: #5a3100;
  font-size: 14px;
  font-weight: 900;
}

.tw-steps span {
  font-size: 14px;
  font-weight: 800;
  line-height: 17px;
  text-align: center;
  text-wrap: balance;
}

.tw-help .card .over-text {
  margin-top: 12px;
  font-size: 13.5px;
  line-height: 18px;
}

@media (max-height: 620px) {
  .tw-diagram {
    height: 96px;
    margin-top: 8px;
  }
}
