/* Mobile Responsiveness CSS */
/* Optimized for landscape mobile gaming */

/* ======================================
   CSS Variables
   ====================================== */
:root {
    --mobile-action-btn-size: 48px;
    --mobile-joystick-size: 90px;
    --mobile-hotbar-height: 60px;
    --mobile-header-height: 36px;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

/* ======================================
   Utility Classes
   ====================================== */
.desktop-only {
    display: block;
}

.mobile-only {
    display: none !important;
}

/* ======================================
   Touch Device Detection
   Use max-height for landscape detection
   ====================================== */

/* Landscape mobile: height <= 500px catches most phones in landscape */
@media screen and (max-height: 500px),
screen and (max-width: 768px) {

    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: flex !important;
    }

    /* Body - prevent scrolling and bouncing */
    body {
        overflow: hidden;
        touch-action: none;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        position: fixed;
        width: 100%;
        height: 100%;
    }

    /* Game wrapper fills entire screen. Sem "display" aqui: quem mostra ou
       esconde o jogo e' o new.css (none no carregamento) e o style inline de
       show/hideGameInterface (flex no jogo, none de volta no login). Com o
       antigo "display: flex !important" a barra do topo, o direcional e a
       hotbar apareciam na tela de login. */
    #game-wrapper {
        flex-direction: row !important;
        min-width: unset !important;
        min-height: unset !important;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }

    /* Allow oogwrap to be visible for equipment but hide layout impact */
    #game-wrapper .oogwrap {
        display: block !important;
        position: absolute;
        top: 0;
        right: 0;
        width: 0;
        height: 0;
        overflow: visible;
        pointer-events: none;
        z-index: 9990;
    }

    /* Hide specific desktop elements inside oogwrap */
    .oogwrap .minimap-container,
    .oogwrap .character-status {
        display: none !important;
    }

    /* Ensure equipment wrapper is visible */
    .equipment-options-wrapper {
        display: block !important;
        pointer-events: auto;
    }

    /* Main game area - full width/height */
    #game-wrapper .main {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 100%;
        min-height: 0;
        overflow: hidden;
        position: relative;
    }

    /* Hide middle section (desktop hotbar area) */
    #game-wrapper .main .middle {
        display: none !important;
    }

    /* Canvas takes full space */
    #game-wrapper .main .upper {
        flex: 1 1 auto;
        min-height: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: hidden;
    }

    .canvas-wrapper {
        width: 100% !important;
        height: 100% !important;
        position: relative;
    }

    #screen {
        width: 100% !important;
        height: 100% !important;
        display: block;
    }

    /* Hide original hotbar */
    .hotbar {
        display: none !important;
    }

    /* Context menus - hide on mobile */
    .contextmenu {
        display: none !important;
    }

    /* Windows positioned on right side for mobile */
    .window {
        pointer-events: auto !important;
        position: fixed !important;
        top: 170px !important;
        left: auto !important;
        right: 5px !important;
        transform: scale(0.85);
        /* Slightly smaller to fit better */
        transform-origin: top right;
        width: 190px !important;
        /* Visual width matches equipment */
        max-width: 60vw;
        max-height: 60vh;
        z-index: 9995;
        overflow: visible;
        font-size: 11px;
    }

    /* Battle window stays on the right side */
    #battle-window {
        z-index: 9990 !important;
        top: 170px !important;
        right: 5px !important;
        left: auto !important;
    }

    /* Container windows (backpack, loot, corpse) open on the LEFT side */
    /* Target any window with containerIndex attribute (dynamically created) */
    .window[containerIndex] {
        left: 5px !important;
        right: auto !important;
        top: 50px !important;
        transform-origin: top left;
    }

    .window .header {
        height: 20px !important;
        line-height: 20px !important;
        font-size: 10px !important;
    }

    .window .body {
        max-height: 40vh !important;
        overflow-y: auto !important;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        padding: 2px !important;
    }

    .window .slot {
        width: 32px !important;
        height: 32px !important;
        margin: 1px !important;
        border: 1px solid #444;
        /* Add border to see slots better */
    }

    /* Larger touch targets */
    .slot {
        width: 36px !important;
        height: 36px !important;
    }

    .slot canvas {
        width: 36px !important;
        height: 36px !important;
    }

    /* Equipment panel - show in top right on mobile */
    .equipment.wrapper {
        position: fixed !important;
        top: 50px !important;
        right: 5px !important;
        left: auto !important;
        z-index: 9998;
        background: rgba(30, 30, 30, 0.95);
        border: 1px solid #555;
        border-radius: 6px;
        padding: 4px;
        transform: scale(0.75);
        transform-origin: top right;
    }

    .equipment-options-wrapper {
        display: block !important;
    }

    .equipment-column {
        gap: 2px !important;
    }

    .equipment.wrapper .slot {
        width: 32px !important;
        height: 32px !important;
    }

    .equipment.wrapper .slot canvas {
        width: 32px !important;
        height: 32px !important;
    }

    #player-capacity {
        font-size: 10px !important;
        padding: 2px !important;
    }

    .equipment-buttons {
        display: none !important;
    }
}

