/* The rotary dial code field: six code boxes on a white page and under them a 1960s telephone dial in sage enamel,
   with a cream number card, a clear finger wheel, a chrome finger stop and a printed centre card. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #1d221e;           /* the digits and the words */
  --muted: #6b726c;         /* the quiet buttons */
  --box: #f5f4f0;           /* an empty code box */
  --box-full: #ffffff;      /* a code box with its digit */
  --box-line: #dedbd2;      /* the edge of a box */
  --box-next: #8f958b;      /* the edge of the box the next digit goes into */
  --box-filled: #b9bdb3;    /* the edge once a digit is in */
  --focus: #2d6a5c;         /* the focus rings */
  --accent: #e39a2d;        /* the pulse ticks and the hole being dialled */
  --ok: #2c8556;            /* verified */
  --ok-soft: #ecf6ef;       /* a verified box */
  --ok-ink: #1d5e3b;        /* a verified digit */
  --base: #a9bfa3;          /* the dial's enamelled base, sage */
  --base-hi: #d6e3d0;       /* where the light falls on it */
  --base-lo: #7d9677;       /* where it turns away */
  --well: #9db495;          /* the well the wheel turns in */
  --well-lo: #7b9474;       /* the well's shadowed edge */
  --card: #f3eedf;          /* the number card, cream */
  --card-ink: #262823;      /* the numerals on it */
  --card-line: #9aa592;     /* the rings printed on it */
  --card-letters: #7e857a;  /* the small letters above the numerals */
  --label-ink: #5e665f;     /* the small words on the centre card */
  --wheel: #8fb3a6;         /* the finger wheel's clear plastic, a cool mint tint */
  --wheel-edge: #4f6e60;    /* its edge, where the plastic is seen through its thickness */
  --rule: #b8553d;          /* the red rule on the centre card */
  --shadow: #2b3a28;        /* the shadows, a deep green-grey */
}

* {
  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: 'Archivo 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: 40px 16px;
}

/* the dial is as wide as the phone's screen and at most 380; short screens keep room for the boxes above it. The
   boxes share the dial's width, whatever the number of digits (the script writes --n) */
.rd {
  --d: min(380px, calc(100vw - 32px), max(280px, calc(100svh - 250px)));
  --bw: min(52px, calc((var(--d) - (var(--n, 6) - 1) * 8px - 16px) / var(--n, 6)));
  display: grid;
  justify-items: center;
  width: var(--d);
}

/* ---------------------------------------------------------------- the boxes */
.rd__boxes {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rd__box {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--bw);
  height: calc(var(--bw) * 1.2);
  border-radius: calc(var(--bw) * 0.22);
  background: var(--box);
  overflow: hidden;
  box-shadow: inset 0 0 0 1.5px var(--box-line);
  transition: box-shadow 0.3s ease, background-color 0.4s ease;
}

.rd__digit {
  display: block;
  font-size: calc(var(--bw) * 0.56);
  font-weight: 600;
  font-stretch: 100%;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  transition: color 0.4s ease;
}

/* the box the next digit will drop into: a short bar where it will sit */
.rd__caret {
  position: absolute;
  left: 50%;
  bottom: 22%;
  width: 34%;
  height: 2px;
  border-radius: 2px;
  background: var(--ink);
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity 0.25s, background-color 0.25s;
}

.rd__box[data-state='next'] {
  background: var(--box-full);
  box-shadow: inset 0 0 0 1.5px var(--box-next);
}

.rd__box[data-state='next'] .rd__caret {
  opacity: 0.22;
}

/* with the dial focused, the bar blinks like a caret: typing goes there */
.rd[data-focus] .rd__box[data-state='next'] .rd__caret {
  animation: rd-blink 1.1s steps(1) infinite;
}

@keyframes rd-blink {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 0.1; }
}

/* while the wheel runs home with a digit for this box, the bar stays still in the colour of the ticks */
.rd__box.is-coming .rd__caret,
.rd[data-focus] .rd__box.is-coming .rd__caret {
  background: var(--accent);
  opacity: 1;
  animation: none;
}

