Without knowing anything about how CSS is implemented by browser engines—you can constrain by context:
IF inside WithSidebarLayout, the main column is too narrow THEN switch to NoSidebarLayout.
No idea how that would be expressed in CSS syntax, though.
The CSS :has() pseudo-class is similar in how it goes against CSS’s grain.