/* Новогодняя открытка Vivanti — вязаная версия (макет Figma 1920×1080). */

:root {
  --snow: #eef0f4;
  --sky: #b9cbe3;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--snow);
}

body { -webkit-tap-highlight-color: transparent; }

img { user-select: none; -webkit-user-drag: none; }

/* Размытая подложка за сценой: заполняет поля, если экран не 16:9 или больше максимального размера сцены.
   Два слоя — поляна и вязка; вязка проявляется вместе с вязкой на сцене (app.js). */
.backdrop {
  position: fixed;
  inset: -80px;
  overflow: hidden;
  background: var(--snow);
}
.backdrop__layer {
  position: absolute;
  inset: 0;
  background: center / cover no-repeat;
  filter: blur(40px) saturate(1.05);
  transform: scale(1.05);
}
.backdrop__layer--meadow { background-image: url("assets/meadow-2.jpg"); }
.backdrop__layer--knit { background-image: url("assets/knit.jpg"); opacity: 0; will-change: opacity; }
/* Телефон: сцена закрывает почти весь экран — подложки нет совсем (фиксированный слой во весь экран ~17 МБ
   видеопамяти; мобильный Chrome при нехватке памяти терял плитки карточки), поля — цветом фона страницы */
.is-phone .backdrop { display: none; }

.viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* Сцена в координатах макета; масштаб и сдвиг выставляет app.js */
.stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 1920px;
  height: 1080px;
  overflow: hidden;
  transform-origin: 0 0;
  background: linear-gradient(var(--sky), var(--snow) 45%);
  /* сцена не проявляется сама (полупрозрачный слой во весь экран мерцал на телефонах) — её закрывает .loader */
}
.stage.is-ready { box-shadow: 0 24px 90px rgba(28, 38, 70, .28); }
.is-phone .stage.is-ready { box-shadow: none; }

/* Шторка возврата к поляне (телефон): белая, как снег; прозрачность ставит app.js */
.curtain {
  position: fixed;
  inset: 0;
  z-index: 9;
  background: var(--snow);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ---------- Экран загрузки ---------- */
.loader {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--snow);
  transition: opacity .5s ease;
}
.loader.is-hidden { opacity: 0; pointer-events: none; }
.loader__ball {
  width: 96px;
  height: 96px;
  animation: loader-spin 1.6s linear infinite;
}
.loader__text {
  margin: 0;
  font: 800 16px/1.3 Inter, system-ui, sans-serif;
  color: #3a4a7a;
  letter-spacing: .01em;
}
@keyframes loader-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .loader__ball { animation-duration: 4s; }
}

/* ---------- Экран 1: поляна ---------- */

.scene {
  position: absolute;
  inset: 0;
  /* точка, вокруг которой фон приближается к экрану 2 (из позиции фона во фрейме «2»); на телефоне — своя */
  transform-origin: var(--scene-origin, 1233px 293px);
  will-change: transform;
  /* на телефоне фон шире сцены (~4160 px, видна четверть): без обрезки слой занимал видеопамять целиком —
     мобильный Chrome не успевал дорисовывать плитки и куски карточки пропадали (2026-11-16) */
  overflow: hidden;
}

/* Фон поляны: на компьютере во всю сцену; на телефоне — по высоте сцены и сдвинут так, чтобы в кадре
   были домики и кусок ёлки (app.js → applyLayout ставит --bg-x / --bg-w) */
.scene__bg {
  position: absolute;
  left: var(--bg-x, 0px);
  top: 0;
  width: var(--bg-w, 100%);
  height: 100%;
  max-width: none;
  pointer-events: none;
}
/* размытый фон экрана 2 — заранее размытая маленькая копия (lab/retouch-meadow.html), а не живой filter: blur:
   на телефонах живое размытие картинки шириной ~4000 точек каждый кадр мерцало сразу после тапа по клубку */
.scene__bg--blur { opacity: 0; will-change: opacity; }

.shadows { position: absolute; inset: 0; pointer-events: none; }

.shadow {
  position: absolute;
  pointer-events: none;
}
.shadow--sheep { opacity: .6; }
.shadow__inner {
  position: absolute;
  inset: 0;
  overflow: hidden;
  animation: shadow-bob 3.4s ease-in-out infinite;
  animation-delay: var(--d, 0s);
}
.shadow--sheep .shadow__inner { animation: none; }
.shadow__inner img {
  position: absolute;
  left: 0;
  top: -150.91%;
  width: 100%;
  height: 364.35%;
}

.sheep {
  position: absolute;
  pointer-events: none;
}
.sheep img { position: absolute; max-width: none; }

