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

body {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
    min-height: 100vh;
    padding: 20px;
    padding-bottom: 100px; /* Добавлено для мобильных кнопок */
}

.back-home {
    position: fixed;
    top: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    text-decoration: none;
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    z-index: 1000;
}

.back-home:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.game-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.game-header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.game-header h1 {
    font-size: 3.5rem;
    background: linear-gradient(45deg, #00b4d8, #90e0ef);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.game-header p {
    color: #90e0ef;
    font-size: 1.2rem;
    opacity: 0.8;
}

.game-board {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
}

#gameCanvas {
    background: #0d1b2a;
    border-radius: 10px;
    border: 3px solid #1b263b;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.game-controls {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

.btn {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 140px;
    justify-content: center;
}

.btn-start {
    background: linear-gradient(135deg, #00b4d8, #0077b6);
    color: white;
}

.btn-pause {
    background: linear-gradient(135deg, #ffb703, #fb8500);
    color: white;
}

.btn-restart {
    background: linear-gradient(135deg, #9d4edd, #5a189a);
    color: white;
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* КОМПАКТНЫЕ МОБИЛЬНЫЕ КНОПКИ - ИСПРАВЛЕНО */
.mobile-controls {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 0 20px;
}

.mobile-controls-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
    max-width: 300px;
    margin: 0 auto;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 15px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.mobile-btn {
    width: 100%;
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: all 0.2s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.mobile-btn:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.9);
}

/* Позиционирование кнопок в сетке */
#upBtn {
    grid-column: 3;
    grid-row: 1;
}

#leftBtn {
    grid-column: 2;
    grid-row: 2;
}

#downBtn {
    grid-column: 3;
    grid-row: 2;
}

#rightBtn {
    grid-column: 4;
    grid-row: 2;
}

/* Центральная кнопка паузы */
#mobilePauseBtn {
    grid-column: 3;
    grid-row: 3;
    background: rgba(255, 180, 3, 0.2);
    border-color: rgba(255, 180, 3, 0.3);
}

#mobilePauseBtn:active {
    background: rgba(255, 180, 3, 0.3);
}

.game-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 30px;
}

