/* Touch-only HUD. The canvas owns the two gesture regions, while only buttons
   intercept hits in this overlay. HUD canvas coordinates use CSS pixels. */
body.touch #touch {
  --control: clamp(46px, 7vmin, 56px);
  --fire-size: clamp(66px, 10vmin, 80px);
  --stick-size: clamp(100px, 19vmin, 134px);
  --gap: clamp(8px, 1.5vmin, 13px);
  --edge-r: max(15px, calc(env(safe-area-inset-right, 0px) + 7px));
  --edge-l: max(15px, calc(env(safe-area-inset-left, 0px) + 7px));
  --dock: max(95px, calc(env(safe-area-inset-bottom, 0px) + 75px));
  position: absolute;
  inset: 0;
  pointer-events: none;
  -webkit-tap-highlight-color: transparent;
}

body.touch #touch button,
body.touch #touch #stick {
  touch-action: none;
  box-sizing: border-box;
  border: 1px solid #c5d8df9e;
  background: radial-gradient(ellipse at 36% 18%, #56707b92, #0d1b25ba 83%);
  box-shadow:
    inset 0 0 0 2px #07151b4d,
    0 2px 5px #07161f50;
  color: #f3f9fa;
}

body.touch #touch button {
  pointer-events: auto;
  width: var(--control);
  height: var(--control);
  padding: 0;
}

body.touch #touch button svg {
  width: 23px;
  height: 23px;
  stroke-width: 1.8;
  pointer-events: none;
}

body.touch #touch button.active,
body.touch #touch button[aria-pressed="true"] {
  border-color: #ffbf87;
  background: #814e30e0;
  box-shadow:
    inset 0 0 0 2px #ffc18a57,
    0 1px 6px #121a20a6;
}

body.touch #touch #stick {
  pointer-events: none;
  left: max(5.5vw, var(--edge-l));
  bottom: calc(var(--dock) + 2px);
  width: var(--stick-size);
  height: var(--stick-size);
  opacity: 0.75;
}
body.touch #touch #stick::before {
  content: "";
  position: absolute;
  inset: 6%;
  border: 1px dashed #d6e8eb85;
  border-radius: 50%;
}
body.touch #touch #stick b {
  width: 39%;
  height: 39%;
  border-color: #dae7e8b3;
  background: radial-gradient(ellipse at 38% 28%, #9db4c5c7, #566e7bc2);
  box-shadow:
    0 2px 4px #0c1a245e,
    inset 0 1px 4px #c6dae98c;
}
body.touch #touch #stick.tracking {
  bottom: auto;
  --pad-radius: calc(var(--stick-size) / 2);
  --rim: calc(var(--pad-radius) + 5px);
  left: clamp(
    calc(env(safe-area-inset-left, 0px) + var(--rim)),
    var(--stick-x),
    calc(48% - var(--rim))
  );
  top: clamp(
    calc(env(safe-area-inset-top, 0px) + var(--rim)),
    var(--stick-y),
    calc(100% - env(safe-area-inset-bottom, 0px) - var(--rim))
  );
  transform: translate(-50%, -50%);
  opacity: 1;
}
body.touch #touch #stick.sprinting::before {
  border-color: #ffb87c;
  border-width: 2px;
}
body.touch #touch #stick.sprinting b {
  border-color: #ffd4a6;
  background: radial-gradient(ellipse at 38% 28%, #d49a67db, #885935cf);
}

body.touch #touch #tshoot {
  right: var(--edge-r);
  bottom: calc(var(--dock) + var(--control) + var(--gap));
  width: var(--fire-size) !important;
  height: var(--fire-size) !important;
  border: 2px solid #ffbb84;
  background: radial-gradient(ellipse at 35% 24%, #8c5f45cf, #332c29c9 82%);
  box-shadow:
    inset 0 0 0 3px #351e1945,
    0 2px 7px #1e191666;
}
body.touch #touch #tshoot.active {
  background: #b96637e8;
  border-color: #ffddae;
}
body.touch #touch #tshoot svg {
  width: 34px;
  height: 34px;
}

body.touch #touch #taim {
  width: calc(var(--control) + 6px);
  height: calc(var(--control) + 6px);
  right: calc(var(--edge-r) + var(--fire-size) + var(--gap));
  bottom: calc(var(--dock) + var(--control) + var(--gap) + 7px);
}
body.touch #touch #taim.latched::after {
  content: "";
  position: absolute;
  bottom: 5px;
  width: 12px;
  height: 3px;
  border-radius: 2px;
  background: #ffe1b7;
  pointer-events: none;
}
body.touch #touch #taim.active::before {
  content: "";
  position: absolute;
  right: -5px;
  top: calc(50% - 3px);
  width: 6px;
  height: 6px;
  border-top: 2px solid #ffcd98;
  border-right: 2px solid #ffcd98;
  transform: rotate(45deg);
  pointer-events: none;
}
body.touch #touch.slide-firing #taim {
  border-color: #ffe3bd;
}
body.touch #touch #tjump {
  right: calc(var(--edge-r) + 4px);
  bottom: calc(
    var(--dock) + var(--control) + var(--fire-size) + var(--gap) * 2
  );
}
body.touch #touch #treload {
  right: var(--edge-r);
  bottom: var(--dock);
}
body.touch #touch #tswitch {
  right: calc(var(--edge-r) + var(--control) + var(--gap));
  bottom: var(--dock);
}

