.fps-touch-controls {
  --control-size: clamp(3.5rem, 13vw, 5.25rem);
  --control-gap: clamp(0.5rem, 2vw, 1rem);
  --safe-top: max(0.5rem, env(safe-area-inset-top));
  --safe-right: max(0.75rem, env(safe-area-inset-right));
  --safe-bottom: max(0.75rem, env(safe-area-inset-bottom));
  --safe-left: max(0.75rem, env(safe-area-inset-left));
  --fps-reduced-gore: 0;
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  pointer-events: none;
}

.fps-touch-controls[data-reduced-gore="true"] {
  --fps-reduced-gore: 1;
}

.fps-touch-stick,
.fps-touch-look,
.fps-touch-button {
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.fps-touch-stick,
.fps-touch-button {
  z-index: 1;
}

.fps-touch-stick {
  --stick-x: 0px;
  --stick-y: 0px;
  position: absolute;
  left: var(--safe-left);
  bottom: var(--safe-bottom);
  width: clamp(7.5rem, 29vw, 11rem);
  aspect-ratio: 1;
  border: 2px solid rgb(255 255 255 / 35%);
  border-radius: 50%;
  background: radial-gradient(circle, rgb(255 255 255 / 10%) 0 34%, rgb(0 0 0 / 34%) 36% 100%);
  box-shadow: inset 0 0 1.5rem rgb(0 0 0 / 55%), 0 0.25rem 1rem rgb(0 0 0 / 28%);
}

.fps-touch-stick__thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  aspect-ratio: 1;
  border: 2px solid rgb(255 255 255 / 55%);
  border-radius: 50%;
  background: rgb(30 36 42 / 74%);
  box-shadow: 0 0.2rem 0.7rem rgb(0 0 0 / 45%);
  transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y)));
}

.fps-touch-look {
  position: absolute;
  inset: var(--safe-top) 0 0;
  z-index: 0;
}

.fps-touch-button {
  position: absolute;
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  width: var(--control-size);
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid rgb(255 255 255 / 48%);
  border-radius: 50%;
  color: #fff;
  background: rgb(18 21 25 / 72%);
  box-shadow: inset 0 0 0.65rem rgb(255 255 255 / 9%), 0 0.2rem 0.8rem rgb(0 0 0 / 40%);
  font: 800 clamp(0.65rem, 2.2vw, 0.9rem) / 1 system-ui, sans-serif;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 2px #000;
}

.fps-touch-button:active {
  transform: scale(0.94);
  filter: brightness(1.25);
}

.fps-touch-button--fire {
  right: var(--safe-right);
  bottom: var(--safe-bottom);
  width: calc(var(--control-size) * 1.18);
  border-color: rgb(255 117 80 / 78%);
  background: rgb(112 21 15 / 76%);
}

.fps-touch-button--use {
  right: calc(var(--safe-right) + var(--control-size) * 1.28);
  bottom: calc(var(--safe-bottom) + var(--control-size) * 0.38);
}

.fps-touch-button--weaponPrevious {
  right: calc(var(--safe-right) + var(--control-size) * 2.25);
  bottom: calc(var(--safe-bottom) + var(--control-size) * 1.15);
}

.fps-touch-button--weaponNext {
  right: calc(var(--safe-right) + var(--control-size) * 1.25);
  bottom: calc(var(--safe-bottom) + var(--control-size) * 1.55);
}

.fps-touch-button--pause {
  top: var(--safe-top);
  right: var(--safe-right);
  width: max(44px, calc(var(--control-size) * 0.62));
  background: rgb(18 21 25 / 60%);
}

.fps-touch-controls[data-left-handed="true"] .fps-touch-stick {
  right: var(--safe-right);
  left: auto;
}

.fps-touch-controls[data-left-handed="true"] .fps-touch-button--fire {
  right: auto;
  left: var(--safe-left);
}

.fps-touch-controls[data-left-handed="true"] .fps-touch-button--use {
  right: auto;
  left: calc(var(--safe-left) + var(--control-size) * 1.28);
}

.fps-touch-controls[data-left-handed="true"] .fps-touch-button--weaponPrevious {
  right: auto;
  left: calc(var(--safe-left) + var(--control-size) * 2.25);
}

.fps-touch-controls[data-left-handed="true"] .fps-touch-button--weaponNext {
  right: auto;
  left: calc(var(--safe-left) + var(--control-size) * 1.25);
}

.fps-touch-controls[data-left-handed="true"] .fps-touch-button--pause {
  right: auto;
  left: var(--safe-left);
}

@media (pointer: coarse), (any-pointer: coarse) {
  .fps-touch-controls {
    display: block;
  }
}

@media (orientation: portrait) {
  .fps-touch-controls {
    --control-size: clamp(3.25rem, 15vw, 4.75rem);
  }

  .fps-touch-stick {
    width: clamp(7rem, 34vw, 10rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .fps-touch-stick__thumb,
  .fps-touch-button {
    transition: none;
  }
}
