/* Bridge Builder 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 { --teal:#1f8a70; --teal-d:#126650; --sun:#ffc83d; --ink:#1f2b3a; --cream:#fff7e6; --red:#e5484d; --card:rgba(255,248,232,.97);
  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(#9fd8ff 0%, #e9f6ff 100%); 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; }
.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 #app { position: absolute; inset: 0; touch-action: none; }
#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 #ui .panel, #stage #ui input { pointer-events: auto; }
#stage button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
#stage button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
#stage [hidden] { display: none !important; }

#stage #loader { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: linear-gradient(#1f8a70 0%, #74c9b0 60%, #e6f7f0 100%); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-shadow: 0 3px 0 rgba(10,60,45,.45); text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 30px); letter-spacing: 2px; }
#stage .load-in span { font-size: 14px; }
#stage .spinner { width: 42px; height: 42px; border-radius: 50%; border: 6px solid rgba(255,255,255,.35); border-top-color: var(--sun); animation: bbspin .8s linear infinite; }
@keyframes bbspin { 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; }

/* HUD */
#stage .hud { position: absolute; inset: 0; pointer-events: none; padding: max(8px, env(safe-area-inset-top)) 8px 8px; display: flex; flex-direction: column; }
#stage .hud-top { display: flex; gap: 6px; align-items: stretch; }
#stage .ibtn { min-width: 44px; min-height: 44px; border: 0; border-radius: 12px; background: rgba(20,40,60,.78); color: #fff; font-weight: 800; font-size: 13px; padding: 0 10px; box-shadow: 0 2px 0 rgba(0,0,0,.3); }
#stage .ibtn.sq { width: 44px; padding: 0; font-size: 18px; }
#stage .meter { flex: 1; min-width: 0; background: rgba(20,40,60,.78); border-radius: 12px; padding: 6px 9px 5px; color: #fff; }
#stage .meter-bar { position: relative; height: 12px; border-radius: 6px; background: rgba(255,255,255,.22); overflow: visible; }
#stage .meter-bar i { display: block; height: 100%; width: 0; border-radius: 6px; background: #ffd23f; transition: width .12s; }
#stage .meter-bar i.s3 { background: #4ad77a; } #stage .meter-bar i.s2 { background: #b6e04a; } #stage .meter-bar i.s1 { background: #ffd23f; } #stage .meter-bar i.over { background: var(--red); }
#stage .meter-bar .mk { position: absolute; top: -3px; bottom: -3px; width: 3px; margin-left: -1px; background: #fff; border-radius: 2px; opacity: .9; }
#stage .meter-txt { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; margin-top: 4px; font-weight: 700; }
#stage .meter-txt span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }
#stage .bolts { min-width: 54px; background: rgba(20,40,60,.78); border-radius: 12px; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px 8px; }
#stage .bolts small { font-size: 9px; letter-spacing: 1px; opacity: .8; } #stage .bolts b { font-size: 15px; color: var(--sun); }
#stage .hint { align-self: center; margin-top: 8px; max-width: 92%; background: rgba(255,248,232,.95); border-radius: 12px; padding: 8px 12px; font-size: 13px; font-weight: 700; text-align: center; box-shadow: 0 3px 0 rgba(0,0,0,.2); }
#stage .msg { align-self: center; margin-top: 6px; max-width: 90%; background: rgba(229,72,77,.94); color: #fff; border-radius: 10px; padding: 5px 11px; font-size: 12px; font-weight: 700; opacity: 0; transition: opacity .15s; text-align: center; }
#stage .msg.on { opacity: 1; }
#stage .hud-zoom { position: absolute; right: 8px; top: 84px; display: flex; flex-direction: column; gap: 6px; }
#stage .legend { position: absolute; left: 8px; top: 84px; display: flex; align-items: center; gap: 5px; font-size: 10px; font-weight: 800; color: #fff; background: rgba(20,40,60,.7); border-radius: 10px; padding: 4px 8px; }
#stage .legend i { width: 56px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #40cc73, #f2d940, #f24033); }
#stage .hud-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
#stage .mats { pointer-events: auto; display: flex; gap: 6px; overflow-x: auto; touch-action: pan-x; padding-bottom: 2px; }
#stage .mat { flex: 1 0 auto; min-width: 64px; min-height: 48px; border: 3px solid transparent; border-radius: 12px; background: rgba(255,248,232,.95); color: var(--ink); display: grid; grid-template-columns: 14px 1fr; grid-template-rows: auto auto; column-gap: 6px; align-items: center; padding: 3px 8px; text-align: left; }
#stage .mat i { grid-row: 1 / 3; width: 14px; height: 30px; border-radius: 4px; }
#stage .mat b { font-size: 12px; } #stage .mat small { font-size: 10px; opacity: .7; }
#stage .mat { touch-action: pan-x; }
#stage .mat.on { border-color: var(--teal); background: #fff; box-shadow: 0 0 0 2px #fff; }
#stage .acts { display: flex; gap: 6px; }
#stage .act { flex: 1; min-height: 48px; border: 0; border-radius: 12px; background: rgba(20,40,60,.82); color: #fff; font-weight: 800; font-size: 14px; box-shadow: 0 3px 0 rgba(0,0,0,.3); }
#stage .act:disabled { opacity: .45; }
#stage .act.on { background: var(--red); }
#stage .act.test { flex: 1.5; background: var(--teal); font-size: 17px; letter-spacing: 1px; }

