/* Motion layer — живой луг, появление секций, «рисование» линий, hover.
   Всё декоративно: без JS и с prefers-reduced-motion страницы остаются статичными и читаемыми.
   Анимируются только transform / opacity (+ разовое stroke-dashoffset для рисования линий). */

:root {
  --ease-out: cubic-bezier(.22, .8, .24, 1);
  --ease-spring: cubic-bezier(.34, 1.45, .64, 1);
  --ease-soft: cubic-bezier(.45, .05, .25, 1);
}

/* ---------- Hero: слои луга (создаёт motion.js, статичны без анимации) ---------- */

.hero__paint { transform: scale(1.08); transform-origin: 50% 45%; will-change: transform; }
.hero__fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.hero__light, .hero__motes, .hero__grass { position: absolute; inset: 0; }

.hero__light i { position: absolute; border-radius: 50%; will-change: transform; }
.hero__light i:nth-child(1) { left: 16%; top: 50%; width: 54%; aspect-ratio: 2.1; background: radial-gradient(closest-side, rgba(255, 247, 208, .6), rgba(255, 247, 208, 0)); }
.hero__light i:nth-child(2) { left: 60%; top: 14%; width: 30%; aspect-ratio: 1.8; background: radial-gradient(closest-side, rgba(244, 250, 214, .5), rgba(244, 250, 214, 0)); }
.hero__light i:nth-child(3) { left: 52%; top: 56%; width: 62%; aspect-ratio: 2.4; background: radial-gradient(closest-side, rgba(96, 142, 112, .2), rgba(96, 142, 112, 0)); }

.hero__grass { inset: auto -40px 0 -40px; height: 120px; }
/* луг мягко растворяется в бумаге, трава стоит поверх */
.hero__fade { position: absolute; inset: auto 0 0 0; height: 84px; background: linear-gradient(to bottom, rgba(238, 244, 226, 0), rgba(238, 244, 226, .78) 68%, var(--paper)); }
.hero__grass .tuft { /* специфичность выше, чем у .hero__scene svg */
  position: absolute; bottom: -5px; left: var(--x); height: var(--h); width: auto; max-width: none;
  margin-left: calc(var(--h) * -.44); overflow: visible;
  transform-origin: 50% 100%; will-change: transform;
}
.tuft--flip { scale: -1 1; }

