## 2 Structure and Working Principle  
A resonance occurs with RWGS, when the phase matching condition is satisfied along the direction that is perpendicular to the gratings' lines, between the first diffraction order and the leaky waveguide mode, given by the following formula:  
\[n\sin\theta+m\frac{\lambda}{\Lambda}=n_{eff}\]  
where \(n\) is the refractive index of the incident medium, \(\theta\) the angle of incidence, \(m\) the diffraction order, \(\Lambda\) the grating period, \(\lambda\) the vacuum wavelength, and \(n_{eff}\) the real part of the effective refractive index of the waveguide mode. For the calculation of \(n_{eff}\), effective medium theory (EMT) can be applied to substitute a grating with a homogeneous thin film [24]. In the case of the fiber-tip RWG in this work, \(\theta\) is regarded as zero. A simplified two-dimensional (2D) infinite grating and a plane wave incident situated vertically onto the grating were employed as a starting point for the sensor's design. A Si\({}_{3}\)N\({}_{4}\) with a refractive index of \(\sim\)2.0 at around 1550 nm wavelength was chosen for the waveguide and grating, due to good adherence between the quartz and Si\({}_{3}\)N\({}_{4}\) layers [25]. The substrate material index was set to 1.452, the same as that of the fiber core. In aqueous solution detection, the surrounding refractive index was set to 1.33. Numerical tools (DiffractMOD module, RSoft 2021) based on the rigorous coupled mode analysis method (RCWA) were employed for determination of the exact structural parameters. The detailed design parameters are presented in Table 1, where \(d_{1}\) and \(d_{2}\) are the thickness of the waveguide and grating layers, respectively, and \(c\) is the duty circle. Polarization was set to TE with the electric field component E\({}_{y}\) established parallel to the grating grooves. An example of RCWA simulation results is shown in Figure 1. In relation to the given parameters, the peak position of the resonance was found to be at 1543.8 nm wavelength, as seen in Figure 1a. A typical standing wave pattern, due to the second-order Bragg reflection, is observed at the resonant wavelength and is shown in Figure 1b. \begin{table}
\begin{tabular}{c c c c c c c c} \hline \hline
**Parameter** & \(\mathbf{d_{1}}\) & \(\mathbf{d_{2}}\) & \(\mathbf{\Lambda}\) & \(\mathbf{c}\) & \(\mathbf{n_{\text{core}}}\) & \(\mathbf{n_{\text{clad}}}\) & \(\mathbf{n_{\text{env}}}\) & \(\mathbf{n_{\text{wg}}}\) \\ \hline Value & 0.18 \(\mu\)m & 0.2 \(\mu\)m & 0.95 \(\mu\)m & 0.7 & 1.452 & 1.447 & 1.33 & 2.0 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Sensor’s design parameters used for the simulations. Figure 1: RCWA results for the 2D RWG. (**a**) Reflection (solid blue) and transmission (dashed red) spectra; (**b**) Electric field component Ey at the resonant wavelength of 1543.8 nm (normalized to the incident field). The designed fiber-tip RWG sensor is presented schematically in Figure 2a,b. A Corning SMF28e fiber was chosen with a core diameter of 8.2 \(\upmu\)m, and core and cladding indices of 1.452 and 1.447, respectively. The practical implementation of this sensor can be achieved using, e.g., photolithography with subsequent etching, or direct focused ion beam (FIB) structuring. For both methods, the waveguiding high-index Si\({}_{3}\)N\({}_{4}\) layer needs to be deposited first using, e.g., sputtering or e-beam evaporation. Using a high-resolution photoresit (e.g., AZ\({}^{\text{\#}}\) MIR 701) and an interference lithography Lloyd's mirror setup with a 400 nm laser, quasi-infinite photoresist grating can be implemented over the whole area of the 125 \(\upmu\)m diameter fiber cladding and subsequently transferred into the Si\({}_{3}\)N\({}_{4}\) layer using dry etching. However, fabrication of the gold (Au) metal mirrors within the required positioning accuracy would be quite challenging (see Figure 2a). In contrast, FIB milling allows for high-resolution and high-positioning-accuracy fabrication of an RWG grating with a limited number of bars and metal mirrors on its sides.