/* The elastic button: a pill whose label widens on the typeface's width axis while the fill swells past its size and
   settles, and squashes under a press. The room for the wide label is kept by an invisible copy, so the buttons
   never push anything around. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #1f2a22;           /* the dark button, and the text of the outlined one */
  --cream: #f4efe4;         /* the text on the dark button */
  --accent: #d9642b;        /* the rust button */
  /* set by the script from its values: how wide and heavy the label gets, how long and how springy */
  --stretch: 122%;
  --weight: 620;
  --weight-up: 720;
  --time: 0.6s;
  --bounce: cubic-bezier(0.34, 1.9, 0.45, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 40px clamp(18px, 3.2vw, 48px);
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  padding: 14px;
}

/* ---------------------------------------------------------------- the elastic button */
.elastic {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  height: 60px;
  padding: 0 26px 0 30px;
  border-radius: 999px;
  color: var(--on);
  font-size: 18px;
  font-weight: var(--weight);
  font-stretch: 100%;
  line-height: 1;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;   /* no link preview under a long press on iPhone */
}

/* the fill is a layer of its own: it can swell and squash without moving the label */
.elastic__fill {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--bg);
  box-shadow: var(--ring, 0 0 0 0 transparent), 0 0 0 0 rgba(31, 42, 34, 0);
  transition: background-color 0.3s ease, box-shadow var(--time) ease;
}

/* when it swells it also lifts: a soft shadow grows under it */
.elastic.is-on .elastic__fill {
  box-shadow: var(--ring, 0 0 0 0 transparent), 0 16px 28px -16px rgba(31, 42, 34, 0.6);
}

/* the invisible wide copy, zero high, holds the room of the widest label */
.elastic__label {
  display: inline-grid;
}

.elastic__label::before {
  content: attr(data-label);
  grid-area: 1 / 1;
  height: 0;
  overflow: hidden;
  visibility: hidden;
  font-stretch: var(--stretch);
  font-weight: var(--weight-up);
  white-space: nowrap;
}

.elastic__text {
  grid-area: 1 / 1;
  justify-self: center;
  white-space: nowrap;
  transition: font-stretch var(--time) var(--bounce), font-weight var(--time) var(--bounce);
}

.elastic__icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: translate var(--time) var(--bounce), rotate var(--time) var(--bounce);
}

/* on: under the pointer, reached with the keyboard, or for a moment after a tap */
.elastic.is-on .elastic__text {
  font-stretch: var(--stretch);
  font-weight: var(--weight-up);
}

.elastic.is-on .elastic__icon--arrow {
  translate: 5px 0;
}

.elastic.is-on .elastic__icon--page {
  rotate: -10deg;
  translate: 0 -1px;
}

.elastic.is-on .elastic__icon--gift {
  rotate: 8deg;
  translate: 0 -2px;
}

.elastic--ink {
  --bg: var(--ink);
  --on: var(--cream);
}

.elastic--accent {
  --bg: var(--accent);
  --on: #fff6ea;
}

.elastic--ghost {
  --bg: rgba(31, 42, 34, 0);
  --on: var(--ink);
  --ring: inset 0 0 0 1.5px var(--ink);
}

.elastic--ghost.is-on {
  --bg: rgba(31, 42, 34, 0.07);
}

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

.elastic--accent:focus-visible {
  outline-color: var(--ink);
}

/* reduced motion: no widening and no swelling, only the colour answers */
@media (prefers-reduced-motion: reduce) {
  .elastic__text,
  .elastic__icon {
    transition: none;
  }

  .elastic.is-on .elastic__text {
    font-stretch: 100%;
    font-weight: var(--weight);
  }

  .elastic.is-on .elastic__icon {
    translate: none;
    rotate: none;
  }

  .elastic--ink.is-on {
    --bg: #2f3d33;
  }

  .elastic--accent.is-on {
    --bg: #c45522;
  }
}

@media (max-width: 760px) {
  .buttons {
    flex-direction: column;
    align-items: center;
  }

  .elastic {
    height: 56px;
    font-size: 17px;
  }
}
