/* Отклик касаний и жизнь замка (docs/ANIM.md §2.9, фаза P5): нажатие на телефоне, окна с движением, фигуры замка
   (js/screens/citylife.js), дым над трубами, заряд алтаря призыва (js/anim/burst.js). Всё движение — только при обычной
   настройке движения: «уменьшить движение» (система или ?motion=0 → html.kod-still, js/ui.js) — игра выглядит как
   раньше. Размеры — в пикселях сцены 1280×720. */

/* ——— нажатие на телефоне: на сенсорном экране :hover нет, отклик — :active (сжатие и тень) ———
   только у элементов без своего transform (иначе нажатие сдвинуло бы их с места). Аудит 07.11 («анимации, анимации и
   анимации»): сжатие — за 0,06 с, отпустили — пружинит обратно с лёгким перелётом; отклик и у вкладок, фишек, стрелки
   «назад», «!» и карточек-кнопок окон (у карточек со своим :active — их правило: Доска дня, Почта, ячейки предметов) */
@media (hover: none) and (prefers-reduced-motion: no-preference) {
  html:not(.kod-still) .btn, html:not(.kod-still) .hbtn .c, html:not(.kod-still) .rbtn .c, html:not(.kod-still) .plus,
  html:not(.kod-still) .lord .portrait, html:not(.kod-still) .btn-close, html:not(.kod-still) .rally-flag .c,
  html:not(.kod-still) .bq, html:not(.kod-still) .chapter, html:not(.kod-still) .chat, html:not(.kod-still) .harvest-all,
  html:not(.kod-still) .res .r, html:not(.kod-still) .asst, html:not(.kod-still) .pick, html:not(.kod-still) .q-tab,
  html:not(.kod-still) .un-tab, html:not(.kod-still) .cht-tab, html:not(.kod-still) .lord .pill[role="button"],
  html:not(.kod-still) .btn-back, html:not(.kod-still) .btn-help, html:not(.kod-still) .bs-tab, html:not(.kod-still) .hz-chip,
  html:not(.kod-still) .rd-chips .chip, html:not(.kod-still) .rd-tabs .tab, html:not(.kod-still) button.ml-card,
  html:not(.kod-still) button.rs-tile, html:not(.kod-still) button.bs-card, html:not(.kod-still) button.hz-card,
  html:not(.kod-still) .un-dk {
    transition: transform 0.28s cubic-bezier(0.3, 1.8, 0.5, 1), filter 0.2s ease-out;
  }
  html:not(.kod-still) .btn:not(:disabled):active { transform: translateY(3px) scale(0.95); filter: brightness(0.9); }
  html:not(.kod-still) .hbtn:active .c, html:not(.kod-still) .rbtn:active .c, html:not(.kod-still) .plus:active,
  html:not(.kod-still) .lord:active .portrait, html:not(.kod-still) .btn-close:active,
  html:not(.kod-still) .rally-flag:active .c, html:not(.kod-still) .btn-back:active, html:not(.kod-still) .btn-help:active {
    transform: scale(0.88); filter: brightness(1.18);
  }
  html:not(.kod-still) .bq:active, html:not(.kod-still) .chapter:active, html:not(.kod-still) .chat:active,
  html:not(.kod-still) .harvest-all:active, html:not(.kod-still) .res .r:active, html:not(.kod-still) .asst:active,
  html:not(.kod-still) .pick:active, html:not(.kod-still) .q-tab:active, html:not(.kod-still) .un-tab:active,
  html:not(.kod-still) .cht-tab:active, html:not(.kod-still) .lord .pill[role="button"]:active,
  html:not(.kod-still) .bs-tab:active, html:not(.kod-still) .hz-chip:active, html:not(.kod-still) .rd-chips .chip:active,
  html:not(.kod-still) .rd-tabs .tab:active, html:not(.kod-still) button.ml-card:active, html:not(.kod-still) button.rs-tile:active,
  html:not(.kod-still) button.bs-card:active, html:not(.kod-still) button.hz-card:active, html:not(.kod-still) .un-dk:active {
    transform: scale(0.96); filter: brightness(0.9);
  }
  /* нажали — сжатие быстро, без пружины (пружина — при отпускании, правило выше) */
  html:not(.kod-still) :is(.btn, .hbtn .c, .rbtn .c, .plus, .lord .portrait, .btn-close, .rally-flag .c, .bq, .chapter, .chat,
    .harvest-all, .res .r, .asst, .pick, .q-tab, .un-tab, .cht-tab, .btn-back, .btn-help, .bs-tab, .hz-chip, .rd-chips .chip,
    .rd-tabs .tab, button.ml-card, button.rs-tile, button.bs-card, button.hz-card, .un-dk):active,
  html:not(.kod-still) :is(.hbtn, .rbtn, .lord, .rally-flag):active :is(.c, .portrait) {
    transition: transform 0.06s ease-out, filter 0.06s ease-out;
  }
  /* справа налево стрелка «назад» зеркальна (css/lang.css) — сжатие не снимает зеркало */
  html[dir="rtl"]:not(.kod-still) .btn-back:active { transform: scale(-0.88, 0.88); }
  /* пузырь добычи качается своей анимацией (transform занят) — только светлеет */
  html:not(.kod-still) .po .bubble:active { filter: brightness(1.15); }
}

