body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: radial-gradient(circle at center, #0a0a20 0%, #050510 100%);
    color: #fff;
    font-family: 'Outfit', sans-serif;
}

.thai-font {
    font-family: 'Noto Sans Thai', 'Outfit', sans-serif;
}

#simulation-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
}

/* Header/Controls */
.header {
    width: 100%;
    padding: 20px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    pointer-events: none;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 2px;
    background: linear-gradient(to right, #00f2fe 0%, #4facfe 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
}

/* Utilities */
.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.5s ease, visibility 0.5s;
}

.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto !important;
}

/* Buttons */
.btn-primary {
    background: rgba(0, 242, 254, 0.1);
    border: 1px solid rgba(0, 242, 254, 0.3);
    color: #00f2fe;
    padding: 12px 28px;
    border-radius: 50px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: auto;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary:hover {
    background: rgba(0, 242, 254, 0.2);
    box-shadow: 0 0 20px rgba(0, 242, 254, 0.4);
    transform: translateY(-2px);
}

#chaos-btn {
    pointer-events: auto;
}

/* Reveal Button Container */
#reveal-container {
    position: absolute;
    bottom: 25%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

#reveal-btn {
    padding: 16px 48px;
    font-size: 1.4rem;
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.2), rgba(79, 172, 254, 0.2));
    border: 2px solid rgba(0, 242, 254, 0.5);
    box-shadow: 0 0 30px rgba(0, 242, 254, 0.3);
}

/* Result Overlay Scroll Fix */
#result-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 5, 15, 0.9);
    backdrop-filter: blur(15px);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    /* Start from top to allow scrolling if needed */
    z-index: 9999;
    pointer-events: auto;
    overflow-y: auto;
    /* Enable vertical scroll */
    padding: 20px 0;
    /* Add some spacing */
}

/* Hide scrollbar for Chrome, Safari and Opera */
#result-overlay::-webkit-scrollbar {
    display: none;
}

#result-overlay {
    -ms-overflow-style: none;
    /* IE and Edge */
    scrollbar-width: none;
    /* Firefox */
}

.glass-panel {
    background: rgba(20, 20, 40, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 24px;
    padding: 48px;
    width: 90%;
    max-width: 800px;
    /* Width increased for 3 cards */
    text-align: center;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.8);
    position: relative;
    /* Remove overflowing hidden to allow children to pop if needed, but here we want containment */
    /* Check height to prevent too tall */
    margin: auto;
    /* Center with flex-start */
    pointer-events: auto;
}

#selected-cards-display {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 30px 0;
    flex-wrap: wrap;
    /* Allow wrapping on very small screens */
}

.result-card {
    width: 150px;
    height: 225px;
    /* 1.5 aspect ratio */
    background-image: url('../assets/cards/card_front_blank.png');
    background-size: cover;
    background-position: center;
    position: relative;
    border-radius: 10px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

.result-card-title {
    font-family: 'Noto Sans Thai', sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
    color: #ffd700;
    /* Gold */
    margin-bottom: 5px;
}

.result-card-id {
    font-size: 2.5rem;
    font-weight: 700;
    color: #fff;
    opacity: 0.8;
}

.result-card-names {
    color: #4facfe;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 20px;
    font-family: 'Noto Sans Thai', sans-serif;
}

#result-content h2 {
    color: #fff;
    font-size: 2.2rem;
    margin-bottom: 24px;
    font-weight: 300;
    letter-spacing: 2px;
}

#interpretation-text {
    color: #b0b0d0;
    font-size: 1.2rem;
    line-height: 1.8;
    margin: 32px 0;
    font-weight: 300;
}

#generated-image-container {
    margin: 32px 0;
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.placeholder-image {
    width: 100%;
    height: 350px;
    background: #101025;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #4facfe;
    font-style: italic;
    border: 1px solid rgba(79, 172, 254, 0.2);
}

/* Cosmic Loader */
.cosmic-loader {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: #00f2fe;
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.3);
    animation: cosmic-spin 1s ease-in-out infinite;
    margin: 10px auto;
}

@keyframes cosmic-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Mystical Loader with Floating Orbs */
.mystical-loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
}

.mystical-orbs {
    display: flex;
    gap: 15px;
    margin-bottom: 25px;
}

.orb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    animation: orbFloat 1.8s ease-in-out infinite;
}

.orb-1 {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    box-shadow: 0 0 20px rgba(79, 172, 254, 0.6);
    animation-delay: 0s;
}

.orb-2 {
    background: linear-gradient(135deg, #a855f7 0%, #ec4899 100%);
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.6);
    animation-delay: 0.3s;
}

.orb-3 {
    background: linear-gradient(135deg, #fcd34d 0%, #f59e0b 100%);
    box-shadow: 0 0 20px rgba(252, 211, 77, 0.6);
    animation-delay: 0.6s;
}

@keyframes orbFloat {

    0%,
    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }

    50% {
        transform: translateY(-15px) scale(1.2);
        opacity: 0.7;
    }
}

