/* The toffee sweetness slider: a patisserie's sweetness on a white page. The caramel goes from a burnt, bitter
   brown to a pale blond toffee as it gets sweeter, through the five colours below; the script reads every colour
   of the paper, the caramel and the shine from here. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #2b1a11;           /* the label, the focus ring */
  --muted: #a08f80;         /* the note and the two ends of the scale */
  --paper: #f7f1e6;         /* the strip of baking paper */
  --paper-edge: #e6d9c3;    /* its edges */
  --tick: #ddcbae;          /* the marks printed on the paper */
  --caramel-bitter: #4a2213; /* the caramel at its most bitter */
  --caramel-dark: #7b3914;
  --caramel: #b45d18;
  --caramel-golden: #d88a2b;
  --caramel-blond: #eab25a; /* the caramel at its sweetest */
  --cream: #fde9c4;         /* the swirl of cream in the toffee ball */
  --shine: #fffaf0;         /* the reflections */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

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

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

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

/* ---------------------------------------------------------------- the label and the note */
.sweet__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.sweet__label {
  font-size: 15px;
  font-weight: 620;
  font-variation-settings: 'opsz' 14, 'SOFT' 50;
  letter-spacing: 0.005em;
}

/* the note says what that sweetness tastes of; it changes with a short fade */
.sweet__note {
  display: block;
  color: var(--muted);
  font-size: 13.5px;
  font-style: normal;
  font-weight: 420;
  font-variation-settings: 'opsz' 12, 'SOFT' 100;
  white-space: nowrap;
}

.sweet__note-text {
  display: block;
}

/* ---------------------------------------------------------------- the word */
/* the script moves the weight and the SOFT axis with the knob, so the word gets rounder and fatter, like softer
   toffee, the sweeter it is; from Sweet on the WONK axis lets the letters lean. Each letter is a span of its own,
   for the drip when the word changes */
.sweet__word {
  display: flex;
  align-items: baseline;
  height: 62px;
  margin: 2px 0 0;
  font-size: 50px;
  line-height: 1.12;
  font-weight: 520;
  font-variation-settings: 'opsz' 72, 'SOFT' 40, 'WONK' 0;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.sweet__letter {
  display: inline-block;
  will-change: transform;
}

/* ---------------------------------------------------------------- the paper, the caramel and the ball */
.sweet__track {
  position: relative;
  height: 80px;
  touch-action: pan-y;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* the canvas runs past the track on both sides, for the dollop at the start and the ball at the end */
.sweet__canvas {
  position: absolute;
  left: -16px;
  top: 0;
  width: calc(100% + 32px);
  height: 100%;
  pointer-events: none;
}

/* the real slider: invisible, out of the pointer's way, but it takes the focus, the keys and the screen reader */
.sweet__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) {
  .sweet__track.is-near {
    cursor: grab;
  }
}

.sweet.is-held .sweet__track {
  cursor: grabbing;
}

/* ---------------------------------------------------------------- the two ends */
.sweet__scale {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 460;
  font-variation-settings: 'opsz' 12, 'SOFT' 100;
}

@media (max-width: 480px) {
  .sweet__word {
    height: 56px;
    font-size: 44px;
  }
}
