body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #3D2B1F; /* Dark Wood Brown */
    color: #F5F5DC; /* Beige */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background-image: url('background_pirate.png'); /* Updated background */
    background-size: cover;
    background-position: center;
    overflow: hidden; /* Hide scrollbars if background is too large */
}

#slot-machine {
    background-color: rgba(60, 40, 20, 0.9); /* Darker, richer brown */
    border: 5px solid #5C4033; /* Dark Brown Wood border */
    border-radius: 20px;
    padding: 20px;
    box-shadow: 
        0 0 30px rgba(218, 165, 32, 0.5), /* Base gold shadow */
        0 0 50px rgba(40, 30, 20, 0.5) inset, /* Inner dark brown shadow */
        /* Base Neon Glow - subtle when off */
        0 0 3px #FFD700, /* Gold subtle */
        0 0 6px #FFD700,
        0 0 9px #DAA520, /* Goldenrod */
        inset 0 0 8px rgba(218, 165, 32, 0.3);
    text-align: center;
    width: 90%;
    max-width: 900px;
    transition: box-shadow 0.4s ease-in-out; /* Smooth transition for neon glow */
}

#slot-machine.neon-glow-active {
    box-shadow: 
        0 0 30px rgba(218, 165, 32, 0.7),
        0 0 50px rgba(40, 30, 20, 0.5) inset,
        /* Active Neon Glow - bright! */
        0 0 8px #fff, /* white core for brightness */
        0 0 15px #FFD700, /* Gold */
        0 0 25px #FFFF00, /* Yellow */
        0 0 35px #DAA520, /* Goldenrod */
        0 0 50px #DAA520,
        inset 0 0 15px rgba(218, 165, 32, 0.6);
}

header h1 {
    font-size: 2.8em;
    color: #FFD700; /* Vibrant Gold */
    text-shadow: 0 0 8px #FF8C00, 0 0 15px #B22222, 0 0 4px #000; /* Orange/Firebrick glow */
    margin-bottom: 20px;
    font-family: 'Luckiest Guy', cursive; /* Adventurous font - fits pirates too */
}

#reels-container {
    display: flex;
    justify-content: center;
    gap: 10px; /* Spacing between reels */
    margin-bottom: 20px;
    padding: 10px;
    background: rgba(0,0,0,0.5); /* Darker contrast for reels */
    border-radius: 10px;
    border: 2px solid #4A3B31; /* Darker wood border */
    position: relative; /* For payline overlay */
}

.reel {
    display: flex;
    flex-direction: column;
    gap: 5px; /* Spacing between symbols in a reel */
    background-color: rgba(20, 10, 5, 0.6); /* Darker brown background for reel itself */
    padding: 5px;
    border-radius: 8px;
    /* overflow: hidden; <-- REMOVED to prevent clipping symbol pop animation if reels were also to overflow */
    box-shadow: inset 0 0 10px rgba(0,0,0,0.6);
}

.symbol-cell {
    width: 100px; 
    height: 100px; 
    background-color: rgba(0,0,0,0.6); /* Dark background for symbols */
    border: 1px solid #5C4033; /* Dark Brown Wood border */
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    /* overflow: hidden; <-- REMOVED to allow pop animation to extend beyond cell bounds */
    transition: outline 0.2s, box-shadow 0.2s, transform 0.2s; /* For winning highlight */
    position: relative; /* For z-index stacking of winning symbols */
    z-index: 1; /* Base z-index */
}

.symbol-cell img {
    width: 90%;
    height: 90%;
    object-fit: contain;
    transition: transform 0.1s ease-out, opacity 0.1s ease-out;
}

.reel.spinning .symbol-cell img {
    animation: spinSymbol 0.1s linear infinite;
}

@keyframes spinSymbol {
    0% { transform: translateY(-15px) scale(0.9); opacity: 0.7; }
    50% { transform: translateY(0px) scale(1); opacity: 1; }
    100% { transform: translateY(15px) scale(0.9); opacity: 0.7; }
}

