:root {
    --bg-core: #0a0b0d;
    --bg-surface: #15191d;
    --primary: #f59e0b;
    --primary-glow: rgba(245, 158, 11, 0.2);
    --text-main: #e2e8f0;
    --text-dim: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);

    /* Rarity Colors */
    --common-base: #64748b;
    --rare-base: #3b82f6;
    --epic-base: #a855f7;
    --legendary-base: #eab308;
    --legendary-glow: #f59e0b;
}

body {
    margin: 0;
    font-family: 'Space Grotesk', sans-serif;
    background-color: var(--bg-core);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 40px 20px;
}

.container {
    width: 100%;
    max-width: 800px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 40px;
    border-radius: 12px;
    position: relative;
    text-align: center;
    /* Subtle noise texture */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.05'/%3E%3C/svg%3E");
}

.container::before {
    content: "MODULE // 02 // LUCK_ENGINE";
    position: absolute;
    top: -24px;
    left: 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--primary);
    letter-spacing: 1px;
}

.back-link {
    display: block;
    text-align: left;
    margin-bottom: 24px;
    text-decoration: none;
    color: var(--text-dim);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: -1px;
}

p {
    color: var(--text-dim);
    margin-bottom: 40px;
    font-family: 'JetBrains Mono', monospace;
}

#tries-left {
    color: var(--primary);
    font-weight: 700;
}

/* Control Panel */
.controls {
    margin-top: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

#draw-button {
    padding: 20px 60px;
    font-size: 1.2rem;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    background: var(--primary);
    color: var(--bg-core);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: 0 0 30px var(--primary-glow);
    transition: 0.3s;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
}

#draw-button::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 60%);
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.3s, transform 0.3s;
}

#draw-button:hover:not(:disabled)::after {
    opacity: 1;
    transform: scale(1);
}

#draw-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 40px var(--primary-glow);
}

#draw-button:disabled {
    background: #334155;
    color: var(--text-dim);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

/* 3D Card Stage */
#result-display {
    height: 350px;
    /* Pre-allocate space */
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1200px;
}

.card {
    width: 240px;
    height: 340px;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

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

.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: #1e293b;
    border: 1px solid var(--border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.card-front {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    color: var(--bg-surface);
}

.card-logo {
    font-size: 5rem;
    font-weight: 800;
    opacity: 0.1;
    animation: pulse 2s infinite;
}

.card-back {
    transform: rotateY(180deg);
    padding: 20px;
    background-size: cover;
    background-position: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    overflow: hidden;
}

/* Rarity Styles for Card Back */

/* Common */
.card-back.rarity-common {
    background: linear-gradient(to bottom right, #334155, #1e293b);
    border: 2px solid var(--common-base);
}

.rarity-common h3 {
    color: var(--common-base);
}

/* Rare */
.card-back.rarity-rare {
    background: linear-gradient(to bottom right, #1e3a8a, #0f172a);
    border: 2px solid var(--rare-base);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.4);
}

.rarity-rare h3 {
    color: #60a5fa;
    text-shadow: 0 0 10px rgba(59, 130, 246, 0.8);
}

/* Epic */
.card-back.rarity-epic {
    background: radial-gradient(circle at center, #581c87 0%, #3b0764 100%);
    border: 2px solid var(--epic-base);
    box-shadow: 0 0 30px rgba(168, 85, 247, 0.6);
}

.rarity-epic::after {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1h2v2H1V1zm4 0h2v2H5V1zm4 0h2v2H9V1z' fill='%23a855f7' fill-opacity='0.1'/%3E%3C/svg%3E");
    opacity: 0.3;
}

.rarity-epic h3 {
    color: #d8b4fe;
    text-shadow: 0 0 15px rgba(168, 85, 247, 1);
}

/* Legendary */
.card-back.rarity-legendary {
    background: radial-gradient(circle at top, #fcd34d 0%, #b45309 60%, #451a03 100%);
    border: 3px solid var(--legendary-base);
    box-shadow: 0 0 50px rgba(245, 158, 11, 0.6), inset 0 0 20px rgba(255, 255, 255, 0.2);
    animation: legendaryGlow 3s infinite alternate;
}




.rarity-legendary h3 {
    color: #fffbeb;
    text-shadow: 0 0 10px #b45309, 0 0 20px #f59e0b;
    font-size: 1.1rem;
}

/* Card Typography */
.card-back h3 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    margin-bottom: auto;
    margin-top: 10px;
    letter-spacing: 2px;
    z-index: 2;
}

.card-back p {
    font-size: 1.6rem;
    font-weight: 800;
    color: white;
    z-index: 2;
    text-align: center;
    line-height: 1.2;
    margin-bottom: auto;
}

/* Animations */
@keyframes pulse {

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

    50% {
        transform: scale(1.1);
        opacity: 0.2;
    }
}

@keyframes legendaryGlow {
    0% {
        box-shadow: 0 0 30px rgba(245, 158, 11, 0.5);
    }

    100% {
        box-shadow: 0 0 60px rgba(245, 158, 11, 0.9), 0 0 20px var(--legendary-glow);
    }
}

/* Inventory Grid */
.collection {
    margin-top: 60px;
    padding-top: 40px;
    border-top: 1px solid var(--border);
}

.collection h2 {
    font-size: 1.5rem;
    margin-bottom: 30px;
    text-transform: uppercase;
    color: var(--text-dim);
}

.collection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
}

.collection-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    padding: 15px;
    border-radius: 8px;
    transition: 0.3s;
    position: relative;
    overflow: hidden;
}

.collection-card:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.05);
}

