/*
 * A — motion: scroll reveals and the contact bar's visibility. Loaded last (VARIANTS.a.css).
 * Everything that moves is staged under `.js.motion` only, so without JS or with reduced motion
 * every target sits in its final frame; the bar's hidden state is under `.js` (it toggles with
 * reduced motion too, without the transition).
 *
 * The grid is the clock. One column takes one --cell to open, so whatever arrives together opens
 * as one sweep across the twelve columns (six on phones): reveal.js tells each target where it
 * sits (--reveal-x, --reveal-y) and the delay below starts it when the sweep reaches its column.
 *   mask  a head or a lead opens column by column: a hard-edged mask that steps, never fades
 *   rule  a block's top rule draws across its columns, then the block drops open beneath it
 *   fade  a gloss: its leader draws, then the remark cuts in
 * Masks are clip-paths with generous negative insets on the sides they are not opening from, so
 * no glyph overhang is ever cut; when an animation ends the target is back to `clip-path: none`.
 */

:root {
  --cell: 55ms;
  --ease-open: cubic-bezier(0.2, 0.8, 0, 1);
}

.js.motion [data-reveal] {
  --cells: var(--cols);
  --reveal-delay: calc(var(--reveal-x, 0) * var(--cols) * var(--cell) + var(--reveal-y, 0) * 480ms);
}

/* How many columns each kind of target spans (a full row unless said here), so it steps on the
   column lines. */
@media (min-width: 768px) {
  .js.motion .section__head[data-reveal] {
    --cells: 8;
  }

  .js.motion .section__lead[data-reveal] {
    --cells: 9;
  }

  .js.motion .program[data-reveal] {
    --cells: 4;
  }

  .js.motion .method[data-reveal] {
    --cells: 6;
  }
}

@media (min-width: 1200px) {
  .js.motion .section__lead[data-reveal] {
    --cells: 4;
  }

  .js.motion .method[data-reveal] {
    --cells: 4;
  }
}

/* ---------------------------------------------------------------- mask */

.js.motion [data-reveal="mask"]:not(.is-revealed) {
  clip-path: inset(-50% 100% -50% -1em);
}

.js.motion [data-reveal="mask"].is-revealed {
  animation: a-mask calc(var(--cells) * var(--cell)) steps(var(--cells), jump-start) var(--reveal-delay) backwards;
}

@keyframes a-mask {
  from {
    clip-path: inset(-50% 100% -50% -1em);
  }

  to {
    clip-path: inset(-50% 0 -50% -1em);
  }
}

/* ---------------------------------------------------------------- rule */

/* The rule is the block's own 1px top border; while it draws, a stand-in on top of it does. */
.js.motion [data-reveal="rule"] {
  --draw: calc(var(--cells) * var(--cell));
  position: relative;
}

.js.motion [data-reveal="rule"]::before {
  content: "";
  position: absolute;
  top: -1px;
  right: 0;
  left: 0;
  height: 1px;
  background: var(--rule);
  transform-origin: 0 50%;
  scale: 0 1;
  pointer-events: none;
}

.js.motion [data-reveal="rule"]:not(.is-revealed) {
  border-top-color: transparent;
  clip-path: inset(-2px -1em calc(100% - 2px) -1em);
}

.js.motion [data-reveal="rule"].is-revealed {
  animation:
    a-rule-hold var(--draw) linear var(--reveal-delay) backwards,
    a-drop 640ms var(--ease-open) calc(var(--reveal-delay) + var(--draw) * 0.5) backwards;
}

.js.motion [data-reveal="rule"].is-revealed::before {
  animation: a-draw var(--draw) linear var(--reveal-delay) backwards;
}

@keyframes a-draw {
  from {
    scale: 0 1;
  }

  to {
    scale: 1 1;
  }
}

/* The border stays clear until its stand-in has drawn all the way across. */
@keyframes a-rule-hold {
  from,
  to {
    border-top-color: transparent;
  }
}

@keyframes a-drop {
  from {
    clip-path: inset(-2px -1em calc(100% - 2px) -1em);
  }

  to {
    clip-path: inset(-2px -1em -1em -1em);
  }
}

/* ---------------------------------------------------------------- fade (a gloss) */

/* Only the top strip shows (a margin note's leader lives there) until the remark cuts in. */
.js.motion [data-reveal="fade"]:not(.is-revealed) {
  clip-path: inset(-1px -1em calc(100% - 3px) -1em);
}

