* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: white;
    overflow: hidden;
    position: relative;
}

/* Экран поворота */
#rotate-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    flex-direction: column;
}

.rotate-content {
    text-align: center;
    padding: 20px;
}

.rotate-icon {
    font-size: 80px;
    margin-bottom: 30px;
    animation: rotate 2s infinite ease-in-out;
}

.rotate-text {
    font-size: 24px;
    color: white;
    max-width: 300px;
    line-height: 1.4;
}

@keyframes rotate {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}

#game-container {
    position: relative;
    width: 1280px;
    height: 720px;
    border: 4px solid #2c3e50;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    background: linear-gradient(to bottom, #87CEEB, #1E90FF);
    image-rendering: pixelated;
    /* Фиксированный размер и центрирование */
    margin: auto;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 20;
    cursor: pointer;
}

#start-message {
    font-size: 48px;
    font-weight: bold;
    color: #fff;
    text-align: center;
    pointer-events: none;
}

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

#settings-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s;
    pointer-events: auto;
}

#settings-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: rotate(30deg);
}

#gamepad-indicator {
    position: absolute;
    top: 15px;
    right: 80px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s;
}

#gamepad-indicator.connected {
    opacity: 1;
    background: rgba(46, 204, 113, 0.7);
}

#settings-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(30, 30, 40, 0.95);
    border-radius: 15px;
    padding: 30px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
    z-index: 30;
    display: none;
    pointer-events: auto;
}

#settings-modal h2 {
    text-align: center;
    margin-bottom: 25px;
    color: #3498db;
    font-size: 28px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.control-setting {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 12px 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    transition: background 0.3s;
}

.control-setting:hover {
    background: rgba(255, 255, 255, 0.15);
}

.control-setting label {
    font-size: 18px;
    font-weight: 500;
    flex: 1;
}

.key-input {
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: 2px solid #3498db;
    border-radius: 6px;
    padding: 8px 15px;
    font-size: 16px;
    width: 120px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    flex-shrink: 0;
}

.key-input:focus {
    outline: none;
    border-color: #2ecc71;
    box-shadow: 0 0 10px rgba(46, 204, 113, 0.5);
}

.key-input.listening {
    background: rgba(46, 204, 113, 0.3);
    border-color: #2ecc71;
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    justify-content: flex-end;
}

.volume-btn {
    width: 35px;
    height: 35px;
    border: none;
    border-radius: 50%;
    background: rgba(52, 152, 219, 0.7);
    color: white;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.volume-btn:hover {
    background: rgba(41, 128, 185, 0.9);
    transform: scale(1.1);
}

.volume-bar {
    width: 120px;
    height: 16px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
}

.volume-level {
    height: 100%;
    background: linear-gradient(90deg, #3498db, #2ecc71);
    border-radius: 8px;
    width: 50%;
    transition: width 0.3s;
}

.volume-value {
    font-size: 14px;
    color: #ecf0f1;
    min-width: 40px;
    text-align: center;
    flex-shrink: 0;
}

.music-toggle-btn {
    background: #2ecc71;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 15px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 120px;
    flex-shrink: 0;
}

.music-toggle-btn:hover {
    background: #27ae60;
    transform: translateY(-2px);
}

.music-toggle-btn.muted {
    background: #e74c3c;
}

.music-toggle-btn.muted:hover {
    background: #c0392b;
}

#gamepad-status {
    background: rgba(0, 0, 0, 0.5);
    color: #e74c3c;
    border: 2px solid #e74c3c;
    border-radius: 6px;
    padding: 8px 15px;
    font-size: 16px;
    width: 120px;
    text-align: center;
    flex-shrink: 0;
}

#gamepad-status.connected {
    color: #2ecc71;
    border-color: #2ecc71;
}

#modal-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 30px;
}

.modal-btn {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

#save-settings {
    background: #2ecc71;
    color: white;
}

#save-settings:hover {
    background: #27ae60;
    transform: translateY(-2px);
}

#reset-settings {
    background: #e74c3c;
    color: white;
}

#reset-settings:hover {
    background: #c0392b;
    transform: translateY(-2px);
}

#mobile-settings-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(30, 30, 40, 0.95);
    border-radius: 15px;
    padding: 30px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
    z-index: 30;
    display: none;
    pointer-events: auto;
}

#mobile-settings-modal h2 {
    text-align: center;
    margin-bottom: 25px;
    color: #3498db;
    font-size: 24px;
}

.mobile-settings-content {
    margin: 0;
}

.mobile-settings-content .control-setting {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
}

.mobile-settings-content .control-setting label {
    text-align: center;
    margin-bottom: 5px;
}

.mobile-settings-content .volume-control {
    justify-content: center;
}

#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #333;
    font-size: 24px;
    background: #fff;
    padding: 25px 40px;
    border-radius: 15px;
    text-align: center;
    z-index: 25;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.progress-bar {
    width: 300px;
    height: 20px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    margin-top: 15px;
    overflow: hidden;
    border: 1px solid #ddd;
}

.progress {
    height: 100%;
    background: linear-gradient(90deg, #3498db, #2ecc71);
    border-radius: 10px;
    width: 0%;
    transition: width 0.3s;
}

/* Мобильные кнопки управления */
#mobile-controls {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    display: none;
    justify-content: space-between;
    padding: 0 20px;
    pointer-events: none;
    z-index: 15;
}

