/* ==========================================================================
   Shared mobile gameplay HUD + controls — shanebrumback.com
   ONE source of truth for touch controls across all site games
   (FPS Game Starter, Zombie Attack, ...). Do NOT hard-code these sizes per game;
   override the CSS variables on :root only if a game truly needs it.

   CONTRACT (classes):
     .mg-joy   joystick base        > .mg-knob  joystick knob
     .mg-btn   any round action btn   + .mg-fire (red, big) / .mg-jump (cyan, small)
     .mg-corner top-right circle btn  + .mg-exit (red ✕, far right) / .mg-max (navy ⛶ / ⤢, left of ✕)
     .mg-hud   compact stats panel, top-left
     .mg-score SCORE / KILLS / LIVES bar (top-center on touch landscape)
     .mg-rotate full-screen "ROTATE TO LANDSCAPE" prompt (+ .mg-rot-ph phone icon, .mg-rot-sub, .rotate-continue-btn)
   CONTRACT (state classes on <body>, set by the game):
     .mg-active     after Play on a touch device -> shows joystick + buttons + corners
     .mg-portrait   touch device held in portrait  -> with .mg-active shows .mg-rotate
     .mg-no-fs      fullscreen API unsupported -> hides .mg-max
     .mg-landscape-hide-header (optional) hides <header>/.site-header while .mg-active in landscape
   Rules: controls only after Play + landscape; rotate prompt only after Play.
   ========================================================================== */
:root {
  --mg-safe-t: env(safe-area-inset-top, 0px);
  --mg-safe-r: env(safe-area-inset-right, 0px);
  --mg-safe-b: env(safe-area-inset-bottom, 0px);
  --mg-safe-l: env(safe-area-inset-left, 0px);
  --mg-joy-size: 120px;  --mg-knob-size: 52px;
  --mg-fire-size: 92px;  --mg-jump-size: 64px;
  --mg-joy-x: 20px;      --mg-joy-y: 20px;
  --mg-fire-x: 22px;     --mg-fire-y: 26px;
  --mg-jump-x: 122px;    --mg-jump-y: 22px;
  --mg-corner-size: 42px; --mg-corner-gap: 8px; --mg-corner-top: 8px; --mg-corner-right: 12px;
  --mg-exit-bg: #ef4444;  --mg-max-bg: rgba(15,23,42,.85);
  --mg-fire-bg: rgba(239,68,68,0.85); --mg-jump-bg: rgba(34,211,238,0.85);
  --mg-accent: #22d3ee;   --mg-score: #fbbf24;
  --mg-z-controls: 6;     --mg-z-corner: 30;
}
/* short (phone landscape) screens: compact sizes = FPS Game Starter reference */
@media (max-height: 500px) {
  :root {
    --mg-joy-size: 96px; --mg-knob-size: 40px;
    --mg-fire-size: 74px; --mg-jump-size: 54px;
    --mg-joy-x: 14px; --mg-joy-y: 12px;
    --mg-fire-x: 14px; --mg-fire-y: 14px;
    --mg-jump-x: 100px; --mg-jump-y: 12px;
  }
}

