.touch-controls {
  position: fixed;
  inset: 0;
  z-index: 18;
  display: none;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.joystick {
  position: absolute;
  left: calc(18px + var(--safe-left));
  bottom: calc(18px + var(--safe-bottom));
  width: 126px;
  height: 126px;
  border: 1px solid rgba(111, 211, 230, 0.28);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(111, 211, 230, 0.1), transparent 62%),
    rgba(13, 17, 25, 0.62);
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.35), 0 12px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
  pointer-events: auto;
  touch-action: none;
}

.joystick-ring {
  position: absolute;
  inset: 14px;
  border: 1px dashed rgba(111, 211, 230, 0.18);
  border-radius: 50%;
}

.joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border: 1px solid rgba(111, 211, 230, 0.5);
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 26%, rgba(255, 255, 255, 0.32), transparent 40%),
    linear-gradient(135deg, rgba(111, 211, 230, 0.55), rgba(183, 156, 255, 0.45));
  box-shadow: 0 0 22px rgba(111, 211, 230, 0.22);
  transition: transform 110ms ease-out;
  will-change: transform;
}

.joystick.is-dragging .joystick-knob {
  transition: none;
}

.touch-actions {
  position: absolute;
  right: calc(18px + var(--safe-right));
  bottom: calc(20px + var(--safe-bottom));
  display: grid;
  grid-template-columns: 48px 48px;
  grid-template-rows: 48px 48px;
  gap: 9px;
  pointer-events: auto;
}

.touch-btn {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(13, 17, 25, 0.78);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-soft);
  color: var(--text-soft);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  touch-action: manipulation;
  transition: transform 80ms ease, border-color 120ms ease;
}

.touch-btn:active {
  transform: scale(0.94);
  border-color: var(--accent);
}

.touch-btn-small {
  color: var(--muted);
  font-size: 12px;
}

.touch-btn-primary {
  width: 62px;
  height: 62px;
  margin: -7px;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 26px rgba(111, 211, 230, 0.28);
  color: #06100f;
  font-size: 17px;
}

#touch-help {
  grid-column: 1;
  grid-row: 1;
}

#touch-journal {
  grid-column: 2;
  grid-row: 1;
}

#touch-ops {
  grid-column: 1;
  grid-row: 2;
}

#touch-interact {
  grid-column: 2;
  grid-row: 2;
  align-self: end;
  justify-self: end;
}

#touch-interact[data-near="true"] {
  box-shadow: 0 0 0 3px rgba(245, 211, 107, 0.38), 0 0 28px rgba(245, 211, 107, 0.35);
}

body[data-modal="true"] .touch-controls {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

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

@media (max-width: 420px) {
  .joystick {
    width: 112px;
    height: 112px;
  }

  .joystick-knob {
    width: 48px;
    height: 48px;
    margin: -24px 0 0 -24px;
  }

  .touch-actions {
    grid-template-columns: 44px 44px;
    grid-template-rows: 44px 44px;
    gap: 7px;
  }

  .touch-btn {
    width: 44px;
    height: 44px;
  }

  .touch-btn-primary {
    width: 58px;
    height: 58px;
    margin: -7px;
  }
}
