/* ===== Splash — home page intro ======================================
   Three Figma frames played as one sequence (portfolio-stuff, 1432:3550 →
   1432:3544 → 1432:3515):

     1  a grey ball flies up and drops, "hey!" rises in under it
     2  it hits as the gradient name card, "i'm yelim"
     3  the card draws in to the back of the chick's head, which turns
        to face you; "welcome to my portfolio!" and the site nav fade in

   One element (.splash__shape) is the dot, the card and the chick's face,
   so each step is a morph rather than a cut. splash.js flips data-stage on
   .splash; each stage runs one keyframed animation that starts exactly
   where the previous one ended. The head spin is driven from splash.js.

   Offsets are measured from the centre of the 1280-wide Figma frame. */

.splash {
  display: none;
}

html.splash-on {
  overflow: hidden;
}

html.splash-on .splash {
  display: block;
  position: fixed;
  inset: 0 0 auto;
  /* The visible screen, not the layout viewport: on phones a fixed inset: 0
     box runs on under the browser's toolbars, which put the splash's
     centre below the centre of what you can see. svh (toolbars showing)
     rather than dvh, which changes as the toolbars slide and would move
     the centre mid-animation. */
  height: 100vh;
  height: 100svh;
  /* The slow push-in scales the stage past the screen edges; clip it here
     so nothing can widen the page. */
  overflow: hidden;
  z-index: 50;
  /* The site's pill grey (also the footer's). */
  background: var(--wild-sand);
  cursor: pointer;
  transition: opacity 400ms var(--ease-out);
}

.splash[data-stage="out"] {
  opacity: 0;
  pointer-events: none;
}

/* The site header stays under the splash (z-index 3 < 50) until the
   splash has gone: no nav during the intro. */

/* Exit: a quick press, then the chick poofs out (small swell, slight
   blur, fade) as the splash dissolves to the hero; splash.js runs the
   chick part. The fade starts as the press releases. */
html.splash-on .splash[data-stage="out"] {
  transition: opacity 280ms cubic-bezier(0.3, 0, 0.5, 1) 120ms;
}

/* ----- The morphing shape ------------------------------------------- */

/* Position, size, radius and colour all live in the keyframes, so a stage
   change never snaps: each animation's first keyframe is the last one's end.
   Layout centres it; the moves ride on `translate` and `scale`, scaling
   about its own bottom centre. */
.splash__shape {
  position: absolute;
  /* Centred by layout (inset 0 + auto margins), not translate(-50%, -50%).
     Phones resolved that percentage once, against the ball's 30px, and
     kept it while the width animated: the card grew only to the right of
     centre, then snapped back to centre. Layout recomputes it every frame. */
  inset: 0;
  margin: auto;
  width: 30px;
  height: 30px;
  border-radius: 15px;
  background: #d8d8d8;
  overflow: hidden;
  /* Safari can drop a rounded overflow clip while an element animates,
     drawing the card's art outside it for a frame (a sideways flash on
     iPhone). A mask forces the clip; isolation keeps the art's blend
     modes inside the card. */
  -webkit-mask-image: -webkit-radial-gradient(white, black);
  isolation: isolate;
  opacity: 0;
  /* Scale about its own bottom centre. */
  transform-origin: 50% 100%;
  translate: 0 13.1px;
}

/* Rhythm: each frame (dot, card, chick) gets the same time on screen.
   Transitions are short and strongly eased; between them the whole stage
   keeps creeping forward on a slow linear push-in, so nothing is ever
   fully still. */
.splash__stage {
  position: absolute;
  inset: 0;
}

.splash[data-stage] .splash__stage {
  animation: splash-drift 3.25s linear both;
}

@keyframes splash-drift {
  from { scale: 0.97; }
  to   { scale: 1.06; }
}

/* 1 → 2 — one unbroken flight, after the reference intro's Lottie: the
   ball launches up from below, growing as it rises, peaks (the only
   instant its speed touches zero, like a thrown ball), then accelerates
   straight down the centre line, beginning to widen near the bottom, and
   hits: the card spreads out from that point in place (the rectangle
   itself never travels), carrying the impact on. Stages 1 and 2 share this one
   animation list, so switching stage at the impact doesn't restart it.
   Position, size, corners and squash each run on their own curve. */
