/* The Galton board forecast: a revenue forecast as beads falling through brass pins behind glass, alone on a black
   page, with the words and the pill under it. The board is painted by script.js on the canvas with the colours
   below. */
:root {
  --page: #000000;          /* the page */
  --ink: #f2f0ea;           /* the words */
  --muted: #8a8e95;         /* the quiet words */
  --ok: #5fe3b0;            /* forecast ready */
  --error: #ff6a5c;         /* the data source timed out */
  --panel: #0c1016;         /* the board behind the glass */
  --panel-edge: #1f252e;    /* the board's rim */
  --brass: #c9a066;         /* the pins, the gate and the bins */
  --glow: #ffc96b;          /* a pin struck by a bead */
  --bead: #dfe5ee;          /* the steel beads */
  --curve: #7cf0c8;         /* the bell drawn at the end, and the beads inside the 90% range */
  --button: #f2f0ea;        /* the main pill */
  --button-ink: #0b0b0c;    /* its words */
  --line: #34383e;          /* the ring round the quiet pill */
  --focus: #ffb35c;         /* the keyboard's focus ring */
}

* {
  box-sizing: border-box;
}

/* a tap is a click at once: no wait for a double tap, no zoom */
html {
  touch-action: manipulation;
}

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

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Archivo Variable', system-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;
  padding: 40px 16px;
}

/* ---------------------------------------------------------------- the forecast */
.fc {
  display: grid;
  width: min(320px, 100%);
}

/* the board: 236 by 266 units */
.fc__board {
  position: relative;
}

.fc__canvas {
  display: block;
  width: 100%;
  aspect-ratio: 236 / 266;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}

.fc__canvas.is-knock {
  cursor: pointer;
}

/* the scale under the bins, inside the glass: script.js writes the three values */
.fc__axis {
  position: absolute;
  inset: auto 0 1.6% 0;
  height: 14px;
  margin: 0;
  pointer-events: none;
}

.fc__tick-label {
  position: absolute;
  top: 0;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  line-height: 14px;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* the three labels sit under the left edge, the middle and the right edge of the bins */
.fc__tick-label[data-axis='0'] {
  left: 4.24%;
}

.fc__tick-label[data-axis='1'] {
  left: 50%;
  transform: translateX(-50%);
}

.fc__tick-label[data-axis='2'] {
  right: 4.24%;
}

/* ---------------------------------------------------------------- the words */
.fc__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding: 0 4px;
}

.fc__words {
  min-width: 0;
}

.fc__title,
.fc__meta {
  margin: 0;
  white-space: nowrap;
}

.fc__title {
  font-size: 19px;
  font-weight: 600;
  line-height: 24px;
  letter-spacing: -0.02em;
}

.fc__meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 450;
  line-height: 18px;
  font-variant-numeric: tabular-nums;
}

.fc__swap {
  display: inline-block;
}

.fc[data-mode='failed'] .fc__title {
  color: var(--error);
}

.fc[data-mode='done'] .fc__title {
  color: var(--ok);
}

/* the percentage, and the tick that takes its place at the end */
.fc__figure {
  position: relative;
  flex: none;
  display: grid;
  place-items: center end;
  min-width: 56px;
  height: 30px;
  margin: 0;
}

.fc__pct {
  grid-area: 1 / 1;
  font-size: 27px;
  font-weight: 500;
  line-height: 30px;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}

.fc[data-mode='failed'] .fc__pct {
  color: var(--error);
}

.fc__done {
  grid-area: 1 / 1;
  width: 30px;
  height: 30px;
  fill: none;
  stroke: var(--ok);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
}

/* ---------------------------------------------------------------- the pill */
/* the fill is a layer of its own that swells past the edge with a bounce, and the words widen on the width axis of
   the font; pressed, the pill squashes a little */
.pill {
  position: relative;
  justify-self: stretch;
  display: grid;
  place-items: center;
  height: 48px;
  margin-top: 18px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--button-ink);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.005em;
  white-space: nowrap;
  cursor: pointer;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  transition: color 0.25s ease;
}

.pill::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--button);
  transition: inset 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.3s ease, box-shadow 0.3s ease;
}

.pill__label {
  display: inline-block;
  font-stretch: 92%;
  font-variant-numeric: tabular-nums;
  transition: font-stretch 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* while it works the pill goes quiet */
.pill.is-quiet {
  color: var(--muted);
  cursor: default;
}

.pill.is-quiet::before {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--line);
}

@media (hover: hover) and (pointer: fine) {
  .pill:not(.is-quiet):hover::before {
    inset: -3px -5px;
  }

  .pill:not(.is-quiet):hover .pill__label {
    font-stretch: 108%;
  }
}

.pill:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .pill::before,
  .pill__label {
    transition: none;
  }
}
