/* --- Global Styles --- */
:root {
    /* The default darkness is now set in JS, but this can be a fallback */
    --image-darken-amount: rgba(0, 0, 0, 0.0);
}

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: black;
    color: white;
    -webkit-tap-highlight-color: transparent;
}

* {
    box-sizing: border-box;
}


/* --- Loading Spinner --- */
#loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    transition: opacity 0.3s;
}

.spinner {
    border: 5px solid rgba(255, 255, 255, 0.2);
    border-top: 5px solid #4da6ff;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}


/* --- Main Layout --- */
.coaster-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    flex-direction: row;
}

.coaster-side {
    position: relative;
    flex: 1;
    background-size: cover;
    background-position: center;
    transition: filter 0.3s ease;
}

.coaster-side::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, transparent 40%),
        linear-gradient(to bottom, rgba(0, 0, 0, 0.7) 0%, transparent 30%),
        var(--image-darken-amount);
    transition: background 0.3s; /* Smooth transition for darkness change */
}

/* 3. Removes all overlays when darkness is 0% */
body.no-vignette .coaster-side::before {
    background: var(--image-darken-amount);
}


/* --- Text Overlays --- */
.creator-overlay, .name-overlay, .park-overlay, .stat-overlay {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    width: 95%;
    text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.8);
    padding: 0 10px;
}

.creator-overlay {
    top: 10px;
    font-size: 0.8em;
    opacity: 0.7;
}

.name-overlay {
    bottom: 80px;
    font-size: 2em;
    font-weight: bold;
}

.park-overlay {
    bottom: 60px;
    font-size: 1em;
    font-style: italic;
    opacity: 0.9;
}

.stat-overlay {
    bottom: 20px;
    font-size: 1.8em;
    font-weight: 500;
}


/* --- Central Controls --- */
.controls {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    z-index: 10;
    width: 90%;
}

#stat-name {
    font-size: 1.5em;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    text-align: center;
}

.controls button {
    padding: 12px 25px;
    font-size: 1.2em;
    cursor: pointer;
    background: rgba(20, 20, 20, 0.7);
    color: white;
    border: 2px solid white;
    border-radius: 10px;
    transition: background 0.3s, transform 0.2s;
    width: 220px;
    max-width: 100%;
    text-align: center;
}

.controls button:hover {
    background: white;
    color: black;
    transform: scale(1.05);
}


/* --- Scoreboard & UI Icons --- */
#best-score-container, #current-score-container {
    position: absolute;
    font-size: 1.2em;
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 15px;
    border-radius: 10px;
    z-index: 20;
}
#best-score-container {
    top: 20px;
    left: 25px;
}
#current-score-container {
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
}

.ui-icons {
    position: absolute;
    top: 20px;
    right: 25px;
    z-index: 20;
    display: flex;
    gap: 20px;
}

#settings-icon, #leaderboard-icon {
    font-size: 2em;
    cursor: pointer;
    transition: transform 0.3s, color 0.3s;
    color: white;
}
#leaderboard-icon {
    color: #f9d71c;
}

#settings-icon:hover, #leaderboard-icon:hover {
    transform: scale(1.1) rotate(15deg);
}

/* --- Improved Notification --- */
#notification {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    font-size: 5em;
    font-weight: bold;
    text-shadow: 3px 3px 10px black;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
    pointer-events: none;
}

#notification.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* --- Timer Bar --- */
#timer-bar-container {
    width: 220px;
    max-width: 100%;
    height: 8px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
}

#timer-bar {
    width: 100%;
    height: 100%;
    background-color: #39d47a;
    border-radius: 4px;
}


/* --- Modal Styles --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: #282828;
    color: white;
    padding: 25px 35px;
    border-radius: 15px;
    width: 90%;
    max-width: 550px;
    text-align: center;
    position: relative;
    box-shadow: 0 5px 20px rgba(0,0,0,0.5);
    text-shadow: none;
}

.modal-content h2 {
    margin-top: 0;
    color: #4da6ff;
}
.modal-content h2 .fa-trophy {
    color: #f9d71c;
}

.close-button, .close-leaderboard-button {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}


/* --- Leaderboard Modal Specifics --- */
.coming-soon {
    margin: 30px 0;
}
.coming-soon p {
    font-size: 1.5em;
    font-weight: bold;
    margin: 0;
}
.coming-soon span {
    font-size: 1em;
    opacity: 0.8;
}


/* --- Settings Modal Specifics --- */
.setting-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 25px 0;
    font-size: 1.1em;
}

.setting-option label {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
}

.setting-option label small {
    font-size: 0.7em;
    opacity: 0.6;
    font-weight: normal;
    margin-top: 3px;
}

.setting-option select {
    font-size: 1em;
    background: #444;
    color: white;
    border: 1px solid #666;
    border-radius: 5px;
    padding: 5px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    flex-grow: 1;
    margin: 0 15px;
    height: 8px;
    border-radius: 4px;
}

input[type="range"]::-webkit-slider-runnable-track {
    -webkit-appearance: none;
    appearance: none;
    height: 8px;
    border-radius: 4px;
    background: transparent;
}
input[type="range"]::-moz-range-track {
    -moz-appearance: none;
    appearance: none;
    height: 8px;
    border-radius: 4px;
    background: transparent;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    margin-top: -6px;
    background-color: #4da6ff;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    border: 2px solid white;
    transition: background-color 0.2s;
}
input[type="range"]::-webkit-slider-thumb:hover {
    background-color: #8cc8ff;
}
input[type="range"]::-moz-range-thumb {
    border: none;
    border-radius: 50%;
    background-color: #4da6ff;
    height: 20px;
    width: 20px;
    border: 2px solid white;
    transition: background-color 0.2s;
}
input[type="range"]::-moz-range-thumb:hover {
    background-color: #8cc8ff;
}

