/* ==========================================================================
   СТИЛИ ИНТЕГРАЦИИ ИГРЫ (контейнер Phaser, HUD, экран загрузки)
   ========================================================================== */

/* Кинематографичный переход — затемнение */
#cinematic-overlay {
    position: fixed;
    inset: 0;
    background: #000000;
    z-index: 100000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.6s ease-in-out;
}

#cinematic-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Первый шаг мобильного запуска: fullscreen запрашивается только после нажатия. */
#mobile-entry:not([hidden]) {
    position: fixed;
    inset: 0;
    z-index: 110000;
    display: grid;
    place-items: center;
    padding:
        max(20px, env(safe-area-inset-top))
        max(20px, env(safe-area-inset-right))
        max(20px, env(safe-area-inset-bottom))
        max(20px, env(safe-area-inset-left));
    background: rgba(3, 8, 16, 0.94);
    color: #eef6ff;
    font-family: 'Roboto', sans-serif;
}

.mobile-entry-card {
    width: min(440px, 100%);
    max-height: 100%;
    overflow-y: auto;
    padding: clamp(24px, 6vmin, 40px);
    border: 1px solid rgba(126, 203, 255, 0.3);
    border-radius: 20px;
    background: linear-gradient(145deg, rgba(18, 35, 57, 0.98), rgba(20, 15, 35, 0.98));
    box-shadow: 0 20px 70px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.mobile-entry-mark {
    margin-bottom: 18px;
    color: #7ecbff;
    font-size: clamp(12px, 3vmin, 15px);
    font-weight: 700;
    letter-spacing: 0.12em;
}

.mobile-entry-card h1 {
    margin-bottom: 12px;
    font-size: clamp(22px, 6vmin, 30px);
}

.mobile-entry-card p {
    color: #c3d0df;
    font-size: clamp(15px, 4vmin, 17px);
    line-height: 1.55;
}

.mobile-entry-card .mobile-entry-help {
    margin-top: 12px;
    color: #9fb2c8;
    font-size: clamp(13px, 3.5vmin, 15px);
}

.mobile-entry-card .mobile-entry-error {
    margin-top: 12px;
    color: #ffb4a8;
}

#mobile-entry-continue {
    width: 100%;
    min-height: 48px;
    margin-top: 24px;
    padding: 12px 20px;
    border: 0;
    border-radius: 12px;
    background: linear-gradient(100deg, #287ac0, #9b343f);
    color: #fff;
    font: inherit;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}

#mobile-entry-continue:focus-visible {
    outline: 3px solid #dff8ff;
    outline-offset: 3px;
}

/* Контейнер игры: поверх всего сайта, полноэкранный */
#game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: #050b12;
    z-index: 9000;
    overflow: hidden;
}

/* Когда игра открыта — убираем скролл сайта */
body.game-active {
    overflow: hidden;
}

#game-container canvas {
    display: block;
    z-index: 1;
}

/* ==========================================================================
   Экран загрузки (крутящийся логотип)
   ========================================================================== */
#game-loading {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    background: rgba(5, 11, 18, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 99000;
}

.gl-spinner {
    width: 64px;
    height: 64px;
    border: 5px solid rgba(80, 120, 220, 0.22);
    border-top-color: #5078dc;
    border-right-color: #aa3737;
    border-radius: 50%;
    animation: gl-spin 0.9s linear infinite;
}

@keyframes gl-spin {
    to { transform: rotate(360deg); }
}

.gl-text {
    color: #dff8ff;
    font-family: 'Roboto', sans-serif;
    font-size: 15px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* ==========================================================================
   Прогресс-бар загрузки
   ========================================================================== */
.gl-progress-container {
    width: 280px;
    margin-top: 8px;
}

.gl-progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(80, 120, 220, 0.15);
    border-radius: 3px;
    overflow: hidden;
}

.gl-progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #5078dc, #7ecbff);
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* ==========================================================================
   Сообщение об ошибке запуска (не хватает файлов / нет сервера)
   ========================================================================== */
#game-error {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(5, 11, 18, 0.92);
    z-index: 9600;
    padding: 24px;
    text-align: center;
}

#game-error .ge-box {
    max-width: 560px;
    color: #fca5a5;
    font-family: 'Roboto', sans-serif;
    font-size: 15px;
    line-height: 1.7;
}

#game-error .ge-retry {
    margin-top: 16px;
    padding: 10px 22px;
    background: rgba(80, 120, 220, 0.3);
    border: 1px solid rgba(80, 120, 220, 0.6);
    color: #ffffff;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Roboto', sans-serif;
    transition: background 0.15s;
}

#game-error .ge-retry:hover {
    background: rgba(80, 120, 220, 0.6);
}

/* ==========================================================================
   HUD игровой сцены
   ========================================================================== */
#hud-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 9400;
}

#hud-overlay > * {
    pointer-events: auto;
}

#minimap-border {
    position: absolute;
    box-sizing: border-box;
    border: 2px solid rgba(255, 255, 255, 0.8);
    pointer-events: none;
}

/* Верхний HUD (счёт, статус флага) — гарантированно поверх canvas */
#score-bg,
#hud-flag-status {
    z-index: 9401;
}

/* Лента убийств (верхний левый угол) */
#killfeed-container {
    position: absolute;
    top: clamp(48px, 16vmin, 64px);
    left: clamp(8px, 3vmin, 12px);
    display: flex;
    flex-direction: column;
    gap: clamp(4px, 1.5vmin, 6px);
    pointer-events: none;
    max-width: calc(100vw - 180px);
    z-index: 9500;
}