body.touch #touch #tauto {
  left: var(--edge-l);
  right: auto;
  bottom: calc(var(--dock) + var(--stick-size) + var(--gap) * 2);
  min-width: 58px;
  width: auto;
  max-width: 96px;
  padding-inline: 8px;
  border-radius: 12px;
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  font:
    650 11px/1.05 system-ui,
    sans-serif;
}
body.touch #touch #tauto svg {
  width: 19px;
  height: 19px;
}

@media (orientation: landscape) and (max-height: 520px) {
  body.touch #touch {
    --dock: max(65px, calc(env(safe-area-inset-bottom, 0px) + 58px));
    --stick-size: clamp(92px, 24vmin, 112px);
  }
}

@media (orientation: portrait) and (max-width: 440px) {
  body.touch #touch {
    --edge-r: max(10px, calc(env(safe-area-inset-right, 0px) + 5px));
    --edge-l: max(10px, calc(env(safe-area-inset-left, 0px) + 5px));
  }
  body.touch #touch #stick {
    left: max(7vw, var(--edge-l));
  }
}

@media (orientation: landscape) and (max-height: 350px) {
  body.touch #touch #tauto {
    left: max(90px, calc(env(safe-area-inset-left, 0px) + 80px));
  }
}

/* The world reaches each edge. Only actionable HUD elements clear cutouts. */
body.touch .hud-map,
body.touch .hud-topright {
  top: max(7px, calc(env(safe-area-inset-top, 0px) + 3px));
}
body.touch .hud-map {
  left: max(12px, calc(env(safe-area-inset-left, 0px) + 4px));
}
body.touch .hud-topright {
  right: max(12px, calc(env(safe-area-inset-right, 0px) + 4px));
}
body.touch .hud-topright button {
  width: 44px;
  height: 44px;
}
body.touch .vitals,
body.touch .munition {
  bottom: max(6px, calc(env(safe-area-inset-bottom, 0px) + 3px));
}
body.touch .vitals {
  left: max(12px, calc(env(safe-area-inset-left, 0px) + 4px));
}
body.touch .munition {
  right: max(12px, calc(env(safe-area-inset-right, 0px) + 4px));
}

/* Keep the primary controls in a thumb arc; the two utility keys sit on its
   inner lower edge and the whole cluster clears the ammunition counter. */
body.touch #touch {
  --control: clamp(47px, 9vmin, 58px);
  --fire-size: clamp(78px, 17vmin, 94px);
  --aim-size: clamp(62px, 13vmin, 74px);
  --stance-size: clamp(54px, 11vmin, 66px);
  --gap: clamp(7px, 1.6vmin, 13px);
}
body.touch #touch #tshoot,
body.touch #touch #taim,
body.touch #touch #tjump,
body.touch #touch #tcrouch {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1px;
  border-radius: 50%;
}
body.touch #touch button span {
  font:
    650 10px/1.05 system-ui,
    sans-serif;
  letter-spacing: 0.045em;
  text-shadow: 0 1px 2px #17232c;
  pointer-events: none;
}
body.touch #touch #tshoot {
  bottom: calc(var(--dock) + var(--stance-size) + var(--gap));
}
body.touch #touch #taim {
  width: var(--aim-size);
  height: var(--aim-size);
  bottom: calc(
    var(--dock) + var(--stance-size) + var(--gap) +
      (var(--fire-size) - var(--aim-size)) / 2
  );
}
body.touch #touch #taim svg {
  width: 27px;
  height: 27px;
}
body.touch #touch #tjump,
body.touch #touch #tcrouch {
  width: var(--stance-size);
  height: var(--stance-size);
}
body.touch #touch #tjump {
  right: calc(var(--edge-r) + 7px);
  bottom: calc(
    var(--dock) + var(--stance-size) + var(--fire-size) + var(--gap) * 2
  );
}
body.touch #touch #tcrouch {
  right: calc(var(--edge-r) + 7px);
  bottom: var(--dock);
}
body.touch #touch #treload {
  right: calc(var(--edge-r) + var(--stance-size) + var(--gap) + 7px);
}
body.touch #touch #tswitch {
  right: calc(
    var(--edge-r) + var(--stance-size) + var(--control) + var(--gap) * 2 + 7px
  );
}
body.touch #touch #taim.latched::after {
  bottom: 3px;
}
@media (orientation: landscape) and (max-height: 350px) {
  body.touch #touch {
    --dock: max(45px, calc(env(safe-area-inset-bottom, 0px) + 41px));
    --control: 44px;
    --stance-size: 49px;
    --fire-size: 70px;
    --aim-size: 58px;
    --gap: 6px;
  }
}

/* Native selection and link previews obscure held controls in embedded iOS browsers. */
#game, #game *, #combat-medal, #combat-medal * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
#shell, dialog { touch-action: manipulation; }
#shell button, dialog button { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

#damage-bearing {
  position: absolute;
  pointer-events: none;
  width: clamp(122px, 34vmin, 222px);
  aspect-ratio: 1;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.damage-arc { position: absolute; inset: 0; }
.damage-arc svg { position: absolute; width: 49%; top: 0; left: 25.5%; overflow: visible; }
.damage-arc .arc-rim { fill: #ee5148; stroke: #601f2a; stroke-width: 1; }
.damage-arc .arc-core { fill: #ffe1c5; }