.rd__box[data-state='filled'] {
  background: var(--box-full);
  box-shadow: inset 0 0 0 1.5px var(--box-filled), 0 6px 12px -10px rgba(43, 58, 40, 0.45);
}

.rd__gap {
  flex: none;
  width: 10px;
  height: 2px;
  margin: 0 3px;
  border-radius: 2px;
  background: var(--box-filled);
}

.rd[data-state='checking'] .rd__box {
  box-shadow: inset 0 0 0 1.5px var(--box-filled);
}

.rd[data-state='ok'] .rd__box {
  background: var(--ok-soft);
  box-shadow: inset 0 0 0 1.5px var(--ok);
}

.rd[data-state='ok'] .rd__digit {
  color: var(--ok-ink);
}

/* ---------------------------------------------------------------- the dial */
.rd__dial {
  position: relative;
  width: var(--d);
  aspect-ratio: 1;
  margin-top: 28px;
  border-radius: 50%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

/* the wheel repaints alone while it turns */
.rd__art--wheel {
  will-change: transform;
}

/* 16px, or a phone zooms in when it gets the focus */
.rd__input {
  left: 50%;
  top: 50%;
  font-size: 16px;
}

/* the focus of the keys: a ring round the dial */
.rd__dial::after {
  content: '';
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  box-shadow: 0 0 0 2.5px var(--focus);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.rd[data-focus='keys'] .rd__dial::after {
  opacity: 1;
}

.rd[data-state='checking'] .rd__dial,
.rd[data-state='ok'] .rd__dial {
  cursor: default;
}

/* ---------------------------------------------------------------- the drawing */
.rd__numeral {
  fill: var(--card-ink);
  font-size: 22px;
  font-weight: 560;
  font-stretch: 104%;
  text-anchor: middle;
}

.rd__letters {
  fill: var(--card-letters);
  font-size: 6.4px;
  font-weight: 650;
  font-stretch: 118%;
  letter-spacing: 0.14em;
  text-anchor: middle;
}

.rd__ring-hover {
  fill: none;
  stroke: var(--focus);
  stroke-width: 1.6;
  opacity: 0;
  transition: opacity 0.2s;
}

.rd__hole.is-hover .rd__ring-hover {
  opacity: 0.45;
}

.rd__ring-on {
  fill: var(--accent);
  fill-opacity: 0.14;
  stroke: var(--accent);
  stroke-width: 2.6;
}

.rd__lbl-big {
  fill: var(--ink);
  font-size: 17px;
  font-weight: 720;
  font-stretch: 125%;
  letter-spacing: 0.24em;
  text-anchor: middle;
}

.rd__lbl-small {
  fill: var(--label-ink);
  font-size: 10.5px;
  font-weight: 560;
  font-stretch: 108%;
  letter-spacing: 0.04em;
  text-anchor: middle;
}

.rd__lbl-ok {
  fill: var(--ok);
  font-size: 12.5px;
  font-weight: 700;
  font-stretch: 112%;
  letter-spacing: 0.06em;
  text-anchor: middle;
}

/* ---------------------------------------------------------------- the buttons */
.rd__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 6px;
  margin-top: 20px;
}

/* quiet buttons, each with its little drawing: pointed at, the message hops in as if it had just arrived, and the
   arrow of Clear turns back anticlockwise, the way the wheel goes home */
.rd__quiet {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px 0 11px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 560;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.2s, background-color 0.2s, opacity 0.25s, transform 0.18s cubic-bezier(0.3, 1.6, 0.5, 1);
  -webkit-tap-highlight-color: transparent;
}

.rd__icon {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.45s cubic-bezier(0.3, 1.7, 0.45, 1);
}

@media (hover: hover) {
  .rd__quiet:hover {
    background: var(--box);
    color: var(--ink);
  }

  .rd__quiet--sms:hover .rd__icon {
    transform: translateY(-2px) rotate(-8deg);
  }

  .rd__quiet--clear:hover .rd__icon {
    transform: rotate(-70deg);
  }
}

.rd__quiet:active {
  transform: scale(0.96);
}

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

.rd__quiet[aria-disabled='true'] {
  opacity: 0.42;
  cursor: default;
  pointer-events: none;
}
