@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

/* ── Обнуление и базовые стили ── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    overflow: hidden;
    background: #000;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    min-height: 100vh;
}
canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* ── Общая система экранов (SPA Router) ── */
.screen {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: none !important;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 20px;
    background: rgba(0, 0, 0, 0.88);
}
.screen.active {
    display: flex !important;
}

/* ── Общие панели и элементы меню ── */
.panel {
    background: rgba(10, 10, 18, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 18px;
    padding: 36px 44px;
    text-align: center;
    min-width: 320px;
    max-width: 560px;
    width: 90%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.panel-title {
    font-size: 18px;
    color: #ffd700;
    margin-bottom: 6px;
    letter-spacing: 0.05em;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}
.panel-sub {
    font-size: 8px;
    color: #888;
    line-height: 2;
}

/* ── Кнопки ── */
.btn {
    padding: 14px 20px;
    font-size: 10px;
    font-family: 'Press Start 2P', monospace;
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
    border: 1.5px solid rgba(255, 255, 255, 0.22);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    letter-spacing: 0.04em;
    text-align: center;
    line-height: 1.6;
    touch-action: manipulation;
}
.btn:hover, .btn:active {
    background: rgba(255, 255, 255, 0.18);
}
.btn:active {
    transform: scale(0.98);
}
.btn.primary {
    background: rgba(0, 255, 204, 0.12);
    border-color: rgba(0, 255, 204, 0.5);
    color: #00ffcc;
}
.btn.primary:hover {
    background: rgba(0, 255, 204, 0.25);
}
.btn.danger {
    background: rgba(255, 60, 60, 0.1);
    border-color: rgba(255, 60, 60, 0.4);
    color: #ff4444;
}
.btn.danger:hover {
    background: rgba(255, 60, 60, 0.22);
}
.btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Поля ввода */
input[type="text"] {
    width: 100%;
    padding: 12px 14px;
    font-size: 10px;
    font-family: 'Press Start 2P', monospace;
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.15s;
}
input[type="text"]:focus {
    border-color: rgba(0, 255, 204, 0.6);
}
input[type="text"]::placeholder {
    color: #444;
}

/* Настройки количества врагов */
.setting-label {
    font-size: 9px;
    color: #aaa;
    margin-bottom: 10px;
    line-height: 1.8;
}
.setting-options {
    display: flex;
    gap: 12px;
    justify-content: center;
}
.opt-btn {
    width: 60px;
    height: 60px;
    font-size: 18px;
    font-family: 'Press Start 2P', monospace;
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    touch-action: manipulation;
}
.opt-btn.active {
    background: rgba(255, 213, 0, 0.2);
    border-color: #ffd700;
    color: #ffd700;
}
.opt-btn:hover, .opt-btn:active {
    background: rgba(255, 255, 255, 0.15);
}

/* Кнопки прицела — иконки точно по центру */
.ch-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    font-size: 22px;
}

/* Вместимость комнат */
.cap-btn.active-cap {
    background: rgba(0, 255, 204, 0.15);
    border-color: rgba(0, 255, 204, 0.5);
    color: #00ffcc;
}

/* ── Системные плавающие индикаторы лобби ── */
#ping-badge {
    position: fixed;
    top: 14px;
    left: 14px;
    font-size: 7px;
    color: #555;
    transition: color 0.3s;
    z-index: 25;
    display: none;
}

/* ── Специфические элементы экранов Мультиплеера ── */
#rooms-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 280px;
    overflow-y: auto;
    padding-right: 4px;
}
#rooms-list::-webkit-scrollbar { width: 4px; }
#rooms-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

