/* ==========================================================================
   1. BASE & VARIABLES
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@400;700&display=swap');

:root {
    --bg-dark: #121214;
    --bg-panel: #1e1e22;
    --border-color: #333;
    --text-main: #e0e0e0;
    --text-gold: #f0c674;
    --color-green: #28a745;
    --color-red: #ff4d4d;
    --color-blue: #4d79ff;
    --header-height: 55px;
    --nav-height: 60px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Roboto Condensed', sans-serif;
    font-size: 14px;
    padding-top: var(--header-height);
    padding-bottom: var(--nav-height);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

a {
    text-decoration: none;
    color: inherit;
}

h1,
h2,
h3,
h4 {
    margin: 0 0 10px 0;
    color: #fff;
}

button,
input,
textarea {
    font-family: inherit;
}

.game-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 15px;
}

.link-button {
    background: none;
    border: none;
    padding: 0;
    color: #8af;
    text-decoration: underline;
    cursor: pointer;
    font-size: 1em;
}

/* ==========================================================================
   2. HEADER (HUD)
   ========================================================================== */
.game-header {
    position: fixed; top: 0; left: 0; right: 0;
    height: var(--header-height);
    background: rgba(25, 25, 30, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #333;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
.header-inner {
    max-width: 1100px; margin: 0 auto; height: 100%;
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 15px; gap: 15px;
}

/* Левая часть: Юзер */
.hud-user { display: flex; align-items: center; gap: 8px; min-width: 80px; }
.hud-level {
    background: #333; color: var(--text-gold);
    width: 24px; height: 24px; border-radius: 50%;
    display: flex; justify-content: center; align-items: center;
    font-weight: bold; font-size: 0.85em; border: 1px solid #555;
}
.hud-name {
    font-weight: bold; font-size: 0.9em; color: #fff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100px;
}

/* Центр: Полоски */
.hud-bars {
    flex-grow: 1;
    max-width: 350px; /* Чуть шире */
    display: flex;
    flex-direction: column;
    gap: 6px; /* Больше отступ между полосками */
}

.bar-compact {
    position: relative;
    height: 10px; /* Увеличили высоту (было 10-12px) */
    background: #080808; /* Очень темный фон подложки */
    border-radius: 4px;
    border: 1px solid #444;
    overflow: hidden;
    /* Внутренняя тень для объема */
    box-shadow: inset 0 0 5px rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
}

/* Заливка (Анимация) */
.bar-compact .fill {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    transition: width 0.3s ease-out;
    z-index: 1;
}

/* Градиенты для объема */
.bar-compact.red .fill {
    background: linear-gradient(180deg, #ff4d4d 0%, #b30000 100%);
    box-shadow: 0 0 5px #ff0000;
}
.bar-compact.blue .fill {
    background: linear-gradient(180deg, #4d79ff 0%, #002db3 100%);
    box-shadow: 0 0 5px #0040ff;
}
/* Стиль для Голода/Опыта */
.bar-compact .fill.xp { background: linear-gradient(180deg, #ffd700 0%, #ff8c00 100%); }

/* Иконка (Слева) */
.bar-compact .icon {
    position: absolute;
    left: 5px;
    top: 0; bottom: 0;
    z-index: 3;
    font-size: 12px;
    line-height: 18px; /* Центрирование по вертикали */
    text-shadow: 0 1px 2px #000;
}

/* Цифры (По центру) */
.bar-compact .val {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0; /* Растягиваем на весь блок */
    z-index: 3; /* Поверх заливки */

    display: flex;
    justify-content: center; /* По центру горизонтально */
    align-items: center;     /* По центру вертикально */

    font-size: 11px;
    font-weight: bold;
    color: #fff;
    font-family: monospace; /* Чтобы цифры не прыгали */
    letter-spacing: 0.5px;

    /* Жесткая обводка текста, чтобы читалось на любом фоне */
    text-shadow:
            -1px -1px 0 #000,
            1px -1px 0 #000,
            -1px  1px 0 #000,
            1px  1px 0 #000,
            0 0 5px rgba(0,0,0,0.8);
}
/* Правая часть: Деньги и Меню ПК */
.hud-right { display: flex; align-items: center; gap: 15px; }
.hud-money { font-weight: bold; color: var(--text-gold); font-size: 0.95em; white-space: nowrap; }

/* Статусы (Травма, Голод) */
.status-icons {
    display: flex;
    gap: 5px;
}

.status-icon {
    font-size: 1.2em;
    background: rgba(0, 0, 0, 0.5);
    padding: 2px 5px;
    border-radius: 4px;
    cursor: help;
    animation: pulse-red 1.5s infinite;
    border: 1px solid transparent;
}

.status-icon.injury {
    border-color: #a00;
    background: rgba(100, 0, 0, 0.3);
}

.status-icon.starve {
    border-color: #d60;
    background: rgba(100, 50, 0, 0.3);
}

@keyframes pulse-red {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.7;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ==========================================================================
   3. BOTTOM NAV (MOBILE)
   ========================================================================== */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--nav-height);
    background: #161619; border-top: 1px solid #333;
    display: flex; /* ПОКАЗАНО НА МОБИЛКАХ */
    justify-content: space-around; align-items: center;
    z-index: 999; padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -5px 20px rgba(0,0,0,0.5);
}
.nav-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: #666; width: 100%; height: 100%; text-decoration: none;
}
.nav-item.active { color: #fff; }
.nav-icon { font-size: 1.4em; margin-bottom: 2px; }
.nav-label { font-size: 0.65em; text-transform: uppercase; font-weight: bold; }
/* ==========================================================================
   4. MAP & LOCATIONS
   ========================================================================== */
.location-container {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 20px;
}

.location-image {
    width: 100%;
    height: 200px;
    background: #000;
    border-bottom: 2px solid var(--border-color);
    overflow: hidden;
}

.location-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 5s ease;
}

.location-info {
    padding: 15px;
    text-align: center;
    background: #202024;
}

.location-navigation {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
    padding: 15px;
    background: #161619;
}

.btn-action {
    display: block;
    width: 100%;
    padding: 12px;
    background: #2c2c33;
    color: #fff;
    border: 1px solid #444;
    border-left: 4px solid #666;
    border-radius: 4px;
    text-align: left;
    cursor: pointer;
    font-weight: bold;
    text-transform: uppercase;
}

.btn-move {
    border-left-color: var(--color-blue);
}

.btn-enter {
    border-left-color: var(--text-gold);
    color: #ffeeb0;
}

/* ==========================================================================
   5. CHAT SYSTEM v2.0
   ========================================================================== */
#chat-trigger {
    position: fixed;
    bottom: 85px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #4d79ff;
    color: #fff;
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 2000;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    transition: transform 0.2s;
}

#chat-trigger:hover {
    transform: scale(1.1);
}

#chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #f00;
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    padding: 2px 5px;
    border-radius: 10px;
    border: 2px solid #4d79ff;
}

#chat-badge.hidden {
    display: none;
}