.killfeed-entry {
    background: rgba(10, 15, 24, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: clamp(4px, 1.5vmin, 6px) clamp(8px, 3.5vmin, 14px);
    font-family: 'Roboto', sans-serif;
    font-size: clamp(11px, 3.3vmin, 13px);
    font-weight: 500;
    color: #e2e8f0;
    text-align: center;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    animation: killfeed-fadein 0.3s ease;
    line-height: 1.4;
}

.killfeed-entry .team-blue {
    color: #4da3ff;
    font-weight: 700;
}

.killfeed-entry .team-red {
    color: #ff6b6b;
    font-weight: 700;
}

.killfeed-entry .kill-icon {
    margin: 0 4px;
    opacity: 0.7;
}

@keyframes killfeed-fadein {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Кнопка «ВЫХОД» — позиционируется из Phaser-кода под мини-картой */
#exit-btn {
    position: absolute;
    transform: translate(-50%, 0);
    padding: clamp(6px, 2vmin, 8px) clamp(10px, 4vmin, 16px);
    font-family: 'Roboto', sans-serif;
    font-size: clamp(11px, 3.3vmin, 13px);
    font-weight: 600;
    letter-spacing: 1px;
    color: #ffffff;
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transition: background 0.15s, border-color 0.15s;
}

#exit-btn:hover {
    background: rgba(148, 57, 57, 0.9);
    border-color: rgba(255, 140, 140, 0.6);
}

/* Кнопка звука в бою (скрываем — управление через меню) */
#sound-toggle {
    display: none !important;
}

/* Кнопка возврата на сайт (верхний левый угол, поверх всего) */
#site-exit-btn {
    position: absolute;
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    padding: clamp(6px, 2vmin, 8px) clamp(10px, 3.5vmin, 14px);
    font-family: 'Roboto', sans-serif;
    font-size: clamp(11px, 3.3vmin, 13px);
    font-weight: 600;
    color: #cbd5e1;
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    cursor: pointer;
    z-index: 9700;
    transition: background 0.15s, color 0.15s;
}

#site-exit-btn:hover {
    background: rgba(148, 57, 57, 0.85);
    color: #ffffff;
}

/* ==========================================================================
   Элементы нижнего HUD (используются UserInterface.js)
   ========================================================================== */

/* Счёт матча — верхний центр */
#score-bg {
    position: absolute;
    top: max(8px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: clamp(8px, 4vmin, 16px);
    align-items: center;
    background: rgba(10, 15, 24, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: clamp(4px, 1.5vmin, 6px) clamp(10px, 4.5vmin, 18px);
    font-family: 'Roboto', sans-serif;
    font-size: clamp(15px, 4.8vmin, 19px);
    font-weight: 700;
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

#blue-score { color: #4da3ff; }
#red-score { color: #ff6b6b; }
#vs-text { font-size: clamp(10px, 3vmin, 12px); font-weight: 400; color: #8899aa; }

/* Статус флага */
#hud-flag-status {
    position: absolute;
    top: clamp(42px, 14vmin, 56px);
    left: 50%;
    transform: translateX(-50%);
    color: #dbe7f4;
    font-family: 'Roboto', sans-serif;
    font-size: clamp(10px, 3vmin, 12px);
    background: rgba(10, 15, 24, 0.6);
    padding: clamp(2px, 0.8vmin, 3px) clamp(8px, 3vmin, 12px);
    border-radius: 8px;
    white-space: nowrap;
}

/* Нижняя панель: HP / оружие / гранаты */
#hud-bg {
    position: absolute;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: clamp(4px, 2vmin, 10px);
    background: rgba(10, 15, 24, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    max-width: calc(100vw - 24px);
    flex-wrap: wrap;
    justify-content: center;
    padding: clamp(6px, 2vmin, 10px) clamp(10px, 4vmin, 18px);
    color: #ffffff;
    font-family: 'Roboto', sans-serif;
    font-size: clamp(10px, 3.3vmin, 13px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.hud-label {
    color: #7fa6c5;
    font-size: clamp(8px, 2.8vmin, 11px);
    letter-spacing: clamp(0px, 0.25vmin, 1px);
}

#hp-bar-bg {
    width: clamp(64px, 24vmin, 120px);
    height: clamp(7px, 2vmin, 10px);
    background: rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    overflow: hidden;
}

#hp-bar-fill {
    height: 100%;
    width: 100%;
    background: #2ecc71;
    border-radius: 6px;
    transition: width 0.2s ease, background 0.2s ease;
}

#hp-text {
    font-weight: 700;
    min-width: clamp(30px, 8vmin, 44px);
}

#weapon-text {
    min-width: clamp(48px, 17vmin, 76px);
    text-align: center;
}

.wep-icon {
    display: none;
    width: clamp(18px, 5.6vmin, 22px);
    height: clamp(18px, 5.6vmin, 22px);
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: clamp(10px, 3vmin, 12px);
    font-weight: 700;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    line-height: 1;
    padding: 0;
    margin: 0;
}

#grenade-text {
    min-width: clamp(48px, 17vmin, 80px);
}

/* Режим наблюдателя */
#spectator-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    font-family: 'Roboto', sans-serif;
    font-size: clamp(15px, 5vmin, 20px);
    color: #cfe7ff;
    background: rgba(10, 15, 24, 0.75);
    padding: clamp(8px, 3vmin, 12px) clamp(14px, 6vmin, 26px);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    white-space: nowrap;
}
