/* Общие стили и сброс */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #1a1a2e, #16213e, #0f3460);
    overflow: hidden;
    height: 100vh;
    color: white;
}

/* Контейнер игры */
#gameContainer {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* HUD интерфейс */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 1rem;
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), rgba(0,0,0,0));
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

#score {
    font-size: 1.5rem;
    font-weight: bold;
    color: #00ff88;
    text-shadow: 0 0 10px rgba(0, 255, 136, 0.5);
}

#controls {
    text-align: right;
    opacity: 0.8;
}

.control-info {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

/* Игровое поле */
#gameField {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #2d4a22;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Экраны меню и окончания игры */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    transition: opacity 0.3s ease;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.screen-content {
    text-align: center;
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    padding: 3rem;
    border-radius: 15px;
    border: 2px solid #00ff88;
    box-shadow: 0 0 30px rgba(0, 255, 136, 0.3);
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
}

.screen-content h1 {
    font-size: 3rem;
    margin-bottom: 1rem;
    background: linear-gradient(45deg, #00ff88, #00d4ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
}

.screen-content h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: #ff6b6b;
}

.screen-content p {
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
    opacity: 0.9;
}

/* Кнопки */
button {
    background: linear-gradient(45deg, #00ff88, #00d4ff);
    border: none;
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: bold;
    color: #1a1a2e;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 255, 136, 0.3);
    margin: 0.5rem;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 255, 136, 0.5);
    filter: brightness(1.1);
}

button:active {
    transform: translateY(0);
    box-shadow: 0 3px 10px rgba(0, 255, 136, 0.3);
}

/* Инструкции */
.instructions {
    margin-top: 2rem;
    padding: 1.5rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    border-left: 4px solid #00ff88;
}

.instructions h3 {
    margin-bottom: 1rem;
    color: #00ff88;
}

.instructions p {
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

/* Адаптивность для мобильных устройств */
@media (max-width: 768px) {
    #hud {
        padding: 0.5rem;
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }

    #score {
        font-size: 1.2rem;
    }

    .control-info {
        font-size: 0.8rem;
        text-align: center;
    }

    .screen-content {
        padding: 2rem 1.5rem;
        margin: 1rem;
    }

    .screen-content h1 {
        font-size: 2rem;
    }

    .screen-content h2 {
        font-size: 1.5rem;
    }

    .screen-content p {
        font-size: 1rem;
    }

    button {
        padding: 0.8rem 1.5rem;
        font-size: 1rem;
    }

    .instructions {
        margin-top: 1rem;
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .screen-content {
        padding: 1.5rem 1rem;
        margin: 0.5rem;
    }

    .screen-content h1 {
        font-size: 1.8rem;
    }

    button {
        width: 100%;
        margin: 0.25rem 0;
    }
}

/* Анимации */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.screen-content {
    animation: fadeIn 0.5s ease;
}

/* Улучшенная типографика */
@media (max-width: 768px) {
    .control-info {
        display: none;
    }
}

/* Эффекты для счета */
#scoreValue {
    transition: all 0.3s ease;
}

#scoreValue.updated {
    transform: scale(1.2);
    text-shadow: 0 0 20px rgba(0, 255, 136, 0.8);
}

/* Мобильные элементы управления */
.mobile-controls {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
    display: none; /* Скрыты по умолчанию, показываются только на мобильных */
}

/* Кнопка стрельбы */
.shoot-button {
    position: absolute;
    bottom: max(30px, env(safe-area-inset-bottom, 30px) + 20px);
    left: max(30px, env(safe-area-inset-left, 30px));
    width: 80px;
    height: 80px;
    background: radial-gradient(circle, #ff4444, #cc1111);
    border: 4px solid #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px rgba(255, 68, 68, 0.6), inset 0 0 20px rgba(255, 255, 255, 0.2);
    pointer-events: auto;
    user-select: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.shoot-button:active {
    transform: scale(0.9);
    box-shadow: 0 0 30px rgba(255, 68, 68, 0.8), inset 0 0 20px rgba(255, 255, 255, 0.4);
}

.button-icon {
    font-size: 32px;
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.5));
    display: flex;
    align-items: center;
    justify-content: center;
}

.button-icon svg {
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.5));
}