/* ======================================
   Mobile Status Bar (Top)
   ====================================== */
#mobile-status-bar {
    display: none;
    position: fixed;
    top: 0;
    left: var(--safe-area-left);
    right: var(--safe-area-right);
    height: var(--mobile-header-height);
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0.6));
    border-bottom: 1px solid #444;
    z-index: 10001;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 2px 12px;
    box-sizing: border-box;
    gap: 12px;
}

@media screen and (max-height: 500px),
screen and (max-width: 768px) {
    #mobile-status-bar {
        display: flex;
    }
}

.mobile-bar-container {
    flex: 1 1 auto;
    max-width: 400px;
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: center;
}

.mobile-bar {
    flex: 1;
    height: 18px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.mobile-bar-fill {
    height: 100%;
    transition: width 0.2s ease;
}

.mobile-bar-fill.health {
    background: linear-gradient(to bottom, #22cc22, #118811);
}

.mobile-bar-fill.mana {
    background: linear-gradient(to bottom, #3388ff, #2255aa);
}

.mobile-bar-text {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 11px;
    line-height: 18px;
    color: white;
    text-shadow: 1px 1px 2px black, -1px -1px 2px black;
    font-weight: bold;
}

#mobile-menu-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    font-size: 16px;
    flex-shrink: 0;
    min-height: 32px;
    padding: 0;
}

/* ======================================
   Mobile Action Bar (Bottom Overlay)
   Overlay style - doesn't take space from game
   ====================================== */
#mobile-action-bar {
    display: none;
    position: fixed;
    bottom: 15px;
    left: 10px;
    right: 10px;
    height: var(--mobile-hotbar-height);
    background: transparent;
    z-index: 10001;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 0;
    padding-left: var(--safe-area-left);
    padding-right: var(--safe-area-right);
    padding-bottom: var(--safe-area-bottom);
    box-sizing: border-box;
    pointer-events: none;
}

#mobile-action-bar>* {
    pointer-events: auto;
}

@media screen and (max-height: 500px),
screen and (max-width: 768px) {
    #mobile-action-bar {
        display: flex;
    }
}

/* ======================================
   Virtual Joystick (Left Side)
   ====================================== */
#mobile-joystick-zone {
    width: var(--mobile-joystick-size);
    height: var(--mobile-joystick-size);
    position: relative;
    flex-shrink: 0;
}

/* Direcional (d-pad): base circular escura, quatro setas nas bordas e um
   knob no centro que acompanha o dedo. A seta da direcao ativa acende (duas
   numa diagonal); tocar no centro e' modo de virar (.turning). */
#virtual-joystick {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(52, 52, 52, 0.78) 0%, rgba(24, 24, 24, 0.72) 70%, rgba(14, 14, 14, 0.8) 100%);
    border: 3px solid rgba(150, 150, 150, 0.55);
    box-shadow: 0 0 14px rgba(0, 0, 0, 0.55), inset 0 0 18px rgba(0, 0, 0, 0.5);
    touch-action: none;
}

