/* Mobile / tablet touch controls + HUD tweaks */
html.touch-play,
html.touch-play body {
  touch-action: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

canvas#game,
canvas#overlay {
  touch-action: none;
}

.touch-controls {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.touch-controls.hidden { display: none; }

.touch-joystick {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(88px, calc(72px + env(safe-area-inset-bottom)));
  width: 130px;
  height: 130px;
  pointer-events: auto;
}

.touch-joy-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(14, 10, 22, 0.55);
  border: 2px solid rgba(122, 58, 240, 0.45);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.35);
}

.touch-joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(122, 58, 240, 0.85), rgba(90, 40, 200, 0.9));
  border: 2px solid #000;
  box-shadow: 0 3px 0 #000, inset 1px 1px 0 rgba(255, 255, 255, 0.25);
  will-change: transform;
}

.touch-actions {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(82px, calc(68px + env(safe-area-inset-bottom)));
  display: grid;
  grid-template-columns: 56px 56px;
  grid-template-rows: 48px 64px 64px;
  gap: 8px;
  pointer-events: auto;
}

.touch-btn {
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-weight: bold;
  font-size: 10px;
  letter-spacing: 0.5px;
  color: #e8e4f0;
  background: linear-gradient(180deg, #3a3450, #252030);
  border: 2px solid #000;
  box-shadow: 0 3px 0 #000, inset 1px 1px 0 rgba(255, 255, 255, 0.12);
  border-radius: 0;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #000, inset 0 2px 4px rgba(0, 0, 0, 0.35);
}

.touch-pause {
  grid-column: 1;
  grid-row: 1;
  font-size: 16px;
  background: linear-gradient(180deg, #4a4062, #2a2438);
}

.touch-skills {
  grid-column: 2;
  grid-row: 1;
  font-size: 8px;
  color: #ffd95e;
  background: linear-gradient(180deg, #3a2818, #1a1008);
  border-color: #7a6222;
}

.touch-focus {
  grid-column: 1 / -1;
  grid-row: 2;
  color: #68d8f8;
  background: linear-gradient(180deg, #1e4a5a, #122830);
  border-color: #2a6a7a;
}

.touch-dash {
  grid-column: 1 / -1;
  grid-row: 3;
  font-size: 13px;
  color: #fff;
  background: linear-gradient(180deg, #9a5cf8, #6226d8);
}

/* HUD layout when touch controls visible */
body.touch-play .skills-fab { display: none; }

body.touch-play .hotbar {
  bottom: max(8px, env(safe-area-inset-bottom));
  transform: translateX(-50%) scale(0.82);
  transform-origin: center bottom;
}

body.touch-play .hud-top-left {
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  width: min(200px, 42vw);
  padding: 6px;
  gap: 4px;
}

body.touch-play .hud-top-center {
  top: max(6px, env(safe-area-inset-top));
}

body.touch-play .run-timer { font-size: 22px; }

body.touch-play .map-name { font-size: 9px; }

body.touch-play .boss-bar {
  width: min(280px, 72vw);
  padding: 4px 6px;
}

body.touch-play .hud-top-right {
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  max-width: 38vw;
}

body.touch-play .points-chip,
body.touch-play .kills-chip {
  font-size: 11px;
  padding: 3px 8px;
}

body.touch-play .quest-tracker { display: none; }

body.touch-play .pulse-check {
  top: 18%;
  font-size: 11px;
  max-width: 92vw;
  text-align: center;
}

body.touch-play .bar { height: 16px; }

body.touch-play .bar.mini { height: 8px; width: 90px; }

body.touch-play .pip { width: 12px; height: 12px; }

/* Menus on narrow screens */
@media (max-width: 640px) {
  .panel { padding: 18px 16px; margin: 2vh auto; width: calc(100% - 16px); }
  .panel h1 { font-size: 18px; }
  .logo { font-size: 34px; letter-spacing: 3px; }
  .main-menu { max-width: 100%; }
  .menu-buttons .mc-btn { padding: 14px 16px; font-size: 13px; }
  .choices { flex-direction: column; align-items: stretch; }
  .choice { width: 100%; max-width: 320px; margin: 0 auto; padding: 18px 14px; }
  .modal { padding: 18px 14px; max-height: 88vh; width: calc(100% - 20px); }
  .build-grid { grid-template-columns: 1fr; }
}

@media (max-width: 380px) {
  .touch-joystick { width: 110px; height: 110px; }
  .touch-joy-knob { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
  .touch-actions {
    grid-template-columns: 50px 50px;
    grid-template-rows: 44px 56px 56px;
  }
}
