/* ==========================================================================
   کامپوننت تایید پیامکی (OTP) — مشترک بین بازیابی رمز و پیش‌ثبت‌نام
   ==========================================================================

   فلسفه‌ی رنگ: در طول تعامل همه‌چیز خنثی و در پالت برندِ پرتال است
   (فیروزه‌ای/آبی روی اسلیت تیره). سبز فقط و فقط برای «حکم تایید» نگه
   داشته شده، پس وقتی ظاهر می‌شود معنا دارد.

   همه‌ی حرکت‌ها با transform و opacity انجام می‌شوند تا روی لایه‌ی
   کامپوزیت بمانند و ۶۰ فریم را نگه دارند.
   ========================================================================== */

:root {
    --otp-ice: #e2f4ff;
    --otp-text: #eef4fb;
    --otp-muted: #8b97a8;
    --otp-muted-soft: #5b657a;

    /* برندِ پرتال — حالت خنثی */
    --otp-brand: #22d3ee;
    --otp-brand-deep: #3b82f6;

    /* حکم */
    --otp-ok: #34d399;
    --otp-bad: #fb7185;

    --otp-border: rgba(226, 244, 255, 0.14);
    --otp-border-active: rgba(34, 211, 238, 0.85);

    --otp-slot: 46px;
    --otp-slot-h: 54px;
    --otp-radius: 14px;

    /* شعاع مدار؛ جاوااسکریپت هم همین را می‌خواند */
    --otp-orbit: 104px;
}

/* ---------------------------------------------------------------- صحنه */

.otp-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    /* ارتفاع ثابت است تا وقتی ردیف به مدار می‌رود، کارت نپرد */
    min-height: 268px;
    margin: 4px 0 2px;
}

/* ---------------------------------------------------------------- مدار */

.otp-orbit {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.86);
    pointer-events: none;
    transition: opacity 300ms ease, transform 300ms cubic-bezier(0.45, 0, 0.2, 1);
}

.otp-stage[data-phase="orbit"] .otp-orbit,
.otp-stage[data-phase="spin"] .otp-orbit,
.otp-stage[data-phase="verdict"] .otp-orbit {
    opacity: 1;
    transform: scale(1);
}

/* موقع جمع‌شدن، مسیر مدار هم با تایل‌ها تو می‌رود */
.otp-stage[data-phase="collapse"] .otp-orbit,
.otp-stage[data-phase="success"] .otp-orbit {
    opacity: 0;
    transform: scale(0.35);
    transition-duration: 420ms;
}

.otp-orbit svg {
    display: block;
    overflow: visible;
}

.otp-orbit-track {
    fill: none;
    stroke: rgba(226, 244, 255, 0.28);
    stroke-width: 1.5;
    stroke-dasharray: 2 8;
    stroke-linecap: round;
}

.otp-stage[data-phase="verdict"] .otp-orbit-track {
    stroke: rgba(52, 211, 153, 0.5);
    transition: stroke 220ms ease;
}

/* ---------------------------------------------------------------- هاب */

.otp-hub {
    /* مرکز با margin منفی گرفته می‌شود نه با translate، تا transform
       کامل در اختیار انیمیشن بماند */
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    margin: -2.5px 0 0 -2.5px;
    border-radius: 999px;
    background: var(--otp-ice);
    opacity: 0;
    transition: opacity 260ms ease, background 200ms ease,
                box-shadow 200ms ease;
}

.otp-stage[data-phase="orbit"] .otp-hub,
.otp-stage[data-phase="spin"] .otp-hub,
.otp-stage[data-phase="verdict"] .otp-hub,
.otp-stage[data-phase="collapse"] .otp-hub {
    opacity: 0.9;
}

.otp-stage[data-phase="verdict"] .otp-hub,
.otp-stage[data-phase="collapse"] .otp-hub {
    background: var(--otp-ok);
    box-shadow: 0 0 10px rgba(52, 211, 153, 0.6);
}

.otp-stage[data-phase="success"] .otp-hub {
    opacity: 0;
}

/* ---------------------------------------------------------------- ردیف */

