/* ═══ Modals + Overlays — The Internet's Wishing Well 3D ═══
   Source-of-truth styling for any popup that takes over the screen:
     - .overlay         OverlayStack wrapper (most flows + result cards)
     - .stripe-overlay  payment-specific wrapper (separate code path)
   Plus the cards inside (.stripe-overlay-card, .support-card, etc.)
   and the cosmic-btn family used inside them.

   Design rules (2026-05-20):
     1. Every modal MUST fit the viewport. No content sprawl.
        Cards cap at min(95vw, 720px) wide and min(92vh, 800px) tall
        with internal overflow-y: auto so long content scrolls within
        the card, never the page.
     2. Safe-area padding (env(safe-area-inset-*)) so iPhone notches
        + home-bars don't clip the modal.
     3. Backdrop with blur + darkening so the 3D scene fades behind
        the modal — equivalent to "camera adjusts" since the scene
        is dimmed to the point that camera framing doesn't matter.
     4. Mobile (≤640px): card becomes full-bleed with rounded corners,
        100dvw × 100dvh with safe-area padding. Optimizes thumb reach
        for the form fields + pay button.
     5. Close button is always visible (top-right, large hit target).
*/

/* ── 1. OverlayStack wrapper ────────────────────────────────────────── */
/* The wrapper is created by overlay-stack.ts with inline styles
   (position:fixed, inset:0, display:grid, placeItems:center,
   zIndex:50+). We add backdrop + safe-area padding here so the
   content has breathing room AND a clear visual separator from the
   3D scene. */
