diff --git a/frontend/editor-poc.html b/frontend/editor-poc.html
index b09d885..5ee8c73 100644
--- a/frontend/editor-poc.html
+++ b/frontend/editor-poc.html
@@ -782,15 +782,14 @@ body { font-family: var(--sans); background: var(--bg); color: var(--text); heig
// ---- Bubble menu ----
function showBubble() {
if (ta.selectionStart === ta.selectionEnd) { hideBubble(); return; }
- // Position below the selection start, using caret pixel calc
- var pt = caretToPixel(ta.selectionStart);
- // Convert from editorWrap-relative to viewport-relative
+ // Position below selection END (where user finished selecting)
+ var pt = caretToPixel(ta.selectionEnd);
var wr = editorWrap.getBoundingClientRect();
var top = wr.top + pt.y + 4;
var left = wr.left + pt.x - 10;
- // Fallback if caret calc gives odd values
- if (top < 50) { var tr = ta.getBoundingClientRect(); top = tr.bottom + 6; left = tr.left + (tr.width / 2) - (bubble.offsetWidth / 2); }
- if (top + 36 > window.innerHeight) top = top - 60;
+ // Clamp to viewport (never use textarea fallback)
+ if (top < 60) top = 60;
+ if (top + 40 > window.innerHeight - 10) top = window.innerHeight - 50;
if (left < 6) left = 6;
if (left + bubble.offsetWidth > window.innerWidth - 6) left = window.innerWidth - bubble.offsetWidth - 6;
bubble.style.left = left + 'px'; bubble.style.top = top + 'px';