/* ——— окна: появляются с подскоком, закрываются — гаснут (js/ui.js modal: закрытое окно — .modal-out, его уже не
   видят проверки «открыто ли окно»; через 150 мс его нет) ——— */
@media (prefers-reduced-motion: no-preference) {
  html:not(.kod-still) .modal-wrap { animation: kod-veil-in 0.18s ease-out; }
  html:not(.kod-still) .modal { animation: kod-modal-in 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.15); }
  /* окно во весь экран (ui.js modal → full): без подскока — быстро въезжает снизу и проявляется */
  html:not(.kod-still) .modal-wrap.full { animation: none; }
  html:not(.kod-still) .modal.full { animation: kod-full-in 0.2s cubic-bezier(0.2, 0.8, 0.3, 1); }
  /* нижняя панель (ui.js modal → sheet): без затемнения, выезжает снизу за 0,2 с */
  html:not(.kod-still) .modal-wrap.sheet { animation: none; }
  html:not(.kod-still) .modal.sheet { animation: kod-sheet-in 0.2s cubic-bezier(0.2, 0.8, 0.3, 1); }
}
.modal-out {
  position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(8, 10, 16, 0.62); pointer-events: none; animation: kod-veil-out 0.15s ease-in forwards;
}
.modal-out > .modal, html:not(.kod-still) .modal-out > .modal { animation: kod-modal-out 0.15s ease-in forwards; }
.modal-out.full { background: none; animation: none; }
.modal-out.full > .modal, html:not(.kod-still) .modal-out.full > .modal { animation: kod-full-out 0.15s ease-in forwards; }
.modal-out.sheet { background: none; align-items: flex-end; animation: none; }
.modal-out.sheet > .modal, html:not(.kod-still) .modal-out.sheet > .modal { animation: kod-sheet-out 0.15s ease-in forwards; }
/* всплывающее гаснет с тем же размытием позади, что и было (css/kod.css), размытие уходит вместе с затемнением */
@supports ((backdrop-filter: blur(6px)) or (-webkit-backdrop-filter: blur(6px))) {
  .modal-out:not(.full):not(.sheet):not(.mv-route) {
    background: rgba(8, 10, 16, 0.4); -webkit-backdrop-filter: blur(6px) saturate(0.85); backdrop-filter: blur(6px) saturate(0.85);
    animation: kod-blur-out 0.15s ease-in forwards;
  }
  html.kod-lo .modal-out:not(.full):not(.sheet) { background: rgba(8, 10, 16, 0.62); -webkit-backdrop-filter: none; backdrop-filter: none; animation: kod-veil-out 0.15s ease-in forwards; }
}
@keyframes kod-blur-out { to { background-color: rgba(8, 10, 16, 0); -webkit-backdrop-filter: blur(0) saturate(1); backdrop-filter: blur(0) saturate(1); } }
@keyframes kod-sheet-in { from { transform: translateY(100%); } }
@keyframes kod-sheet-out { to { transform: translateY(100%); } }
@keyframes kod-veil-in { from { background-color: rgba(8, 10, 16, 0); } }
@keyframes kod-veil-out { to { background-color: rgba(8, 10, 16, 0); } }
@keyframes kod-modal-in { 0% { transform: scale(0.9); opacity: 0; } 60% { opacity: 1; } 100% { transform: scale(1); } }
@keyframes kod-modal-out { to { transform: scale(0.94) translateY(6px); opacity: 0; } }
@keyframes kod-full-in { from { transform: translateY(28px); opacity: 0; } }
@keyframes kod-full-out { to { transform: translateY(20px); opacity: 0; } }

