/* Train: the table first. One header row; the modes are a deck behind the mode name. */
body.rail-shell .shell{position:relative}
body.rail-shell .train-tabs{display:flex;align-items:center;gap:16px;height:64px;min-height:64px;border-bottom:0}
body.rail-shell .train-workspace{display:block;padding-top:0;min-height:0}

/* Mode switcher: the current drill's picture and name; opens the deck. */
.train-tabs .mode-switch{display:inline-flex;align-items:center;gap:10px;min-height:44px;padding:0 10px 0 6px;margin:0;border:0;border-radius:10px;background:transparent;color:var(--text-1);font:500 17px/1 var(--sans);cursor:pointer;transition:background-color 150ms var(--ease)}
.train-tabs .mode-switch:hover,.train-tabs .mode-switch[aria-expanded=true]{background:var(--raise)}
.train-tabs .mode-switch:active{transform:scale(.98)}
.train-tabs .mode-switch:focus-visible{outline:2px solid var(--focus);outline-offset:2px}
body.rail-shell .train-tabs #mode-name{color:var(--text-1);white-space:nowrap}
#mode-name:empty::before{content:attr(data-empty)}
#mode-glyph{display:contents}
#mode-glyph .mode-glyph{width:36px;height:24px}
.mode-caret{width:14px;height:14px;flex:none;fill:none;stroke:var(--text-3);stroke-width:1.75;stroke-linecap:round;stroke-linejoin:round;transition:transform 200ms var(--ease)}
.mode-switch[aria-expanded=true] .mode-caret{transform:rotate(180deg)}
/* The lobby is the deck itself: no switcher repeating the rail's Train. */
body.rail-shell[data-screen=title] .train-tabs #home{visibility:hidden}

