To further elaborate on your issue, let me provide another example:
div {
& {
color: blue;
}
color: red;
}
<div>
hello
</div>
The concept of "nested rules" and "declarations" can sometimes be confusing, but according to the Specification, the browser will interpret them by placing the "nested rules" at the end.
Therefore, your original code will be reordered like this:
div {
color: red;
& {
color: blue;
}
}
<div>
hello
</div>
Eventually, it will be structured as follows:
div {
color: red;
}
div {
color: blue;
}
<div>
hello
</div>
Remember, always organize your code with "declarations" first before adding any "nested rules."