/* The verification code field: six boxes on a white page, a ring on the box being typed, a green pill when the code
   is right and red boxes when it is wrong. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #16171a;           /* the figures, the ring */
  --muted: #73757d;
  --box: #f3f2ef;           /* an empty box */
  --edge: #e2dfd8;          /* the edge of an empty box */
  --ok: #1f9d55;            /* right */
  --ok-soft: #e7f7ee;
  --no: #d9443f;            /* wrong */
  --size: 56px;             /* a box */
  --gap: 10px;
}

* {
  box-sizing: border-box;
}

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

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

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

.code {
  display: grid;
  justify-items: center;
  gap: 14px;
}

.code__label {
  font-size: 16px;
  font-weight: 560;
  color: var(--muted);
}

/* ---------------------------------------------------------------- the field */
.code__field {
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

/* the real input lies over the boxes, invisible: it takes the taps, the keys, the pastes and the codes from texts */
.code__input {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font-size: 16px;
  opacity: 0;
  cursor: text;
}

.code__boxes {
  position: relative;
  display: flex;
  gap: var(--gap);
}

.code__box {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--size);
  height: calc(var(--size) * 1.2);
  border-radius: 14px;
  background: var(--box);
  box-shadow: inset 0 0 0 1.5px var(--edge);
  font-size: calc(var(--size) * 0.54);
  font-weight: 620;
  font-variant-numeric: tabular-nums;
  transition: background-color 0.25s ease, box-shadow 0.25s ease;
}

.code__box.is-full {
  background: #ffffff;
  box-shadow: inset 0 0 0 1.5px #c9c5bc, 0 6px 14px -10px rgba(0, 0, 0, 0.35);
}

.code__field.is-wrong .code__box {
  background: #fdf0ef;
  box-shadow: inset 0 0 0 1.5px var(--no);
  color: var(--no);
}

/* the ring on the box being typed, with its caret when the box is empty */
.code__ring {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  width: var(--size);
  height: calc(var(--size) * 1.2);
  border-radius: 14px;
  box-shadow: 0 0 0 2px var(--ink), 0 0 0 6px rgba(22, 23, 26, 0.08);
  opacity: 0;
  pointer-events: none;
}

.code__caret {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 42%;
  margin: -21% 0 0 -1px;
  border-radius: 1px;
  background: var(--ink);
  animation: blink 1.05s steps(1) infinite;
}

.code__ring.is-full .code__caret {
  display: none;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* the green pill the boxes melt into */
.code__done {
  position: absolute;
  left: 50%;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 100%;
  padding: 0 28px;
  border-radius: 999px;
  background: var(--ok-soft);
  box-shadow: inset 0 0 0 1.5px var(--ok);
  color: var(--ok);
  font-size: 20px;
  font-weight: 650;
  white-space: nowrap;
  opacity: 0;
  translate: -50% 0;
  pointer-events: none;
}

.code__done svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.code__status {
  min-height: 1.4em;
  margin: 2px 0 0;
  font-size: 15px;
  color: var(--muted);
}

.code__status.is-ok {
  color: var(--ok);
}

.code__status.is-no {
  color: var(--no);
}

/* ---------------------------------------------------------------- the switch for the demo */
.fail {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.fail input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.fail__box {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1.5px #b9b6ae;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.fail__box svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.6, 0.5, 1);
}

.fail input:checked + .fail__box {
  background: var(--no);
  box-shadow: none;
}

.fail input:checked + .fail__box svg {
  opacity: 1;
  transform: none;
}

.fail input:focus-visible + .fail__box {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

@media (max-width: 440px) {
  :root {
    --size: 48px;
    --gap: 8px;
  }
}