/* screens */
#stage .screens { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 10px; background: rgba(20,40,60,.35); overflow: hidden; }
#stage .panel { width: 100%; max-height: 100%; background: var(--card); border-radius: 20px; padding: 14px; display: flex; flex-direction: column; gap: 9px; box-shadow: 0 6px 0 rgba(10,30,40,.3); overscroll-behavior: contain; }
#stage .panel.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
#stage .panel h2 { font-size: 22px; color: var(--teal-d); letter-spacing: .5px; }
#stage .panel p { font-size: 14px; } #stage .muted { color: #55657a; font-size: 13px; }
#stage .logo { display: flex; flex-direction: column; line-height: 1; margin-bottom: 4px; }
#stage .logo b { font-size: clamp(32px, 11vw, 46px); color: var(--teal); letter-spacing: 1px; text-shadow: 0 3px 0 rgba(10,60,45,.2); }
#stage .logo b + b { color: #e8832a; }
#stage .logo span { font-size: 13px; letter-spacing: 2px; color: #55657a; font-weight: 700; margin-top: 6px; }
#stage .b { min-height: 48px; border: 0; border-radius: 13px; background: #dfe9ee; color: var(--ink); font-weight: 800; font-size: 15px; padding: 0 14px; box-shadow: 0 3px 0 rgba(0,0,0,.18); flex: 1; }
#stage .b.primary { background: var(--teal); color: #fff; } #stage .b.big { min-height: 56px; font-size: 17px; }
#stage .b.dim { opacity: .55; } #stage .b.small { min-height: 44px; flex: 0 0 auto; padding: 0 12px; font-size: 13px; }
#stage .b.danger { background: var(--red); color: #fff; }
#stage .row2 { display: flex; gap: 8px; }
#stage .foot { text-align: center; color: #55657a; font-size: 12px; }
#stage .sc-head { display: flex; align-items: center; gap: 10px; } #stage .sc-head h2 { margin: 0; }
#stage .world { font-size: 14px; color: var(--teal-d); margin: 6px 0 2px; }
#stage .grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
#stage .card { min-height: 64px; border: 0; border-radius: 12px; background: #fff; box-shadow: 0 3px 0 rgba(0,0,0,.15); padding: 6px 10px; text-align: left; display: grid; gap: 1px; color: var(--ink); }
#stage .card i { font-style: normal; font-size: 11px; opacity: .6; } #stage .card b { font-size: 13px; }
#stage .card.lock { opacity: .5; } #stage .st { color: #c9c9c9; font-size: 16px; } #stage .st.on { color: #ffb400; }
#stage .bigstars { font-size: 38px; text-align: center; letter-spacing: 6px; }
#stage .bigstars .st { font-size: 42px; }
#stage .results p, #stage .pause p { text-align: center; } #stage .reward { color: var(--teal-d); font-weight: 800; } #stage .goal { font-weight: 700; }
#stage .results h2, #stage .pause h2 { text-align: center; }
#stage .ach { font-size: 13px; color: #8a5a00; font-weight: 700; }
#stage .facts { list-style: none; display: flex; gap: 6px; flex-wrap: wrap; } #stage .facts li { background: #fff; border-radius: 10px; padding: 5px 9px; font-size: 12px; } #stage .facts b { color: var(--teal-d); }
#stage .bolts-line { font-weight: 800; color: #8a5a00; }
#stage .shop { background: #fff; border-radius: 14px; padding: 10px; display: grid; gap: 7px; font-size: 13px; }
#stage .tiers { display: flex; gap: 6px; } #stage .tiers i { width: 30px; height: 30px; border-radius: 50%; background: #dfe9ee; display: grid; place-items: center; font-style: normal; font-weight: 800; } #stage .tiers i.on { background: var(--teal); color: #fff; }
#stage .paints { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
#stage .paint { min-height: 52px; border: 3px solid transparent; border-radius: 12px; background: #eef3f5; padding: 4px 8px; text-align: left; font-weight: 800; font-size: 13px; display: grid; grid-template-columns: 18px 1fr; gap: 0 8px; align-items: center; color: var(--ink); }
#stage .paint i { grid-row: 1 / 3; width: 18px; height: 30px; border-radius: 5px; } #stage .paint small { font-weight: 600; opacity: .7; } #stage .paint.sel { border-color: var(--teal); }
#stage .awards { list-style: none; display: grid; gap: 6px; }
#stage .awards li { background: #fff; border-radius: 12px; padding: 7px 10px; display: grid; gap: 1px; font-size: 12px; opacity: .65; }
#stage .awards li.got { opacity: 1; border-left: 5px solid var(--teal); } #stage .awards b { font-size: 14px; } #stage .awards em { color: #8a5a00; font-style: normal; font-weight: 800; }
#stage .tog { min-height: 48px; border: 0; border-radius: 12px; background: #fff; display: flex; justify-content: space-between; align-items: center; padding: 0 14px; font-weight: 800; font-size: 14px; color: var(--ink); box-shadow: 0 2px 0 rgba(0,0,0,.12); }
#stage .tog i { font-style: normal; background: #dfe9ee; border-radius: 10px; padding: 3px 12px; font-size: 13px; } #stage .tog.on i { background: var(--teal); color: #fff; }
#stage .seg { display: grid; gap: 6px; font-size: 13px; font-weight: 800; } #stage .seg > div { display: flex; gap: 6px; flex-wrap: wrap; }
#stage .seg button { flex: 1; min-height: 46px; border: 0; border-radius: 11px; background: #dfe9ee; font-weight: 800; padding: 0 8px; color: var(--ink); } #stage .seg button.on { background: var(--teal); color: #fff; }
#stage .rng { display: grid; gap: 4px; font-weight: 800; font-size: 13px; } #stage .rng input { width: 100%; min-height: 44px; touch-action: pan-y; accent-color: var(--teal); }
#stage .toast { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); max-width: 88%; background: rgba(20,40,60,.92); color: #fff; padding: 8px 14px; border-radius: 12px; font-size: 13px; font-weight: 700; text-align: center; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; }
#stage .toast.on { opacity: 1; }
#stage .flash { position: absolute; inset: 0; pointer-events: none; z-index: 25; background: rgba(255,90,70,.22); animation: bbflash .4s ease-out forwards; }
@keyframes bbflash { from { opacity: 1; } to { opacity: 0; } }

