body {
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(to bottom right, #1e3c72, #2a5298);
    font-family: 'Press Start 2P', cursive;
    color: #fff;
    overflow: hidden;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 20px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
    max-width: 90vw;
}

.game-header {
    text-align: center;
    margin-bottom: 30px;
    width: 100%;
}

.game-title {
    text-shadow: 4px 4px 0px #ff6b6b;
    margin-bottom: 15px;
    font-size: 3.5rem;
    letter-spacing: 3px;
}

.score-container {
    background: #333;
    padding: 15px 25px;
    border-radius: 10px;
    font-size: 1.8rem;
    border: 3px solid #4169E1;
    box-shadow: 0 0 15px rgba(65, 105, 225, 0.7);
}

#game-board {
    display: grid;
    grid-template-rows: repeat(20, 30px);
    grid-template-columns: repeat(30, 30px);
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><rect width="20" height="20" fill="%23202830"/><path d="M 0,10 H 20" stroke="%23363d47" stroke-width="1"/><path d="M 10,0 V 20" stroke="%23363d47" stroke-width="1"/></svg>');
    background-size: 30px 30px;
    background-color: #202830;
    border: 8px solid #444;
    border-radius: 10px;
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.5);
}

/* Train styles - Locomotive (head) */
.train-locomotive {
    background: linear-gradient(to bottom, #d32f2f, #b71c1c);
    border-radius: 6px;
    box-shadow: 0 0 8px #ff5252;
    position: relative;
    z-index: 2;
}

.train-locomotive::before {
    content: '';
    position: absolute;
    background-color: black;
    width: 8px;
    height: 4px;
    border-radius: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

.train-locomotive::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 6px;
    background: #ffeb3b;
    border-radius: 50%;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 0 10px #ffeb3b;
}

/* Train styles - Wagon (body) */
.train-wagon {
    background: linear-gradient(to bottom, #1976d2, #0d47a1);
    position: relative;
    border-radius: 4px;
    border: 1px solid #2196f3;
    box-sizing: border-box;
}

.train-wagon::after {
    content: '';
    position: absolute;
    background-color: #e1f5fe;
    width: 6px;
    height: 6px;
    border-radius: 2px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.7;
}

/* Special cars with different colors based on position */
.train-wagon:nth-child(3n) {
    background: linear-gradient(to bottom, #388e3c, #1b5e20);
    border-color: #4caf50;
}

.train-wagon:nth-child(3n)::after {
    background-color: #e8f5e9;
}

.train-wagon:nth-child(5n) {
    background: linear-gradient(to bottom, #ffa000, #ff6f00);
    border-color: #ffc107;
}

.train-wagon:nth-child(5n)::after {
    background-color: #fff8e1;
}

/* Smoke effect from locomotive */
@keyframes smoke {
    0% {
        transform: translate(0, 0) scale(0.5);
        opacity: 0.9;
    }
    100% {
        transform: translate(-10px, -20px) scale(1.5);
        opacity: 0;
    }
}

.smoke {
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    top: -10px;
    right: -5px;
    animation: smoke 2s infinite;
}

.food {
    background: radial-gradient(circle at 30% 30%, #ffeb3b, #fbc02d);
    border-radius: 2px;
    box-shadow: 0 0 12px rgba(255, 235, 59, 0.7);
    position: relative;
}

.food::before, .food::after {
    content: '';
    position: absolute;
    background: #000;
    width: 80%;
    height: 2px;
    left: 10%;
}

.food::before {
    top: 30%;
}

.food::after {
    bottom: 30%;
}

.controls-info {
    margin-top: 25px;
    color: #ddd;
    font-size: 1rem;
    background: rgba(0, 0, 0, 0.5);
    padding: 15px;
    border-radius: 10px;
    width: 80%;
    text-align: center;
}

.speed-control {
    margin-top: 15px;
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 0.9rem;
}

#speed-slider {
    width: 150px;
    cursor: pointer;
}

.hidden {
    display: none;
}

#game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 50px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 0 30px rgba(255, 0, 0, 0.7);
    border: 5px solid #ff5722;
    animation: appear 0.5s ease-out;
    font-size: 1.5rem;
}

#restart-button {
    padding: 20px 40px;
    background-color: #4caf50;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.5rem;
    font-family: 'Press Start 2P', cursive;
    margin-top: 30px;
    transition: all 0.2s;
    box-shadow: 0 6px 0 #388e3c;
}

#restart-button:hover {
    background-color: #45a049;
    transform: translateY(2px);
    box-shadow: 0 4px 0 #388e3c;
}

#restart-button:active {
    transform: translateY(6px);
    box-shadow: none;
}

@keyframes pulse {
    0% {
        transform: scale(0.8);
    }
    100% {
        transform: scale(1.1);
    }
}

@keyframes appear {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes grow {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.5);
    }
    100% {
        transform: scale(1);
    }
}

.cell {
    transition: all 0.1s;
}

.cell.eaten {
    animation: grow 0.3s ease-out;
}

@keyframes shake {
    0%, 100% { 
        transform: translateX(0); 
    }
    10%, 30%, 50%, 70%, 90% { 
        transform: translateX(-10px); 
    }
    20%, 40%, 60%, 80% { 
        transform: translateX(10px); 
    }
}

.shake {
    animation: shake 0.5s;
}

/* Media query for different screen sizes */
@media (max-height: 900px) {
    #game-board {
        grid-template-rows: repeat(20, 25px);
        grid-template-columns: repeat(30, 25px);
        background-size: 25px 25px;
    }
    
    .game-title {
        font-size: 2.5rem;
    }
    
    .score-container {
        font-size: 1.4rem;
    }
}

@media (max-height: 700px) {
    #game-board {
        grid-template-rows: repeat(20, 20px);
        grid-template-columns: repeat(30, 20px);
        background-size: 20px 20px;
    }
    
    .game-title {
        font-size: 2rem;
    }
}
