/* ============================================================================
 * Mobile Touch Controls & MOBA Combat Layout (iPhone / Android / iPad)
 * - Left floating analog joystick with directional glow
 * - Right MOBA cluster: Primary Attack + Radial Skill Arc + Interact/Loot + Potions
 * - Compact Hero HP/MP/XP strip & responsive viewport scaling for 844×390 / 390×844
 * ============================================================================ */

html, body {
  overscroll-behavior: none;
  -webkit-touch-callout: none;
}

#game {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

body.mobile-mode:not(.gamepad-mode) #ui-hud-bar,
body.mobile-mode #help,
body.mobile-mode #btn-autofollow,
body.mobile-mode:not(.gamepad-mode) #btn-gamepad {
  display: none !important;
}

/* Compact top-left & top-right chrome on mobile viewports */
body.mobile-mode #top-bar {
  top: max(6px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  max-width: min(35vw, 292px);
  gap: 3px;
}

body.mobile-mode #stats {
  font-size: 10px;
  line-height: 1.22;
  padding: 3px 6px;
  background: rgba(10, 8, 6, 0.66);
  border-radius: 4px;
}

body.mobile-mode .top-pills {
  gap: 3px;
  flex-wrap: wrap;
}

body.mobile-mode .lang-pill {
  font-size: 9.5px;
  padding: 2px 5px;
  min-height: 20px;
}

body.mobile-mode #gear {
  display: none;
}

body.mobile-mode #top-right-hud {
  top: max(5px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
}

body.mobile-mode #minimap-wrap {
  width: 168px !important;
  height: 162px !important;
}

body.mobile-mode #minimap-wrap .mm-circle {
  width: 150px !important;
  height: 150px !important;
  top: 6px !important;
}

body.mobile-mode #minimap-canvas {
  width: 150px !important;
  height: 150px !important;
}

body.mobile-mode .mm-action-btn {
  width: 22px !important;
  height: 22px !important;
}

body.mobile-mode .mm-action-btn svg {
  width: 11px !important;
  height: 11px !important;
}

body.mobile-mode .mm-btn-settings { left: 82px !important; top: -3px !important; }
body.mobile-mode .mm-btn-overlay  { left: 114px !important; top: 14px !important; }
body.mobile-mode .mm-btn-zoomin   { left: 134px !important; top: 44px !important; }
body.mobile-mode .mm-btn-zoomout  { left: 138px !important; top: 80px !important; }
body.mobile-mode .mm-btn-hide     { left: 127px !important; top: 110px !important; }

body.mobile-mode #minimap-sub,
body.mobile-mode #minimap-foot,
body.mobile-mode #minimap-tooltip {
  display: none;
}

body.mobile-mode #target {
  top: max(6px, env(safe-area-inset-top));
  transform: translateX(-50%) scale(0.84);
  transform-origin: top center;
}

/* Fit 581×754 ARPG panels cleanly on landscape mobile (390px height) without bottom HUD bar */
body.mobile-mode .ui-panel.left-dock {
  top: 50%;
  left: max(8px, env(safe-area-inset-left));
  transform: translateY(-50%) scale(var(--mobile-panel-scale, 0.48));
  transform-origin: left center;
  z-index: 60;
}

body.mobile-mode .ui-panel.right-dock {
  top: 50%;
  right: max(8px, env(safe-area-inset-right));
  transform: translateY(-50%) scale(var(--mobile-panel-scale, 0.48));
  transform-origin: right center;
  z-index: 60;
}

body.mobile-mode #skill-panel {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(var(--mobile-skill-scale, 0.64));
  transform-origin: center center;
  z-index: 62;
}

body.mobile-mode .npc-dialog {
  z-index: 64;
}

body.mobile-mode .char-modal-backdrop {
  z-index: 68;
}

body.mobile-mode .char-modal-box {
  max-height: calc(100vh - 16px);
  overflow-y: auto;
}

body.mobile-mode #item-tooltip {
  z-index: 72;
}

body.mobile-mode #cursor-item {
  z-index: 75;
}

