The text is a contenteditable region. On each selection change I position the bar off the range's bounding rectangle. Bold and friends go through the document commands so their state reads back with queryCommandState; size, weight, and color wrap the range in a managed span. The real trick: every control cancels its own mousedown, so the selection stays put and commands stack without reselecting.
// Position the bar off the live selection rectangle.
const rect = range.getBoundingClientRect()
let top = rect.top - barHeight - 10 // above the selection
if (top < 2) top = rect.bottom + 10 // flip below near the top
The Ask AI pill is a non-active affordance, not a fake response, and reduced motion drops the spring for a plain fade.