#virtual-joystick .dpad-arrow {
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
    opacity: 0.85;
    transition: border-color 0.08s;
    pointer-events: none;
    z-index: 2;
}

/* triangulos por borda: tamanho relativo a base (var --dpad-arrow) */
#virtual-joystick {
    --dpad-arrow: calc(var(--mobile-joystick-size) * 0.085);
    --dpad-arrow-cor: rgba(225, 225, 225, 0.9);
    --dpad-arrow-acesa: #ffd75a;
}

#virtual-joystick .dpad-arrow[data-dir="north"] {
    top: 9%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 0 var(--dpad-arrow) calc(var(--dpad-arrow) * 1.3) var(--dpad-arrow);
    border-color: transparent transparent var(--dpad-arrow-cor) transparent;
}

#virtual-joystick .dpad-arrow[data-dir="south"] {
    bottom: 9%;
    left: 50%;
    transform: translateX(-50%);
    border-width: calc(var(--dpad-arrow) * 1.3) var(--dpad-arrow) 0 var(--dpad-arrow);
    border-color: var(--dpad-arrow-cor) transparent transparent transparent;
}

#virtual-joystick .dpad-arrow[data-dir="west"] {
    left: 9%;
    top: 50%;
    transform: translateY(-50%);
    border-width: var(--dpad-arrow) calc(var(--dpad-arrow) * 1.3) var(--dpad-arrow) 0;
    border-color: transparent var(--dpad-arrow-cor) transparent transparent;
}

#virtual-joystick .dpad-arrow[data-dir="east"] {
    right: 9%;
    top: 50%;
    transform: translateY(-50%);
    border-width: var(--dpad-arrow) 0 var(--dpad-arrow) calc(var(--dpad-arrow) * 1.3);
    border-color: transparent transparent transparent var(--dpad-arrow-cor);
}

#virtual-joystick .dpad-arrow.active[data-dir="north"] { border-bottom-color: var(--dpad-arrow-acesa); }
#virtual-joystick .dpad-arrow.active[data-dir="south"] { border-top-color: var(--dpad-arrow-acesa); }
#virtual-joystick .dpad-arrow.active[data-dir="west"] { border-right-color: var(--dpad-arrow-acesa); }
#virtual-joystick .dpad-arrow.active[data-dir="east"] { border-left-color: var(--dpad-arrow-acesa); }

#joystick-knob {
    position: absolute;
    width: 30%;
    height: 30%;
    top: 35%;
    left: 35%;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, rgba(90, 90, 90, 0.95) 0%, rgba(40, 40, 40, 0.95) 70%);
    border: 2px solid rgba(160, 160, 160, 0.7);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
    transition: transform 0.05s ease-out;
    pointer-events: none;
    z-index: 1;
}

#virtual-joystick.turning #joystick-knob {
    border-color: var(--dpad-arrow-acesa);
}

/* ======================================
   Mobile Hotbar (Center) - Skill slots
   ====================================== */
#mobile-hotbar {
    display: flex;
    flex: 0 1 auto;
    gap: 6px;
    justify-content: center;
    align-items: center;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    border: 1px solid #444;
    max-width: 250px;
    overflow-x: auto;
    scrollbar-width: none;
}

#mobile-hotbar::-webkit-scrollbar {
    display: none;
}

.mobile-hotbar-slot {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border: 2px solid #555;
    border-radius: 6px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.mobile-hotbar-slot:active {
    transform: scale(0.95);
    border-color: #888;
}

.mobile-hotbar-slot canvas {
    width: 32px;
    height: 32px;
}

.mobile-slot-key {
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 10px;
    color: #999;
    font-weight: bold;
    text-shadow: 1px 1px 1px black;
}

/* ======================================
   Action Buttons (Right Side)
   ====================================== */
#mobile-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    align-items: flex-end;
}

