/* Email code step on the sign-in page (js/login.js): shown after a correct password on
   every sign-in, and after sign-up to confirm the email. Six round boxes, an animated
   envelope, and feedback animations for typing, wrong codes and success. */

.otp-step {
  --otp-ok: #16a34a;
  --otp-error: #ef4444;
  text-align: center;
}
[data-theme='dark'] .otp-step {
  --otp-ok: #4ade80;
  --otp-error: #f87171;
}

/* Slides in from the right whenever the step opens. */
.otp-step.is-entering {
  animation: otp-step-in 0.45s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
@keyframes otp-step-in {
  from {
    opacity: 0;
    transform: translateX(28px);
  }
}

/* ── Header: back arrow + title, as in the reference screens ── */
.otp-top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
}
.otp-back {
  position: absolute;
  left: -0.35rem;
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text-main);
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    transform 0.15s ease;
}
.otp-back:hover {
  background: var(--option-hover, rgba(59, 130, 246, 0.12));
  transform: translateX(-2px);
}
.otp-back:focus-visible {
  outline: 2px solid var(--blue-light);
  outline-offset: 2px;
}
.otp-back svg {
  width: 1.4rem;
  height: 1.4rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.otp-title {
  margin: 0;
  color: var(--blue-main);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-transform: none;
}

/* ── Envelope: drops in, then floats; turns into a green check on success ── */
.otp-mail {
  display: grid;
  place-items: center;
  width: 5.5rem;
  height: 5.5rem;
  margin: 1.1rem auto 0.9rem;
  border-radius: 50%;
  background: color-mix(in srgb, var(--blue-main) 12%, transparent);
  transition: background-color 0.35s ease;
}
.otp-mail-icon {
  width: 3.4rem;
  height: 3.4rem;
  overflow: visible;
  fill: none;
  stroke: var(--blue-main);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: otp-mail-float 2.6s ease-in-out 0.6s infinite;
}
.is-entering .otp-mail-icon {
  animation:
    otp-mail-drop 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.4) both,
    otp-mail-float 2.6s ease-in-out 0.6s infinite;
}
.otp-mail-envelope {
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
  transform-origin: 50% 50%;
}
.otp-mail-badge {
  fill: #f59e0b;
  stroke: var(--card-bg, #fff);
  stroke-width: 2.5;
  transform-box: fill-box;
  transform-origin: center;
  animation: otp-badge-pulse 1.6s ease-in-out infinite;
}
.otp-mail-check {
  stroke: var(--otp-ok);
  stroke-width: 4;
  stroke-dasharray: 40;
  stroke-dashoffset: 40;
  opacity: 0;
}
@keyframes otp-mail-drop {
  from {
    opacity: 0;
    transform: translateY(-18px) rotate(-8deg) scale(0.8);
  }
}
@keyframes otp-mail-float {
  50% {
    transform: translateY(-4px);
  }
}
@keyframes otp-badge-pulse {
  50% {
    transform: scale(1.25);
  }
}
/* A new code was sent: the envelope flies up and comes back. */
.otp-mail.is-resent .otp-mail-icon {
  animation: otp-mail-resend 0.7s ease both;
}
@keyframes otp-mail-resend {
  40% {
    opacity: 0;
    transform: translate(14px, -16px) rotate(10deg) scale(0.85);
  }
  41% {
    opacity: 0;
    transform: translate(-14px, 10px) scale(0.85);
  }
}

.otp-intro {
  margin: 0 auto 1.25rem;
  max-width: 22rem;
  color: var(--text-muted);
  font-size: 0.9375rem;
  line-height: 1.55;
}
.otp-intro strong {
  color: var(--text-main);
  overflow-wrap: anywhere;
}

/* ── Six round code boxes ── */
.otp-boxes {
  display: flex;
  justify-content: center;
  gap: clamp(0.4rem, 2vw, 0.7rem);
  margin-bottom: 1.5rem;
}
:root .otp-box {
  width: clamp(2.6rem, 11vw, 3.1rem);
  height: clamp(2.6rem, 11vw, 3.1rem);
  min-height: 0;
  padding: 0;
  border: 1.5px solid var(--field-border, rgba(59, 130, 246, 0.3));
  border-radius: 50%;
  background: var(--control-bg, rgba(148, 163, 184, 0.18));
  color: var(--text-main);
  font-size: 1.25rem !important;
  font-weight: 700;
  text-align: center;
  caret-color: var(--blue-main);
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease,
    box-shadow 0.15s ease,
    color 0.15s ease;
}
:root .otp-box:focus {
  outline: none;
  border-color: var(--blue-main);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--blue-main) 22%, transparent);
}
:root .otp-box.is-filled {
  border-color: var(--blue-main);
  background: var(--field-bg, #fff);
}
/* Boxes appear one after another when the step opens. */
.is-entering .otp-box {
  animation: otp-box-in 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.3) calc(0.15s + var(--i) * 0.05s) both;
}
@keyframes otp-box-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.7);
  }
}
/* A digit going in. */
.otp-box.is-pop {
  animation: otp-pop 0.22s ease-out;
}
@keyframes otp-pop {
  50% {
    transform: scale(1.14);
  }
}

/* Wrong code: the row shakes and the boxes flash red. */
.otp-boxes.is-error {
  animation: otp-shake 0.45s ease;
}
:root .otp-boxes.is-error .otp-box {
  border-color: var(--otp-error);
  color: var(--otp-error);
}
@keyframes otp-shake {
  15%,
  55% {
    transform: translateX(-8px);
  }
  35%,
  75% {
    transform: translateX(8px);
  }
  90% {
    transform: translateX(-3px);
  }
}

/* Right code: boxes turn green in a ripple and the envelope becomes a check. */
:root .otp-step.is-success .otp-box {
  border-color: var(--otp-ok);
  background: color-mix(in srgb, var(--otp-ok) 14%, transparent);
  color: var(--otp-ok);
  animation: otp-pop 0.3s ease-out calc(var(--i) * 0.06s);
}
.otp-step.is-success .otp-mail {
  background: color-mix(in srgb, var(--otp-ok) 16%, transparent);
}
.otp-step.is-success .otp-mail-icon {
  animation: otp-pop 0.4s ease-out;
}
.otp-step.is-success .otp-mail-envelope {
  opacity: 0;
  transform: scale(0.6);
}
.otp-step.is-success .otp-mail-badge {
  display: none;
}
.otp-step.is-success .otp-mail-check {
  opacity: 1;
  transition:
    stroke-dashoffset 0.45s ease 0.15s,
    opacity 0.1s ease 0.15s;
  stroke-dashoffset: 0;
}

/* ── Verify button and resend ── */
:root .otp-submit {
  width: 100%;
  border: none;
  cursor: pointer;
}
/* Sign In, Create Student Account and Verify while their request is running. */
:root .btn.is-busy {
  opacity: 0.75;
  cursor: progress;
}
.otp-resend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.15rem 0.35rem;
  margin-top: 0.85rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}
:root .otp-resend .otp-resend-btn {
  display: inline-block;
  margin: 0;
  padding-inline: 0.25rem;
}
:root .otp-resend .otp-resend-btn:disabled {
  color: var(--text-muted);
  text-decoration: none;
  cursor: default;
}
