CSS Specificity issue with Reach UI
Bug report
Describe the bug
When extending the @reach/listbox component, the css that is generated by stitches holds a lower priority than the base css that is required by the library. This means that much of the styling you define with styled will be overridden without !important everywhere.
To Reproduce
https://codesandbox.io/s/musing-nobel-tuyif?file=/src/App.js
The sandbox contains a minimum repro :) When you inspect the dropdown (popover) element, you will see that the priority of stitches styles are lower.
The top dropdown, built with stitches, will have a white background when open. The bottom dropdown, built with SC, has a green background as expected.
Expected behavior
This seems to work as expected using styled-components, which I was using before testing this out (love what you guys have here!).
Screenshots
Stitches behavior

S-C behavior

System information
- Version of Stitches: canary-7
- Version of Styled Components: 5.2.1
Hmm, yeah. It seems that the style tag added by stitches quite high up in the head. Whereas as styled-components tries to put it as lower down as possible.
@peduarte I could work on this if you could provide some insight on how we want to implement it? Not sure if we want to follow how styled-components does it (https://github.com/styled-components/styled-components/blob/08390f25fa7e353107f0a30080075104cec6426f/packages/styled-components/src/sheet/dom.js#L10).
/cc @jonathantneal
If you would like to put the stitches style tag (<style id="stitches" />) lower in the <head />, then it will take whichever priority you would like to give it.
@jonathantneal, Using snowpack to bundle, I don't have the liberty of inserting a style tag lower in the <head />. I forked this and am working on a branch where stitches inserts its style at the bottom of the <head />- assuming this is something that should be fixed.

FWIW, the @reach styles are not required. They're heavily emphasized, but if you - in good faith - replicate things with higher precedence... that's a totally valid workaround.
There are a few ways we can provide this feature. @kysley, what would be your ideal API?
We could let you specify a node. We could let you specify a selector. We could give you a react element. We could fire an "update" event or something like that with all the necessary CSS. We could give you a prepend/append switch and ... well, hopefully you see that you have options, and we want the best DX for you.
I’m glad y’all need this feature. I was surprised that nearly-if-not-all CSS-in-JS libraries get away with auto-injecting the <style> tag. I’m good with the feature, because so many designers & developers prefer how quickly they can build things this way, but I would personally never let a script perform any kind of implicit DOM manipulation on my site, because I prefer everything explicit like how things work with css() or styled().
Anyway — it may be wise to not add features for their own sake, but your request shows me that Stitches ought to give control of <style> to authors (like me, and maybe you, too! 😸). We’ll add this, your feedback is appreciated, and thanks for bringing it up.
Thanks for understanding @jonathantneal, expressing my frustration (and intent) with such grace.
Thinking about an ideal API, prepend/append switch sounds good- perhaps the best? As a consumer I might worry about placing the react element too close to the root (so that stitches styles are processed/added too soon, if that makes sense?). A switch would be expressive enough to know, that if the order is append, its going at the end of the <head/>.
I don't see an issue with specifying a selector/node, but that might be more useful for core users- or users who don't have all their styles bundled for them.
@jonathantneal Possibly related: https://github.com/modulz/stitches/issues/357
Checking in to say that the api works as expected. Thanks a lot @jonathantneal!
@kysley Great to hear.