U.S. stocks gained on Thursday after surprisingly strong March retail sales increased optimism that the economic recovery is on track.

Investors snapped up retailers' shares after top U.S. chains reported a record year-over-year increase in same-store sales for March. The sales reflected a boost in consumer demand that some investors had doubted would materialize, with job growth still anemic.

The S&P retail index <.RLX> rose 1.3 percent. Online merchant Amazon.com jumped 4.5 percent to $140.96, its highest close in four months.

Retail sales are the whole backbone of the entire recovery, said Keith Springer, president of Capital Financial Advisory Services in Sacramento, California.

The whole premise is, if consumer spending and retail sales maintain anywhere close to where they were a couple years ago, then that will be a true recovery.

The Dow Jones industrial average <.DJI> gained 29.55 points, or 0.27 percent, to 10,927.07. The Standard & Poor's 500 Index <.SPX> rose 3.99 points, or 0.34 percent, to 1,186.44. The Nasdaq Composite Index <.IXIC> added 5.65 points, or 0.23 percent, to 2,436.81.

S&P'S SLOW AND STEADY CLIMB

The indexes' moderate gains were characteristic of the rally's most recent leg. The S&P 500 has ground slowly higher since the beginning of March, rising 7.4 percent, even as momentum indicators suggest the rally could stall in coming weeks.

The biggest thing in the market at the moment is, the path of least resistance is higher, said David Katz, chief investment officer of Matrix Asset Advisors in New York. You've had an improving market for the last month-and-a-half, and you have people that were under-invested that seem to be jumping on that bandwagon.

Among advancers in the retail space, Target Corp rose 3 percent to $55.64, while Gap Inc climbed 3.1 percent to $24.59.

Major retail chains reported a record 9.1 percent jump in March same-store sales -- beating the forecast for a 6.3 percent gain, according to Thomson Reuters data. Of the 28 retailers that Thomson Reuters tracks, more than 90 percent topped estimates.

Even so, retail executives and analysts warned that the jump in March would come at the expense of April sales.

Gains in retailers' stocks eclipsed worries about Greece's debt load as the country's borrowing costs rose to new highs even as the government struggled to reassure markets it can stay solvent.

An index of U.S.-listed stocks of Greek companies <.BKGR> fell 2.2 percent.

In a move that could create the second-largest air carrier in the United States, UAL Corp's United Airlines and US Airways Group were in merger talks, according to two sources familiar with the matter.

Shares of both companies surged, with UAL Corp up 6.8 percent at $20.23 and US Airways jumping 10.7 percent to $7.55.

SEMIS SLIDE

On the downside, shares of chipmakers tumbled, with the Philadelphia Stock Exchange index of semiconductors <.SOXX> down 1.4 percent at 371.47. The close tested a key trend line support in the 372 area, according to Stifel Nicolaus options strategist Elliot Spar.

We need to see a clear break of 372, which could target a recent low of 360 in the index, Spar said. As the index is a leading sector in the Nasdaq Composite, weakness in the SOXX could be a catalyst for a break in the Nasdaq to below 2,413, which was today's low and trend-line support.

On the economic front, data showed the number of workers filing for unemployment benefits unexpectedly rose last week. But the jump reflected volatility from the Easter holiday and did not alter the view that labor markets are recovering.

About 8.48 billion shares traded on the New York Stock Exchange, the American Stock Exchange and Nasdaq, below last year's estimated daily average of 9.65 billion.

Advancing stocks outnumbered declining ones on the NYSE by a ratio of 8 to 7, while on the Nasdaq, nearly 14 stocks rose for every 13 that fell.

(Reporting by Leah Schnurr; Editing by Jan Paschal)