How it decides
The crawler looks for the group whose User-agent matches its name (case-insensitive). If there is none, it uses the User-agent: * group. If several groups name the same crawler, their rules are combined.
Within the group, the Allow or Disallow rule whose pattern matches the path and is longest, that is, the most specific, wins. If an Allow and a Disallow tie in length, Allow wins. The asterisk matches any sequence of characters and the dollar sign marks the end of the URL. An empty Disallow blocks nothing.
That is how the RFC 9309 standard defines it and how Google applies it. Remember that robots.txt controls crawling, not indexing: to keep a page out of Google, use noindex and let it be crawled.
Everything is calculated in your browser. Nothing is sent to any server.