
/* ========================================= */
/* БАЗОВЫЙ КОНТЕЙНЕР ИГРЫ                    */
/* ========================================= */
#game {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0 auto;
    width: 100vw;
    max-width: 400px;
    height: 100vh;
    height: 100dvh;
    z-index: 500;
    background: #000;
    overflow: hidden;
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    font-family: 'Press Start 2P', monospace;
}

#game:not(.active) { display: none !important; }

#game canvas {
    margin: auto !important;
    display: block !important;
    max-width: 100%;
    max-height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}


/* ========================================= */
/* ПОДЗЕМЕЛЬЕ — Уровни 3 и 4                 */
/* ========================================= */
#game.level-brick {
    background: linear-gradient(to bottom,
        #1a1a2e 0%, #16213e 30%, #0f0f1a 70%, #0a0a0f 100%
    );
}

#game.level-brick::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center,
        transparent 0%, rgba(0,0,0,0.3) 50%, rgba(0,0,0,0.7) 100%
    );
    pointer-events: none;
    z-index: 1;
}

/* ========================================= */
/* АКТИВНОЕ СОСТОЯНИЕ                        */
/* ========================================= */
#game.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* ========================================= */
/* HEALTH BARS — ПИКСЕЛЬНЫЙ СТИЛЬ            */
/* ========================================= */

/* Полоска игрока — сегментированная красная */
#playerHealth {
    background:
        repeating-linear-gradient(
            90deg,
            #ff2244 0px,
            #ff2244 calc(100% - 3px),
            #8B0000 calc(100% - 3px),
            #8B0000 100%
        );
    image-rendering: pixelated;
}

/* Полоска врага — тёмно-красная */
#enemyHealth {
    background:
        repeating-linear-gradient(
            90deg,
            #B22222 0px,
            #B22222 calc(100% - 3px),
            #6B0000 calc(100% - 3px),
            #6B0000 100%
        );
    image-rendering: pixelated;
}

/* Контейнер HP-баров */
.health-container {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    margin: 0 auto;
    width: 100%;
    max-width: 400px;
    padding: 0 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 1000;
    transition: opacity 0.1s, visibility 0.1s;
    box-sizing: border-box;
}

/* Строка одного HP-бара */
.health-bar {
    align-items: center;
    display: flex;
    gap: 8px;
    padding: 6px 8px;

    /* Пергаментный фон как на карточках референса */
    background: #f0e0c0;

    /* Линовка поверх — как на скрине 2 */
    background-image:
        repeating-linear-gradient(
            0deg,
            rgba(0,0,0,0.06) 0px,
            rgba(0,0,0,0.06) 1px,
            transparent 1px,
            transparent 5px
        );

    /* Пиксельная рамка — 2px solid + 4px drop-shadow без blur */
    border: 3px solid #000;
    border-radius: 0;
    box-shadow:
         4px  4px 0 #000,   /* правая/нижняя тень — как у кнопок */
        -1px -1px 0 rgba(255,255,255,0.6) inset,   /* светлый блик внутри */
         1px  1px 0 rgba(0,0,0,0.4) inset;         /* тёмный паз внутри */

    image-rendering: pixelated;
}

/* Метка "Игрок" / "Враг" */
.health-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    font-weight: normal;
    min-width: 46px;
    color: #1a0000;
    /* Жёсткая пиксельная тень */
    text-shadow:
        1px 1px 0 rgba(255,255,255,0.5);
    letter-spacing: 0;
    line-height: 1.4;
    image-rendering: pixelated;
    white-space: nowrap;
}

/* "Желоб" под полоску */
.health-bar-bg {
    background: #3a0000;
    border-radius: 0;
    border: 2px solid #000;
    box-shadow:
        inset  2px  2px 0 #000,
        inset -1px -1px 0 #555;
    flex: 1;
    height: 16px;
    overflow: hidden;
    image-rendering: pixelated;
}

/* Сама полоска */
.health-bar-fill {
    border-radius: 0;
    height: 100%;
    /* Ступенчатая анимация — как счётчик очков в пиксельных RPG */
    transition: width 0.1s steps(8, end);
    position: relative;
}

/* Блик сверху — 1 ряд пикселей */
.health-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(255,255,255,0.3);
    image-rendering: pixelated;
}

/* ========================================= */
/* СЧЁТЧИКИ МОНЕТ И КРИСТАЛЛОВ               */
/* ========================================= */
.coin-counter,
.diamond-counter {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    letter-spacing: 0;
    text-shadow:
        1px 1px 0 #000,
        2px 2px 0 #000;
    border-radius: 0;
    padding: 5px 10px;
    image-rendering: pixelated;
    /* Пиксельный 3D-блок */
    box-shadow:
         3px  3px 0 #000,
        -1px -1px 0 rgba(255,255,255,0.15);
}