.mobile-controls-left, .mobile-controls-right {
    display: flex;
    align-items: center;
    gap: 15px;
    pointer-events: auto;
}

/* Кнопки стрелок */
.mobile-btn.arrow-btn {
    width: 70px;
    height: 70px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    touch-action: manipulation;
    transition: all 0.2s;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.mobile-btn.arrow-btn:active {
    background: rgba(52, 152, 219, 0.8);
    transform: scale(0.95);
}

.mobile-btn.action-btn {
    width: 70px;
    height: 70px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 28px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    touch-action: manipulation;
    transition: all 0.2s;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.mobile-btn.action-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

#mobile-run {
    background: rgba(0, 0, 0, 0.7);
}

#mobile-jump {
    background: rgba(0, 0, 0, 0.7);
}

#mobile-settings {
    background: rgba(52, 152, 219, 0.7);
    font-size: 24px;
}

/* Стили для мобильных устройств и планшетов */
@media (max-width: 1024px) {
    body {
        padding: 10px;
        touch-action: manipulation;
        overflow: auto;
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 100vh;
        height: auto;
    }
    
    #game-container {
        width: 100%;
        max-width: 1280px;
        height: auto;
        aspect-ratio: 16/9;
        border: 2px solid #2c3e50;
        border-radius: 8px;
        margin: auto;
    }
    
    #mobile-controls {
        display: flex !important;
    }
    
    #settings-btn {
        display: none;
    }
    
    #start-message {
        font-size: 32px;
        padding: 0 20px;
    }
    
    .control-setting {
        flex-direction: column;
        gap: 10px;
    }
    
    .key-input {
        width: 100%;
    }
    
    #loading {
        font-size: 20px;
        padding: 25px 35px;
    }
    
    .progress-bar {
        width: 280px;
    }
}

/* Стили для планшетов (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .mobile-btn.arrow-btn,
    .mobile-btn.action-btn {
        width: 80px;
        height: 80px;
        font-size: 36px;
    }
    
    .mobile-btn.action-btn {
        font-size: 30px;
    }
    
    #mobile-settings {
        font-size: 26px;
    }
    
    .mobile-controls-left, .mobile-controls-right {
        gap: 20px;
    }
}

/* Стили для мобильных телефонов */
@media (max-width: 768px) {
    #start-message {
        font-size: 24px;
    }
    
    #settings-modal {
        padding: 20px;
    }
    
    #settings-modal h2 {
        font-size: 20px;
    }
    
    #mobile-settings-modal {
        padding: 20px;
    }
    
    #mobile-settings-modal h2 {
        font-size: 20px;
    }
    
    .control-setting label {
        font-size: 14px;
    }
    
    .mobile-settings-content {
        font-size: 16px;
    }
    
    .volume-bar {
        width: 100px;
    }
    
    .rotate-text {
        font-size: 20px;
    }
    
    .rotate-icon {
        font-size: 60px;
    }
    
    /* Адаптация кнопок для маленьких экранов */
    .mobile-btn.arrow-btn,
    .mobile-btn.action-btn {
        width: 60px;
        height: 60px;
        font-size: 28px;
    }
    
    .mobile-btn.action-btn {
        font-size: 24px;
    }
    
    #mobile-settings {
        font-size: 20px;
    }
}

/* Стили для очень маленьких экранов */
@media (max-width: 480px) {
    /* Еще меньше кнопки для очень маленьких экранов */
    .mobile-btn.arrow-btn,
    .mobile-btn.action-btn {
        width: 55px;
        height: 55px;
        font-size: 24px;
    }
    
    .mobile-btn.action-btn {
        font-size: 20px;
    }
    
    #mobile-settings {
        font-size: 18px;
    }
    
    .mobile-controls-left, .mobile-controls-right {
        gap: 10px;
    }
    
    .volume-bar {
        width: 80px;
    }
    
    .volume-btn {
        width: 30px;
        height: 30px;
        font-size: 16px;
    }
    
    .music-toggle-btn {
        min-width: 100px;
        font-size: 12px;
        padding: 6px 12px;
    }
}

/* Показываем кнопки на мобильных устройствах и планшетах */
@media (max-width: 1024px) and (hover: none) and (pointer: coarse) {
    #mobile-controls {
        display: flex;
    }
}

/* Скрываем обычные настройки на мобильных устройствах и планшетах */
@media (max-width: 1024px) {
    #settings-modal {
        display: none !important;
    }
}

/* Показываем экран поворота на мобильных в портретной ориентации */
@media (max-width: 1024px) and (orientation: portrait) {
    #rotate-screen {
        display: flex;
    }
    
    #game-container {
        display: none !important;
    }
    
    body {
        background: #000 !important;
    }
}

/* Скрываем экран поворота в ландшафтной ориентации */
@media (max-width: 1024px) and (orientation: landscape) {
    #rotate-screen {
        display: none;
    }
    
    #game-container {
        display: block;
    }
    
    body {
        background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
    }
}

/* Для десктопов всегда скрываем экран поворота */
@media (min-width: 1025px) {
    #rotate-screen {
        display: none;
    }
}