I have gone through your question. I found it interesting so I am trying to help you.
Your error "Start tag
head seen but an element of the same type was already open." Usually occurs as a start tag for a head element is the optional.
As any style element can only exist within a head tag so usually a parser will know to open a head element when it sees a
<style> tag, as inserting the invisible
<head> start tag.
No error or warning will be thrown there as I already told you that your
<head> start tag is the optional.
But if a parser sees your
<head> start tag then it will certainly throw the error as your head was already in open state.