body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #1b1e21;
    -webkit-tap-highlight-color: transparent;
}

a {
    color: #ff9900;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    box-sizing: border-box;
    position: relative; /* This makes the container the positioning context for the help button */
}

header {
    text-align: center;
    margin-bottom: 20px;
    color: #ccc;
}

h1 {
    margin: 0;
    color: #ccc;
}

.game-area {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    gap: 14px;
    overflow: hidden;
}

.screenshot-container {
    position: relative;
    height: 50%;
    background-color: rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    width: 100%;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -o-user-select: none;
    user-select: none;
    touch-action: none;
    transition: height 0.3s ease-in-out;
}

.screenshot {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: grab;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    pointer-events: auto;
    -moz-window-dragging: no-drag;
}

.screenshot-transition {
    transition: transform 0.25s ease;
}


.screenshot:active {
    cursor: grabbing;
}

.map-container {
    position: relative;
    height: 50%;
    transition: height 0.3s ease-in-out;
}

#map {
    height: 100%;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Base styles for control buttons */
.screenshot-control-button {
    position: absolute;
    background-color: rgba(27, 30, 33, 0.6);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 5px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    transition: background-color 0.3s;
}

.screenshot-control-button:hover {
    background-color: rgba(27, 30, 33, 0.9);
}

.screenshot-control-button svg {
    width: 100%;
    height: 100%;
    stroke: white;
}

/* Screenshot expand/collapse button position */
#toggle-size-button {
    bottom: 10px;
    left: 10px;
    z-index: 10;
}

/* Map expand/collapse button position */
#toggle-map-size-button {
    top: 10px;
    left: 10px;
    z-index: 1001; /* Position above Leaflet controls */
}


/* Expanded State */
.game-area.screenshot-expanded .screenshot-container {
    height: 80%;
}

.game-area.screenshot-expanded .map-container {
    height: 20%;
}

.game-area.map-expanded .screenshot-container {
    height: 20%;
}

.game-area.map-expanded .map-container {
    height: 80%;
}


.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    gap: 10px;
}

.round-info, .score-info {
    font-size: 1.2rem;
    font-weight: bold;
    color: #ccc;
    flex-shrink: 0;
}

.actions-container {
    display: flex;
    flex-grow: 1;
    justify-content: center;
    gap: 10px;
}

.lifeline-button {
    background-color: #2c3e50;
    border: 1px solid #34495e;
    display: flex;
    align-items: center;
    justify-content: center;
}
.lifeline-button:hover {
    background-color: #34495e;
}
.lifeline-button:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
    opacity: 0.5;
}

.make-guess-button {
    background-color: #27ae60;
}
.make-guess-button:hover {
    background-color: #2ecc71;
}
.make-guess-button:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
}


button {
    background-color: #3a2c5b;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 10px 20px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #ff9900;
}

button:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
}

.results-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1002;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.results-content {
    background-color: #1b1e21;
    padding: 30px;
    border-radius: 10px;
    width: 600px;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    color: #ccc;
}

.results-content button {
    display: block;
    margin: 0 auto;
    margin-top: 20px;
}

.results-header {
    color: #ccc;
    text-align: center;
    margin-bottom: 20px;
}

.results-map {
    height: 400px;
    margin-bottom: 20px;
    border-radius: 10px;
    overflow: hidden;
}

.results-details {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.round-result {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 10px;
    border-left: 5px solid #3498db;
}

.round-score {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 15px;
    color: #ccc;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.round-meta {
    color: #ccc;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.simulator-info {
    display: flex;
    align-items: center;
}

.sim-icon {
    display: inline-block;
    width: 24px;
    height: 24px;
    margin-right: 8px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.sim-icon.msfs2020 {
    background-image: url('msfs2020-icon.png');
}

.sim-icon.msfs2024 {
    background-image: url('msfs2024-icon.png');
}

.flight-info {
    margin-left: 32px;
}

.final-score {
    text-align: center;
    font-size: 2rem;
    font-weight: bold;
    margin: 20px 0;
    color: #ccc;
}

.play-again {
    display: block;
    margin: 20px auto;
    padding: 12px 30px;
    font-size: 1.2rem;
}

.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    font-size: 1.5rem;
    color: white;
}

.spinner {
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 5px solid white;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-right: 15px;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1002;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: #1b1e21;
    color: #ccc;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    max-width: 500px;
    margin: auto;
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 5px;
}

.modal-content p {
    margin: 10px 0;
}

.modal-content button {
    padding: 10px 20px;
    background-color: #3a2c5b;
    color: #fff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.modal-content button:hover {
    background-color: #ff9900;
}

/* Difficulty Modal */
#difficulty-modal .modal-content {
    max-width: 700px;
}
.difficulty-options {
    display: flex;
    gap: 20px;
    margin-top: 20px;
}
.difficulty-option {
    flex: 1;
    padding: 20px;
    border: 2px solid #333;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
}
.difficulty-option:hover {
    border-color: #ff9900;
    background-color: rgba(255, 153, 0, 0.1);
}
.difficulty-option h3 {
    text-align: center;
    margin-top: 0;
    color: #ff9900;
}
.difficulty-option ul {
    padding-left: 20px;
    font-size: 0.9rem;
}


