/* The cardboard box button: an espresso pill on a white page, with an open box of corrugated board in its round right
   end. The box is real CSS 3D: walls, floor and four flaps are planes in one 3D space, each with an outside and an
   inside; the script swings the flaps on their springs and drops the candles in. */
:root {
  --page: #ffffff;          /* the page */
  --pill: #33291f;          /* the pill, at its top */
  --pill-deep: #1d1712;     /* the pill, at its foot */
  --ink: #f8f0e3;           /* the words */
  --muted: #bfae98;         /* the small words, and the words while it packs */
  --tick: #f0b261;          /* the tick of Added */
  --kraft: #c8925a;         /* the board, outside */
  --kraft-light: #e0b47b;   /* the board where the light falls, and its cut edges */
  --kraft-in: #b07a45;      /* the board, inside */
  --print: #5d3a1b;         /* the arrows printed on the box */
  --tape: #d4553a;          /* the tape over the seam */
  --glass: #c47530;         /* the candle's amber glass */
  --glass-lit: #f2b56a;     /* the glass, where the light falls */
  --glass-deep: #7a3d14;    /* the glass, in its shadow */
  --wax: #fbf3e2;           /* the wax */
  --label: #f3ead8;         /* the candle's paper label */
  --label-ink: #6c7f5c;     /* the lines printed on it */
  --focus: #33291f;         /* the ring of the keyboard's focus */

  /* the box, in pixels: its width, its depth, its height and the length of its flaps */
  --bw: 34px;
  --bd: 26px;
  --bh: 23px;
  --fl: 13px;
}

* {
  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: 'Bricolage Grotesque Variable', 'Bricolage Grotesque', 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 candle falls from: it belongs to the component */
.pack {
  display: grid;
  justify-items: center;
  padding-top: 64px;
}

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

.pack__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 */
.pack__fill {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background:
    radial-gradient(90% 140% at 22% 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(29, 23, 18, 0.22),
    0 14px 28px -14px rgba(29, 23, 18, 0.6);
  transition: inset 0.6s cubic-bezier(0.34, 1.9, 0.45, 1), box-shadow 0.4s ease;
}

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

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

/* ---------------------------------------------------------------- the words */
.pack__faces {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 26px;
  right: 0;
  pointer-events: none;
}

.pack__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: 10px;
  text-align: left;
  white-space: nowrap;
}

.pack__face--busy,
.pack__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, so the pill never changes size */
.pack__word {
  display: inline-grid;
  padding-bottom: 2px;
  font-size: 18px;
  font-weight: 640;
  font-stretch: 86%;
  letter-spacing: -0.012em;
  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);
}

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

