DPG is correct. Your resting metabolic rate, which is to say your energy expenditure when you go to sleep/rest, is actually higher then if you were to exercise and pump up those arms and legs. Unusual yes, this is one of the unknowns that most people do not know, which is understandable so because it seems illogical. But if you may have heard a lady friend commenting about their summer or something of the sort, you may hear "all I did was sleep during the vacation and I still lost weight!", well now you know why. I account the famous "freshman 15" for this reason as well, why college students gain weight, because of poor dieting, AND the lack of sleep.
Even if you were to lets say just sit down at your chair and stare at this screen and do nothing else for a full day, you could be burning anywhere from 1000-2000 calories.
As the first two above me stated, stay away from the carbs, simple carbs at least such as fruits (fructose), dairy products (maltose), etc.
The downside of eating late? If you went to sleep soon after eating, you will have increased chances of indigestion and poor absorption. This is obvious and you may have already experienced it. The simple explanation would be that the way your gastrointestinal system works, gravity is an essential part to bringing the food into the system. The hydrochloric acid in your stomach can go into places that you may not want them to enter, thus the "heart burns".
Hope we have answered your questions.
Don't go stuffing yourself with midnight snacks now just because we said its ok =P