/* ——— замок: фигуры (жители, строитель на лесах, строй во дворе) — маленькие холсты на сцене, двигает их
   translate, глубина — z-index как у построек; дым над трубами — две CSS-струйки; холст частиц — над сценой ———
   Фигуры рисуются в слое сцены: без will-change и translate3d (холсты жителей и строителя — в памяти, не на GPU).
   Свой слой у каждой фигуры вперемешку с постройками по z-index дробил постройки на слои, и набор слоёв менялся при
   каждом появлении жителя — риск мерцания на телефоне (как у прежней земли замка, city.js).
   Дым — над всеми постройками (z-index от 99000 из citylife.js, ниже надписей .po): его струйки — свои слои
   (анимация transform), постройки под ними не дробятся; рамка с overflow: hidden ограничивает «возможное перекрытие»
   анимации; точка трубы (left/top) — в рамке на (24, 110) */
.scene .cl-act { position: absolute; left: 0; top: 0; pointer-events: none; }
.scene .cl-smoke {
  position: absolute; width: 72px; height: 116px; margin: -110px 0 0 -24px; overflow: hidden; pointer-events: none;
}
.cl-smoke i {
  position: absolute; left: 14px; top: 90px; width: 20px; height: 20px; border-radius: 50%; opacity: 0;
  background: radial-gradient(circle, rgba(236, 236, 240, 0.8), rgba(206, 206, 212, 0) 70%);
  animation: cl-smoke 3.8s ease-out infinite;
}
.cl-smoke i:nth-child(2) { animation-delay: -1.9s; }
@keyframes cl-smoke {
  0% { transform: translate(0, 0) scale(0.45); opacity: 0; }
  14% { opacity: 0.75; }
  100% { transform: translate(16px, -70px) scale(2.3); opacity: 0; }
}
.viewport > .city-fx { position: absolute; left: 0; top: 0; pointer-events: none; }
html.kod-still .scene .cl-act, html.kod-still .scene .cl-smoke, html.kod-still .viewport > .city-fx { display: none; }
@media (prefers-reduced-motion: reduce) {
  .scene .cl-act, .scene .cl-smoke, .viewport > .city-fx { display: none; }
}

/* ——— призыв героев: алтарь заряжается, пока идёт запрос (js/anim/burst.js charge) ——— */
.hz-altar.kod-charging .hz-core { animation: kod-core 0.42s ease-in-out infinite alternate; }
.hz-altar.kod-charging .hz-ring { border-color: var(--gold); filter: drop-shadow(0 0 6px rgba(255, 214, 120, 0.9)); }
.kod-charging:not(.hz-altar) { animation: kod-charge 0.42s ease-in-out infinite alternate; }
@keyframes kod-core {
  from { transform: scale(1); box-shadow: 0 0 40px rgba(255, 150, 60, 0.8); }
  to { transform: scale(1.12); box-shadow: 0 0 96px rgba(255, 206, 120, 1); }
}
@keyframes kod-charge { to { filter: brightness(1.25); } }
