/* Touch controls and phone layout. Load order: base, hud, menu, touch. */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 3; }

#touch [data-zone] {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
/* Look is the whole screen; move is layered over its lower-left corner and
   wins there, so a thumb in the corner steers and anywhere else aims. */
#touch [data-zone="look"] { inset: 0; }
#touch [data-zone="move"] { left: 0; bottom: 0; width: 45%; height: 62%; }

/* The stick pad is drawn where the thumb landed rather than at a fixed spot,
   so it is positioned in page coordinates by the script. */
#touch-pad {
  position: absolute; width: 132px; height: 132px;
  margin: -66px 0 0 -66px;
  border: 1.5px solid rgba(255,255,255,.22);
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255,255,255,0) 58%, rgba(255,255,255,.07) 59% 60%, rgba(255,255,255,0) 61%),
    radial-gradient(circle, rgba(14,18,24,.35), rgba(14,18,24,.15));
  box-shadow: 0 0 0 1px rgba(0,0,0,.25), inset 0 0 24px rgba(0,0,0,.25);
  opacity: 0; transition: opacity .14s;
}
#touch-pad.live { opacity: 1; }
#touch-nub {
  position: absolute; left: 50%; top: 50%;
  width: 56px; height: 56px;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255,255,255,.7);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(255,255,255,.4), rgba(255,255,255,.12));
  box-shadow: 0 4px 14px rgba(0,0,0,.4), 0 0 0 4px rgba(255,107,44,.18);
}

#touch-btns {
  position: absolute; right: 16px; bottom: 16px;
  display: grid; gap: 9px;
  /* Explicit placement rather than auto-flow: FIRE has to land under the
     thumb in the bottom-right corner with AIM immediately beside it, and
     letting the small buttons flow would strand AIM in the middle of the
     screen where no thumb reaches. */
  grid-template-columns: 54px 54px 82px;
  grid-template-rows: 54px 54px 82px;
  pointer-events: none;
}
#touch-btns [data-action="armoury"]  { grid-area: 1 / 1; }
#touch-btns [data-action="snap"]     { grid-area: 1 / 2; }
#touch-btns [data-action="swap"]     { grid-area: 1 / 3; }
#touch-btns [data-action="interact"] { grid-area: 2 / 1; }
#touch-btns [data-action="reload"]   { grid-area: 2 / 2; }
#touch-btns [data-action="jump"]     { grid-area: 2 / 3; }
#touch-btns [data-action="ads"]      { grid-area: 3 / 2; }
#touch-btns [data-action="fire"]     { grid-area: 3 / 3; }

/* Pause. On desktop the browser's own Escape releases pointer lock and the
   game treats that as the pause signal -- there is no key binding for it at
   all. Touch has no lock to lose, so without this button a player could never
   leave a run except by dying. */
#touch-pause, #touch-fs {
  position: absolute; top: calc(14px + env(safe-area-inset-top));
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(12,16,22,.62);
  box-shadow: 0 6px 16px rgba(0,0,0,.3);
  color: var(--text);
  font: 800 16px/1 var(--font-display);
  letter-spacing: .1em;
  transition: background .08s, border-color .08s, transform .08s;
}
#touch-pause { right: calc(16px + env(safe-area-inset-right)); }
/* Fullscreen toggle, beside pause. Hidden where the API is unavailable --
   an iPhone cannot do it at all, and offering a button that does nothing is
   worse than not offering one. touch.js removes .unavailable when it can. */
#touch-fs { right: calc(68px + env(safe-area-inset-right)); font-size: 18px; }
#touch-pause.down, #touch-fs.down {
  background: rgba(255,107,44,.32); border-color: var(--accent); transform: scale(.94);
}
#touch-fs.unavailable { display: none; }

/* Zoom and scroll lock.
   touch-action on the document is what kills double-tap zoom and pinch in
   Chrome; overscroll-behavior kills pull-to-refresh and the rubber-band.
   Neither is enough for iOS Safari on its own -- lockGestures() supplies the
   rest. Scoped to body.touch so a desktop browser keeps normal behaviour. */
body.touch, body.touch #hud, body.touch canvas {
  touch-action: none;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
}
/* The panels keep their scroll: the armoury list is taller than a phone in
   landscape, so it has to pan even though nothing else does. */
