/* Token purchase modal — conversion-first, distinct from the quota/sign-in modals.
   Patterns: balance context up top, anchored "Best value" pack, per-question cost,
   one high-contrast CTA per card, risk-reversal at the CTA, trust footer.
   ponytail: neutral shadows only (no gold glow); recommended pack is the anchor. */

.pay-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: rgba(3, 6, 17, 0.8);
    backdrop-filter: blur(10px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.pay-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.pay-overlay[hidden] { display: none; }

.pay-sheet {
    width: min(560px, 100%);
    max-height: min(90vh, 820px);
    overflow-y: auto;
    background: #0d1220;
    border: 1px solid var(--panel-border);
    border-radius: 24px;
    box-shadow: 0 28px 72px rgba(0, 0, 0, 0.48);
    transform: translateY(10px);
    transition: transform 0.22s ease;
    position: relative;
}

.pay-overlay.active .pay-sheet { transform: translateY(0); }

.pay-head {
    padding: 1.6rem 1.6rem 1.2rem;
}

.pay-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--brand-gold);
    margin-bottom: 0.5rem;
}

.pay-title {
    font-family: 'Poppins', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0 0 0.4rem;
    line-height: 1.15;
}

.pay-sub {
    font-family: 'Inter', sans-serif;
    font-size: 0.88rem;
    color: var(--muted-ink);
    line-height: 1.5;
    margin: 0;
}

.pay-sub strong { color: var(--ink); font-weight: 600; }

.pay-close {
    position: absolute;
    top: 1.1rem;
    right: 1.1rem;
    background: none;
    border: none;
    color: var(--muted-ink);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: color 0.15s ease;
    z-index: 2;
}

.pay-close:hover { color: var(--ink); }

/* balance context — the low-balance moment is the highest-intent upsell trigger */
.pay-balance {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 1.6rem 1.1rem;
    padding: 0.7rem 0.95rem;
    border-radius: 14px;
    border: 1px solid rgba(255, 215, 0, 0.22);
    background: rgba(255, 215, 0, 0.07);
}

.pay-balance-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: rgba(255, 215, 0, 0.14);
    color: var(--brand-gold);
    flex: 0 0 auto;
}

.pay-balance-text {
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    color: var(--muted-ink);
    line-height: 1.35;
}

.pay-balance-text strong {
    display: block;
    font-family: 'Poppins', sans-serif;
    font-size: 1rem;
    color: var(--ink);
    font-weight: 700;
}

.pay-body {
    padding: 0 1.6rem 0.5rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* package card */
.pay-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    width: 100%;
    padding: 1.1rem 1rem 1rem;
    border-radius: 18px;
    border: 1px solid var(--panel-border);
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.pay-card:hover {
    border-color: rgba(255, 215, 0, 0.4);
    transform: translateY(-2px);
}

.pay-card:disabled { opacity: 0.55; cursor: default; transform: none; }

/* the recommended pack: anchor + badge */
.pay-card.is-best {
    border-color: rgba(255, 215, 0, 0.55);
    background:
        radial-gradient(120% 90% at 50% 0%, rgba(255, 215, 0, 0.12), transparent 60%),
        rgba(255, 255, 255, 0.03);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.pay-card-badge {
    position: absolute;
    top: -0.7rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.22rem 0.7rem;
    border-radius: 999px;
    background: var(--brand-gold);
    color: #050a18;
    font-family: 'Inter', sans-serif;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.pay-card-badge.is-soft {
    background: rgba(148, 163, 184, 0.15);
    color: var(--muted-ink);
    border: 1px solid var(--panel-border);
    box-shadow: none;
}

.pay-card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    border: 1px solid rgba(255, 215, 0, 0.25);
    background: rgba(255, 215, 0, 0.09);
    color: var(--brand-gold);
}

.pay-card-name {
    font-family: 'Poppins', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.15;
}

.pay-card-tokens {
    font-family: 'Poppins', sans-serif;
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--ink);
    margin-top: -0.15rem;
}

.pay-card-amount {
    font-family: 'Poppins', sans-serif;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1;
}

.pay-card-unit {
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    color: var(--muted-ink);
    margin-top: -0.3rem;
}

.pay-card-bonus {
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--brand-gold);
    margin-top: -0.3rem;
}

.pay-card-cta {
    margin-top: 0.35rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: 100%;
    min-height: 42px;
    border-radius: 12px;
    border: 1px solid rgba(255, 215, 0, 0.4);
    background: transparent;
    color: var(--brand-gold);
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    transition: filter 0.15s ease, background 0.15s ease;
}

/* solid CTA on the recommended pack = highest visual weight */
.pay-card.is-best .pay-card-cta {
    background: var(--brand-gold);
    color: #050a18;
    border-color: var(--brand-gold);
}

.pay-card:hover .pay-card-cta { filter: brightness(1.06); }

.pay-note {
    margin: 0.35rem 1.6rem 0.25rem;
    text-align: center;
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    line-height: 1.4;
    color: var(--muted-ink);
}

.pay-state {
    grid-column: 1 / -1;
    padding: 2.5rem 1rem;
    text-align: center;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    color: var(--muted-ink);
}