.mote, .petal { position: absolute; left: var(--x); top: var(--y); opacity: 0; will-change: transform, opacity; }
.mote {
  width: var(--s); height: var(--s); border-radius: 50%;
  background: radial-gradient(circle, #fffbe0 0 24%, rgba(255, 228, 128, .75) 44%, rgba(255, 228, 128, 0) 72%);
}
.petal { width: 11px; height: 7px; background: #fdfdf6; border: 1px solid #d8d0bf; border-radius: 62% 38% 60% 40%; }

@media (max-width: 760px) {
  .hero__grass .tuft:nth-child(even) { display: none; }
  .hero__grass .tuft { height: calc(var(--h) * .8); }
}

/* ---------- Подчёркивание заголовков от руки ---------- */

.squiggle { display: block; width: clamp(120px, 14vw, 168px); height: auto; aspect-ratio: 150 / 14; margin-top: 8px; overflow: visible; }
.squiggle path { fill: none; stroke: var(--apricot-deep); stroke-width: 3.4; stroke-linecap: round; }
.blog-head .squiggle { width: clamp(140px, 18vw, 220px); margin-top: 10px; }

/* ---------- Hover: бережные состояния ---------- */

.btn { transition: transform .28s var(--ease-spring), box-shadow .28s var(--ease-out), background-color .28s ease; }
.btn:hover { transform: translate(-1px, -3px) rotate(-1.2deg); box-shadow: 4px 7px 0 var(--ink); background: color-mix(in srgb, var(--apricot) 82%, var(--sun)); }
.btn--ghost:hover { transform: translate(-1px, -3px) rotate(1.2deg); background: var(--sun); }
.btn:active { transform: translate(2px, 3px); box-shadow: 1px 1px 0 var(--ink); transition-duration: .08s; }

.brand svg { transform-origin: 20% 85%; transition: transform .5s var(--ease-spring); }
.brand:hover svg { transform: rotate(-14deg) scale(1.08); }
.nav a { transition: transform .25s var(--ease-spring); }
.nav a:hover { transform: translateY(-2px); }

.services svg { transform-origin: 50% 80%; transition: transform .5s var(--ease-spring); }
.services li:hover svg { transform: translateY(-4px) rotate(-6deg) scale(1.06); }

.case-card { transition: transform .4s var(--ease-out), box-shadow .4s var(--ease-out); box-shadow: 0 0 0 color-mix(in srgb, var(--meadow) 70%, transparent); }
.case-card:hover, .case-card:focus-within { transform: translate(-2px, -4px); box-shadow: 6px 9px 0 color-mix(in srgb, var(--meadow) 70%, transparent); }

.stone { transition: transform .45s var(--ease-spring); }
.path li:hover .stone { transform: translateY(-6px) rotate(-4deg); }

.faq summary { transition: transform .3s var(--ease-out); }
.faq summary:hover { transform: translateX(5px); }
.faq summary::after { transition: transform .35s var(--ease-spring); }
.faq summary:hover::after { transform: scale(1.25) rotate(90deg); }
.faq details[open] summary:hover::after { transform: scale(1.25); }

.links svg { transition: transform .45s var(--ease-spring); }
.links a:hover svg { transform: rotate(-8deg) scale(1.1); }
.contact { transition: box-shadow .4s var(--ease-out); box-shadow: 0 0 0 color-mix(in srgb, var(--meadow) 70%, transparent); }
.contact:hover { box-shadow: 6px 9px 0 color-mix(in srgb, var(--meadow) 70%, transparent); }

.posts li { transition: transform .35s var(--ease-out); }
.posts li:hover { transform: translateX(8px); }
.note { transition: box-shadow .4s var(--ease-out); }

.demo__pick button { transition: transform .25s var(--ease-spring), background-color .25s ease, box-shadow .25s ease; }
.demo__pick button:hover { transform: translateY(-2px); background: color-mix(in srgb, var(--sun) 55%, var(--petal)); }

/* ============================================================
   Всё, что движется само, — только если пользователь не против
   ============================================================ */
@media (prefers-reduced-motion: no-preference) {

  /* --- Hero: вход --- */
  .top .wrap { animation: fade-down .9s var(--ease-out) .05s backwards; }
  .hero h1 { transform-origin: 12% 85%; animation: hero-title 1.25s var(--ease-out) .15s backwards; }
  .hero .alias { animation: hero-alias 1s var(--ease-out) .6s backwards; }
  .hero .lead { animation: rise 1s var(--ease-out) .85s backwards; }
  .hero .actions .btn { animation: rise .9s var(--ease-out) 1.05s backwards; }
  .hero .actions .btn + .btn { animation-delay: 1.18s; }
  .hero__paint { animation: scene-in 2.2s var(--ease-out) backwards; }
  .note { animation: note-in 1.1s var(--ease-spring) .9s backwards, note-float 6.5s ease-in-out 2.2s infinite alternate; }
  .note .bar > span { transform-origin: 0 50%; animation: bar-fill 1.3s var(--ease-out) 1.7s backwards; }

  /* --- Hero: жизнь луга --- */
  .hero__light i:nth-child(1) { animation: light-a 28s ease-in-out infinite alternate; }
  .hero__light i:nth-child(2) { animation: light-b 22s ease-in-out -6s infinite alternate; }
  .hero__light i:nth-child(3) { animation: light-c 44s ease-in-out -10s infinite alternate; }
  .tuft { animation: sway var(--d, 4s) ease-in-out var(--dl, 0s) infinite alternate; }
  .mote { animation: mote var(--d, 12s) linear var(--dl, 0s) infinite; }
  .petal { animation: petal var(--d, 18s) linear var(--dl, 0s) infinite; }
  .hero.is-away .hero__fx * { animation-play-state: paused; }

  /* параллакс от указателя: --px/--py выставляет motion.js */
  .hero__paint { translate: calc(var(--px, 0) * -12px) calc(var(--py, 0) * -8px); }
  .hero__light { translate: calc(var(--px, 0) * -20px) calc(var(--py, 0) * -12px); }
  .hero__motes { translate: calc(var(--px, 0) * -30px) calc(var(--py, 0) * -18px); }
  .hero__grass { translate: calc(var(--px, 0) * -34px) 0; }

  /* --- Разделитель-трава колышется --- */
  .grass::before { animation: grass-sway 5.5s ease-in-out infinite alternate; }

  /* --- Появление при скролле (классы ставит motion.js) --- */
  .rv { opacity: 0; }
  .rv.is-in { opacity: 1; animation: rv-up 1s var(--ease-out) backwards; animation-delay: calc(var(--rv-i, 0) * var(--rv-step, 90ms)); }
  .rv--left.is-in { animation-name: rv-left; }
  .rv--card.is-in { animation-name: rv-card; animation-duration: 1.15s; }
  .rv--grow.is-in { transform-origin: 50% 100%; animation-name: rv-grow; animation-duration: 1.2s; animation-timing-function: var(--ease-spring); }
  .rv--none, .rv--none.is-in { opacity: 1; animation: none; }
  .grass.rv.is-in { opacity: .9; }
  .rv.rv--now { animation: none; }

  /* камни пилота: выпрыгивают по очереди вдоль тропинки */
  .path li.rv { --rv-step: 240ms; }
  .path li.rv.is-in .stone { animation: stone-pop .9s var(--ease-spring) backwards; animation-delay: calc(var(--rv-i, 0) * var(--rv-step) + .1s); }
  .path__pen { stroke-dasharray: 1 2; stroke-dashoffset: 1; }
  .path__line.is-in .path__pen { stroke-dashoffset: 0; animation: pen 2s var(--ease-soft) .15s backwards; }

  /* рисование линий: иконки услуг, контактов, подчёркивания */
  .rv:not(.is-in) .ink { opacity: 0; }
  .rv.is-in .ink { animation: draw-in 1.25s var(--ease-soft) backwards; animation-delay: calc(var(--rv-i, 0) * var(--rv-step, 90ms) + var(--k, 0) * 130ms + .2s); }
  .rv.is-in .squiggle .ink { animation-duration: .9s; animation-delay: .45s; }
  .rv.rv--now .ink { animation: none; }

  /* карточка кейса: цифры по очереди */
  .case-card.rv.is-in .case-stats div { animation: rv-up .8s var(--ease-out) backwards; animation-delay: calc(.35s + var(--k, 0) * 110ms); }
  .case-stats div:nth-child(2) { --k: 1; } .case-stats div:nth-child(3) { --k: 2; } .case-stats div:nth-child(4) { --k: 3; }

  /* FAQ: ответ мягко раскрывается */
  .faq details[open] > p { animation: faq-open .5s var(--ease-out) backwards; }

  /* --- Графики: появляются, когда доезжают до экрана --- */
  .cv:not(.is-in) .chart__plot { opacity: 0; }
  .cv.is-in:not(.is-done) .chart__plot { animation: fade .6s ease-out backwards; }
  .cv.is-in:not(.is-done) .chart__plot [tabindex] {
    transform-box: fill-box; transform-origin: center;
    animation: chart-pop .7s var(--ease-spring) backwards; animation-delay: calc(.35s + var(--i, 0) * 80ms);
  }
  .cv.is-in:not(.is-done) [data-chart="latency"] rect[tabindex] { transform-origin: 0 50%; animation-name: chart-grow; animation-duration: 1s; animation-timing-function: var(--ease-out); }
  .cv.is-in:not(.is-done) .chart__plot :is(.ci, .front, .point-label, .bar-value, .sweet-label) { animation: fade .8s ease-out 1s backwards; }
  .cv.is-in:not(.is-done) .chart__plot .sweet { transform-box: fill-box; transform-origin: 0 0; animation: sweet-in 1s var(--ease-out) .15s backwards; }
  .cv.is-in:not(.is-done) [data-chart="coverage"] path { stroke-dasharray: var(--len, 1400); animation: line-draw 1.8s var(--ease-soft) .3s backwards; }
  .cv.is-in:not(.is-done) [data-chart="coverage"] circle:not([tabindex]) { transform-box: fill-box; transform-origin: center; animation: chart-pop .7s var(--ease-spring) 1.7s backwards; }
  .cv.is-in:not(.is-done) .chart__note { animation: rv-up .8s var(--ease-out) 1.6s backwards; }

  /* --- Параллакс слоёв при прокрутке: без JS, там где есть scroll-timeline --- */
  @supports (animation-timeline: scroll()) {
    @media (min-width: 1025px) {
      .hero__light, .hero__motes { animation: par-fx linear both; animation-timeline: scroll(root block); animation-range: 0 95vh; }
      .hero__text { animation: par-text linear both; animation-timeline: scroll(root block); animation-range: 0 95vh; }
    }
  }
}

/* ---------- Keyframes ---------- */

@keyframes fade { from { opacity: 0; } }
@keyframes fade-down { from { opacity: 0; transform: translateY(-14px); } }
@keyframes rise { from { opacity: 0; transform: translateY(26px); } }
@keyframes hero-title { from { opacity: 0; transform: translateY(46px) rotate(-6deg) scale(.9); } }
@keyframes hero-alias { from { opacity: 0; transform: translateX(-34px) rotate(-5deg); } }
@keyframes scene-in { from { opacity: .35; transform: scale(1.16); } }
@keyframes note-in { from { opacity: 0; transform: translateY(-46px) rotate(-7deg) scale(.94); } }
@keyframes note-float { from { translate: 0 0; } to { translate: 0 -9px; } }
@keyframes bar-fill { from { transform: scaleX(0); } }

@keyframes light-a { from { transform: translate3d(-6%, 4%, 0) scale(.94); } to { transform: translate3d(14%, -8%, 0) scale(1.12); } }
@keyframes light-b { from { transform: translate3d(8%, -6%, 0) scale(1.05); } to { transform: translate3d(-22%, 22%, 0) scale(.9); } }
@keyframes light-c { from { transform: translate3d(12%, 6%, 0) scale(1); } to { transform: translate3d(-18%, -10%, 0) scale(1.15); } }

@keyframes sway { from { transform: rotate(-4deg) skewX(-3deg); } to { transform: rotate(5deg) skewX(4.5deg); } }
@keyframes grass-sway { from { transform: skewX(-7deg); } to { transform: skewX(7deg); } }

@keyframes mote {
  0% { opacity: 0; transform: translate3d(0, 0, 0) scale(.5); }
  14% { opacity: var(--o, .8); }
  38% { opacity: calc(var(--o, .8) * .35); }
  55% { opacity: var(--o, .8); transform: translate3d(var(--dx, 20px), calc(var(--dy, -90px) * .55), 0) scale(1); }
  82% { opacity: calc(var(--o, .8) * .5); }
  100% { opacity: 0; transform: translate3d(calc(var(--dx, 20px) * -.5), var(--dy, -90px), 0) scale(.6); }
}
@keyframes petal {
  0% { opacity: 0; transform: translate3d(0, 0, 0) rotate(0deg); }
  10% { opacity: .95; }
  50% { transform: translate3d(calc(var(--dx, -260px) * .42), calc(var(--dy, 240px) * .58), 0) rotate(calc(var(--r, 420deg) * .5)); }
  88% { opacity: .9; }
  100% { opacity: 0; transform: translate3d(var(--dx, -260px), var(--dy, 240px), 0) rotate(var(--r, 420deg)); }
}

@keyframes rv-up { from { opacity: 0; transform: translate3d(0, 34px, 0); } }
@keyframes rv-left { from { opacity: 0; transform: translate3d(-28px, 0, 0); } }
@keyframes rv-card { from { opacity: 0; transform: translate3d(0, 48px, 0) rotate(-1.4deg) scale(.97); } }
@keyframes rv-grow { from { opacity: 0; transform: scaleY(.05); } }
@keyframes stone-pop { from { opacity: 0; transform: translateY(18px) scale(.4) rotate(-14deg); } }
@keyframes pen { from { stroke-dashoffset: 1; } }
@keyframes draw-in {
  from { opacity: 1; stroke-dasharray: 1 2; stroke-dashoffset: 1; fill-opacity: 0; }
  55% { fill-opacity: 0; }
  to { opacity: 1; stroke-dasharray: 1 2; stroke-dashoffset: 0; fill-opacity: 1; }
}
@keyframes faq-open { from { opacity: 0; transform: translateY(-8px); } }

@keyframes chart-pop { from { opacity: 0; transform: scale(0); } }
@keyframes chart-grow { from { transform: scaleX(0); } }
@keyframes sweet-in { from { opacity: 0; transform: scale(.6); } }
@keyframes line-draw { from { stroke-dashoffset: var(--len, 1400); } to { stroke-dashoffset: 0; } }

@keyframes par-fx { to { transform: translate3d(0, 70px, 0); } }
@keyframes par-text { to { transform: translate3d(0, 46px, 0); } }

/* ---------- Спокойный режим: ничего не движется ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .mote, .petal { display: none; }
}

@media print {
  .rv, .rv .ink, .cv .chart__plot { opacity: 1 !important; animation: none !important; }
}
