Gyrokinetic theory of perpendicular cyclotron resonance in a nonuniformly magnetized plasma