.room-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: 10px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    transition: background 0.15s;
    cursor: pointer;
    gap: 12px;
}
.room-card:hover { background: rgba(255,255,255,0.1); }
.room-card.full { opacity: 0.45; cursor: not-allowed; }
.room-name { font-size: 8px; color: #fff; text-align: left; flex: 1; }
.room-meta { font-size: 7px; color: #888; white-space: nowrap; }
.room-players { font-size: 8px; white-space: nowrap; }
.room-players.ok { color: #00ffcc; }
.room-players.full { color: #ff4444; }
#rooms-empty { font-size: 8px; color: #555; text-align: center; padding: 24px 0; line-height: 2.4; }

/* Панель Лобби внутри комнаты */
#lobby-panel { max-width: 620px; }
#lobby-players-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 120px;
    padding: 4px 0;
}
.lobby-player {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    font-size: 8px;
}
.lobby-player .ava {
    width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1.5px solid rgba(255, 255, 255, 0.2);
}
.lobby-player .pname { flex: 1; color: #fff; text-align: left; }
.lobby-player .ready-badge { font-size: 7px; padding: 3px 8px; border-radius: 5px; }
.lobby-player .ready-badge.yes { color: #00ffcc; border: 1px solid rgba(0,255,204,0.4); }
.lobby-player .ready-badge.no { color: #888; border: 1px solid rgba(255,255,255,0.15); }
.lobby-player .host-badge { font-size: 7px; color: #ffd700; }

#lobby-chat {
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    padding: 10px 12px;
    max-height: 120px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
}
#lobby-chat::-webkit-scrollbar { width: 3px; }
#lobby-chat::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
.chat-msg { font-size: 7px; line-height: 1.9; }
.chat-msg .chat-author { color: #ffd700; }
.chat-msg .chat-text { color: #ccc; }
.chat-msg.system-msg { color: #555; }
#lobby-chat-row { display: flex; gap: 8px; }
#lobby-chat-input { flex: 1; font-size: 8px; padding: 8px 10px; }
#lobby-chat-send { font-size: 8px; padding: 8px 14px; white-space: nowrap; }

/* ── Игровой интерфейс (HUD Наложения) ── */
#ui {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 10;
    color: #fff;
    font: 9px/2 'Press Start 2P', monospace;
    text-shadow: 1px 1px 0 #000;
    pointer-events: none;
    user-select: none;
    display: none;
}
/* Мульти-HUD: ник + статус + пинг + смерти */
#multi-hud { display: none; margin-bottom: 4px; }
#mp-nick {
    font-size: 9px; color: #ffd700; line-height: 2;
    border-bottom: 1px solid rgba(255,255,255,0.12);
    margin-bottom: 2px; padding-bottom: 2px;
}
#net-conn-text { font-size: 9px; line-height: 2; transition: color 0.3s; }
#net-conn-text.conn-online      { color: #00ffcc; }
#net-conn-text.conn-connecting  { color: #ffaa00; }
#net-conn-text.conn-offline     { color: #ff4444; }
#net-ping { font-size: 9px; color: #aaa; line-height: 2; }
#dead-ui  { font-size: 9px; color: #ff8888; line-height: 2; }

/* Оверлей смерти в мультиплеере */
#mp-death-screen {
    position: fixed; inset: 0; z-index: 40;
    display: none; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.72);
    font-family: 'Press Start 2P', monospace;
}
#mp-death-screen.show { display: flex; }
.mp-death-box {
    background: rgba(10,10,16,0.97);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 14px; padding: 36px 48px;
    text-align: center; display: flex; flex-direction: column; gap: 14px;
    min-width: 280px;
}
.mp-death-title {
    font-size: 22px; color: #ff4444;
    text-shadow: 0 0 20px rgba(255,68,68,0.6);
    margin-bottom: 4px;
}
#mp-killer-label { font-size: 8px; color: #888; min-height: 16px; }
/* Контейнеры счёта — только для show/hide, сами невидимы */
#scoreboard, #team-scores { display: none; }

/* Счёт синих — слева от player-hud */
.score-team-a {
    position: fixed;
    top: 14px;
    right: calc(50% + 76px);
    text-align: right;
    white-space: nowrap;
    color: #00ff88;
    font: 8px/2 'Press Start 2P', monospace;
    text-shadow: 1px 1px 0 #000;
    pointer-events: none;
    z-index: 10;
}
/* Счёт красных — справа от player-hud */
.score-team-b {
    position: fixed;
    top: 14px;
    left: calc(50% + 76px);
    text-align: left;
    white-space: nowrap;
    color: #ff3300;
    font: 8px/2 'Press Start 2P', monospace;
    text-shadow: 1px 1px 0 #000;
    pointer-events: none;
    z-index: 10;
}
#score-a { color: #00ff88; }
#score-b { color: #ff3300; }

#death-info {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 15;
    font: 9px/2.2 'Press Start 2P', monospace;
    color: #ff4444;
    text-shadow: 1px 1px 0 #000;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}
#death-info.show { opacity: 1; }

#hit-flash {
    position: fixed;
    inset: 0;
    z-index: 12;
    background: rgba(220, 30, 30, 0.45);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.35s ease-out;
}

/* Фиксированные глобальные кнопки управления игры */
#fs-btn, #menu-btn {
    position: fixed;
    top: 14px;
    z-index: 25;
    width: 46px;
    height: 46px;
    padding: 0;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border: 1.5px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    line-height: 44px;
    text-align: center;
    touch-action: none;
}
#fs-btn:hover, #menu-btn:hover { background: rgba(255, 255, 255, 0.15); }
#fs-btn { right: 14px; font-size: 20px; }
#menu-btn { right: 68px; font-size: 18px; display: none; }

/* Пост-матчевые и внутриигровые оверлеи */
.game-overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
}
.game-overlay.show {
    display: flex;
}

/* Наэкранные мобильные джойстики */
.joy-wrap {
    display: none;
    position: fixed;
    pointer-events: none;
    z-index: 15;
    width: 128px;
    height: 128px;
    opacity: 0.30;
}
.joy-base {
    position: absolute; top: 0; left: 0;
    width: 128px; height: 128px; border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.08);
}
.joy-knob {
    position: absolute;
    width: 54px; height: 54px; border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
}

/* Кнопки гранаты (мобильные) */
.gren-btn {
    position: fixed;
    z-index: 20;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: transparent;
    border: 10px solid #fff;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
    opacity: 0.5;
    transition: opacity 0.2s;
}
.gren-btn::before,
.gren-btn::after {
    content: '';
    position: absolute;
    background: #fff;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.gren-btn::before { width: 18px; height: 10px; }
.gren-btn::after  { width: 10px; height: 18px; }
.gren-btn:active { transform: scale(0.93); }
#gren-btn-l { left: 16px; bottom: 200px; }
#gren-btn-r { right: 16px; bottom: 200px; }
#gren-ui {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    color: #fff;
    text-shadow: 1px 1px 0 #000;
    pointer-events: none;
    background: rgba(0,0,0,0.5);
    padding: 6px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
#gren-count { color: #ffd700; }
#gren-cd-txt { color: #ff8844; font-size: 8px; }

/* ── HUD игрока: HP + гранаты ── */
#player-hud {
    position: fixed;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 15;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 120px;
    pointer-events: none;
}
#hp-bars, #gren-bars { display: flex; gap: 4px; }
.hp-bar {
    flex: 1; height: 12px; border-radius: 3px;
    background: #22ee55;
    box-shadow: 0 0 5px rgba(34,238,85,0.55);
    transition: background .15s, box-shadow .15s;
}
.hp-bar.depleted { background: #1c1c1c; box-shadow: none; }
.gren-bar {
    flex: 1; height: 10px; border-radius: 3px;
    background: #ff8800;
    box-shadow: 0 0 5px rgba(255,136,0,0.5);
    transition: background .15s, box-shadow .15s;
}
.gren-bar.depleted { background: #1c1c1c; box-shadow: none; }
#gren-cd-bar {
    height: 3px; border-radius: 2px;
    background: #1c1c1c; overflow: hidden;
}
#gren-cd-fill {
    height: 100%; border-radius: 2px;
    background: #ff8800; width: 100%;
    transition: width .1s linear;
}

/* Системные полноэкранные экраны (загрузка, предупреждения) */
#loading-screen, #connect-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    transition: opacity 0.6s;
}
#loading-title { font-size: 16px; color: #ffd700; text-shadow: 0 0 20px rgba(255,215,0,0.6); margin-bottom: 8px; }
#loading-bar-bg {
    width: 260px; height: 10px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 5px; overflow: hidden;
}
#loading-bar {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, #ffd700, #ff8c00);
    border-radius: 5px; transition: width 0.25s ease;
}
#loading-pct { font-size: 8px; color: #888; }