@keyframes winningSymbolPopEffect {
    0% {
        transform: scale(1);
        box-shadow: none;
        opacity: 1;
    }
    25% {
        transform: scale(1.35); /* Increased pop */
        box-shadow: 0 0 25px #FFD700, 0 0 15px #FFFF00, 0 0 5px #FFF; /* Brighter, more fiery glow */
        opacity: 1;
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 10px #FFD700;
        opacity: 0.95;
    }
    75% {
        transform: scale(1.25); /* Second pop */
        box-shadow: 0 0 20px #FFD700, 0 0 10px #FFFF00;
        opacity: 1;
    }
    100% {
        transform: scale(1.15); /* Settle to a slightly larger highlighted scale */
        box-shadow: 0 0 18px #FFD700, 0 0 8px #FFFF00; /* Maintain strong glow */
        opacity: 1;
    }
}

/* Class for symbol highlight on win */
.winning-symbol { /* This class is added to the symbol-cell */
    z-index: 5 !important; /* Ensure winning symbols pop above others */
    /* outline and outline-offset are now part of the img animation's final state if needed, or applied directly */
}

.winning-symbol img { 
    outline: 3px solid #FFD700; 
    outline-offset: 2px; 
    /* The animation will define transform and box-shadow dynamically */
    animation: winningSymbolPopEffect 1.5s ease-in-out forwards;
}

#controls {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping for smaller screens */
    justify-content: space-around;
    align-items: center;
    margin-bottom: 15px; /* Adjusted margin for action-buttons */
    padding: 10px; /* Reduced padding */
    background-color: rgba(40,25,15,0.5); /* Dark brown tint */
    border-radius: 10px;
}

.info-display {
    font-size: 1.1em; /* Slightly reduced */
    color: #D2B48C; /* Tan */
    margin: 5px 10px; /* Add some margin for spacing */
}

.info-display span:first-child {
    font-weight: bold;
    color: #F0E68C; /* Khaki */
}

.bet-control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bet-adj-button {
    background-color: #CD853F; /* Peru/Brownish */
    color: white;
    border: 1px solid #8B4513; /* SaddleBrown border */
    border-radius: 5px;
    width: 28px;
    height: 28px;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
}

.bet-adj-button:hover {
    background-color: #A0522D; /* Sienna */
}

#action-buttons {
    display: flex;
    justify-content: center;
    gap: 20px; /* Space between Paytable and Spin buttons */
    margin-top: 10px;
}

#paytable-button, #spin-button {
    padding: 12px 25px; /* Slightly smaller */
    font-size: 1.3em; /* Slightly smaller */
    font-weight: bold;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3), inset 0 -2px 2px rgba(255,255,255,0.2), inset 0 2px 2px rgba(0,0,0,0.2);
    transition: background 0.3s ease, transform 0.1s ease;
}

#paytable-button {
    background: linear-gradient(145deg, #708090, #465058); /* SlateGray gradient */
}
#paytable-button:hover {
    background: linear-gradient(145deg, #5a6873, #353c41);
    transform: translateY(-2px);
}

#spin-button {
    background: linear-gradient(145deg, #FF4500, #B22222); /* OrangeRed/Firebrick gradient */
}

#spin-button:hover {
    background: linear-gradient(145deg, #E03D00, #A01F1F);
    transform: translateY(-2px);
}

#paytable-button:active, #spin-button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3), inset 0 -1px 1px rgba(255,255,255,0.2), inset 0 1px 1px rgba(0,0,0,0.2);
}

#spin-button:disabled {
    background: #555;
    cursor: not-allowed;
    opacity: 0.7;
}

#message-display {
    margin-top: 15px;
    font-size: 1.1em;
    color: #FFD700; /* Gold */
    min-height: 20px; 
    position: relative; /* Added for potential relative positioning of other elements if needed */
    z-index: 1; /* Ensure it's not hidden by absolutely positioned elements by default */
}

