/* ==========================================================================
   Новогоднее оформление (App\Core\NewYear)

   Файл подключается в layouts/site.php только когда оформление включено
   в Админке → Настройки. Выключено — файла на странице нет, сайт прежний.

     .ny-garland   гирлянда, висит под нижним краем шапки на всех страницах
     .ny-hat       шапка Деда Мороза на голове бойца в логотипе
     .ny-snow      слой снега, только верхний блок главной (newyear-snow.js)

   Всё декоративное: aria-hidden, pointer-events: none, без картинок
   (провод — маска из встроенного SVG, лампочки — градиенты).
   ========================================================================== */

:root {
  --ny-wire: #4d5969;
  --ny-socket: linear-gradient(90deg, #262c35 0%, #737f8f 45%, #353d48 100%);
  --ny-glass-shade: rgba(0, 0, 0, .38);
  --ny-hat-shadow: drop-shadow(0 1.5px 1.4px rgba(0, 0, 0, .5));
}
:root[data-theme="light"] {
  --ny-wire: #9ba7b6;
  --ny-socket: linear-gradient(90deg, #7f8a99 0%, #d5dbe3 45%, #8f9aa8 100%);
  --ny-glass-shade: rgba(60, 20, 30, .18);
  /* на белой шапке сайта белому меху нужен контур: тень без сдвига его и рисует */
  --ny-hat-shadow: drop-shadow(0 0 .5px rgba(25, 40, 60, .55)) drop-shadow(0 1px 1.2px rgba(25, 40, 60, .25));
}

/* ---- Гирлянда ------------------------------------------------------------
   Ряд одинаковых звеньев по 56px: в каждом свой кусок провода с провисом и
   лампочка в нижней точке, поэтому провод и лампочки не расходятся ни на
   какой ширине. Нечётное число звеньев по центру — рисунок симметричен.
   Лампочка: тёмное «выключенное» стекло (b), над ним «горящее» (b::before)
   и ореол (b::after) — мерцание это только opacity, работает на видеокарте. */
.ny-garland {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1;                 /* под меню шапки (200) и мобильным меню (99); на компьютере 0, см. ниже */
  height: 34px;
  margin-top: -1px;           /* концы провода лежат на нижней линии шапки */
  display: flex;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
  contain: layout paint;
}
/* Второй ряд шапки при прокрутке получает backdrop-filter и становится
   отдельным слоем на уровне 0 — гирлянда (она позже в разметке) ложилась
   поверх открытого меню «Скачать». Ставим ряд выше гирлянды; первый ряд
   (z-index: 2) по-прежнему выше второго. На телефоне второй ряд — это
   выезжающее меню, его не трогаем. */
@media (min-width: 1024px) {
  .header__main { position: relative; z-index: 1; }
  .ny-garland { z-index: 0; }
}
.ny-garland i {
  position: relative;
  flex: none;
  width: 56px;
  height: 100%;
  --r: 0deg;
}
/* провод */
.ny-garland i::before {
  content: "";
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 12px;
  background: var(--ny-wire);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='12' viewBox='0 0 56 12'%3E%3Cpath d='M-1 1.4Q28 13.2 57 1.4' fill='none' stroke='%23000' stroke-width='1.4'/%3E%3C/svg%3E") 0 0 / 100% 100% no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='12' viewBox='0 0 56 12'%3E%3Cpath d='M-1 1.4Q28 13.2 57 1.4' fill='none' stroke='%23000' stroke-width='1.4'/%3E%3C/svg%3E") 0 0 / 100% 100% no-repeat;
}
/* цоколь */
.ny-garland i::after {
  content: "";
  position: absolute;
  left: 50%; top: 6px;
  width: 5px; height: 5px;
  margin-left: -2.5px;
  border-radius: 1.5px 1.5px 1px 1px;
  background: var(--ny-socket);
  transform: rotate(var(--r));
  transform-origin: 50% 0;
}
/* стекло, выключенное */
.ny-garland b {
  position: absolute;
  left: 50%; top: 10.5px;
  width: 8px; height: 12px;
  margin-left: -4px;
  border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
  background: var(--d);
  box-shadow: inset 0 -2px 2.5px var(--ny-glass-shade);
  transform: rotate(var(--r));
  transform-origin: 50% -4.5px;   /* поворот вокруг точки подвеса */
}
/* стекло, горящее */
.ny-garland b::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(circle at 34% 27%, rgba(255, 255, 255, .95) 0, rgba(255, 255, 255, .95) .8px, rgba(255, 255, 255, 0) 2.4px),
    radial-gradient(ellipse 70% 62% at 50% 60%, var(--h), var(--c) 82%);
  box-shadow: inset 0 -1.5px 2px rgba(0, 0, 0, .16);
  animation: nyTwinkle var(--t, 4.6s) ease-in-out var(--dl, 0s) infinite;
}
/* ореол */
.ny-garland b::after {
  content: "";
  position: absolute;
  left: 50%; top: 58%;
  width: 30px; height: 30px;
  margin: -15px 0 0 -15px;
  border-radius: 50%;
  background: radial-gradient(circle closest-side, var(--g), rgba(0, 0, 0, 0));
  animation: nyTwinkle var(--t, 4.6s) ease-in-out var(--dl, 0s) infinite;
}
/* Горит большую часть времени и раз за цикл плавно приглушается. */
@keyframes nyTwinkle {
  0%, 42%, 100% { opacity: 1; }
  71%           { opacity: .2; }
}

