/* The Newton's cradle loader: a card payment as a cradle of polished steel balls on a walnut base, alone on a black
   page, with the words, the three steps and the pill under it. The cradle is painted by script.js on the canvas with
   the colours below. */
:root {
  --page: #000000;          /* the page */
  --ink: #f3f1ec;           /* the words */
  --muted: #8b8f96;         /* the quiet words */
  --faint: #4a4e55;         /* the steps still to come */
  --track: #24272c;         /* the empty track of a step */
  --ok: #4fd68f;            /* payment complete */
  --error: #ff6a5c;         /* card declined */
  --steel: #c9d0d8;         /* the polished steel of the balls and the frame */
  --sky: #eef3f8;           /* the light the steel reflects from above */
  --wood: #6a4229;          /* the walnut base */
  --wood-dark: #2b170c;     /* its shaded front */
  --string: #c7ccd3;        /* the threads */
  --button: #f3f1ec;        /* the main pill */
  --button-ink: #0b0b0c;    /* its words */
  --line: #34383e;          /* the ring round the quiet pill */
  --focus: #ffb35c;         /* the keyboard's focus ring */
}

* {
  box-sizing: border-box;
}

/* a tap is a click at once: no wait for a double tap, no zoom */
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', 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: 40px 16px;
}

/* ---------------------------------------------------------------- the payment */
.pay {
  display: grid;
  width: min(380px, 100%);
}

/* the cradle: 380 by 214 units */
.pay__cradle {
  display: block;
  width: 100%;
  aspect-ratio: 380 / 214;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}

.pay__cradle.is-grab {
  cursor: grab;
}

.pay__cradle.is-held {
  cursor: grabbing;
}

/* ---------------------------------------------------------------- the words */
.pay__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 0 4px;
}

.pay__words {
  min-width: 0;
}

.pay__title,
.pay__meta {
  margin: 0;
  white-space: nowrap;
}

.pay__title {
  font-size: 19px;
  font-weight: 600;
  line-height: 24px;
  letter-spacing: -0.02em;
}

.pay__meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 450;
  line-height: 18px;
}

.pay__swap {
  display: inline-block;
}

.pay[data-mode='declined'] .pay__title {
  color: var(--error);
}

.pay[data-mode='done'] .pay__title {
  color: var(--ok);
}

/* the percentage, and the tick that takes its place at the end */
.pay__figure {
  position: relative;
  flex: none;
  display: grid;
  place-items: center end;
  min-width: 56px;
  height: 30px;
  margin: 0;
}

.pay__pct {
  grid-area: 1 / 1;
  font-size: 27px;
  font-weight: 500;
  line-height: 30px;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}

.pay[data-mode='declined'] .pay__pct {
  color: var(--error);
}

.pay__tick {
  grid-area: 1 / 1;
  width: 30px;
  height: 30px;
  fill: none;
  stroke: var(--ok);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
}

/* ---------------------------------------------------------------- the three steps */
.pay__steps {
  display: grid;
  grid-template-columns: 34fr 38fr 28fr;
  gap: 6px;
  margin-top: 16px;
  padding: 0 4px;
}

.step {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.step__word {
  overflow: hidden;
  color: var(--faint);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 16px;
  letter-spacing: 0.005em;
  white-space: nowrap;
  text-overflow: clip;
  transition: color 0.35s ease;
}

.step__track {
  position: relative;
  height: 3px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--track);
}

/* script.js sets its width as a scale */
.step__fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: background-color 0.4s ease;
}

.step[data-state='now'] .step__word,
.step[data-state='done'] .step__word {
  color: var(--ink);
}

.step[data-state='fail'] .step__word {
  color: var(--error);
}

.step[data-state='fail'] .step__fill {
  background: var(--error);
}

/* at the end the three tracks turn green one after the other */
.pay[data-mode='done'] .step__fill {
  background: var(--ok);
}

.pay[data-mode='done'] .step:nth-child(2) .step__fill {
  transition-delay: 0.1s;
}

.pay[data-mode='done'] .step:nth-child(3) .step__fill {
  transition-delay: 0.2s;
}

/* ---------------------------------------------------------------- the pill */
/* the fill is a layer of its own that swells past the edge with a bounce, and the words widen on the width axis of
   the font; pressed, the pill squashes a little */
.pill {
  position: relative;
  justify-self: stretch;
  display: grid;
  place-items: center;
  height: 48px;
  margin-top: 20px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--button-ink);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.005em;
  white-space: nowrap;
  cursor: pointer;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  transition: color 0.25s ease;
}

.pill::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--button);
  transition: inset 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.3s ease, box-shadow 0.3s ease;
}

.pill__label {
  display: inline-block;
  font-stretch: 92%;
  font-variant-numeric: tabular-nums;
  transition: font-stretch 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* while it works the pill goes quiet */
.pill.is-quiet {
  color: var(--muted);
  cursor: default;
}

.pill.is-quiet::before {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--line);
}

@media (hover: hover) and (pointer: fine) {
  .pill:not(.is-quiet):hover::before {
    inset: -3px -5px;
  }

  .pill:not(.is-quiet):hover .pill__label {
    font-stretch: 108%;
  }
}

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

@media (prefers-reduced-motion: reduce) {
  .pill::before,
  .pill__label,
  .step__word,
  .step__fill {
    transition: none;
  }
}
