/* The sentence that prints itself: a black page, a sentence in large thin type that is the progress bar, the
   percentage and the count under it, a thin line, and a line of small type with the button at the foot.
   In a real app it sits wherever the export was started (a panel, a sheet, a toast): here it is alone in the middle. */
:root {
  --page: #000000;          /* the page */
  --ink: #f4f1ea;           /* the printed letters, the figures, the line */
  --light: #a8a49c;         /* the letters not printed yet */
  --muted: #7b7871;         /* the small type */
  --track: #2a2926;         /* the faint line of the whole export */
  --accent: #ff5a2a;        /* the head of the line, and what went wrong */
  --on-ink: #0b0b0a;        /* the words on the button under the finger */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Archivo Variable', 'Archivo', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

.ex {
  position: relative;
  display: grid;
  width: min(400px, 100%);
}

/* ---------------------------------------------------------------- the sentence */
/* the words wrap like text but sit on the last lines, so the shorter sentence at the end lands on the figures.
   Every letter is a cell as wide as the letter at its lightest: the script finds, for every weight, the width (wdth)
   that keeps the letter inside its cell, so the sentence never moves while it prints */
.ex__phrase {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-end;
  min-height: 3.3em;
  margin: 0;
  font-size: clamp(31px, 10vw, 42px);
  line-height: 1.1;
  /* the gap between the words is the width of a space of the thin cut */
  column-gap: 0.25em;
  font-variation-settings: 'wght' 100, 'wdth' 125;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.ex__word {
  display: inline-flex;
  flex: none;
}

/* the cell: GSAP moves it when the sentence sets itself again */
.ex__ch {
  display: inline-block;
  flex: none;
  height: 1.1em;
  text-align: center;
}

/* the letter in it: its weight, width, tone and the little press are written by the script on every frame */
.ex__g {
  display: block;
  color: var(--light);
  color: color-mix(in srgb, var(--ink) calc(var(--k, 0) * 100%), var(--light));
  font-variation-settings: 'wght' 100, 'wdth' 125;
  will-change: transform;
}

/* ---------------------------------------------------------------- the figures */
.ex__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-top: 30px;
}

.ex__pct {
  display: inline-flex;
  align-items: flex-end;
  height: 1em;
  font-size: 26px;
  line-height: 1;
  font-variation-settings: 'wght' 460, 'wdth' 100;
  font-variant-numeric: tabular-nums;
}

/* every figure is a drum of 0 to 9 and 0 again in a window as tall as a figure; the window softens at its edges */
.slot {
  position: relative;
  display: inline-block;
  width: 0.62em;
  height: 1em;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 22%, #000 78%, transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0, #000 22%, #000 78%, transparent 100%);
}

.slot__drum {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  text-align: center;
}

.slot__drum span {
  display: block;
  height: 1em;
}

.ex__sign {
  margin-left: 0.04em;
  font-size: 0.62em;
  line-height: 1.32;
  font-variation-settings: 'wght' 420, 'wdth' 100;
  color: var(--muted);
}

.ex__count {
  color: var(--muted);
  font-size: 13px;
  font-variation-settings: 'wght' 450, 'wdth' 100;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- the line */
.ex__line {
  position: relative;
  height: 15px;
  margin-top: 10px;
}

.ex__track,
.ex__fill {
  position: absolute;
  left: 0;
  top: 7px;
  height: 1px;
}

.ex__track {
  width: 100%;
  background: var(--track);
  transform-origin: 0 50%;
}

.ex__fill {
  width: 0;
  background: var(--ink);
}

/* the head: a short stroke of the accent where the work has got to; the mark stays where a lost connection stopped it */
.ex__head,
.ex__mark {
  position: absolute;
  left: 0;
  top: 2px;
  width: 1.5px;
  height: 11px;
  margin-left: -0.75px;
  background: var(--accent);
  opacity: 0;
}

.ex__mark {
  top: 4px;
  height: 7px;
  width: 1px;
  margin-left: -0.5px;
}

/* ---------------------------------------------------------------- the foot and the button */
.ex__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 44px;
  margin-top: 14px;
}

/* the line of small type sits in a window, so the words can change by rising */
.ex__swap {
  position: relative;
  display: inline-grid;
  min-width: 0;
  overflow: hidden;
  padding: 0.2em 0.04em;
  margin: -0.2em -0.04em;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.25;
  font-variation-settings: 'wght' 450, 'wdth' 100;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ex__swap > span {
  grid-area: 1 / 1;
}

.ex__swap .is-error {
  color: var(--accent);
}

.ex__btn {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  height: 44px;
  padding: 0 21px;
  overflow: hidden;
  border: 0;
  border-radius: 22px;
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(244, 241, 234, 0.4);
  font: inherit;
  font-size: 14.5px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  transition: box-shadow 0.3s ease, color 0.25s ease;
}

/* the fill swells out from the middle with a small give */
.ex__btnfill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--ink);
  transform: scale(0.88, 0.5);
  opacity: 0;
  transition: transform 0.55s cubic-bezier(0.3, 1.5, 0.5, 1), opacity 0.12s ease;
}

/* the words widen on the wdth axis */
.ex__label {
  position: relative;
  display: inline-block;
  font-variation-settings: 'wght' 540, 'wdth' 100;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: font-variation-settings 0.5s cubic-bezier(0.3, 1.5, 0.5, 1);
}

@media (hover: hover) {
  .ex__btn:hover {
    color: var(--on-ink);
    box-shadow: inset 0 0 0 1px var(--ink);
  }

  .ex__btn:hover .ex__btnfill {
    transform: scale(1);
    opacity: 1;
  }

  .ex__btn:hover .ex__label {
    font-variation-settings: 'wght' 580, 'wdth' 118;
  }
}

/* a finger, and the preview's pretend press, get the same as the mouse while they press */
.ex__btn:active,
.ex__btn.is-pressed {
  color: var(--on-ink);
}

.ex__btn:active .ex__btnfill,
.ex__btn.is-pressed .ex__btnfill {
  transform: scale(1);
  opacity: 1;
}

.ex__btn:active .ex__label,
.ex__btn.is-pressed .ex__label {
  font-variation-settings: 'wght' 580, 'wdth' 118;
}

.ex__btn:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .ex__btnfill {
    transform: none;
    transition: opacity 0.25s ease;
  }

  .ex__label {
    transition: none;
  }
}
