/* The gift wrap button: a deep pine pill on a white page, with a small kraft box in its round left end. The box, the
   paper, the ribbon on its faces are drawn by script.js on a canvas, the bow on top is an SVG redrawn every frame
   (their colours come from here); the pill, the words and the states are CSS. */
:root {
  --page: #ffffff;          /* the page */
  --pill: #1f3a31;          /* the pill, at its top */
  --pill-deep: #12251f;     /* the pill, at its foot */
  --ink: #f5efe2;           /* the words */
  --muted: #a8b9b0;         /* the price, and the words while it wraps */
  --chip: rgba(245, 239, 226, 0.1);   /* the little Remove pill */
  --kraft: #c89b68;         /* the box, brown kraft board */
  --kraft-lid: #d6ab79;     /* the lid of the box */
  --paper: #f6eedd;         /* the wrapping paper */
  --paper-back: #e9e2d2;    /* the plain back of the paper */
  --print: #c6493a;         /* the stripes printed on the paper */
  --print-gold: #d3a443;    /* the thin gold lines printed between them */
  --satin: #b51d3a;         /* the satin ribbon and the bow */
  --satin-light: #ff8d96;   /* where the light runs along the satin */
  --satin-dark: #5e0b1c;    /* the satin in its folds */
  --focus: #1f3a31;         /* 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;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

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

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

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

.wrap__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 */
.wrap__fill {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background:
    radial-gradient(48px 48px at 36px 32px, rgba(255, 255, 255, 0.07), transparent 70%),
    radial-gradient(90% 140% at 18% 0%, rgba(255, 255, 255, 0.06), 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.4),
    0 1px 2px rgba(18, 37, 31, 0.22),
    0 14px 28px -14px rgba(18, 37, 31, 0.6);
  transition:
    inset 0.6s cubic-bezier(0.34, 1.9, 0.45, 1),
    box-shadow 0.4s ease;
}

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

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

/* the box, the paper and the bow sit in the round left end of the pill */
.wrap__art {
  position: absolute;
  left: 0;
  top: 0;
  width: 76px;
  height: 60px;
  pointer-events: none;
}

.wrap__box,
.wrap__bow {
  position: absolute;
  inset: 0;
  width: 76px;
  height: 60px;
  overflow: visible;
}

/* the paper, arriving open, never pokes out of the pill's round end */
.wrap__box {
  clip-path: inset(0 round 30px 0 0 30px);
}

/* the bow sits on the paper with a soft shadow of its own */
.wrap__bow {
  filter: drop-shadow(0 0.8px 0.7px rgba(70, 8, 20, 0.45));
}

.st-dark {
  stop-color: var(--satin-dark);
}

.st-mid {
  stop-color: var(--satin);
}

.st-light {
  stop-color: var(--satin-light);
}

/* the opening of each loop, darker: the inside of the satin */
.wrap__hole {
  fill: var(--satin-dark);
  opacity: 0.78;
}

/* the light along the top of each loop */
.wrap__gleam {
  fill: none;
  stroke: #fff;
  stroke-opacity: 0.55;
  stroke-width: 0.7;
  stroke-linecap: round;
}

.wrap__crease {
  fill: none;
  stroke: var(--satin-dark);
  stroke-opacity: 0.6;
  stroke-width: 0.5;
  stroke-linecap: round;
}

/* ---------------------------------------------------------------- the words */
/* three faces on top of each other, right of the box: at rest, while it wraps, and wrapped */
.wrap__faces {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 76px;
  right: 0;
  pointer-events: none;
}

.wrap__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;
}

.wrap__face--busy,
.wrap__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 */
.wrap__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);
}

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

.wrap__price {
  margin-left: -3px;
  padding-bottom: 1px;
  font-size: 16px;
  font-weight: 520;
  line-height: 1;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* while it wraps: the words in a quieter tone, with a sheen running through them */
.wrap__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;
}

/* wrapped: the words, and the little Remove pill at the right end */
.wrap__face--done {
  gap: 14px;
}

.wrap__done {
  padding-bottom: 1px;
  font-size: 17px;
  font-weight: 640;
  letter-spacing: -0.008em;
  line-height: 1;
}

.wrap__chip {
  flex: none;
  display: grid;
  place-items: center;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--chip);
  box-shadow: inset 0 0 0 1px rgba(245, 239, 226, 0.13);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

/* ---------------------------------------------------------------- under the pointer */
@media (hover: hover) and (pointer: fine) {
  .wrap__btn:not([aria-disabled='true']):hover .wrap__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.4),
      0 1px 2px rgba(18, 37, 31, 0.22),
      0 18px 32px -14px rgba(18, 37, 31, 0.66);
  }

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

  .wrap__btn:not([aria-disabled='true']):hover .wrap__chip {
    background: rgba(245, 239, 226, 0.18);
    box-shadow: inset 0 0 0 1px rgba(245, 239, 226, 0.24);
  }
}

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

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

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

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

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