Ok, so the box-sizing thing is not something "with your browser" then, but just seems to be how it is defined in the MediaWiki/Fandom CSS.
I'm not entirely sure what is going on and why, to be honest.
However, I think I found a working solution. This seems to give the desired result:
.page-content figure.thumb {
background-color: var(--theme-page-background-color--secondary);
border: 1px solid var(--theme-accent-color);
box-sizing: initial;
padding: 3px;
margin-bottom: 10px;
/*
overflow: hidden;
width: min-content;
*/
}
Note that I have commented out overflow and width, as I could not figure out the reason it's there and it seems to do nothing as far as I noticed.
I would recommend you use it this way and check your pages, and if it works fine everywhere, you could remove the commented part for good.
You can replace both the dark and light mode rules with the code above (everything between line 65 an 81). These two rules are exactly the same, so there is no need to have them twice. The light/dark colors are realized with the color variables used.
This is how it looks using my code: