/* The gumball machine button: a cocoa pill on a white page, with a small gumball machine standing in its round left
   end. The machine, the gumballs, the chute and the cup are drawn by script.js on a canvas (their colours come from
   here); the pill, the words and the states are CSS. */
:root {
  --page: #ffffff;          /* the page */
  --pill: #33202a;          /* the pill, at its top */
  --pill-deep: #1a0f15;     /* the pill, at its foot */
  --ink: #fff4ea;           /* the words */
  --muted: #d4b2ad;         /* the price, and the words while it adds */
  --chip: rgba(255, 244, 234, 0.1);   /* the little Clear pill */
  --enamel: #d9302c;        /* the red enamel of the machine */
  --enamel-light: #ff7a66;  /* the enamel where the light falls */
  --enamel-dark: #7c1210;   /* the enamel in its shadow */
  --chrome: #d7dde2;        /* the chrome of the knob and the chute */
  --chrome-dark: #6c7680;   /* the chrome in its shadow */
  --cup: #120a0e;           /* the cup in the pill, where the gumballs land */
  --gum-cherry: #ec3a52;    /* the gumballs */
  --gum-orange: #ff8b26;
  --gum-lemon: #ffd43c;
  --gum-mint: #36c98d;
  --gum-sky: #3d9cff;
  --gum-grape: #8d5bea;
  --gum-pink: #ff74b1;
  --gum-milk: #f6efe3;
  --focus: #33202a;         /* the ring of the keyboard's focus */
}

* {
  box-sizing: border-box;
}

/* a tap is a click at once: no wait for a double tap */
html {
  touch-action: manipulation;
}

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

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--pill);
  font-family: 'Mona Sans Variable', 'Mona Sans', system-ui, -apple-system, 'Segoe 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: 72px 16px;
}

/* the whole thing: the machine stands at the left, its foot on the line of the pill's foot, its globe over it */
.gum {
  position: relative;
  /* the script sets the width from the words; this is the width before it does */
  width: 306px;
  max-width: calc(100vw - 32px);
  height: 104px;
}

/* the canvas covers the machine, the chute and the cup, and a margin above for the gumballs flying home */
.gum__art {
  position: absolute;
  left: 0;
  top: -24px;
  width: 132px;
  height: 128px;
  z-index: 2;
  pointer-events: none;
}

/* ---------------------------------------------------------------- the pill */
.gum__btn {
  position: absolute;
  left: 36px;
  bottom: 0;
  display: block;
  width: 270px;
  height: 60px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.gum__btn[aria-disabled='true'] {
  cursor: progress;
}

/* the fill is a layer of its own, so it can swell past the pill with a bounce without moving anything */
.gum__fill {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background:
    radial-gradient(80% 140% at 30% 0%, rgba(255, 255, 255, 0.08), transparent 62%),
    linear-gradient(180deg, var(--pill), var(--pill-deep));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -1px 0 rgba(0, 0, 0, 0.45),
    0 1px 2px rgba(26, 15, 21, 0.22),
    0 14px 28px -14px rgba(26, 15, 21, 0.6);
  transition:
    inset 0.6s cubic-bezier(0.34, 1.9, 0.45, 1),
    box-shadow 0.4s ease;
}

.gum__btn:focus-visible {
  outline: 2.5px solid var(--focus);
  outline-offset: 5px;
}

html[data-using='pointer'] .gum__btn:focus-visible {
  outline: none;
}

/* ---------------------------------------------------------------- the words */
/* three faces on top of each other, right of the cup: at rest, while it adds, and the count */
.gum__faces {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 94px;
  right: 0;
  pointer-events: none;
}

.gum__face {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  /* as wide as the words, not as the pill is now: the script measures it to size the pill */
  width: max-content;
  display: flex;
  align-items: center;
  gap: 7px;
  text-align: left;
  white-space: nowrap;
}

.gum__face--busy,
.gum__face--done {
  opacity: 0;
  visibility: hidden;
}

/* the words at rest widen on the typeface's width axis under the pointer; the script keeps their room free at the
   end of the pill, so the pill never changes size */
.gum__word {
  display: inline-block;
  padding-bottom: 1px;
  font-size: 17px;
  font-weight: 620;
  font-stretch: 100%;
  letter-spacing: -0.008em;
  line-height: 1;
  transition: font-stretch 0.6s cubic-bezier(0.34, 1.9, 0.45, 1), font-weight 0.6s cubic-bezier(0.34, 1.9, 0.45, 1);
}

.gum__price {
  padding-bottom: 1px;
  font-size: 15px;
  font-weight: 540;
  line-height: 1;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.gum__price::before {
  content: '·';
  margin-right: 6px;
}

/* while it adds: the words in a quieter tone, with a sheen running through them */
.gum__shine {
  padding-bottom: 1px;
  font-size: 17px;
  font-weight: 560;
  line-height: 1;
  color: var(--muted);
  background: linear-gradient(100deg, var(--muted) 0%, var(--muted) 38%, var(--ink) 50%, var(--muted) 62%, var(--muted) 100%);
  background-size: 260% 100%;
  background-position: var(--sheen, 100%) 0;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* the count: Added, the number on a roller, in cart */
.gum__face--done {
  gap: 12px;
}

.gum__done {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 1px;
  font-size: 17px;
  font-weight: 620;
  letter-spacing: -0.008em;
  line-height: 1.1;
}

.gum__dot {
  color: var(--muted);
}

.gum__roll {
  display: inline-block;
  height: 1.1em;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.gum__digits {
  display: grid;
  line-height: 1.1;
  text-align: center;
}

.gum__chip {
  display: grid;
  place-items: center;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--chip);
  box-shadow: inset 0 0 0 1px rgba(255, 244, 234, 0.12);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  opacity: 0;
  visibility: hidden;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

/* ---------------------------------------------------------------- under the pointer */
@media (hover: hover) and (pointer: fine) {
  .gum__btn:not([aria-disabled='true']):hover .gum__fill {
    inset: -2px -7px;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.12),
      inset 0 -1px 0 rgba(0, 0, 0, 0.45),
      0 1px 2px rgba(26, 15, 21, 0.22),
      0 18px 32px -14px rgba(26, 15, 21, 0.66);
  }

  .gum__btn:not([aria-disabled='true']):hover .gum__word {
    font-stretch: 116%;
    font-weight: 680;
  }

  .gum__btn:not([aria-disabled='true']):hover .gum__chip {
    background: rgba(255, 244, 234, 0.18);
    box-shadow: inset 0 0 0 1px rgba(255, 244, 234, 0.22);
  }
}

/* the keys bring the focus: the words widen as under the pointer */
html[data-using='keys'] .gum__btn:focus-visible .gum__word {
  font-stretch: 116%;
  font-weight: 680;
}

/* ---------------------------------------------------------------- reduced motion: no swelling, no widening */
@media (prefers-reduced-motion: reduce) {
  .gum__fill,
  .gum__word {
    transition: box-shadow 0.3s ease, filter 0.3s ease;
  }

  html[data-using='keys'] .gum__btn:focus-visible .gum__word {
    font-stretch: 100%;
    font-weight: 620;
  }
}

@media (prefers-reduced-motion: reduce) and (hover: hover) and (pointer: fine) {
  .gum__btn:not([aria-disabled='true']):hover .gum__fill {
    inset: 0;
    filter: brightness(1.25);
  }

  .gum__btn:not([aria-disabled='true']):hover .gum__word {
    font-stretch: 100%;
    font-weight: 620;
  }
}
