#lw-touch-controller,
#lw-touch-controller * {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#lw-touch-controller {
  position: fixed;
  inset: 0;
  z-index: 2147483600;
  display: none;
  pointer-events: none;
  touch-action: none;
  font-family: Arial, Helvetica, sans-serif;
}

html.lw-mobile-device #lw-touch-controller:not([hidden]) { display: block; }

.lw-touch-stick {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom, 0px));
  width: clamp(96px, 17vw, 138px);
  height: clamp(96px, 17vw, 138px);
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.34);
  box-shadow: inset 0 0 22px rgba(255, 255, 255, 0.08), 0 3px 14px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
  touch-action: none;
}

#lw-left-stick { left: max(18px, env(safe-area-inset-left, 0px)); }
#lw-right-stick { right: max(18px, env(safe-area-inset-right, 0px)); }

.lw-touch-stick::before,
.lw-touch-stick::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: rgba(255, 255, 255, 0.12);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.lw-touch-stick::before { width: 62%; height: 1px; }
.lw-touch-stick::after { width: 1px; height: 62%; }

.lw-touch-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46%;
  height: 46%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.24);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#lw-touch-actions {
  position: absolute;
  right: max(150px, calc(19vw + env(safe-area-inset-right, 0px)));
  bottom: max(22px, env(safe-area-inset-bottom, 0px));
  width: clamp(112px, 16vw, 146px);
  height: clamp(112px, 16vw, 146px);
  pointer-events: none;
}

.lw-touch-button,
.lw-touch-system-button {
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 255, 255, 0.68);
  color: #fff;
  background: rgba(0, 0, 0, 0.48);
  box-shadow: 0 2px 9px rgba(0, 0, 0, 0.35);
  font-weight: 800;
  text-shadow: 0 1px 2px #000;
  pointer-events: auto;
  touch-action: none;
}

.lw-touch-button {
  width: clamp(42px, 6.1vw, 54px);
  height: clamp(42px, 6.1vw, 54px);
  border-radius: 50%;
  font-size: clamp(15px, 2.2vw, 20px);
}

.lw-touch-button.is-pressed,
.lw-touch-system-button.is-pressed {
  transform: scale(0.92);
  background: rgba(1, 105, 204, 0.76);
}

#lw-touch-y { left: 0; top: 50%; transform: translateY(-50%); }
#lw-touch-a { right: 0; top: 50%; transform: translateY(-50%); }
#lw-touch-x { left: 50%; top: 0; transform: translateX(-50%); }
#lw-touch-b { left: 50%; bottom: 0; transform: translateX(-50%); }
#lw-touch-y.is-pressed,
#lw-touch-a.is-pressed { transform: translateY(-50%) scale(0.92); }
#lw-touch-x.is-pressed,
#lw-touch-b.is-pressed { transform: translateX(-50%) scale(0.92); }

#lw-touch-system {
  position: absolute;
  left: 50%;
  top: max(12px, env(safe-area-inset-top, 0px));
  display: flex;
  gap: 10px;
  transform: translateX(-50%);
  pointer-events: none;
}

.lw-touch-system-button {
  position: relative;
  min-width: 58px;
  height: 34px;
  padding: 0 12px;
  border-radius: 17px;
  font-size: 11px;
  letter-spacing: 0.04em;
}

@media screen and (orientation: portrait) {
  html.lw-mobile-device #lw-touch-controller { display: none !important; }
}

@media screen and (max-height: 430px) and (orientation: landscape) {
  .lw-touch-stick { width: 94px; height: 94px; }
  #lw-touch-actions {
    right: max(118px, calc(100px + env(safe-area-inset-right, 0px)));
    width: 104px;
    height: 104px;
  }
  .lw-touch-button { width: 40px; height: 40px; font-size: 15px; }
}

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