Theory of kinetic ballooning modes excited by energetic particles in tokamaks