/* The chili heat slider: a taqueria's spice level on a white page. The pepper ripens through the five chili colours
   below, from green to deep red; the script reads every colour from here. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #1a1512;           /* text, the focus ring */
  --muted: #9a918b;         /* the words not chosen */
  --rail: #f1ece7;          /* the rail the pepper lies on */
  --tick: #ddd5ce;          /* the marks of the heats not reached */
  --chili-green: #4f9a2c;   /* the pepper at the mildest */
  --chili-amber: #e7a21c;   /* ripening */
  --chili-orange: #f0581c;
  --chili-red: #d81f1f;
  --chili-deep: #a10e22;    /* the pepper at the hottest */
  --stalk: #3f7a23;         /* the stalk and its cap */
  --stalk-dark: #234d14;
  --flame-outer: #e8331b;   /* the flames, from the edge to the core */
  --flame: #ff8a1d;
  --flame-core: #ffd447;
  --sweat: #cdeaff;         /* the drops of sweat */
  --sweat-edge: #4ea6dc;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

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

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

.heat {
  width: min(460px, 100%);
  user-select: none;
  -webkit-user-select: none;
}

/* ---------------------------------------------------------------- the name and the heat */
.heat__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 2px;
}

.heat__label {
  font-size: 17px;
  font-weight: 620;
  font-stretch: 96%;
  letter-spacing: -0.005em;
}

/* the figure grows heavier and wider with the heat (the script moves both axes); the box is as wide as the widest,
   so nothing beside it moves */
.heat__value {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  min-width: 86px;
  font-variant-numeric: tabular-nums;
}

.heat__number {
  font-size: 30px;
  line-height: 1;
  font-weight: 400;
  font-stretch: 80%;
  letter-spacing: -0.02em;
}

.heat__of {
  margin-left: 2px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 560;
}

/* ---------------------------------------------------------------- the rail and the pepper */
.heat__track {
  position: relative;
  height: 116px;
  touch-action: pan-y;
  outline: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* the canvas runs a little past the track on both sides, for the stalk's curl and the flames at the tip */
.heat__canvas {
  position: absolute;
  left: -14px;
  top: 0;
  width: calc(100% + 28px);
  height: 100%;
  pointer-events: none;
}

/* the grip sits round the pepper's tip: it only shows the keys' ring, and a soft ring under the mouse */
.heat__grip {
  position: absolute;
  left: -18px;
  top: -18px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  pointer-events: none;
}

.heat__grip::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--ink);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.18s, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@media (hover: hover) {
  .heat__track.is-near .heat__grip::after {
    opacity: 0.16;
    transform: scale(1);
  }

  .heat__track.is-near {
    cursor: grab;
  }
}

.heat__track:focus-visible .heat__grip::after {
  opacity: 1;
  transform: scale(1);
}

.is-held .heat__track {
  cursor: grabbing;
}

/* ---------------------------------------------------------------- the three words */
.heat__scale {
  position: relative;
  height: 24px;
  margin-top: -4px;
}

.heat__word {
  position: absolute;
  left: 0;
  top: 0;
  translate: -50% 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 520;
  font-stretch: 92%;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.3s, font-weight 0.35s, font-stretch 0.35s;
}

.heat__word.is-on {
  color: var(--ink);
  font-weight: 800;
  font-stretch: 118%;
}

.heat__word--top.is-on {
  color: var(--chili-deep);
}

@media (prefers-reduced-motion: reduce) {
  .heat__word,
  .heat__grip::after {
    transition: opacity 0.2s, color 0.2s;
  }
}
