/* =====================================================================
   Анімації по сайту.
   Тут лише рух: кольори, розміри й розташування задає styles.css.
   Логіка — site/motion.js (хвилі на кнопках, поява під час прокрутки, конфеті)
   і morph() у site/account.js (плавна зміна теми).
   Хто вимкнув анімації в системі («зменшити рух»), бачить усе одразу:
   майже все нижче — під @media (prefers-reduced-motion: no-preference).
   ===================================================================== */

/* Плавна зміна теми (morph у site/account.js): нова розкривається колом від кнопки
   (--morph-x, --morph-y — її центр, --morph-r — до найдальшого кута), стара тим часом трохи пригасає. */
:root.morph-vt::view-transition-old(root),
:root.morph-vt::view-transition-new(root) { mix-blend-mode: normal; }
:root.morph-vt::view-transition-old(root) { animation: morph-recede .75s cubic-bezier(.4, 0, .2, 1) both; }
:root.morph-vt::view-transition-new(root) { animation: morph-reveal .75s cubic-bezier(.65, 0, .35, 1) both; }
@keyframes morph-reveal {
  from { clip-path: circle(0 at var(--morph-x, 50%) var(--morph-y, 50%)); }
  to   { clip-path: circle(var(--morph-r, 150vmax) at var(--morph-x, 50%) var(--morph-y, 50%)); }
}
@keyframes morph-recede { to { filter: brightness(.9) saturate(.85); } }
:root.morph-vt::view-transition-group(root) { animation-duration: .75s; }
/* «Зменшити рух»: лише коротке перетікання */
:root.morph-vt-calm::view-transition-old(root),
:root.morph-vt-calm::view-transition-new(root) { animation-duration: .25s; }
/* Без View Transitions: сторінка згасає й проявляється */
:root.morph-fade body { transition: opacity .38s ease; }
:root.morph-fade-out body { opacity: 0; transition-duration: .2s; }

/* Іменовані частини екрана входу не виходять з кола окремо */
:root.morph-vt .auth-card, :root.morph-vt .auth-tabs-pill { view-transition-name: none; }

/* Повідомлення внизу: на телефоні — на всю ширину тексту, а не вузьким стовпчиком */
.toast { width: max-content; }