.js.motion [data-reveal="fade"].is-revealed {
  animation: a-hold-strip 280ms linear var(--reveal-delay) backwards;
}

.js.motion .margin-note[data-reveal]:not(.is-revealed)::before {
  scale: 0 1;
}

.js.motion .margin-note[data-reveal].is-revealed::before {
  transform-origin: 0 50%;
  animation: a-draw 220ms cubic-bezier(0.6, 0, 0.2, 1) var(--reveal-delay) backwards;
}

@keyframes a-hold-strip {
  from,
  to {
    clip-path: inset(-1px -1em calc(100% - 3px) -1em);
  }
}

/* ---------------------------------------------------------------- contact bar */

/*
 * Hidden on the first screen and while #contact is on screen (contact-bar.js sets is-visible):
 * out of the tab order and the accessibility tree, and fixed, so nothing reflows. With motion its
 * three cells open one by one from the left and close the same way back.
 */
.js .contact-bar:not(.is-visible) {
  visibility: hidden;
}

.js.motion .contact-bar {
  clip-path: inset(0);
  transition:
    clip-path 210ms steps(3, jump-start),
    visibility 0s;
}

.js.motion .contact-bar:not(.is-visible) {
  clip-path: inset(0 100% 0 0);
  transition:
    clip-path 210ms steps(3, jump-start),
    visibility 0s 210ms;
}

/* ---------------------------------------------------------------- the lens (lens.js) */

/*
 * The lens row snaps from row to row (lens.js sets its transforms; nothing here eases a move).
 * As its ground comes wholly under a line of the sentence, that line's brackets draw (--i: their
 * order in the line). On the sentence it parses it: the underlines run, S and V drop onto them,
 * the tags rise on their leaders, the modifiers step back (--i: each mark's place in that order).
 * Leaving a line or the sentence undoes it at once (the transitions live on the drawn states only).
 */
.js.motion #top.has-lens .lens-row .mark {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.js.motion #top.has-lens .lens-row .mark--bracket.is-lit {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 200ms cubic-bezier(0.6, 0, 0.2, 1) calc(var(--i, 0) * 50ms);
}

.js.motion #top.has-lens.is-parsed .lens-row .mark--under {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 200ms cubic-bezier(0.4, 0, 0.2, 1) calc(var(--i, 0) * 110ms);
}

/* S and V fall the last short way onto their underlines, accelerating: from the baseline, under
   the letters, never through them. */
.js.motion #top.has-lens [data-lens-target] .role-label {
  opacity: 0;
  translate: 0 -0.7em;
}

.js.motion #top.has-lens.is-parsed [data-lens-target] .role-label {
  --drop-at: calc(160ms + var(--i, 0) * 110ms);
  opacity: 1;
  translate: none;
  transition:
    translate 200ms cubic-bezier(0.55, 0, 1, 0.45) var(--drop-at),
    opacity 120ms linear var(--drop-at);
}

/* A tag rises on its leader from the bracket. */
.js.motion #top.has-lens [data-lens-target] .note {
  clip-path: inset(100% -1em 0 -1em);
}

.js.motion #top.has-lens.is-parsed [data-lens-target] .note {
  clip-path: inset(-1em);
  transition: clip-path 320ms cubic-bezier(0.2, 0.8, 0, 1) calc(80ms + var(--i, 0) * 110ms);
}

.js.motion #top.has-lens.is-parsed [data-lens-target] {
  transition: color 520ms ease 400ms;
}

/*
 * Then the title parses itself: on wide screens the elbow draws across, then down, then the
 * arrowhead lands and 수식 is set; on phones its twin in the sixth column goes out, down and back
 * in to its head, and 수식 is set. Each part grows from where the line starts (--at, --dur per part).
 */
.js.motion #top.has-lens .hero__arrow :is(line, path) {
  transform-box: fill-box;
}

.js.motion #top.has-lens:not(.is-titled) .hero__arrow :is(.hero__arrow-elbow > line:first-of-type, .hero__arrow-drop line:nth-of-type(odd)) {
  scale: 0 1;
}

.js.motion #top.has-lens:not(.is-titled) .hero__arrow :is(.hero__arrow-elbow > line:last-of-type, .hero__arrow-drop line:nth-of-type(2)) {
  scale: 1 0;
}

.js.motion #top.has-lens:not(.is-titled) .hero__arrow path {
  scale: 0;
}

.js.motion #top.has-lens:not(.is-titled) .hero__arrow text {
  opacity: 0;
}

