/* Kaivee motion layer: playful, snappy "sticker" motion for the public site and /app.

   House rules
   - Every animation and transition lives inside the prefers-reduced-motion:
     no-preference block. People who ask for less motion get the static site.
   - Movement uses the individual transform properties (translate, rotate, scale)
     so it stacks on top of each sticker's resting tilt from site.css/style.css.
     Everything lands exactly where it sat before this file existed.
   - Content is only hidden before a reveal when motion.js has marked it as
     off-screen (data-reveal). Without JavaScript nothing is ever hidden.
   - Idle motion is limited to the home hero (stars, speech bubble, Kai's loop),
     one page-header star per page and the "current stage" ring on /progress. */

:root {
  --k-ink: #161616;
  --k-spring: cubic-bezier(.34, 1.56, .64, 1);
  --k-spring-soft: cubic-bezier(.3, 1.25, .6, 1);
  --k-out: cubic-bezier(.22, 1, .36, 1);
}

/* Real damped springs where the browser supports linear() easing.
   --k-spring: damping ratio 0.5 (about 16% overshoot) for stickers.
   --k-spring-soft: damping ratio 0.7 (about 5% overshoot) for cards. */
@supports (animation-timing-function: linear(0, 1)) {
  :root {
    --k-spring: linear(0, 0.035, 0.125, 0.251, 0.397, 0.547, 0.691, 0.821, 0.931, 1.019, 1.085, 1.129, 1.154, 1.163, 1.159, 1.145, 1.125, 1.102, 1.077, 1.054, 1.032, 1.014, 0.999, 0.987, 0.98, 0.975, 0.974, 0.974, 0.976, 0.979, 0.983, 0.987, 0.991, 0.994, 0.997, 1, 1.002, 1.003, 1.004, 1.004, 1);
    --k-spring-soft: linear(0, 0.018, 0.064, 0.132, 0.212, 0.3, 0.39, 0.479, 0.564, 0.644, 0.716, 0.781, 0.837, 0.885, 0.926, 0.959, 0.986, 1.006, 1.022, 1.033, 1.04, 1.044, 1.046, 1.046, 1.044, 1.041, 1.037, 1.033, 1.029, 1.025, 1.021, 1.017, 1.014, 1.011, 1.008, 1.006, 1.004, 1.002, 1.001, 1, 1);
  }
}

/* ---------- Static pieces (state and layout, no movement) ---------- */

