/**
 * Block: how-it-works-hero (patterns/how-it-works-hero.php)
 */

.tidal-wave-how-hero .tidal-wave-text-nowrap {
  white-space: nowrap;
}

.tidal-wave-how-hero .tidal-wave-page-hero__columns {
  align-items: center;
}

.tidal-wave-how-hero__actions.tidal-wave-hero__actions {
  gap: 0.55rem;
  row-gap: 0.55rem;
  margin-block-start: var(--tidal-wave-copy-action-gap) !important;
}

.tidal-wave-how-hero__visual {
  min-width: 0;
}

.tidal-wave-how-hero__icon-reel {
  --tidal-hiw-icon-cycle: 7s;
  position: relative;
  z-index: 1;
  width: min(100%, 13.5rem);
  max-width: 100%;
  margin-inline: auto;
  aspect-ratio: 1;
  perspective: 1100px;
  perspective-origin: 50% 50%;
}

.tidal-wave-how-hero__icon-face,
.tidal-wave-how-hero .wp-block-image.tidal-wave-how-hero__icon-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  transform: rotateY(90deg);
  opacity: 0;
  animation-name: tidal-hiw-icon-flip;
  animation-duration: var(--tidal-hiw-icon-cycle);
  animation-timing-function: cubic-bezier(0.45, 0.05, 0.55, 0.95);
  animation-iteration-count: infinite;
  animation-fill-mode: both;
  animation-play-state: paused;
  will-change: transform, opacity;
}

/* Fixed square slot so every artboard renders the same size on flip. */
.tidal-wave-how-hero__icon-face img,
.tidal-wave-how-hero .wp-block-image.tidal-wave-how-hero__icon-face img,
.tidal-wave-how-hero__icon-face .tidal-wave-theme-icon {
  display: block;
  box-sizing: border-box;
  width: 82%;
  height: 82%;
  max-width: 82%;
  max-height: 82%;
  margin: 0;
  object-fit: contain;
  object-position: center;
}

/* Stagger so each face holds briefly then flips back on the Y axis. */
.tidal-wave-how-hero__icon-face--1 {
  animation-delay: 0s;
}

.tidal-wave-how-hero__icon-face--2 {
  animation-delay: calc(var(--tidal-hiw-icon-cycle) / 3);
}

.tidal-wave-how-hero__icon-face--3 {
  animation-delay: calc(var(--tidal-hiw-icon-cycle) * 2 / 3);
}

.tidal-wave-how-hero.is-inview .tidal-wave-how-hero__icon-face,
.tidal-wave-how-hero.is-inview .wp-block-image.tidal-wave-how-hero__icon-face {
  animation-play-state: running;
}

/*
 * Face timeline (of one cycle):
 * 0–5%   enter from rotateY(-90°)
 * 5–28%  hold front
 * 28–33% spin to the back (rotateY 90°)
 * 33–100% wait offstage
 */
@keyframes tidal-hiw-icon-flip {
  0% {
    transform: rotateY(-90deg);
    opacity: 0;
  }

  5% {
    transform: rotateY(0deg);
    opacity: 1;
  }

  28% {
    transform: rotateY(0deg);
    opacity: 1;
  }

  33% {
    transform: rotateY(90deg);
    opacity: 0;
  }

  100% {
    transform: rotateY(90deg);
    opacity: 0;
  }
}

.tidal-wave-how-hero:not(.is-inview) .tidal-wave-how-hero__icon-face--1 {
  transform: rotateY(0deg);
  opacity: 1;
  animation: none;
}

.tidal-wave-how-hero:not(.is-inview) .tidal-wave-how-hero__icon-face--2,
.tidal-wave-how-hero:not(.is-inview) .tidal-wave-how-hero__icon-face--3 {
  transform: rotateY(90deg);
  opacity: 0;
  animation: none;
}