.mystical-message {
    font-family: 'Noto Sans Thai', sans-serif;
    font-size: 1.1rem;
    color: #4facfe;
    transition: opacity 0.3s ease;
    text-align: center;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.secondary-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #aaa;
    padding: 8px 24px;
    border-radius: 20px;
    cursor: pointer;
    font-family: 'Noto Sans Thai', sans-serif;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 0.9rem;
}

.secondary-btn:hover {
    color: #fff;
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.05);
}

/* Instructions */
.instructions {
    position: absolute;
    bottom: 40px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.9rem;
    font-weight: 300;
    letter-spacing: 1px;
}

@media (max-width: 600px) {
    .glass-panel {
        padding: 24px;
    }

    #result-content h2 {
        font-size: 1.6rem;
    }
}

/* ============================================
   CINEMATIC REVEAL STAGE
   ============================================ */

#reveal-stage {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, #0a0a25 0%, #020208 100%);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Changed from hidden to allow result-phase scrolling */
    overflow: visible;
}

/* Phase 1: Card Reveal */
#card-reveal-phase {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

#reveal-card-container {
    width: 200px;
    height: 300px;
    perspective: 1000px;
}

.reveal-card-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 12px;
    box-shadow:
        0 0 40px rgba(79, 172, 254, 0.4),
        0 20px 60px rgba(0, 0, 0, 0.6);
}

#card-label {
    margin-top: 30px;
    font-size: 1.8rem;
    color: #ffd700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
    opacity: 0;
    letter-spacing: 2px;
}

/* Phase 2: Cosmic Transition */
#cosmic-phase {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.cosmic-particles {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Spiral Warp Hole - Particles orbit and converge to center */
.particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    box-shadow: 0 0 15px currentColor;
}

/* Each particle starts at different position and spirals in */
.p1 {
    color: #4facfe;
    background: #4facfe;
    animation: spiralIn 3s ease-in infinite;
    animation-delay: 0s;
}

.p2 {
    color: #00f2fe;
    background: #00f2fe;
    animation: spiralIn 3s ease-in infinite;
    animation-delay: 0.4s;
}

.p3 {
    color: #a855f7;
    background: #a855f7;
    animation: spiralIn 3s ease-in infinite;
    animation-delay: 0.8s;
}

.p4 {
    color: #ec4899;
    background: #ec4899;
    animation: spiralIn 3s ease-in infinite;
    animation-delay: 1.2s;
}

.p5 {
    color: #fcd34d;
    background: #fcd34d;
    animation: spiralIn 3s ease-in infinite;
    animation-delay: 0.2s;
}

.p6 {
    color: #4facfe;
    background: #4facfe;
    animation: spiralIn 3s ease-in infinite;
    animation-delay: 0.6s;
}

.p7 {
    color: #00f2fe;
    background: #00f2fe;
    animation: spiralIn 3s ease-in infinite;
    animation-delay: 1s;
}

.p8 {
    color: #a855f7;
    background: #a855f7;
    animation: spiralIn 3s ease-in infinite;
    animation-delay: 1.4s;
}

/* Spiral inward animation - starts far, orbits while moving to center */
@keyframes spiralIn {
    0% {
        transform: rotate(0deg) translateX(300px) scale(1.5);
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    50% {
        transform: rotate(360deg) translateX(150px) scale(1);
        opacity: 1;
    }

    90% {
        opacity: 0.8;
    }

    100% {
        transform: rotate(720deg) translateX(0) scale(0);
        opacity: 0;
    }
}

/* Enhanced cosmic glow - pulsing vortex center */
.cosmic-glow {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    background: radial-gradient(circle,
            rgba(79, 172, 254, 0.5) 0%,
            rgba(168, 85, 247, 0.3) 30%,
            rgba(236, 72, 153, 0.1) 60%,
            transparent 70%);
    animation: vortexPulse 1.5s ease-in-out infinite;
    box-shadow:
        0 0 60px rgba(79, 172, 254, 0.5),
        0 0 120px rgba(168, 85, 247, 0.3),
        inset 0 0 40px rgba(255, 255, 255, 0.1);
}

@keyframes vortexPulse {

    0%,
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 0.7;
    }

    50% {
        transform: scale(1.2) rotate(180deg);
        opacity: 1;
    }
}

/* Phase 3: Result Panel - Uses position:fixed to escape parent and enable scrolling */
#result-phase {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: scroll;
    /* Force scrollbar */
    -webkit-overflow-scrolling: touch;
    /* Smooth iOS momentum scrolling */
    touch-action: pan-y pinch-zoom;
    /* Allow vertical scroll and zoom */
    pointer-events: auto;
    z-index: 10002;
    padding: 40px 20px 100px 20px;
    /* Extra bottom padding for scroll */
    box-sizing: border-box;
    overscroll-behavior: contain;
    background: radial-gradient(circle at center, #0a0a25 0%, #020208 100%);
    /* Own background */
}

#result-phase .glass-panel {
    max-width: 800px;
    width: 90%;
    margin-bottom: 60px;
    /* Extra space at bottom for scrolling */
}