:root {
    --bg-color: #0b0216;
    --primary-color: #5b21b6;
    --secondary-color: #3b0764;
    --gold: #fcd34d;
    --gold-glow: rgba(252, 211, 77, 0.6);
    --glass-bg: rgba(30, 20, 50, 0.7);
    --glass-border: rgba(252, 211, 77, 0.3);
    --text-main: #f3f4f6;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Mitr', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Background Space/Stars */
.stars, .twinkling {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; height: 100%;
    display: block;
    z-index: -2;
}
.stars {
    background: #000 url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MDAiIGhlaWdodD0iNDAwIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjMDAwIi8+PGNpcmNsZSBjeD0iMjAiIGN5PSI1MCIgcj0iMSIgZmlsbD0iI2ZmZiIvPjxjaXJjbGUgY3g9IjEwMCIgY3k9IjIwMCIgcj0iMS41IiBmaWxsPSIjZmZmIi8+PGNpcmNsZSBjeD0iMjUwIiBjeT0iMTAwIiByPSIxIiBmaWxsPSIjZmZmIi8+PGNpcmNsZSBjeD0iMzAwIiBjeT0iMzUwIiByPSIyIiBmaWxsPSIjZmZmIi8+PC9zdmc+') repeat top center;
    z-index: -2;
}

.container {
    width: 100%;
    max-width: 900px;
    padding: 20px;
    text-align: center;
    z-index: 1;
}

header {
    margin-bottom: 40px;
}

.glow-text {
    font-size: 3rem;
    color: var(--gold);
    text-shadow: 0 0 10px var(--gold-glow), 0 0 20px var(--gold-glow);
    margin-bottom: 10px;
    font-weight: 500;
}

#subtitle {
    font-size: 1.2rem;
    color: #cbd5e1;
}

h2 {
    font-size: 1.8rem;
    margin-bottom: 30px;
    color: #e2e8f0;
    font-weight: 400;
}

.gold-text {
    color: var(--gold);
    text-shadow: 0 0 5px rgba(252, 211, 77, 0.4);
}

/* Screens */
.screen {
    display: none;
    animation: fadeIn 0.8s ease-in-out;
}
.screen.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Buttons */
.btn {
    font-family: 'Mitr', sans-serif;
    font-size: 1.2rem;
    padding: 15px 30px;
    margin: 10px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--glass-bg);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
}

.btn:hover {
    background: var(--primary-color);
    box-shadow: 0 0 15px var(--primary-color);
    transform: translateY(-3px);
}

.mystic-btn {
    display: block;
    width: 80%;
    max-width: 400px;
    margin: 15px auto;
    font-size: 1.4rem;
}

.action-btn {
    background: linear-gradient(45deg, var(--secondary-color), var(--primary-color));
    border: 2px solid var(--gold);
    color: white;
    font-weight: 500;
    box-shadow: 0 0 15px rgba(252, 211, 77, 0.3);
}

.action-btn:hover {
    box-shadow: 0 0 25px rgba(252, 211, 77, 0.6);
}

.btn-secondary {
    background: transparent;
    border: 1px solid #64748b;
    color: #94a3b8;
}

/* Deck & Shuffle */
.deck-container {
    height: 250px;
    position: relative;
    margin: 30px auto;
    width: 150px;
}

.tarot-deck {
    position: relative;
    width: 100%;
    height: 100%;
}

.card-back {
    width: 150px;
    height: 250px;
    background-image: url('card_back.png');
    background-size: cover;
    background-position: center;
    border: 2px solid var(--gold);
    border-radius: 10px;
    position: absolute;
    top: 0; left: 0;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}

.tarot-deck .card-back:nth-child(1) { transform: rotate(-5deg) translateX(-10px); }
.tarot-deck .card-back:nth-child(2) { transform: rotate(0deg); }
.tarot-deck .card-back:nth-child(3) { transform: rotate(5deg) translateX(10px); }