body.mobile-mode #chat-dock {
  left: max(10px, env(safe-area-inset-left));
  bottom: max(236px, calc(env(safe-area-inset-bottom) + 232px));
  width: min(264px, 46vw);
}
body.mobile-mode .chat-ch-btn {
  padding: 3px 7px;
  font-size: 11px;
}
body.mobile-mode .chat-input,
body.mobile-mode .chat-send-btn {
  height: 27px;
  font-size: 11.5px;
}

/* Dim/disable MOBA touch pads whenever full panels/modals are open so taps go cleanly to UI */
body.mobile-mode.mobile-ui-open #mobile-controls {
  opacity: 0.18;
  pointer-events: none;
}

/* ---- Root Mobile Overlay ---- */
#mobile-controls {
  position: fixed;
  inset: 0;
  z-index: 32;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  font-family: Georgia, 'Times New Roman', serif;
  transition: opacity 0.16s ease;
}

#mobile-controls[hidden] {
  display: none !important;
}

/* ---- Left Virtual Joystick ---- */
#moba-joy-zone {
  position: absolute;
  left: max(6px, env(safe-area-inset-left));
  bottom: max(6px, env(safe-area-inset-bottom));
  width: min(42vw, 270px);
  height: min(58vh, 224px);
  pointer-events: auto;
  touch-action: none;
}

.moba-joy-base {
  position: absolute;
  left: 28px;
  bottom: 22px;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(28, 22, 16, 0.36) 0%, rgba(16, 12, 9, 0.72) 72%, rgba(92, 68, 36, 0.38) 100%);
  border: 2px solid rgba(196, 154, 86, 0.52);
  box-shadow:
    0 4px 18px rgba(0, 0, 0, 0.65),
    inset 0 0 16px rgba(0, 0, 0, 0.75);
  pointer-events: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.moba-joy-base::before {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  border: 1px dashed rgba(212, 172, 102, 0.24);
}

.moba-joy-base.active {
  border-color: rgba(242, 196, 109, 0.92);
  box-shadow:
    0 0 22px rgba(218, 160, 68, 0.36),
    inset 0 0 18px rgba(0, 0, 0, 0.8);
}

.moba-joy-dir {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  opacity: 0;
  background: conic-gradient(
    from -35deg,
    rgba(246, 198, 104, 0.65) 0deg,
    rgba(246, 198, 104, 0.0) 70deg,
    rgba(246, 198, 104, 0.0) 360deg
  );
  -webkit-mask: radial-gradient(transparent 58%, #000 62%);
  mask: radial-gradient(transparent 58%, #000 62%);
  pointer-events: none;
  transition: opacity 0.1s ease;
}

.moba-joy-base.active .moba-joy-dir {
  opacity: 1;
}

.moba-joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin-left: -24px;
  margin-top: -24px;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 32%, #e8c478 0%, #9b6f30 48%, #3c2710 100%);
  border: 2px solid #f5dca0;
  box-shadow:
    0 3px 10px rgba(0, 0, 0, 0.8),
    inset 0 1px 3px rgba(255, 245, 214, 0.65);
  pointer-events: none;
}

/* ---- Bottom-Center Compact Hero Status Strip ---- */
#moba-status-strip {
  position: absolute;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom));
  transform: translateX(-68%);
  width: 238px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: auto;
}

.moba-quick-menu {
  display: flex;
  justify-content: space-between;
  gap: 4px;
}

.moba-menu-btn {
  position: relative;
  padding: 3px 6px;
  border-radius: 5px;
  border: 1px solid rgba(176, 136, 74, 0.62);
  background: linear-gradient(180deg, rgba(38, 29, 20, 0.9), rgba(17, 13, 9, 0.92));
  color: #e6d2a8;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  touch-action: manipulation;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.65);
}

.moba-menu-btn:active,
.moba-menu-btn.on {
  border-color: #f0c46c;
  color: #fff2cc;
  background: linear-gradient(180deg, rgba(84, 58, 24, 0.94), rgba(38, 25, 10, 0.95));
}