#timer-value, #darken-value {
    width: 45px;
    text-align: right;
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
}

.github-button {
    display: inline-block;
    text-decoration: none;
    background-color: #333;
    color: white;
    padding: 10px 15px;
    border-radius: 8px;
    transition: background-color 0.3s;
}
.github-button:hover {
    background-color: #555;
}
.github-button i {
    margin-right: 8px;
}

#suggest-coaster-button {
    background-color: #444;
    color: #888;
    padding: 10px 15px;
    border-radius: 8px;
    border: none;
    font-size: 1em;
    cursor: not-allowed;
}

/* Stat Filters */
.stat-filter-container {
    margin-top: 25px;
    text-align: left;
}
.stat-filter-container h3 {
    text-align: center;
    margin-bottom: 15px;
}
.stat-filters {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
.filter-option {
    display: flex;
    align-items: center;
    background: #3e3e3e;
    padding: 8px;
    border-radius: 5px;
}
.filter-option label {
    margin-left: 8px;
    cursor: pointer;
    flex-direction: row;
}
.filter-option input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}
.filter-option input[type="checkbox"]:disabled + label {
    opacity: 0.5;
    cursor: not-allowed;
}
.filter-option input[type="checkbox"]:disabled {
    cursor: not-allowed;
}
.filter-option.disabled {
    background: #333;
    opacity: 0.6;
}

.toggle-switch {
    appearance: none;
    width: 40px;
    height: 22px;
    background-color: #555;
    border-radius: 11px;
    position: relative;
    cursor: pointer;
    transition: background-color 0.3s;
}
.toggle-switch::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: white;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
}
.toggle-switch:checked {
    background-color: #4da6ff;
}
.toggle-switch:checked::before {
    transform: translateX(18px);
}


/* --- Game Over Modal Specifics --- */
.coaster-comparison {
    display: flex;
    justify-content: space-around;
    gap: 15px;
    margin: 25px 0;
}

.coaster-info {
    background-color: #3e3e3e;
    padding: 15px;
    border-radius: 10px;
    width: 48%;
}

.coaster-info h3 {
    margin-top: 0;
    font-size: 1em;
}

.coaster-info a {
    color: #4da6ff;
    text-decoration: none;
    display: inline-block;
    margin-top: 10px;
    font-weight: bold;
}
.coaster-info a:hover {
    text-decoration: underline;
}

.game-over-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
    flex-wrap: wrap;
}

#play-again-button {
    width: auto;
    font-size: 1.1em;
    border: none;
    background: linear-gradient(45deg, #4da6ff, #3b8ee5);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease, filter 0.2s ease;
}
#play-again-button:hover {
    transform: scale(1.05) translateY(-2px);
    filter: brightness(1.1);
    color: white;
}
#play-again-button i {
    margin-right: 8px;
}


#copy-score-button {
    width: auto;
    font-size: 1.1em;
    border: none;
    background-color: #5865F2;
}
#copy-score-button:hover {
    background-color: #4a56d1;
    color: white;
}
#copy-score-button i {
    margin-right: 8px;
}


/* --- Animations --- */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}


/* --- Responsive Design for Mobile --- */
@media (max-width: 768px) {
    .coaster-container {
        flex-direction: column;
        justify-content: space-between;
    }
    
    .coaster-side {
        height: 45vh;
        width: 100vw;
    }

    .controls {
        width: 90%;
        max-width: 350px;
        top: 50%;
        background: none;
        backdrop-filter: none;
        padding: 0;
    }
    
    #stat-name {
        font-size: 1.2em;
        background: rgba(0, 0, 0, 0.5);
    }

    .name-overlay { font-size: 1.3em; bottom: 65px; }
    .park-overlay { font-size: 0.8em; bottom: 45px; }
    .stat-overlay { font-size: 1.2em; }

    .controls button {
        font-size: 1em;
        padding: 10px 20px;
        width: 180px;
    }
    .modal-content {
        width: 95%;
        padding: 20px 15px;
        max-height: 85vh;
        overflow-y: auto;
    }
    .coaster-comparison {
        flex-direction: column;
    }
    .coaster-info {
        width: 100%;
    }
    #notification {
        font-size: 3em;
    }

    #best-score-container {
        top: auto;
        bottom: 15px;
        left: 15px;
        transform: none;
        font-size: 1em;
    }
    #current-score-container {
        left: auto;
        right: 15px;
        bottom: 15px;
        transform: none;
        font-size: 1em;
    }

    .ui-icons {
        right: 15px;
        gap: 15px;
    }
    #settings-icon, #leaderboard-icon {
        font-size: 1.8em;
    }
    .stat-filters {
        grid-template-columns: 1fr;
    }

    /* Reposition text on the TOP coaster to prevent overlap */
    #coaster-left .name-overlay {
        bottom: auto;
        top: 50px;
    }
    #coaster-left .park-overlay {
        bottom: auto;
        top: 80px; 
    }
    #coaster-left .stat-overlay {
        bottom: auto;
        top: 15px;
    }
    #coaster-left .creator-overlay {
        display: none;
    }
}