.coin-counter {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-190px);

    background: #1a0000;
    border: 2px solid #ff2244;
    color: #ff4466;
    z-index: 1000000;
    display: none;
    align-items: center;
    gap: 6px;
}

.diamond-counter {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-80px);

    background: #1a0800;
    border: 2px solid #ffaa33;
    color: #ffcc66;
    z-index: 100000000;
    display: none;
    align-items: center;
    gap: 6px;
}

.game-active .coin-counter,
.game-active .diamond-counter {
    display: flex;
}

/* ========================================= */
/* КНОПКА ПАУЗЫ                              */
/* ========================================= */
.pause-btn {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(140px);
    z-index: 1000;

    background: #1a1a1a;
    border: 2px solid #fff;
    border-radius: 0;
    color: white;
    padding: 6px 8px;
    cursor: pointer;

    /* Пиксельный 3D-блок */
    box-shadow:
         3px  3px 0 #000,
        -1px -1px 0 rgba(255,255,255,0.15);

    transition:
        transform   0.05s steps(1, end),
        box-shadow  0.05s steps(1, end);
}

.pause-btn:hover {
    background: #2a2a2a;
    border-color: #fff;
}

.pause-btn:active {
    transform: translateX(140px) translate(3px, 3px);
    box-shadow: 0 0 0 0 transparent;
}

.pause-btn img {
    width: 20px;
    height: 20px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
}

/* ========================================= */
/* КНОПКА "НАЗАД"                            */
/* ========================================= */
.back-to-main-menu-btn {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-180px);
    z-index: 1005;

    background: #1a1a1a;
    color: #fff;
    border: 2px solid rgba(255,255,255,0.5);
    border-radius: 0;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;

    font-family: 'Press Start 2P', monospace;
    font-size: 0.85rem;
    text-shadow: 2px 2px 0 #000;
    cursor: pointer;

    box-shadow:
         3px  3px 0 #000,
        -1px -1px 0 rgba(255,255,255,0.1);

    transition: transform 0.05s steps(1, end);
}

.back-to-main-menu-btn:active {
    transform: translateX(-180px) translate(3px, 3px);
    box-shadow: 0 0 0 0 transparent;
}

.coin-icon img {
    width: 18px;
    height: 18px;
    vertical-align: middle;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* ========================================= */
/* ИГРОВЫЕ КОНТРОЛЛЕРЫ                       */
/* ========================================= */
#gameControls {
    position: fixed;
    bottom: 20px;
    left: 0;
    right: 0;
    margin: 0 auto;
    width: 100%;
    max-width: 400px;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 10px;
    box-sizing: border-box;
    transition: opacity 0.1s, visibility 0.1s;
}

#gameControls.hidden { display: none !important; }

.control-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.control-group.right-group {
    flex-direction: column;
    gap: 6px;
}

/* --- ПИКСЕЛЬНАЯ КНОПКА УПРАВЛЕНИЯ --- */
.control-btn {
    width: 62px;
    height: 62px;

    /* Пергаментный фон — как карточки на референсе */
    background: #2a0000;
    border: 0;
    border-radius: 0;
    outline: none;
    cursor: pointer;

    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    image-rendering: pixelated;

    /*
     * Пиксельный "3D-блок":
     * верх/лево — светлые грани, низ/право — тёмные + внешняя рамка
     */
    box-shadow:
        /* внешний бордер */
         0   0   0 2px #DC143C,
        /* верхняя грань */
         0  -4px 0 2px #6a0020,
        /* левая грань */
        -4px  0  0 2px #6a0020,
        /* правая грань */
         4px  0  0 2px #1a0005,
        /* нижняя грань */
         0   4px 0 2px #1a0005,
        /* угловые пиксели рамки */
        -4px -4px 0 2px #DC143C,
         4px -4px 0 2px #DC143C,
        -4px  4px 0 2px #DC143C,
         4px  4px 0 2px #DC143C;

    transition:
        box-shadow 0.05s steps(1, end),
        transform  0.05s steps(1, end);
}

.control-btn:hover {
    background: #3a0808;
    box-shadow:
         0   0   0 2px #FF2040,
         0  -4px 0 2px #8a0030,
        -4px  0  0 2px #8a0030,
         4px  0  0 2px #2a0010,
         0   4px 0 2px #2a0010,
        -4px -4px 0 2px #FF2040,
         4px -4px 0 2px #FF2040,
        -4px  4px 0 2px #FF2040,
         4px  4px 0 2px #FF2040;
}