#chat-panel {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 340px;
    height: 450px;
    background: rgba(25, 25, 30, 0.98);
    border: 1px solid #444;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    z-index: 2001;
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

#chat-panel.hidden {
    display: none !important;
}

/* Адаптив */
@media (max-width: 600px) {
    #chat-panel {
        right: 0;
        left: 0;
        bottom: 60px;
        width: 100%;
        height: 50vh;
        border-radius: 8px 8px 0 0;
        border-left: none;
        border-right: none;
    }
}

/* --- ШАПКА С ТАБАМИ --- */
.chat-header-row {
    display: flex;
    background: #111;
    border-bottom: 1px solid #333;
    height: 40px;
    border-radius: 8px 8px 0 0;
}

.chat-tabs-scroll {
    flex-grow: 1;
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
}

.chat-tabs-scroll::-webkit-scrollbar {
    display: none;
}

.c-tab {
    background: transparent;
    border: none;
    color: #888;
    padding: 0 15px;
    font-weight: bold;
    font-size: 0.85em;
    cursor: pointer;
    border-right: 1px solid #222;
    display: flex;
    align-items: center;
    gap: 5px;
}

.c-tab:hover {
    background: #222;
    color: #ccc;
}

.c-tab.active {
    background: #1e1e22;
    color: #fff;
    border-bottom: 2px solid #4d79ff;
}

.c-tab.private {
    color: #d0f;
}

.c-tab.private.active {
    border-bottom-color: #d0f;
}

.c-tab .close-tab {
    font-size: 14px;
    color: #666;
    padding: 2px;
    border-radius: 50%;
}

.c-tab .close-tab:hover {
    color: #fff;
    background: #d00;
}

.chat-close-main {
    width: 40px;
    background: #151515;
    border: none;
    color: #666;
    cursor: pointer;
    border-left: 1px solid #333;
}

