/* --- Import professional fonts from Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&family=Roboto+Mono:wght@500&display=swap');

/* General Body Styling */
body {
    font-family: 'Poppins', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f4f4f9;
    color: #333;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 50px 0;
    text-align: center;
    user-select: none;
    -webkit-user-select: none; /* For Safari */
    overflow-x: hidden;
}

/* --- Screen Management --- */
#card-selection-screen, #game-screen {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* --- Card Selection Screen --- */
#card-selector {
    display: flex;
    justify-content: center;
    gap: 25px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding: 0 15px;
}

.card-option {
    background-color: white;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(74, 85, 162, 0.1);
    padding: 20px;
    width: 220px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 2px solid transparent;
}
.card-option:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px rgba(74, 85, 162, 0.15);
}
.card-option h3 {
    margin: 0 0 10px 0;
    font-size: 1.5em;
    font-weight: 700;
    color: #34407B;
}
.card-option .cost {
    font-size: 1.2em;
    font-weight: 600;
    color: #4A55A2;
    margin-bottom: 15px;
}
.card-option .top-prize {
    font-size: 0.9em;
    color: #555;
    background-color: #f0f0f5;
    padding: 5px 10px;
    border-radius: 20px;
    display: inline-block;
}

/* --- Game Screen --- */

/* Balance Container Styling */
#balance-container {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    background: #4A55A2;
    color: white;
    padding: 8px 25px;
    border-radius: 0 0 15px 15px;
    font-size: 1.2em;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 100;
}

#balance-amount {
    font-family: 'Roboto Mono', monospace;
}

/* Typography for headings */
h1 { 
    color: #34407B; 
    margin-bottom: 0; 
    font-weight: 700;
    font-size: 2.5em;
}
.subtitle { 
    color: #555; 
    margin-top: 5px; 
    font-weight: 400;
}

/* Wrapper for game and key */
.game-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 30px;
    margin-top: 20px;
}

/* Main Game Container */
#game-container {
    padding: 20px;
    background-color: white;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(74, 85, 162, 0.1);
    width: 450px;
}

/* The Scratchcard Itself */
#scratchcard-container {
    position: relative;
    width: 400px;
    height: 200px;
    margin: 20px auto;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: transform 0.1s ease-out, box-shadow 0.2s ease-out, border 0.2s ease-out;
    -webkit-tap-highlight-color: transparent;
    border: 2px solid transparent; /* Placeholder for win glow */
}

/* Shiny Foil Effect */
#scratchcard-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(100deg, rgba(255, 255, 255, 0) 20%, rgba(255, 255, 255, 0.4) 50%, rgba(255, 255, 255, 0) 80%);
    z-index: 3;
    transform: translateX(-150%);
    animation: shine 3s infinite;
    pointer-events: none;
}
@keyframes shine {
    0% { transform: translateX(-150%); }
    25% { transform: translateX(150%); }
    100% { transform: translateX(150%); }
}

#scratchcard-container.scratching-active {
    transform: scale(0.98) rotate(-0.5deg);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

/* --- VISUAL EFFECTS --- */
.flipping { animation: card-flip 0.5s ease-in-out; }
@keyframes card-flip {
    from { transform: rotateY(0deg); }
    50% { transform: rotateY(90deg); opacity: 0.5; }
    to { transform: rotateY(0deg); }
}

#scratchcard-container.win-glow-border {
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.7), 0 4px 15px rgba(0,0,0,0.1);
    border: 2px solid gold;
}

.confetti {
    position: fixed; width: 10px; height: 10px; opacity: 0.9;
    z-index: 1000; pointer-events: none; animation: fall 3s linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: 0; } }

/* The Scratchable Canvas Layer */
#scratch-canvas {
    position: absolute; top: 0; left: 0; z-index: 2;
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="%23e6b800" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><text x="50%" y="50%" text-anchor="middle" stroke="none" fill="%23e6b800" font-size="12px" dy=".3em">$</text></svg>'), auto;
    transition: opacity 0.5s ease-out; width: 100%; height: 100%; touch-action: none;
}