/* Нажатие — кнопка "утапливается" на 3px */
.control-btn:active {
    transform: translate(3px, 3px);
    background: rgba(220,20,60,0.2);
    box-shadow:
         0  0  0 2px #DC143C,
        -1px -1px 0 2px #DC143C,
         1px  1px 0 2px #1a0005;
}

.control-btn img {
    width: 78%;
    height: 78%;
    object-fit: contain;
    pointer-events: none;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Кнопка атаки — крупнее, ярче */
#attack {
    width: 74px;
    height: 74px;
    font-family: 'Press Start 2P', monospace;
    font-size: 1.5rem;
    color: #fff;
    text-shadow:
        2px 2px 0 #000,
        4px 4px 0 #8B0000;
    background: #3a0000;
    box-shadow:
         0   0   0 3px #DC143C,
         0  -4px 0 3px #7a0020,
        -4px  0  0 3px #7a0020,
         4px  0  0 3px #1a0005,
         0   4px 0 3px #1a0005,
        -4px -4px 0 3px #DC143C,
         4px -4px 0 3px #DC143C,
        -4px  4px 0 3px #DC143C,
         4px  4px 0 3px #DC143C;
}

#attack:active {
    transform: translate(3px, 3px);
    background: rgba(220,20,60,0.35);
    box-shadow:
         0  0  0 3px #DC143C,
         1px 1px 0 3px #1a0005;
}

/* Кнопки зелий */
.potion-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    color: #fff;
    text-shadow: 1px 1px 0 #000, 2px 2px 0 #000;
    line-height: 1.3;
    flex-direction: column;
    gap: 2px;
}

/* ========================================= */
/* ДИАЛОГ (VN)                               */
/* ========================================= */
.vn-dialog-box {
    position: fixed;
    bottom: 30px;
    left: 0;
    right: 0;
    margin: 0 auto;
    width: 90%;
    max-width: 380px;

    /* Пергамент как на карточке уровня (референс скрин 2) */
    background: #f0e0b8;
    background-image:
        repeating-linear-gradient(
            0deg,
            rgba(0,0,0,0.06) 0px,
            rgba(0,0,0,0.06) 1px,
            transparent 1px,
            transparent 5px
        );

    border: 3px solid #000;
    border-radius: 0;

    /*
     * Двойная пиксельная рамка:
     * внутренняя тёмная обводка + внешний 4px drop-тень
     */
    box-shadow:
         4px  4px 0 #000,
        -1px -1px 0 rgba(255,255,255,0.5) inset,
         2px  2px 0 rgba(0,0,0,0.3)       inset;

    color: #1a0000;
    padding: 14px 16px;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    line-height: 1.9;
    text-shadow: 1px 1px 0 rgba(255,255,255,0.4);
    letter-spacing: 0.3px;
    z-index: 10000;
    image-rendering: pixelated;
}

/* Внутренняя декоративная рамка (как на карточках RPG) */
.vn-dialog-box::before {
    content: '';
    position: absolute;
    top:    3px;
    left:   3px;
    right:  3px;
    bottom: 3px;
    border: 1px solid rgba(0,0,0,0.2);
    pointer-events: none;
}

/* Стрелка "продолжить" */
.vn-continue-indicator {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: #8B0000;
    text-shadow: 1px 1px 0 rgba(255,255,255,0.4);
    animation: blinkIndicator 0.8s steps(1, end) infinite;
}

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

/* Имя персонажа */
.vn-character-name {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: #8B0000;
    text-shadow:
        1px 1px 0 rgba(255,255,255,0.5),
        2px 2px 0 rgba(0,0,0,0.2);
    margin-bottom: 8px;
    letter-spacing: 1px;
}

/* ========================================= */
/* ПОДСКАЗКА УПРАВЛЕНИЯ                      */
/* ========================================= */
.touch-hint {
    position: fixed;
    bottom: 120px;
    left: 0;
    right: 0;
    margin: 0 auto;
    width: 90%;
    max-width: 380px;

    /* Тёмная пиксельная панелька */
    background: #0f0f0f;
    border: 2px solid rgba(255,255,255,0.35);
    border-radius: 0;

    box-shadow:
         3px  3px 0 #000,
        -1px -1px 0 rgba(255,255,255,0.08);

    color: rgba(255,255,255,0.7);
    padding: 7px 12px;
    font-family: 'Press Start 2P', monospace;
    font-size: 6px;
    line-height: 1.7;
    text-align: center;
    text-shadow: 1px 1px 0 #000;
    z-index: 1001;
    pointer-events: none;
    opacity: 1;
    transition: opacity 2s steps(8, end);
    image-rendering: pixelated;
}