/* --- КОНТЕНТ --- */
.chat-view {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-view.hidden {
    display: none;
}

#chat-history {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    scrollbar-width: thin;
    scrollbar-color: #555 #222;
}

#chat-history::-webkit-scrollbar {
    width: 6px;
}

#chat-history::-webkit-scrollbar-track {
    background: #222;
}

#chat-history::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 3px;
}

.chat-msg {
    margin-bottom: 6px;
    font-size: 0.9em;
    line-height: 1.4;
    word-wrap: break-word;
}

.msg-time {
    color: #555;
    font-size: 0.85em;
    margin-right: 5px;
}

.msg-author {
    font-weight: bold;
    color: #f0c674;
    cursor: pointer;
}

.msg-author:hover {
    text-decoration: underline;
}

.msg-text {
    color: #ddd;
}

.chat-msg.private {
    background: rgba(255, 0, 255, 0.05);
    border-left: 2px solid #d0f;
    padding-left: 5px;
}

.msg-prefix {
    color: #d0f;
    font-weight: bold;
    margin-right: 5px;
}

/* --- ФОРМА ВВОДА --- */
.chat-input-area {
    display: flex;
    padding: 8px;
    border-top: 1px solid #333;
    background: #1a1a1d;
}

#chat-input {
    flex-grow: 1;
    background: #000;
    border: 1px solid #444;
    color: #fff;
    padding: 8px;
    border-radius: 4px 0 0 4px;
    outline: none;
}

.chat-input-area button {
    background: #333;
    border: 1px solid #444;
    border-left: none;
    color: #fff;
    padding: 0 15px;
    cursor: pointer;
    border-radius: 0 4px 4px 0;
}

.chat-input-area button:hover {
    background: #4d79ff;
}

/* --- СПИСОК ОНЛАЙН --- */
/* Исправлено: было //* */
#online-list {
    overflow-y: auto;
    flex-grow: 1;
}

.online-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid #222;
}

.u-name {
    font-weight: bold;
    color: #ccc;
}

.u-lvl {
    color: #f0c674;
    font-size: 0.8em;
    margin-right: 5px;
}

.btn-xs {
    padding: 2px 8px;
    font-size: 0.75em;
    background: #333;
    border: 1px solid #555;
    color: #fff;
    border-radius: 3px;
    cursor: pointer;
    margin-left: 5px;
}

/* --- АНИМАЦИИ --- */
@keyframes glow {
    50% {
        text-shadow: 0 0 5px #f0f;
    }
}

/* ==========================================================================
   6. ITEM POPUP
   ========================================================================== */
.item-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 3000;
    display: none;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(3px);
}

.item-popup-overlay.active {
    display: flex;
    animation: popIn 0.2s ease-out;
}

.item-popup {
    width: 90%;
    max-width: 360px;
    background: #1a1a1d;
    border: 1px solid #555;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.9);
    position: relative;
}

@keyframes popIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.item-popup-header {
    font-size: 1.3em;
    font-weight: bold;
    color: #fff;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
}

.item-popup-type {
    font-size: 0.85em;
    color: #888;
    text-transform: uppercase;
    margin-bottom: 15px;
}

.item-popup-stats {
    background: #111;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 15px;
    font-family: monospace;
    font-size: 1.1em;
}

.item-popup-desc {
    font-size: 0.9em;
    color: #aaa;
    font-style: italic;
    line-height: 1.4;
    margin-bottom: 20px;
}

.item-popup-image {
    text-align: center;
    margin-bottom: 15px;
    background: #0a0a0a;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #333;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
}

.item-popup-image img {
    max-width: 100%;
    max-height: 150px;
    object-fit: contain;
    filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.5));
}

.item-popup-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    width: 100%;
}

.item-popup-actions button {
    flex: 1;
    height: 42px;
    padding: 0 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    font-family: inherit;
    font-weight: bold;
    font-size: 0.9em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 0;
    width: auto;
}

.item-popup-actions button:active {
    transform: scale(0.98);
}

.popup-btn-chat {
    background: #4d79ff;
    color: #fff;
    box-shadow: 0 4px 10px rgba(77, 121, 255, 0.3);
}

.popup-btn-chat:hover {
    background: #3a66cc;
}

.item-popup-actions button.close {
    background: #2a2a2e;
    color: #aaa;
}

.item-popup-actions button.close:hover {
    background: #333;
    color: #fff;
    border-color: #666;
}

