/* Steps with the advancing line: the steps of a checkout on white, in Archivo (a variable sans, weight 100 to 900
   and width 62 to 125). One thin line runs under the names; the script draws it, moves its head and its tail and
   sets the weight, the width and the colour of every name. Minimal style. */
:root {
  --page: #ffffff;        /* the page */
  --ink: #141414;         /* the ink: the steps done and the line behind them */
  --grey: #a3a3a3;        /* the steps to come */
  --rule: #e2e2e2;        /* the line still to run */
  --tick: #c9c9c9;        /* the ticks still to reach */
  --accent: #2747ff;      /* the current step and the stretch of line that is moving */
  --button: #141414;      /* the main button */
  --on-button: #ffffff;   /* its words */
}

* {
  box-sizing: border-box;
}

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

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

button {
  font: inherit;
  color: inherit;
  margin: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

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

/* ---------------------------------------------------------------- the steps */
.flow {
  position: relative;
  width: min(600px, 100%);
}

.flow__steps {
  display: grid;
  grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr));
  margin: 0;
  padding: 0;
  list-style: none;
}

.step {
  --a: 0;                 /* written by the script: how much this is the current step, 0 to 1 */
  --d: 0;                 /* and how much it is done */
  --h: 0;                 /* and how much the pointer is on it, when it is done */
  min-width: 0;
}

.step__btn {
  display: block;
  position: relative;
  width: 100%;
  padding: 6px 8px 4px 0;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: none;
  cursor: default;
  text-align: left;
  user-select: none;
  -webkit-user-select: none;
}

.step.is-done .step__btn {
  cursor: pointer;
}

.step__btn:focus-visible,
.back:focus-visible,
.next:focus-visible {
  outline: 1.5px solid var(--accent);
  outline-offset: 4px;
}

.step__btn:focus {
  outline-offset: 4px;
}

.step__btn:focus:not(:focus-visible) {
  outline: none;
}

/* the lift rises out of its mask when the steps arrive; the name inside it moves aside for the tick */
.step__lift {
  display: block;
  position: relative;
  white-space: nowrap;
}

.step__name {
  display: inline-block;
  font-size: 15px;
  line-height: 1.25;
  letter-spacing: 0.002em;
  font-variation-settings: 'wght' 360, 'wdth' 100;
  color: color-mix(in srgb, var(--accent) calc(var(--h) * 70%), color-mix(in srgb, var(--ink) calc(var(--d) * 100%), color-mix(in srgb, var(--accent) calc(var(--a) * 100%), var(--grey))));
}

.step__check {
  color: color-mix(in srgb, var(--accent) calc(var(--h) * 70%), var(--ink));
}

/* the tick: a stroke the script draws with stroke-dashoffset as the ink reaches the end of the step */
.step__check {
  position: absolute;
  left: 0;
  top: 50%;
  width: 13px;
  height: 11px;
  margin-top: -6px;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------------------------------------------------------------- the line */
.flow__line {
  display: block;
  width: 100%;
  height: 20px;
  margin-top: 2px;
  overflow: visible;
}

.flow__line path {
  fill: none;
  stroke-linecap: butt;
  stroke-linejoin: round;
}

.line__track {
  stroke: var(--rule);
  stroke-width: 1;
}

.line__ink {
  stroke: var(--ink);
  stroke-width: 2;
}

.line__run {
  stroke: var(--accent);
  stroke-width: 2;
}

.tick {
  --a: 0;
  --d: 0;
  stroke: color-mix(in srgb, var(--ink) calc(var(--d) * 100%), color-mix(in srgb, var(--accent) calc(var(--a) * 100%), var(--tick)));
  stroke-width: 1;
  shape-rendering: crispEdges;
}

/* ---------------------------------------------------------------- the foot: the note and the two buttons */
.flow__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 30px;
}

.flow__note {
  position: relative;
  min-width: 0;
  height: 22px;
  margin: 0;
  overflow: hidden;
  font-size: 14px;
  line-height: 22px;
  color: #6e6e6e;
  font-variation-settings: 'wght' 400, 'wdth' 100;
  flex: 1;
}

/* the words that roll in and out of the note and of the main button */
.roll__item {
  display: block;
  white-space: nowrap;
}

.flow__note .roll__item {
  position: absolute;
  left: 0;
  top: 0;
}

.flow__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.back,
.next {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 46px;
  border: 0;
  border-radius: 999px;
  background: none;
  font-size: 15px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.back {
  gap: 9px;
  padding: 0 16px 0 14px;
  color: var(--ink);
  font-variation-settings: 'wght' 480, 'wdth' 100;
  transition: opacity 0.3s ease, font-variation-settings 0.45s cubic-bezier(0.34, 1.5, 0.64, 1);
}

.back__arrow,
.next__arrow {
  width: 14px;
  height: 12px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.5s cubic-bezier(0.34, 1.6, 0.64, 1);
}

.back.is-off {
  opacity: 0.28;
  cursor: default;
}

/* the main button: a pill that swells on a spring while its words widen on the width axis */
.next {
  gap: 10px;
  padding: 0 20px 0 22px;
  color: var(--on-button);
  isolation: isolate;
}

.next__body {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--button);
  transition: transform 0.55s cubic-bezier(0.34, 1.7, 0.64, 1);
}

.next__text {
  position: relative;
  display: block;
  height: 22px;
  overflow: hidden;
  line-height: 22px;
  font-variation-settings: 'wght' 560, 'wdth' 100;
  transition: font-variation-settings 0.45s cubic-bezier(0.34, 1.5, 0.64, 1);
}

.next__text .roll__item {
  position: absolute;
  left: 0;
  top: 0;
}

.next:active .next__body {
  transform: scale(0.965);
  transition-duration: 0.12s;
}

@media (hover: hover) and (pointer: fine) {
  .back:not(.is-off):hover {
    font-variation-settings: 'wght' 480, 'wdth' 112;
  }

  .back:not(.is-off):hover .back__arrow {
    transform: translateX(-3px);
  }

  .next:hover .next__body {
    transform: scale(1.045, 1.07);
  }

  .next:hover .next__text {
    font-variation-settings: 'wght' 560, 'wdth' 114;
  }

  .next:hover .next__arrow {
    transform: translateX(3px);
  }

  .next:hover:active .next__body {
    transform: scale(0.985, 1);
  }
}

/* ---------------------------------------------------------------- the telephone */
@media (max-width: 520px) {
  .step__name {
    font-size: 13.5px;
  }

  .step__check {
    width: 11px;
    height: 10px;
    margin-top: -5px;
  }

  .flow__foot {
    flex-direction: column;
    align-items: stretch;
    gap: 18px;
    margin-top: 24px;
  }

  .flow__note {
    flex: none;
  }

  .flow__actions {
    justify-content: space-between;
  }

  .back {
    padding-left: 4px;
  }
}