/* Stages 1 and 2 share one identical animation list, so switching
   stage at the hit never restarts anything. */
.splash[data-stage="1"] .splash__shape,
.splash[data-stage="2"] .splash__shape {
  opacity: 1;
  animation:
    splash-flight-move 893ms both,
    splash-flight-size 1374ms both,
    splash-flight-corners 1374ms both,
    splash-flight-squash 893ms both;
}

@keyframes splash-flight-move {
  /* launch: instant speed, easing into the peak */
  0%    { translate: 0 120px;  opacity: 0;
          animation-timing-function: cubic-bezier(0.1, 0.7, 0.15, 1); }
  6%    { opacity: 1; }
  /* peak at ~425ms: the long, slow tail of the rise is the hang time */
  47.5% { translate: 0 -74px;
          animation-timing-function: cubic-bezier(0.45, 0, 0.8, 0.55); }
  /* fall: gathering speed all the way to the hit at 680ms */
  76.2% { translate: 0 -0.31px; }
  100%  { translate: 0 -0.31px; opacity: 1; }
}

/* Size and corners run the whole 1374ms up to the draw-in (move and
   grow 893); the hit is at 680ms (49.5% here). In flight the ball
   stretches as a capsule (its real height, fully rounded ends — not a
   squashed oval): tall when it's fast, round at the slow peak, tallest
   just before the hit. On the hit it goes wide and flat, spreads into the
   card, lands a touch tall and keeps slowly getting shorter (and the
   tiniest bit wider) right up to the draw-in. Size, not scale, so it only
   ever stretches straight up and down, and the words don't stretch. */