/* The Hidden Prize Layer & Grid */
#prize-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
    background: linear-gradient(135deg, #e9f0fd, #dbe6f7);
    z-index: 1; visibility: hidden;
}

#prize-grid {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 10px; width: 100%; height: 100%;
    padding: 10px; box-sizing: border-box;
}

.grid-item {
    display: flex; justify-content: center; align-items: center;
    font-size: 2.5em; background-color: rgba(255, 255, 255, 0.5);
    border-radius: 8px; box-shadow: inset 0 0 5px rgba(0,0,0,0.1);
    line-height: 1; overflow: hidden;
}

.win-animation .grid-item.winning-symbol { animation: win-glow 1.5s ease-in-out infinite alternate; }
@keyframes win-glow {
    from { transform: scale(1); }
    to { transform: scale(1.2); filter: drop-shadow(0 0 10px #ffbf00); }
}

/* Prize Key Styling */
#prize-key { 
    background-color: white; padding: 10px 20px; border-radius: 15px; 
    box-shadow: 0 8px 25px rgba(74, 85, 162, 0.1); 
}
#prize-key h2 { 
    margin-top: 5px; color: #34407B; font-size: 1.2em; font-weight: 700;
}
.key-item { 
    display: grid; grid-template-columns: auto 1fr auto; align-items: center;
    gap: 15px; padding: 8px 0; font-size: 1.1em; border-bottom: 1px solid #eee; 
}
.key-item:last-child { border-bottom: none; }
.key-symbols { letter-spacing: 2px; }
.key-prize {
    font-family: 'Roboto Mono', monospace; font-weight: 500;
    color: #333; text-align: right;
}
.key-wins {
    font-size: 0.8em; font-weight: 400; color: #667; background-color: #f0f0f5;
    padding: 2px 6px; border-radius: 5px; white-space: nowrap; font-style: italic;
}

/* Results & Buttons */
.button-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}
#results-container { margin-top: 20px; }
#result-message { font-size: 24px; font-weight: 600; margin: 10px 0; }
#result-message.win { color: #10b981; }
#result-message.lose { color: #ef4444; }
#probability-text { font-size: 14px; color: #666; margin-top: 5px; }

#play-again-btn, #reset-balance-btn, #change-card-btn {
    padding: 12px 25px; font-size: 16px; font-weight: 600; color: white;
    border: none; border-radius: 25px; cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    letter-spacing: 0.5px;
}
#play-again-btn:hover, #reset-balance-btn:hover, #change-card-btn:hover {
    transform: translateY(-2px); box-shadow: 0 6px 15px rgba(0, 0, 0, 0.15);
}
#play-again-btn:active, #reset-balance-btn:active, #change-card-btn:active {
    transform: translateY(0px) scale(0.98); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

#play-again-btn { background: linear-gradient(45deg, #536DFE, #3D5AFE); }
#reset-balance-btn { background: linear-gradient(45deg, #FF7043, #F4511E); }
#change-card-btn { background: linear-gradient(45deg, #66BB6A, #4CAF50); }

.hidden { display: none !important; }

/* Disclaimer Footer */
#disclaimer { position: fixed; bottom: 0; left: 0; width: 100%; background-color: rgba(0, 0, 0, 0.7); color: #ddd; padding: 5px 0; font-size: 12px; z-index: 50; }
#disclaimer p { margin: 0; }

/* --- Media Query for Mobile Responsiveness --- */
@media (max-width: 800px) {
    body { padding-top: 70px; }
    .game-wrapper {
        flex-direction: column; align-items: center;
        gap: 25px; width: 95%; margin-top: 10px;
    }
    #game-container, #prize-key {
        width: 100%; max-width: 450px; padding: 15px; box-sizing: border-box;
    }
    #scratchcard-container {
        width: 100%; height: auto; aspect-ratio: 2 / 1; margin: 15px auto;
    }
    h1 { font-size: 1.7em; }
    .subtitle { font-size: 0.9em; padding: 0 10px; }
    .grid-item { font-size: 2.2em; }
}

@media (max-width: 750px) {
    #card-selector { flex-direction: column; align-items: center; }
    .card-option { width: 80%; max-width: 300px; }
}