/* Celebration bits are absolutely placed around a fixed point. */
.k-burst { position: fixed; z-index: 1000; width: 0; height: 0; pointer-events: none; }
.k-bit {
  position: absolute; left: -6px; top: -6px; width: 12px; height: 12px;
  border: 2px solid var(--k-ink); border-radius: 50%; background: var(--c, #FFD84D);
}
.k-bit.is-strip { left: -4px; top: -9px; width: 8px; height: 18px; border-radius: 3px; }
svg.k-bit { left: -12px; top: -12px; width: 24px; height: 24px; border: 0; border-radius: 0; background: none; overflow: visible; }
svg.k-bit path { fill: var(--c, #FFD84D); stroke: var(--k-ink); stroke-width: 5; stroke-linejoin: round; }

/* Kai's looping clip sits exactly over the photo inside the white ring. */
.hero-loop {
  position: absolute; inset: 10px; width: calc(100% - 20px); height: calc(100% - 20px);
  border-radius: 50%; object-fit: cover; opacity: 0; pointer-events: none;
}
.hero-photo.is-playing .hero-loop { opacity: 1; }
/* The arrow carries its own space and cancels the .btn flex gap, so the button keeps its exact width. */
.btn-arrow { display: inline-block; margin-left: -8px; }

/* The upload box's dashed border, redrawn as SVG so the dashes can march. */
.upload-zone.has-ants { border-color: transparent; }
.k-ants { position: absolute; left: -3px; top: -3px; pointer-events: none; overflow: visible; }
.k-ants rect { fill: none; stroke: var(--k-ink); stroke-width: 3; stroke-dasharray: 9 6; }

/* /collect: the three steps tick off as each part is done. */
.mini-steps li.is-done .num { position: relative; color: transparent; }
.mini-steps li.is-done .num::after {
  content: "\2713"; position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--k-ink); font-weight: 900;
}

/* /collect: "Kaivee is watching" while the real job is queued or running. */
.count-up { font-variant-numeric: tabular-nums; }
.watch { display: none; width: min(280px, 100%); margin: 6px auto 12px; }
#analysisResult[data-state="queued"] .watch,
#analysisResult[data-state="running"] .watch { display: block; }
.watch-frame {
  position: relative; overflow: hidden; aspect-ratio: 4 / 3;
  border: 3px solid var(--k-ink); border-radius: 18px; box-shadow: 4px 4px 0 var(--k-ink);
  background: radial-gradient(#16161622 1.4px, transparent 1.4px) 0 0 / 16px 16px, #BFE6FF;
}
.watch-icon { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; translate: -50% -50%; }
.watch-still { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; }
.watch-still.has-frame { opacity: 1; }
.watch-frame::before {
  content: ""; position: absolute; inset: 12px; z-index: 2; pointer-events: none;
  --c: #FFFFFF; --l: 22px; --t: 4px;
  background:
    linear-gradient(var(--c) 0 0) top left / var(--l) var(--t),
    linear-gradient(var(--c) 0 0) top left / var(--t) var(--l),
    linear-gradient(var(--c) 0 0) top right / var(--l) var(--t),
    linear-gradient(var(--c) 0 0) top right / var(--t) var(--l),
    linear-gradient(var(--c) 0 0) bottom left / var(--l) var(--t),
    linear-gradient(var(--c) 0 0) bottom left / var(--t) var(--l),
    linear-gradient(var(--c) 0 0) bottom right / var(--l) var(--t),
    linear-gradient(var(--c) 0 0) bottom right / var(--t) var(--l);
  background-repeat: no-repeat;
  filter: drop-shadow(1.5px 1.5px 0 var(--k-ink));
}
.watch-scan {
  position: absolute; left: 0; right: 0; top: 0; height: 100%; z-index: 1; opacity: 0; pointer-events: none;
  background: linear-gradient(to bottom, transparent 40%, rgba(255, 216, 77, .45) 47%, #FFD84D 50%, rgba(255, 216, 77, .45) 53%, transparent 60%);
}
.watch-chip {
  position: absolute; left: 10px; bottom: 10px; z-index: 3;
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  background: #FFFFFF; border: 2px solid var(--k-ink); border-radius: 999px;
  font-size: 12px; font-weight: 900; line-height: 1.2;
}
.watch-chip .rec-dot { width: 9px; height: 9px; }
.watch-label-running { display: none; }
#analysisResult[data-state="running"] .watch-label-running { display: inline; }
#analysisResult[data-state="running"] .watch-label-queued { display: none; }
/* A finished result reads as its own sticker card. */
#analysisResult:is([data-state="done"], [data-state="rejected"], [data-state="unavailable"], [data-state="failed"], [data-state="gave-up"]) #analysisResultText {
  margin: 0 0 8px; padding: 12px 16px; background: #FFFFFF;
  border: 2.5px solid var(--k-ink); border-radius: 16px; box-shadow: 3px 3px 0 var(--k-ink); font-weight: 600;
}

@media print {
  [data-reveal] { opacity: 1 !important; }
  .k-burst, .hero-loop { display: none !important; }
}

/* ---------- Motion (only for people who haven't asked for less) ---------- */

@media (prefers-reduced-motion: no-preference) {

  /* Keyframes ------------------------------------------------------------ */
  @keyframes k-slap   { from { opacity: 0; scale: 1.45; rotate: -9deg; } to { opacity: 1; scale: 1; rotate: 0deg; } }
  @keyframes k-pop    { from { opacity: 0; scale: .3; } to { opacity: 1; scale: 1; } }
  @keyframes k-drop   { from { opacity: 0; translate: 0 34px; rotate: 3deg; } to { opacity: 1; translate: 0 0; rotate: 0deg; } }
  @keyframes k-rise   { from { opacity: 0; translate: 0 18px; } to { opacity: 1; translate: 0 0; } }
  @keyframes k-slide  { from { opacity: 0; translate: -22px 0; } to { opacity: 1; translate: 0 0; } }
  @keyframes k-spin-in { from { opacity: 0; scale: 0; rotate: -220deg; } to { opacity: 1; scale: 1; rotate: 0deg; } }
  @keyframes k-hero-in { from { scale: .55; rotate: -14deg; translate: 0 -24px; } to { scale: 1; rotate: 0deg; translate: 0 0; } }
  @keyframes k-stamp {
    0%   { opacity: 0; scale: 2.6; rotate: -18deg; animation-timing-function: cubic-bezier(.55, 0, 1, .45); }
    45%  { opacity: 1; scale: .9; rotate: 3deg; animation-timing-function: ease-out; }
    72%  { scale: 1.06; rotate: -1deg; }
    100% { opacity: 1; scale: 1; rotate: 0deg; }
  }
  @keyframes k-thud   { 0%, 100% { translate: 0 0; } 30% { translate: 0 4px; } 65% { translate: 0 -1px; } }
  @keyframes k-wiggle { 0%, 100% { rotate: 0deg; } 25% { rotate: -7deg; } 55% { rotate: 5deg; } 80% { rotate: -2deg; } }
  @keyframes k-jelly  { 0%, 100% { scale: 1 1; } 30% { scale: 1.14 .88; } 50% { scale: .94 1.07; } 70% { scale: 1.03 .98; } }
  @keyframes k-hop    { 0%, 100% { translate: 0 0; } 40% { translate: 0 -8px; } }
  @keyframes k-bob    { from { translate: 0 0; } to { translate: 0 -6px; } }
  @keyframes k-twirl  { to { rotate: 360deg; } }
  @keyframes k-breathe { from { scale: .95; } to { scale: 1; } }
  @keyframes k-scan   { from { translate: 0 -50%; } to { translate: 0 50%; } }
  @keyframes k-ants   { to { stroke-dashoffset: -15; } }
  @keyframes k-stripes { to { background-position: 19.8px 0; } }
  @keyframes k-sweep  { from { translate: -110% 0; } to { translate: 330% 0; } }
  @keyframes k-toast  { from { opacity: 0; translate: 0 36px; scale: .9; } to { opacity: 1; translate: 0 0; scale: 1; } }
  @keyframes k-ring {
    0%       { box-shadow: 3px 3px 0 var(--k-ink), 0 0 0 0 rgba(166, 233, 184, .95); }
    70%, 100% { box-shadow: 3px 3px 0 var(--k-ink), 0 0 0 12px rgba(166, 233, 184, 0); }
  }
  @keyframes k-burst {
    from { opacity: 1; translate: 0 0; scale: .3; rotate: 0deg; }
    75%  { opacity: 1; }
    to   { opacity: 0; translate: var(--dx) var(--dy); scale: 1; rotate: var(--rot); }
  }

  /* Scroll reveals (motion.js sets data-reveal on off-screen elements) ---- */
  [data-reveal]:not(.is-in) { opacity: 0; }
  [data-reveal].is-in {
    animation-duration: .75s; animation-timing-function: var(--k-spring-soft);
    animation-fill-mode: backwards; animation-delay: var(--d, 0ms);
  }
  [data-reveal="drop"].is-in  { animation-name: k-drop; }
  [data-reveal="pop"].is-in   { animation-name: k-pop; animation-duration: .6s; animation-timing-function: var(--k-spring); }
  [data-reveal="slide"].is-in { animation-name: k-slide; animation-duration: .6s; animation-timing-function: var(--k-spring); }
  [data-reveal="rise"].is-in  { animation-name: k-rise; animation-duration: .6s; animation-timing-function: var(--k-out); }
  [data-reveal="stamp"].is-in { animation: k-rise .45s var(--k-out) backwards, k-thud .35s ease-out .62s; }
  [data-reveal="stamp"].is-in .tag-dark { animation: k-stamp .6s linear .2s backwards; }
  .panel.is-in .corner-tag { animation: k-slap .6s var(--k-spring) .35s backwards; }
  .person.is-in .avatar { animation: k-pop .6s var(--k-spring) calc(var(--d, 0ms) + .22s) backwards; }
  .way.is-in .tag { animation: k-slap .55s var(--k-spring) calc(var(--d, 0ms) + .3s) backwards; }

  /* Hover and press: springy, like peeling a sticker ---------------------- */
  .btn { transition: transform .32s var(--k-spring), box-shadow .15s ease; }
  .btn:hover:not(:disabled) { transform: translate(-2px, -2px); box-shadow: 4px 4px 0 var(--k-ink); }
  .btn-orange:hover:not(:disabled) { box-shadow: 5px 5px 0 var(--k-ink); }
  .btn:active:not(:disabled) { transform: translate(1px, 1px) scale(.97); box-shadow: none; transition-duration: .08s; }
  .btn-arrow { transition: translate .3s var(--k-spring); }
  .btn:hover .btn-arrow { translate: 4px 0; }
  .logo:hover { animation: k-wiggle .5s ease-in-out; }

  .signal-chip { transition: transform .35s var(--k-spring), box-shadow .15s ease; }
  .signal-tip {
    transform: translateX(calc(-50% + var(--shift, 0px))) translateY(8px) scale(.9);
    transform-origin: 50% 100%;
    transition: opacity .15s ease, transform .35s var(--k-spring), visibility .15s;
  }
  .signal.is-open .signal-tip,
  .signal-chip:focus-visible + .signal-tip { transform: translateX(calc(-50% + var(--shift, 0px))) translateY(0) scale(1); }
  @media (hover: hover) {
    .signal:hover .signal-tip { transform: translateX(calc(-50% + var(--shift, 0px))) translateY(0) scale(1); }
  }

  .steps > .step, .ways > .way, .people > .person, .tips > .tip {
    transition: translate .35s var(--k-spring), box-shadow .2s ease;
  }
  .steps > .step:hover, .ways > .way:hover, .people > .person:hover, .tips > .tip:hover {
    translate: 0 -5px; box-shadow: 5px 7px 0 var(--k-ink);
  }
  .people > .person:hover .avatar { animation: k-wiggle .55s ease-in-out; }
  .pill-list > li { transition: translate .3s var(--k-spring); }
  .pill-list > li:hover { translate: 4px 0; }

  /* Home hero: Kai's circle drops in, then the stickers slap on ---------- */
  .hero-photo { transform-origin: 0 50%; animation: k-hero-in .95s var(--k-spring) .05s backwards; }
  .hero-loop { transition: opacity .3s ease; }
  /* No transform-origin change here: the bubble is tilted, and a new pivot would move where it settles. */
  .hero-art .bubble { animation: k-pop .6s var(--k-spring) .42s backwards, k-bob 2.8s ease-in-out 1.6s infinite alternate; }
  .hero-art .s-ears { animation: k-slap .6s var(--k-spring) .66s backwards; }
  .hero-art .s-pant { animation: k-slap .6s var(--k-spring) .8s backwards; }
  .hero-art .star-a { animation: k-spin-in .9s var(--k-spring) .5s backwards, k-twirl 24s linear 1.5s infinite; }
  .hero-art .star-b { animation: k-spin-in .9s var(--k-spring) .62s backwards, k-bob 3.4s ease-in-out 1.6s infinite alternate; }
  .hero-copy a.btn-orange { animation: k-wiggle .7s ease-in-out 1.7s; }

  /* Page headers on the other public pages ------------------------------- */
  main > section:first-child > .tag:first-child { animation: k-slap .6s var(--k-spring) .1s backwards; }
  main > section:first-child > .star { animation: k-spin-in .9s var(--k-spring) .35s backwards, k-twirl 26s linear 1.3s infinite; }

  /* /progress: stages light up in order, the current one keeps a soft ring */
  .panel:not([data-reveal]) .stage-track .stage,
  .panel.is-in .stage-track .stage { animation: k-slide .55s var(--k-spring) .45s backwards; }
  .panel:not([data-reveal]) .stage-track .stage:nth-child(2),
  .panel.is-in .stage-track .stage:nth-child(2) { animation-delay: .6s; }
  .panel:not([data-reveal]) .stage-track .stage:nth-child(3),
  .panel.is-in .stage-track .stage:nth-child(3) { animation-delay: .75s; }
  .panel:not([data-reveal]) .stage-track .stage.is-now,
  .panel.is-in .stage-track .stage.is-now { animation: k-slide .55s var(--k-spring) .45s backwards, k-ring 2.6s ease-out 1.4s infinite; }

  /* /collect ----------------------------------------------------------------- */
  .collect-intro .mini-steps li { animation: k-pop .5s var(--k-spring) .3s backwards; }
  .collect-intro .mini-steps li:nth-child(2) { animation-delay: .4s; }
  .collect-intro .mini-steps li:nth-child(3) { animation-delay: .5s; }
  .mini-steps li.is-done { animation: k-jelly .5s ease; }
  .mini-steps li.is-done .num::after { animation: k-pop .45s var(--k-spring); }
  .collect-card { animation: k-rise .6s var(--k-out) .15s backwards; }

  .upload-zone { transition: background .15s ease, transform .35s var(--k-spring); }
  .upload-zone:hover .upload-icon, .upload-zone.is-dragover .upload-icon { animation: k-hop .6s var(--k-spring); }
  .upload-zone:hover .k-ants rect, .upload-zone.is-dragover .k-ants rect { animation: k-ants .6s linear infinite; }

  #progressFill {
    background-image: repeating-linear-gradient(-45deg, transparent 0 7px, rgba(22, 22, 22, .14) 7px 14px);
    background-size: 19.8px 19.8px;
    animation: k-stripes .6s linear infinite;
  }

  #thanks .thanks-star { animation: k-spin-in .9s var(--k-spring) .05s backwards; }
  #thanks .tag { animation: k-slap .6s var(--k-spring) .3s backwards; }
  #thanks h2 { animation: k-rise .5s var(--k-out) .2s backwards; }

  #analysisResult .watch { animation: k-drop .6s var(--k-spring-soft) backwards; }
  .watch-frame::before { animation: k-breathe 1.3s ease-in-out infinite alternate; }
  .watch-chip .rec-dot { animation: rec-pulse 1.1s infinite; }
  /* The scan line only exists while it moves; frozen, it reads as a glitch. */
  #analysisResult[data-state="running"] .watch-scan { opacity: 1; animation: k-scan 1.9s ease-in-out infinite alternate; }
  #analysisResult[data-state="done"] #analysisResultText { animation: k-slap .65s var(--k-spring) backwards; }
  /* The result card: the card drops in, the still slaps on, then the stickers pop one by one. */
  #analysisResult[data-state="done"] .report { animation: k-drop .6s var(--k-spring-soft) backwards; }
  #analysisResult[data-state="done"] .report-photo { animation: k-slap .6s var(--k-spring) .12s backwards; }
  #analysisResult[data-state="done"] .report-headline { animation: k-rise .5s var(--k-spring-soft) .24s backwards; }
  #analysisResult[data-state="done"] .report-sticker { animation: k-pop .5s var(--k-spring) calc(.42s + var(--i, 0) * .11s) backwards; }
  #analysisResult[data-state="done"] .report-meaning { animation: k-slide .45s var(--k-spring-soft) calc(.5s + var(--i, 0) * .11s) backwards; }
  /* "Couldn't analyse" outcomes arrive calmly. No bounce, no shake. */
  #analysisResult:is([data-state="rejected"], [data-state="unavailable"], [data-state="failed"], [data-state="gave-up"]) #analysisResultText {
    animation: k-rise .5s var(--k-out) backwards;
  }

  /* Celebration bits */
  .k-bit { animation: k-burst .95s cubic-bezier(.15, .85, .35, 1) both; }

  /* /app (private library) ---------------------------------------------- */
  .capture-view, .library-view { animation: k-rise .45s var(--k-out) backwards; }
  .details-panel, .result-panel { animation: k-drop .6s var(--k-spring-soft) backwards; }
  .result-panel .result-icon { animation: k-spin-in .8s var(--k-spring) .15s backwards; }
  .toast { animation: k-toast .5s var(--k-spring) backwards; }
  .steps-list li.is-current > span { animation: k-pop .45s var(--k-spring); }
  .steps-list li.is-complete > span { animation: k-jelly .45s ease; }
  .label-button.is-selected, .annotation-chip.is-selected { animation: k-jelly .4s ease; }
  .count.is-bumped { animation: k-jelly .45s ease; }
  .site-header .brand:hover { animation: k-wiggle .5s ease-in-out; }
  .button { transition: transform .32s var(--k-spring), box-shadow .15s ease; }
  .button:hover:not(:disabled) { transform: translate(-2px, -2px); box-shadow: 4px 4px 0 var(--k-ink); }
  .button:active:not(:disabled) { transform: translate(1px, 1px) scale(.97); box-shadow: none; transition-duration: .08s; }
  .clip-card { transition: translate .35s var(--k-spring), box-shadow .2s ease; }
  .clip-card:hover { translate: 0 -4px; box-shadow: 7px 9px 0 var(--k-ink); }
  .clip-card:is([data-analysis="queued"], [data-analysis="running"]) .clip-media::after {
    content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 45%; pointer-events: none;
    background: linear-gradient(100deg, transparent, rgba(255, 216, 77, .5), transparent);
    animation: k-sweep 1.6s ease-in-out infinite;
  }
  #progressBar {
    background-image: repeating-linear-gradient(-45deg, transparent 0 7px, rgba(22, 22, 22, .18) 7px 14px) !important;
    background-size: 19.8px 19.8px !important;
    animation: k-stripes .6s linear infinite;
  }
}