.mg-joy { position: fixed; left: calc(var(--mg-joy-x) + var(--mg-safe-l)); bottom: calc(var(--mg-joy-y) + var(--mg-safe-b)); width: var(--mg-joy-size); height: var(--mg-joy-size); border-radius: 50%; background: rgba(255,255,255,0.12); border: 2px solid rgba(255,255,255,0.35); z-index: var(--mg-z-controls); display: none; touch-action: none; }
.mg-knob { position: absolute; left: 50%; top: 50%; width: var(--mg-knob-size); height: var(--mg-knob-size); margin: calc(var(--mg-knob-size) / -2) 0 0 calc(var(--mg-knob-size) / -2); border-radius: 50%; background: rgba(34,211,238,0.7); pointer-events: none; }
.mg-btn { position: fixed; z-index: var(--mg-z-controls); display: none; padding: 0; border-radius: 50%; border: 2px solid rgba(255,255,255,0.7); font: bold 14px Arial, sans-serif; color: #0b1220; touch-action: none; user-select: none; -webkit-user-select: none; }
.mg-fire { width: var(--mg-fire-size); height: var(--mg-fire-size); right: calc(var(--mg-fire-x) + var(--mg-safe-r)); bottom: calc(var(--mg-fire-y) + var(--mg-safe-b)); background: var(--mg-fire-bg); color: #fff; }
.mg-jump { width: var(--mg-jump-size); height: var(--mg-jump-size); right: calc(var(--mg-jump-x) + var(--mg-safe-r)); bottom: calc(var(--mg-jump-y) + var(--mg-safe-b)); background: var(--mg-jump-bg); }
body.mg-active .mg-joy, body.mg-active .mg-btn { display: block; }

.mg-corner { position: fixed; top: calc(var(--mg-corner-top) + var(--mg-safe-t)); z-index: var(--mg-z-corner); width: var(--mg-corner-size); height: var(--mg-corner-size); padding: 0; border: none; border-radius: 9999px; color: #fff; font: 700 20px/1 system-ui, sans-serif; display: none; align-items: center; justify-content: center; cursor: pointer; touch-action: manipulation; box-shadow: 0 2px 8px rgba(0,0,0,.45); }
.mg-exit { right: calc(var(--mg-corner-right) + var(--mg-safe-r)); background: var(--mg-exit-bg); }
.mg-max  { right: calc(var(--mg-corner-right) + var(--mg-corner-size) + var(--mg-corner-gap) + var(--mg-safe-r)); background: var(--mg-max-bg); font-size: 18px; }
body.mg-active .mg-corner { display: flex; }
body.mg-no-fs .mg-max { display: none !important; }

.mg-hud { position: fixed; left: 12px; top: 12px; padding: 8px 12px; background: rgba(8,18,32,0.75); border-left: 3px solid var(--mg-accent); color: #e2e8f0; font: 12px/1.5 monospace; z-index: 5; white-space: pre; pointer-events: none; }
.mg-score { position: fixed; right: 14px; top: 12px; padding: 6px 14px; background: rgba(8,18,32,0.75); border-right: 3px solid var(--mg-score); color: var(--mg-score); font: bold 20px/1.3 monospace; z-index: 5; pointer-events: none; }
@media (max-height: 500px) {
  .mg-hud { font-size: 8px; line-height: 1.35; padding: 3px 7px; top: calc(6px + var(--mg-safe-t)); left: calc(6px + var(--mg-safe-l)); max-width: 34vw; overflow: hidden; }
  .mg-score { top: 6px; right: 8px; padding: 3px 10px; font-size: 13px; }
}
@media (pointer: coarse) and (orientation: landscape) {
  .mg-score { left: 50%; right: auto; transform: translateX(-50%); top: calc(6px + var(--mg-safe-t)); white-space: nowrap; }
}

.mg-rotate { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; text-align: center; padding: 24px; background: #0a061a; color: var(--mg-accent); font: 700 16px/1.4 "Press Start 2P", monospace; z-index: 2147483647; touch-action: none; }
.mg-rotate > div { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.mg-rotate .mg-rot-ph, .mg-rotate .za-rot-ph { width: 46px; height: 78px; border: 4px solid var(--mg-accent); border-radius: 9px; animation: mgRot 1.6s ease-in-out infinite; }
.mg-rotate .mg-rot-sub, .mg-rotate .za-rot-sub { font-size: 10px; color: #aaa; }
.mg-rotate .rotate-continue-btn { font-family: Arial, sans-serif; }
@keyframes mgRot { 0%,20% { transform: rotate(0); } 50%,70% { transform: rotate(90deg); } 100% { transform: rotate(0); } }
body.mg-active.mg-portrait .mg-rotate { display: flex; }
@media (orientation: landscape) and (pointer: coarse) {
  body.mg-active.mg-landscape-hide-header header, body.mg-active.mg-landscape-hide-header .site-header { display: none !important; }
}
