Turns out the answer is, in fact, to declare the variables above the <!DOCTYPE html> tag. Not sure why my initial testing of this didn't work.
For those coming here with compiler errors but the error not being highlighted by the IDE, variables declared in the <head> section are not available in the <body> section even though the IDE is showing they're available to be referenced.