This talk will present a modified gyrokinetic theory to predict the critical gradient that determines the linear onset of the ion temperature gradient (ITG) mode in stellarator plasmas. A coarse-graining technique is applied to the drift curvature, entering the standard gyrokinetic equations, around local minima. Thanks to its simplicity, this novel formalism yields an estimate for the critical gradient with a computational cost low enough for application to stellarator optimization. When comparing against a gyrokinetic solver, our results show good agreement for an assortment of stellarator designs. Insight gained here into the physics of the onset of the ITG-driven instability enables us to devise a compact configuration, similar to the Wendelstein 7-X device, but with almost twice the ITG linear critical gradient, an improved nonlinear critical gradient, and reduced ITG mode transport above the nonlinear critical gradient. Preliminary optimization results applying the coarse-graining technique to quasisymmetric stellarator design using SIMSOPT will also be discussed.