/* The key lock button: a pin tumbler lock in section, drawn like a clean technical drawing inside a pale pill, on a
   white page. Steel and brass, hatched where they are cut; the script draws the moving parts. */
:root {
  --page: #ffffff;          /* the page */
  --paper: #f5f3ee;         /* the pill: the paper of the drawing */
  --ink: #23272e;           /* the outlines and the words */
  --steel: #e4e7eb;         /* the housing, cut */
  --hatch-steel: #9ea6b0;   /* its hatching */
  --brass: #efdcaa;         /* the plug, cut */
  --hatch-brass: #c09a55;   /* its hatching */
  --pin: #e2b75c;           /* the key pins, brass */
  --driver: #b9c1ca;        /* the driver pins, steel */
  --key: #d5dae0;           /* the key, nickel silver */
  --spring: #3b424c;        /* the springs */
  --line: #2f6bff;          /* the shear line, and the light that runs along it */
  --ok: #138a55;            /* signed in */
  --err: #d33a2c;           /* the wrong key */
  --muted: #7c818a;
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

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

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Geist Variable', system-ui, sans-serif;
  -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: 56px 16px;
}

/* every measure of the pill follows its width, so the drawing keeps its look at any size */
.lock {
  --w: min(400px, calc(100vw - 32px));
  --u: calc(var(--w) / 390);
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: 20px 0 6px;
}

.lock__btn {
  position: relative;
  display: block;
  width: var(--w);
  aspect-ratio: 390 / 120;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  overflow: hidden;
  outline: none;
  box-shadow:
    inset 0 0 0 1.5px var(--ink),
    inset 0 calc(var(--u) * 2) 0 rgba(255, 255, 255, 0.9),
    0 calc(var(--u) * 10) calc(var(--u) * 24) calc(var(--u) * -10) rgba(35, 39, 46, 0.35);
  transition: box-shadow 0.25s, background-color 0.25s, transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

@media (hover: hover) {
  .lock__btn:hover {
    background: #f1eee7;
    box-shadow:
      inset 0 0 0 1.5px var(--ink),
      inset 0 calc(var(--u) * 2) 0 rgba(255, 255, 255, 0.9),
      0 calc(var(--u) * 14) calc(var(--u) * 28) calc(var(--u) * -10) rgba(35, 39, 46, 0.42);
  }
}

.lock__btn:active {
  transform: translateY(1px) scale(0.995);
}

/* the focus of the keys: a ring round the pill */
.lock__btn:focus-visible {
  box-shadow:
    inset 0 0 0 1.5px var(--ink),
    0 0 0 3px var(--page),
    0 0 0 5.5px var(--line);
}

.lock__btn[aria-disabled='true'] {
  cursor: default;
}

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

/* the plug's cut face turns as a picture, about the plug's axis */
.lock__art--face {
  transform-origin: 50% 65%;
  will-change: transform;
}

/* the words, in the free end of the pill, right of the lock */
.lock__label {
  position: absolute;
  left: calc(var(--u) * 256);
  right: calc(var(--u) * 18);
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--u) * 7);
  font-size: calc(var(--u) * 20);
  font-weight: 620;
  letter-spacing: -0.01em;
  white-space: nowrap;
  pointer-events: none;
  transition: color 0.3s;
}

.lock__icon {
  flex: none;
  width: calc(var(--u) * 19);
  height: calc(var(--u) * 19);
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.lock[data-tone='ok'] .lock__label {
  color: var(--ok);
}

.lock[data-tone='err'] .lock__label {
  color: var(--err);
}

/* the second, quiet button: it tries a key that is cut wrong */
.lock__wrong {
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: rgba(124, 129, 138, 0.35);
  text-underline-offset: 3px;
  cursor: pointer;
  transition: color 0.2s, text-decoration-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .lock__wrong:hover {
    color: var(--ink);
    text-decoration-color: currentColor;
  }
}

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

.lock__wrong[aria-disabled='true'] {
  opacity: 0.45;
  cursor: default;
}

/* ---------------------------------------------------------------- the drawing */
.part {
  stroke: var(--ink);
  stroke-width: 1.1;
  stroke-linejoin: round;
}

.hole {
  fill: var(--paper);
}

.spring__front {
  fill: none;
  stroke: var(--spring);
  stroke-width: 1.25;
  stroke-linecap: round;
}

.spring__back {
  fill: none;
  stroke: var(--spring);
  stroke-width: 0.7;
  stroke-linecap: round;
  opacity: 0.45;
}

.shear {
  fill: none;
  stroke: var(--line);
  stroke-width: 0.9;
  stroke-dasharray: 9 2.5 1.5 2.5;
  opacity: 0.75;
}

.centre {
  fill: none;
  stroke: var(--ink);
  stroke-width: 0.5;
  stroke-dasharray: 7 2 1.2 2;
  opacity: 0.35;
}