.otp-row {
    position: relative;
    display: flex;
    gap: 11px;
    direction: ltr;      /* ارقام همیشه چپ‌به‌راست پر می‌شوند */
}

/* ورودیِ واقعی: نامرئی ولی سر جایش، تا کیبورد عددی موبایل و
   autocomplete="one-time-code" و پیست همه کار کنند. حذفش نمی‌کنیم
   چون آن‌وقت دسترس‌پذیری و پیست از دست می‌رفت. */
.otp-field {
    position: absolute;
    inset: 0;
    width: 100%;
    opacity: 0;
    border: 0;
    background: transparent;
    color: transparent;
    caret-color: transparent;
    /* روی iOS ورودیِ کوچک‌تر از ۱۶ پیکسل کل صفحه را زوم می‌کند */
    font-size: 16px;
    text-align: center;
    letter-spacing: 1em;
    z-index: 2;
    cursor: pointer;
}

.otp-field:disabled {
    cursor: default;
}

/* ---------------------------------------------------------------- خانه */

.otp-slot {
    position: relative;
    width: var(--otp-slot);
    height: var(--otp-slot-h);
    border-radius: var(--otp-radius);
    border: 1px solid var(--otp-border);
    background: rgba(226, 244, 255, 0.04);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    font-weight: 800;
    color: var(--otp-text);
    font-variant-numeric: tabular-nums;
    transition: border-color 180ms ease, background 180ms ease,
                box-shadow 180ms ease, color 180ms ease;
    will-change: transform;
}

.otp-slot.is-active {
    border-color: var(--otp-border-active);
    background: rgba(34, 211, 238, 0.07);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1),
                inset 0 1px 0 rgba(226, 244, 255, 0.12);
}

.otp-slot.is-filled {
    border-color: rgba(226, 244, 255, 0.3);
    background: rgba(226, 244, 255, 0.07);
}

.otp-slot-digit {
    display: block;
    transition: opacity 200ms ease;
}

/* نشانگر چشمک‌زن فقط در خانه‌ی فعالِ خالی */
.otp-slot.is-active .otp-caret {
    position: absolute;
    width: 2px;
    height: 22px;
    border-radius: 2px;
    background: var(--otp-brand);
    animation: otp-blink 1.1s steps(2, start) infinite;
}

.otp-slot.is-filled .otp-caret {
    display: none;
}

@keyframes otp-blink {
    to { opacity: 0; }
}

/* ------------------------------------------------- حکم روی خانه‌ها */

.otp-stage[data-phase="verdict"] .otp-slot,
.otp-stage[data-phase="collapse"] .otp-slot {
    border-color: var(--otp-ok);
    background: rgba(52, 211, 153, 0.08);
    box-shadow: 0 0 12px rgba(52, 211, 153, 0.22);
    transition-duration: 220ms;
}

.otp-stage[data-phase="collapse"] .otp-slot-digit {
    opacity: 0;
}

.otp-stage[data-phase="success"] .otp-row {
    opacity: 0;
    transition: opacity 200ms ease;
}

/* ------------------------------------------------- خطا */

.otp-row.is-bad .otp-slot {
    border-color: var(--otp-bad);
    background: rgba(251, 113, 133, 0.08);
    box-shadow: none;
}

.otp-row.is-bad {
    animation: otp-shake 420ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

/* لرزش مهارشده — نه بازی‌گونه */
@keyframes otp-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(2px); }
}

/* ---------------------------------------------------------------- هسته‌ی موفقیت */

.otp-core {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 46px;
    height: 46px;
    margin: -23px 0 0 -23px;
    border-radius: 13px;
    border: 1.5px solid var(--otp-ok);
    background: rgba(52, 211, 153, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.92);
    pointer-events: none;
}

.otp-stage[data-phase="success"] .otp-core {
    opacity: 1;
    animation: otp-core-pop 420ms cubic-bezier(0.34, 0.9, 0.3, 1) forwards;
}

@keyframes otp-core-pop {
    0%   { transform: scale(0.92); }
    55%  { transform: scale(1.04); }
    100% { transform: scale(1); }
}

.otp-check {
    width: 24px;
    height: 24px;
}

