#crypto-popup-overlay,
#crypto-popup-overlay * {
    box-sizing: border-box;
}

body.crypto-popup-open {
    overflow: hidden;
}

#crypto-popup-overlay[hidden] {
    display: none !important;
}

#crypto-popup-overlay {
    position: fixed;
    inset: 0;
    z-index: 99998;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    visibility: hidden;
    transition: opacity 240ms ease, visibility 240ms ease;
}

#crypto-popup-overlay.is-visible {
    opacity: 1;
    visibility: visible;
}

#crypto-popup-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 99999;
    max-height: 90vh;
    overflow-y: auto;
    max-width: 520px;
    width: calc(100% - 2rem);
    padding: 2rem;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 24px;
    background: #ffffff;
    color: #111827;
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.32);
    font-family: inherit;
}

#crypto-popup-modal:focus {
    outline: none;
}

.popup-close-btn {
    position: absolute;
    top: 0.85rem;
    right: 0.95rem;
    width: 2.25rem;
    height: 2.25rem;
    border: 0;
    border-radius: 999px;
    background: #f3f4f6;
    color: #111827;
    font-size: 1.7rem;
    line-height: 1;
    cursor: pointer;
    transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.popup-close-btn:hover,
.popup-close-btn:focus-visible {
    background: #111827;
    color: #ffffff;
    transform: rotate(90deg);
}

.popup-form-wrap {
    opacity: 1;
    transition: opacity 400ms ease;
}

.popup-form-wrap.is-fading-out {
    opacity: 0;
    pointer-events: none;
}

#crypto-popup-title,
.popup-success-wrap h2 {
    margin: 0 2rem 0.45rem 0;
    color: #111827;
    font-size: clamp(1.55rem, 4vw, 2.1rem);
    font-weight: 800;
    line-height: 1.12;
}

.crypto-popup-intro,
.popup-success-wrap p {
    margin: 0 0 1.35rem;
    color: #4b5563;
    font-size: 1rem;
    line-height: 1.55;
}

#crypto-popup-form {
    display: flex;
    flex-direction: column;
    gap: 0.95rem;
}

.crypto-popup-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
}

.crypto-popup-field {
    display: flex;
    flex-direction: column;
}

.crypto-popup-field label,
.crypto-popup-label {
    display: block;
    margin-bottom: 0.42rem;
    color: #111827;
    font-size: 0.92rem;
    font-weight: 700;
}

.crypto-buy-sell-toggle {
    display: flex;
    gap: 0.75rem;
    width: 100%;
}

.crypto-toggle-btn {
    flex: 1 1 0;
    min-height: 48px;
    padding: 0.85rem 0.9rem;
    border: 2px solid #e5e7eb;
    border-radius: 14px;
    background: #f8fafc;
    color: #111827;
    font-size: 0.92rem;
    font-weight: 900;
    letter-spacing: 0.055em;
    cursor: pointer;
    transition: background 180ms ease, border-color 180ms ease, box-shadow 180ms ease, color 180ms ease, transform 180ms ease;
}

.crypto-toggle-btn:hover,
.crypto-toggle-btn:focus-visible {
    border-color: #f7931a;
    box-shadow: 0 0 0 4px rgba(247, 147, 26, 0.14);
}

.crypto-toggle-btn.active {
    border-color: #f7931a;
    background: #f7931a;
    color: #ffffff;
    box-shadow: 0 10px 22px rgba(247, 147, 26, 0.28);
}

.crypto-toggle-btn:active {
    transform: translateY(1px);
}

.crypto-popup-field input,
.crypto-popup-field select {
    width: 100%;
    min-height: 48px;
    padding: 0.78rem 0.92rem;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    background: #ffffff;
    color: #111827;
    font: inherit;
    transition: border-color 180ms ease, box-shadow 180ms ease;
}

.crypto-popup-field select {
    appearance: auto;
}

.crypto-popup-field input:focus,
.crypto-popup-field select:focus {
    border-color: #f7931a;
    outline: none;
    box-shadow: 0 0 0 4px rgba(247, 147, 26, 0.14);
}

.crypto-popup-field.has-error input,
.crypto-popup-field.has-error select,
.crypto-popup-field.has-error .crypto-toggle-btn {
    border-color: #dc2626;
}

.crypto-field-error {
    display: none;
    margin-top: 0.35rem;
    color: #dc2626;
    font-size: 0.84rem;
    font-weight: 600;
    line-height: 1.35;
}

.crypto-field-error.is-visible {
    display: block;
}

.crypto-popup-error-banner {
    padding: 0.78rem 0.9rem;
    border: 1px solid #fecaca;
    border-radius: 12px;
    background: #fef2f2;
    color: #b91c1c;
    font-size: 0.92rem;
    font-weight: 700;
    line-height: 1.45;
}

.crypto-popup-error-banner[hidden] {
    display: none !important;
}