.touch-hint.fade-out { opacity: 0; }

/* ========================================= */
/* АДАПТИВНОСТЬ                              */
/* ========================================= */
@media (max-width: 768px) {
    #gameControls   { bottom: 10px; padding: 8px; }
    .control-btn    { width: 56px; height: 56px; }
    #attack          { width: 66px; height: 66px; font-size: 1.3rem; }
    .control-group  { gap: 5px; }
    .control-group.right-group { gap: 4px; }
}

@media (max-width: 480px) {
    #gameControls   { bottom: 5px; padding: 6px; }
    .control-btn    { width: 50px; height: 50px; }
    #attack          { width: 58px; height: 58px; font-size: 1.1rem; }
    .control-group  { gap: 4px; }
    .control-group.right-group { gap: 3px; }
}

/* ========================================= */
/* TOUCH MODE                                */
/* ========================================= */
#gameControls.touch-mode .control-group:first-child  { display: none; }
#gameControls.touch-mode #attack                      { display: none; }
#gameControls.touch-mode #super-attack                { display: none; }
#gameControls.touch-mode #super-cooldown-info         { display: none; }

#gameControls.touch-mode {
    justify-content: center;
    align-items: flex-end;
    gap: 10px;
    pointer-events: none;
}

#gameControls.touch-mode .control-group.right-group {
    flex-direction: row;
    gap: 10px;
    pointer-events: auto;
}

#gameControls.touch-mode .potion-btn {
    display: flex;
    pointer-events: auto;
}

/* ========================================= */
/* ЗЕЛЬЯ — АНИМАЦИИ                          */
/* ========================================= */
@keyframes potionAppear {
    0%   { opacity: 0; transform: translateX(-50%) scale(0.5);  }
    50%  { opacity: 1; transform: translateX(-50%) scale(1.1);  }
    100% { opacity: 1; transform: translateX(-50%) scale(1);    }
}

@keyframes potionDisappear {
    0%   { opacity: 1; transform: translateX(-50%) scale(1);                    }
    100% { opacity: 0; transform: translateX(-50%) scale(0.5) translateY(-20px);}
}

@keyframes particleFly0 {
    0%   { transform: translate(0,0)        scale(1); opacity: 1; }
    100% { transform: translate(-60px,-80px) scale(0); opacity: 0; }
}
@keyframes particleFly1 {
    0%   { transform: translate(0,0)       scale(1); opacity: 1; }
    100% { transform: translate(60px,-70px) scale(0); opacity: 0; }
}
@keyframes particleFly2 {
    0%   { transform: translate(0,0)      scale(1); opacity: 1; }
    100% { transform: translate(-70px,30px) scale(0); opacity: 0; }
}
@keyframes particleFly3 {
    0%   { transform: translate(0,0)     scale(1); opacity: 1; }
    100% { transform: translate(70px,40px) scale(0); opacity: 0; }
}

.potion-notification .potion-icon {
    font-size: 20px;
    image-rendering: pixelated;
    animation: iconPulse 0.4s steps(2, end) infinite alternate;
}

@keyframes iconPulse {
    0%   { transform: scale(1);   }
    100% { transform: scale(1.2); }
}

.potion-health {
    animation:
        potionAppear 0.3s steps(4, end) forwards,
        healthGlow   0.5s steps(2, end) infinite alternate;
}

.potion-energy {
    animation:
        potionAppear 0.3s steps(4, end) forwards,
        energyGlow   0.4s steps(2, end) infinite alternate;
}

/* Пиксельное свечение зелий — только box-shadow без blur */
@keyframes healthGlow {
    0%   { box-shadow: 0 0 0 2px #ff4444, 0 0 0 5px rgba(255,68,68,0.35); }
    100% { box-shadow: 0 0 0 4px #ff4444, 0 0 0 8px rgba(255,68,68,0.55); }
}

@keyframes energyGlow {
    0%   { box-shadow: 0 0 0 2px #ffff00, 0 0 0 5px rgba(255,255,0,0.35); }
    100% { box-shadow: 0 0 0 4px #ffff00, 0 0 0 8px rgba(255,255,0,0.55); }
}

/* ========================================= */
/* УРОВЕНЬ 1 — ФОНОВАЯ КАРТИНКА              */
/* ========================================= */
#game.level-1 {
    background: url('../assets/fon/1level.png') center / cover no-repeat #000;
    animation: none;
}

#game.level-1::before,
#game.level-1::after {
    display: none;
}