.moba-menu-dot {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ff4738;
  border: 1px solid #ffdca8;
  box-shadow: 0 0 6px rgba(255, 71, 56, 0.9);
}

.moba-bars-card {
  background: rgba(14, 11, 8, 0.84);
  border: 1px solid rgba(148, 112, 60, 0.6);
  border-radius: 6px;
  padding: 4px 6px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.72);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.moba-bar-row {
  position: relative;
  height: 12px;
  background: #0b0807;
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid rgba(90, 70, 44, 0.55);
}

.moba-bar-fill {
  height: 100%;
  width: 100%;
  transition: width 0.08s linear;
}

.moba-bar-fill.hp {
  background: linear-gradient(90deg, #6f0f11 0%, #be1e24 65%, #e44236 100%);
}

.moba-bar-fill.mp {
  background: linear-gradient(90deg, #102768 0%, #1d4fb8 65%, #3a7ef0 100%);
}

.moba-bar-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 5px;
  font-size: 9.5px;
  font-weight: 700;
  color: #f7ecd6;
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
  pointer-events: none;
}

.moba-xp-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.moba-lvl-tag {
  font-size: 9.5px;
  color: #e4be70;
  font-weight: 700;
  white-space: nowrap;
}

.moba-xp-track {
  flex: 1;
  height: 3px;
  background: #1a1510;
  border-radius: 2px;
  overflow: hidden;
}

.moba-xp-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #9f7934, #f2cf7c);
}

/* ---- Right MOBA Combat & Radial Skill Cluster ---- */
#moba-right {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  width: 340px;
  height: 226px;
  pointer-events: none;
  transform-origin: bottom right;
}

.moba-round-btn {
  position: absolute;
  border-radius: 50%;
  padding: 0;
  margin: 0;
  border: 2px solid #b58d4b;
  background-color: #1a1410;
  color: #f4e4c1;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 4px 14px rgba(0, 0, 0, 0.8),
    inset 0 0 10px rgba(0, 0, 0, 0.72);
  transition: transform 0.07s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.moba-round-btn:active,
.moba-round-btn.pressed {
  transform: scale(0.92);
  border-color: #ffe09a;
}

/* Primary Attack Button (Bottom-Right Anchor) */
#moba-atk-btn {
  width: 78px;
  height: 78px;
  right: 14px;
  bottom: 12px;
  border: 3px solid #ddb05c;
  background:
    radial-gradient(circle at 50% 42%, rgba(92, 34, 22, 0.92), rgba(28, 14, 10, 0.96));
  box-shadow:
    0 0 20px rgba(204, 92, 44, 0.35),
    0 5px 16px rgba(0, 0, 0, 0.86),
    inset 0 0 12px rgba(255, 190, 110, 0.25);
}

#moba-atk-btn::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1.5px solid rgba(226, 178, 92, 0.34);
  pointer-events: none;
}

#moba-atk-btn.pressed {
  box-shadow:
    0 0 26px rgba(255, 146, 68, 0.72),
    0 3px 10px rgba(0, 0, 0, 0.9);
}

.moba-skill-art {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-repeat: no-repeat;
  pointer-events: none;
  overflow: hidden;
}

.moba-btn-cap {
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(12, 9, 7, 0.92);
  border: 1px solid rgba(186, 144, 76, 0.65);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #f3dfb6;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
}

/* Radial Class Skill Buttons */
.moba-skill-btn {
  overflow: visible;
}

.moba-skill-btn.selected {
  border-color: #ffd97d;
  box-shadow:
    0 0 14px rgba(255, 198, 92, 0.55),
    0 4px 12px rgba(0, 0, 0, 0.82);
}

.moba-skill-btn.aura-on {
  border-color: #6cf0ff;
  box-shadow:
    0 0 18px rgba(90, 224, 255, 0.78),
    0 4px 12px rgba(0, 0, 0, 0.82);
}

.moba-skill-btn.oom .moba-skill-art {
  filter: grayscale(0.85) brightness(0.52);
}