.collection-card h3 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: var(--text-dim);
    margin-bottom: 8px;
    text-transform: uppercase;
}

.collection-card p {
    font-size: 0.9rem;
    color: white;
    margin: 0;
    font-family: inherit;
    font-weight: 700;
}

.unlocked-common {
    border-left: 3px solid var(--common-base);
}

.unlocked-rare {
    border-left: 3px solid var(--rare-base);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.1);
}

.unlocked-epic {
    border-left: 3px solid var(--epic-base);
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.15);
}

.unlocked-legendary {
    border-left: 3px solid var(--legendary-base);
    background: linear-gradient(to right, rgba(234, 179, 8, 0.1), transparent);
    box-shadow: 0 0 20px rgba(234, 179, 8, 0.2);
}

/* Probability Jokbo */
.probability-registry {
    margin-top: 60px;
    padding-top: 40px;
    border-top: 1px dashed var(--border);
}

.probability-registry h3 {
    font-size: 1.2rem;
    color: var(--text-dim);
    margin-bottom: 30px;
}

.jokbo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
}

.jokbo-item {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: 0.3s;
}

.jokbo-item:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateY(-2px);
}

.thumb-frame {
    width: 100px;
    height: 140px;
    background-color: #000;
    background-size: cover;
    background-position: center;
    border-radius: 6px;
    margin-bottom: 15px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.jokbo-info {
    text-align: center;
}

.j-rarity {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.j-rate {
    display: block;
    font-size: 0.9rem;
    color: var(--text-dim);
}

/* Rarity Colors for Jokbo */
.jokbo-item.rarity-legendary .j-rarity {
    color: var(--legendary-base);
}

.jokbo-item.rarity-epic .j-rarity {
    color: var(--epic-base);
}

.jokbo-item.rarity-rare .j-rarity {
    color: var(--rare-base);
}

.jokbo-item.rarity-common .j-rarity {
    color: var(--common-base);
}

.hidden {
    display: none !important;
}

/* Update Card Backs to use Images */
.card-back.rarity-common {
    background-image: url('images/card_common.png') !important;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
}

.card-back.rarity-rare {
    background-image: url('images/card_rare.png') !important;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
}

.card-back.rarity-epic {
    background-image: url('images/card_epic.png') !important;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
}

.card-back.rarity-legendary {
    background-image: url('images/card_legendary.png') !important;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
}