/* The run: one segment per spot, in the header next to the drill it belongs to. */
body.rail-shell .train-tabs #run-progress{display:flex;align-items:center;gap:3px;flex:1 1 auto;max-width:420px;min-width:0;height:20px;margin:0 auto 0 8px;padding:0}
body.rail-shell .train-tabs #run-progress i{flex:1;min-width:4px;height:4px;margin:0;border-radius:2px}
body.rail-shell .train-tabs #finish-run{min-height:36px;padding:0 12px;border:0;border-radius:8px;background:transparent;color:var(--text-2);font:400 14px var(--sans);margin:0}
body.rail-shell .train-tabs #finish-run:hover{background:var(--raise);color:var(--text-1)}
body:not([data-screen=game]):not([data-screen=end]) .train-tabs :is(#run-progress,#finish-run){visibility:hidden}
body.rail-shell .train-tabs #profile.history-button{display:inline-flex;align-items:center;gap:8px;min-height:40px;margin:0;padding:0 12px;border:0;border-radius:8px;background:transparent;color:var(--text-2);font:400 14px var(--sans)}
body.rail-shell .train-tabs .history-button:hover,body[data-screen=profile] .train-tabs .history-button{background:var(--raise);color:var(--text-1)}
.history-button svg{width:16px;height:16px;flex:none;fill:none;stroke:currentColor;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round}

/* Hand number and street are already the lit segment and the board: kept for assistive tech only. */
#game-screen .arena-top :is(#hand-number,#street){position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
body.rail-shell #game-screen .arena-top:not(:has(.clock-block:not([hidden]))){height:0;min-height:0;margin:0;padding:0;border:0;overflow:hidden}
body.rail-shell #game-screen .arena-top{border-bottom:0;justify-content:center}
body.rail-shell #game-screen{padding-top:4px}
@media(min-width:900px){body.rail-shell #game-screen .play-layout{max-width:920px;margin-inline:auto}}

/* The deck. Closed while playing; the whole lobby when no run is on. */
body.rail-shell #mode-navigation{display:none}
body.rail-shell[data-screen=title] #mode-navigation{display:block;max-width:880px;margin:clamp(24px,14vh,128px) auto 0}
/* Under the lobby deck: loading progress, or the error and Retry. */
body.rail-shell[data-screen=title] #title-screen{display:flex;align-items:center;justify-content:center;gap:12px;min-height:44px;max-width:880px;margin:16px auto 0;color:var(--text-2)}
body.rail-shell[data-screen=title] #title-screen #data-status{margin:0}
body.rail-shell.modes-open #mode-navigation{display:block;position:absolute;z-index:45;top:58px;left:22px;width:min(800px,calc(100% - 44px));padding:12px;border-radius:16px;background:var(--raise);box-shadow:0 0 0 1px var(--line-2),0 24px 48px -16px color-mix(in srgb,var(--shadow-ink) 75%,transparent);transform-origin:24px 0;animation:deck-in 200ms var(--ease) both}
body.rail-shell #mode-navigation #mode-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:0;height:auto;overflow:visible;mask-image:none;scroll-snap-type:none;flex-direction:initial}
body.rail-shell #mode-navigation #mode-grid::after{content:none}
body.rail-shell #mode-navigation #mode-grid section{display:block;margin:0;padding:0 6px;border:0}
body.rail-shell #mode-navigation #mode-grid section+section{box-shadow:-1px 0 0 var(--line)}
body.rail-shell #mode-navigation #mode-grid section>h2{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;margin:0;padding:0}
body.rail-shell #mode-navigation :is(#lobby-personal,#lobby-preflop,#lobby-postflop){display:flex;flex-direction:column;gap:4px}
body.rail-shell #mode-navigation .mode-tile{position:relative;flex:none;margin:0;border-radius:10px}
body.rail-shell #mode-navigation #mode-grid .mode-card{display:grid;grid-template-columns:44px minmax(0,1fr);grid-template-rows:auto auto;column-gap:12px;row-gap:2px;align-items:center;align-content:center;width:100%;min-height:60px;height:auto;padding:8px 40px 8px 10px;border:0;border-radius:10px;background:transparent;box-shadow:none;transform:none;animation:none;text-align:left;color:var(--text-1);transition:background-color 150ms var(--ease)}
body.rail-shell #mode-navigation #mode-grid .mode-card:hover,body.rail-shell #mode-navigation #mode-grid .mode-card:focus-visible{background:var(--raise-2)}
body.rail-shell #mode-navigation #mode-grid .mode-card:active{transform:scale(.98)}
body.rail-shell #mode-navigation #mode-grid .mode-card[aria-pressed=true]{background:var(--raise-2);box-shadow:inset 0 0 0 1px var(--accent-line)}
body.rail-shell #mode-navigation #mode-grid .mode-card .mode-glyph{grid-row:1/3;width:44px;height:30px}
body.rail-shell #mode-navigation #mode-grid .mode-card>span{grid-column:2;flex:none;font:500 14px/1.3 var(--sans);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
body.rail-shell #mode-navigation #mode-grid .mode-card>small{grid-column:2;margin:0;font:400 12px/1.3 var(--mono);font-variant-numeric:tabular-nums;color:var(--text-3)}
body.rail-shell #mode-navigation #mode-grid .mode-card>small:empty{display:none}
body.rail-shell #mode-navigation #mode-grid .mode-card[data-state=loading] .mode-glyph{opacity:.4}
/* The unlock link sits under its tile, never over the tile's own hit area. */
body.rail-shell #mode-navigation .mode-tile:has(.tile-import){padding-bottom:20px}
body.rail-shell #mode-navigation #mode-grid .mode-tile:has(.tile-import) .mode-card{min-height:44px;padding-block:8px 0}
body.rail-shell #mode-navigation .tile-import{position:absolute;left:66px;bottom:0;display:inline-flex;align-items:center;min-height:24px;padding:0;font:400 12px var(--sans);color:var(--accent-text);text-decoration:none}
body.rail-shell #mode-navigation .tile-import:hover{text-decoration:underline;text-underline-offset:3px}
body.rail-shell #mode-navigation #mode-grid .tile-settings{position:absolute;top:50%;right:4px;bottom:auto;width:36px;height:36px;margin-top:-18px;display:grid;place-items:center;padding:0;border:0;border-radius:8px;background:transparent;color:var(--text-3)}
body.rail-shell #mode-navigation #mode-grid .tile-settings:hover{background:var(--raise-3);color:var(--text-1)}
.tile-settings svg{width:16px;height:16px;fill:none;stroke:currentColor;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round}
body.modes-open #mode-navigation .mode-tile{animation:deck-tile 220ms var(--ease) both}
body.modes-open #mode-navigation .mode-tile:nth-child(2){animation-delay:30ms}
body.modes-open #mode-navigation .mode-tile:nth-child(3){animation-delay:60ms}
@keyframes deck-in{from{opacity:0;transform:translateY(-6px) scale(.98)}to{opacity:1;transform:none}}
@keyframes deck-tile{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:none}}

/* Mode pictures. */
.mode-glyph{display:block;flex:none;overflow:visible}
.mode-glyph .g-card{fill:var(--card-face)}
.mode-glyph .g-faded{fill-opacity:.35}
.mode-glyph .g-brass{fill:var(--accent)}
.mode-glyph .g-dim{fill:var(--text-3)}
.mode-glyph .g-loss{fill:var(--loss)}
.mode-glyph .g-line{fill:none;stroke:var(--text-3);stroke-width:1.4;stroke-linecap:round}
.mode-glyph .g-arrow{fill:none;stroke:var(--accent);stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round}

/* Phones: the header is one compact row, the run bar sits under it, the deck is a bottom sheet. */
@media(max-width:899px){
 body.rail-shell .train-tabs{flex-wrap:wrap;height:auto;min-height:52px;gap:4px 8px;padding:0}
 body.rail-shell .train-tabs .mode-switch{min-height:44px;font-size:16px}
 body.rail-shell .train-tabs #run-progress{order:5;flex:1 0 100%;max-width:none;height:12px;margin:0 0 8px}
 body.rail-shell .train-tabs #finish-run{margin-left:auto}
 body.rail-shell .train-tabs #profile.history-button{width:44px;min-height:44px;padding:0;justify-content:center}
 body.rail-shell .train-tabs .history-button span{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
 body.rail-shell #mode-navigation #mode-grid{grid-template-columns:1fr}
 body.rail-shell #mode-navigation #mode-grid section{padding:6px 0}
 body.rail-shell #mode-navigation #mode-grid section+section{box-shadow:0 -1px 0 var(--line)}
 body.rail-shell #mode-navigation :is(#lobby-personal,#lobby-preflop,#lobby-postflop){display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:4px}
 body.rail-shell #mode-navigation .mode-tile{display:block}
 body.rail-shell #mode-navigation #mode-grid .mode-card{grid-template-columns:1fr;grid-template-rows:auto;justify-items:center;row-gap:4px;min-height:92px;padding:10px 4px;text-align:center}
 body.rail-shell #mode-navigation #mode-grid .mode-card .mode-glyph{grid-row:auto}
 body.rail-shell #mode-navigation #mode-grid .mode-card>span{grid-column:auto;font-size:12px;white-space:normal;line-height:1.2}
 body.rail-shell #mode-navigation #mode-grid .mode-card>small{grid-column:auto;font-size:11px}
 body.rail-shell #mode-navigation #mode-grid .mode-tile:has(.tile-import) .mode-card{min-height:72px;padding:10px 4px 0}
 body.rail-shell #mode-navigation .mode-tile:has(.tile-import){padding-bottom:0}
 body.rail-shell #mode-navigation .tile-import{position:static;display:flex;justify-content:center;font-size:11px}
 body.rail-shell #mode-navigation #mode-grid .tile-settings{top:4px;right:4px;margin:0}
 body.rail-shell[data-screen=title] #mode-navigation{margin-top:8px}
 body.rail-shell.modes-open #mode-navigation{position:fixed;z-index:60;top:auto;left:0;right:0;bottom:0;width:auto;max-height:calc(100dvh - 64px);overflow-y:auto;padding:12px 12px calc(16px + env(safe-area-inset-bottom));border-radius:16px 16px 0 0;transform-origin:50% 100%;animation:sheet-in 260ms var(--ease) both}
 body.rail-shell.modes-open::after{content:'';position:fixed;inset:0;z-index:55;background:var(--scrim);animation:scrim-in 200ms ease both}
}
@keyframes sheet-in{from{transform:translateY(24px);opacity:0}to{transform:none;opacity:1}}
@keyframes scrim-in{from{opacity:0}to{opacity:1}}
@media(prefers-reduced-motion:reduce){
 body.rail-shell.modes-open #mode-navigation,body.modes-open #mode-navigation .mode-tile,body.rail-shell.modes-open::after{animation:none}
 .mode-caret,.train-tabs .mode-switch{transition:none}
}
/* Current spot in the run: the first unplayed segment carries the accent. */
body.rail-shell #run-progress i[class=""]:first-child,body.rail-shell #run-progress i:is(.perfect,.correct,.error)+i[class=""]{background:var(--accent)}

body.rail-shell.has-continuation[data-screen=title] #title-screen{margin-top:clamp(24px,8vh,72px)}
body.rail-shell.has-continuation[data-screen=title] #mode-navigation{margin-top:24px}
#personal-continue{min-height:44px;font-variant-numeric:tabular-nums}
