Professional?
I am a retired
swab jockey (was in the 'Black shoe' Navy).
I learned electronics in the vacuum tube era. Started using computers that loaded from
paper tape.
I do this for
fun (and to make the horrible formatting I see, pleasant for me to read.)
From your description, a One Size Fits All

Stylesheet
is not what you want for a TEXTBOOK. (Dr. Knuth wrote TeX for this reason).
OSFA might work for a novel. You have specific requirements.
Ask a Computer science (web page designer) for help.
Ebooks are closer to HTML 3.2 (which Mobi is based upon). No fancy Java needed (or wanted).