body.touch #overlay { touch-action: pan-y; overscroll-behavior: contain; }

/* Safe areas. black-translucent puts the iOS status bar over the canvas, and
   a notch in landscape eats the left or right edge, so the controls and the
   HUD are inset by whatever the device reports. */
body.touch #touch-btns {
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
}

.tbtn {
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  display: grid; place-items: center;
  width: 54px; height: 54px;
  border: 1.5px solid rgba(255,255,255,.24);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, rgba(40,48,58,.62), rgba(12,16,22,.55));
  box-shadow: 0 6px 16px rgba(0,0,0,.32), inset 0 1px 0 rgba(255,255,255,.08);
  color: var(--text);
  font: 800 12px/1 var(--font-display);
  letter-spacing: .12em;
  text-shadow: var(--shadow);
  transition: background .08s, border-color .08s, transform .08s, box-shadow .08s;
}
.tbtn.wide { width: 82px; height: 82px; font-size: 15px; letter-spacing: .16em; }
.tbtn.down {
  background: rgba(255,107,44,.34); border-color: var(--accent); transform: scale(.93);
  box-shadow: 0 0 0 4px rgba(255,107,44,.2), 0 4px 10px rgba(0,0,0,.3);
}
.tbtn.latched { border-color: var(--accent); color: var(--accent); background: rgba(255,107,44,.16); }
.tbtn.fire {
  border: 2px solid rgba(255,107,44,.85);
  background: radial-gradient(circle at 50% 35%, rgba(255,107,44,.42), rgba(160,40,10,.3));
  box-shadow: 0 0 0 4px rgba(255,107,44,.14), 0 8px 20px rgba(0,0,0,.35);
}
.tbtn.fire.down { background: rgba(255,107,44,.62); }
/* USE and ARM are the context buttons; tint them so the prompt's "USE" key
   chip and the button it names look like the same thing. */
#touch-btns [data-action="interact"] { border-color: rgba(255,255,255,.5); }
#touch-btns [data-action="armoury"] { color: var(--gold); border-color: rgba(255,207,77,.45); }

/* ======================================================================
   HUD on touch.

   The bottom corners belong to the stick and the buttons, so the HUD lives
   along the top. The left column keeps its flow but leads with vitals; the
   right column is dissolved so the gun readout can sit under the pause
   button and the kill feed can sit beside the buttons.
   ====================================================================== */
body.touch #hud-left { top: calc(10px + env(safe-area-inset-top)); gap: 8px; width: 240px; }
body.touch #vitals { order: -1; margin-top: 0; min-width: 0; padding: 7px 10px 8px; gap: 5px; }
body.touch #hp-num { font-size: 32px; }
body.touch #hp-max { font-size: 13px; }
body.touch #hp-label { display: none; }
body.touch .hp-ico { width: 14px; height: 14px; margin-bottom: 3px; }
body.touch #hp-bar { width: 190px; height: 9px; }
body.touch #hud #coins b { font-size: 20px; }
body.touch #hud #score b { font-size: 16px; }
body.touch #streak-count { font-size: 26px; }
body.touch .fx-blurb { display: none; }
body.touch #effects { width: 180px; }

body.touch #hud-right { display: contents; }
body.touch #ammo-box, body.touch #weapons, body.touch #feed, body.touch #ffa {
  position: absolute; scale: var(--hs);
}
body.touch #ammo-box {
  top: calc(64px + env(safe-area-inset-top)); right: calc(16px + env(safe-area-inset-right));
  min-width: 150px; padding: 6px 10px 7px; transform-origin: top right;
}
body.touch #ammo-num { font-size: 32px; }
/* The active weapon chip below already names the gun. */
body.touch #ammo-name { display: none; }
body.touch #ammo-num small { font-size: 16px; }
body.touch #ammo-name { font-size: 12px; }
/* Slots as a row of chips; only the drawn gun is named. */
body.touch #weapons {
  top: calc(126px + env(safe-area-inset-top)); right: calc(16px + env(safe-area-inset-right));
  margin: 0; flex-direction: row; flex-wrap: wrap; justify-content: flex-end;
  max-width: 46vw; transform-origin: top right;
}
body.touch .wep { height: 24px; font-size: 12px; padding: 0 4px; }
body.touch .wep.active { height: 26px; padding-right: 9px; font-size: 13px; }
body.touch .wep:not(.active) .wn { display: none; }
body.touch #ffa { top: calc(158px + env(safe-area-inset-top)); right: calc(16px + env(safe-area-inset-right)); transform-origin: top right; }
/* Landscape: the feed sits just left of the button cluster, bottom-up. */
body.touch #feed {
  bottom: calc(14px + env(safe-area-inset-bottom)); right: calc(250px + env(safe-area-inset-right));
  max-width: min(300px, 32vw); transform-origin: bottom right;
}
body.touch #feed .fi { font-size: 12px; padding-top: 4px; padding-bottom: 4px; }

