The problem isn’t that trademarks are country-based but that trademarks are business area based. You can have multiple trademarks for the same word for different companies if the companies do different things. Apple doesn’t have the right to prevent you from using the word „apple“ to sell lawn mowers.
E.g. Apple has a trademark in the context of technology but not in the context of farming
Whereas gTLDs are flat namespace