Text this: Bridging Domain Invariance and Diversity: A Fine-Grained Risk Bound for Domain Generalization