.pack__price {
  padding: 5px 9px 6px;
  border-radius: 999px;
  background: rgba(248, 240, 227, 0.1);
  box-shadow: inset 0 0 0 1px rgba(248, 240, 227, 0.13);
  font-size: 14px;
  font-weight: 600;
  font-stretch: 92%;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* while it packs: the words in a quieter tone, with a sheen running through them */
.pack__shine {
  padding-bottom: 2px;
  font-size: 18px;
  font-weight: 580;
  font-stretch: 90%;
  letter-spacing: -0.006em;
  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;
}

/* done: a small line over the big one */
.pack__lines {
  display: grid;
  gap: 4px;
}

.pack__lead {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 560;
  letter-spacing: 0.01em;
  line-height: 1;
}

.pack__tick {
  flex: none;
  width: 13px;
  height: 13px;
  margin-left: -1px;
  fill: none;
  stroke: var(--tick);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
}

.pack__ship {
  font-size: 17px;
  font-weight: 660;
  font-stretch: 92%;
  letter-spacing: -0.01em;
  line-height: 1.05;
}

/* ---------------------------------------------------------------- the box */
/* the perspective, in the round right end of the pill */
.crate {
  position: absolute;
  top: 0;
  right: 4px;
  width: 70px;
  height: 60px;
  perspective: 360px;
  perspective-origin: 50% 20%;
  pointer-events: none;
}

.crate__shadow {
  position: absolute;
  left: 50%;
  top: 44px;
  width: 54px;
  height: 10px;
  margin-left: -27px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
}

/* the layer that hops; the box under it is turned towards you, a little from above */
.crate__hop {
  position: absolute;
  left: 50%;
  top: 31px;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}

.crate__rig {
  position: absolute;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
  transform: rotateX(-32deg) rotateY(-34deg);
}

.wall,
.flap,
.tab,
.jars,
.cut {
  position: absolute;
  transform-style: preserve-3d;
}

.side {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  /* corrugated board: the flutes show faintly through the liner */
  background:
    repeating-linear-gradient(90deg, rgba(90, 55, 20, 0.07) 0 1px, transparent 1px 2.6px),
    var(--kraft);
  box-shadow: inset 0 0 0 0.6px rgba(92, 58, 24, 0.55);
}

/* every plane takes its light from --shade, which the script sets from its angle for the flaps */
.side::after {
  content: '';
  position: absolute;
  inset: 0;
  background: #1c120a;
  opacity: var(--shade, 0);
}

.side--in {
  --shade: 0.3;
  transform: rotateY(180deg);
  background:
    repeating-linear-gradient(90deg, rgba(90, 55, 20, 0.08) 0 1px, transparent 1px 2.6px),
    var(--kraft-in);
}

.wall--front,
.wall--back {
  left: calc(var(--bw) / -2);
  top: calc(var(--bh) / -2);
  width: var(--bw);
  height: var(--bh);
}

.wall--front {
  transform: translateZ(calc(var(--bd) / 2));
  --shade: 0.02;
}

.wall--back {
  transform: translateZ(calc(var(--bd) / -2)) rotateY(180deg);
  --shade: 0.36;
}

.wall--left,
.wall--right {
  left: calc(var(--bd) / -2);
  top: calc(var(--bh) / -2);
  width: var(--bd);
  height: var(--bh);
}

.wall--left {
  transform: translateX(calc(var(--bw) / -2)) rotateY(-90deg);
  --shade: 0.3;
}

.wall--right {
  transform: translateX(calc(var(--bw) / 2)) rotateY(90deg);
  --shade: 0.26;
}

.wall--floor {
  left: calc(var(--bw) / -2);
  top: calc(var(--bd) / -2);
  width: var(--bw);
  height: var(--bd);
  transform: translateY(calc(var(--bh) / 2)) rotateX(90deg);
}

/* the floor shows only its inside, which faces up */
.wall--floor .side--in {
  --shade: 0.4;
  transform: none;
}

/* the arrows printed on the front, this way up */
.side--print {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 14'%3E%3Cg fill='none' stroke='%235d3a1b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 12.5V2.5M2.5 6L6 2.5L9.5 6M18 12.5V2.5M14.5 6L18 2.5L21.5 6'/%3E%3C/g%3E%3Cpath d='M1.5 13.2h21' stroke='%235d3a1b' stroke-width='1.3' stroke-linecap='round'/%3E%3C/svg%3E") 74% 70% / 12px 7px no-repeat,
    linear-gradient(180deg, rgba(255, 238, 205, 0.18), transparent 45%),
    repeating-linear-gradient(90deg, rgba(90, 55, 20, 0.07) 0 1px, transparent 1px 2.6px),
    var(--kraft);
}

/* the flaps: hinged on the top edge of their wall; the script turns them */
.flap {
  transform-origin: 50% 100%;
}

.flap--front,
.flap--back {
  left: calc(var(--bw) / -2);
  top: calc(var(--bh) / -2 - var(--fl));
  width: var(--bw);
  height: var(--fl);
}

.flap--left,
.flap--right {
  left: calc(var(--bd) / -2);
  top: calc(var(--bh) / -2 - var(--fl));
  width: var(--bd);
  height: var(--fl);
}

/* the flaps' free edges are cut board: a lighter edge with the flutes in it */
.flap .side--out {
  background:
    linear-gradient(180deg, var(--kraft-light) 0 1.1px, transparent 1.1px),
    repeating-linear-gradient(90deg, rgba(90, 55, 20, 0.07) 0 1px, transparent 1px 2.6px),
    var(--kraft);
}

/* the tape: on each long flap, along its free edge, so it is cut in two when the box opens */
.tape {
  position: absolute;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, 0.08)),
    var(--tape);
  box-shadow: inset 0 0 0 0.4px rgba(90, 20, 8, 0.4);
}