/* Джойстик управления */
.joystick-container {
    position: absolute;
    bottom: max(30px, env(safe-area-inset-bottom, 30px) + 20px);
    right: max(30px, env(safe-area-inset-right, 30px));
    width: 120px;
    height: 120px;
    pointer-events: auto;
}

.joystick-base {
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, #444444, #222222);
    border: 4px solid #ffffff;
    border-radius: 50%;
    position: relative;
    box-shadow: 0 0 20px rgba(68, 68, 68, 0.6), inset 0 0 20px rgba(255, 255, 255, 0.1);
}

.joystick-knob {
    position: absolute;
    width: 50px;
    height: 50px;
    background: radial-gradient(circle, #00ff88, #00cc66);
    border: 3px solid #ffffff;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 15px rgba(0, 255, 136, 0.6), inset 0 0 10px rgba(255, 255, 255, 0.3);
    transition: all 0.1s ease;
    cursor: grab;
}

.joystick-knob:active {
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.1);
}

/* Показывать мобильные элементы только на сенсорных устройствах */
@media (hover: none) and (pointer: coarse) {
    .mobile-controls {
        display: block;
    }
    
    /* Скрыть подсказки управления на мобильных */
    #controls {
        display: none;
    }
}

/* Адаптация для маленьких экранов */
@media (max-width: 480px) {
    .shoot-button {
        width: 70px;
        height: 70px;
        bottom: 80px; /* Поднимаем выше от нижней панели */
        left: 20px;
    }
    
    .button-icon {
        font-size: 28px;
    }
    
    .button-icon svg {
        width: 28px;
        height: 28px;
    }
    
    .joystick-container {
        width: 100px;
        height: 100px;
        bottom: 80px; /* Поднимаем выше от нижней панели */
        right: 20px;
    }
    
    .joystick-knob {
        width: 40px;
        height: 40px;
    }
}

/* Дополнительная адаптация для портретной ориентации телефонов */
@media (max-width: 480px) and (orientation: portrait) {
    .shoot-button {
        bottom: 100px; /* Еще выше в портретном режиме */
    }
    
    .joystick-container {
        bottom: 100px; /* Еще выше в портретном режиме */
    }
}

/* Адаптация для очень маленьких экранов */
@media (max-width: 360px) {
    .shoot-button {
        width: 60px;
        height: 60px;
        bottom: 90px; /* Поднимаем выше от нижней панели */
        left: 15px;
    }
    
    .button-icon {
        font-size: 24px;
    }
    
    .button-icon svg {
        width: 24px;
        height: 24px;
    }
    
    .joystick-container {
        width: 90px;
        height: 90px;
        bottom: 90px; /* Поднимаем выше от нижней панели */
        right: 15px;
    }
    
    .joystick-knob {
        width: 35px;
        height: 35px;
    }
}

/* Дополнительная адаптация для маленьких экранов в портретном режиме */
@media (max-width: 360px) and (orientation: portrait) {
    .shoot-button {
        bottom: 110px; /* Еще выше в портретном режиме на маленьких экранах */
    }
    
    .joystick-container {
        bottom: 110px; /* Еще выше в портретном режиме на маленьких экранах */
    }
}

/* Специальная адаптация для современных телефонов с высоким экраном */
@media (max-height: 700px) and (orientation: portrait) and (hover: none) {
    .shoot-button {
        bottom: max(80px, env(safe-area-inset-bottom, 20px) + 60px) !important;
    }
    
    .joystick-container {
        bottom: max(80px, env(safe-area-inset-bottom, 20px) + 60px) !important;
    }
}

/* Адаптация для iPhone X и более новых с "челкой" */
@media (max-height: 812px) and (orientation: portrait) and (hover: none) {
    .shoot-button {
        bottom: max(90px, env(safe-area-inset-bottom, 34px) + 56px) !important;
    }
    
    .joystick-container {
        bottom: max(90px, env(safe-area-inset-bottom, 34px) + 56px) !important;
    }
}

/* Эффекты при нажатии */
.shoot-button.pressed {
    background: radial-gradient(circle, #ff6666, #dd2222);
    transform: scale(0.85);
}

.joystick-active {
    box-shadow: 0 0 25px rgba(0, 255, 136, 0.8), inset 0 0 20px rgba(255, 255, 255, 0.2);
}