.bb-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.bb-bar .btn { min-height: 44px; min-width: 44px; }
.bb-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.bb-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.bb-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.bb-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.bb-guide p { margin-bottom: .5rem; font-size: .95rem; }
@media (prefers-reduced-motion: reduce) { #stage .flash { animation: none; opacity: .3; } #stage .spinner { animation-duration: 2s; } }
#stage .costbar { position: relative; height: 10px; border-radius: 6px; background: rgba(30,41,59,.15); margin: 6px 0 4px; overflow: hidden; }
#stage .costbar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--teal-d, #1F8A70); border-radius: 6px; }
#stage .costbar b { position: absolute; top: 0; bottom: 0; width: 3px; background: #f5b301; }
#stage .muted.small { font-size: 12px; }
#stage .results .bigstars .st.on { animation: bbpop .5s ease-out both; }
#stage .results .bigstars .st.on:nth-child(2) { animation-delay: .15s; } #stage .results .bigstars .st.on:nth-child(3) { animation-delay: .3s; }
@keyframes bbpop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.25); opacity: 1; } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { #stage .results .bigstars .st.on { animation: none; } }
/* ---- full screen (shell immersive on iPhone, native on Android): the stage fills the whole area below the dock ---- */
html.pip-immersive .game-wrap, html.pip-native .game-wrap { display: flex; flex-direction: column; }
html.pip-immersive .game-wrap > .bb-bar, html.pip-immersive .game-wrap > .bb-keys, html.pip-immersive .game-wrap > .ad-well,
html.pip-native .game-wrap > .bb-bar, html.pip-native .game-wrap > .bb-keys, html.pip-native .game-wrap > .ad-well,
html.pip-immersive #bigbtn, html.pip-native #bigbtn { display: none !important; }
html.pip-immersive #stage, html.pip-native #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 #stage, html.pip-native .game-wrap #stage { width: 100%; max-width: none; }
html.pip-immersive #stage #ui, html.pip-native #stage #ui { padding-bottom: env(safe-area-inset-bottom, 0px); }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .toast, html.pip-native #stage .toast { bottom: 80px; }
}
/* soft vignette over the 3D view (static, no per-frame cost) */
#stage #app::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, rgba(255,255,255,0) 60%, rgba(20,50,70,.16) 100%); }