.streaks-container {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    color: #ccc;
}

.streak {
    display: flex;
    align-items: center;
    gap: 10px;
}

.streak:first-child {
    flex: 1;
    justify-content: flex-start;
}

.streak:nth-child(2) {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.streak-label {
    font-weight: bold;
}

.stats-button, .history-button {
    background-color: #3a2c5b;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 8px 15px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background-color 0.3s;
}

.stats-button:hover, .history-button:hover {
    background-color: #ff9900;
}

.stats-toggle-buttons {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
    border: 1px solid #333;
    border-radius: 5px;
    overflow: hidden;
}
.stats-toggle-button {
    flex: 1;
    padding: 10px;
    background-color: transparent;
    color: #ccc;
    border: none;
    border-radius: 0;
    margin: 0 !important;
    transition: background-color 0.3s;
}
.stats-toggle-button.active {
    background-color: #3a2c5b;
    color: white;
}
.stats-toggle-button:not(.active):hover {
    background-color: #2c2c2c;
}


.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin: 20px 0;
}

.stat-item {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}
.casual-stat {
    display: none; /* Hidden by default */
}

.stat-label {
    font-size: 0.9rem;
    color: #ccc;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: #ff9900;
}

.country-match {
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    font-size: 0.9rem;
}

.country-match.correct {
    background-color: rgba(46, 204, 113, 0.2);
    color: #2ecc71;
}

.country-match.incorrect {
    background-color: rgba(231, 76, 60, 0.2);
    color: #e74c3c;
}

.clear-stats-button {
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 10px 20px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
    margin-top: 10px;
}

.clear-stats-button:hover {
    background-color: #c0392b;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.leaflet-control-attribution {
    max-width: 250px;
    max-height: 30px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    transition: max-height 0.3s ease-in-out;
}

.leaflet-control-attribution:hover {
    max-height: 100px;
    overflow: auto;
    white-space: normal;
}

/* --- HISTORY STYLES --- */
.history-content {
    background-color: #1b1e21;
    padding: 30px;
    border-radius: 10px;
    width: 600px;
    max-width: 90%;
    max-height: 90%;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.history-description {
    color: #ccc;
    text-align: center;
    margin-bottom: 20px;
}

.history-games-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 20px;
}

.history-game-card {
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    transition: background-color 0.2s ease-in-out;
    padding: 15px;
}

.history-game-card.active {
    background-color: rgba(255, 255, 255, 0.05);
}

.history-game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    cursor: pointer;
    user-select: none;
    gap: 10px;
}

.history-game-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.history-game-title {
    font-size: 1.2rem;
    font-weight: bold;
    color: #ccc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-game-date {
    font-size: 0.85rem;
    font-weight: normal;
    color: #999;
}

.history-game-meta {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-shrink: 0;
}

.history-game-difficulty {
    font-size: 0.9rem;
    font-weight: bold;
    padding: 3px 8px;
    border-radius: 5px;
}
.history-game-difficulty.casual {
    background-color: #2980b9;
    color: white;
}
.history-game-difficulty.normal {
    background-color: #f39c12;
    color: white;
}

.history-game-score {
    font-size: 1.2rem;
    font-weight: bold;
    color: #ccc;
}

.history-toggle-icon {
    font-size: 1.2rem;
    color: #999;
    transition: transform 0.3s ease-in-out;
}

.history-game-card.active .history-toggle-icon {
    transform: rotate(180deg);
}

