The temperature of the gas is inversely proportional to the average wavelength of its spectrum
This relationship happens to be exactly the same as Wien's Law. It is one of three relationships which describe the way in which black-body radiation is emitted by glowing liquids and solids, and, as it turns out, as discussed here, by gases which are so thick that light has to struggle through them for some time before finally escaping from them. It is much harder to show, without complex mathematics, that the other two relationships are also obeyed, but as in the case of Wien's Law, the following result can be verified. If light has to struggle through a gas for some time in order to get through it, then, by the time that it has finally passed through the gas, it will no longer look like it did when it first entered the gas. Instead, it will be identical to black-body radiation, corresponding to the temperature of the gas. It is for this reason that, as stated above, the relationship between temperature and brightness inside a star is given by Stefan's Law, which is one of those black-body radiation laws. Everywhere inside a star, all the way from the center to the surface, the radiation which flows through the gas is black-body radiation corresponding to the temperature of the gas. When light interacts with gas in this way, we say that the light and the gas are in Local Thermodynamic Equilibrium, meaning that the heat properties (or thermodynamics) of the gas, and of the light, are in balance (or equilibrium).
Summarizing what has been stated so far, as you go down into a star, each "layer" must be brighter than the layer above it, by an amount approximately equal to the surface brightness of the star, and to accomplish this, as you go down into the star, each layer must be HOTTER than the layer above, by an amount which would be calculated from Stefan's Law.
There is, however, a notable exception to the above rule, when you are not inside the star, but outside it. As you should already know, in the atmosphere of the Sun, the temperatures increase as you go upwards, not downwards. This seems to violate the above statement, but there is a reason for that. In low-density gases (gases so rarefied that you can look right through them), the light does not have to struggle to get through the gas. In fact, the light emitted by the surface of the Sun goes through most of the atmosphere without even noticing that it is in the way. As a result, it is neither slowed nor altered by its passage through the gas. Instead, it just goes right through it. In this circumstance, the rule that the layers have to be brighter as you go downwards is obeyed, but the rule that temperature has to increase is not obeyed. The contradiction is due to the fact (explained in class, but, so far, not in this supplement) that for optically thin gases (gases thin enough to look through), the gas and the light are not in Local Thermodynamic Equilibrium, and temperature is not related to brightness by the black-body radiation laws, but instead, depends upon temperature and density. It is only in optically thick gases (gases so thick that you cannot see through them, and light has to struggle through the gas for some time to get out of it) that the black-body relationships are true. In the atmosphere of the Sun, since the gases are rarefied, and are optically "thin", density is more important than temperature in determining how bright the gases are. The corona is very hot, but there is practically nothing there, and the large brightness that you would expect from its temperature, multiplied by practically nothing, comes out millions of times fainter than the surface of the Sun. In the chromosphere and photosphere, the gases are cooler, but are denser than in the corona, and as you go downwards, and the density increases, the brightness increases, as well. It is only when you reach the "surface" of the Sun, and the gases become optically thick, that the black-body relationship begins to apply. But from there, all the way to the center of the Sun, that relationship is the only one that has any effect on the brightness, so the temperature has to increase in lockstep with the brightness.
Heat Flow in the Outer Regions of a Star -- Convective Envelopes
So far, we have restricted our discussion to the regions, deep in the interior of a star, where radiation moves from one region to another through the diffusion of individual photons. This region is called, as mentioned above, the radiative core of the star (there is also a smaller region, where the nuclear fusion of the star occurs, which is sometimes referred to as the nuclear core). However, near the outside of the star, things may work a little differently, because another factor may come into play.
As mentioned early on, the photons may be either scattered by (bounced off of), or absorbed by the gas particles. The electrons, which make up more than half of the particles in the stellar interior, and any bare nuclei, which make up all the other particles deep within the star, where temperatures are many millions of degrees, cannot actually absorb photons. All they can do is bounce the photons in random directions, and (occasionally) exchange energy with them. However, in the cooler regions near the surface of the star, there may be atoms or ions which have one or more electrons attached to their nuclei, despite the relatively high temperatures. This is especially true of many-electron atoms such as iron, silicon, or oxygen. In the outer regions, near the surface of the star, these particles may have a chance to actually absorb the energy of a photon, and in one way or another, hold onto it for some short period of time. Eventually, they will give up the energy they absorbed, either as a similar photon, or as several photons of lower energy, with a total energy approximately equal to the energy of the absorbed photon. The time involved between the absorption and subsequent emission(s) is very short, but since light travels so fast, even if the energy is held onto for even a few millionths of a second, it may "block" or "slow" the outward flow of the light as much as several millions of individual scatterings. As a result, even if the amount of such absorption is relatively small, it may enhance the opacity (the amount of blockage of the light by the gas), and slow down the light, by a substantial amount.
Whether this is true or not depends upon the density of the gas in the region where the temperature is low enough for absorption to occur. If the star is huge, and relatively hot, the region near the surface which is cool enough for such absorption is so spread out, and so low in density, that the overal opacity of the gas (its ability to block gas) is very low, and so any additional opacity added by absorption is not very important, and nothing happens, except that the light has a slight additional amount of slowing. However, if the star is smaller, or cooler, so that the region cool enough for absorption reaches deeper into the star, and the density of the regions where absorption is significant is somewhat larger, the additional absorption may become quite significant, and cause an interesting side effect, namely a vertical mixing, or convection of the gases, in a region referred to as the convective envelope (so-called because it is in convective motion, and is on the outside of the star).
Whether convection occurs or not depends upon how fast the temperature has to increase, as you go inwards, in order to cause the light from the interior of the star to flow through the gas at a rate equal to the surface brightness of the star. In the upper Main Sequence stars referred to as blue supergiants, the star is as much as 20 times the size of the Sun, which gives those stars nearly ten thousand times the volume of the Sun. Such stars are several tens of times as massive as the Sun, but since they have such huge volumes, they are as much as a hundred times less dense than the Sun. Near the surface, instead of being hundreds of times less dense than the air at the surface of the Earth, they are hundreds of thousands of times less dense. Halfway down from the surface to the center, instead of being denser than water, they are hardly any denser than ordinary air. And even in the center, where the Sun is more than a hundred times as dense as water, such stars are only about the same density as water.
Since such stars have such low densities, it is easy for the light which is made inside them to leak from layer to layer, and as you go inwards, the temperature increases relatively slowly (as little as three Kelvins per mile). Even though, in the center, they require huge temperatures (as much as 30 or 40 million Kelvins) in order to produce the immense amount of thermonuclear fusion which sustains their brightness, they are so large that the temperature can go up very slowly, and still attain very high temperatures in the center.
In the case of the Sun, however, the gas is much denser, and so it is much harder for the light inside the Sun to struggle from layer to layer. The effect of this is to increase the rate at which temperature increases (in the same way that, at the surface of Venus, the greenhouse gases in its atmosphere, by making it hard for the heat of the planet to escape, raise the surface temperature by nearly a factor of three, compared to what it would otherwise be). Whereas a blue giant may have a temperature gradient (the rate of temperature increase) of only three degrees per mile, the temperature gradient of the Sun is around 30 Kelvins per mile (about 15 million Kelvins, in less than half a million miles).
Because of the fact that, in the outer regions where the light is blocked by both scattering and absorption, the denser gas within the Sun makes it much harder for light to escape, and causes a much higher temperature gradient than in larger, hotter Upper Main Sequence stars, the rate of temperature rise can become so large that the gas is not stable against vertical mixing, or convection, and vertical mixing of regions as large as the Earth, or larger, moving upwards (and downwards) at speeds of several miles to a few tens of miles per second, helps move heat outwards. In very large, hot stars, with much lower densities in the regions where absorption is significant, the temperature gradient required to create convection is higher than the actual temperature gradient, and there is no convection. Heat flows outwards only through the diffusion of photons (radiation) from one place to another. But as you move from hotter stars to cooler, denser stars, the actual temperature gradient in the outer regions increases, and a convective envelope forms in the regions near the surface where density and opacity are high enough to force such mixing. As you move to still cooler, or denser, stars, the convective envelope grows, reaching further and further into the star, and for the coolest, and densest, stars, the envelope actually reaches down into the core of the star.