/* Payline Visualization */
#payline-overlay-container {
    position: absolute;
    top: 10px; /* Match reels-container padding */
    left: 10px; /* Match reels-container padding */
    right: 10px; /* Match reels-container padding */
    bottom: 10px; /* Match reels-container padding */
    pointer-events: none; /* Allow clicks to pass through */
    z-index: 10; /* Above reels, below floating text */
    overflow: visible; /* Important: default is hidden, lines might be clipped */
}

.payline-path {
    position: absolute;
    height: 4px; /* Line thickness */
    background-color: rgba(255, 215, 0, 0.8); /* Gold, semi-transparent */
    opacity: 0;
    transition: opacity 0.3s ease;
    box-shadow: 0 0 8px rgba(255, 215, 0, 1), 0 0 3px white; /* Gold glow */
    border-radius: 2px;
    transform-origin: 0 50%; /* For rotation */
}

.payline-path.active {
    opacity: 1;
}

/* NEW: Styles for Floating Win Amount */
#floating-text-container {
    position: absolute;
    top: 10%; /* Positioned relative to slot-machine, above reels */
    left: 0;
    width: 100%;
    height: 40%; /* Covers a good portion of the reel area height for text to float through */
    pointer-events: none;
    z-index: 20; /* Above paylines and reels */
    overflow: hidden; /* Clip text that floats too far up */
}

.floating-win-text {
    position: absolute;
    font-size: 2.8em; /* Larger for more impact */
    font-weight: bold;
    font-family: 'Luckiest Guy', cursive; /* Match header font for thematic consistency */
    color: #FFD700; /* Gold */
    text-shadow: 
        0 0 4px #FFF, /* White core for brightness */
        0 0 8px #FFD700, 
        0 0 12px #FFD700, 
        0 0 20px #FF8C00, /* Orange/fire glow */
        0 0 30px #B22222; /* Deeper red for outer glow */
    animation: floatUpAndFade 2s ease-out forwards;
    transform: translateX(-50%); /* For horizontal centering based on its own width */
    white-space: nowrap; /* Prevent wrapping if amount is large */
}

@keyframes floatUpAndFade {
    0% {
        opacity: 0;
        transform: translate(-50%, 80px) scale(0.8); /* Start lower, smaller, and invisible */
    }
    20% {
        opacity: 1;
        transform: translate(-50%, 20px) scale(1.1); /* Quickly appear and grow slightly */
    }
    80% {
        opacity: 1;
        transform: translate(-50%, -60px) scale(1); /* Float up */
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -100px) scale(0.9); /* Float further up, shrink and fade out */
    }
}

/* Modal Styles */
.modal {
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.7); /* Darker dim background */
    display: flex; /* For centering modal content */
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #4A3B31; /* Dark Wood Brown for modal */
    margin: auto;
    padding: 20px;
    border: 3px solid #804A00; /* Darker brown border */
    border-radius: 15px;
    width: 80%;
    max-width: 700px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    color: #F5F5DC; /* Beige text */
    position: relative;
}

.close-button {
    color: #ccc;
    float: right; /* Old style, but effective */
    position: absolute; /* Better control */
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
}

.close-button:hover,
.close-button:focus {
    color: #fff;
    text-decoration: none;
    cursor: pointer;
}

.modal-content h2 {
    text-align: center;
    color: #FFD700; /* Gold */
    font-family: 'Luckiest Guy', cursive;
    margin-bottom: 20px;
}

#paytable-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); /* Responsive grid */
    gap: 15px;
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 10px; /* For scrollbar */
}

.paytable-symbol-entry {
    background-color: rgba(30,20,10,0.4); /* Dark brown tint */
    border: 1px solid #654321; /* Dark Oak border */
    border-radius: 8px;
    padding: 10px;
    text-align: center;
}

.paytable-symbol-entry img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    margin-bottom: 8px;
}

.paytable-symbol-entry h4 {
    margin: 5px 0;
    color: #FFEBCD; /* BlanchedAlmond */
    font-size: 1.1em;
}

.paytable-symbol-entry p {
    font-size: 0.9em;
    margin: 3px 0;
    color: #DEB887; /* BurlyWood */
}