.overlay {
    background: rgba(2, 2, 8, 0.72);
    -webkit-backdrop-filter: blur(8px) saturate(120%);
    backdrop-filter: blur(8px) saturate(120%);
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── 2. Stripe payment overlay ─────────────────────────────────────── */
/* The Stripe overlay has its own wrapper (.stripe-overlay) — it
   already sets backdrop inline but doesn't constrain the card.
   These rules add the card chrome + Elements iframe sizing. */

.stripe-overlay {
    /* Extra safety: ensure we sit above OverlayStack's 50+ tier. */
    z-index: 100;
}

.stripe-overlay-card {
    position: relative;
    background: linear-gradient(180deg, rgba(13, 13, 48, 0.96) 0%, rgba(8, 8, 26, 0.96) 100%);
    border: 1px solid rgba(123, 47, 247, 0.35);
    border-radius: 14px;
    box-shadow:
        0 24px 60px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(232, 224, 255, 0.04) inset,
        0 0 40px rgba(123, 47, 247, 0.12);
    padding: clamp(1.25rem, 4vw, 1.75rem);
    width: min(95vw, 460px);
    max-height: min(92dvh, 800px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    color: var(--starlight, #e8e0ff);
    font-family: var(--font-body, 'Outfit', system-ui, sans-serif);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.stripe-overlay-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    background: rgba(232, 224, 255, 0.06);
    border: 1px solid rgba(232, 224, 255, 0.12);
    border-radius: 999px;
    color: var(--starlight, #e8e0ff);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    z-index: 1;
}
.stripe-overlay-close:hover,
.stripe-overlay-close:focus-visible {
    background: rgba(232, 224, 255, 0.14);
    border-color: rgba(232, 224, 255, 0.32);
    outline: none;
}

.stripe-overlay-title {
    margin: 0;
    padding-right: 3rem;  /* leave room for the close button */
    font-family: var(--font-heading, 'Cinzel', serif);
    font-size: clamp(1.1rem, 3.5vw, 1.4rem);
    font-weight: 600;
    color: var(--starlight, #e8e0ff);
    letter-spacing: 0.02em;
}

.stripe-mount {
    /* Stripe Elements iframe lives inside this. Min-height reserves
       space so the modal doesn't jump when Elements paints (~600ms
       on slow connections). */
    min-height: 240px;
    background: rgba(6, 6, 14, 0.55);
    border: 1px solid rgba(232, 224, 255, 0.08);
    border-radius: 10px;
    padding: 0.75rem;
}

.stripe-overlay-message {
    min-height: 1.2em;
    font-size: 0.85rem;
    color: #ff8a8a;
    text-align: center;
}
.stripe-overlay-message:empty { display: none; }

.stripe-overlay-sacred {
    margin: 0;
    text-align: center;
    font-family: var(--font-sacred, 'Cormorant Garamond', Georgia, serif);
    font-style: italic;
    font-size: 0.95rem;
    color: var(--soft-lavender, rgba(232, 224, 255, 0.7));
    letter-spacing: 0.02em;
}

/* ── 3. Cosmic button family (used inside many modals) ─────────────── */
/* Without these, every <button> in a modal renders as a browser-default
   gray rectangle. Cosmic-btn is the brand-aligned primary button. */
.cosmic-btn {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid rgba(123, 47, 247, 0.55);
    border-radius: 999px;
    padding: 0.85rem 1.5rem;
    background: linear-gradient(135deg, rgba(123, 47, 247, 0.85) 0%, rgba(0, 245, 255, 0.65) 100%);
    color: var(--starlight, #e8e0ff);
    font-family: var(--font-heading, 'Cinzel', serif);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    min-height: 44px;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
    box-shadow: 0 4px 14px rgba(123, 47, 247, 0.25);
}
.cosmic-btn:hover:not(:disabled),
.cosmic-btn:focus-visible:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(123, 47, 247, 0.4), 0 0 24px rgba(0, 245, 255, 0.18);
    outline: none;
}
.cosmic-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(123, 47, 247, 0.25);
}
.cosmic-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.cosmic-btn-pay {
    width: 100%;
    /* The pay button is the modal's primary action; give it more
       presence than secondary buttons. */
    font-size: 1.05rem;
}

/* .cta-btn-primary is always paired with .cosmic-btn in leaderboard.ts
   (className = 'cosmic-btn cta-btn-primary'), so cosmic-btn carries
   the look; this rule is just a marker for any future override. */

.cta-btn-secondary {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid rgba(232, 224, 255, 0.28);
    border-radius: 999px;
    padding: 0.85rem 1.5rem;
    background: transparent;
    color: var(--starlight, #e8e0ff);
    font-family: var(--font-heading, 'Cinzel', serif);
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    min-height: 44px;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.cta-btn-secondary:hover:not(:disabled),
.cta-btn-secondary:focus-visible:not(:disabled) {
    border-color: rgba(232, 224, 255, 0.55);
    background: rgba(232, 224, 255, 0.05);
    outline: none;
}

/* ── 4. Generic support/result card (used by oracle/letgo/leaderboard) ── */
/* Same chrome rules as stripe-overlay-card but for the bespoke-cards
   built by individual flows (.support-card, .vigil-letgo-card,
   .game-leaderboard, .oracle-card). */
.support-card,
.vigil-letgo-card,
.game-leaderboard,
.dash-card,
.lb-actions ~ * {
    color: var(--starlight, #e8e0ff);
    font-family: var(--font-body, 'Outfit', system-ui, sans-serif);
}

.support-card,
.vigil-letgo-card,
.game-leaderboard {
    background: linear-gradient(180deg, rgba(13, 13, 48, 0.96) 0%, rgba(8, 8, 26, 0.96) 100%);
    border: 1px solid rgba(123, 47, 247, 0.35);
    border-radius: 14px;
    box-shadow:
        0 24px 60px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(232, 224, 255, 0.04) inset;
    padding: clamp(1.25rem, 4vw, 1.75rem);
    width: min(95vw, 520px);
    max-height: min(92dvh, 800px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.support-close {
    align-self: flex-end;
    background: rgba(232, 224, 255, 0.06);
    border: 1px solid rgba(232, 224, 255, 0.12);
    border-radius: 999px;
    width: 44px;
    height: 44px;
    color: var(--starlight, #e8e0ff);
    font-size: 1.4rem;
    cursor: pointer;
    margin: -0.25rem -0.25rem 0 0;
}

.lb-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 0.5rem;
}

/* ── 5. Mobile — full-bleed below the small-viewport breakpoint ────── */
@media (max-width: 640px) {
    .stripe-overlay-card,
    .support-card,
    .vigil-letgo-card,
    .game-leaderboard {
        width: 100%;
        max-height: 100%;
        border-radius: 14px;
    }
    .stripe-overlay-title {
        font-size: 1.1rem;
    }
    .cosmic-btn,
    .cta-btn-secondary {
        width: 100%;
    }
}

/* ── 6. Body-class signal — let the 3D scene visually quiet down ───── */
/* main.ts already sets `body.has-modal-overlay` while a modal is up.
   We use it to nudge the canvas brightness so users perceive the
   scene as having "stepped back" for the modal. */
body.has-modal-overlay #scene-root {
    filter: brightness(0.4) saturate(0.7);
    transition: filter 0.3s ease;
}
body:not(.has-modal-overlay) #scene-root {
    filter: none;
    transition: filter 0.3s ease;
}
