Hi! First of all, I want to tell you it is normal to struggle. It is not a negative thing. Actually, it is only through struggle that we learn more and get better. I would say "Embrace struggle". :) So don't worry about that bit.
Also, the project looks quite good and I really liked the transition effect of when the popup fades in and out. That was cool.
With regards to what you request specifically, IMHO it may work better to place the .share-box2
inside the .share
and then from there you can handle the positioning with a media query (or container query, whichever you prefer) and then using absolute positioning (eg you change the relative positioning according to the viewport/container width). Then, in JavaScript, you only handle the opening and closing of your popup (not its positioning, which is more like style, and it's probably better handled in CSS).
Also, it would help to use more semantic HTML, (section, article, button, etc.) and this includes probably using the <dialog>
HTML element (I would use it as non-modal, check MDN for this). It should make things easier with opening and closing it, I think.
Hope that's both helpful and clear, but feel free to follow up, responding here, and I will try my best to be of help.
Also, remember you've done a great job, and in development there's never a goal, you're always in a "struggle" to learn and improve on smth. Don't worry about it, just enjoy it. HTH!