.moba-skill-btn.oom {
  border-color: rgba(110, 128, 168, 0.55);
}

.moba-mana-pip {
  position: absolute;
  top: -4px;
  right: -2px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 8px;
  background: #13397a;
  border: 1px solid #7cb3ff;
  color: #e6f2ff;
  font-size: 8.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.moba-skill-btn.oom .moba-mana-pip {
  background: #591818;
  border-color: #ff8080;
  color: #ffdcdc;
}

/* Drag-to-Aim Ring around active skill button */
.moba-aim-pad {
  position: absolute;
  width: 112px;
  height: 112px;
  margin-left: -56px;
  margin-top: -56px;
  border-radius: 50%;
  border: 1.5px dashed rgba(120, 214, 255, 0.78);
  background: radial-gradient(circle, rgba(64, 168, 255, 0.14) 0%, rgba(16, 36, 58, 0.28) 100%);
  pointer-events: none;
  z-index: 40;
}

.moba-aim-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  margin-top: -11px;
  border-radius: 50%;
  background: radial-gradient(circle, #c8f4ff 0%, #3aa8ff 70%, #14549c 100%);
  border: 1.5px solid #ffffff;
  box-shadow: 0 0 10px rgba(88, 198, 255, 0.9);
}

/* Contextual Interact / Pickup Button */
#moba-interact-btn {
  width: 44px;
  height: 44px;
  right: 98px;
  bottom: 8px;
  border-color: rgba(168, 144, 102, 0.55);
  background: radial-gradient(circle at 50% 38%, #2e261c, #14100c);
  font-size: 18px;
  opacity: 0.55;
}

#moba-interact-btn.has-target {
  opacity: 1;
  border-color: #ffd978;
  background: radial-gradient(circle at 50% 38%, #5c4318, #221708);
  box-shadow:
    0 0 16px rgba(255, 206, 94, 0.65),
    0 4px 12px rgba(0, 0, 0, 0.85);
}

/* Bottom Summoner-Row Quick Buttons: HP Potion, MP Potion, Loot Eye */
.moba-pot-btn {
  width: 42px;
  height: 42px;
  bottom: 10px;
  font-size: 13px;
  font-weight: 700;
}

#moba-hp-btn {
  right: 212px;
  border-color: #d45555;
  background: radial-gradient(circle at 38% 32%, #a82026 0%, #4d0c10 72%, #220608 100%);
}

#moba-mp-btn {
  right: 260px;
  border-color: #558ce6;
  background: radial-gradient(circle at 38% 32%, #1f56b8 0%, #0e2559 72%, #07112b 100%);
}

#moba-loot-btn {
  width: 38px;
  height: 38px;
  right: 308px;
  bottom: 12px;
  font-size: 15px;
  border-color: rgba(178, 146, 92, 0.65);
  background: radial-gradient(circle at 50% 38%, #33281b, #15100b);
}

#moba-loot-btn.on {
  border-color: #ffd875;
  box-shadow: 0 0 12px rgba(255, 208, 96, 0.58);
}

.moba-pot-btn.empty {
  opacity: 0.38;
  filter: grayscale(0.7);
}

.moba-count-badge {
  position: absolute;
  top: -5px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #14100d;
  border: 1px solid #d7b16a;
  color: #fff0cf;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* Responsive Portrait / Narrow Mobile Adaptation (e.g. 390×844) */
@media (max-width: 660px) {
  #moba-right {
    transform: scale(0.82);
  }
  #moba-joy-zone {
    width: 176px;
    height: 176px;
  }
  .moba-joy-base {
    left: 14px;
    bottom: 14px;
    width: 102px;
    height: 102px;
  }
  #moba-status-strip {
    left: max(10px, env(safe-area-inset-left));
    bottom: auto;
    top: calc(max(8px, env(safe-area-inset-top)) + 64px);
    transform: none;
    width: 172px;
  }
}

@media (max-height: 430px) {
  #moba-right {
    transform: scale(0.92);
  }
}