@media (prefers-reduced-motion: no-preference) {
  /* ---------- поява сторінки: блоки по черзі піднімаються ---------- */
  .wrap > *, .foot { animation: mo-rise .6s cubic-bezier(.2, .8, .3, 1) backwards; }
  .wrap > :nth-child(2) { animation-delay: .06s; }
  .wrap > :nth-child(3) { animation-delay: .12s; }
  .wrap > :nth-child(4) { animation-delay: .18s; }
  .wrap > :nth-child(5) { animation-delay: .24s; }
  .wrap > :nth-child(n+6), .foot { animation-delay: .3s; }

  /* картки модулів, уроки, план на сьогодні, досягнення, цифри профілю — по черзі */
  .modules > *, .lessons > li, .tp-list > li, .badges > *, .stats > *, .stats-sm > * {
    animation: mo-rise .55s cubic-bezier(.2, .8, .3, 1) backwards;
    animation-delay: calc(.12s + var(--mo-i, 0) * .06s);
  }
  :is(.modules, .lessons, .tp-list, .badges, .stats, .stats-sm) > :nth-child(2) { --mo-i: 1; }
  :is(.modules, .lessons, .tp-list, .badges, .stats, .stats-sm) > :nth-child(3) { --mo-i: 2; }
  :is(.modules, .lessons, .tp-list, .badges, .stats, .stats-sm) > :nth-child(4) { --mo-i: 3; }
  :is(.modules, .lessons, .tp-list, .badges, .stats, .stats-sm) > :nth-child(5) { --mo-i: 4; }
  :is(.modules, .lessons, .tp-list, .badges, .stats, .stats-sm) > :nth-child(6) { --mo-i: 5; }
  :is(.modules, .lessons, .tp-list, .badges, .stats, .stats-sm) > :nth-child(7) { --mo-i: 6; }
  :is(.modules, .lessons, .tp-list, .badges, .stats, .stats-sm) > :nth-child(n+8) { --mo-i: 7; }
  /* план на сьогодні перемальовується після кожного прикладу — тоді без повторної появи */
  .today.mo-settled .tp-list > li { animation: none; }

  /* текст уроку з'являється під час прокрутки (класи ставить motion.js) */
  .mo-wait { opacity: 0; transform: translateY(22px); }
  .mo-in { animation: mo-rise .6s cubic-bezier(.2, .8, .3, 1) backwards; animation-delay: var(--mo-d, 0s); }

  /* ---------- кнопки: пружний натиск і хвиля від пальця ---------- */
  .btn, .tp-go, .kr-form button, .icon-btn, .seg button, .tabs button, .user-chip {
    transition: transform .25s cubic-bezier(.3, 1.6, .5, 1), box-shadow .2s ease, background-color .25s ease, color .25s ease;
  }
  .btn:active, .tp-go:active, .kr-form button:active, .icon-btn:active, .seg button:active, .tabs button:active {
    transform: scale(.95); transition-duration: .08s;
  }
  .mo-ripple-host { position: relative; overflow: hidden; isolation: isolate; }
  .mo-ripple {
    position: absolute; z-index: -1; pointer-events: none; border-radius: 50%;
    width: var(--s); height: var(--s); left: var(--x); top: var(--y); margin: calc(var(--s) / -2) 0 0 calc(var(--s) / -2);
    background: currentColor; opacity: .22; transform: scale(0); animation: mo-ripple .6s cubic-bezier(.2, .8, .3, 1) forwards;
  }
  @keyframes mo-ripple { to { transform: scale(1); opacity: 0; } }

  /* стрілка в кнопці «Почати…» трохи їде вперед */
  .btn svg { transition: transform .25s cubic-bezier(.3, 1.6, .5, 1); }
  .btn:hover svg:last-child { transform: translateX(3px); }
  .pager .btn:first-child:hover svg:first-child { transform: translateX(-3px); }

  /* вибрана вкладка й сегмент «підстрибують» */
  .tabs button[aria-selected="true"], .seg button[aria-pressed="true"] { animation: mo-soft .4s cubic-bezier(.3, 1.6, .5, 1); }

  /* ---------- шапка ---------- */
  .brand img { transition: transform .5s cubic-bezier(.3, 1.6, .5, 1); }
  .brand:hover img { transform: rotate(-12deg) scale(1.08); }
  #theme-toggle svg { transition: transform .6s cubic-bezier(.3, 1.4, .5, 1); }
  #theme-toggle:hover svg { transform: rotate(-25deg); }
  .user-chip:hover .avatar { animation: mo-pop .4s cubic-bezier(.3, 1.6, .5, 1); }

  /* ---------- картки ---------- */
  .card { transition: transform .3s cubic-bezier(.2, .8, .3, 1), box-shadow .3s ease; }
  a.mod:hover, .badge:not(.locked):hover { transform: translateY(-4px); }
  a.mod .mod-sym { transition: transform .4s cubic-bezier(.3, 1.6, .5, 1); }
  a.mod:hover .mod-sym { transform: rotate(-8deg) scale(1.1); }
  .badge .b-ico { transition: transform .4s cubic-bezier(.3, 1.6, .5, 1); }
  .badge:not(.locked):hover .b-ico { transform: scale(1.2) rotate(-8deg); }
  .lesson .l-num { transition: transform .4s cubic-bezier(.3, 1.6, .5, 1); }
  .lesson:hover .l-num { transform: scale(1.12); }
  .lesson.is-done .l-check { animation: mo-pop .45s cubic-bezier(.3, 1.6, .5, 1) backwards; animation-delay: calc(.35s + var(--mo-i, 0) * .06s); }

  /* ---------- прогрес ---------- */
  .bar > span { transition: width .8s cubic-bezier(.2, .8, .3, 1); animation: mo-grow 1s cubic-bezier(.2, .8, .3, 1) .2s backwards; transform-origin: left; }
  @keyframes mo-grow { from { transform: scaleX(0); } }
  .heatmap i { animation: mo-fade .5s ease backwards; }
  .wk-bar { transition: height .5s cubic-bezier(.3, 1.4, .5, 1); transform-origin: bottom; }
  .today:not(.mo-settled) .wk-bar { animation: mo-bar .7s cubic-bezier(.3, 1.4, .5, 1) backwards; }
  .today:not(.mo-settled) .wk-bar:nth-child(2) { animation-delay: .05s; }
  .today:not(.mo-settled) .wk-bar:nth-child(3) { animation-delay: .1s; }
  .today:not(.mo-settled) .wk-bar:nth-child(4) { animation-delay: .15s; }
  .today:not(.mo-settled) .wk-bar:nth-child(5) { animation-delay: .2s; }
  .today:not(.mo-settled) .wk-bar:nth-child(6) { animation-delay: .25s; }
  .today:not(.mo-settled) .wk-bar:nth-child(7) { animation-delay: .3s; }
  @keyframes mo-bar { from { transform: scaleY(0); } }
  .tp-ring-fg { transition: stroke-dasharray .9s cubic-bezier(.2, .8, .3, 1); }
  .tp-ring.mo-bump text { animation: mo-pop .5s cubic-bezier(.3, 1.6, .5, 1); transform-box: fill-box; transform-origin: center; }
  .tp-item.mo-just-done .tp-mark { animation: mo-pop .5s cubic-bezier(.3, 1.6, .5, 1); }
  .done-btn.is-done { animation: mo-pop .45s cubic-bezier(.3, 1.6, .5, 1); }

  /* ---------- Kopfrechnen ---------- */
  .kr-task span { animation: mo-task .45s cubic-bezier(.2, .9, .3, 1.2) backwards; }
  .kr-task small { animation: mo-fade .5s ease .12s backwards; }
  .kr-note.ok { animation: mo-pop .45s cubic-bezier(.3, 1.6, .5, 1); transform-origin: left center; }
  .kopf.mo-right { animation: mo-glow .8s ease; }
  .kopf.mo-miss .kr-form { animation: mo-shake .45s cubic-bezier(.36, .07, .19, .97); }
  .kopf.mo-miss .kr-note { animation: mo-fade .3s ease; }

  /* ---------- розв'язки, вкладки профілю, повідомлення ---------- */
  .prose details[open] > :not(summary) { animation: mo-rise .4s cubic-bezier(.2, .8, .3, 1) backwards; }
  .prose summary { transition: color .2s, transform .25s cubic-bezier(.3, 1.6, .5, 1); }
  .prose summary:hover { transform: translateX(3px); }
  .tab-panel:not([hidden]) { animation: mo-rise .45s cubic-bezier(.2, .8, .3, 1) backwards; }
  .toast { transition: opacity .25s ease, transform .5s cubic-bezier(.3, 1.6, .5, 1); }
  .toast:not(.show) { transform: translate(-50%, 24px) scale(.9); }
  .toast.show { transform: translate(-50%, 0) scale(1); }
  .alert { animation: mo-rise .4s cubic-bezier(.2, .8, .3, 1) backwards; }
}