.js.motion #top.has-lens.is-titled .hero__arrow :is(line, path, text) {
  transition:
    scale var(--dur, 0s) var(--ease, linear) var(--at, 0s),
    opacity 0s var(--at, 0s);
}

.js.motion #top.has-lens .hero__arrow-elbow > line:first-of-type {
  --dur: 300ms;
  transform-origin: 0 50%;
}

.js.motion #top.has-lens .hero__arrow-elbow > line:last-of-type {
  --at: 300ms;
  --dur: 220ms;
  transform-origin: 50% 0;
}

.js.motion #top.has-lens .hero__arrow-elbow path {
  --at: 520ms;
  --dur: 140ms;
  --ease: cubic-bezier(0.2, 0.8, 0, 1);
  transform-origin: 50% 0;
}

.js.motion #top.has-lens .hero__arrow-elbow > text {
  --at: 620ms;
}

.js.motion #top.has-lens .hero__arrow-drop line:nth-of-type(1) {
  --dur: 140ms;
  transform-origin: 0 50%;
}

.js.motion #top.has-lens .hero__arrow-drop line:nth-of-type(2) {
  --at: 140ms;
  --dur: 260ms;
  transform-origin: 50% 0;
}

.js.motion #top.has-lens .hero__arrow-drop line:nth-of-type(3) {
  --at: 400ms;
  --dur: 80ms;
  transform-origin: 100% 50%;
}

.js.motion #top.has-lens .hero__arrow-drop path {
  --at: 480ms;
  --dur: 140ms;
  --ease: cubic-bezier(0.2, 0.8, 0, 1);
  transform-origin: 100% 50%;
}

.js.motion #top.has-lens .hero__arrow-drop text {
  --at: 620ms;
}

/* ---------------------------------------------------------------- the anatomy (anatomy.js) */

/*
 * One sentence taken apart on the pinned stage, a step per sixth of the scroll; anatomy.js sets
 * `data-step` and these states run the moves. Each transition is the one into its state, so a
 * step backwards undoes its own way (going back, `is-back` holds the marks until the fold has
 * opened). The words move by FLIP vectors anatomy.js measures (--fx, --fy); --k is a mark's place
 * in reading order.
 *   raw      every word white, nothing drawn
 *   clauses  brackets 01–05 draw in order, each tag rising on its leader
 *   roles    the S/V/O underlines run out, the letters drop onto them, the arrows draw
 *   core     the marks clear, the modifiers dim over their hatched strip, the underlines swell
 *            into red blocks; then the hatching folds to nothing with its words, and the blocks
 *            and their words close up into the core sentence
 *   meaning  the blocks thin to underlines again; the translation opens under the core
 *   motto    "Trust the process." opens, and its red full stop lands last
 */
#anatomy {
  --ease-fold: cubic-bezier(0.7, 0, 0.2, 1);
  --fold-at: 420ms;
  --fold: 620ms;
}

.js.motion #anatomy.is-back {
  --after-fold: 560ms;
}

/* Words: white until the core; then the modifiers dim and fold away, the core closes up. The raw
   sentence is set close, as plain text, over the room its brackets will take (--rx). */
.js.motion #anatomy.is-staged .anatomy-sentence .tok {
  color: var(--room-fg);
  transform-origin: 0 50%;
  transition:
    color 240ms ease,
    translate 520ms var(--ease-fold),
    scale 520ms var(--ease-fold),
    opacity 160ms linear;
}

.js.motion #anatomy.is-staged[data-step="raw"] .anatomy-sentence .tok {
  translate: var(--rx, 0) 0;
  transition:
    color 240ms ease,
    translate 360ms var(--ease-fold) 100ms,
    scale 520ms var(--ease-fold),
    opacity 160ms linear;
}

.js.motion #anatomy.is-staged:is([data-step="core"], [data-step="meaning"], [data-step="motto"]) .anatomy-sentence .tok {
  translate: var(--fx, 0) var(--fy, 0);
  transition:
    color 240ms ease,
    translate var(--fold) var(--ease-fold) var(--fold-at),
    scale var(--fold) var(--ease-fold) var(--fold-at),
    opacity 280ms linear calc(var(--fold-at) + 160ms);
}

.js.motion #anatomy.is-staged:is([data-step="core"], [data-step="meaning"], [data-step="motto"]) .anatomy-sentence .tok:not([data-core]) {
  color: var(--recede);
  scale: 0 1;
  opacity: 0;
}

