/* Brindle Valley Railway - stage and in-game UI. Everything is scoped under #stage so site styles never leak in. */
html.pip-big, html.pip-big body { overflow: hidden; }
#stage { --ink:#1f2b3d; --panel:#fffaf0; --panel2:#f3e9d2; --line:#d9c9a3; --accent:#d9534f; --accent-d:#a93c39; --gold:#f2b632; --green:#3aa86a; --blue:#2f8fd8; --dim:#6b7488;
  position: relative; width: min(100%, calc(78vh * 0.5625)); width: min(100%, calc(78svh * 0.5625)); aspect-ratio: 9 / 16; margin: 0 auto; overflow: hidden;
  border-radius: 14px; background: linear-gradient(#bfe3ff, #e8f6ff); color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; line-height: 1.25; font-size: 14px; }
#stage.is-big { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; aspect-ratio: auto; border-radius: 0; z-index: 99999; }
.game-wrap.pip-stage #stage { width: min(100%, calc((100vh - 64px) * 0.5625)); width: min(100%, calc((100svh - 64px) * 0.5625)); }
#stage *, #stage *::before, #stage *::after { box-sizing: border-box; }
#stage [hidden] { display: none !important; }
#stage #app { position: absolute; inset: 0; }
#stage #app canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#stage #ui { position: absolute; inset: 0; pointer-events: none; }
#stage #ui button, #stage .sheet, #stage .selcard, #stage .screen, #stage .tabs, #stage .hud .hudbtns { pointer-events: auto; }
#stage button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
#stage button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; box-shadow: 0 0 0 5px var(--accent); }

#stage #loader { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: linear-gradient(#7cc46a, #bfe3ff); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-shadow: 0 2px 0 rgba(20,60,40,.5); text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 30px); letter-spacing: 1px; }
#stage .load-in span { font-size: 14px; }
#stage .spinner { width: 42px; height: 42px; border-radius: 50%; border: 6px solid rgba(255,255,255,.4); border-top-color: var(--gold); animation: itspin .8s linear infinite; }
@keyframes itspin { to { transform: rotate(360deg); } }
#stage #ctxlost { position: absolute; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; background: rgba(20,32,50,.88); color: #fff; font-weight: 700; }

/* labels and floats over the map */
#stage .labels, #stage .floats { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
#stage .tlabel { position: absolute; left: 0; top: 0; display: none; white-space: nowrap; background: rgba(255,250,240,.9); border-radius: 10px; padding: 2px 8px; font-weight: 800; font-size: 12px; box-shadow: 0 2px 0 rgba(0,0,0,.18); will-change: transform; }
#stage .tlabel.sel { background: var(--gold); }
#stage .tlabel .fest { margin-left: 6px; color: #b3261e; font-size: 11px; }
#stage .float { position: absolute; transform: translate(-50%, -50%); font-weight: 800; font-size: 15px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); animation: itfloat 1.3s ease-out forwards; }
#stage .float.good { color: #fff6a8; }
@keyframes itfloat { 0% { opacity: 1; margin-top: 0; } 100% { opacity: 0; margin-top: -46px; } }

/* HUD */
#stage .hud { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; gap: 6px; padding: max(8px, env(safe-area-inset-top)) 8px 4px; pointer-events: none; }
#stage .cashbox { background: rgba(31,43,61,.82); color: #fff; border-radius: 12px; padding: 4px 10px; min-width: 96px; }
#stage .cash { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
#stage .inc { font-size: 11px; opacity: .85; font-variant-numeric: tabular-nums; }
#stage .hudmid { flex: 1; min-width: 0; text-align: center; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.65); font-weight: 700; font-size: 12px; padding-top: 2px; }
#stage .chpill { display: inline-block; margin-top: 2px; background: rgba(242,182,50,.95); color: #3b2a00; text-shadow: none; border-radius: 10px; padding: 1px 8px; }
#stage .hudbtns { display: flex; gap: 6px; }
#stage .b { border: 0; border-radius: 12px; background: var(--panel2); color: var(--ink); font-weight: 800; font-size: 14px; padding: 10px 12px; min-height: 44px; min-width: 44px; box-shadow: 0 3px 0 var(--line); }
#stage .b:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
#stage .b.dis { opacity: .5; }
#stage .b.go { background: var(--green); color: #fff; box-shadow: 0 3px 0 #277a4b; }
#stage .b.danger { background: #e8b4b0; }
#stage .boost { background: var(--gold); box-shadow: 0 3px 0 #b88410; font-size: 12px; padding: 6px 8px; }
#stage .boost.on { background: #ff8a3a; color: #fff; }
#stage .pausebtn { background: rgba(31,43,61,.82); color: #fff; box-shadow: none; }
#stage .strip { position: absolute; left: 8px; right: 8px; top: calc(max(8px, env(safe-area-inset-top)) + 54px); background: rgba(255,250,240,.92); border-radius: 10px; padding: 4px 10px 6px; font-size: 12px; font-weight: 700; }
#stage .bar { height: 7px; border-radius: 4px; background: rgba(0,0,0,.14); overflow: hidden; margin-top: 3px; }
#stage .bar i { display: block; height: 100%; width: 0; background: var(--green); transition: width .25s; }
#stage .bar.gold i { background: var(--gold); }
#stage .hint { position: absolute; left: 14px; right: 14px; top: calc(max(8px, env(safe-area-inset-top)) + 100px); background: var(--accent); color: #fff; border-radius: 12px; padding: 8px 12px; font-weight: 700; font-size: 13px; text-align: center; box-shadow: 0 3px 0 var(--accent-d); }

/* tabs, sheet, selected town card */
#stage .tabs { position: absolute; left: 0; right: 0; bottom: 0; display: flex; background: var(--panel); border-top: 2px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#stage .tab { flex: 1; border: 0; background: transparent; padding: 10px 2px; min-height: 48px; font-weight: 800; font-size: 12px; color: var(--dim); }
#stage .tab.on { color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
#stage .tab.alert::after { content: "!"; display: inline-block; margin-left: 3px; background: var(--gold); color: #3b2a00; border-radius: 50%; width: 15px; height: 15px; line-height: 15px; font-size: 11px; }
#stage .sheet { position: absolute; left: 0; right: 0; bottom: calc(50px + env(safe-area-inset-bottom)); height: 46%; background: var(--panel); border-radius: 16px 16px 0 0; box-shadow: 0 -3px 12px rgba(0,0,0,.25); overflow: hidden; display: flex; }
#stage .sbody { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; touch-action: pan-y; overscroll-behavior: contain; padding: 8px 10px 12px; }
#stage .selcard { position: absolute; left: 8px; right: 8px; bottom: calc(58px + env(safe-area-inset-bottom)); background: var(--panel); border-radius: 14px; padding: 8px 10px; box-shadow: 0 3px 12px rgba(0,0,0,.3); }
#stage .card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px; margin-bottom: 8px; }
#stage .chead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
#stage .dim { color: var(--dim); font-size: 12px; }
#stage .small { font-size: 11px; margin-top: 4px; }
#stage .empty { padding: 12px 6px; color: var(--dim); }
#stage .trow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
#stage .trow .b { flex: 1 1 30%; font-size: 12px; padding: 6px 6px; }
#stage .tname { flex: 1 1 100%; font-weight: 800; display: flex; align-items: center; gap: 6px; }
#stage .trow.buy { border-top: 1px dashed var(--line); padding-top: 6px; }
#stage .trow.tgt { flex-wrap: nowrap; }
#stage .trow.tgt .bar { flex: 1; }
#stage .trow.done span { color: var(--green); font-weight: 800; }
#stage .chipb { border: 3px solid var(--line); }
#stage .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; }
#stage .dem { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
#stage .dchip { display: inline-flex; align-items: center; gap: 4px; background: var(--panel2); border-radius: 8px; padding: 2px 6px; font-size: 11px; font-weight: 700; }
#stage .dchip.prod { background: #e1f3e5; }
#stage .crow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
#stage .crow span { flex: 1 1 100%; font-weight: 700; }
#stage .crow .b { flex: 1; }
#stage .xbtn { padding: 4px 10px; }
#stage .ugrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#stage .ub { font-size: 12px; padding: 6px; }
#stage .ub.wide { width: 100%; text-align: left; margin-bottom: 2px; }
#stage .prow { margin-bottom: 4px; }
#stage .mrow, #stage .arow { padding: 4px 0; border-bottom: 1px solid #eee; font-size: 12px; }
#stage .arow { display: flex; flex-direction: column; opacity: .55; }
#stage .arow.got { opacity: 1; }
#stage .set { display: block; width: 100%; margin-bottom: 8px; text-align: left; }

/* toasts */
#stage .toasts { position: absolute; left: 0; right: 0; top: calc(max(8px, env(safe-area-inset-top)) + 134px); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
#stage .toast { background: rgba(31,43,61,.92); color: #fff; padding: 6px 12px; border-radius: 12px; font-weight: 700; font-size: 13px; max-width: 90%; text-align: center; animation: ittoast .25s ease-out; }
#stage .toast.good { background: rgba(39,122,75,.95); }
#stage .toast.bad { background: rgba(169,60,57,.95); }
@keyframes ittoast { from { opacity: 0; transform: translateY(-8px); } }

/* full-stage screens */
#stage .screen { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(31,43,61,.55); padding: 12px; overflow-y: auto; touch-action: pan-y; }
#stage .scr { width: 100%; max-width: 360px; margin: auto; background: var(--panel); border-radius: 18px; padding: 16px; box-shadow: 0 6px 24px rgba(0,0,0,.35); text-align: center; }
#stage .scr h2 { font-size: 22px; margin-bottom: 2px; }
#stage .scr .sub { color: var(--dim); font-size: 13px; margin-bottom: 12px; }
#stage .scr p { margin: 8px 0; }
#stage .scr .b.big { display: block; width: 100%; margin-top: 8px; font-size: 16px; padding: 12px; }
#stage .scr .row2 { display: flex; gap: 8px; margin-top: 8px; }
#stage .scr .row2 .b { flex: 1; }
#stage .score { font-size: 32px; font-weight: 800; color: var(--accent); margin: 4px 0; }
#stage .starsbig { font-size: 36px; color: var(--gold); letter-spacing: 4px; }
#stage .tline { color: var(--dim); } #stage .tline.got { color: var(--green); font-weight: 800; }
#stage .banner { background: #fff1c2; border-radius: 10px; padding: 6px 8px; font-weight: 700; }
#stage .goalline { font-weight: 700; color: var(--accent-d); }
#stage .lvls { display: flex; flex-direction: column; gap: 6px; max-height: 52vh; overflow-y: auto; touch-action: pan-y; }
#stage .lvl { text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
#stage .lvl small { grid-column: 1 / -1; color: var(--dim); font-weight: 600; }
#stage .lvl.dis { opacity: .55; }
#stage .setbox { margin-top: 8px; }
@media (max-height: 520px) { #stage .scr { padding: 10px; } #stage .scr .b.big { padding: 8px; } }
@keyframes itpulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }
#stage .boost.on, #stage .tab.alert { animation: itpulse 1s ease-in-out infinite; }
#stage .scr.title h2 { color: var(--accent-d); text-shadow: 0 2px 0 var(--gold); }
#stage .scr .banner { animation: ittoast .35s ease-out; }
@media (prefers-reduced-motion: reduce) { #stage .float, #stage .toast, #stage .spinner, #stage .boost.on, #stage .tab.alert, #stage .scr .banner { animation: none; } #stage .bar i { transition: none; } }

/* page chrome below the stage */
.it-bar { display: flex; justify-content: center; margin: 10px 0 4px; }
.it-bar .btn { min-height: 44px; }
.it-keys { text-align: center; font-size: .78rem; color: #64748b; margin-top: 6px; }
.it-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 16px; line-height: 1.6; }
.it-guide h2 { font-size: 1.3rem; margin-bottom: .6rem; }
.it-guide h3 { font-size: 1.02rem; margin: 1rem 0 .3rem; }
.it-guide p { margin-bottom: .6rem; }

/* Full screen (shell immersive/native): the 3D stage fills the screen, in portrait and landscape.
   The shell sizes .game-wrap; the canvas is re-sized by the ResizeObserver and PIPShell.onResize. */
html.pip-immersive .game-wrap.pip-stage { display: flex; flex-direction: column; overflow: hidden; }
html.pip-immersive .game-wrap.pip-stage #stage { flex: 1 1 auto; min-height: 0; width: 100%; max-width: none; height: auto; aspect-ratio: auto; border-radius: 0; margin: 0; }
html.pip-immersive .game-wrap.pip-stage > .it-bar, html.pip-immersive .game-wrap.pip-stage > .it-keys, html.pip-immersive .game-wrap.pip-stage > .game-title { display: none; }
html.pip-immersive #stage .tabs { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .sheet { left: auto; width: min(58%, 520px); height: calc(100% - 120px); bottom: calc(50px + env(safe-area-inset-bottom)); border-radius: 16px 0 0 0; }
  html.pip-immersive #stage .tab { min-height: 44px; }
}