.mobile-action-btn {
    width: var(--mobile-action-btn-size);
    height: var(--mobile-action-btn-size);
    min-width: var(--mobile-action-btn-size);
    min-height: var(--mobile-action-btn-size);
    border-radius: 50%;
    border: 3px solid;
    color: white;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
    padding: 0;
}

.mobile-action-btn:active {
    transform: scale(0.9);
    filter: brightness(1.2);
}

.mobile-action-btn.attack {
    background: linear-gradient(145deg, #cc2222, #881111);
    border-color: #ff5555;
}

.mobile-action-btn.use {
    background: linear-gradient(145deg, #22aa22, #116611);
    border-color: #55ff55;
}

.mobile-action-btn.look {
    background: linear-gradient(145deg, #2255cc, #113388);
    border-color: #5588ff;
}

.mobile-action-btn.inventory {
    background: linear-gradient(145deg, #aa8833, #775522);
    border-color: #ddaa44;
}

#mobile-panel-tabs {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 0 4px;
}

.mobile-tab-btn {
    background: rgba(20, 20, 26, 0.85);
    border: 1px solid #555;
    border-radius: 6px;
    color: #ccc;
    cursor: pointer;
    font-size: 18px;
    height: 40px;
    width: 44px;
    padding: 0;
}

.mobile-tab-btn.active {
    border-color: gold;
    color: gold;
    box-shadow: 0px 0px 8px 0px gold;
}

.mobile-action-btn.precise.active {
    border-color: gold;
    box-shadow: 0px 0px 10px 0px gold;
}

.mobile-action-btn.equipment {
    background: linear-gradient(145deg, #8844aa, #553377);
    border-color: #aa66dd;
}

/* Hotkey preset cycle button (P1..P6): tap goes to the next preset; flashes on a switch */
.mobile-action-btn.preset {
    background-color: rgba(30, 30, 30, 0.9);
    border-color: #555;
    color: #ddd;
    font-size: 13px;
    font-weight: bold;
    user-select: none;
}

.mobile-action-btn.preset.flash {
    background-color: rgba(212, 160, 23, 0.9);
    color: #fff;
    transition: background-color 0.2s, color 0.2s;
}

.mobile-action-btn.chat {
    background: linear-gradient(145deg, #22aaaa, #117777);
    border-color: #44dddd;
}

/* ======================================
   Mobile Chat Overlay
   ====================================== */
@media screen and (max-height: 500px),
screen and (max-width: 768px) {

    /* Chat is hidden by default on mobile */
    #game-wrapper .main .lower {
        display: none !important;
    }

    /* When chat is active (toggled via JS) */
    #game-wrapper .main .lower.mobile-chat-active {
        display: flex !important;
        position: fixed !important;
        bottom: 70px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 90vw !important;
        max-width: 500px !important;
        height: 35vh !important;
        background: rgba(20, 20, 20, 0.95) !important;
        border: 2px solid #44dddd !important;
        border-radius: 8px !important;
        z-index: 10000 !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    .mobile-chat-active .chatbox-wrapper {
        flex: 1;
        display: flex;
        flex-direction: column;
        height: 100%;
    }

    .mobile-chat-active .wrapper-header {
        padding: 4px;
        background: rgba(40, 40, 40, 0.9);
    }

    .mobile-chat-active #chat-text {
        flex: 1;
        overflow-y: auto;
    }

    .mobile-chat-active .chat-footer {
        padding: 4px;
        display: flex;
        gap: 4px;
    }

    .mobile-chat-active #chat-input {
        flex: 1;
        font-size: 14px;
        padding: 8px;
        border-radius: 4px;
    }
}

/* Menu button in action bar */
#mobile-menu-btn.mobile-action-btn {
    background: linear-gradient(145deg, #555, #333);
    border-color: #888;
    font-size: 18px;
}

/* ======================================
   Landscape Specific Optimizations
   ====================================== */
@media screen and (max-height: 500px) and (orientation: landscape) {

    :root {
        --mobile-action-btn-size: 44px;
        --mobile-joystick-size: 80px;
        --mobile-hotbar-height: 50px;
        --mobile-header-height: 32px;
    }

    /* Compact status bar */
    #mobile-status-bar {
        height: 28px;
    }

    .mobile-bar {
        height: 16px;
    }

    .mobile-bar-text {
        font-size: 10px;
        line-height: 16px;
    }

    #mobile-menu-btn {
        width: 28px;
        height: 28px;
        min-height: 28px;
        font-size: 14px;
    }

    /* Joystick positioning - higher for landscape */
    #mobile-action-bar {
        bottom: 12px;
        left: 8px;
        right: 8px;
    }

    /* Smaller touch targets in compact landscape */
    .mobile-action-btn {
        font-size: 16px;
    }

    #mobile-hotbar .slot {
        width: 32px !important;
        height: 32px !important;
    }
}

