/* The yo-yo button: an ink pill on a white page, with a lacquered yo-yo in its round right end. The yo-yo and its
   string are drawn by script.js in an SVG (their colours come from here); the pill, the words and the states are
   CSS. */
:root {
  --page: #ffffff;          /* the page */
  --pill: #1f1d1b;          /* the pill, at its top */
  --pill-deep: #0e0d0c;     /* the pill, at its foot */
  --ink: #f6f1e7;           /* the words */
  --muted: #a39d92;         /* the small words */
  --lacquer: #e2412b;       /* the yo-yo's lacquer */
  --lacquer-deep: #8e1c10;  /* the lacquer in its shadow */
  --hub: #f4ead6;           /* the yo-yo's ivory cap */
  --mark: #1f1d1b;          /* the swirl printed on the cap */
  --string: #e9e1cf;        /* the cotton string */
  --focus: #e2412b;         /* 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: 'Instrument Sans Variable', 'Instrument 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: 48px 16px;
}

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

/* the unit holds the pill and, under its right end, the room the yo-yo drops into */
.yoyo__unit {
  position: relative;
  padding-bottom: 150px;
}

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

.yoyo__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 */
.yoyo__fill {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background:
    radial-gradient(90% 140% at 20% 0%, rgba(255, 255, 255, 0.09), 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.5),
    0 1px 2px rgba(20, 18, 16, 0.2),
    0 14px 28px -14px rgba(20, 18, 16, 0.6);
  transition:
    inset 0.6s cubic-bezier(0.34, 1.9, 0.45, 1),
    box-shadow 0.4s ease;
}

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

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

/* the yo-yo lives in the right end of the pill and drops below it; the pointer goes through it */
.yoyo__art {
  position: absolute;
  right: -20px;
  top: -10px;
  width: 100px;
  height: 250px;
  overflow: visible;
  pointer-events: none;
}

/* ---------------------------------------------------------------- the words */
/* three faces on top of each other, left of the yo-yo: at rest, while the stories load, and added */
.yoyo__faces {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 28px;
  right: 64px;
  pointer-events: none;
}

.yoyo__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;
  text-align: left;
  white-space: nowrap;
}

.yoyo__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 */
.yoyo__word {
  display: inline-grid;
  padding-bottom: 1px;
  font-size: 17.5px;
  font-weight: 560;
  font-stretch: 82%;
  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);
}

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

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

.yoyo__big {
  font-size: 16.5px;
  font-weight: 600;
  font-stretch: 88%;
  letter-spacing: -0.006em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- under the pointer */
@media (hover: hover) and (pointer: fine) {
  .yoyo__btn:not([aria-disabled='true']):hover .yoyo__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.5),
      0 1px 2px rgba(20, 18, 16, 0.2),
      0 18px 32px -14px rgba(20, 18, 16, 0.66);
  }

  .yoyo__btn:not([aria-disabled='true']):hover .yoyo__word {
    font-stretch: 100%;
    font-weight: 650;
  }
}

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

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

  html[data-using='keys'] .yoyo__btn:focus-visible:not([aria-disabled='true']) .yoyo__word {
    font-stretch: 82%;
    font-weight: 560;
  }
}

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

  .yoyo__btn:not([aria-disabled='true']):hover .yoyo__word {
    font-stretch: 82%;
    font-weight: 560;
  }
}
