/* Homepage preloader, see template-parts/preloader.php. Taken over 1:1 from
   the Prime design artifact: only the P mark shows first (the rest of the
   logo clipped away, shifted to the centre), it grows, then the logo slides
   into place and unfolds while the bar below fills. */

@layer components {
  .preloader {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 34px;
    align-items: center;
    justify-content: center;
    background: #ecedeb;
    transition:
      opacity 0.5s ease,
      visibility 0.5s ease;
  }

  .preloader[data-state='done'] {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  .preloader__logo {
    width: min(340px, 70vw);
  }

  .preloader__logo img {
    width: 100%;
    height: auto;
  }

  /* Kept on 'done' too, so the logo and the full bar stay while fading out. */
  .preloader:is([data-state='run'], [data-state='done']) .preloader__logo {
    animation: preloader-logo 2.1s cubic-bezier(0.7, 0, 0.2, 1) both;
  }

  .preloader__bar {
    width: 140px;
    height: 2px;
    overflow: hidden;
    border-radius: 2px;
    background: rgb(21 63 63 / 15%);
  }

  .preloader__bar span {
    display: block;
    width: 0;
    height: 100%;
    background: #153f3f;
  }

  .preloader:is([data-state='run'], [data-state='done']) .preloader__bar span {
    animation: preloader-bar 2.3s ease forwards;
  }

  /* The clip only works horizontally; top, bottom and left sit 1px outside
     the box on purpose. The logo is 44.58px high, so the box edge cuts a
     pixel row. Chrome clips on the compositor while the animation runs and
     in paint once it has finished, and the two draw that cut row
     differently: with inset(0) that row jumped at 2.1s (the flicker). */
  @keyframes preloader-logo {
    0% {
      opacity: 0;
      transform: translateX(40.5%) scale(0.86);
      clip-path: inset(-1px 81% -1px -1px);
    }

    28% {
      opacity: 1;
      transform: translateX(40.5%) scale(1);
      clip-path: inset(-1px 81% -1px -1px);
    }

    62%,
    100% {
      opacity: 1;
      transform: none;
      clip-path: inset(-1px);
    }
  }

  @keyframes preloader-bar {
    to {
      width: 100%;
    }
  }
}