/* ======================================
   Portrait Mode (Phone Upright)
   ====================================== */
@media screen and (max-width: 768px) and (orientation: portrait) {

    :root {
        --mobile-action-btn-size: 56px;
        --mobile-joystick-size: 110px;
    }

    /* Show chat in portrait */
    #game-wrapper .main .lower {
        display: block !important;
        max-height: 80px;
        flex: 0 0 auto;
    }

    /* Bottom bar positions */
    #mobile-action-bar {
        bottom: 90px;
    }
}

/* ======================================
   iOS Safari / Notch Support
   ====================================== */
@supports (padding: env(safe-area-inset-top)) {
    #mobile-status-bar {
        padding-top: env(safe-area-inset-top);
        height: calc(var(--mobile-header-height) + env(safe-area-inset-top));
    }
}

/* Prevent iOS rubber banding */
@supports (-webkit-touch-callout: none) {

    html,
    body {
        height: 100%;
        overflow: hidden;
    }

    #game-wrapper {
        height: -webkit-fill-available;
    }
}

/* ======================================
   Debug Statistics - Make Smaller on Mobile
   ====================================== */
@media screen and (max-height: 500px),
screen and (max-width: 768px) {
    #debug-statistics {
        font-size: 8px !important;
        top: 40px !important;
        left: 4px !important;
        max-width: 200px;
        background: rgba(0, 0, 0, 0.7);
        padding: 4px;
        border-radius: 4px;
    }
}
/* ======================================================================
   LAYOUT MOBILE (body.m-ui) -- Touch.__applyLayout liga as classes e poe as
   medidas em --m-* no :root. Referencia de comportamento: o client do
   Minibia. Tudo aqui vence as regras de media query acima.

   retrato:  topo | tela de jogo (largura toda) | vida e mana | controles
   paisagem: topo (com vida e mana) | tela de jogo centralizada | controles
             por cima das margens laterais
   ====================================================================== */

body.m-ui {
    --m-ui-bg: rgba(14, 15, 17, 0.96);
    --m-ui-borda: rgba(120, 120, 120, 0.35);
    --m-btn-bg: rgba(28, 30, 33, 0.92);
    --m-btn-borda: rgba(160, 160, 160, 0.45);
    background: #000;
}

/* ---- tela de jogo: retangulo exato calculado em JS, sem distorcao ---- */
body.m-ui #game-wrapper .main .upper {
    position: fixed !important;
    left: var(--m-canvas-x) !important;
    top: var(--m-canvas-y) !important;
    width: var(--m-canvas-w) !important;
    height: var(--m-canvas-h) !important;
    flex: none !important;
    z-index: 1;
}

body.m-ui #game-wrapper .main .upper .canvas-wrapper {
    width: 100% !important;
    height: 100% !important;
    /* canvas.css da ao wrapper min 480x352 (o canvas do desktop): no
       celular isso vencia a largura e o canvas vazava da tela */
    min-width: 0 !important;
    min-height: 0 !important;
}

body.m-ui #screen {
    width: 100% !important;
    height: 100% !important;
    transform: none !important;
}