/* On its red block a role's words are ink. */
.js.motion #anatomy.is-staged[data-step="core"] .span--role .tok {
  color: var(--ink);
  transition:
    color 160ms linear 140ms,
    translate var(--fold) var(--ease-fold) var(--fold-at);
}

/* The strip: the underlines are the red blocks thinned to their foot (--sy). They run out in the
   roles step, swell in the core and close up with their words, then thin again. */
.js.motion #anatomy.is-staged .anatomy-band--role {
  scale: 0 var(--sy);
  transition:
    scale 220ms cubic-bezier(0.4, 0, 0.2, 1) calc(var(--after-fold, 0ms) * 0.6 + var(--k, 0) * 110ms),
    translate 520ms var(--ease-fold);
}

.js.motion #anatomy.is-staged:is([data-step="roles"], [data-step="meaning"], [data-step="motto"]) .anatomy-band--role {
  scale: 1 var(--sy);
}

.js.motion #anatomy.is-staged:is([data-step="core"], [data-step="meaning"], [data-step="motto"]) .anatomy-band--role {
  translate: var(--fx, 0) var(--fy, 0);
  transition:
    scale 320ms cubic-bezier(0.4, 0, 0.2, 1),
    translate var(--fold) var(--ease-fold) var(--fold-at);
}

.js.motion #anatomy.is-staged[data-step="core"] .anatomy-band--role {
  scale: 1;
  transition:
    scale 240ms cubic-bezier(0.2, 0.8, 0, 1) 120ms,
    translate var(--fold) var(--ease-fold) var(--fold-at);
}

/* The hatching shows under the modifiers, then folds to its left edge with them. Going back it
   opens with them, then goes. */
.js.motion #anatomy.is-staged .anatomy-band--fold {
  opacity: 0;
  transition:
    scale 520ms var(--ease-fold),
    opacity 160ms linear 420ms;
}

.js.motion #anatomy.is-staged:is([data-step="core"], [data-step="meaning"], [data-step="motto"]) .anatomy-band--fold {
  opacity: 1;
  scale: 0 1;
  transition:
    opacity 120ms linear 120ms,
    scale var(--fold) var(--ease-fold) var(--fold-at);
}

/* Brackets draw in reading order; their tags rise on their leaders. */
.js.motion #anatomy.is-staged .anatomy-marks .mark {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 140ms linear;
}

.js.motion #anatomy.is-staged:is([data-step="clauses"], [data-step="roles"]) .anatomy-marks .mark {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 220ms cubic-bezier(0.6, 0, 0.2, 1) calc(var(--after-fold, 0ms) + 220ms + var(--k, 0) * 120ms);
}

.js.motion #anatomy.is-staged :is(.span--clause, .span--phrase) > .note {
  clip-path: inset(100% -1em 0 -1em);
  transition: clip-path 140ms linear;
}

.js.motion #anatomy.is-staged:is([data-step="clauses"], [data-step="roles"]) :is(.span--clause, .span--phrase) > .note {
  clip-path: inset(-1em);
  transition: clip-path 320ms cubic-bezier(0.2, 0.8, 0, 1) calc(var(--after-fold, 0ms) + 300ms + var(--k, 0) * 120ms);
}

/* S, V, O fall the last short way onto their underlines, and stay with their words from then on;
   the role note is set with them. */
.js.motion #anatomy.is-staged .role-label {
  opacity: 0;
  translate: 0 -0.7em;
  transition:
    translate 160ms ease-in,
    opacity 100ms linear;
}

.js.motion #anatomy.is-staged[data-step="roles"] .role-label {
  --drop-at: calc(var(--after-fold, 0ms) + 160ms + var(--k, 0) * 110ms);
  opacity: 1;
  translate: none;
  transition:
    translate 200ms cubic-bezier(0.55, 0, 1, 0.45) var(--drop-at),
    opacity 120ms linear var(--drop-at);
}

/* Back from the core they travel home with their words instead. */
.js.motion #anatomy.is-staged.is-back[data-step="roles"] .role-label {
  transition: translate 520ms var(--ease-fold);
}

.js.motion #anatomy.is-staged:is([data-step="core"], [data-step="meaning"], [data-step="motto"]) .role-label {
  opacity: 1;
  translate: var(--fx, 0) var(--fy, 0);
  transition: translate var(--fold) var(--ease-fold) var(--fold-at);
}

