If you're looking to achieve this effect using only CSS, unfortunately that's not possible. However, you can create a JavaScript function to help with the task.
The following function will retrieve the value '3' from your :root{}:
getComputedStyle(document.documentElement)
.getPropertyValue('--n');
Since JavaScript cannot be directly placed in CSS files, you will need to implement this in your HTML file. Your objective is to encapsulate an html style tag around the variable obtained from this function:
<script>
document.getElementById('custom-container'); // Select the div container
node.innerHTML('<style> #custom-container p:nth-child('); // Wrap style around the variable
getComputedStyle(document.documentElement)
.getPropertyValue('--n'); // Obtain your variable, which in this case is '3'
node.innerHTML('){background: green;padding: 10px;}</style>'); // Close the wrapping and define the style
</script>
<div id="custom-container"> <!-- Add an ID to mark your div container -->
<p>a</p>
<p>b</p>
<p>c</p>
</div>