/* ==========================================================================
   Entrance animation

   Recreates the opening seven seconds of images/FOCUS_MEDIA_V1.mp4: the mark
   is drafted in thin construction lines, flooded with yellow, opened into a
   window onto the work, then shrunk into the full lockup as FOCUS writes in.

   The whole timeline is CSS keyframes on delays. js/intro.js only decides
   whether to play, builds the markup, measures the two custom properties the
   shrink needs, and tears the overlay down at the end - so the animation
   itself never depends on a JS timer staying in step.

   Kept out of main.scss / main.css on purpose: those two are a compiled pair
   and sass isn't installed here, so hand-editing them risks the .scss and the
   .css drifting apart.
   ========================================================================== */

/* --------------------------------------------------------------------------
   The cover

   js/intro.js is a blocking script in <head>, so this class lands before the
   body is parsed and the navy is painted on the very first frame. Without it
   the page would flash through before the overlay mounted.
   -------------------------------------------------------------------------- */
html.intro-active {
  overflow: hidden;
}

html.intro-active::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: var(--deep-blue, #1d2733);
}

/* Dropped the moment the overlay itself is in the DOM and carrying the navy,
   so the two never cross-fade against each other. */
html.intro-mounted::before {
  display: none;
}

.fx-intro {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--deep-blue, #1d2733);
  /* The overlay is the only thing on screen; nothing behind it is reachable. */
  touch-action: none;
}

