/* The coupon button: a warm charcoal pill on a black page, with a small paper coupon in its left end. The coupon is an
   SVG cut in two by clip paths along a torn edge the script works out each time; the pill, the words, the pen stroke
   and the rolling digits are CSS and SVG. */
:root {
  --page: #000000;          /* the page */
  --pill: #2a2521;          /* the pill, at its top */
  --pill-deep: #171411;     /* the pill, at its foot */
  --ink: #f8efe2;           /* the words and the price */
  --muted: #a99d8f;         /* the small words, and the old price */
  --coupon: #f07a34;        /* the coupon's printed face, at its top */
  --coupon-deep: #d4541c;   /* the coupon's printed face, at its foot */
  --coupon-ink: #fff4e6;    /* the words printed on the coupon */
  --fibre: #fff8ee;         /* the white core of the paper along the tear */
  --pen: #ff6b3d;           /* the pen stroke over the old price */
  --chip: #f07a34;          /* the little badge with the discount */
  --chip-ink: #24130a;      /* the words on the badge */
  --focus: #f8efe2;         /* 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: 72px 16px 140px;
}

.deal {
  display: grid;
  justify-items: center;
}

/* ---------------------------------------------------------------- the pill */
.deal__btn {
  position: relative;
  display: block;
  /* the script sets the width from the words; this is the width before it does */
  width: 340px;
  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;
}

.deal__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 */
.deal__fill {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background:
    radial-gradient(90% 140% at 18% 0%, rgba(255, 255, 255, 0.07), 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.5),
    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;
}

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

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

/* ---------------------------------------------------------------- the coupon */
.deal__coupon {
  position: absolute;
  left: 10px;
  top: 9px;
  width: 104px;
  height: 42px;
  overflow: visible;
  /* a pull on the coupon tears it: the page does not scroll under the finger */
  touch-action: none;
}

.cp-a {
  stop-color: var(--coupon);
}

.cp-b {
  stop-color: var(--coupon-deep);
}

.cp-paper {
  fill: url(#cp-paper);
}

/* a fine print of lines on the bias, like the security print of a voucher */
.cp-printed {
  fill: url(#cp-print);
  opacity: 0.16;
}

.cp-print {
  stroke: var(--coupon-ink);
  stroke-width: 0.5;
}

.cp-dash {
  fill: none;
  stroke: var(--coupon-ink);
  stroke-width: 0.7;
  stroke-dasharray: 2.2 1.6;
  opacity: 0.6;
}

.cp-leaf path:first-child {
  fill: var(--coupon-ink);
  opacity: 0.92;
}

.cp-vein {
  fill: none;
  stroke: var(--coupon-deep);
  stroke-width: 0.55;
  stroke-linecap: round;
}

.cp-off {
  fill: var(--coupon-ink);
  font-family: 'Mona Sans Variable', 'Mona Sans', system-ui, sans-serif;
  font-size: 7.4px;
  font-weight: 700;
  letter-spacing: 0.1em;
  opacity: 0.86;
}

.cp-code {
  fill: var(--coupon-ink);
  font-family: 'JetBrains Mono Variable', 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12.4px;
  font-weight: 760;
  letter-spacing: 0.04em;
}

/* each half of the coupon lies on the pill with its own soft shadow */
.cp-piece {
  filter: drop-shadow(0 1.2px 1.2px rgba(0, 0, 0, 0.45));
}

/* the white core of the paper, along the torn edge */
.cp-fiber {
  fill: none;
  stroke: var(--fibre);
  stroke-width: 0.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------------------------------------------------------------- the words */
/* three faces on top of each other, right of the coupon: at rest, while it checks, and applied. The script moves
   them all left when the torn half is gone */
.deal__faces {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  pointer-events: none;
}

.deal__face {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: max-content;
  display: flex;
  align-items: center;
  text-align: left;
  white-space: nowrap;
}

.deal__face--busy,
.deal__face--done {
  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 */
.deal__word {
  display: inline-grid;
  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);
}

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

/* while it checks: the words in a quieter tone, with a sheen running through them */
.deal__shine {
  padding-bottom: 1px;
  font-size: 17px;
  font-weight: 560;
  letter-spacing: -0.004em;
  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;
}

.deal__lines {
  display: grid;
  gap: 5px;
}

.deal__applied {
  font-size: 15.5px;
  font-weight: 640;
  letter-spacing: -0.006em;
  line-height: 1;
}

.deal__sub {
  font-size: 11.5px;
  font-weight: 520;
  letter-spacing: 0.01em;
  line-height: 1;
  color: var(--muted);
}

.deal__code {
  font-family: 'JetBrains Mono Variable', 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink);
}

/* ---------------------------------------------------------------- the price */
.deal__price {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 22px;
  display: grid;
  align-items: center;
  justify-items: end;
  pointer-events: none;
}

.deal__now,
.deal__was {
  grid-area: 1 / 1;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.2;
  white-space: nowrap;
}

.deal__now {
  display: flex;
}

.deal__was {
  position: relative;
  display: flex;
  opacity: 0;
  visibility: hidden;
  transform-origin: 100% 50%;
}

/* the rolling digits: each one a strip of figures behind a window one figure high */
.deal__col {
  display: inline-block;
  width: 0.64em;
  height: 1.2em;
  overflow: hidden;
  /* the wheel turns away at its top and bottom */
  -webkit-mask-image: linear-gradient(transparent, #000 14%, #000 86%, transparent);
  mask-image: linear-gradient(transparent, #000 14%, #000 86%, transparent);
}

/* a digit that does not change, in a cell as wide as a wheel */
.deal__dig {
  display: inline-block;
  width: 0.64em;
  height: 1.2em;
  line-height: 1.2em;
  text-align: center;
}

.deal__strip {
  display: block;
}

.deal__strip > span {
  display: block;
  height: 1.2em;
  line-height: 1.2em;
  text-align: center;
}

.deal__ch {
  display: inline-block;
  height: 1.2em;
  line-height: 1.2em;
}

/* the pen stroke over the old price */
.deal__strike {
  position: absolute;
  left: -4px;
  top: -3px;
  width: calc(100% + 8px);
  height: calc(100% + 6px);
  overflow: visible;
}

.deal__strike path {
  fill: none;
  stroke: var(--pen);
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* the little badge with the discount */
.deal__chip {
  position: absolute;
  top: 50%;
  right: 110px;
  display: grid;
  place-items: center;
  height: 24px;
  margin-top: -12px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--chip-ink);
  font-size: 12.5px;
  font-weight: 720;
  letter-spacing: 0.01em;
  line-height: 1;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

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

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

  .deal__coupon {
    cursor: grab;
  }
}

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

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

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

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

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