/* Овечка по клику подпрыгивает и дрыгает ножками (app.js → setupSheep).
   .sheep__hop — прыжок (приседание, полёт, приземление), .sheep__crop — вырезка из sheep-sheet.png;
   ножки — копии той же картинки в своих окошках под туловищем, на основной картинке под ними дырки (clip-path) */
.sheep__hop,
.sheep__crop { position: absolute; inset: 0; }
.sheep__hop { transform-origin: 50% 100%; }
.sheep__crop { overflow: hidden; }
.sheep__leg { position: absolute; overflow: hidden; transform-origin: 50% 0; }
.sheep__hit {
  position: absolute;
  inset: 12% 6% 8%;
  border-radius: 50%;
  pointer-events: auto;
  cursor: pointer;
}
.sheep.is-hopping .sheep__hop { animation: sheep-hop .86s both; }
.sheep.is-hopping .sheep__leg { animation: sheep-kick .86s ease-in-out both; animation-delay: var(--ld, 0s); }
.shadow--sheep .shadow__inner.is-hopping { animation: sheep-shadow .86s both; }
.stage.is-playing .sheep__hit { pointer-events: none; }

@keyframes sheep-hop {
  0%   { transform: none; animation-timing-function: ease-out; }
  14%  { transform: scale(1.07, .9); animation-timing-function: ease-in; }
  26%  { transform: translateY(calc(var(--h) * -.55)) rotate(var(--tilt)) scale(.95, 1.07); animation-timing-function: ease-out; }
  42%  { transform: translateY(calc(var(--h) * -1)) rotate(calc(var(--tilt) * -.5)) scale(1); animation-timing-function: ease-in; }
  60%  { transform: translateY(calc(var(--h) * -.42)) rotate(calc(var(--tilt) * .3)) scale(.97, 1.04); animation-timing-function: ease-in; }
  71%  { transform: translateY(0) scale(1.09, .88); animation-timing-function: ease-out; }
  83%  { transform: scale(.97, 1.04); }
  92%  { transform: scale(1.015, .985); }
  100% { transform: none; }
}
/* ножки: в полёте — несколько быстрых взмахов, передние и задние в противофазе (знак в --k) */
@keyframes sheep-kick {
  0%, 18% { transform: rotate(0); }
  28%  { transform: rotate(var(--k)); }
  37%  { transform: rotate(calc(var(--k) * -.75)); }
  46%  { transform: rotate(calc(var(--k) * .9)); }
  55%  { transform: rotate(calc(var(--k) * -.55)); }
  66%  { transform: rotate(calc(var(--k) * .2)); }
  72%, 100% { transform: rotate(0); }
}
@keyframes sheep-shadow {
  0%   { transform: none; opacity: 1; }
  14%  { transform: scale(1.05, 1.08); opacity: 1; }
  42%  { transform: scale(.76); opacity: .5; }
  71%  { transform: scale(1.08, 1.1); opacity: 1; }
  100% { transform: none; opacity: 1; }
}

.ball {
  position: absolute;
  padding: 0;
  border: 0;
  background: none;
  border-radius: 50%;
  cursor: pointer;
  outline: none;
}
.ball__inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  animation: ball-bob 3.4s ease-in-out infinite;
  animation-delay: var(--d, 0s);
}
/* Клубки в Figma хранятся сжатыми 1024×576 и растягиваются в квадрат — так же и здесь */
.ball img {
  position: relative;            /* над canvas хвостика */
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
/* Хвостик нитки на снегу: canvas шире клубка, лежит под картинкой (рисует app.js) */
.ball__tail {
  position: absolute;
  left: -60%;
  top: -20%;
  width: 220%;
  height: 150%;
  pointer-events: none;
}
/* подъём при наведении — отдельными translate/scale, чтобы не спорить с transform покачивания */
.ball .ball__inner { transition: translate .35s cubic-bezier(.3, 1.6, .5, 1), scale .35s cubic-bezier(.3, 1.6, .5, 1); }
.ball:hover .ball__inner { translate: 0 -14px; scale: 1.04; }
.ball:active .ball__inner { translate: 0 -4px; scale: .97; }
.ball:focus-visible .ball__inner { filter: drop-shadow(0 0 14px rgba(255, 255, 255, .95)); }

.ball.is-nope .ball__inner { animation: ball-nope .55s ease-in-out; }

/* Выбранный клубок: на время сценария переносится из поляны на сцену над ниткой, движением управляет JS,
   а его хвостик рисует общая WebGL-нитка */
.ball--hero { transform-origin: 50% 50%; z-index: 2; }
.ball--hero .ball__inner { animation: none; translate: none; scale: none; transition: none; }
.ball--hero .ball__tail { visibility: hidden; }

.stage.is-playing .ball { pointer-events: none; }
.stage.is-playing .ball__inner,
.stage.is-playing .shadow__inner { animation: none; }

/* «Уменьшить движение»: без фонового покачивания (сценарий по клику всё равно играет — см. app.js) */
@media (prefers-reduced-motion: reduce) {
  .ball__inner,
  .shadow__inner { animation: none; }
}

@keyframes ball-bob {
  0%, 100% { transform: translateY(0) rotate(0); }
  50%      { transform: translateY(-9px) rotate(-1.5deg); }
}
@keyframes shadow-bob {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(.93); opacity: .82; }
}
@keyframes ball-nope {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-7deg); }
  45% { transform: rotate(6deg); }
  70% { transform: rotate(-3deg); }
}