.fx-intro.is-done {
  animation: fx-overlay-out 0.45s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes fx-overlay-out {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

/* --------------------------------------------------------------------------
   Lockup

   Sized as the finished logo. The mark sits in its final slot from the start
   and is transformed up to full-screen size for the drafting stages, so the
   shrink lands exactly on the wordmark with no seam to correct.

   images/logo.webp is 1400x215 with the mark occupying x 0-216, which is what
   every percentage below is derived from.
   -------------------------------------------------------------------------- */
.fx-lockup {
  --fx-w: min(46vw, 480px);
  /* How much bigger the mark is while it is being drafted. */
  --fx-scale: 5;

  position: relative;
  width: var(--fx-w);
  aspect-ratio: 1400 / 215;
}

@media (max-width: 640px) {
  .fx-lockup {
    --fx-w: min(78vw, 340px);
    --fx-scale: 4.4;
  }
}

/* Landscape phones and short windows: the drafted mark would otherwise run
   off the top and bottom. */
@media (max-height: 620px) {
  .fx-lockup {
    --fx-scale: 3.6;
  }
}

/* aspect-ratio is recent enough that a height fallback is worth keeping. */
@supports not (aspect-ratio: 1 / 1) {
  .fx-lockup::after {
    content: '';
    display: block;
    padding-top: 15.357%;
  }
}

.fx-mark {
  position: absolute;
  left: 0;
  top: 0;
  width: 15.429%; /* 216 / 1400 */
  height: 100%;
  overflow: visible;
  transform-origin: 50% 50%;
  /* Drafting position: dead centre of the viewport, scaled up.

     The lockup is centred, so its left edge sits at 50vw - w/2 and the mark
     slot's centre at 50vw - w/2 + 0.154286w/2. Pushing right by
     w * (0.5 - 0.077143) puts that centre on 50vw. Vertically the mark is the
     full height of an already-centred lockup, so there is nothing to correct.

     Derived rather than measured on purpose: a measurement taken while the
     tab is in the background comes back as zero, and the mark would start
     the animation in the wrong place. */
  transform: translateX(calc(var(--fx-w) * 0.422857)) scale(var(--fx-scale));
}

.is-running .fx-mark {
  animation: fx-shrink 1.45s cubic-bezier(0.65, 0, 0.35, 1) 3.95s forwards;
}

@keyframes fx-shrink {
  to {
    transform: translateX(0) scale(1);
  }
}

/* --------------------------------------------------------------------------
   Stage 1 - construction lines (0.10s - 0.75s)
   -------------------------------------------------------------------------- */
/* Stroke widths are in viewBox units, not screen pixels, so the line keeps
   its weight relative to the mark as it scales - which is what the video
   does. non-scaling-stroke would leave it hairline at full size. */
.fx-guides {
  fill: none;
  stroke: var(--deep-blue-2, #3a516d);
  stroke-width: 1.6;
  opacity: 0;
}

.is-running .fx-guides > * {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: fx-draw 0.65s cubic-bezier(0.33, 1, 0.68, 1) 0.1s forwards;
}

.is-running .fx-guides > *:nth-child(2) {
  animation-delay: 0.18s;
}
.is-running .fx-guides > *:nth-child(3) {
  animation-delay: 0.26s;
}
.is-running .fx-guides > *:nth-child(4) {
  animation-delay: 0.34s;
}

.is-running .fx-guides {
  animation: fx-guides-life 1.95s linear forwards;
}

@keyframes fx-guides-life {
  0% {
    opacity: 0;
  }
  6% {
    opacity: 0.9;
  }
  79% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   Stage 2 - the mark drafts itself (0.40s - 1.75s)

   fx-ghost is the same outline drawn two more times a few units off, sliding
   home and fading as the real one completes. That doubled, settling line is
   what reads as a drawing in the video.
   -------------------------------------------------------------------------- */
.fx-outline {
  fill: none;
  stroke: var(--white, #fff);
  stroke-width: 2.6;
}

.is-running .fx-outline > * {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: fx-draw 1.35s cubic-bezier(0.65, 0, 0.35, 1) 0.4s forwards;
}

.is-running .fx-outline > *:nth-child(2) {
  animation-delay: 0.55s;
}
.is-running .fx-outline > *:nth-child(3) {
  animation-duration: 0.6s;
  animation-delay: 1.15s;
}

@keyframes fx-draw {
  to {
    stroke-dashoffset: 0;
  }
}

/* Once the fill has taken over, the line stops being the subject and just
   holds the edges - it never disappears, exactly as in the video. */
.is-running .fx-outline {
  animation: fx-outline-settle 0.4s ease-out 2.55s forwards;
}

@keyframes fx-outline-settle {
  to {
    stroke: var(--gray, #acb9bf);
    stroke-opacity: 0.55;
  }
}

.fx-ghost {
  fill: none;
  stroke: var(--white, #fff);
  stroke-width: 1.8;
  opacity: 0;
}

.fx-ghost--a {
  --fx-gx: 7px;
  --fx-gy: -5px;
}

.fx-ghost--b {
  --fx-gx: -6px;
  --fx-gy: 6px;
}

.is-running .fx-ghost {
  animation: fx-ghost-life 1.5s cubic-bezier(0.33, 1, 0.68, 1) 0.35s forwards;
}

.is-running .fx-ghost--b {
  animation-delay: 0.5s;
}

@keyframes fx-ghost-life {
  0% {
    opacity: 0;
    transform: translate(var(--fx-gx, 0px), var(--fx-gy, 0px));
  }
  25% {
    opacity: 0.4;
  }
  70% {
    opacity: 0.22;
  }
  100% {
    opacity: 0;
    transform: translate(0, 0);
  }
}

/* --------------------------------------------------------------------------
   Stage 3 - the yellow floods in (1.85s - 2.80s)

   Each half of the mark is clipped to its own outline, and a very wide yellow
   stroke is drawn along a centre line running from the rounded corner, up the
   column and out along the arm. Clipped, that reads as ink flooding the shape
   end to end, which is the motion in the source.
   -------------------------------------------------------------------------- */
.fx-flood {
  fill: none;
  stroke: var(--yellow, #ffa405);
  stroke-width: 132;
  stroke-linecap: butt;
  stroke-linejoin: miter;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.is-running .fx-flood {
  animation: fx-draw 0.95s cubic-bezier(0.5, 0, 0.35, 1) 1.85s forwards;
}

.fx-dot {
  fill: var(--yellow, #ffa405);
  transform-box: fill-box;
  transform-origin: 50% 50%;
  transform: scale(0);
}

.is-running .fx-dot {
  animation: fx-dot-in 0.35s cubic-bezier(0.34, 1.4, 0.64, 1) 3s forwards;
}

@keyframes fx-dot-in {
  to {
    transform: scale(1);
  }
}

/* --------------------------------------------------------------------------
   Stage 4 - the mark opens onto the work (3.85s - 5.50s)
   -------------------------------------------------------------------------- */
.fx-photos {
  opacity: 0;
}

.is-running .fx-photos {
  animation: fx-photos-life 1.65s linear 3.85s forwards;
}

@keyframes fx-photos-life {
  0% {
    opacity: 0;
  }
  21% {
    opacity: 1;
  }
  79% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* Each frame holds, then hands over to the one stacked above it. */
.fx-photos image {
  opacity: 0;
}

.fx-photos image:first-child {
  opacity: 1;
}

.is-running .fx-photos image:nth-child(2) {
  animation: fx-fade-in 0.4s ease-in-out 4.35s forwards;
}

.is-running .fx-photos image:nth-child(3) {
  animation: fx-fade-in 0.4s ease-in-out 4.85s forwards;
}

@keyframes fx-fade-in {
  to {
    opacity: 1;
  }
}

/* --------------------------------------------------------------------------
   Stage 5 - FOCUS writes in (5.40s - 6.80s)

   Every piece is the same logo.png used as an alpha mask over a flat colour,
   so the letterforms are the real ones and the intro can invert the palette
   the way the video does - yellow mark, white word - without a second asset.

   clip-path isolates one letter and also wipes it: the right inset starts at
   the letter's own left edge and opens out to its right edge.
   -------------------------------------------------------------------------- */
.fx-word {
  position: absolute;
  inset: 0;
  display: block;
  background-color: var(--white, #fff);
  -webkit-mask-image: url(../images/logo.webp);
  mask-image: url(../images/logo.webp);
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  opacity: 0;
}

.fx-word--tag {
  background-color: var(--gray, #acb9bf);
}

/* Longhands throughout: the animation shorthand would reset the per-letter
   delay set alongside it, and it wins on specificity. */
.is-running .fx-word {
  animation-duration: 0.42s;
  animation-timing-function: cubic-bezier(0.33, 1, 0.68, 1);
  animation-fill-mode: forwards;
}

/* Each letter's slice of the source, taken at the midpoints of the empty
   columns between them: 260.5, 471.5, 682, 872.5, 1059, 1248 of 1400.
   The video brings O C U S up first and closes with the F. */
.fx-word--o {
  clip-path: inset(0 66.321% 0 33.679%);
}
.fx-word--c {
  clip-path: inset(0 51.286% 0 48.714%);
}
.fx-word--u {
  clip-path: inset(0 37.679% 0 62.321%);
}
.fx-word--s {
  clip-path: inset(0 24.357% 0 75.643%);
}
.fx-word--f {
  clip-path: inset(0 81.393% 0 18.607%);
}

.is-running .fx-word--o {
  animation-name: fx-letter-o;
  animation-delay: 5.4s;
}
.is-running .fx-word--c {
  animation-name: fx-letter-c;
  animation-delay: 5.47s;
}
.is-running .fx-word--u {
  animation-name: fx-letter-u;
  animation-delay: 5.54s;
}
.is-running .fx-word--s {
  animation-name: fx-letter-s;
  animation-delay: 5.61s;
}
.is-running .fx-word--f {
  animation-name: fx-letter-f;
  animation-delay: 5.95s;
}

@keyframes fx-letter-o {
  from {
    opacity: 0;
    clip-path: inset(0 66.321% 0 33.679%);
  }
  to {
    opacity: 1;
    clip-path: inset(0 51.286% 0 33.679%);
  }
}
@keyframes fx-letter-c {
  from {
    opacity: 0;
    clip-path: inset(0 51.286% 0 48.714%);
  }
  to {
    opacity: 1;
    clip-path: inset(0 37.679% 0 48.714%);
  }
}
@keyframes fx-letter-u {
  from {
    opacity: 0;
    clip-path: inset(0 37.679% 0 62.321%);
  }
  to {
    opacity: 1;
    clip-path: inset(0 24.357% 0 62.321%);
  }
}
@keyframes fx-letter-s {
  from {
    opacity: 0;
    clip-path: inset(0 24.357% 0 75.643%);
  }
  to {
    opacity: 1;
    clip-path: inset(0 10.857% 0 75.643%);
  }
}
@keyframes fx-letter-f {
  from {
    opacity: 0;
    clip-path: inset(0 81.393% 0 18.607%);
  }
  to {
    opacity: 1;
    clip-path: inset(0 66.321% 0 18.607%);
  }
}

/* ENG over ARQ, split on the gap between the two lines. */
.fx-word--eng {
  clip-path: inset(0 0 53.5% 89.143%);
}
.fx-word--arq {
  clip-path: inset(46.5% 0 0 89.143%);
}

.is-running .fx-word--eng {
  animation-name: fx-fade-in;
  animation-duration: 0.3s;
  animation-timing-function: ease-out;
  animation-delay: 6.35s;
}
.is-running .fx-word--arq {
  animation-name: fx-fade-in;
  animation-duration: 0.3s;
  animation-timing-function: ease-out;
  animation-delay: 6.5s;
}

/* --------------------------------------------------------------------------
   Skip
   -------------------------------------------------------------------------- */
.fx-skip {
  position: absolute;
  right: max(24px, 4vw);
  bottom: max(24px, 4vh);
  padding: 10px 22px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: none;
  color: var(--gray, #acb9bf);
  font-family: 'Poppins', sans-serif;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  opacity: 0;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.is-running .fx-skip {
  animation: fx-fade-skip 0.4s ease-out 1.2s forwards;
}

@keyframes fx-fade-skip {
  to {
    opacity: 0.75;
  }
}

.fx-skip:hover,
.fx-skip:focus-visible {
  color: var(--white, #fff);
  border-color: rgba(255, 255, 255, 0.6);
}

/* --------------------------------------------------------------------------
   Reduced motion

   js/intro.js already declines to play at all here, so this is only a belt
   and braces guard for the overlay never being left on screen.
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html.intro-active {
    overflow: auto;
  }

  html.intro-active::before,
  .fx-intro {
    display: none;
  }
}
