Why does the cool gas cause absorption lines while the hot gas causes emission lines?
Electrons in an atom can either absorb photons and go from a lower to a higher energy level, or emit photons when they drop from a higher to a lower energy level. Whether a gas absorbs or emits photons depends on what levels its electrons are already in, which depends on the temperature of the gas. A gas with all its electrons in the ground state (which will be the case if it is relatively cold) can only absorb photons. A situation where we might see an absorption spectrum of dark lines is for the Sun or other star: in this case, the Sun is a glowing blackbody and produces a continuous spectrum of thermal radiation. However the Sun has relatively cool outer layers of gas, for which electrons are in the ground state or low energy levels. In this case, photons from the blackbody radiation get absorbed by the outer layers of gas, but only for certain wavelengths corresponding to transitions between allowed energy levels. A hot gas, on the other hand, has atoms jiggling around violently an