.crypto-popup-submit,
.crypto-popup-success-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 52px;
    padding: 0.92rem 1.2rem;
    border: 0;
    border-radius: 14px;
    background: #f7931a;
    color: #ffffff;
    font-size: 1rem;
    font-weight: 900;
    line-height: 1;
    cursor: pointer;
    transition: background 180ms ease, box-shadow 180ms ease, transform 180ms ease, opacity 180ms ease;
}

.crypto-popup-submit:hover:not(:disabled),
.crypto-popup-submit:focus-visible:not(:disabled),
.crypto-popup-success-close:hover,
.crypto-popup-success-close:focus-visible {
    background: #dc7e07;
    box-shadow: 0 12px 24px rgba(247, 147, 26, 0.28);
}

.crypto-popup-submit:active:not(:disabled),
.crypto-popup-success-close:active {
    transform: translateY(1px);
}

.crypto-popup-submit:disabled {
    cursor: not-allowed;
}

.crypto-popup-submit.is-loading {
    opacity: 0.92;
}

.crypto-popup-submit.is-loading::after {
    content: '';
    width: 18px;
    height: 18px;
    margin-left: 0.65rem;
    border: 2px solid rgba(255, 255, 255, 0.55);
    border-top-color: #ffffff;
    border-radius: 999px;
    animation: crypto-popup-spin 700ms linear infinite;
}

.crypto-popup-submit.submit-success {
    background: #16a34a;
    animation: crypto-popup-submit-success 600ms ease both;
}

.crypto-popup-submit.submit-success::after {
    content: '✓';
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.2rem;
    height: 1.2rem;
    margin-left: 0.55rem;
    border: 2px solid currentColor;
    border-radius: 999px;
    font-size: 0.78rem;
    line-height: 1;
    animation: crypto-popup-check-pop 450ms ease both;
}

.popup-success-wrap {
    display: none;
    min-height: 330px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    opacity: 0;
    transition: opacity 400ms ease;
}

.popup-success-wrap.is-visible {
    opacity: 1;
}

.popup-success-wrap h2 {
    margin: 0 0 0.55rem;
}

.popup-success-wrap p {
    max-width: 360px;
    margin-bottom: 1.45rem;
}

.crypto-popup-checkmark {
    width: 96px;
    height: 96px;
    margin-bottom: 1.1rem;
}

.crypto-popup-checkmark-circle,
.crypto-popup-checkmark-check {
    stroke: #16a34a;
    stroke-width: 4.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.crypto-popup-checkmark-circle {
    stroke-dasharray: 190;
    stroke-dashoffset: 190;
    animation: crypto-popup-draw-circle 800ms ease forwards;
}

.crypto-popup-checkmark-check {
    stroke-dasharray: 52;
    stroke-dashoffset: 52;
    animation: crypto-popup-draw-check 800ms ease 180ms forwards;
}

.crypto-popup-success-close {
    width: auto;
    min-width: 150px;
    padding-right: 1.6rem;
    padding-left: 1.6rem;
}

@keyframes crypto-popup-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes crypto-popup-submit-success {
    0% {
        transform: scale(1);
        background: #f7931a;
    }

    55% {
        transform: scale(1.04);
        background: #22c55e;
    }

    100% {
        transform: scale(1);
        background: #16a34a;
    }
}

@keyframes crypto-popup-check-pop {
    0% {
        opacity: 0;
        transform: scale(0.35);
    }

    70% {
        opacity: 1;
        transform: scale(1.12);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes crypto-popup-draw-circle {
    to {
        stroke-dashoffset: 0;
    }
}

@keyframes crypto-popup-draw-check {
    to {
        stroke-dashoffset: 0;
    }
}

@media (max-width: 560px) {
    #crypto-popup-modal {
        width: calc(100% - 1rem);
        padding: 1.45rem;
        border-radius: 20px;
    }

    #crypto-popup-title {
        margin-right: 1.75rem;
    }

    .crypto-popup-grid {
        grid-template-columns: 1fr;
    }

    .crypto-buy-sell-toggle {
        gap: 0.55rem;
    }

    .crypto-toggle-btn {
        padding-right: 0.65rem;
        padding-left: 0.65rem;
        font-size: 0.84rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    #crypto-popup-overlay,
    .popup-close-btn,
    .popup-form-wrap,
    .crypto-toggle-btn,
    .crypto-popup-field input,
    .crypto-popup-field select,
    .crypto-popup-submit,
    .crypto-popup-success-close,
    .popup-success-wrap {
        transition: none;
    }

    .crypto-popup-submit.is-loading::after,
    .crypto-popup-submit.submit-success,
    .crypto-popup-submit.submit-success::after,
    .crypto-popup-checkmark-circle,
    .crypto-popup-checkmark-check {
        animation: none;
    }

    .crypto-popup-checkmark-circle,
    .crypto-popup-checkmark-check {
        stroke-dashoffset: 0;
    }
}