/* Desktop: reel height follows the left copy column. */
@media (min-width: 782px) {
  .tidal-wave-how-hero .tidal-wave-page-hero__columns {
    align-items: stretch;
  }

  .tidal-wave-how-hero__visual {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .tidal-wave-how-hero__icon-reel {
    --tidal-hiw-icon-cycle: 6s;
    width: auto;
    height: 100%;
    max-height: 100%;
    max-width: min(100%, 25.3rem);
    aspect-ratio: 1;
    margin-inline: auto;
  }

  .tidal-wave-how-hero__icon-face {
    animation-name: tidal-hiw-icon-flip-desktop;
  }
}

/* Desktop: slightly shorter hold before each flip. */
@keyframes tidal-hiw-icon-flip-desktop {
  0% {
    transform: rotateY(-90deg);
    opacity: 0;
  }

  5% {
    transform: rotateY(0deg);
    opacity: 1;
  }

  22% {
    transform: rotateY(0deg);
    opacity: 1;
  }

  27% {
    transform: rotateY(90deg);
    opacity: 0;
  }

  100% {
    transform: rotateY(90deg);
    opacity: 0;
  }
}

@media (max-width: 781px) {
  /*
   * Keep icons paintable: page-hero overflow:hidden + preserve-3d often
   * drops the reel on mobile Safari/Chrome.
   */
  .tidal-wave-how-hero.tidal-wave-wave-section,
  .tidal-wave-how-hero.tidal-wave-page-hero {
    overflow: visible;
  }

  /*
   * Mobile order: eyebrow → title → image → description (matches About).
   * display:contents lets copy children share the column flex with the visual.
   */
  .tidal-wave-how-hero .tidal-wave-page-hero__columns,
  .tidal-wave-how-hero .tidal-wave-page-hero__columns.wp-block-columns {
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
  }

  .tidal-wave-how-hero .tidal-wave-page-hero__columns > .wp-block-column:not(.tidal-wave-how-hero__visual) {
    display: contents;
  }

  /*
   * display:contents removes the stagger column’s box, so IntersectionObserver
   * never adds .is-inview and children would stay opacity:0. Show copy on mobile.
   */
  .tidal-wave-how-hero .tidal-wave-page-hero__columns > .wp-block-column.tidal-animate-stagger > * {
    opacity: 1;
    transform: none;
    transition: none;
    will-change: auto;
  }

  .tidal-wave-how-hero .tidal-wave-page-hero__columns > .tidal-wave-how-hero__visual {
    flex-basis: auto !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .tidal-wave-how-hero .tidal-wave-eyebrow {
    order: 1;
  }

  .tidal-wave-how-hero .tidal-wave-headline {
    order: 2;
    margin-block-start: 0;
    margin-block-end: var(--tidal-wave-title-support-gap) !important;
  }

  .tidal-wave-how-hero__visual {
    order: 3;
    display: flex !important;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin-block: 1rem 1.25rem;
    min-height: 0;
    container-type: inline-size;
  }

  /*
   * Target the copy-column child (not columns > p): display:contents keeps
   * the paragraph nested in the DOM while it participates in the flex order.
   */
  .tidal-wave-how-hero .tidal-wave-page-hero__description,
  .tidal-wave-how-hero .wp-block-column:not(.tidal-wave-how-hero__visual) > p:not(.tidal-wave-eyebrow) {
    order: 4;
    margin-block: 0;
  }

  .tidal-wave-how-hero__actions.tidal-wave-hero__actions {
    order: 5;
    width: 100%;
  }

  .tidal-wave-how-hero__icon-reel {
    /* ~3/4 of the title/description measure; explicit height for absolute faces. */
    width: 75%;
    max-width: 75%;
    height: 75cqw;
    max-height: 75cqw;
    aspect-ratio: 1;
    flex: 0 0 auto;
    margin-inline: auto;
    margin-block: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tidal-wave-how-hero__icon-face {
    animation: none !important;
  }

  .tidal-wave-how-hero__icon-face--1 {
    transform: rotateY(0deg) !important;
    opacity: 1 !important;
  }

  .tidal-wave-how-hero__icon-face--2,
  .tidal-wave-how-hero__icon-face--3 {
    transform: rotateY(90deg) !important;
    opacity: 0 !important;
  }
}
