ll; return; }
          let best = null, bestY = -Infinity;
          for (const w of state.words) {
            if (w.text.startsWith(state.buffer)) {
              if (w.y > bestY) { best = w; bestY = w.y; }
            }
          }
          state.targetId = best ? best.id : null;
        }

        function handleChar(ch) {
          if (!state.running || state.paused) return;
          if (!ch || ch.length !== 1) return;
          state.totalTyped++;
          const next = (state.buffer + ch).toLowerC