/* ============================================
   МОБИЛЬНАЯ ВЕРСИЯ ИГРЫ — минималистичная и удобная
   Breakpoints: 768px (планшет), 480px (телефон)
   Safe-area для вырезов и жестов
   ============================================ */

/* --- Базовые мобильные переменные --- */
@media (max-width: 768px) {
    :root {
        --mobile-touch-min: 44px;
        --mobile-header-h: 52px;
        --mobile-safe-top: env(safe-area-inset-top, 0px);
        --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
        --mobile-safe-left: env(safe-area-inset-left, 0px);
        --mobile-safe-right: env(safe-area-inset-right, 0px);
    }
}

/* ========== ПЛАНШЕТ + ТЕЛЕФОН (<= 768px) ========== */
@media (max-width: 768px) {

    /* --- BODY: безопасные отступы --- */
    .game-body {
        overflow-y: auto;
        overflow-x: hidden;
        height: auto;
        min-height: 100vh;
        min-height: calc(100vh + var(--mobile-safe-bottom, 0px));
        padding-left: var(--mobile-safe-left);
        padding-right: var(--mobile-safe-right);
        padding-bottom: var(--mobile-safe-bottom);
        -webkit-overflow-scrolling: touch;
    }

    /* --- ХЕДЕР: компактный, липкий --- */
    .game-header {
        height: var(--mobile-header-h);
        min-height: calc(var(--mobile-header-h) + var(--mobile-safe-top));
        padding: 8px 10px;
        padding-top: calc(8px + var(--mobile-safe-top));
        gap: 6px;
        flex-wrap: nowrap;
        position: sticky;
        top: 0;
        z-index: 1000;
        background: var(--color-panel);
        border-bottom: 1px solid var(--color-border);
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    }
    .header-logo {
        display: none;
    }
    .header-icons {
        gap: 2px;
        flex: 1;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 0 4px;
    }
    .header-icons::-webkit-scrollbar {
        display: none;
    }
    .header-icon-btn {
        min-width: var(--mobile-touch-min);
        min-height: var(--mobile-touch-min);
        padding: 6px 8px;
        border-radius: var(--radius-md);
        flex-shrink: 0;
    }
    .hib-label {
        display: none;
    }
    .hib-icon {
        font-size: 1.25em;
    }
    .header-nav-divider {
        margin: 0 2px;
        height: 22px;
        align-self: center;
    }
    .header-right {
        gap: 6px;
        flex-shrink: 0;
    }
    .header-user-name {
        display: none;
    }
    .server-time {
        display: none;
    }
    .pve-toggle-wrap {
        padding: 6px 10px;
        min-height: var(--mobile-touch-min);
    }
    .pve-label {
        display: none;
    }

    /* --- Гамбургер: аккуратная кнопка --- */
    .mobile-hamburger {
        display: flex;
        align-items: center;
        justify-content: center;
        width: var(--mobile-touch-min);
        height: var(--mobile-touch-min);
        background: var(--color-panel-light);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        color: var(--color-text);
        font-size: 1.35em;
        cursor: pointer;
        flex-shrink: 0;
        transition: background var(--transition-fast), border-color var(--transition-fast);
    }
    .mobile-hamburger:hover,
    .mobile-hamburger:active {
        background: var(--color-panel-hover);
        border-color: var(--color-accent);
    }

    /* --- Мини HP/MP/XP в хедере --- */
    .mobile-mini-bars {
        display: flex;
        flex-direction: column;
        gap: 3px;
        min-width: 56px;
        max-width: 72px;
        flex-shrink: 0;
    }
    .mobile-mini-bar {
        height: 6px;
        border-radius: 3px;
        background: rgba(0, 0, 0, 0.35);
        overflow: hidden;
    }
    .mobile-mini-bar-fill {
        height: 100%;
        border-radius: 3px;
        transition: width 0.25s ease;
    }
    .mobile-mini-bar-fill.hp { background: var(--color-hp); }
    .mobile-mini-bar-fill.mp { background: var(--color-mp); }
    .mobile-mini-bar-fill.xp { background: var(--color-exp); }

    /* --- Drawer: боковое меню --- */
    .mobile-drawer-overlay {
        position: fixed;
        inset: 0;
        z-index: 9000;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
        padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    }
    .mobile-drawer-overlay.open {
        opacity: 1;
        pointer-events: auto;
    }
    .mobile-drawer {
        position: fixed;
        top: 0;
        left: 0;
        width: min(300px, 85vw);
        height: 100vh;
        height: 100dvh;
        z-index: 9001;
        background: var(--color-panel);
        border-right: 1px solid var(--color-border);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        padding-top: var(--mobile-safe-top);
    }
    .mobile-drawer.open {
        transform: translateX(0);
    }
    .mobile-drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 14px 16px;
        border-bottom: 1px solid var(--color-border);
        flex-shrink: 0;
    }
    .mobile-drawer-header span {
        font-weight: 700;
        font-size: 1rem;
        color: var(--color-accent-bright);
        letter-spacing: 0.02em;
    }
    .mobile-drawer-close {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: rgba(239, 68, 68, 0.12);
        border: 1px solid rgba(239, 68, 68, 0.3);
        color: #f87171;
        font-size: 18px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background 0.15s, transform 0.15s;
    }
    .mobile-drawer-close:active {
        transform: scale(0.96);
    }
    .mobile-drawer-content {
        flex: 1;
        overflow-y: auto;
        padding: 12px;
        -webkit-overflow-scrolling: touch;
    }
    .mobile-drawer .side-panel {
        border: none;
        border-radius: var(--radius-md);
        padding: 12px;
        margin-bottom: 8px;
        background: var(--color-panel-light);
    }
    .mobile-drawer .side-panel + .side-panel {
        border-top: none;
        margin-top: 4px;
    }
    .mobile-drawer .nav-link {
        min-height: var(--mobile-touch-min);
        padding: 12px 14px;
        font-size: 0.9em;
        margin-bottom: 4px;
    }
    .mobile-drawer .npc-item {
        min-height: 44px;
        padding: 10px 12px;
        font-size: 0.88em;
    }

    /* --- Основной контент --- */
    .main-container {
        flex-direction: column;
        padding: 10px;
        padding-bottom: calc(10px + var(--mobile-safe-bottom));
        gap: 10px;
        flex: 1;
    }
    .left-column,
    .right-column {
        display: none;
    }
    .main-panel {
        width: 100%;
        min-height: 0;
    }

    /* --- Локация --- */
    .location-scene {
        flex-direction: column !important;
        gap: 12px;
    }
    .location-image {
        width: 100% !important;
        max-height: 180px;
        order: -1;
        border-radius: var(--radius-md);
        overflow: hidden;
    }
    .location-info {
        width: 100% !important;
    }

    /* --- Нижняя панель (чат) --- */
    .bottom-panel {
        flex-direction: column;
        padding: 0 10px 10px;
        padding-bottom: calc(10px + var(--mobile-safe-bottom));
        flex: none;
        height: auto;
        gap: 8px;
    }
    .chat-panel {
        min-height: 200px;
        max-height: 280px;
        border-radius: var(--radius-md);
        overflow: hidden;
    }
    .players-panel {
        display: none;
    }

    /* --- Бой: читаемая компактная раскладка --- */
    .combat-overlay {
        padding: 0;
        align-items: stretch;
        padding-top: var(--mobile-safe-top);
        padding-bottom: var(--mobile-safe-bottom);
    }
    .combat-panel {
        flex-direction: column;
        max-width: none;
        max-height: none;
        height: 100%;
        gap: 0;
    }
    .combat-enemy-side {
        order: 1;
        width: 100%;
        flex-direction: row;
        align-items: center;
        gap: 12px;
        padding: 12px;
        border-radius: 0;
        border-bottom: 1px solid var(--color-border);
        max-height: 100px;
    }
    .combat-enemy-side .combat-image {
        width: 64px;
        height: 64px;
        margin: 0;
        flex-shrink: 0;
        border-radius: var(--radius-sm);
    }
    .combat-enemy-side .combat-fighter-info { flex: 1; min-width: 0; }
    .combat-enemy-side .combat-enemy-details { text-align: left; font-size: 0.85em; }

    .combat-center {
        order: 2;
        flex: 1;
        min-height: 0;
        padding: 10px;
        overflow-y: auto;
    }
    .combat-log {
        font-size: 0.8em;
        line-height: 1.45;
    }

    .combat-player-side {
        order: 3;
        width: 100%;
        flex-direction: row;
        align-items: flex-start;
        gap: 10px;
        padding: 12px;
        border-top: 1px solid var(--color-border);
        max-height: none;
    }
    .combat-player-side .combat-image {
        width: 56px;
        height: 56px;
        margin: 0;
        flex-shrink: 0;
        border-radius: var(--radius-sm);
    }
    .combat-player-side .combat-fighter-info { flex: 1; min-width: 0; }

    .combat-attacks {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
    }
    .battle-attack-btn {
        width: calc(50% - 3px);
        min-height: var(--mobile-touch-min);
        padding: 10px 8px;
        font-size: 0.85em;
        border-radius: var(--radius-md);
    }
    .battle-attack-btn .attack-btn-name { font-size: 0.75em; }
    .battle-attack-btn .attack-btn-mp { font-size: 0.65em; }

    .combat-pet-side {
        order: 4;
        width: 100%;
        flex-direction: row;
        align-items: center;
        gap: 10px;
        padding: 10px 12px;
        border-top: 1px solid var(--color-border);
        max-height: 76px;
    }
    .combat-pet-side .combat-image {
        width: 48px;
        height: 48px;
        margin: 0;
        border-radius: var(--radius-sm);
    }

    .combat-bottom-controls {
        padding: 10px 12px;
        gap: 10px;
        flex-wrap: wrap;
    }
    .combat-surrender-btn,
    .combat-close-btn {
        padding: 12px 18px;
        font-size: 0.9em;
        min-height: var(--mobile-touch-min);
        border-radius: var(--radius-md);
        flex: 1;
        min-width: 120px;
    }

    /* --- Окна: полноэкранные на мобиле --- */
    .game-window {
        width: 100vw !important;
        width: 100dvw !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-width: none !important;
        max-height: none !important;
        top: 0 !important;
        left: 0 !important;
        transform: none !important;
        border-radius: 0;
        border: none;
        padding-top: var(--mobile-safe-top);
        padding-bottom: var(--mobile-safe-bottom);
    }
    .gw-close {
        width: 40px;
        height: 40px;
        font-size: 20px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .gw-header {
        cursor: default;
        padding: 12px 14px;
    }
    .gw-body {
        padding: 12px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #hero-window,
    #inventory-window,
    #attacks-window {
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
    }
    .inventory-body {
        flex-direction: column;
        gap: 12px;
    }
    .inventory-grid {
        width: 100% !important;
        height: auto !important;
    }
    .equipped-attacks-panel {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
    }

    .pets-window,
    .clan-container {
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: none !important;
    }
    .clan-sidebar { width: 80px; }

    .player-profile-container {
        width: 95vw !important;
        max-width: none !important;
    }
    .account-inner { width: 100% !important; }

    .header-dropdown {
        width: calc(100vw - 24px) !important;
        max-width: 400px;
        right: 50%;
        transform: translateX(50%);
        left: auto;
    }

    /* --- Лут / PVP попапы --- */
    .loot-popup-container {
        left: 10px;
        right: 10px;
        top: calc(var(--mobile-header-h) + 8px);
        top: calc(var(--mobile-header-h) + var(--mobile-safe-top) + 8px);
    }
    .loot-popup { min-width: auto; max-width: none; border-radius: var(--radius-lg); }
    .pvp-challenge-popup {
        left: 10px;
        right: 10px;
        width: auto;
        border-radius: var(--radius-lg);
    }

    /* --- Тач: минимум 44px --- */
    button:not(.header-icon-btn):not(.gw-close),
    .nav-link,
    .more-menu-item,
    .npc-item {
        min-height: var(--mobile-touch-min);
    }
    .nav-link {
        padding: 12px 14px !important;
        font-size: 0.9em;
    }

    /* --- NPC --- */
    .npc-trade-window {
        grid-template-columns: 1fr !important;
    }
    .npc-dialogue-avatar {
        width: 80px !important;
        height: 80px !important;
    }

    /* --- Торговля --- */
    .trade-body { flex-direction: column; }
    .trade-panel,
    .trade-exchange {
        min-width: unset;
        max-width: 100%;
        width: 100%;
    }

    .buff-tooltip { font-size: 0.85em; }
}

