/*
 * Motion (client folder design/liikesuunnitelma-2026-11-28.md, Niko approved 2026-11-28). Light movement that
 * draws the eye to getting in touch. Only transform and opacity (plus the line draw), nothing loops, nothing moves
 * for visitors who ask for less motion, and nothing is hidden unless motion.js has run.
 */
@media (prefers-reduced-motion: no-preference) {
  /* Pages fade into each other where the browser supports it. */
  @view-transition {
    navigation: auto;
  }

  /* Buttons: the arrow steps forward, a press gives a little. */
  .xg-btn__icon {
    transition: transform 200ms ease;
  }

  .xg-btn:is(:hover, :focus-visible) .xg-btn__icon {
    transform: translateX(4px);
  }

  .xg-btn {
    transition: transform 120ms ease, background-color var(--transition), color var(--transition), border-color var(--transition);
  }

  .xg-btn:active {
    transform: scale(0.98);
  }

  /* Image cards: the photo comes a touch closer. */
  :is(.xg-postcard__media, .xg-option__media, .xg-servicecard__media, .xg-servicegroup__media, .xg-campaign) {
    overflow: hidden;
  }

  :is(.xg-postcard, .xg-option, .xg-servicecard, .xg-servicegroup, .xg-campaign, .xg-path) img {
    transition: transform 500ms ease;
  }

  :is(.xg-postcard, .xg-option, .xg-servicecard, .xg-servicegroup, .xg-campaign, .xg-path):is(:hover, :focus-within) img {
    transform: scale(1.03);
  }

  /* Entrance: motion.js marks only things below the fold, then adds .is-in once. */
  .xg-reveal {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 400ms ease, transform 400ms ease;
    transition-delay: calc(var(--xg-i, 0) * 60ms);
  }

  .xg-reveal.is-in {
    opacity: 1;
    transform: none;
  }

  /* The preview waits beside its place; it must not widen the page meanwhile. */
  .xg-studio {
    overflow-x: clip;
  }

  .xg-studio__preview.xg-reveal {
    transform: translateX(32px);
  }

  .xg-studio__preview.xg-reveal.is-in {
    transform: none;
  }

  /* Process: each step's top line draws towards the quote button, one after another. */
  .xg-process .xg-steps__item.xg-reveal {
    position: relative;
    border-block-start-color: transparent;
  }

  .xg-process .xg-steps__item.xg-reveal::after {
    content: "";
    position: absolute;
    inset: -2px 0 auto;
    block-size: 2px;
    background: var(--color-ink);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 500ms ease calc(150ms + var(--xg-i, 0) * 220ms);
  }

  [data-surface="dark"] .xg-steps__item.xg-reveal::after {
    background: var(--color-accent);
  }

  .xg-process .xg-steps__item.xg-reveal.is-in::after {
    transform: scaleX(1);
  }

  /* Studio steps: the numbers 01–03 light up in turn, once. */
  .xg-studio .xg-steps__item.is-in::before {
    animation: xg-lit 900ms ease calc(300ms + var(--xg-i, 0) * 450ms) 1 both;
  }

  @keyframes xg-lit {
    0% { opacity: 0.35; }
    50% { opacity: 1; transform: scale(1.18); }
    100% { opacity: 1; transform: none; }
  }

  /* Closing CTA: one sweep of light across the button, like light on glass. */
  .xg-cta .xg-btn {
    position: relative;
    overflow: hidden;
  }

  .xg-cta .xg-btn::after {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    inline-size: 45%;
    background: linear-gradient(105deg, transparent, rgb(255 255 255 / 35%), transparent);
    transform: translateX(-120%);
    pointer-events: none;
  }

  .xg-cta.is-shine .xg-btn::after {
    animation: xg-shine 900ms ease 500ms 1 forwards;
  }

  @keyframes xg-shine {
    to { transform: translateX(330%); }
  }

  /* Car-glass quiz: each step slides in, the progress bar fills smoothly. */
  .xg-quiz .leadflow-stage .leadflow__step:not([hidden]) {
    animation: xg-step 280ms ease 1 both;
  }

  @keyframes xg-step {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: none; }
  }

  .xg-quiz .leadflow-stage .leadflow__progress-bar {
    transition: width 400ms ease;
  }

  .xg-actionbar {
    transition: transform 240ms ease, visibility 0s linear 0s;
  }

  .xg-actionbar[data-away] {
    transform: translateY(100%);
    transition: transform 240ms ease, visibility 0s linear 240ms;
  }
}

