With the expansion of China’s high-speed rail (HSR) system, the frequency of inter-city train services has been significantly increased, making HSR a preferred choice for many travelers. In traditional ticketing systems which bind a ticket to a specific reserved seat, passengers arriving early or late at the station can lead to either excessive waiting or additional costs associated with changing tickets. In this paper, we explore an alternative ticketing approach known as "flexible ticketing," which allows passengers to board any train within a designated time window after arriving at the station. However, this flexibility introduces challenges for HSR operators in ensuring that passengers can board their desired trains, especially given the strict train capacity constraints inherent to HSR. To investigate this issue, we formulate a bilevel optimization model for a two-train schedule between two cities, where the upper level represents the HSR operator's decisions on capacity and pricing, and the lower level models the passengers' two-stage choices regarding ticketing mode and departure time, taking into account the uncertainty of their train access times. Assuming uniformly distributed train access times and risk-neutral passengers, we derive analytical solutions for the operator's optimal decisions aimed at either revenue or social welfare maximization, as well as the resulting unique equilibrium costs for passengers. Our findings suggest that flexible ticketing is particularly advantageous when trains have short headways, the level of train access time uncertainty is high, and passengers place a high value on their time. Under these conditions, flexible ticketing can serve as a premium service that boosts operator revenue without compromising traveler benefits.