/*
 * Koorda — mouvement. The rules of brand/MOTION.md, for the web.
 *
 * All of it in one file, so it can be read as a whole and switched off as a
 * whole. Only `transform` and `opacity` move: neither recomputes the layout,
 * so nothing here makes the page jump while it animates.
 *
 * `prefers-reduced-motion` is honoured at the end of the file, once, for
 * everything above it: every entrance becomes an appearance, every loop
 * stops, and nothing that was readable stops being readable.
 */

/* --- the sheet arrives from where the finger was -------------------- */

/* Each child of the panel rises 16 px and fades in, one after another: the
   eyebrow, then the code, then its place, then what to do with it. A swap
   re-inserts the children, so the entrance plays on every new answer and
   never on a panel that is merely sitting there. */
#panel-body > * {
  animation: koorda-rise var(--motion-base) var(--ease-out) both;
}

#panel-body > *:nth-child(2) { animation-delay: calc(1 * var(--motion-stagger)); }
#panel-body > *:nth-child(3) { animation-delay: calc(2 * var(--motion-stagger)); }
#panel-body > *:nth-child(4) { animation-delay: calc(3 * var(--motion-stagger)); }
#panel-body > *:nth-child(5) { animation-delay: calc(4 * var(--motion-stagger)); }
#panel-body > *:nth-child(n + 6) { animation-delay: calc(5 * var(--motion-stagger)); }

@keyframes koorda-rise {
  from {
    opacity: 0;
    transform: translateY(var(--rise-sheet));
  }
}

/* --- the pin is planted -------------------------------------------- */

/* The marker element is positioned by MapLibre through its own inline
   transform, so the drop is played on an inner element: animating the outer
   one would fight the map for where the pin is. */
.koorda-drop__pin {
  animation: koorda-drop var(--motion-slow) var(--ease-spring) both;
}

@keyframes koorda-drop {
  from {
    opacity: 0;
    transform: translateY(-12px) scale(0.6);
  }
}

/* The ring that leaves the point: where the touch landed, seen before
   anything about it is read. */
.koorda-drop__ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid var(--color-accent);
  border-radius: var(--radius-pill);
  pointer-events: none;
  animation: koorda-ring 600ms var(--ease-out) both;
}

@keyframes koorda-ring {
  from {
    opacity: 0.9;
    transform: scale(0.4);
  }
  to {
    opacity: 0;
    transform: scale(3.2);
  }
}

/* --- the code writes itself ---------------------------------------- */

/* Characters not yet written hold their place, so the badge has its final
   width from the first frame and nothing beside it moves while it fills. */
.code-mark [data-char] {
  transition: opacity var(--motion-fast) var(--ease-out);
}

.code-mark [data-char="waiting"] {
  opacity: 0;
}

/* --- loading is an aperture ---------------------------------------- */

/* The Koorda mark as the one loading sign: the outer arcs turn one way, the
   inner ones the other, the pin in the middle stays put — somewhere is being
   looked for, and it is that one. */
.koorda-loader {
  display: inline-block;
  width: 1.25em;
  height: 1.25em;
  vertical-align: -0.25em;
}

.koorda-loader__outer,
.koorda-loader__inner {
  transform-box: view-box;
  transform-origin: 32px 32px;
}

.koorda-loader__outer {
  animation: koorda-turn 1.6s linear infinite;
}

.koorda-loader__inner {
  animation: koorda-turn 1.6s linear infinite reverse;
}

@keyframes koorda-turn {
  to {
    transform: rotate(360deg);
  }
}

/* --- presentation pages: sections reveal once ---------------------- */

/* Hidden only once the script has said it is there to reveal them. Without
   JavaScript, `motion-ready` never appears and every section is simply
   shown. */
.motion-ready [data-reveal] {
  opacity: 0;
  transform: translateY(var(--rise-section));
  transition:
    opacity var(--motion-slow) var(--ease-out),
    transform var(--motion-slow) var(--ease-out);
  transition-delay: calc(var(--reveal-index, 0) * var(--motion-stagger));
}

.motion-ready [data-reveal].is-revealed {
  opacity: 1;
  transform: none;
}

/* The cards of a revealed section follow it in, one after another. */
.motion-ready [data-reveal] .row > * {
  opacity: 0;
  transform: translateY(var(--rise-sheet));
  transition:
    opacity var(--motion-slow) var(--ease-out),
    transform var(--motion-slow) var(--ease-out);
}

.motion-ready [data-reveal].is-revealed .row > * {
  opacity: 1;
  transform: none;
}

.motion-ready [data-reveal] .row > *:nth-child(2) { transition-delay: calc(2 * var(--motion-stagger)); }
.motion-ready [data-reveal] .row > *:nth-child(3) { transition-delay: calc(4 * var(--motion-stagger)); }
.motion-ready [data-reveal] .row > *:nth-child(4) { transition-delay: calc(6 * var(--motion-stagger)); }
.motion-ready [data-reveal] .row > *:nth-child(5) { transition-delay: calc(8 * var(--motion-stagger)); }
.motion-ready [data-reveal] .row > *:nth-child(6) { transition-delay: calc(10 * var(--motion-stagger)); }

/* --- the anatomy follows the living map ---------------------------- */

.code-anatomy__row {
  transition:
    background var(--motion-base) var(--ease-out),
    opacity var(--motion-base) var(--ease-out);
}

.code-anatomy.is-playing .code-anatomy__row {
  opacity: 0.45;
}

.code-anatomy.is-playing .code-anatomy__row.is-current {
  opacity: 1;
  background: color-mix(in srgb, var(--color-accent) 8%, transparent);
}

/* The living map in the example card. */
.home-example__map {
  height: 220px;
  margin: 0 0 var(--space-4);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-bg);
}

.home-example__step {
  min-height: 1.5em;
  transition: opacity var(--motion-fast) var(--ease-out);
}

/* --- without motion ------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  #panel-body > *,
  .koorda-drop__pin,
  .koorda-loader__outer,
  .koorda-loader__inner {
    animation: none;
  }

  .koorda-drop__ring {
    display: none;
  }

  .code-mark [data-char="waiting"] {
    opacity: 1;
  }

  .motion-ready [data-reveal],
  .motion-ready [data-reveal] .row > * {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* The touch marker's own box, for the ring to be centred in. */
.koorda-drop {
  position: relative;
  display: inline-block;
}
