About diet and gaining muscle...
I don't really measure my calories precisely, but I keep track of my weight and adjust my food according to whether I want to gain or lose. For losing weight, the easiest way for me is to do intermittent fasting (skip breakfast), avoid snacks and eat in moderation for most meals.
To gain weight, I eat breakfast, have a snack of cottage cheese or protein bread with peanut butter between meals and generally eat more at meals. Also I load up my post-workout protein shake with extra stuff like banana, peanut butter and a bit of olive oil.
Generally to be sure that you are gaining muscle, keep track of your measurements. Shoulder, chest and biceps are what I mostly check. They should increase on a surplus and not change much on a caloric deficit.