.paytable-note {
    font-size: 0.9em;
    text-align: center;
    margin-top: 20px;
    color: #FFEBCD; /* BlanchedAlmond */
}

/* Bonus Modal Styles */
.bonus-modal-content {
    background-color: #5C4033; /* Darker Wood Brown for bonus modal */
    border: 4px solid #DAA520; /* Goldenrod border */
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.7), inset 0 0 20px rgba(0,0,0,0.5);
}

.bonus-modal-content h2 {
    color: #FFD700; /* Gold */
    font-family: 'Luckiest Guy', cursive;
    font-size: 2.5em;
    text-shadow: 0 0 10px #FF8C00;
}

.bonus-modal-content p {
    font-size: 1.2em;
    color: #F5DEB3; /* Wheat */
    margin-bottom: 20px;
}

#bonus-item-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin: 20px 0;
    gap: 15px;
}

.bonus-item {
    width: 120px;
    height: 120px;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative; /* For prize text overlay */
}

.bonus-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.bonus-item:hover:not(.selected):not(.disabled) {
    transform: scale(1.1);
    box-shadow: 0 0 15px #FFD700;
}

.bonus-item.selected img {
    /* Style for the chosen, opened chest */
    /* The image source will change in JS */
}

.bonus-item.disabled {
    opacity: 0.6;
    cursor: default;
}

.bonus-item-prize-text {
    position: absolute;
    bottom: -25px; /* Position below the chest */
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.4em;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 0 0 5px #000;
    background-color: rgba(0,0,0,0.5);
    padding: 3px 8px;
    border-radius: 5px;
    white-space: nowrap;
}

#bonus-result-display {
    font-size: 1.5em;
    color: #FFFFE0; /* LightYellow */
    margin-top: 15px;
    font-weight: bold;
}

#bonus-continue-button {
    background: linear-gradient(145deg, #32CD32, #228B22); /* LimeGreen/ForestGreen gradient */
    color: white;
    padding: 10px 20px;
    font-size: 1.2em;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 20px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
    box-shadow: 0 3px 6px rgba(0,0,0,0.3);
    transition: background 0.3s ease;
}

#bonus-continue-button:hover {
    background: linear-gradient(145deg, #28a428, #1c6f1c);
}

/* Add a jungle font from Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Luckiest+Guy&display=swap');

/* Responsive adjustments */
@media (max-width: 768px) {
    .symbol-cell {
        width: 80px;
        height: 80px;
    }
    #paytable-button, #spin-button {
        padding: 10px 20px;
        font-size: 1.2em;
    }
    header h1 {
        font-size: 2.2em;
    }
    .info-display {
        font-size: 1em;
    }
     .bet-adj-button {
        width: 24px;
        height: 24px;
        font-size: 1em;
    }
    #paytable-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
}

@media (max-width: 600px) {
    #slot-machine {
        padding: 15px;
    }
    #reels-container {
        gap: 5px;
    }
    .symbol-cell {
        width: 60px; 
        height: 60px;
    }
    #controls {
        flex-direction: column;
        gap: 8px;
        padding: 8px;
    }
    .info-display {
        margin: 3px 5px;
    }
    header h1 {
        font-size: 1.8em;
    }
    #paytable-button, #spin-button {
        font-size: 1.1em;
        padding: 8px 15px;
    }
    .modal-content {
        width: 90%;
        padding: 15px;
    }
    #paytable-grid {
       grid-template-columns: 1fr; /* Single column for very small screens */
    }
     .paytable-symbol-entry img {
        width: 50px;
        height: 50px;
    }
}

@media (max-width: 450px) {
    .symbol-cell {
        width: 45px; 
        height: 45px;
    }
     header h1 {
        font-size: 1.5em;
    }
    #paytable-button, #spin-button {
        padding: 8px 12px;
        font-size: 1em;
    }
    .info-display {
        font-size: 0.9em;
    }
    .bet-adj-button {
        width: 22px;
        height: 22px;
        font-size: 0.9em;
    }
}