.otp-check path {
    fill: none;
    stroke: var(--otp-ok);
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 32;
    stroke-dashoffset: 32;
}

.otp-stage[data-phase="success"] .otp-check path {
    animation: otp-draw 240ms 140ms cubic-bezier(0.45, 0, 0.2, 1) forwards;
}

@keyframes otp-draw {
    to { stroke-dashoffset: 0; }
}

/* ------------------------------------------------- پژواک */

.otp-echo {
    position: absolute;
    top: 50%;
    left: 50%;
    border: 1px solid rgba(52, 211, 153, 0.3);
    opacity: 0;
    pointer-events: none;
}

.otp-echo-1 {
    width: 92px;
    height: 92px;
    margin: -46px 0 0 -46px;
    border-radius: 26px;
}

.otp-echo-2 {
    width: 142px;
    height: 142px;
    margin: -71px 0 0 -71px;
    border-radius: 42px;
    border-color: rgba(52, 211, 153, 0.18);
}

.otp-stage[data-phase="success"] .otp-echo-1 {
    animation: otp-echo 720ms 120ms cubic-bezier(0.2, 0.6, 0.2, 1) forwards;
}

.otp-stage[data-phase="success"] .otp-echo-2 {
    animation: otp-echo 820ms 220ms cubic-bezier(0.2, 0.6, 0.2, 1) forwards;
}

@keyframes otp-echo {
    0%   { opacity: 0; transform: scale(0.55); }
    35%  { opacity: 1; }
    100% { opacity: 0; transform: scale(1.12); }
}

/* ------------------------------------------------- ذرات */

/* میزبانِ ذرات یک نقطه‌ی بی‌ابعاد در مرکز است؛ ذره‌ها از همان نقطه
   بیرون می‌زنند */
.otp-sparks {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
}

.otp-spark {
    position: absolute;
    top: 0;
    left: 0;
    border-radius: 999px;
    background: var(--otp-ok);
    opacity: 0;
    pointer-events: none;
}

.otp-stage[data-phase="success"] .otp-spark {
    animation: otp-spark 760ms cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

@keyframes otp-spark {
    0%   { opacity: 0; transform: translate(0, 0) scale(0.4); }
    25%  { opacity: 0.95; }
    100% {
        opacity: 0;
        transform: translate(var(--sx), var(--sy)) scale(1);
    }
}

/* ---------------------------------------------------------------- متن کارت */

.otp-copy {
    transition: opacity 300ms ease, transform 300ms ease;
}

.otp-copy.is-out {
    opacity: 0;
    transform: translateY(-5px);
    pointer-events: none;
}

.otp-copy-done {
    opacity: 0;
    transform: translateY(5px);
    transition: opacity 300ms ease, transform 300ms ease;
    pointer-events: none;
}

.otp-copy-done.is-in {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* ---------------------------------------------------------------- پایین کارت */

.otp-resend {
    transition: opacity 260ms ease, transform 260ms ease;
}

.otp-resend.is-out {
    opacity: 0;
    transform: translateY(4px);
    pointer-events: none;
}

/* ---------------------------------------------------------------- کم‌تحرکی */

@media (prefers-reduced-motion: reduce) {
    .otp-orbit,
    .otp-hub,
    .otp-core,
    .otp-echo,
    .otp-spark,
    .otp-copy,
    .otp-copy-done,
    .otp-slot {
        transition-duration: 1ms !important;
        animation: none !important;
    }

    .otp-row.is-bad {
        animation: none !important;
    }

    .otp-stage[data-phase="success"] .otp-core {
        opacity: 1;
        transform: scale(1);
    }

    .otp-stage[data-phase="success"] .otp-check path {
        stroke-dashoffset: 0;
    }

    .otp-echo,
    .otp-spark {
        display: none;
    }
}

/* ---------------------------------------------------------------- موبایل */

@media (max-width: 420px) {
    :root {
        --otp-slot: 40px;
        --otp-slot-h: 48px;
        --otp-orbit: 92px;
    }

    .otp-row {
        gap: 7px;
    }

    .otp-slot {
        font-size: 17px;
    }

    .otp-stage {
        min-height: 244px;
    }
}