.tape--half {
  left: -0.5px;
  right: -0.5px;
  top: 0;
  height: 4px;
  transform-origin: 0 50%;
  transform: scaleX(0);
}

/* the ends of the tape, folded down the short sides */
.tab {
  left: -4px;
  top: calc(var(--bh) / -2);
  width: 8px;
  height: 7px;
}

.tab--left {
  transform: translateX(calc(var(--bw) / -2 - 0.4px)) rotateY(-90deg);
}

.tab--right {
  transform: translateX(calc(var(--bw) / 2 + 0.4px)) rotateY(90deg);
}

.tab .tape {
  inset: 0;
  transform-origin: 50% 0;
  transform: scaleY(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* the blade that cuts the tape along the seam when the box opens again */
.cut {
  left: calc(var(--bw) / -2);
  top: -0.6px;
  width: var(--bw);
  height: 1.2px;
  transform: translateY(calc(var(--bh) / -2 - 1.6px)) rotateX(90deg);
  background: linear-gradient(90deg, rgba(255, 246, 225, 0), #fff6e1 70%, #ffffff);
  transform-origin: 0 50%;
  opacity: 0;
}

/* ---------------------------------------------------------------- the candles */
.jar {
  position: absolute;
  left: -7.5px;
  top: -10px;
  width: 15px;
  height: 20px;
  transform-style: flat;
}

.jar__art {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.glass { stop-color: var(--glass); }
.glass-lit { stop-color: var(--glass-lit); }
.glass-deep { stop-color: var(--glass-deep); }
.glass-edge { stop-color: color-mix(in srgb, var(--glass-deep) 70%, #000); }
.wax { stop-color: var(--wax); }
.wax-deep { stop-color: color-mix(in srgb, var(--wax) 78%, #8a6a3a); }

.jar__label {
  fill: var(--label);
}

.jar__ink {
  fill: none;
  stroke: var(--label-ink);
  stroke-width: 1.3;
  stroke-linecap: round;
}

.jar__wick {
  fill: none;
  stroke: #2b2017;
  stroke-width: 0.9;
  stroke-linecap: round;
}

.jar__gleam {
  fill: none;
  stroke: #fff3df;
  stroke-width: 1.1;
  stroke-linecap: round;
  opacity: 0.55;
}

.jar__lip {
  fill: none;
  stroke: var(--glass-lit);
  stroke-width: 0.8;
  opacity: 0.8;
}

/* ---------------------------------------------------------------- under the pointer */
@media (hover: hover) and (pointer: fine) {
  .pack__btn:not([aria-disabled='true']):hover .pack__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(29, 23, 18, 0.22),
      0 18px 32px -14px rgba(29, 23, 18, 0.66);
  }

  .pack__btn:not([aria-disabled='true']):hover .pack__word {
    font-stretch: 100%;
    font-weight: 700;
  }
}

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

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

  html[data-using='keys'] .pack__btn:focus-visible .pack__word {
    font-stretch: 86%;
    font-weight: 640;
  }
}

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

  .pack__btn:not([aria-disabled='true']):hover .pack__word {
    font-stretch: 86%;
    font-weight: 640;
  }
}
