/* The tape measure slider: a table's length on a white page. An oak table drawn from the front with its dimension
   line, and under it a yellow tape measure with a black rubber grip, chrome clip and mouth, a red lock slider and a
   brass hook at the end of the printed yellow steel. The drawing takes its colours from here. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #1f1c18;           /* the length, the words and the focus ring */
  --muted: #7d766b;         /* the quiet words */
  --hair: #e6e1d8;          /* the outlines of the chips and the lock */
  --dim: #9a9286;           /* the dimension line, the range and the guide down to the hook */
  --floor: #ddd6ca;         /* the floor under the table */
  --oak: #d4a067;           /* the oak of the table */
  --oak-light: #eac795;     /* its lit edge */
  --oak-dark: #a46c39;      /* its shaded side */
  --shell: #f6b81f;         /* the case */
  --shell-light: #ffdb5e;   /* the case where the light falls */
  --shell-dark: #d68c05;    /* the case in its own shadow */
  --rubber: #2a2c30;        /* the rubber grip */
  --chrome: #dfe3e8;        /* the belt clip and the mouth */
  --slider: #d63b2c;        /* the lock slider, and the word on when the lock is on */
  --tape: #f7d84f;          /* the steel tape's yellow coating */
  --print: #1c1a17;         /* the tape's black print */
  --mark: #d42c22;          /* the tape's red decimetre marks and the window's hairline */
  --brass: #d8ab50;         /* the hook */
  --focus: #2f6bff;         /* the focus rings */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

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

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

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 32px 16px;
}

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

/* ---------------------------------------------------------------- the drawing */
.tm__rig {
  position: relative;
}

.tm__art {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  pointer-events: none;
}

/* the length on the dimension line: it is the slider's readout */
.tm__readout {
  font-family: 'Archivo Variable', system-ui, sans-serif;
  font-size: 19px;
  font-weight: 680;
  font-stretch: 94%;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.tm__readunit {
  fill: var(--muted);
  font-size: 14px;
  font-weight: 560;
  font-stretch: 100%;
  letter-spacing: 0;
}

/* the tape's print: condensed numerals, as on the steel */
.tm__tapenum {
  font-family: 'Archivo Variable', system-ui, sans-serif;
  font-stretch: 66%;
  font-weight: 680;
  font-variant-numeric: tabular-nums;
}

.tm__rangetext {
  font-family: 'Archivo Variable', system-ui, sans-serif;
  font-size: 10px;
  font-weight: 560;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* the lock slider in the drawing can be pressed too */
.tm__slidehit {
  pointer-events: all;
  cursor: pointer;
}

/* the handle over the hook: empty, but it has the focus ring and takes the drag. No scrolling on it: a finger drags */
.tm__hook {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--hw, 48px);
  height: var(--hh, 60px);
  margin: calc(var(--hh, 60px) / -2) 0 0 calc(var(--hw, 48px) / -2);
  border-radius: 12px;
  cursor: grab;
  outline: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.2s;
}

.tm__hook:focus-visible {
  box-shadow: 0 0 0 2px var(--page), 0 0 0 4.5px var(--focus);
}

/* taken with the pointer, it is focused for the keys but shows no ring until one is pressed */
.tm__hook.is-pointer:focus-visible {
  box-shadow: none;
}

.tm.is-dragging,
.tm.is-dragging .tm__hook {
  cursor: grabbing;
}

/* ---------------------------------------------------------------- the lock and the presets */
.tm__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 14px;
  margin-top: 10px;
}

.tm__lockrow {
  display: grid;
  justify-items: start;
  gap: 5px;
  min-width: 0;
}

.tm__lock {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px 7px 10px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: var(--page);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 620;
  line-height: 1.1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s, border-color 0.2s, transform 0.15s;
}

@media (hover: hover) {
  .tm__lock:hover {
    border-color: #d6cfc3;
    background: #faf8f4;
  }
}

.tm__lock:active {
  transform: translateY(1px);
}

.tm__lock:focus-visible,
.tm__chip:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.tm__padlock {
  width: 17px;
  height: 17px;
  overflow: visible;
}

.tm__shackle {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.9;
  stroke-linecap: round;
  transform-box: view-box;
  transform-origin: 13.8px 9px;
  transition: transform 0.3s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.tm__body {
  fill: var(--ink);
}

.tm__keyhole {
  fill: none;
  stroke: var(--page);
  stroke-width: 1.8;
  stroke-linecap: round;
}

.tm[data-lock='off'] .tm__shackle {
  transform: translateY(-2.2px) rotate(26deg);
}

/* the state in a word: red when the lock holds the tape */
.tm__badge {
  min-width: 2.2em;
  color: var(--slider);
  font-size: 12px;
  font-weight: 720;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  transition: color 0.25s;
}

.tm[data-lock='off'] .tm__badge {
  color: var(--muted);
}

.tm__hint {
  padding-left: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.tm__presets {
  display: flex;
  gap: 6px;
}

.tm__chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 7px 12px 7px 11px;
  border: 1px solid var(--hair);
  border-radius: 12px;
  background: var(--page);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 640;
  line-height: 1.15;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s, transform 0.15s;
}

.tm__cm {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 520;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s;
}

@media (hover: hover) {
  .tm__chip:hover {
    border-color: #d6cfc3;
    background: #faf8f4;
  }
}

.tm__chip:active {
  transform: translateY(1px);
}

/* the chip whose length the tape shows */
.tm__chip[data-on] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--page);
}

.tm__chip[data-on] .tm__cm {
  color: rgba(255, 255, 255, 0.66);
}

@media (max-width: 440px) {
  .tm__controls {
    flex-direction: column;
    align-items: stretch;
  }

  .tm__lockrow {
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 10px;
  }

  .tm__presets {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tm__chip {
    align-items: center;
    padding: 8px 6px;
  }
}