.js.motion #anatomy.is-staged .span--role > .note {
  opacity: 0;
  transition: opacity 120ms linear;
}

.js.motion #anatomy.is-staged[data-step="roles"] .span--role > .note {
  opacity: 1;
  transition: opacity 200ms linear calc(var(--after-fold, 0ms) + 420ms);
}

/* The arrows draw once the letters are down, each from its bracket to its word; the head last. */
.js.motion #anatomy.is-staged .anatomy-arrows .arrow {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 140ms linear;
}

.js.motion #anatomy.is-staged .anatomy-arrows .arrow-head {
  opacity: 0;
  transition: opacity 80ms linear;
}

.js.motion #anatomy.is-staged[data-step="roles"] .anatomy-arrows .arrow {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 360ms cubic-bezier(0.6, 0, 0.2, 1) calc(var(--after-fold, 0ms) + 460ms + var(--k, 0) * 110ms);
}

.js.motion #anatomy.is-staged[data-step="roles"] .anatomy-arrows .arrow-head {
  opacity: 1;
  transition: opacity 60ms linear calc(var(--after-fold, 0ms) + 820ms + var(--k, 0) * 110ms);
}

/* The translation opens under the core, column by column like a head; then the motto, and its
   full stop lands last. */
.js.motion #anatomy.is-staged :is(.anatomy-translation, .anatomy-motto) {
  opacity: 0;
  clip-path: inset(-50% 100% -50% -0.2em);
  transition:
    clip-path 120ms linear,
    opacity 0s linear 120ms;
}

.js.motion #anatomy.is-staged:is([data-step="meaning"], [data-step="motto"]) .anatomy-translation,
.js.motion #anatomy.is-staged[data-step="motto"] .anatomy-motto {
  opacity: 1;
  clip-path: inset(-50% -0.5em -50% -0.2em);
  transition:
    clip-path 480ms steps(8, jump-start) var(--open-at, 240ms),
    opacity 0s linear var(--open-at, 240ms);
}

.js.motion #anatomy.is-staged[data-step="motto"] .anatomy-motto {
  --open-at: 80ms;
}

.js.motion #anatomy.is-staged .anatomy-motto::after {
  opacity: 0;
  scale: 2.6;
  transition:
    scale 0s linear 120ms,
    opacity 0s linear 120ms;
}

.js.motion #anatomy.is-staged[data-step="motto"] .anatomy-motto::after {
  opacity: 1;
  scale: none;
  transition:
    scale 160ms cubic-bezier(0.55, 0, 1, 0.45) 680ms,
    opacity 60ms linear 680ms;
}

/* The captions: the step it is on. */
.js.motion #anatomy.is-staged .anatomy-captions li {
  color: var(--room-mute);
  transition:
    color 200ms linear,
    border-color 200ms linear,
    opacity 160ms linear;
}

.js.motion #anatomy.is-staged .anatomy-captions li.is-now {
  color: var(--room-fg);
}

@media (min-width: 1200px) {
  .js.motion #anatomy.is-staged .anatomy-captions li:is(.is-now, .is-done) {
    border-top-color: var(--room-fg);
  }
}

@media (max-width: 1199px) {
  .js.motion #anatomy.is-staged .anatomy-captions li:not(.is-now) {
    opacity: 0;
  }

  .js.motion #anatomy.is-staged .anatomy-captions::after {
    scale: 0.2 1;
    transition: scale 360ms var(--ease-fold);
  }

  .js.motion #anatomy.is-staged[data-step="clauses"] .anatomy-captions::after {
    scale: 0.4 1;
  }

  .js.motion #anatomy.is-staged[data-step="roles"] .anatomy-captions::after {
    scale: 0.6 1;
  }

  .js.motion #anatomy.is-staged[data-step="core"] .anatomy-captions::after {
    scale: 0.8 1;
  }

  .js.motion #anatomy.is-staged:is([data-step="meaning"], [data-step="motto"]) .anatomy-captions::after {
    scale: 1;
  }
}

/* Measuring: every word and letter where the type puts it, and nothing easing back after (nor
   into the first step: the stage is set up as it stands). */
.js.motion #anatomy:is(.is-measuring, .is-settling) *,
.js.motion #anatomy:is(.is-measuring, .is-settling) *::before,
.js.motion #anatomy:is(.is-measuring, .is-settling) *::after {
  transition: none !important;
}

.js.motion #anatomy.is-measuring :is(.tok, .role-label) {
  translate: none !important;
  scale: none !important;
}