/* Header menu: panels and their items come in when opened, a sand line follows the pointer. Animations restart each
   time a panel goes from hidden to shown, so no script is needed. */
@media (prefers-reduced-motion: no-preference) {
  @keyframes xg-drop {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: none; }
  }

  @keyframes xg-rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }

  @keyframes xg-from-side {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: none; }
  }

  @media (min-width: 68.01em) {
    :is(.xg-nav__link, .xg-nav__toggle) {
      position: relative;
    }

    :is(.xg-nav__link, .xg-nav__toggle)::after {
      content: "";
      position: absolute;
      inset: auto 0 0.35rem;
      block-size: 2px;
      background: var(--color-accent);
      transform: scaleX(0);
      transform-origin: left;
      transition: transform 220ms ease;
    }

    :is(.xg-nav__link, .xg-nav__toggle):is(:hover, :focus-visible, [aria-expanded="true"], [aria-current="page"])::after,
    .xg-nav__item.is-current > :is(.xg-nav__link, .xg-nav__toggle)::after {
      transform: scaleX(1);
    }

    .xg-nav__chevron {
      transition: transform 220ms ease;
    }

    .xg-nav__toggle[aria-expanded="true"] .xg-nav__chevron {
      transform: translateY(0.1em) rotate(225deg);
    }

    .xg-nav__toggle[aria-expanded="true"] + .xg-nav__panel {
      animation: xg-drop 220ms ease both;
    }

    .xg-nav__toggle[aria-expanded="true"] + .xg-nav__panel .xg-nav__sub > li {
      animation: xg-rise 260ms ease both;
    }

    .xg-nav__toggle[aria-expanded="true"] + .xg-nav__panel .xg-nav__promo {
      animation: xg-from-side 320ms ease 120ms both;
    }

    .xg-nav__sublink .xg-icon {
      transition: transform 200ms ease;
    }

    .xg-nav__sublink:is(:hover, :focus-visible) .xg-icon {
      transform: translateX(3px);
    }
  }

  @media (max-width: 68em) {
    .xg-header.is-open .xg-nav {
      animation: xg-drop 220ms ease both;
    }

    .xg-header.is-open .xg-nav__list > li {
      animation: xg-rise 280ms ease both;
    }

    .xg-header.is-open .xg-nav__mobile-actions {
      animation: xg-rise 320ms ease 260ms both;
    }

    .xg-nav__toggle[aria-expanded="true"] + .xg-nav__panel {
      animation: xg-drop 220ms ease both;
    }

    .xg-header__toggle[aria-expanded="true"] .xg-header__close {
      animation: xg-turn 220ms ease both;
    }

    @keyframes xg-turn {
      from { opacity: 0; transform: rotate(-90deg); }
      to { opacity: 1; transform: none; }
    }
  }

  /* One item after another, 35 ms apart; later items share the last delay. */
  :is(.xg-nav__sub, .xg-header.is-open .xg-nav__list) > li:nth-child(2) { animation-delay: 35ms !important; }
  :is(.xg-nav__sub, .xg-header.is-open .xg-nav__list) > li:nth-child(3) { animation-delay: 70ms !important; }
  :is(.xg-nav__sub, .xg-header.is-open .xg-nav__list) > li:nth-child(4) { animation-delay: 105ms !important; }
  :is(.xg-nav__sub, .xg-header.is-open .xg-nav__list) > li:nth-child(5) { animation-delay: 140ms !important; }
  :is(.xg-nav__sub, .xg-header.is-open .xg-nav__list) > li:nth-child(6) { animation-delay: 175ms !important; }
  :is(.xg-nav__sub, .xg-header.is-open .xg-nav__list) > li:nth-child(n + 7) { animation-delay: 210ms !important; }
}

/* Print shows everything. */
@media print {
  .xg-reveal {
    opacity: 1 !important;
    transform: none !important;
  }
}