.shuffling .card-back:nth-child(1) { animation: shuffleLeft 0.5s infinite alternate; }
.shuffling .card-back:nth-child(3) { animation: shuffleRight 0.5s infinite alternate; }

@keyframes shuffleLeft {
    to { transform: translateX(-40px) rotate(-15deg); z-index: 10; }
}
@keyframes shuffleRight {
    to { transform: translateX(40px) rotate(15deg); z-index: 10; }
}

/* Card Spread (Horizontal Overlap Rows) */
.card-spread {
    position: relative;
    width: 100%;
    height: auto; 
    margin-top: 40px;
    margin-bottom: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px; /* Vertical space between rows */
}

.card-row {
    display: flex;
    justify-content: center;
    width: 100%;
    max-width: 900px;
}

.pickable-card {
    width: 75px;  
    height: 130px; 
    background-image: url('card_back.png');
    background-size: cover;
    background-position: center;
    border: 2px solid var(--gold);
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s;
    box-shadow: 2px 2px 10px rgba(0,0,0,0.8);
    position: relative;
    margin-left: -40px; /* overlap cards horizontally */
    
    /* Initially hidden, will be animated in */
    opacity: 0;
    animation: spreadFan 1s forwards ease-out;
}

.card-row .pickable-card:first-child {
    margin-left: 0;
}

.pickable-card:hover {
    transform: translateY(-30px) scale(1.2) !important;
    box-shadow: 0 15px 35px var(--gold-glow);
    border-color: #fff;
    z-index: 999 !important; /* Always bring hovered card to front */
}

/* Fix hover flickering by extending the hitbox downwards to cover the gap when the card moves up */
.pickable-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.pickable-card:hover::after {
    /* When card moves up, extend hitbox down significantly so mouse doesn't fall off */
    height: 350px; 
    left: -30px;
    width: calc(100% + 60px);
}

/* Spread Animation for Rows */
@keyframes spreadFan {
    from { 
        opacity: 0; 
        transform: translateY(50px) scale(0.5); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0) scale(1); 
    }
}

/* Result Flip Card */
.result-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
}

@media(min-width: 768px) {
    .result-layout {
        flex-direction: row;
        align-items: flex-start;
        text-align: left;
    }
}

.card-reveal-container {
    perspective: 1000px;
    width: 240px;
    height: 400px;
    margin: 0 auto;
}

.flip-card {
    width: 100%;
    height: 100%;
    transition: transform 1.2s;
    transform-style: preserve-3d;
    cursor: pointer;
}

.flip-card.flipped {
    transform: rotateY(180deg);
}

.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.flip-card-front, .flip-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 10px;
}

.flip-card-front {
    /* Using card-back style */
    width: 100%; height: 100%;
}

.flip-card-back {
    transform: rotateY(180deg);
    background: #fff;
    padding: 10px;
    box-shadow: 0 0 30px rgba(252, 211, 77, 0.5);
}

.flip-card-back img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 5px;
}

/* Result Text */
.glass-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(15px);
    border-radius: 15px;
    padding: 30px;
    flex: 1;
    min-height: 400px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    opacity: 0;
    transition: opacity 1s 0.5s; /* Fade in after flip */
}

.glass-panel.show {
    opacity: 1;
}

#result-title {
    margin-bottom: 5px;
    font-size: 2.2rem;
}

#result-category-label {
    color: #a78bfa;
    margin-bottom: 20px;
    font-weight: 300;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 10px;
}

.result-content-box {
    line-height: 1.8;
    font-size: 1.1rem;
    color: #f1f5f9;
    white-space: pre-wrap; /* To preserve newlines from JSON */
}

.mt-20 {
    margin-top: 40px;
}

/* Loading */
#loading {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(11, 2, 22, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 5px solid rgba(252, 211, 77, 0.2);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

.hidden {
    display: none !important;
}
