.direction-pad.joystick {
  --joystick-size: clamp(90px, 27vw, 112px);
  position: absolute;
  z-index: 4;
  left: var(--joystick-left, max(10px, env(safe-area-inset-left, 0px)));
  bottom: var(--joystick-bottom, 18px);
  display: none;
  width: var(--joystick-size);
  height: var(--joystick-size);
  padding: 0;
  overflow: hidden;
  border: 1px solid #aab391cb;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #364137cb, #171c21eb 75%);
  box-shadow: 0 5px 20px #070a0c80, inset 0 0 0 4px #111a1a60;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.direction-pad.joystick:focus-visible { outline-offset: 3px; }
.joystick-ring, .joystick-thumb { position: absolute; border-radius: inherit; pointer-events: none; }
.joystick-ring { inset: 14%; border: 1px solid #c4d0b149; }
.joystick-ring::before {
  position: absolute;
  top: 50%;
  left: -3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  transform: translateY(-50%);
  background: #c2c9ad80;
  box-shadow: calc(var(--joystick-size) * .72 - 1px) 0 #c2c9ad80;
  content: '';
}
.joystick-ring::after {
  position: absolute;
  top: -3px;
  left: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  transform: translateX(-50%);
  background: #c2c9ad80;
  box-shadow: 0 calc(var(--joystick-size) * .72 - 1px) #c2c9ad80;
  content: '';
}
.joystick-thumb {
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 39%;
  height: 39%;
  transform: translate(calc(-50% + var(--joystick-x, 0px)), calc(-50% + var(--joystick-y, 0px)));
  border: 1px solid #d0deac;
  background: radial-gradient(circle at 48% 38%, #697447, #465034 72%);
  box-shadow: 0 3px 10px #101410bb, inset 0 0 0 3px #d8e98b24;
  transition: transform 105ms ease-out;
}
.joystick-thumb::after {
  width: 23%;
  height: 23%;
  border-radius: 50%;
  background: #d7ed9a;
  content: '';
}
.joystick[data-engaged] { cursor: grabbing; border-color: #d6ef9d; }
.joystick[data-engaged] .joystick-thumb { transition: none; background: #b7d66f; border-color: #e3f5ba; }
.joystick[data-engaged] .joystick-thumb::after { background: #4d6334; }

@media (pointer: coarse), (max-width: 640px) {
  .direction-pad.joystick { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  .joystick-thumb { transition: none; }
}