/* цвета: тёплое золото, красный, изумруд, лёд, розовый
   --c горящее стекло, --h его раскалённая середина, --d выключенное, --g ореол */
.ny-garland i:nth-child(5n+1) { --c: #ff3d56; --h: #ffc0c8; --d: #5e1a24; --g: rgba(255, 61, 86, .5); }
.ny-garland i:nth-child(5n+2) { --c: #ffbd3a; --h: #fff3c9; --d: #5c4719; --g: rgba(255, 189, 58, .46); }
.ny-garland i:nth-child(5n+3) { --c: #2fd27b; --h: #c3ffdf; --d: #174f33; --g: rgba(47, 210, 123, .42); }
.ny-garland i:nth-child(5n+4) { --c: #3ea2ff; --h: #cfe8ff; --d: #1b4266; --g: rgba(62, 162, 255, .46); }
.ny-garland i:nth-child(5n)   { --c: #ff5cbf; --h: #ffd0ee; --d: #5c2247; --g: rgba(255, 92, 191, .44); }

:root[data-theme="light"] .ny-garland i:nth-child(5n+1) { --c: #ef2d48; --h: #ff9aa8; --d: #f3c3ca; --g: rgba(239, 45, 72, .26); }
:root[data-theme="light"] .ny-garland i:nth-child(5n+2) { --c: #f5a514; --h: #ffe08a; --d: #f2dfb4; --g: rgba(245, 165, 20, .26); }
:root[data-theme="light"] .ny-garland i:nth-child(5n+3) { --c: #18b863; --h: #8ff0bb; --d: #c2e8d3; --g: rgba(24, 184, 99, .22); }
:root[data-theme="light"] .ny-garland i:nth-child(5n+4) { --c: #2489ee; --h: #9fd0ff; --d: #c6def5; --g: rgba(36, 137, 238, .24); }
:root[data-theme="light"] .ny-garland i:nth-child(5n)   { --c: #e33f9c; --h: #ffa6d8; --d: #f2c9e1; --g: rgba(227, 63, 156, .22); }

/* лампочки висят чуть вразнобой */
.ny-garland i:nth-child(4n+1) { --r: 7deg; }
.ny-garland i:nth-child(4n+2) { --r: -5deg; }
.ny-garland i:nth-child(4n+3) { --r: 3deg; }
.ny-garland i:nth-child(4n)   { --r: -8deg; }

/* у каждой лампочки свой темп и своя фаза: рисунок не повторяется на экране */
.ny-garland i:nth-child(3n+1) { --t: 3.9s; }
.ny-garland i:nth-child(3n+2) { --t: 4.7s; }
.ny-garland i:nth-child(3n)   { --t: 5.6s; }
.ny-garland i:nth-child(7n+1) { --dl: -0.3s; }
.ny-garland i:nth-child(7n+2) { --dl: -2.2s; }
.ny-garland i:nth-child(7n+3) { --dl: -1.2s; }
.ny-garland i:nth-child(7n+4) { --dl: -3.5s; }
.ny-garland i:nth-child(7n+5) { --dl: -0.9s; }
.ny-garland i:nth-child(7n+6) { --dl: -2.8s; }
.ny-garland i:nth-child(7n)   { --dl: -1.7s; }

/* ---- Шапка на логотипе ----------------------------------------------------
   Логотип 407×100, голова бойца — 22.6% ширины от левого края, у самого
   верха картинки. Размеры и сдвиги считаются от высоты логотипа, поэтому
   на телефоне (28px) шапка садится туда же, что и на компьютере (40px). */
.header__brand { position: relative; --ny-logo-h: 40px; }
@media (max-width: 1023px) {
  .header__brand { --ny-logo-h: 28px; }
}
.ny-hat {
  position: absolute;
  left: calc(var(--ny-logo-h) * .595);
  top: calc(50% - var(--ny-logo-h) * .958);
  width: calc(var(--ny-logo-h) * .652);
  height: calc(var(--ny-logo-h) * .5705);
  overflow: visible;
  transform: rotate(-9deg);
  transform-origin: 50% 81%;
  filter: var(--ny-hat-shadow);
  pointer-events: none;
}
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .header__brand:hover .ny-hat { animation: nyHatWiggle 900ms ease-in-out; }
}
@keyframes nyHatWiggle {
  0%, 100% { transform: rotate(-9deg); }
  30%      { transform: rotate(-16deg); }
  62%      { transform: rotate(-5deg); }
  84%      { transform: rotate(-10.5deg); }
}

/* ---- Снег (слой создаёт newyear-snow.js только на главной) -------------
   Падение (i) и покачивание (b) — отдельные анимации transform, таяние —
   opacity: всё это ведёт видеокарта, основной поток не занят. */
:root { --ny-flake: 255, 255, 255; }
:root[data-theme="light"] { --ny-flake: 128, 156, 194; }
.ny-snow {
  position: absolute;
  left: 0; right: 0;
  z-index: 2;                 /* над содержимым (.main = 1), под шапкой (100) */
  overflow: hidden;
  pointer-events: none;
  contain: layout paint style;
  opacity: 0;
  transition: opacity 1.6s ease;
}
.ny-snow.is-on { opacity: 1; }
.ny-snow i {
  position: absolute;
  top: 0;
  width: var(--s); height: var(--s);
  margin: calc(var(--s) / -2) 0 0 calc(var(--s) / -2);
  will-change: transform, opacity;
  animation:
    nySnowFall var(--du, 14s) linear var(--dl, 0s) infinite,
    nySnowFade var(--du, 14s) linear var(--dl, 0s) infinite;
}
.ny-snow b {
  display: block;
  width: 100%; height: 100%;
  border-radius: 50%;
  opacity: var(--a, .8);
  background: radial-gradient(circle closest-side,
    rgba(var(--ny-flake), 1) 0%, rgba(var(--ny-flake), .95) 38%,
    rgba(var(--ny-flake), .36) 66%, rgba(var(--ny-flake), 0) 100%);
  animation: nySnowSway var(--sp, 3s) ease-in-out var(--sdl, 0s) infinite alternate;
}
.ny-snow.is-paused i, .ny-snow.is-paused b { animation-play-state: paused; }
@keyframes nySnowFall {
  from { transform: translate3d(0, -12px, 0); }
  to   { transform: translate3d(var(--dx, 0px), var(--fall, 600px), 0); }
}
/* проявляются под гирляндой, тают в нижней трети */
@keyframes nySnowFade {
  0%   { opacity: 0; }
  7%   { opacity: 1; }
  60%  { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes nySnowSway {
  from { transform: translateX(calc(var(--amp, 8px) * -1)); }
  to   { transform: translateX(var(--amp, 8px)); }
}

/* ---- Уважение к настройкам и печать -------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .ny-garland b::before, .ny-garland b::after { animation: none; }
  .ny-snow { display: none; }
}
@media print {
  .ny-garland, .ny-hat, .ny-snow { display: none !important; }
}
