/* The little trolley button: a deep basil green pill on a black page, with a chrome wire shopping trolley in its
   round left end. The trolley, its springs, its wheels and the boxes in it are drawn by script.js on a canvas (their
   colours come from here); the pill, the words and the states are CSS. */
:root {
  --page: #000000;          /* the page */
  --pill: #24563f;          /* the pill, at its top */
  --pill-deep: #133126;     /* the pill, at its foot */
  --ink: #f3efe4;           /* the words */
  --muted: #a7c2b2;         /* the price, and the small words */
  --tick: #c9f08a;          /* the tick of Added */
  --chrome-light: #f6f9fb;  /* the wire of the trolley, where the light falls */
  --chrome: #aab6bf;        /* the wire */
  --chrome-dark: #47535c;   /* the wire, in its shadow */
  --grip: #e4583d;          /* the plastic grip on the handle */
  --tyre: #15191c;          /* the wheels */
  --box: #f4eee2;           /* the cream labels on the boxes */
  --box-1: #d9714a;         /* the first box, in its colourway: Clay */
  --box-2: #3b4f8f;         /* the second: Ink */
  --box-3: #9db48a;         /* the third: Sage */
  --box-4: #e49aa3;         /* the fourth: Rose */
  --box-5: #d9c497;         /* the fifth: Oat */
  --focus: #c9f08a;         /* 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(--ink);
  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;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

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

/* the room above the pill is where the boxes fall from: it belongs to the component */
.trolley {
  display: grid;
  justify-items: center;
  padding-top: 64px;
}

/* ---------------------------------------------------------------- the pill */
.trolley__btn {
  position: relative;
  display: block;
  /* the script sets the width from the words; this is the width before it does */
  width: 270px;
  max-width: calc(100vw - 32px);
  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;
}

.trolley__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 */
.trolley__fill {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background:
    radial-gradient(90% 140% at 20% 0%, rgba(255, 255, 255, 0.09), transparent 62%),
    linear-gradient(180deg, var(--pill), var(--pill-deep));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -1px 0 rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.04);
  transition: inset 0.6s cubic-bezier(0.34, 1.9, 0.45, 1), box-shadow 0.4s ease;
}

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

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

/* the canvas covers the pill and the room above it, where the boxes fall */
.trolley__art {
  position: absolute;
  left: 0;
  top: -64px;
  width: 100%;
  height: calc(100% + 64px);
  pointer-events: none;
}

/* ---------------------------------------------------------------- the words */
/* two faces on top of each other, right of the trolley. While the trolley runs, the words show only to the right of
   it: the script moves the soft edge of the mask (--cut) with the trolley's nose */
.trolley__faces {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  pointer-events: none;
  --cut: -20px;
  -webkit-mask-image: linear-gradient(90deg, transparent calc(var(--cut) - 2px), #000 calc(var(--cut) + 8px));
  mask-image: linear-gradient(90deg, transparent calc(var(--cut) - 2px), #000 calc(var(--cut) + 8px));
}

.trolley__face {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 66px;
  /* 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: 9px;
  text-align: left;
  white-space: nowrap;
}

.trolley__face--done {
  gap: 6px;
  opacity: 0;
  visibility: hidden;
}

/* the words at rest widen on the typeface's width axis under the pointer; the wide copy, invisible and zero high,
   holds their room, so the pill never changes size */
.trolley__word {
  display: inline-grid;
  padding-bottom: 1px;
  font-size: 17px;
  font-weight: 640;
  font-stretch: 100%;
  letter-spacing: -0.01em;
  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);
}

.trolley__word::before {
  content: attr(data-wide);
  height: 0;
  overflow: hidden;
  visibility: hidden;
  font-stretch: 116%;
  font-weight: 700;
}

.trolley__price {
  padding: 5px 9px 6px;
  border-radius: 999px;
  background: rgba(243, 239, 228, 0.1);
  box-shadow: inset 0 0 0 1px rgba(243, 239, 228, 0.12);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  line-height: 1;
}

.trolley__tick {
  flex: none;
  width: 18px;
  height: 18px;
  margin-right: 1px;
  fill: none;
  stroke: var(--tick);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
}

.trolley__done {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1;
  padding-bottom: 1px;
}

.trolley__dot {
  color: var(--muted);
  font-size: 17px;
  font-weight: 600;
  line-height: 1;
}

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

.trolley__count [data-count] {
  display: inline-block;
  color: var(--ink);
  font-weight: 650;
}

/* the small Clear pill, only once the basket is full */
.trolley__chip {
  display: none;
  place-items: center;
  height: 30px;
  margin-left: 6px;
  padding: 0 11px;
  border-radius: 999px;
  background: rgba(243, 239, 228, 0.1);
  box-shadow: inset 0 0 0 1px rgba(243, 239, 228, 0.14);
  font-size: 13px;
  font-weight: 620;
  line-height: 1;
}

.trolley[data-full] .trolley__chip {
  display: grid;
}

/* with the basket full the Clear pill takes the place of Added */
.trolley[data-full] .trolley__done,
.trolley[data-full] .trolley__dot {
  display: none;
}

/* ---------------------------------------------------------------- under the pointer */
@media (hover: hover) and (pointer: fine) {
  .trolley__btn:not([aria-disabled='true']):hover .trolley__fill {
    inset: -2px -7px;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.15),
      inset 0 -1px 0 rgba(0, 0, 0, 0.4),
      0 0 0 1px rgba(255, 255, 255, 0.06);
  }

  .trolley__btn:not([aria-disabled='true']):hover .trolley__word {
    font-stretch: 116%;
    font-weight: 700;
  }
}

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

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

  html[data-using='keys'] .trolley__btn:focus-visible .trolley__word {
    font-stretch: 100%;
    font-weight: 640;
  }
}

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

  .trolley__btn:not([aria-disabled='true']):hover .trolley__word {
    font-stretch: 100%;
    font-weight: 640;
  }
}
