/* The metronome slider: the tempo field of a practice app on a white page, in the minimal style. A metronome in
   hairlines, one vermilion accent (the ticks, the weight's edge and the knob) and a big figure in Roboto Flex that
   grows wider with the tempo. The script reads the colours of the track from here. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #161616;           /* the figure, the rod, the knob's ring */
  --line: #c9c5be;          /* the case, the marks, the track */
  --muted: #8f8a83;         /* BPM, the tempo's name, the scale's words */
  --accent: #ff4b1f;        /* the ticks, the weight's edge, the knob */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Roboto Flex Variable', 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.tempo {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------------------------------------------------------------- the metronome */
.tempo__metro {
  display: block;
  width: min(236px, 36vh, 58vw);
  aspect-ratio: 200 / 220;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-radius: 14px;
}

.tempo__metro:focus-visible {
  outline: 1.5px solid var(--ink);
  outline-offset: 6px;
}

.metro {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.metro__case,
.metro__foot,
.metro__face {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.1;
  stroke-linejoin: round;
}

.metro__face {
  stroke-width: 0.8;
}

.metro__marks line {
  stroke: var(--line);
  stroke-width: 0.8;
}

.metro__rod {
  stroke: var(--ink);
  stroke-width: 1.2;
  stroke-linecap: round;
}

.metro__weight {
  fill: var(--page);
  stroke: var(--accent);
  stroke-width: 1.3;
  stroke-linejoin: round;
}

.metro__shine {
  fill: var(--accent);
  opacity: 0.16;
}

.metro__pivot {
  fill: var(--page);
  stroke: var(--ink);
  stroke-width: 1.2;
}

.metro__arc {
  fill: none;
  stroke: var(--line);
  stroke-width: 0.6;
  opacity: 0.55;
}

.metro__tick {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linecap: round;
  opacity: 0;
}

/* ---------------------------------------------------------------- the figure */
.tempo__read {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  margin-top: clamp(10px, 2.4vh, 22px);
  height: clamp(56px, 11vh, 80px);
}

/* the figure is a row of digit columns: each column slides its digits up or down when the number changes */
.tempo__num {
  display: flex;
  margin: 0;
  height: 100%;
  font-size: clamp(56px, 11vh, 80px);
  line-height: 1;
  font-weight: 600;
  font-stretch: 70%;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.digit {
  position: relative;
  display: block;
  height: 1em;
  overflow: hidden;
  /* the digits come in from white and go out into it: only the one in the middle is sharp */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14%, #000 86%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 14%, #000 86%, transparent 100%);
}

.digit__glyph {
  position: absolute;
  inset: 0;
  display: block;
  text-align: center;
  will-change: transform, opacity;
}

.tempo__side {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 0.4em;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tempo__unit {
  color: var(--ink);
  font-weight: 620;
  font-stretch: 112%;
}

.tempo__name {
  display: block;
  overflow: hidden;
  height: 1.3em;
  color: var(--muted);
  font-weight: 460;
  font-stretch: 96%;
  letter-spacing: 0.04em;
  text-transform: none;
  font-style: italic;
  font-size: 13px;
}

.tempo__name-text {
  display: block;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- the track */
.tempo__track {
  position: relative;
  width: 100%;
  height: 58px;
  margin-top: clamp(4px, 1.4vh, 12px);
  touch-action: pan-y;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.track {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.track__rail {
  stroke: var(--line);
  stroke-width: 1;
}

.track__done {
  stroke: var(--ink);
  stroke-width: 1.2;
}

.track__mark {
  stroke: var(--line);
  stroke-width: 1;
}

.track__mark.is-past {
  stroke: var(--ink);
}

.track__word {
  fill: var(--muted);
  font-size: 10.5px;
  font-weight: 460;
  font-style: italic;
  letter-spacing: 0.02em;
}

.track__knob {
  fill: var(--accent);
}

.track__ring {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.2;
  opacity: 0;
}

/* the real slider: invisible and out of the pointer's way, but it takes the focus, the keys and the screen reader */
.tempo__range {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 1px;
  margin: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}

@media (hover: hover) {
  .tempo__track.is-near {
    cursor: grab;
  }
}

.tempo.is-held .tempo__track {
  cursor: grabbing;
}
