How to create floating UI elements on macOS like Grammarly?

How do I create a floating button on top of another app?

How do I highlight text inside the textbox of another app?

This is how Grammarly works on macOS. It seems that they use accessibility features, but I know nothing else about how to achieve this.

Hello Apple? Why are you making things so difficult for us?

How to create floating UI elements on macOS like Grammarly?
 
 
Q