/* The chrysalis button: a deep green pill on a white page, with a dark round well in its left end where a chrysalis
   hangs from a twig. The twig, the chrysalis and the butterfly are drawn by script.js on a canvas laid over the pill
   and the air above it (their colours come from here); the pill, the words and the states are CSS. */
:root {
  --page: #ffffff;          /* the page */
  --pill: #1b3a31;          /* the pill, at its top */
  --pill-deep: #0e221c;     /* the pill, at its foot */
  --well: #07120f;          /* the round well in the left end, where the chrysalis hangs */
  --ink: #f2eee3;           /* the words */
  --muted: #9cb4a9;         /* the words while it upgrades */
  --twig: #8a6444;          /* the twig across the well */
  --jade: #4ea47c;          /* the chrysalis */
  --jade-light: #a9e2c2;    /* the chrysalis where the light falls */
  --jade-dark: #1b4a37;     /* the chrysalis in its shade */
  --gold: #e4c063;          /* the thin gold line round the chrysalis */
  --husk: #d9ebe0;          /* the empty case, once the butterfly is out */
  --margin: #0b0d12;        /* the black edge of the wings */
  --body: #2a2320;          /* the butterfly's body */
  --focus: #1b3a31;         /* 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;
  margin: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  /* room above the pill for the flight and for the butterfly sitting on its edge */
  padding: 120px 16px 72px;
}

.chry {
  position: relative;
  display: grid;
  justify-items: center;
}

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

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

/* the well: a dark round hollow in the left end, lit a little from the top, where the chrysalis hangs */
.chry__well {
  position: absolute;
  left: 7px;
  top: 7px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background:
    radial-gradient(70% 60% at 50% 18%, rgba(140, 200, 170, 0.14), transparent 70%),
    var(--well);
  box-shadow:
    inset 0 3px 6px rgba(0, 0, 0, 0.7),
    inset 0 -1px 0 rgba(255, 255, 255, 0.06),
    0 1px 0 rgba(255, 255, 255, 0.07);
  pointer-events: none;
}

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

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

/* the canvas over the pill and the air above it: twig, chrysalis and butterfly. Never in the way of the hand */
.chry__air {
  position: absolute;
  z-index: 1;
  left: 0;
  top: 0;
  pointer-events: none;
}

/* ---------------------------------------------------------------- the words */
/* three faces on top of each other, right of the well: at rest, while it upgrades, and upgraded */
.chry__faces {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 62px;
  right: 24px;
  pointer-events: none;
}

.chry__face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

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

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

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

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

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

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

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

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

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

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

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