/* ---------- Салют из конфетти (как в эталоне mikmal.ru/new-year) ----------
   Картинка конфетти в маске-кольце, три слоя — шлейф. Маска — готовая PNG (assets/confetti-mask.png, 1/8 размера,
   отрисована из прежней SVG с feGaussianBlur σ=107): живой SVG-блюр на 2904×2168 Firefox считал на процессоре,
   и анимация вставала на ~1 с в момент «прогрева» салюта (середина бега нитки, 2026-11-18);
   масштаб из центра считает app.js (renderConfetti): резкий вылет и слоу-мо у краёв */
.confetti {
  position: absolute;
  left: -504px;
  top: -566px;
  width: 2904px;
  height: 2168px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  -webkit-mask: url("assets/confetti-mask.png") 0 0 / 100% 100% no-repeat;
  mask: url("assets/confetti-mask.png") 0 0 / 100% 100% no-repeat;
}
/* Телефон: без маски-кольца — маска над анимированными слоями каждый кадр собирается в огромную поверхность,
   и мобильный Chrome терял плитки карточки. Середину всё равно закрывает плашка, края — край экрана. */
.is-phone .confetti { -webkit-mask: none; mask: none; }
/* и один слой вместо трёх: бледные «хвосты» (10 % и 30 %) на маленьком экране почти не видны, а это два огромных слоя */
.is-phone .confetti__layer--a,
.is-phone .confetti__layer--b { display: none; }

.confetti__layer {
  position: absolute;
  overflow: hidden;
  will-change: transform, opacity;
}
.confetti__layer img {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 159.2%;
}
.confetti__layer--a { left: 366px; top: 338px; width: 2172px; height: 1364px; opacity: .1; }
.confetti__layer--b { left: 309px; top: 302px; width: 2286px; height: 1436px; opacity: .3; }
.confetti__layer--c { left: 258px; top: 270px; width: 2388px; height: 1500px; }

/* ---------- Экраны 3–4: вязаное полотно ---------- */

.knit {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;                 /* на вертикальной сцене не растягивать */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  will-change: transform, opacity;
}

/* ---------- Нитка (canvas поверх сцены) ---------- */

.thread {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* «Пространство карточки»: пятна, салют и карточка свёрстаны в координатах макета 1920×1080;
   на телефоне app.js уменьшает и центрует обёртки (transform), на компьютере они совпадают со сценой */
.cardspace {
  position: absolute;
  left: 0;
  top: 0;
  width: 1920px;
  height: 1080px;
  transform-origin: 0 0;
  pointer-events: none;
}
.cardspace--front { z-index: 3; }     /* над ниткой (1) и улетающим клубком (2) */

/* ---------- Экран 4: карточка ---------- */

.card {
  position: absolute;
  inset: 0;
  margin: 0;
  transform-origin: 960px 210px;   /* верх карточки по центру — там её держит нитка */
  visibility: hidden;
  pointer-events: none;
  z-index: 3;
  will-change: transform;
}
/* Плашка: рамка своя у каждого клубка (js/balls.js → card.plate), app.js ставит её в style="" */
.card__bg {
  position: absolute;
  left: 389px;
  top: 222px;
  width: 1117px;
  height: 633px;
}
/* Пятно под текстом: центр (936, 540), размер — с полем 3σ под размытие (картинка в 4 раза меньше) */
.card__glow {
  position: absolute;
  left: 378.75px;
  top: 138.75px;
  width: 1114.5px;
  height: 802.5px;
  opacity: 0;
}

/* ---------- Пятна за плашкой (Figma: Ellipse 1954 / 1955), проявляются с салютом ---------- */
.glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  visibility: hidden;
}
.glow__spot {
  position: absolute;
  opacity: 0;
  will-change: transform, opacity;
}
/* центры (633, 465) и (1353, 727); размер — эллипс + поле 3σ (картинки в 8 раз меньше) */
.glow__spot--a { left: -72px; top: -240px; width: 1410px; height: 1410px; }
.glow__spot--b { left: 438px; top: -188px; width: 1830px; height: 1830px; }
/* Поздравление: место, ширину, размер, цвет и тень ставит app.js (setupCard) по экрану Figma карточки */
.card__title {
  position: absolute;
  left: 530px;
  top: 400px;
  width: 859px;
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  font-weight: 900;
  font-size: 60px;
  line-height: normal;
  color: #fff;
  text-align: center;
  white-space: pre-line;             /* перенос строки задан в тексте (js/balls.js → title) */
  overflow-wrap: break-word;
  opacity: 0;
}
/* Кнопка «В начало» (Figma 137:525, у всех экранов одна): 712,728 496×209, под надписью — красное пятно */
.card__btn {
  position: absolute;
  left: 712px;
  top: 728px;
  width: 496px;
  height: 209px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  opacity: 0;
  outline: none;
}
.card__btn.is-on { pointer-events: auto; }
/* текст, кнопка и пятно под текстом проявляются поверх плашки — свои слои, чтобы их проявление не перерисовывало
   всю плашку каждый кадр (на телефонах карточка от этого мерцала) */