@media print { .mo-wait { opacity: 1; transform: none; } }

/* ---------- конфеті (motion.js, при виконаних цілях) ---------- */
.mo-confetti { position: fixed; inset: 0; z-index: 60; pointer-events: none; overflow: hidden; }
.mo-confetti i {
  position: absolute; left: var(--x); top: var(--y); width: 8px; height: 12px; border-radius: 2px; background: var(--c);
  animation: mo-fly 1.1s cubic-bezier(.15, .7, .4, 1) forwards; animation-delay: var(--d, 0s); opacity: 0;
}
.mo-confetti i:nth-child(3n) { border-radius: 50%; width: 9px; height: 9px; }
@keyframes mo-fly {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--r)); }
}

@keyframes mo-rise { from { opacity: 0; transform: translateY(18px); } }
@keyframes mo-fade { from { opacity: 0; } }
@keyframes mo-pop { 0% { transform: scale(.6); } 60% { transform: scale(1.12); } 100% { transform: none; } }
@keyframes mo-task { from { opacity: 0; transform: translateY(14px) scale(.92); filter: blur(3px); } }
@keyframes mo-shake { 15%, 85% { transform: translateX(-3px); } 30%, 70% { transform: translateX(6px); } 45%, 55% { transform: translateX(-8px); } }
@keyframes mo-glow { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--teal) 60%, transparent); } 100% { box-shadow: 0 0 0 18px transparent; } }
@keyframes mo-soft { 0% { transform: scale(.92); } 60% { transform: scale(1.04); } 100% { transform: none; } }

/* =====================================================================
   Зміна мови (setLang у site/account.js): повзунок UA / DE переїжджає з пружинкою, кнопки «натискаються»,
   сторінку від кнопки накриває коло кольору сайту з назвою мови, а на новій сторінці воно розходиться
   з того ж місця (клас lang-arrive на <html>). Зі «зменшити рух» — без цього.
   ===================================================================== */
@media (prefers-reduced-motion: no-preference) {
  .lang-switch .ls-knob { transition: transform .45s cubic-bezier(.34, 1.56, .64, 1); }
  .lang-switch button:active { transform: scale(.92); }
  .lang-switch button { transition: color .25s ease, transform .15s ease; }
  .lang-switch:hover .ls-knob { box-shadow: 0 3px 0 var(--btn-edge); }
  .lang-cards button:active { transform: scale(.97); }
  .lang-cards button[aria-pressed="true"] .lc-code { animation: mo-pop .45s cubic-bezier(.34, 1.56, .64, 1); }

  .lang-wipe { animation: lang-wipe-in .55s cubic-bezier(.65, 0, .35, 1) both; }
  .lang-wipe span { animation: lang-word-in .5s cubic-bezier(.2, .8, .3, 1) .12s both; }
  :root.lang-arrive::after {
    content: attr(data-wipe-name); position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
    background: var(--teal); color: var(--on-teal); font-size: clamp(32px, 8vw, 64px); font-weight: 800; pointer-events: none;
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; letter-spacing: -.01em;
    animation: lang-wipe-out .8s cubic-bezier(.65, 0, .35, 1) .05s both;
  }
}
@keyframes lang-wipe-in {
  from { clip-path: circle(0 at var(--wipe-x, 50%) var(--wipe-y, 50%)); }
  to   { clip-path: circle(var(--wipe-r, 150vmax) at var(--wipe-x, 50%) var(--wipe-y, 50%)); }
}
@keyframes lang-wipe-out {
  from { clip-path: circle(var(--wipe-r, 150vmax) at var(--wipe-x, 50%) var(--wipe-y, 50%)); }
  70%  { color: transparent; }
  to   { clip-path: circle(0 at var(--wipe-x, 50%) var(--wipe-y, 50%)); color: transparent; }
}
@keyframes lang-word-in {
  from { opacity: 0; transform: translateY(14px) scale(.9); }
  to   { opacity: 1; transform: none; }
}