body.touch #wave-card { min-width: 0; padding: 6px 14px 7px; }
body.touch #wave-num { font-size: 17px; }
body.touch #wave-sub.countdown { font-size: 22px; }
body.touch #hud #bossbar { width: min(400px, 46vw); }
body.touch #hud #boss-name { font-size: 16px; }

body.touch #prompt { top: calc(50% + 48px); font-size: 13px; }
body.touch #prompt .kc { height: 26px; }
body.touch .an-main { font-size: 30px; padding: 5px 30px; }
body.touch #announce[data-kind="wave"] .an-main,
body.touch #announce[data-kind="boss"] .an-main { font-size: 40px; padding: 6px 40px; }
body.touch #announce { top: 30%; }
/* Clear of the buttons: between the stick and the cluster. */
body.touch #travelhud { bottom: calc(12px + env(safe-area-inset-bottom)); min-width: 0; max-width: calc(100vw - 520px); }
body.touch #revive { bottom: auto; top: calc(50% + 40px); }
/* The revive banner takes the prompt's place under the crosshair; the
   prompt steps down beneath it rather than overlapping. */
body.touch #revive.on ~ #prompt { top: calc(50% + 104px); }
body.touch #fps { bottom: auto; top: calc(2px + env(safe-area-inset-top)); }

/* The armoury's exit is pinned at the top on touch by shop.js. */
body.touch #shop #shop-close {
  width: 100%; margin: 0 0 10px; border-radius: var(--r-md);
  box-shadow: 0 10px 20px rgba(6,8,11,.85);
}
body.touch #shop .shop-item { min-height: 44px; }

/* Portrait phone: the top row is the wave card (left) and pause (right); the
   HUD columns start beneath it. */
@media (orientation: portrait) {
  body.touch #topbar { left: calc(14px + env(safe-area-inset-left)); right: 120px; align-items: flex-start; transform-origin: top left; }
  body.touch #hud #bossbar { width: calc(100vw - 32px); }
  body.touch #hud-left { top: calc(74px + env(safe-area-inset-top)); }
  body.touch #hud.coop #hud-left { top: calc(124px + env(safe-area-inset-top)); }
  body.touch #hp-bar { width: 150px; }
  body.touch #hud.boss #hud-left { top: calc(124px + env(safe-area-inset-top)); }
  body.touch #ammo-box { top: calc(74px + env(safe-area-inset-top)); }
  body.touch #hud.boss #ammo-box { top: calc(124px + env(safe-area-inset-top)); }
  body.touch #weapons {
    top: calc(142px + env(safe-area-inset-top)); flex-direction: column; flex-wrap: nowrap;
    align-items: flex-end; max-width: none;
  }
  body.touch #hud.boss #weapons { top: calc(192px + env(safe-area-inset-top)); }
  /* Co-op adds the room tag under the wave card, pushing the boss bar down. */
  body.touch #hud.coop.boss #hud-left,
  body.touch #hud.coop.boss #ammo-box { top: calc(170px + env(safe-area-inset-top)); }
  body.touch #hud.coop.boss #weapons { top: calc(238px + env(safe-area-inset-top)); }
  /* The feed stacks on the right under the weapon slots, narrow enough to
     clear the left column (teammates, effects) beside it. */
  body.touch #feed { bottom: auto; top: calc(300px + env(safe-area-inset-top)); right: calc(16px + env(safe-area-inset-right)); max-width: 38vw; transform-origin: top right; }
  body.touch #hud.boss #feed { top: calc(330px + env(safe-area-inset-top)); }
  body.touch #travelhud { bottom: auto; top: 36%; max-width: 92vw; }
}

/* No reload hint to show: give its line back. */
body.touch #reload-hint:empty { display: none; }