.card__title,
.card__btn,
.card__glow { will-change: transform, opacity; }
.card__btn-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transition: transform .3s cubic-bezier(.3, 1.6, .5, 1);
}
.card__btn-glow {
  position: absolute;
  left: -34.95px;
  top: -68.95px;
  width: 557.9px;
  height: 344.9px;
  max-width: none;
  opacity: .7;                       /* пятно под надписью — 70 % (просьба пользователя, 2026-11-16) */
  transition: transform .3s cubic-bezier(.3, 1.6, .5, 1);
}
.card__btn-text {
  position: absolute;
  left: 0;
  right: 0;
  top: 67.98px;
  font-family: Inter, system-ui, sans-serif;
  font-weight: 800;
  font-size: 61.083px;
  line-height: normal;
  color: #fff;
  text-align: center;
  white-space: nowrap;
  transition: transform .3s cubic-bezier(.3, 1.6, .5, 1);
}
.card__btn:hover .card__btn-bg,
.card__btn:hover .card__btn-glow,
.card__btn:hover .card__btn-text { transform: scale(1.05); }
.card__btn:active .card__btn-bg,
.card__btn:active .card__btn-glow,
.card__btn:active .card__btn-text { transform: scale(.97); }
.card__btn:focus-visible .card__btn-bg { filter: drop-shadow(0 0 12px rgba(255, 255, 255, .95)); }

.noscript {
  position: fixed;
  inset: auto 0 40px;
  margin: 0;
  font: 800 20px/1.3 Inter, system-ui, sans-serif;
  color: #1c2240;
  text-align: center;
}

/* ---------- «Ярлычки» внизу экрана (2026-11-25) ----------
   Край большого круга, выступающий снизу сцены (сцена обрезает остальное): --cap-r — радиус, --cap-h — сколько видно.
   Красный с белым логотипом Vivanti (assets/vivanti-logo-white.svg) — на экране карточки (.brand, ссылка на сайт,
   проявляется и выезжает вместе с кнопкой — app.js), серый с «Выбери клубок» — на поляне (.hint, уходит вниз по клику). */
.brand,
.hint {
  --cap-r: 270px;
  --cap-h: 96px;
  position: absolute;
  left: 50%;
  bottom: calc(var(--cap-h) - 2 * var(--cap-r));
  width: calc(2 * var(--cap-r));
  height: calc(2 * var(--cap-r));
  margin: 0;
  box-sizing: border-box;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  transform: translateX(-50%);
  box-shadow: 0 -4px 22px rgba(40, 30, 60, .18);
  pointer-events: none;
  user-select: none;
}
.is-phone .brand,
.is-phone .hint { --cap-r: 330px; --cap-h: 124px; }

.brand {
  z-index: 4;
  padding-top: 30px;                 /* логотип по центру видимой части */
  background: #d00000;
  opacity: 0;
}
.brand img { display: block; width: 180px; height: auto; }
.is-phone .brand { padding-top: 40px; }
.is-phone .brand img { width: 220px; }
/* ссылка работает, только когда логотип виден (app.js ставит is-on вместе с кнопкой «В начало») */
.brand.is-on { pointer-events: auto; cursor: pointer; }
.brand:focus { outline: none; }
.brand:focus-visible { outline: 3px solid rgba(255, 255, 255, .85); outline-offset: -12px; }

