.mobile-hud-shell {
  display: none;
}

@media (max-width: 1024px) and (pointer: coarse) {
  body.msx-game-stage {
    align-items: stretch;
    justify-content: stretch;
    background: #000;
  }

  body.msx-game-stage .launcher-window {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  body.msx-game-stage .window-titlebar {
    display: none;
  }

  body.msx-game-stage #stage-game.active {
    width: 100vw;
    height: 100dvh;
    flex: none;
    overflow: hidden;
  }

  body.msx-game-stage #gameCanvas {
    width: 100%;
    height: 100%;
  }

  body.msx-game-stage .field-controls-hint,
  body.msx-game-stage .field-quick-warp,
  body.msx-game-stage #sprite-status-hud,
  body.msx-game-stage .hud-footer-bar > div:last-child {
    display: none !important;
  }

  body.msx-game-stage #stage-game.mobile-dev-open .field-controls-hint {
    display: block !important;
    right: calc(env(safe-area-inset-right) + 12px);
    bottom: 78px;
    max-width: 210px;
    font-size: 10px;
    opacity: 0.9;
  }

  body.msx-game-stage #stage-game.mobile-dev-open .field-quick-warp {
    display: flex !important;
    left: calc(env(safe-area-inset-left) + 12px);
    bottom: 78px;
    transform: scale(0.86);
    transform-origin: left bottom;
  }

  body.msx-game-stage .game-top-bar {
    top: calc(env(safe-area-inset-top) + 8px);
    left: calc(env(safe-area-inset-left) + 10px);
  }

  body.msx-game-stage .game-top-bar > div {
    width: 120px;
    padding: 4px !important;
    border-radius: 10px !important;
    background: rgba(6, 10, 14, 0.62) !important;
    backdrop-filter: blur(7px);
  }

  body.msx-game-stage .game-top-bar > div > div:first-child {
    margin: 0 2px 3px !important;
    font-size: 9px !important;
    gap: 8px;
  }

  body.msx-game-stage #minimapCanvas {
    width: 106px !important;
    height: 56px !important;
    opacity: 0.82;
  }

  body.msx-game-stage #auto-play-toggle {
    display: none !important;
  }

  body.msx-game-stage .field-mode-banner {
    display: none !important;
  }

  body.msx-game-stage .field-toast {
    top: calc(env(safe-area-inset-top) + 8px);
    max-width: 58vw;
    padding: 6px 10px;
    font-size: 10px;
    border-radius: 12px;
  }

  body.msx-game-stage .field-dpad {
    left: calc(env(safe-area-inset-left) + 12px);
    bottom: calc(env(safe-area-inset-bottom) + 12px);
    grid-template-columns: 44px 44px 44px;
    grid-template-rows: 44px 44px 44px;
    gap: 2px;
    opacity: 0.78;
  }

  body.msx-game-stage .field-dpad button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(8, 15, 22, 0.48);
    backdrop-filter: blur(5px);
  }

  body.msx-game-stage .field-dpad .pad-jump {
    display: none;
  }

  body.msx-game-stage .mobile-hud-shell {
    position: absolute;
    inset: 0;
    z-index: 60;
    display: block;
    pointer-events: none;
  }

  body.msx-game-stage .mobile-top-actions {
    position: absolute;
    top: calc(env(safe-area-inset-top) + 8px);
    right: calc(env(safe-area-inset-right) + 10px);
    display: flex;
    gap: 6px;
    pointer-events: auto;
  }

  body.msx-game-stage .mobile-top-actions button,
  body.msx-game-stage .mobile-menu-drawer button {
    min-width: 42px;
    min-height: 38px;
    border: 1px solid rgba(255,255,255,0.16);
    border-radius: 12px;
    background: rgba(7, 12, 18, 0.62);
    color: #f4fbff;
    font: 700 10px Kanit, sans-serif;
    backdrop-filter: blur(8px);
  }

  body.msx-game-stage .mobile-combat-controls {
    position: absolute;
    right: calc(env(safe-area-inset-right) + 14px);
    bottom: calc(env(safe-area-inset-bottom) + 14px);
    width: 170px;
    height: 132px;
    display: block;
    pointer-events: none;
  }

  body.msx-game-stage .mobile-combat-controls button {
    position: absolute;
    pointer-events: auto;
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    font: 800 11px Kanit, sans-serif;
    text-shadow: 0 1px 3px #000;
    backdrop-filter: blur(6px);
    touch-action: none;
  }

  body.msx-game-stage .mobile-action-jump {
    width: 72px;
    height: 72px;
    right: 0;
    bottom: 0;
    border-radius: 50%;
    background: rgba(58, 141, 255, 0.56);
  }

  body.msx-game-stage .mobile-action-attack {
    width: 60px;
    height: 60px;
    right: 78px;
    bottom: 18px;
    border-radius: 50%;
    background: rgba(255, 107, 74, 0.58);
  }

  body.msx-game-stage .mobile-action-auto {
    width: 50px;
    height: 40px;
    right: 62px;
    bottom: 86px;
    border-radius: 14px;
    background: rgba(10, 18, 24, 0.66);
    color: #9dffc4;
  }

  body.msx-game-stage .mobile-menu-drawer {
    position: absolute;
    top: calc(env(safe-area-inset-top) + 54px);
    right: calc(env(safe-area-inset-right) + 10px);
    display: none;
    grid-template-columns: repeat(2, minmax(82px, 1fr));
    gap: 7px;
    width: 188px;
    padding: 9px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 16px;
    background: rgba(5, 9, 14, 0.82);
    backdrop-filter: blur(12px);
    pointer-events: auto;
  }

  body.msx-game-stage #stage-game.mobile-menu-open .mobile-menu-drawer {
    display: grid;
  }

  body.msx-game-stage .game-bottom-bar {
    bottom: calc(env(safe-area-inset-bottom) + 7px);
    left: 50%;
    right: auto;
    width: min(46vw, 360px);
    transform: translateX(-50%);
  }

  body.msx-game-stage .hud-footer-bar {
    border: 0;
    border-radius: 12px;
    padding: 5px 8px;
    background: rgba(5, 9, 14, 0.58);
    backdrop-filter: blur(7px);
  }

  body.msx-game-stage .hud-gauges {
    gap: 8px;
    max-width: none;
  }

  body.msx-game-stage .hud-char-badge {
    gap: 5px;
  }

  body.msx-game-stage .hud-job-portrait {
    width: 28px;
    height: 28px;
  }

  body.msx-game-stage .hud-job-line {
    display: none;
  }

  body.msx-game-stage .hud-level-tag {
    font-size: 9px;
    padding: 1px 4px;
  }

  body.msx-game-stage .hud-bar-label {
    font-size: 7px;
  }

  body.msx-game-stage .chat-container {
    display: none;
    width: min(74vw, 520px);
    max-width: none;
    padding: 0;
    pointer-events: auto;
  }

  body.msx-game-stage #stage-game.mobile-chat-open .chat-container {
    display: block;
  }

  body.msx-game-stage #stage-game.mobile-chat-open .game-bottom-bar {
    width: min(74vw, 520px);
    bottom: calc(env(safe-area-inset-bottom) + 8px);
  }

  body.msx-game-stage #stage-game.mobile-chat-open .hud-footer-bar {
    display: none;
  }

  body.msx-game-stage .chat-box-log {
    height: 84px;
    border-radius: 12px 12px 0 0;
    background: rgba(4, 8, 12, 0.72);
    backdrop-filter: blur(8px);
  }

  body.msx-game-stage .chat-input-row {
    border-radius: 0 0 12px 12px;
    background: rgba(4, 8, 12, 0.88);
  }

  body.msx-game-stage #stage-game.mobile-hud-hidden .field-dpad,
  body.msx-game-stage #stage-game.mobile-hud-hidden .mobile-combat-controls,
  body.msx-game-stage #stage-game.mobile-hud-hidden .game-top-bar,
  body.msx-game-stage #stage-game.mobile-hud-hidden .game-bottom-bar {
    display: none;
  }
}