/* ========== ТЕЛЕФОН (<= 480px) ========== */
@media (max-width: 480px) {
    .game-header {
        height: 48px;
        min-height: calc(48px + var(--mobile-safe-top));
        padding: 6px 8px;
        padding-top: calc(6px + var(--mobile-safe-top));
    }
    .header-icon-btn {
        min-width: 42px;
        min-height: 42px;
        padding: 4px 6px;
    }
    .hib-icon { font-size: 1.15em; }

    .main-container { padding: 8px; gap: 8px; }
    .location-image { max-height: 140px; }

    .combat-enemy-side .combat-image { width: 56px; height: 56px; }
    .combat-player-side .combat-image { width: 50px; height: 50px; }
    .battle-attack-btn {
        padding: 8px 6px;
        min-height: 42px;
    }
    .combat-log { font-size: 0.75em; }

    .chat-panel {
        min-height: 180px;
        max-height: 240px;
    }

    .gw-body { padding: 10px; }
    .char-stats-row { grid-template-columns: repeat(2, 1fr); }
    .equipped-attacks-panel { grid-template-columns: 1fr !important; }
}

/* ========== Только десктоп: скрыть мобильные элементы ========== */
@media (min-width: 769px) {
    .mobile-hamburger,
    .mobile-mini-bars,
    .mobile-drawer-overlay,
    .mobile-drawer {
        display: none !important;
    }
}
