:root {
    --primary: #2e4057;
    --secondary: #4f5d75;
    --accent: #ef8354;
    --success: #5cb85c;
    --danger: #d9534f;
    --background: #f7f7f2;
    --text: #2d3142;
    --sea-blue: #a8ddf0;
    --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --border-radius: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--background);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 10px;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

header {
    text-align: center;
    padding: 10px 0;
}

h1 {
    color: var(--primary);
    margin-bottom: 10px;
    font-size: 2rem;
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.5rem;
    }
    body {
        padding: 5px;
    }
    .container {
        gap: 10px;
    }
}

.subtitle {
    color: var(--secondary);
    font-size: 1.1rem;
}

.game-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

@media (min-width: 768px) {
    .game-container {
        flex-direction: row;
    }
    h1 {
        font-size: 2.5rem;
    }
}

@media (max-width: 767px) {
    .game-container {
        flex-direction: column;
    }

    .map-container {
        height: 45vh;
        min-height: 300px;
        width: 100%;
    }

    .game-panel {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .game-mode-grid {
        grid-template-columns: 1fr;
    }

    .map-container {
        height: 40vh;
        min-height: 250px;
    }
}

.map-container {
    flex: 3;
    height: 60vh;
    min-height: 250px;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--box-shadow);
    position: relative;
    z-index: 0;
}

#map {
    height: 100%;
    width: 100%;
    background-color: var(--sea-blue); /* Color the seas blue */
}

.confirm-button-container {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: none;
}

.game-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 15px;
    background-color: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

.welcome-screen, .mode-selection-screen, .multiplayer-screen, .join-screen, .create-game-screen {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
    justify-content: center;
    padding: 20px 15px;
    text-align: center;
}

.welcome-buttons, .mode-buttons, .game-mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 300px;
}

.game-mode-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 400px;
}

.city-display {
    text-align: center;
    padding: 12px;
    background-color: var(--primary);
    color: white;
    border-radius: var(--border-radius);
}

.city-name {
    font-size: 1.4rem;
    font-weight: bold;
    margin-bottom: 5px;
    word-break: break-word;
}

.timer-display {
    font-size: 1.2rem;
    margin-top: 5px;
    color: #fff;
    background-color: var(--secondary);
    padding: 5px 10px;
    border-radius: 4px;
    display: inline-block;
}

.instructions {
    background-color: #e8e8e8;
    padding: 12px;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
}

.result {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background-color: #f0f0f0;
    border-radius: var(--border-radius);
    align-items: center;
    justify-content: center;
}

.result-countdown {
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    from { opacity: 0.8; }
    to { opacity: 1; }
}

.distance {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--accent);
}

.stats {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 8px 0;
    border-top: 1px solid #e0e0e0;
}

.stats-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stats-value {
    font-size: 1.2rem;
    font-weight: bold;
}

button {
    width: 100%;
    padding: 12px;
    background-color: var(--accent);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s ease;
    margin-bottom: 8px;
}

button:hover {
    background-color: #e67242;
}

button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

button.success {
    background-color: var(--success);
}

button.success:hover {
    background-color: #4cae4c;
}

button.danger {
    background-color: var(--danger);
}

button.danger:hover {
    background-color: #c9302c;
}

.popup-content {
    text-align: center;
}

/* Home button */
.home-button {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 40px;
    height: 40px;
    background-color: white;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    font-size: 1.2rem;
    padding: 0;
}

.home-button:hover {
    background-color: #f0f0f0;
}

/* Create game form */
.create-game-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 400px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    text-align: left;
}

.form-group label {
    font-weight: bold;
    color: var(--secondary);
}

.form-control {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: var(--border-radius);
    font-size: 1rem;
}

/* Leaderboard and Player list */
.leaderboard, .player-list {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 0.9rem;
}

.leaderboard th, .leaderboard td,
.player-list th, .player-list td {
    padding: 8px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

.leaderboard th, .player-list th {
    background-color: var(--secondary);
    color: white;
}

/* Enhanced leaderboard styling */
#leaderboardContainer {
    margin-top: 15px;
    background-color: #f8f8f8;
    border-radius: var(--border-radius);
    padding: 10px;
    box-shadow: var(--box-shadow);
}

#leaderboardContainer h3 {
    color: var(--primary);
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.leaderboard {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.leaderboard th {
    background-color: var(--secondary);
    color: white;
    padding: 8px 5px;
    text-align: left;
    font-size: 0.85rem;
}

.leaderboard td {
    padding: 6px 5px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

.leaderboard tr:last-child td {
    border-bottom: none;
}

.leaderboard tr.current-player {
    font-weight: bold;
    background-color: rgba(239, 131, 84, 0.1);
}

.leaderboard .rank-column {
    width: 30px;
    text-align: center;
}

/* Mobile optimizations for leaderboard */
@media (max-width: 480px) {
    #leaderboardContainer {
        padding: 8px;
        margin-top: 10px;
    }

    .leaderboard th, .leaderboard td {
        padding: 5px 3px;
        font-size: 0.8rem;
    }
}

.player-marker {
    display: flex;
    align-items: center;
    gap: 5px;
}

.marker-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.waiting-room {
    width: 100%;
    max-width: 500px;
    margin-top: 20px;
}

.waiting-players {
    margin-top: 10px;
}

.player-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background-color: #f8f8f8;
    margin-bottom: 5px;
    border-radius: 4px;
}

.player-item.host {
    font-weight: bold;
}

.player-status {
    display: flex;
    align-items: center;
    gap: 5px;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #ccc;
}

.status-indicator.guessed {
    background-color: var(--success);
}

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    display: none;
}

.modal {
    background-color: white;
    border-radius: var(--border-radius);
    padding: 20px;
    max-width: 500px;
    width: 90%;
    box-shadow: var(--box-shadow);
}

.modal-header {
    margin-bottom: 15px;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.modal-body {
    margin-bottom: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-footer button {
    margin: 0;
    width: auto;
    padding: 8px 15px;
}

.code-display {
    font-size: 2rem;
    letter-spacing: 3px;
    padding: 15px;
    background-color: #f0f0f0;
    border-radius: var(--border-radius);
    text-align: center;
    margin: 20px 0;
    font-weight: bold;
}

/* Game screens */
.game-screens > div {
    display: none;
}

.game-screens > div.active {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.current-player {
    margin: 10px 0;
    padding: 8px;
    background-color: var(--primary);
    color: white;
    border-radius: var(--border-radius);
}

.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 30px;
}

.spinner {
    border: 5px solid rgba(0, 0, 0, 0.1);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border-left-color: var(--accent);
    animation: spin 1s linear infinite;
}

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

@media (max-width: 480px) {
    body {
        padding: 5px;
        overflow-x: hidden;
    }

    .container {
        padding: 0;
        width: 100%;
        max-width: 100%;
    }

    .game-container {
        gap: 10px;
    }

    .map-container, #map {
        border-radius: 6px;
        height: 40vh !important;
        min-height: 250px !important;
        width: 100% !important;
        display: block !important;
    }

    .game-panel {
        padding: 10px;
        width: 100%;
    }

    button {
        padding: 10px;
        font-size: 0.95rem;
    }

    .city-name {
        font-size: 1.1rem;
    }

    .modal {
        width: 95%;
        padding: 15px 10px;
    }
}