/* The button that recomposes the word: a minimal piece. One black pill on a white page, its letters set like
   movable type in a variable grotesque, and one vermilion tick. The letters are placed by the script. */
:root {
  --page: #ffffff;          /* the page */
  --pill: #141414;          /* the pill */
  --pill-on: #222222;       /* the pill under the pointer */
  --type: #f6f3ec;          /* the letters */
  --accent: #ff5a2a;        /* the tick, and the focus ring */
}

* {
  box-sizing: border-box;
}

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

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

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

.frame {
  display: grid;
  place-items: center;
  height: 76px;
  max-width: 100%;
}

/* ---------------------------------------------------------------- the button */
.bag {
  position: relative;
  display: block;
  width: 152px;             /* set by the script, frame by frame */
  height: 60px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.bag[aria-busy='true'] {
  cursor: progress;
}

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

/* the pill: its width and height follow a spring, so it is drawn on its own around the centre of the button */
.bag__pill {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 152px;
  height: 60px;
  margin: -30px 0 0 -76px;
  border-radius: 999px;
  background: var(--pill);
  overflow: hidden;
  transition: background-color 0.3s ease;
}

.bag.is-on .bag__pill {
  background: var(--pill-on);
}

/* the line of type: its origin is the centre of the pill, every letter is placed from there */
.bag__line {
  position: absolute;
  left: 50%;
  top: 50%;
}

.ch {
  position: absolute;
  left: 0;
  top: 0;
  height: 24px;
  margin-top: -12.5px;
  font-size: 18px;
  line-height: 24px;
  color: var(--type);
  white-space: pre;
  font-kerning: none;
  font-variation-settings: 'wdth' 100, 'wght' 600;
  transform-origin: 0 50%;
  will-change: transform;
}

.bag__tick {
  position: absolute;
  left: 0;
  top: 0;
  width: 20px;
  height: 20px;
  margin-top: -10px;
  overflow: visible;
  opacity: 0;
  transform-origin: 10px 10px;
}

.bag__tick path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

/* ---------------------------------------------------------------- the ruler: hidden, measures the type */
.ruler {
  position: absolute;
  left: 0;
  top: 0;
  visibility: hidden;
  pointer-events: none;
  white-space: nowrap;
  font-size: 18px;
  font-kerning: none;
}

.ruler span {
  display: inline-block;
  white-space: pre;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (hover: hover) {
  .bag:hover .bag__pill {
    background: var(--pill-on);
  }
}
