/* The 6-digit code (pages/verify-email.html :: otp; js/bg-otp.js): one real field, so paste and autofill land whole,
   under six quiet cells, two groups of three set apart by space alone; with what it says back, the resend and the
   confirmed seal. A page sets --otp-accent, --otp-ring and --otp-radius on an ancestor (the account pages: petrol; the
   app: gold). States on .otp: data-state="busy" (checking: a light wave runs across), "error" (a shake), "ok" (confirmed).
   Until drawn (.is-drawn) the plain field shows. */
.otp {
  --otp-tint: var(--otp-accent, var(--gold));
  --otp-line: color-mix(in srgb, var(--ink) 13%, transparent);
  --otp-line-strong: color-mix(in srgb, var(--ink) 26%, transparent);
  position: relative;
}
.otp input { width: 100%; height: 56px; padding: 0 14px; border: 1px solid var(--field-border); border-radius: var(--otp-radius, var(--r-lg));
  background: var(--bg-panel); font: inherit; font-size: 22px; letter-spacing: .4em; color: var(--ink); }
.otp input:focus { outline: 2px solid transparent; border-color: var(--otp-tint); box-shadow: var(--otp-ring, var(--focus-ring)); }
.otp.is-drawn input { position: absolute; inset: 0; z-index: 1; height: 100%; opacity: 0; border: 0; font-size: 16px; caret-color: transparent; cursor: text; }
.otp:not(.is-drawn) .otp__cells { display: none; }

/* the space between the two groups is the grid's own: two gaps around an empty column */
.otp__cells { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) 0 repeat(3, minmax(0, 1fr)); column-gap: 8px;
  pointer-events: none; }
.otp__gap { width: 0; }
.otp__cell { position: relative; display: grid; place-items: center; height: 56px; min-width: 0;
  border: 1px solid var(--otp-line); border-radius: var(--otp-radius, 12px);
  background: var(--bg-panel); box-shadow: 0 1px 2px rgba(var(--shadow-rgb, 15, 23, 42), .05);
  font-family: var(--font-sans); font-size: 24px; font-weight: 500; line-height: 1; font-variant-numeric: tabular-nums; color: var(--ink);
  transition: border-color .18s var(--ease-out), box-shadow .18s var(--ease-out), background-color .18s var(--ease-out), color .18s var(--ease-out); }
/* an empty slot: a faint dot, until the caret reaches it */
.otp__cell:empty::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--otp-line-strong); opacity: .7; }
.otp__cell.is-filled { border-color: var(--otp-line-strong); animation: otp-digit .2s var(--ease-out); }
@keyframes otp-digit { from { transform: scale(.95); } }

/* the cell the next digit goes in; none while the code is out (checking) or done */
.otp:not([data-state="busy"], [data-state="ok"]):focus-within .otp__cell.is-active { border-color: var(--otp-tint);
  box-shadow: var(--otp-ring, 0 0 0 3px color-mix(in srgb, var(--otp-tint) 20%, transparent)); }
.otp:focus-within .otp__cell.is-active:empty::before { content: none; }
.otp:focus-within .otp__cell.is-active:empty::after { content: ""; width: 2px; height: 24px; border-radius: 1px; background: var(--otp-tint);
  animation: otp-caret 1.1s var(--ease-standard, ease-in-out) infinite; }
@keyframes otp-caret { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* checking: the digits rest, and a light wave runs across the cells until the answer */
.otp[data-state="busy"] .otp__cell { color: color-mix(in srgb, var(--ink) 60%, transparent); box-shadow: none;
  animation: otp-wave 1.2s var(--ease-standard, ease-in-out) infinite; }
.otp[data-state="busy"] .otp__cell:nth-child(2) { animation-delay: .08s; }
.otp[data-state="busy"] .otp__cell:nth-child(3) { animation-delay: .16s; }
.otp[data-state="busy"] .otp__cell:nth-child(5) { animation-delay: .24s; }
.otp[data-state="busy"] .otp__cell:nth-child(6) { animation-delay: .32s; }
.otp[data-state="busy"] .otp__cell:nth-child(7) { animation-delay: .40s; }
@keyframes otp-wave {
  0%, 70%, 100% { border-color: var(--otp-line); background-color: var(--bg-panel); }
  35% { border-color: color-mix(in srgb, var(--otp-tint) 55%, transparent); background-color: color-mix(in srgb, var(--otp-tint) 7%, var(--bg-panel)); }
}

/* wrong: said in red, with a short shake */
.otp[data-state="error"] .otp__cell { border-color: color-mix(in srgb, var(--overdue-fg) 70%, transparent);
  background: color-mix(in srgb, var(--overdue-fg) 4%, var(--bg-panel)); color: var(--overdue-fg); }
.otp[data-state="error"] .otp__cells { animation: otp-shake .34s var(--ease-out); }
@keyframes otp-shake { 20% { translate: -5px 0; } 45% { translate: 4px 0; } 70% { translate: -2px 0; } }

/* right: the digits stay as typed, the cells take a green edge a moment before what follows */
.otp[data-state="ok"] .otp__cell { border-color: color-mix(in srgb, var(--paid-fg) 55%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--paid-fg) 12%, transparent); color: var(--ink); }

/* drawn, the sixth digit sends the code: its submit is for no script */
.otp__submit { margin-top: 14px; }
:has(> .otp.is-drawn) > .otp__submit { display: none; }

/* what the code step says back, under the cells */
.otp__status { display: flex; align-items: center; gap: var(--icon-gap-sm); min-height: 22px; margin-top: 12px; font-size: 13px; color: var(--text-muted); }
.otp__status:empty { min-height: 0; margin-top: 0; }
.otp__status svg { flex: none; }
.otp__status--error { color: var(--overdue-fg); }
.otp__status--ok { color: var(--paid-fg); }
.otp__spinner { color: var(--otp-accent, var(--gold)); animation: bg-spin .9s linear infinite; }

/* "Not there? Check spam, or send a new code", counting down (BgOtp.countdown) */
.otp__resend { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: var(--space-1); margin: 18px 0 0; font-size: 13px;
  color: var(--text-muted); text-align: center; }
.otp__resend-link { min-height: var(--tap-min); padding: 0; border: 0; background: none; font: inherit; font-weight: 600;
  color: var(--otp-accent, var(--gold)); cursor: pointer; text-underline-offset: 3px; font-variant-numeric: tabular-nums; }
.otp__resend-link:hover:not(:disabled) { text-decoration: underline; }
.otp__resend-link:disabled { color: var(--text-muted); font-weight: 500; cursor: default; }

/* confirmed */
.otp__seal { display: grid; place-items: center; width: 56px; height: 56px; border-radius: var(--r-xl); background: var(--paid-bg); color: var(--paid-fg); }

@media (max-width: 860px) {
  .otp__cells { column-gap: 6px; }
  .otp__cell { height: 52px; font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  .otp__cell, .otp__cells, .otp__spinner, .otp:focus-within .otp__cell.is-active:empty::after,
  .otp[data-state="busy"] .otp__cell { animation: none; }
}