/* ---- barra do topo ---- */
body.m-ui #mobile-status-bar {
    position: fixed !important;
    left: 0;
    right: 0;
    top: 0;
    height: var(--m-topbar);
    padding: 0 6px;
    display: flex !important;
    align-items: center;
    gap: 6px;
    background: var(--m-ui-bg);
    border-bottom: 1px solid var(--m-ui-borda);
    z-index: 9000;
    box-sizing: border-box;
}

body.m-ui .mobile-top-btn,
body.m-ui .mobile-tab-btn {
    flex: none;
    /* 8 botoes no topo em retrato (menu, tela cheia, 6 abas): num aparelho de
       320 px os 34 px fixos passavam da tela */
    width: clamp(28px, calc((100vw - 12px - 9 * 6px) / 8), 34px) !important;
    min-width: 0 !important;
    margin: 0 !important;
    box-sizing: border-box;
    height: 30px;
    padding: 0;
    border-radius: 6px;
    border: 1px solid var(--m-btn-borda);
    background: var(--m-btn-bg);
    color: #e8e8e8;
    font-size: 17px;
    line-height: 28px;
    text-align: center;
    touch-action: manipulation;
}

body.m-ui .mobile-tab-btn.active {
    border-color: #ffd75a;
    box-shadow: 0 0 6px rgba(255, 215, 90, 0.45);
}

body.m-ui #mobile-panel-tabs {
    display: flex !important;
    gap: 4px;
    margin-left: auto;
    overflow-x: auto;
    scrollbar-width: none;
}

body.m-ui #mobile-panel-tabs::-webkit-scrollbar {
    display: none;
}

/* barras de vida/mana */
body.m-ui .mobile-bar-container {
    display: flex !important;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
}

body.m-ui .mobile-bar {
    flex: 1 1 0;
    max-width: none !important;
    width: auto !important;
    height: 22px;
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    background: rgba(40, 40, 40, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.6);
}

/* retrato: vida e mana saem do topo e ficam logo abaixo da tela de jogo */
body.m-ui.m-portrait .mobile-bar-container {
    position: fixed;
    left: 6px;
    right: 6px;
    top: var(--m-bars-top);
    height: 30px;
    align-items: center;
}

/* ---- controles ---- */
body.m-ui #mobile-action-bar {
    position: fixed !important;
    display: grid !important;
    z-index: 8000;
    box-sizing: border-box;
    height: auto !important;
    background: transparent;
    padding: 0 !important;
}

/* retrato: o resto da altura embaixo; direcional | acoes | hotbar */
body.m-ui.m-portrait #mobile-action-bar {
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--m-controls-h) + var(--safe-area-bottom)) !important;
    padding: 8px 10px calc(8px + var(--safe-area-bottom)) !important;
    grid-template-columns: auto auto auto;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    background: var(--m-ui-bg);
    border-top: 1px solid var(--m-ui-borda);
    --mobile-joystick-size: var(--m-dpad);
}

/* paisagem: camada transparente; direcional embaixo a esquerda, acoes e
   hotbar embaixo a direita, por cima das margens da tela de jogo */
body.m-ui.m-landscape #mobile-action-bar {
    inset: var(--m-topbar) 0 0 0;
    pointer-events: none;
    display: block !important;
    --mobile-joystick-size: min(max(110px, calc(var(--m-margin) - 20px)), 44vh, 160px);
    --m-slot: min(max(40px, calc((var(--m-margin) - 34px) / 3)), 11vh, 52px);
}

body.m-ui.m-landscape #mobile-action-bar > * {
    pointer-events: auto;
}

body.m-ui #mobile-joystick-zone {
    width: var(--mobile-joystick-size) !important;
    height: var(--mobile-joystick-size) !important;
    position: relative;
}

body.m-ui.m-landscape #mobile-joystick-zone {
    position: absolute;
    left: calc(10px + var(--safe-area-left));
    bottom: 12px;
}