#mobile-chat-send {
  display: none;
}

@media (max-width: 1024px) and (pointer: coarse) {
  body.msx-game-stage #stage-game.mobile-chat-open .game-bottom-bar {
    position: absolute;
    left: 50%;
    right: auto;
    bottom: calc(env(safe-area-inset-bottom) + 10px);
    width: min(88vw, 560px);
    max-height: min(34dvh, 128px);
    transform: translateX(-50%);
  }

  body.msx-game-stage #stage-game.mobile-chat-open .chat-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-height: min(34dvh, 128px);
  }
  body.msx-game-stage #stage-game.mobile-chat-open .chat-box-log {
    flex: 0 1 auto;
    height: min(16dvh, 58px);
    min-height: 38px;
    padding: 5px 8px;
    font-size: 10px;
    border-radius: 12px 12px 0 0;
    overflow-y: auto;
  }

  body.msx-game-stage #stage-game.mobile-chat-open .chat-input-row {
    display: flex;
    align-items: stretch;
    min-height: 44px;
    border-radius: 0 0 12px 12px;
    overflow: hidden;
  }

  body.msx-game-stage #stage-game.mobile-chat-open #game-chat-input {
    min-width: 0;
    min-height: 44px;
    padding: 8px 10px;
    font-size: 16px !important;
    user-select: text;
    -webkit-user-select: text;
  }
  body.msx-game-stage #stage-game.mobile-chat-open #mobile-chat-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 64px;
    min-height: 44px;
    padding: 0 12px;
    border: 0;
    border-left: 1px solid rgba(255,255,255,0.14);
    background: rgba(0, 176, 122, 0.82);
    color: #fff;
    font: 800 11px Kanit, sans-serif;
    letter-spacing: 0.02em;
    touch-action: manipulation;
  }
}

/* Match the pickup action to the existing touch controls. */
@media (max-width: 1024px) and (pointer: coarse) {
  body.msx-game-stage #mobile-pickup-button {
    width: 44px;
    height: 44px;
    right: 122px;
    bottom: 86px;
    border-radius: 14px;
    background: rgba(10, 18, 24, 0.66);
  }
}

/* Immersive play shell: once inside the game, the browser viewport is the client. */
body.msx-game-stage {
  align-items: stretch;
  justify-content: stretch;
  background: #000;
}
body.msx-game-stage .launcher-window {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
body.msx-game-stage .window-titlebar { display: none; }
body.msx-game-stage #stage-game.active { width: 100vw; height: 100dvh; flex: none; overflow: hidden; }
body.msx-game-stage #gameCanvas { width: 100%; height: 100%; }

@media (hover: hover) and (pointer: fine) {
  body.msx-game-stage .field-dpad,
  body.msx-game-stage .field-controls-hint,
  body.msx-game-stage #sprite-status-hud,
  body.msx-game-stage #auto-play-toggle,
  body.msx-game-stage .field-mode-banner,
  body.msx-game-stage .mobile-hud-shell {
    display: none !important;
  }
}