#connect-overlay { z-index: 210; color: #ffd700; font-size: 10px; }
#connect-overlay.hidden { display: none; }
#connect-spinner { font-size: 20px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#rotate-warn {
    position: fixed; inset: 0; z-index: 300;
    background: rgba(0,0,0,0.96); display: none;
    flex-direction: column; align-items: center; justify-content: center; gap: 24px;
    color: #fff; text-align: center;
}
#rotate-warn.show { display: flex; }
.rotate-phone {
    width: 30px; height: 54px;
    border: 3px solid #fff; border-radius: 6px; position: relative;
    animation: rotatePhone 2s ease-in-out infinite;
}
.rotate-phone::after {
    content: ''; position: absolute; bottom: 6px; left: 50%;
    transform: translateX(-50%); width: 8px; height: 8px;
    border-radius: 50%; background: #fff;
}
@keyframes rotatePhone { 0%, 35% { transform: rotate(0deg); } 65%, 100% { transform: rotate(-90deg); } }
.rotate-text { font-size: 8px; line-height: 2.2; color: #ccc; }

/* Анимационные медали */
#perfect-win {
    position: fixed; left: 28px; top: 50%; transform: translateY(-50%) translateX(-220px);
    z-index: 18; text-align: center; pointer-events: none; opacity: 0;
}
#perfect-win.show { animation: medalSlideIn 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }
@keyframes medalSlideIn {
    0%   { opacity: 0; transform: translateY(-50%) translateX(-220px) scale(0.4) rotate(-12deg); }
    60%  { opacity: 1; transform: translateY(-50%) translateX(14px)  scale(1.1)  rotate(3deg); }
    80%  { transform: translateY(-50%) translateX(-6px)  scale(0.96) rotate(-1deg); }
    100% { opacity: 1; transform: translateY(-50%) translateX(0)     scale(1)    rotate(0deg); }
}
#perfect-win img { width: 120px; height: auto; display: block; margin: 0 auto 14px; filter: drop-shadow(0 0 14px rgba(255,215,0,0.9)); }
#perfect-win.show img { animation: medalPop 0.5s cubic-bezier(0.34,1.56,0.64,1) 0.65s both; }
@keyframes medalPop {
    0%   { transform: scale(0.5) rotate(-18deg); filter: brightness(2.5) drop-shadow(0 0 24px #ffd700); }
    70%  { transform: scale(1.18) rotate(4deg); }
    100% { transform: scale(1)    rotate(0deg); }
}
#perfect-win .medal-text { font-size: 10px; color: #ffd700; line-height: 2.2; text-shadow: 0 0 10px #ffd700, 0 0 24px rgba(255,215,0,0.5); }
#perfect-win.show .medal-text { animation: goldPulse 2s ease-in-out infinite 0.7s; }
@keyframes goldPulse { 0%, 100% { text-shadow: 0 0 8px #ffd700; opacity: 1; } 50% { text-shadow: 0 0 22px #ffd700, 0 0 44px rgba(255,215,0,0.6); opacity: 0.8; } }

/* ── Режим ИСПЫТАНИЕ ── */

/* Бейдж режима в списке комнат и лобби */
.trial-badge {
    display: inline-block; margin-left: 8px;
    font-size: 6px; padding: 2px 6px;
    background: rgba(255,215,0,0.12);
    border: 1px solid rgba(255,215,0,0.4);
    border-radius: 4px; color: #ffd700;
    vertical-align: middle;
    white-space: nowrap;
}

/* Кнопки режима в экране создания комнаты */
.mode-btn.active-mode {
    background: rgba(255,215,0,0.15);
    border-color: rgba(255,215,0,0.6);
    color: #ffd700;
}

/* Оверлей вступления к уровню */
#trial-intro {
    position: fixed; inset: 0; z-index: 50;
    display: none; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.92);
    font-family: 'Press Start 2P', monospace;
}
#trial-intro.show { display: flex; }
#trial-intro-box {
    text-align: center; display: flex; flex-direction: column; gap: 20px;
}
#trial-intro-title {
    font-size: 28px; color: #ffd700;
    text-shadow: 0 0 30px rgba(255,215,0,0.7), 0 0 60px rgba(255,215,0,0.3);
    letter-spacing: 0.08em;
    animation: trialPulse 1.5s ease-in-out infinite;
}
#trial-intro-level {
    font-size: 13px; color: #fff;
    text-shadow: 0 0 10px rgba(255,255,255,0.4);
    letter-spacing: 0.06em;
}
@keyframes trialPulse {
    0%, 100% { text-shadow: 0 0 20px rgba(255,215,0,0.7); }
    50%       { text-shadow: 0 0 50px rgba(255,215,0,1), 0 0 100px rgba(255,215,0,0.4); }
}