/* acoes: 2 colunas de botoes redondos */
body.m-ui #mobile-actions {
    display: grid !important;
    grid-template-columns: repeat(2, var(--m-act, 44px));
    gap: 8px;
    justify-content: center;
    align-content: center;
    position: static;
}

body.m-ui.m-landscape #mobile-actions {
    position: absolute;
    /* 6 botoes (com o de preset da hotbar): duas colunas, que crescem para a esquerda a partir da borda direita */
    right: calc(14px + var(--safe-area-right) + 3 * var(--m-slot) + 16px);
    bottom: 12px;
    grid-template-columns: repeat(2, var(--m-act, 44px));
}

body.m-ui #mobile-actions .mobile-action-btn,
body.m-ui .mobile-hotbar-slot,
body.m-ui .mobile-hotbar-edit {
    box-sizing: border-box !important;
    padding: 0 !important;
    min-width: 0 !important;
    min-height: 0 !important;
}

body.m-ui #mobile-actions .mobile-action-btn {
    width: var(--m-act, 44px) !important;
    height: var(--m-act, 44px) !important;
    border-width: 2px !important;
    border-radius: 50%;
    font-size: 19px;
    margin: 0 !important;
}

/* hotbar: 8 slots redondos + lapis, em 3 colunas */
body.m-ui #mobile-hotbar {
    display: grid !important;
    grid-template-columns: repeat(3, var(--m-slot));
    gap: 6px;
    justify-content: end;
    align-content: center;
    overflow: visible !important;
    height: auto !important;
    max-width: none !important;
    position: static;
    background: none !important;
    border: 0 !important;
    padding: 0 !important;
}

body.m-ui.m-landscape #mobile-hotbar {
    position: absolute;
    right: calc(10px + var(--safe-area-right));
    bottom: 12px;
}

body.m-ui .mobile-hotbar-slot {
    width: var(--m-slot) !important;
    height: var(--m-slot) !important;
    border-radius: 50% !important;
    border: 2px dashed rgba(170, 170, 170, 0.45) !important;
    background: rgba(20, 20, 22, 0.75) !important;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 !important;
}

body.m-ui .mobile-hotbar-slot canvas {
    width: 72% !important;
    height: 72% !important;
    border-radius: 50%;
}

body.m-ui .mobile-hotbar-slot .mobile-slot-key {
    position: absolute;
    right: 4%;
    bottom: 2%;
    font: bold 12px sans-serif;
    color: #ddd;
    text-shadow: 0 0 3px #000;
}

body.m-ui .mobile-hotbar-edit {
    width: var(--m-slot);
    height: var(--m-slot);
    border-radius: 50%;
    border: 2px solid var(--m-btn-borda);
    background: var(--m-btn-bg);
    color: #eee;
    font-size: calc(var(--m-slot) * 0.38);
    padding: 0;
}

/* ---- chat ----
   retrato: ocupa o vao entre vida/mana e os controles (a tela de jogo e'
   limitada pela largura, entao sobra altura); o botao de chat o esconde.
   paisagem: escondido; o botao de chat o abre por cima da parte de baixo. */
body.m-ui #game-wrapper .main .lower {
    display: none !important;
}

body.m-ui.m-portrait:not(.m-chat-hidden) #game-wrapper .main .lower {
    display: flex !important;
    flex-direction: column;
    position: fixed !important;
    left: 0;
    right: 0;
    top: var(--m-controls-top);
    bottom: calc(var(--m-controls-h) + var(--safe-area-bottom));
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    width: auto !important;
    max-width: none !important;
    transform: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    z-index: 2 !important;
    background: var(--m-ui-bg) !important;
    overflow: hidden !important;
}

body.m-ui.m-portrait #game-wrapper .main .lower .chatbox-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

body.m-ui.m-portrait #game-wrapper .main .lower #chat-text {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* paisagem: o botao de chat abre o painel .mobile-chat-active (acima) */
body.m-ui.m-landscape #game-wrapper .main .lower.mobile-chat-active {
    display: flex !important;
}

body.m-ui #chat-resizer {
    display: none !important;
}
