* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --field-green: #6B8E23;
    --plowed-brown: #8B4513;
    --dirt-dark: #654321;
    --grass-light: #7CB342;
    --tractor-green: #00A000;
    --sky-blue: #87CEEB;
    --text-dark: #2C1810;
    --ui-bg: rgba(255, 248, 235, 0.95);
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(to bottom, var(--sky-blue) 0%, var(--grass-light) 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    color: var(--text-dark);
}

.game-container {
    max-width: 1200px;
    width: 100%;
    background: var(--ui-bg);
    border-radius: 20px;
    box-shadow: 0 10px 40px var(--shadow);
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 3px solid var(--dirt-dark);
}

h1 {
    font-size: 2.5rem;
    color: var(--tractor-green);
    text-shadow: 2px 2px 4px var(--shadow);
    margin-bottom: 15px;
}

.stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--dirt-dark);
    font-weight: 600;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--tractor-green);
}

.game-area {
    position: relative;
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

#gameCanvas {
    border: 5px solid var(--dirt-dark);
    border-radius: 10px;
    background: var(--field-green);
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2);
    max-width: 100%;
    height: auto;
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
    z-index: 10;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    color: white;
    padding: 30px;
    background: rgba(107, 142, 35, 0.9);
    border-radius: 15px;
    border: 3px solid var(--dirt-dark);
    max-width: 90%;
}

#overlayTitle {
    font-size: 2.5rem;
    margin-bottom: 15px;
    color: #FFD700;
    text-shadow: 2px 2px 4px black;
}

#overlayMessage {
    font-size: 1.2rem;
    margin-bottom: 20px;
}

.final-stats {
    margin: 20px 0;
    font-size: 1.1rem;
}

.final-stats.hidden {
    display: none;
}

.final-stats p {
    margin: 10px 0;
}

.game-button {
    background: var(--tractor-green);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 8px var(--shadow);
    margin: 5px;
}

.game-button:hover {
    background: #008800;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px var(--shadow);
}

.game-button:active {
    transform: translateY(0);
}

.game-button.hidden {
    display: none;
}

.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    margin: 20px 0;
}

.control-section {
    flex: 1;
    min-width: 200px;
}

.control-section h3 {
    margin-bottom: 10px;
    color: var(--dirt-dark);
}

.control-info p {
    margin: 5px 0;
    font-size: 0.95rem;
}

.mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.horizontal-controls {
    display: flex;
    gap: 10px;
}

.direction-btn {
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
    background: var(--tractor-green);
    color: white;
    border: 3px solid var(--dirt-dark);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: bold;
}

.direction-btn:hover {
    background: #008800;
    transform: scale(1.1);
}

.direction-btn:active {
    background: #006600;
    transform: scale(0.95);
}

.icon-button {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    background: var(--ui-bg);
    border: 2px solid var(--dirt-dark);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    margin: 0 5px;
}

.icon-button:hover {
    background: var(--grass-light);
    transform: scale(1.1);
}

.info-panel {
    text-align: center;
    padding: 15px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 10px;
    margin-bottom: 20px;
}

.info-panel h3 {
    margin-bottom: 10px;
    color: var(--dirt-dark);
}

.achievements {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
    font-size: 2rem;
}

.achievement {
    opacity: 0.3;
    transition: all 0.3s;
    cursor: help;
}

.achievement.unlocked {
    opacity: 1;
    animation: bounce 0.5s;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Leaderboard */
.leaderboard-panel {
    padding: 15px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 10px;
}

.leaderboard-panel h3 {
    text-align: center;
    margin-bottom: 15px;
    color: var(--dirt-dark);
}

.leaderboard-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
}

#leaderboardPeriod {
    padding: 8px 15px;
    border: 2px solid var(--dirt-dark);
    border-radius: 8px;
    background: white;
    font-size: 0.95rem;
    cursor: pointer;
}

.leaderboard-content {
    max-height: 400px;
    overflow-y: auto;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
}

.leaderboard-table th {
    background: var(--tractor-green);
    color: white;
    padding: 10px;
    text-align: left;
    position: sticky;
    top: 0;
}

.leaderboard-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #ddd;
}

.leaderboard-table tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.5);
}

.leaderboard-table tr:hover {
    background: rgba(124, 179, 66, 0.2);
}

.rank-medal {
    font-size: 1.2rem;
    margin-right: 5px;
}

.loading, .error-message {
    text-align: center;
    padding: 20px;
    color: var(--dirt-dark);
}

.error-message {
    color: #d32f2f;
}

/* Score submission */
.score-submit {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 2px solid rgba(255, 255, 255, 0.3);
}

.score-submit.hidden {
    display: none;
}

#playerName {
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    border: 2px solid var(--dirt-dark);
    border-radius: 8px;
    font-size: 1rem;
    text-align: center;
}

#submitScoreBtn {
    width: 100%;
    margin-bottom: 10px;
}

.submit-message {
    text-align: center;
    font-size: 0.9rem;
    margin-top: 5px;
}

.submit-message.success {
    color: #2e7d32;
}

.submit-message.error {
    color: #d32f2f;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    h1 {
        font-size: 2rem;
    }

    .stats {
        gap: 15px;
    }

    .stat-value {
        font-size: 1.2rem;
    }

    #gameCanvas {
        width: 100%;
        height: auto;
    }

    .mobile-controls {
        display: flex;
    }

    .control-info {
        display: none;
    }

    .controls {
        flex-direction: column;
    }

    #overlayTitle {
        font-size: 2rem;
    }

    .game-button {
        padding: 12px 30px;
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .game-container {
        padding: 10px;
    }

    h1 {
        font-size: 1.5rem;
    }

    .stats {
        gap: 10px;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    .stat-value {
        font-size: 1rem;
    }
}
