/* Redrock Colony 3D - 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 { --rust:#c4562e; --rust-d:#8e3a1c; --sand:#ffd9a8; --ink:#fbeede; --panel:rgba(26,17,32,.86); --ok:#6be08a; --warn:#ffc233; --bad:#ff5a48; --cyan:#7fe3ff;
  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: #1c1428; 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; }
#stage.is-big { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; aspect-ratio: auto; border-radius: 0; z-index: 99999; }
#stage *, #stage *::before, #stage *::after { box-sizing: border-box; }
#stage #app { position: absolute; inset: 0; touch-action: none; }
#stage #app canvas { display: block; width: 100%; height: 100%; }
#stage #ui { position: absolute; inset: 0; pointer-events: none; }
#stage button { font-family: inherit; cursor: pointer; touch-action: manipulation; color: inherit; }
#stage button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
#stage [hidden] { display: none !important; }

#stage #loader { position: absolute; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: linear-gradient(#1c1428, #6b3a2a); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 30px); letter-spacing: 3px; }
#stage .load-in span { font-size: 14px; opacity: .95; }
#stage .spinner { width: 42px; height: 42px; border-radius: 50%; border: 6px solid rgba(255,255,255,.3); border-top-color: var(--warn); animation: scspin .8s linear infinite; }
@keyframes scspin { to { transform: rotate(360deg); } }
#stage #ctxlost { position: absolute; inset: 0; z-index: 55; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; background: rgba(20,12,26,.88); color: #fff; font-weight: 700; }

/* ---- HUD */
#stage .hud-top { position: absolute; left: 0; right: 0; top: 0; padding: 6px 6px 0; pointer-events: none; display: flex; flex-direction: column; gap: 4px; }
#stage .rowa { display: flex; align-items: center; gap: 6px; pointer-events: none; }
#stage .btn { min-height: 44px; min-width: 44px; padding: 0 12px; border-radius: 10px; border: 2px solid rgba(255,255,255,.18); background: var(--panel); font-weight: 800; font-size: 14px; pointer-events: auto; }
#stage .btn.on { background: var(--rust); border-color: var(--sand); }
#stage .btn:disabled { opacity: .45; cursor: default; }
#stage .btn.ghost { background: rgba(255,255,255,.08); }
#stage .btn.warn { background: #7a2a22; }
#stage .btn.mini { min-height: 44px; padding: 0 12px; font-size: 13px; }
#stage .btn.step { min-width: 48px; font-size: 20px; padding: 0; }
#stage .btn.big { display: block; width: 100%; min-height: 52px; font-size: 18px; margin: 8px 0; background: var(--rust); border-color: var(--sand); }
#stage .btn.big.alt { background: #4a2d52; border-color: rgba(255,255,255,.3); }
#stage .rowa .menu { padding: 0 10px; }
#stage .daybox { flex: 1; min-width: 0; background: var(--panel); border-radius: 10px; padding: 4px 8px; text-align: center; font-weight: 800; font-size: 13px; }
#stage .daytrack { height: 5px; border-radius: 3px; background: rgba(255,255,255,.15); margin-top: 3px; overflow: hidden; }
#stage .daybar { display: block; height: 100%; width: 0; background: var(--warn); }
#stage .speeds { display: flex; gap: 4px; }
#stage .btn.sp { padding: 0; min-width: 44px; font-size: 13px; }
#stage .chips { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; pointer-events: none; }
#stage .chip { background: var(--panel); border-radius: 8px; padding: 3px 2px; text-align: center; border: 2px solid transparent; min-width: 0; }
#stage .chip .l { display: block; font-size: 9px; opacity: .75; letter-spacing: .5px; }
#stage .chip .v { display: block; font-size: 14px; font-weight: 800; }
#stage .chip .d { display: block; font-size: 10px; opacity: .8; }
#stage .chip .d.pos { color: var(--ok); } #stage .chip .d.neg { color: var(--bad); }
#stage .chip.low { border-color: var(--bad); animation: scpulse 1s infinite alternate; }
@keyframes scpulse { to { background: #5a2018; } }
#stage button.goals { position: relative; pointer-events: auto; min-height: 30px; border-radius: 8px; border: 0; background: var(--panel); font-size: 12px; font-weight: 700; padding: 0 10px; text-align: left; }
#stage .goal-list { background: var(--panel); border-radius: 8px; padding: 4px 8px; font-size: 12px; pointer-events: none; }
#stage .goal-list .g.ok { color: var(--ok); }
#stage .warnbar { background: rgba(120,60,10,.92); border: 2px solid var(--warn); border-radius: 10px; padding: 6px 10px; font-size: 12px; font-weight: 800; text-align: center; pointer-events: none; }
#stage .warnbar.bad { background: rgba(130,24,16,.94); border-color: var(--bad); }
#stage .hint { background: rgba(255,244,214,.96); color: #3a2418; border-radius: 12px; padding: 8px 12px; font-size: 13px; font-weight: 700; text-align: center; pointer-events: none; box-shadow: 0 3px 10px rgba(0,0,0,.4); }
#stage .toasts { display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; }
#stage .toast { background: rgba(26,17,32,.92); border-radius: 10px; padding: 5px 12px; font-size: 12px; font-weight: 700; max-width: 92%; text-align: center; }
#stage .toast.bad { background: rgba(130,24,16,.94); } #stage .toast.good { background: rgba(20,90,50,.94); } #stage .toast.tech { background: rgba(70,40,120,.94); }

#stage .dock { position: absolute; left: 0; right: 0; bottom: 0; pointer-events: none; }
#stage .panel { background: var(--panel); margin: 0 6px 4px; border-radius: 12px; pointer-events: auto; max-height: min(34svh, 240px); overflow-y: auto; touch-action: pan-y; padding: 6px; }
#stage .sub { display: block; }
#stage .cards { display: flex; gap: 6px; overflow-x: auto; touch-action: pan-x; padding-bottom: 4px; }
#stage .card { flex: 0 0 72px; min-height: 64px; border-radius: 10px; border: 2px solid rgba(255,255,255,.18); background: #3a2644; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 4px 2px; }
#stage .card b { font-size: 15px; } #stage .card .nm { font-size: 9px; opacity: .8; } #stage .card .cost { font-size: 12px; font-weight: 800; color: var(--sand); }
#stage .card.armed { border-color: var(--ok); background: #2c5a3a; }
#stage .card.poor .cost { color: var(--bad); } #stage .card.lock { opacity: .45; }
#stage .brow { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
#stage .bdesc, #stage .crewhead { flex: 1; font-size: 12px; min-width: 0; }
#stage .crow { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
#stage .crow .jn { flex: 1; font-size: 13px; font-weight: 700; } #stage .crow .cnt { width: 44px; text-align: center; font-weight: 800; }
#stage .idle { font-size: 12px; margin-top: 4px; opacity: .85; }
#stage .trow { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
#stage .trow .tt { flex: 1; min-width: 0; } #stage .trow b { display: block; font-size: 13px; } #stage .trow span { font-size: 11px; opacity: .8; }
#stage .trow.done { opacity: .5; }
#stage .tabs { display: flex; gap: 6px; padding: 0 6px 6px; pointer-events: none; }
#stage .btn.tab { flex: 1; pointer-events: auto; min-height: 48px; }
#stage .hpwrap { height: 7px; background: rgba(255,255,255,.18); border-radius: 4px; overflow: hidden; margin: 4px 0; }
#stage .hpbar { display: block; height: 100%; background: var(--ok); }
#stage .si { font-size: 12px; opacity: .9; margin-bottom: 2px; }

/* ---- screens */
#stage .screen { position: absolute; inset: 0; z-index: 30; pointer-events: auto; overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch;
  background: linear-gradient(rgba(20,12,30,.92), rgba(70,34,28,.95)); padding: 14px 14px 22px; }
#stage .shead { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
#stage .shead h2 { font-size: 20px; margin: 0; }
#stage .logo { text-align: center; margin: 8px 0 4px; } #stage .logo b { display: block; font-size: clamp(30px, 10vw, 44px); letter-spacing: 4px; color: var(--sand); text-shadow: 0 3px 0 var(--rust-d); }
#stage .logo span { display: block; font-size: 16px; letter-spacing: 8px; color: var(--cyan); }
#stage .tag { text-align: center; font-size: 13px; margin: 6px 0 10px; opacity: .9; }
#stage .pill { background: rgba(255,255,255,.1); border-radius: 12px; padding: 8px 10px; font-size: 12px; margin: 6px 0; text-align: center; font-weight: 700; }
#stage .pill.good { background: rgba(40,120,70,.5); }
#stage .pair { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin: 6px 0; }
#stage .sbody p { font-size: 13px; margin: 8px 0; } #stage .warnp { color: var(--warn); }
#stage .lcard { display: flex; flex-direction: column; gap: 3px; width: 100%; text-align: left; min-height: 64px; padding: 10px 12px; margin-bottom: 8px; border-radius: 12px; border: 2px solid rgba(255,255,255,.2); background: #3a2644; }
#stage .lcard b { font-size: 15px; } #stage .lcard span { font-size: 12px; opacity: .9; } #stage .lcard em { font-size: 11px; color: var(--sand); font-style: normal; }
#stage .lcard.lock { opacity: .5; }
#stage .lrow { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.12); }
#stage .lrow .lt { flex: 1; min-width: 0; } #stage .lrow b { display: block; font-size: 14px; } #stage .lrow span { font-size: 12px; opacity: .85; }
#stage .bigmark { text-align: center; font-size: 28px; font-weight: 800; margin: 12px 0 4px; } #stage .bigmark.win { color: var(--ok); } #stage .bigmark.lose { color: var(--bad); }
#stage .stars { text-align: center; font-size: 34px; letter-spacing: 6px; color: var(--warn); }
#stage .next { font-weight: 700; color: var(--sand); }

/* ---- page chrome under the game */
.sc-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.sc-bar .btn { min-height: 44px; min-width: 44px; }
.sc-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.sc-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.sc-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.sc-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.sc-guide p { margin-bottom: .5rem; font-size: .95rem; }
@media (max-height: 560px) { #stage .hint { background: rgba(255,244,214,.96); color: #3a2418; border-radius: 12px; padding: 8px 12px; font-size: 13px; font-weight: 700; text-align: center; pointer-events: none; box-shadow: 0 3px 10px rgba(0,0,0,.4); } }
@media (prefers-reduced-motion: reduce) { #stage .chip.low, #stage .spinner { animation: none; } }

#stage button.goals::after { content: ""; position: absolute; left: 0; right: 0; top: -7px; bottom: -7px; }

/* safe areas: keep HUD clear of notches and home bars when the stage fills the screen */
#stage.is-big #ui { padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
@media (prefers-reduced-motion: reduce) { #stage *, #stage *::before, #stage *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }

/* ---- third pass: full screen on phones. The shell makes .game-wrap the stage; the board fills it, the extras step aside. */
.sc-bar { display: none; }
html.pip-immersive .game-wrap { display: flex !important; flex-direction: column; overflow: hidden !important; }
html.pip-immersive .game-wrap > .sc-bar, html.pip-immersive .game-wrap > .sc-keys, html.pip-immersive .game-wrap > noscript { display: none !important; }
html.pip-immersive #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 #stage .hud-top { padding-left: max(6px, env(safe-area-inset-left, 0px)); padding-right: max(6px, env(safe-area-inset-right, 0px)); }
