/* The six-box code field (js/lib/otpInput.js). Loaded by that module only on pages that show a code box.
   The real <input> is stretched invisibly over the boxes, so taps, autofill and paste all land on it. */

.otp { position: relative; }
.otp .otp-input {
  position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; min-height: 0; margin: 0; padding: 0;
  opacity: 0; font-size: 16px; /* 16px: iOS doesn't zoom the page on focus */
  cursor: text; caret-color: transparent;
}
.otp-boxes { display: flex; gap: clamp(5px, 1.6vw, 9px); }
.otp-box:nth-child(3) { margin-right: clamp(4px, 1.6vw, 10px); }   /* 3 + 3, the way the apps show it */

.otp-box {
  position: relative; flex: 1 1 0; min-width: 0; max-width: 3.4rem; height: clamp(3.3rem, 15vw, 4rem);
  display: grid; place-items: center;
  font: 700 clamp(1.3rem, 6.2vw, 1.75rem)/1 var(--font-ui); font-variant-numeric: tabular-nums; color: var(--ink);
  background: var(--cream-2); border: 2px solid rgb(var(--ink-rgb) / .35); border-radius: 10px;
  box-shadow: 0 3px 0 rgb(var(--shade-rgb) / .22);
  transition: border-color var(--dur-2, .22s) var(--ease-out, ease), box-shadow var(--dur-2, .22s) var(--ease-out, ease),
              background-color var(--dur-2, .22s) var(--ease-out, ease), transform var(--dur-2, .22s) var(--ease-out, ease);
}
.otp-box.is-filled { border-color: rgb(var(--ink-rgb) / .6); }

/* where the next digit goes: a ring, and a caret that blinks */
.otp-box.is-active { border-color: var(--focus); box-shadow: 0 0 0 3px var(--focus), 0 3px 0 rgb(var(--shade-rgb) / .22); transform: translateY(-2px); }
.otp-box.is-active:not(.is-filled)::after {
  content: ""; width: 2px; height: 1.6rem; border-radius: 1px; background: var(--ink); animation: otp-caret 1.05s steps(1) infinite;
}
.otp-box.is-pop { animation: otp-pop .22s var(--ease-out, ease-out); }

/* waiting on the server: a quiet wave along the row */
.otp.is-busy .otp-box { animation: otp-wave 1s ease-in-out infinite; }
.otp.is-busy .otp-box:nth-child(2) { animation-delay: .08s; } .otp.is-busy .otp-box:nth-child(3) { animation-delay: .16s; }
.otp.is-busy .otp-box:nth-child(4) { animation-delay: .24s; } .otp.is-busy .otp-box:nth-child(5) { animation-delay: .32s; }
.otp.is-busy .otp-box:nth-child(6) { animation-delay: .4s; }

/* wrong: the row shakes once and goes red */
.otp.is-error .otp-boxes { animation: otp-shake .42s cubic-bezier(.36, .07, .19, .97); }
.otp.is-error .otp-box { border-color: var(--pen); color: var(--pen-deep); background: var(--pen-wash); box-shadow: 0 3px 0 rgb(var(--terra-rgb) / .35); transform: none; }

/* right: each box turns green in turn and lifts */
.otp.is-success .otp-box {
  border-color: var(--ok); color: var(--ok-text); background: var(--ok-wash); box-shadow: 0 3px 0 var(--ok);
  animation: otp-ok .5s var(--ease-out, ease-out) both;
}
.otp.is-success .otp-box:nth-child(1) { animation-delay: 0s; }   .otp.is-success .otp-box:nth-child(2) { animation-delay: .08s; }
.otp.is-success .otp-box:nth-child(3) { animation-delay: .16s; } .otp.is-success .otp-box:nth-child(4) { animation-delay: .24s; }
.otp.is-success .otp-box:nth-child(5) { animation-delay: .32s; } .otp.is-success .otp-box:nth-child(6) { animation-delay: .4s; }

@keyframes otp-caret { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0; } }
@keyframes otp-pop { 0% { transform: scale(.82); } 60% { transform: scale(1.07); } 100% { transform: scale(1); } }
@keyframes otp-wave { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes otp-shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-7px); } 40%, 60% { transform: translateX(7px); } }
@keyframes otp-ok { 0% { transform: translateY(0) scale(1); } 45% { transform: translateY(-8px) scale(1.08); } 100% { transform: translateY(0) scale(1); } }

@media (prefers-reduced-motion: reduce) {
  .otp-box, .otp-box.is-active { transition: none; transform: none; }
  .otp-box.is-active:not(.is-filled)::after { animation: none; }
  .otp-box.is-pop, .otp.is-busy .otp-box, .otp.is-error .otp-boxes, .otp.is-success .otp-box { animation: none; }
}
