@jleonard99
Thanks for the note about the API not properly sanitizing the code. I wouldn't rely on that feature. They may not fix it for a long time (if ever), but there are some things that people continue to push despite Canvas saying it's deprecated. I just wanted to throw that out there that this is undocumented and unsupported behavior and the official Canvas line is that you shouldn't rely on it and frequently test whenever upgrades to their software are made.
As you mentioned, editing the page with the Rich Content Editor makes it disappear as the style element isn't allowed in the body's HTML. This limits its suitability to courses where the instructor cannot change anything. That can be accomplished with Canvas using blueprint courses. If someone can edit the page, then all of the hard work disappears in a flash. I have that situation in one of my courses this semester. I have a flex model that I want the bottom two blocks to always be on a line by themselves. I can put an empty div in through the API but it gets stripped as soon as I edit the page.
The style element isn't allowed in the body. It's allowed in the head. It is invalid HTML to put it in the body, which is what you're doing. Don't expect there to be a solution for the media query when Canvas doesn't support style elements in the body anyways.
The correct solution is to add custom CSS to the theme. That's injected into the head of the HTML document and you could include your media descriptor there. It looks like you have design skills, but based on the name of the page, I cannot tell if you're an instructional designer for the school or this is a class about designing a better interface.
If you're working for the school in a design role (probable since you also know about the API), then you can see your Canvas admin about adding some well thought out CSS to the theme. If it's for a class project, they won't add that for the whole account.
You mention the issue with resizing. The flex grid model can handle some of that for you. I use it for my statistics course home pages and specify different layouts based on the width of the device. It mostly works well, although I get just one column on some phones. I originally started with 3 columns on a wide screen because it looked nice on my screen, but then went back down to two because of the way it looked on the student's. You may be able to make flex work for you rather than using media queries to accomplish it.
But if you really must use the media query, then add it to custom CSS applied through the theme. Realize, though, that it applies everywhere, so you will also want to add specific classes to make sure it doesn't change more than you want.
Another option, if you cannot get the CSS in the theme is to add JavaScript through the theme. It could look for whether the pathname matches a pattern (limiting yourself to content pages and not quizzes or assignments, for example) and then check if a certain classname is found on the page. If the classname is found, then inject the CSS by adding a stylesheet. If the class isn't found on the page, then just return. This is a way that you could add course-level CSS rather than account-level CSS.
One note with pages, though, you may have to add a mutation observer to wait for the page to be rendered -- I've found that guarantees that your script will not run until certain things are available isn't always the case. That was years ago, though, and it might have changed.