.score-panel,
.controls-panel,
.settings-panel {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

h3 {
    color: #90e0ef;
    margin-bottom: 20px;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.score-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.score-item:last-child {
    border-bottom: none;
}

.score-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
}

.score-value {
    font-size: 1.8rem;
    font-weight: bold;
    color: #00b4d8;
}

.control-keys {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.key-row {
    display: flex;
    gap: 10px;
}

.key {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.setting {
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting label {
    display: flex;
    align-items: center;
    gap: 10px;
}

select {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 8px 15px;
    border-radius: 6px;
    cursor: pointer;
    min-width: 150px;
}

select option {
    background: #1a1a2e;
}

.game-over {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.game-over-content {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    border: 2px solid #00b4d8;
    max-width: 500px;
    width: 90%;
}

.game-over h2 {
    font-size: 3rem;
    color: #ff6b6b;
    margin-bottom: 20px;
}

.game-over-score {
    font-size: 4rem;
    font-weight: bold;
    color: #00b4d8;
    margin: 20px 0;
}

.back-link {
    display: inline-block;
    margin-top: 20px;
    color: #90e0ef;
    text-decoration: none;
    font-size: 1.1rem;
    transition: color 0.3s ease;
}

.back-link:hover {
    color: #00b4d8;
}

/* RESPONSIVE */
@media (max-width: 768px) {
    body {
        padding: 10px;
        padding-bottom: 120px; /* Увеличено для мобильных кнопок */
    }
    
    .game-header h1 {
        font-size: 2.2rem;
        margin-top: 40px;
    }
    
    .back-home {
        top: 10px;
        left: 10px;
        padding: 8px 15px;
        font-size: 0.9rem;
    }
    
    #gameCanvas {
        width: 95vw;
        height: 95vw;
        max-width: 450px;
        max-height: 450px;
    }
    
    .mobile-controls {
        display: block;
    }
    
    .game-info {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .game-controls {
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }
    
    .btn {
        min-width: 120px;
        padding: 10px 20px;
        font-size: 1rem;
    }
    
    .score-panel,
    .controls-panel,
    .settings-panel {
        padding: 15px;
    }
    
    .score-value {
        font-size: 1.5rem;
    }
    
    .game-over-content {
        padding: 30px 20px;
    }
    
    .game-over h2 {
        font-size: 2.5rem;
    }
    
    .game-over-score {
        font-size: 3rem;
    }
}

@media (max-width: 480px) {
    .mobile-controls-grid {
        max-width: 250px;
        padding: 10px;
    }
    
    .mobile-btn {
        font-size: 1.2rem;
    }
    
    .game-header h1 {
        font-size: 1.8rem;
    }
    
    .btn {
        min-width: 100px;
        font-size: 0.9rem;
    }
}

/* Snake Game Specific Styles - ОСТАВЛЕНО БЕЗ ИЗМЕНЕНИЙ */

:root {
    /* Color themes */
    --classic-snake: #4CAF50;
    --classic-food: #FF5252;
    --classic-bg: #0d1b2a;
    
    --dark-snake: #BB86FC;
    --dark-food: #03DAC6;
    --dark-bg: #121212;
    
    --green-snake: #00FF88;
    --green-food: #FF4081;
    --green-bg: #0A1929;
    
    --retro-snake: #FF6B6B;
    --retro-food: #4ECDC4;
    --retro-bg: #292F36;
}

/* Theme-specific canvas backgrounds */
.canvas-classic {
    background: var(--classic-bg) !important;
}

.canvas-dark {
    background: var(--dark-bg) !important;
}

.canvas-green {
    background: var(--green-bg) !important;
}

.canvas-retro {
    background: var(--retro-bg) !important;
}

/* Grid lines */
.grid-lines {
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Game stats animation */
.score-value, .level {
    transition: all 0.3s ease;
}

.score-value.increase {
    animation: scoreBounce 0.5s ease;
}

@keyframes scoreBounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* Snake segment animation */
.snake-segment {
    transition: transform 0.1s ease;
}

/* Food animation */
.food {
    animation: pulse 1.5s infinite;
}

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

/* Level up animation */
.level-up {
    animation: levelUp 1s ease;
}

@keyframes levelUp {
    0% { transform: scale(1); }
    50% { transform: scale(1.5); color: #FFD700; }
    100% { transform: scale(1); }
}

/* Control keys hover effect */
.key {
    transition: all 0.2s ease;
}

.key:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

/* Speed indicator */
.speed-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-left: 5px;
    background: #4CAF50;
}

.speed-fast .speed-indicator {
    background: #FF5252;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Game instructions */
.instructions {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 10px;
    margin-top: 20px;
    font-size: 0.9rem;
    opacity: 0.8;
}

.instructions ul {
    list-style: none;
    padding-left: 0;
}

.instructions li {
    margin: 8px 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.instructions i {
    color: #00b4d8;
}
.close-game-over {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    z-index: 10;
}

.close-game-over:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.close-game-over i {
    font-size: 1.2rem;
    color: #ff6b6b;
}

/* Анимация для яблока */
.apple {
    position: relative;
}

.apple::before {
    content: "";
    position: absolute;
    top: -15%;
    left: 50%;
    transform: translateX(-50%);
    width: 8%;
    height: 20%;
    background: #8B4513;
    border-radius: 50%;
    z-index: 1;
}

.apple::after {
    content: "";
    position: absolute;
    top: -25%;
    left: 52%;
    width: 5%;
    height: 30%;
    background: #228B22;
    border-radius: 50% 50% 0 0;
    transform: rotate(-20deg);
}

/* Анимация падения яблока */
@keyframes appleFall {
    0% {
        transform: translateY(-20px) rotate(0deg);
        opacity: 0;
    }
    100% {
        transform: translateY(0) rotate(360deg);
        opacity: 1;
    }
}

.apple-appear {
    animation: appleFall 0.5s ease-out;
}

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

.btn-home {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 140px;
    justify-content: center;
    text-decoration: none;
    background: linear-gradient(135deg, #9d4edd, #5a189a);
    color: white;
}

.btn-home:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    color: white;
}

/* Для мобильных устройств */
@media (max-width: 768px) {
    .game-over-buttons {
        flex-direction: column;
        gap: 10px;
    }
    
    .btn, .btn-home {
        min-width: 200px;
    }
}

@media (max-width: 480px) {
    .btn, .btn-home {
        min-width: 180px;
        padding: 10px 20px;
        font-size: 1rem;
    }
}