@keyframes splash-flight-size {
  /* launch: fast, so stretched; relaxing as it slows */
  0%     { width: 30px;  height: 40px;   background-color: #d8d8d8;
           animation-timing-function: cubic-bezier(0.1, 0.7, 0.15, 1); }
  /* the peak: round */
  30.9%  { width: 30px;  height: 30px;   background-color: #d8d8d8;
           animation-timing-function: cubic-bezier(0.5, 0, 0.9, 0.5); }
  /* falling faster and faster: tallest just before the hit */
  47.4%  { width: 28px;  height: 42px;   background-color: #d8d8d8;
           animation-timing-function: linear; }
  /* the hit: wide and flat */
  49.5%  { width: 60px;  height: 26px;   background-color: #e9e4da;
           animation-timing-function: cubic-bezier(0.15, 0.7, 0.3, 1); }
  /* the card, a touch tall... */
  61.3%  { width: 209px; height: 89.6px; background-color: #fff9eb;
           animation-timing-function: linear; }
  /* ...slowly shortening into the draw-in */
  100%   { width: 213px; height: 86.8px; background-color: #fff9eb; }
}

/* Fully round (a capsule) in flight, squaring off into the card. */
@keyframes splash-flight-corners {
  0%, 49.5% { border-radius: 100px;
              animation-timing-function: cubic-bezier(0.15, 0.7, 0.3, 1); }
  61.3%, 100% { border-radius: 9.065px; }
}

/* Grows as it rises (it's coming at you), uniformly, and back to size by
   the hit. */
@keyframes splash-flight-squash {
  0%    { scale: 0.55; animation-timing-function: cubic-bezier(0.1, 0.7, 0.15, 1); }
  47.5% { scale: 1.1;  animation-timing-function: cubic-bezier(0.45, 0, 0.8, 0.55); }
  76.2% { scale: 1; }
  100%  { scale: 1; }
}



/* 3 — card → the chick's face (Rectangle 4909: 103.74 × 83.661, r 41.83,
   #FFD87E), with recoil: a small wind-up, then a snap in past the face's
   size. At that turning point the drawn chick swaps in invisibly, already
   turning, finishes the recoil and comes round to face you. */
.splash[data-stage="3"] .splash__shape,
.splash[data-stage="out"] .splash__shape {
  opacity: 1;
  animation: splash-card-to-head 357ms both;
}

@keyframes splash-card-to-head {
  /* carries on from the slow shortening... */
  0%   { translate: 0 -0.31px;       width: 213px;    height: 86.8px;   border-radius: 9.065px;
         background-color: #fff9eb;
         animation-timing-function: cubic-bezier(0.3, 0, 0.5, 1); }
  /* ...a small recoil, a little wider... */
  18%  { translate: 0 -0.31px;       width: 224px;    height: 90px;     border-radius: 9.5px;
         background-color: #fff9eb;
         animation-timing-function: cubic-bezier(0.5, 0, 0.2, 1); }
  /* ...snaps in past the face (a touch small), turning yellow on the
     way. This is the recoil's turning point: the drawn chick swaps in
     here in a single frame on the exact same geometry (face scaled
     0.935 × 0.956), already turning, and carries the rest. */
  70%  { translate: 4.13px -14.76px; width: 97px;     height: 80px;     border-radius: 39.1px / 40px;
         background-color: #ffd87e;
         animation-timing-function: cubic-bezier(0.3, 0, 0.4, 1); }
  /* ...springs out past it, and settles */
  86%  { translate: 4.13px -14.76px; width: 105.5px;  height: 84.6px;   border-radius: 42px;
         animation-timing-function: cubic-bezier(0.4, 0, 0.4, 1); }
  100% { translate: 4.13px -14.76px; width: 103.74px; height: 83.661px; border-radius: 41.83px;
         background-color: #ffd87e; }
}

/* ----- Card art (frame 2) -------------------------------------------- */

/* The art's box: Figma's 100.059×209.68 frame, which it draws rotated
   -90°, so 209.68×100.059 here, bottom-centred in the card. The card's
   own rounded clip crops everything in it. */
.splash__art {
  position: absolute;
  left: calc(50% - 0.16px);
  bottom: 0;
  width: 209.68px;
  height: 100.059px;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 320ms var(--ease-out);
}

.splash[data-stage="2"] .splash__art {
  opacity: 1;
  transition: opacity 180ms var(--ease-out) 40ms;
}

/* Leaving the card, the art doesn't dissolve on its own: it stays full
   size so the narrowing card crops it, and fades on exactly the same
   timing as the card turning yellow (18% → 70% of the 357ms draw-in),
   so the gradient blends into the yellow as the card becomes the face.
   It's gone the moment the drawn chick takes over. */
.splash[data-stage="3"] .splash__art {
  animation: splash-art-into-face 250ms both;
}

@keyframes splash-art-into-face {
  0%, 25.7% { opacity: 1; animation-timing-function: cubic-bezier(0.5, 0, 0.2, 1); }
  100%      { opacity: 0; }
}


/* The gradient, flattened to one image (assets/splash/card-art-src.svg,
   rendered at 3×). It runs 25px past the art box each side and 6px top and
   bottom, so it still covers the card as it widens and drifts. Phones
   glitched compositing the old live stack (a rotated clip holding three
   moving blurred glows, one blended), drawing layers out of place for a
   frame; one image, its own layer, can't. */
.splash__art-img {
  position: absolute;
  left: -25px;
  top: -6px;
  width: 259.68px;
  height: 112.059px;
  max-width: none;
  will-change: transform;
}

/* The rings, centred where Figma puts them (converted out of its rotated
   frame), each its own layer. */
.splash__cog {
  position: absolute;
  will-change: transform;
}

.splash__cog--1 { left: calc(96.99px - 50.241px);  top: calc(81.77px - 50.241px); }
.splash__cog--2 { left: calc(34.16px - 61.241px);  top: calc(10.26px - 61.241px); }
.splash__cog--3 { left: calc(225.18px - 61.241px); top: calc(8.37px - 61.241px); }

.splash__ring {
  display: block;
  max-width: none;
}

/* ----- Words -------------------------------------------------------- */

.splash__word {
  position: absolute;
  margin: 0;
  font-family: var(--font-sans);
  font-weight: 400;
  line-height: normal;
  white-space: nowrap;
  pointer-events: none;
}

/* Until splash.js has split a word into letters (it removes data-split),
   the word is plain text and would show at full strength for the moment
   before the script runs — the "hey!" / "welcome…" flash on load. This
   stylesheet loads before the first paint, so the unsplit word never shows. */
.splash__word[data-split] {
  visibility: hidden;
}

.splash__word > span {
  display: inline-block;
  opacity: 0;
  transform: translateY(0.7em);
  transition:
    transform 240ms cubic-bezier(0.3, 1.12, 0.5, 1),
    opacity 150ms linear;
  transition-delay: calc(var(--i) * 12ms);
}

.splash__word.is-in > span {
  opacity: 1;
  transform: none;
}

.splash__word.is-out > span {
  opacity: 0;
  transform: translateY(-0.5em);
  transition-duration: 160ms, 140ms;
  transition-timing-function: var(--ease-out), linear;
  transition-delay: calc(var(--i) * 10ms);
}

/* On exit, "welcome to my portfolio!" just dissolves as a whole. */
.splash__word.is-fade {
  opacity: 0;
  transition: opacity 220ms linear;
}

/* "hey!" falls with the ball instead of floating off. */
.splash__word--hey.is-out > span {
  transform: translateY(0.5em);
  transition-timing-function: cubic-bezier(0.55, 0, 1, 0.45), linear;
}

/* "hey!" — 26.061px, top 382 in frame 1 */
.splash__word--hey,
.splash__word--welcome {
  left: 50%;
  top: 50%;
  font-size: 26.061px;
  letter-spacing: -1.0424px;
  color: #000;
  transform: translateX(-50%);
}

.splash__word--hey { margin-top: 35.1px; }

/* "welcome to my portfolio!" — top 394 in frame 3 */
.splash__word--welcome { margin-top: 47.1px; }

/* "i'm" and "yelim" sit inside the card, placed from its centre/top. */
.splash__word--im,
.splash__word--name {
  color: #272727;
}

.splash__word--name {
  left: calc(50% + 1px);
  top: 32.69px;
  font-size: 40px;
  letter-spacing: -1.6px;
}

.splash__word--im {
  left: calc(50% - 27px);
  top: 44.69px;
  font-size: 18px;
  letter-spacing: -0.72px;
}

/* On phones the Figma placement (the pair sits ~30px right of the card's
   centre) reads as off-centre, so the pair is centred in the card. */
@media (max-width: 40rem) {
  .splash__word--name { left: calc(50% - 29.5px); }
  .splash__word--im   { left: calc(50% - 57.5px); }
}

/* ----- The chick's head spin (frame 3) --------------------------------

   One chick drawn from its parts (Group 5794's geometry). The shape lands
   as the back of the head; splash.js then turns the head half a turn to
   face you, placing each part on the surface of a rotating head every
   frame: parts slide round and foreshorten at the sides, so the turn is
   continuous rather than a set of poses. */

.splash__head {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 103.74px;
  height: 103.739px;
  opacity: 0;
  transform: translate(calc(-50% + 4.13px), calc(-50% - 24.8px));
  transform-origin: 50% 100%;
}

.splash__head svg {
  display: block;
  overflow: visible;
}

/* Parts turn about their own centre. (The tuft never scales.) */
.splash__face,
.splash__face-clip,
.splash__part {
  transform-box: fill-box;
  transform-origin: 50% 50%;
}

/* Until the turn starts, the face shows its back: no features. */
.splash__part {
  opacity: 0;
}

/* The drawn chick takes over from the shape on the same frame. */
.splash[data-spin] .splash__head {
  opacity: 1;
}

.splash[data-spin] .splash__shape {
  opacity: 0;
}


/* ----- The card keeps moving inside while it's up -------------------- */

/* The card itself only widens a touch, so the life is inside it: the
   rings spin like cogs (constant speed, in place, neighbours turning
   opposite ways, speeds matched by size like meshing gears) and the
   gradient drifts slowly sideways. All linear, so nothing eases to a stop
   before the card draws in. */
.splash__cog {
  animation: splash-cog var(--cog-dur) linear infinite var(--cog-dir);
}

.splash__cog--1 { --cog-dur: 2.4s;  --cog-dir: normal; }
.splash__cog--2 { --cog-dur: 2.93s; --cog-dir: reverse; }
.splash__cog--3 { --cog-dur: 2.93s; --cog-dir: reverse; }

@keyframes splash-cog {
  from { rotate: 0deg; }
  to   { rotate: 360deg; }
}

.splash[data-stage="2"] .splash__art-img,
.splash[data-stage="3"] .splash__art-img {
  animation: splash-art-drift 1.1s linear both;
}

@keyframes splash-art-drift {
  from { translate: 8px 0; }
  to   { translate: -10px 0; }
}
