Why is ROC insensitive to class distributions? I am confused over why ROC is invariance under class distribution described in the paper An Introduction to ROC analysis. I cannot understand the example on why the proportion of positive to negative classes in a test set does not affect the ROC curves.
Also to quote from this post, it says that:

To show this, first let's start with a very nice way to define precision, recall and specificity.  Assume you have a "positive" class called 1 and a "negative" class called 0.  $\hat{Y}$ is your estimate of the true class label $Y$.  Then:
$$
\begin{aligned}
&\text{Precision} &= P(Y = 1 | \hat{Y} = 1)  \\
&\text{Recall} = \text{Sensitivity} &= P(\hat{Y} = 1 | Y = 1)  \\
&\text{Specificity} &= P(\hat{Y} = 0 | Y = 0)
\end{aligned}
$$
The key thing to note is that sensitivity/recall and specificity, which make up the ROC curve, are probabilities conditioned on the true class label.  Therefore, they will be the same regardless of what $P(Y = 1)$ is.

I cannot reconcile these few concepts together, likely due to a gap in statistical rigour. I would highly appreciate someone to give me a more detailed example on why the above is true.

To be more specific, can someone explain the above quote? In particular what does it mean to be conditioned on P(Y=1)? What is this P referring to? And why does conditioning on this implies that ROC is insensitive to class distribution.
To add on, I did read through almost every post related to this question, but don't see consensus in whether ROC curve is sensitive or insensitive to class imbalance.
The posts I read: I know it's quite a lot, I even managed to implement ROC curve using pure python code without an issue. But it seems that even if I can implement it, I still do not fully understand it.
Interpretation of ROC

*

*Wikipedia has an extensive explanation of the probability behind ROC

*Probabilistic Perspective of AUC

*AUC - Insider's Guide to the Theory and Applications

*Safe Handling Instructions for Probabilistic Classification.

*c-statistics.

*SIIM Melanoma ROC

*An Introduction to ROC analysis
Pros and Cons of AUROC

*

*The Relationship Between Precision-Recall and ROC Curves

*Drawbacks of AUROC.

*ROC vs precision-and-recall curves

*ROC vs Precision-recall curves on imbalanced dataset

*on why AUC can be misleading

Latest Understanding 21st September 2021:
As Professor Frank Harrell has mentioned in the post below, I reinforce my understanding by further saying:
Y takes on 0 and 1, and the area under the ROC graph (call this value $a$), in a simplified manner, signifies that if you take randomly a positive sample, and a negative sample, your probability of positive sample being ranked higher (read: higher probability) than the negative sample is $a$.
Now with his analogy, the teacher is negative sample, and soccer star is positive sample, so now you conditioned on Y = 0, and Y = 1. Once you conditioned on say, $Y=0$, (Specificity/TNR or 1-FPR) then your sample space effectively reduces from the whole population of the samples, to only $Y=0$, From this, I intuitively think that $Y=1$ does not play a part and hence does not influence the FPR in any way. Similar concept can be applied to TPR. As a result, neither TPR nor FPR depends on the whole sample space (the whole distribution of the test (?) set), and as a result will not be influenced under class distributional changes in the testset (?).
TODO: To reason why precision depends on class distribution.

In classification problems the model output is probability. Different problems have different threshold boundaries. For example when deciding between a dog and a cat, 50% makes sense but when we talk about probability to have a heart attack all probabilities will be much much lower. AUC solves it  by checking the $FPR$ & $TPR$ for many (as much as possible) thresholds between 0 and 1.
AUC only cares about the ranking of the model i.e. if model rank the ones higher than the zeros. 
Let's examine the component of AUC:
$TPR = \frac{TP}{P} $
and
$FPR = \frac{FP}{N} $ 
Let's take as an example $TPR$ (will be similar to $FPR$).
We calculate $TPR$ for every threshold and for each example.
for each example $TP$ is a function of $Y, \hat{Y}, threshold$ - this is not affected by the ratio of positive and negative.
Now, the total number of $TP$ is affected by the total number of $P$ but the $TPR$ should remain the same. Because, if we have more $P$, we will also have more $TP$ at the same ratio for the given threshold.
To conclude, changing the number of $P$ should not affect the $TPR$ for a given threshold. The same is for $FPR$ and $N$, and thus the ratio between positive and negative should not change the ROC curve.
