/* The desk fan switch: a pill with a white knob, and the knob is the fan. The blades and the ribbons are drawn on two
   canvases with the colours below. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #121419;           /* the words */
  --track: #e5e7eb;         /* the track, off */
  --air: #1f86e8;           /* the track, on: the air the fan blows */
  --ribbon: #ffffff;        /* the ribbons, the face towards you */
  --ribbon-back: #cfe4f8;   /* the ribbons, the back of the paper where they turn over */
  --blade: #b6bec9;         /* the blades standing still */
  --blade-on: #8fc1f1;      /* the blades running, blurred into a disc */
  --hub: #7d8796;           /* the middle of the fan */
  --knob: #ffffff;          /* the knob */
  --focus: #1f86e8;         /* 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(--ink);
  font-family: 'Rethink Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.fan {
  display: inline-flex;
  align-items: center;
  gap: 20px;
}

.fan__label {
  font-size: 19px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------------------------------------------------------------- the track */
.fan__switch {
  position: relative;
  flex: none;
  width: 156px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--track);
  cursor: pointer;
  overflow: hidden;
  isolation: isolate;
  /* a finger dragged across moves the knob; up and down the page still scrolls */
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

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

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

/* the colour of the air: its opacity follows the knob along the track */
.fan__fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--air);
  opacity: 0;
}

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

/* the ribbons as they were, fading away over the new ones when the motion is reduced */
.fan__was {
  opacity: 0;
}

/* the track is a little sunk into the page, over the ribbons too */
.fan__shade {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow:
    inset 0 1px 2px rgba(0, 0, 0, 0.15),
    inset 0 0 0 0.5px rgba(0, 0, 0, 0.06);
  pointer-events: none;
}

/* ---------------------------------------------------------------- the knob */
/* two boxes: the knob runs along the track, the puck inside it squashes against the end and shrinks under a finger */
.fan__knob {
  position: absolute;
  left: 0;
  top: 3px;
  width: 50px;
  height: 50px;
  pointer-events: none;
}

.fan__puck {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0) 60%),
    var(--knob);
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.05),
    0 1px 1px rgba(0, 0, 0, 0.08),
    0 3px 8px rgba(0, 0, 0, 0.15),
    inset 0 -1px 1px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.4s ease;
}

/* on the coloured track the knob's shadow takes the colour, deeper, instead of a dirty grey */
.fan__switch[aria-checked='true'] .fan__puck {
  box-shadow:
    0 0 0 0.5px color-mix(in srgb, color-mix(in srgb, var(--air), #000 50%) 30%, transparent),
    0 1px 1px color-mix(in srgb, color-mix(in srgb, var(--air), #000 60%) 35%, transparent),
    0 3px 9px color-mix(in srgb, color-mix(in srgb, var(--air), #000 55%) 50%, transparent),
    inset 0 -1px 1px rgba(0, 0, 0, 0.05);
}

.fan__rotor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