/* Экран смерти в режиме Испытание */
#trial-death-screen {
    position: fixed; inset: 0; z-index: 40;
    display: none; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.78);
    font-family: 'Press Start 2P', monospace;
}
#trial-death-screen.show { display: flex; }
.trial-death-box {
    background: rgba(10,10,16,0.97);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 14px; padding: 36px 48px;
    text-align: center; display: flex; flex-direction: column; gap: 16px;
    min-width: 300px;
}
.trial-death-title {
    font-size: 22px; color: #ff4444;
    text-shadow: 0 0 20px rgba(255,68,68,0.6);
    margin-bottom: 4px;
}
.trial-stats {
    display: flex; flex-direction: column; gap: 10px;
    padding: 12px 0;
    border-top: 1px solid rgba(255,255,255,0.08);
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.trial-stats div { font-size: 8px; color: #ffd700; line-height: 2; }

/* Тосты уведомлений */
#toast-container {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 999; pointer-events: none;
}
.toast { font-size: 8px; padding: 10px 20px; border-radius: 10px; background: rgba(20,20,30,0.95); border: 1px solid rgba(255,255,255,0.15); animation: toastIn 0.3s ease forwards; }
.toast.error { border-color: rgba(255,68,68,0.5); color: #ff6666; }
.toast.ok { border-color: rgba(0,255,204,0.4); color: #00ffcc; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