/* ponytail: post-payment states animate — CSS-native spinner/checkmark/shake, no JS */
.pay-state.pay-busy::before {
    content: "";
    display: block;
    width: 28px;
    height: 28px;
    margin: 0 auto 0.9rem;
    border-radius: 999px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--brand-gold);
    animation: paySpin 0.8s linear infinite;
}

@keyframes paySpin { to { transform: rotate(360deg); } }

.pay-state.pay-success::before {
    content: "";
    display: block;
    width: 34px;
    height: 18px;
    margin: 0.4rem auto 1rem;
    border-left: 4px solid #22c55e;
    border-bottom: 4px solid #22c55e;
    transform: rotate(-45deg) scale(1);
    animation: payCheck 0.45s cubic-bezier(0.19, 1, 0.22, 1) both;
}

@keyframes payCheck {
    from { transform: rotate(-45deg) scale(0); opacity: 0; }
    to { transform: rotate(-45deg) scale(1); opacity: 1; }
}

.pay-state.pay-fail {
    animation: payShake 0.4s ease;
}

@keyframes payShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-3px); }
}

@media (prefers-reduced-motion: reduce) {
    .pay-state.pay-busy::before,
    .pay-state.pay-success::before,
    .pay-state.pay-fail { animation: none; }
}

.pay-state .pay-state-title {
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    color: var(--ink);
    display: block;
    margin-bottom: 0.35rem;
}

.pay-retry {
    margin-top: 1rem;
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--ink);
    padding: 0.6rem 1.2rem;
    border-radius: 10px;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
}

/* trust / risk-reversal strip, right where the purchase hesitation peaks */
.pay-trust {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.35rem 1rem;
    padding: 0.5rem 1.6rem 1.4rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.74rem;
    color: var(--muted-ink);
}

.pay-trust span {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.pay-trust svg { color: var(--brand-gold); flex: 0 0 auto; }

.pay-foot {
    padding: 0.85rem 1.6rem 1.3rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    font-family: 'Inter', sans-serif;
    font-size: 0.74rem;
    color: var(--muted-ink);
    line-height: 1.5;
    text-align: center;
}

.pay-foot a {
    color: var(--brand-gold);
    text-decoration: none;
}

.pay-foot a:hover { text-decoration: underline; }

.pay-close:focus-visible,
.pay-card:focus-visible,
.pay-retry:focus-visible {
    outline: 2px solid var(--brand-gold);
    outline-offset: 2px;
    border-radius: 14px;
}

/* --- light mode --- */
body.light-mode .pay-sheet {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 28px 60px rgba(0, 0, 0, 0.16);
}

body.light-mode .pay-title,
body.light-mode .pay-card-name,
body.light-mode .pay-card-amount { color: #0f172a; }
body.light-mode .pay-eyebrow,
body.light-mode .pay-card-cta { color: #b45309; }
body.light-mode .pay-sub,
body.light-mode .pay-card-tokens,
body.light-mode .pay-card-unit,
body.light-mode .pay-balance-text,
body.light-mode .pay-state,
body.light-mode .pay-trust,
body.light-mode .pay-foot { color: #475569; }

body.light-mode .pay-balance {
    border-color: rgba(180, 130, 0, 0.25);
    background: rgba(255, 215, 0, 0.12);
}
body.light-mode .pay-balance-text strong { color: #0f172a; }

body.light-mode .pay-card {
    border-color: rgba(0, 0, 0, 0.1);
    background: #f8fafc;
}
body.light-mode .pay-card.is-best {
    border-color: rgba(180, 130, 0, 0.5);
    background:
        radial-gradient(120% 90% at 50% 0%, rgba(255, 215, 0, 0.16), transparent 60%),
        #fffbeb;
}
body.light-mode .pay-card-icon {
    border-color: rgba(180, 130, 0, 0.28);
    background: rgba(255, 215, 0, 0.18);
    color: #b45309;
}
body.light-mode .pay-card-cta { border-color: rgba(180, 130, 0, 0.45); }
body.light-mode .pay-card.is-best .pay-card-cta {
    background: #b8860b;
    color: #ffffff;
    border-color: #b8860b;
}
body.light-mode .pay-foot { border-color: rgba(0, 0, 0, 0.08); }
body.light-mode .pay-close:hover,
body.light-mode .pay-retry { color: #0f172a; }

/* --- mobile: stack the cards, recommended still distinguished --- */
@media (max-width: 640px) {
    .pay-overlay { padding: 0.75rem; align-items: flex-end; }
    .pay-sheet { max-height: 94vh; border-radius: 22px 22px 0 0; }
    .pay-head { padding: 1.35rem 1.2rem 1rem; }
    .pay-balance { margin: 0 1.2rem 1rem; }
    .pay-body { padding: 0 1.2rem 0.5rem; grid-template-columns: 1fr; }
    .pay-trust { padding: 0.5rem 1.2rem 1.2rem; }
    .pay-foot { padding: 0.75rem 1.2rem 1.2rem; }
    .pay-card.is-best { order: -1; }
}