/* Подсказка «Выбери клубок» / «Pick a ball»: серый ярлычок, текст белый, по центру видимой части */
.hint {
  --cap-h: 78px;                     /* серый ярлычок ниже красного (2026-11-25, просьба) */
  z-index: 2;
  padding-top: calc(var(--cap-h) / 2 - .55em);
  background: #8f98aa;
  font: 800 30px/1 Inter, system-ui, sans-serif;
  color: #fff;
  white-space: nowrap;
  transition: opacity .6s ease, transform .6s ease;
}
.is-phone .hint { --cap-h: 102px; font-size: 40px; }

/* ---------- Поздравление «С Новым годом!» на стартовом экране (2026-11-25) ----------
   Между облаками и домами (подсказка — внизу, у клубков); Inter Black, красный как у текстов карточек 4, 5, 12;
   уходит вместе с подсказкой. */
.greet {
  position: absolute;
  left: 0;
  right: 0;
  top: 176px;
  z-index: 2;
  margin: 0;
  font: 900 112px/1.1 Inter, system-ui, sans-serif;
  color: #d00000;
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 6px 14px rgba(255, 255, 255, .55);
  pointer-events: none;
  user-select: none;
  transition: opacity .6s ease;
}
.stage.is-playing .greet { opacity: 0; transition-duration: .3s; }
.stage.is-playing .hint { opacity: 0; transform: translateX(-50%) translateY(var(--cap-h)); transition-duration: .3s; }
.is-phone .greet { top: 455px; font-size: 112px; }

/* ---------- Шрифт Glina Script — основной с 2026-11-25 (html.font-glina; ?font=inter — прежняя версия на Inter) ----------
   Рукописный шрифт Liese Mars (SIL OFL 1.1, лицензия — assets/fonts/glina-script-OFL.txt). Одно начертание — поэтому
   font-weight: normal и без синтетического жирного. Размеры подогнаны под шрифт: он мельче Inter при том же кегле;
   поздравление на карточке подбирает app.js (GLINA). Версия на Inter (?font=inter) этими правилами не затронута. */
@font-face {
  font-family: 'Glina Script';
  src: url(assets/fonts/glina-script.otf) format('opentype');
  font-weight: normal;
  font-style: normal;
  font-display: block;
}
.font-glina .greet,
.font-glina .hint,
.font-glina .card__title,
.font-glina .card__btn-text,
.font-glina .loader__text {
  font-family: 'Glina Script', Inter, system-ui, sans-serif;
  font-weight: normal;
  font-synthesis: none;
}
.font-glina .greet { font-size: 150px; top: 157px; line-height: 1; }   /* виден, только если нет контуров (.is-text) */
.font-glina .hint { font-size: 38px; }
.font-glina .loader__text { font-size: 22px; }
/* кнопка «В начало»: Glina мельче Inter — крупнее и по центру «таблетки» (её середина ~100 px от верха картинки 209) */
.font-glina .card__btn-text { top: 0; font-size: 84px; line-height: 200px; }
.font-glina:lang(en) .card__btn-text { font-size: 76px; }   /* «Start over» длиннее — запас на увеличение при наведении */
.font-glina.is-phone .greet { font-size: 150px; top: 445px; }
.font-glina.is-phone .hint { font-size: 50px; }

/* «С Новым годом!» нитками (шрифт Glina): холст ставит и рисует app.js (greetYarn); h1 остаётся для экранных чтецов,
   но не виден (если файл контуров не загрузился — app.js ставит .is-text и надпись видна обычным текстом). */
.greet-yarn {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  transition: opacity .6s ease;
}
.stage.is-playing .greet-yarn { opacity: 0; transition-duration: .3s; }
.font-glina .greet:not(.is-text) { color: transparent; text-shadow: none; }

/* Овечка на экране карточки (телефон — между карточкой и логотипом, компьютер — у левого нижнего угла плашки),
   прыгает по нажатию — app.js → cardSheep. Проявляется вместе с логотипом; нажимается только когда видна (.is-on). */
.cardsheep {
  position: absolute;
  width: 228px;
  height: 194px;
  transform-origin: 0 0;
  z-index: 4;
  opacity: 0;
  pointer-events: none;
}
.cardsheep .sheep__hit { pointer-events: none; }
.stage.is-playing .cardsheep.is-on .sheep__hit,
.cardsheep.is-on .sheep__hit { pointer-events: auto; }