.popup-btn-use {
    background: #28a745;
    color: #fff;
}
/* --- НАВИГАЦИЯ ПК (По умолчанию скрыта!) --- */
/* Меню ПК */
.desktop-nav { display: none; gap: 20px; }
.desktop-nav a {
    color: #aaa; font-weight: bold; text-transform: uppercase; font-size: 0.9em;
    padding: 5px 0; border-bottom: 2px solid transparent; transition: 0.2s;
}
.desktop-nav a:hover, .desktop-nav a.active { color: #fff; border-color: var(--text-gold); }
/* ==========================================================================
   7. MEDIA QUERIES
   ========================================================================== */
@media (min-width: 768px) {
    body {
        padding-bottom: 0;
    }

    .bottom-nav {
        display: none;
    }

    .desktop-nav {
        display: block;
    }

    .location-image {
        height: 400px;
    }

    .location-navigation {
        grid-template-columns: 1fr 1fr;
    }

    .items-grid,
    .backpack-grid,
    .equipped-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

@media (max-width: 767px) {
    .items-grid,
    .backpack-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .item-image,
    .inv-img-box {
        height: 90px;
    }

    .item-info,
    .inv-info {
        padding: 6px;
    }

    .item-name,
    .inv-name {
        font-size: 0.9em;
        margin-bottom: 2px;
    }

    .item-actions,
    .inv-actions {
        padding: 6px;
        flex-direction: column;
        gap: 5px;
    }

    .trade-form {
        flex-direction: column;
        width: 100%;
        gap: 5px;
    }

    .qty-control {
        width: 100%;
        justify-content: space-between;
        height: 26px;
    }

    .qty-control button {
        width: 26px;
    }

    .btn-buy,
    .btn-main,
    .btn-equip {
        width: 100%;
        font-size: 0.8em;
        padding: 6px 0;
        margin: 0;
    }

    .price-row {
        font-size: 0.9em;
        margin-bottom: 5px;
    }
}

/* ==========================================================================
   8. ГЛОБАЛЬНЫЕ УВЕДОМЛЕНИЯ
   ========================================================================== */
.flash-msg {
    padding: 10px 15px;
    margin-bottom: 15px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.9em;
}

.flash-msg.success {
    background: rgba(40, 167, 69, 0.2);
    border: 1px solid #28a745;
    color: #75b798;
}

.flash-msg.error {
    background: rgba(220, 53, 69, 0.2);
    border: 1px solid #dc3545;
    color: #ea868f;
}

/* ==========================================================================
   9. КОНТЕКСТНОЕ МЕНЮ
   ========================================================================== */
.context-menu {
    position: absolute;
    background: #222;
    border: 1px solid #444;
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    min-width: 150px;
    overflow: hidden;
}

.context-menu-item {
    padding: 10px 15px;
    cursor: pointer;
    color: #ddd;
    font-size: 0.9em;
    border-bottom: 1px solid #333;
    transition: background 0.2s;
}

.context-menu-item:last-child {
    border-bottom: none;
}

.context-menu-item:hover {
    background: #333;
    color: #fff;
}

/* ==========================================================================
   10. КНОПКИ
   ========================================================================== */
.btn-tg {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: #229ed9;
    color: #fff;
    padding: 12px 20px;
    border-radius: 6px;
    text-decoration: none;
    font-weight: bold;
    font-size: 1em;
    text-transform: uppercase;
    border: 1px solid #1c8dbf;
    transition: all 0.2s;
    box-shadow: 0 4px 10px rgba(34, 158, 217, 0.3);
}

.btn-tg:hover {
    background: #1c8dbf;
    box-shadow: 0 0 15px rgba(34, 158, 217, 0.6);
    transform: translateY(-2px);
}

.tg-icon {
    font-weight: normal;
    font-size: 1.2em;
}

/* Ссылки на предметы в чате */
.chat-item-link {
    cursor: pointer;
    font-weight: bold;
    text-decoration: underline;
    padding: 0 2px;
    display: inline-block;
}
.chat-item-link:hover {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
}

/* Цвета редкости */
.q-common { color: #fff; }
.q-uncommon { color: #1eff00; text-shadow: 0 0 5px rgba(30, 255, 0, 0.3); }
.q-rare { color: #0070dd; text-shadow: 0 0 5px rgba(0, 112, 221, 0.3); }
.q-epic { color: #a335ee; text-shadow: 0 0 5px rgba(163, 53, 238, 0.3); }