.history-game-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out, margin-top 0.4s ease-in-out;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-game-card.active .history-game-details {
    max-height: 1500px; /* Should be enough for 5 rounds */
    margin-top: 15px;
}

.history-round {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 10px;
    border-left: 5px solid #3498db; /* Color is set by JS */
}

.history-round-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
}

.history-round-header .round-score {
    min-width: 0;
    margin-bottom: 0;
}

.lifeline-icons-container {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.lifeline-used-icon {
    font-size: 1.2rem;
    background-color: rgba(0,0,0,0.4);
    padding: 2px 6px;
    border-radius: 5px;
}

.no-history {
    text-align: center;
    padding: 20px;
    color: #ccc;
    font-style: italic;
}
/* --- END HISTORY STYLES --- */


.buttons-container {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.help-button {
    position: absolute;
    top: 20px;
    right: 20px;
    background-color: #3a2c5b;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 10px 20px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
    z-index: 10;
}

.help-button:hover {
    background-color: #ff9900;
}

.actual-marker {
    filter: hue-rotate(152deg);
}

.high-score-message {
    text-align: center;
    color: #f90;
    font-size: 1.5rem;
    font-weight: bold;
    margin: 20px 0;
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    animation: pulse 0.5s infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

.changelog-content {
    background-color: #1b1e21;
    color: #ccc;
    padding: 20px;
    border-radius: 10px;
    width: 30%;
    max-width: 90%;
    max-height: 90%;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.changelog-content h2 {
    text-align: center;
}

.changelog-content p {
    margin-bottom: 10px;
}

.changelog-content ul {
    margin-left: 20px;
    padding-left: 20px;
}

@media (max-width: 768px) {
    .container {
        padding: 10px 5px;
    }

    header {
        margin-bottom: 10px;
    }
    
    header p {
        margin-top: 5px;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    header p img {
        height: 1.2em;
        vertical-align: middle;
        margin: 0 0.25em;
    }

    .help-button {
        top: 15px;
        right: 15px;
        padding: 8px 15px; /* Adjust padding for smaller screens */
    }

    .game-area {
        gap: 10px;
    }

    .screenshot-container, .map-container {
        height: 45vh;
    }

    .game-area.screenshot-expanded .screenshot-container {
        height: 70vh;
    }
    
    .game-area.screenshot-expanded .map-container {
        height: 15vh;
    }

    .game-area.map-expanded .screenshot-container {
        height: 15vh;
    }

    .game-area.map-expanded .map-container {
        height: 70vh;
    }
    
    .screenshot-control-button {
        width: 36px;
        height: 36px;
    }
    
    #toggle-size-button {
        bottom: 8px;
        left: 8px;
    }

    #toggle-map-size-button {
        top: 8px;
        left: 8px;
    }

    .controls {
        display: grid;
        grid-template-areas:
            "round score"
            "actions actions";
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding: 5px;
    }

    .round-info { 
        grid-area: round;
        text-align: left;
        font-size: 1rem;
    }
    .score-info {
        grid-area: score;
        text-align: right;
        font-size: 1rem;
    }

    .actions-container {
        grid-area: actions;
        width: 100%;
        gap: 5px;
    }

    .actions-container .lifeline-button .button-text {
        display: none;
    }

    .actions-container button {
        flex-grow: 1;
        padding: 10px 5px;
        font-size: 1.2rem; /* Make icons a bit bigger */
    }

    #guess-button {
        flex-grow: 2; /* Make guess button wider than others */
    }

    .streaks-container {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 10px;
        padding: 10px 5px;
    }

    .streak:nth-child(2) {
        position: static;
        transform: none;
        justify-content: flex-end;
    }

    .streak {
        flex-basis: calc(50% - 10px);
        font-size: 0.8rem;
    }

    .buttons-container {
        flex-basis: 100%;
        display: flex;
        justify-content: space-between;
        gap: 10px;
    }

    .stats-button, .history-button {
        flex-grow: 1;
    }

    .results-content, .changelog-content {
        width: 95%;
        max-height: 85vh;
        padding: 15px;
    }
    
    .difficulty-options {
        flex-direction: column;
    }

    .results-map {
        height: 200px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .final-score {
        font-size: 1.5rem;
    }

    .flight-info {
        display: flex;
        justify-content: space-around;
        width: 100%;
        margin-left: 0;
        margin-top: 10px;
    }
}
