/* The latte art button: an espresso-brown pill on a white page, with a cup of coffee seen from above in its round left
   end. The saucer and the cup are drawn by script.js in an SVG, the coffee on a canvas (their colours come from here);
   the pill, the words and the states are CSS. */
:root {
  --page: #ffffff;          /* the page */
  --pill: #4a2c1c;          /* the pill, at its top */
  --pill-deep: #2b170d;     /* the pill, at its foot */
  --ink: #f7ecdc;           /* the words */
  --muted: #c9ae93;         /* the small words */
  --china: #f7f4ee;         /* the cup and the saucer */
  --china-shade: #cfc8bc;   /* the china in its shadow */
  --crema: #b8743a;         /* the crema at its lightest */
  --crema-deep: #6a3416;    /* the crema in its dark flecks, and at the edge of the cup */
  --milk: #fbf3e4;          /* the steamed milk */
  --focus: #4a2c1c;         /* 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: '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: 48px 16px;
}

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

/* the unit holds the pill and the saucer, which stands a little past it */
.latte__unit {
  position: relative;
  padding: 12px 0 12px 12px;
}

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

.latte__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 */
.latte__fill {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background:
    radial-gradient(90% 140% at 20% 0%, rgba(255, 236, 214, 0.1), 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 1px 2px rgba(43, 23, 13, 0.22),
    0 14px 28px -14px rgba(43, 23, 13, 0.62);
  transition:
    inset 0.6s cubic-bezier(0.34, 1.9, 0.45, 1),
    box-shadow 0.4s ease;
}

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

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

/* the cup sits over the round left end; its middle is the middle of that end */
.latte__cup {
  position: absolute;
  left: 4px;
  top: 2px;
  width: 80px;
  height: 80px;
  pointer-events: none;
}

.latte__china,
.latte__over,
.latte__coffee {
  position: absolute;
  inset: 0;
  width: 80px;
  height: 80px;
  overflow: visible;
}

/* the coffee: as wide as the inside of the cup, in its middle */
.latte__coffee {
  inset: auto;
  left: 17px;
  top: 17px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
}

/* ---------------------------------------------------------------- the words */
/* three faces on top of each other, right of the cup: at rest, while the milk pours, and ready */
.latte__faces {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 72px;
  right: 0;
  pointer-events: none;
}

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

.latte__face--two {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 5px;
}

[data-face='busy'],
[data-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 nothing moves beside them */
.latte__word {
  display: inline-grid;
  padding-bottom: 1px;
  font-size: 17.5px;
  font-weight: 620;
  font-stretch: 84%;
  letter-spacing: -0.006em;
  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);
}

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

.latte__price {
  font-size: 14px;
  font-weight: 560;
  font-stretch: 90%;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--muted);
}

.latte__small {
  font-size: 11.5px;
  font-weight: 520;
  font-stretch: 94%;
  letter-spacing: 0.012em;
  line-height: 1;
  color: var(--muted);
}

.latte__big {
  font-size: 16.5px;
  font-weight: 640;
  font-stretch: 88%;
  letter-spacing: -0.006em;
  line-height: 1.05;
}

/* ---------------------------------------------------------------- under the pointer */
@media (hover: hover) and (pointer: fine) {
  .latte__btn:not([aria-disabled='true']):hover .latte__fill {
    inset: -2px -7px;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.14),
      inset 0 -1px 0 rgba(0, 0, 0, 0.4),
      0 1px 2px rgba(43, 23, 13, 0.22),
      0 18px 32px -14px rgba(43, 23, 13, 0.68);
  }

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

/* the keys bring the focus: the words widen as under the pointer */
html[data-using='keys'] .latte__btn:focus-visible:not([aria-disabled='true']) .latte__word {
  font-stretch: 100%;
  font-weight: 700;
}

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

  html[data-using='keys'] .latte__btn:focus-visible:not([aria-disabled='true']) .latte__word {
    font-stretch: 84%;
    font-weight: 620;
  }
}

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

  .latte__btn:not([aria-disabled='true']):hover .latte__word {
    font-stretch: 84%;
    font-weight: 620;
  }
}
