/* Beam Bender 3D - stage and in-game UI. Everything is scoped under #stage so site styles never leak in. */
html.lm-big, html.lm-big body { overflow: hidden; }
#stage { --ink:#e9f1ff; --panel:#16203a; --panel2:#22305a; --accent:#6fd3ff; --gold:#ffd24a; --red:#ff5a6a;
  position: relative; width: min(100%, calc(78vh * 0.5625)); width: min(100%, calc(78svh * 0.5625)); aspect-ratio: 9 / 16; min-height: 320px; margin: 0 auto; overflow: hidden;
  border-radius: 14px; background: #1c2740; 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; }
html.pip-immersive .game-wrap.pip-stage #stage { width: 100%; max-width: none; height: 100%; aspect-ratio: auto; border-radius: 0; }
#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 #ui .panel, #stage #ui .tip, #stage #ui .screen { pointer-events: auto; }
#stage button { font-family: inherit; cursor: pointer; touch-action: manipulation; color: inherit; }
#stage button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

#stage #loader { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: #1c2740; }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 30px); letter-spacing: 2px; color: var(--accent); }
#stage .spinner { width: 40px; height: 40px; border-radius: 50%; border: 5px solid rgba(255,255,255,.2); border-top-color: var(--accent); animation: lmspin .8s linear infinite; }
@keyframes lmspin { 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(12,18,40,.9); font-weight: 700; }

/* HUD */
#stage .hud { position: absolute; inset: 0; pointer-events: none; }
#stage .hud-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 6px; padding: 8px; background: linear-gradient(rgba(10,16,34,.82), rgba(10,16,34,0)); }
#stage .hud-title { flex: 1; min-width: 0; display: flex; flex-direction: column; text-align: center; }
#stage .hud-name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#stage .hud-sub { font-size: 12px; opacity: .8; }
#stage .hud-btn { min-width: 52px; min-height: 44px; padding: 0 8px; border-radius: 12px; border: 2px solid rgba(255,255,255,.25); background: var(--panel2); font-weight: 700; font-size: 13px; }
#stage .hud-btn.hint { border-color: var(--gold); color: var(--gold); }
#stage .hud-btn:disabled { opacity: .4; }
#stage .hud-status { position: absolute; top: 58px; left: 0; right: 0; text-align: center; font-size: 13px; font-weight: 700; text-shadow: 0 2px 0 rgba(0,0,0,.5); white-space: pre; }
#stage .tip { position: absolute; left: 12px; right: 12px; bottom: 148px; padding: 10px 12px; border-radius: 12px; background: rgba(255,248,220,.97); color: #2a2a3a; font-weight: 700; font-size: 14px; text-align: center; box-shadow: 0 4px 14px rgba(0,0,0,.4); }
#stage .tray { position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 8px 8px 10px; background: linear-gradient(rgba(10,16,34,0), rgba(10,16,34,.88) 30%); pointer-events: auto; }
#stage .tool { position: relative; min-width: 56px; min-height: 56px; padding: 4px 8px; border-radius: 14px; border: 2px solid rgba(255,255,255,.22); background: var(--panel); font-size: 12px; font-weight: 700; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
#stage .tool.small { min-width: 48px; }
#stage .tool.on { border-color: var(--accent); background: #243a6e; box-shadow: 0 0 0 2px rgba(111,211,255,.35); }
#stage .tool.empty { opacity: .4; }
#stage .tool .tcount { font-style: normal; font-size: 11px; opacity: .9; }
#stage .dot { width: 18px; height: 18px; border-radius: 4px; background: #d9f6ff; display: block; }
#stage .dot-mirror { transform: rotate(45deg) scaleX(.25) scaleY(1.1); border-radius: 2px; }
#stage .dot-splitter { background: #ffe08a; transform: rotate(45deg) scaleX(.4) scaleY(1.1); border-radius: 2px; }
#stage .dot-prism { background: #f1f5ff; clip-path: polygon(50% 5%, 95% 90%, 5% 90%); border-radius: 0; }
#stage .dot-fR { background: #ff4757; border-radius: 50%; } #stage .dot-fG { background: #2ed573; border-radius: 50%; } #stage .dot-fB { background: #3b82ff; border-radius: 50%; }
#stage .toast { position: absolute; left: 50%; top: 112px; transform: translateX(-50%); max-width: 86%; padding: 8px 14px; border-radius: 999px; background: rgba(0,0,0,.78); font-size: 13px; font-weight: 700; text-align: center; pointer-events: none; }
#stage .fade { position: absolute; inset: 0; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 30; }

/* screens and panels */
#stage .screen { position: absolute; inset: 0; z-index: 20; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: 14px 12px; background: rgba(10,16,34,.74); }
#stage .panel { width: 100%; max-width: 380px; margin: auto; padding: 16px 14px; border-radius: 18px; background: rgba(22,32,58,.97); border: 2px solid rgba(255,255,255,.14); display: flex; flex-direction: column; gap: 10px; }
#stage .panel h1, #stage .panel h2 { text-align: center; margin: 0; }
#stage .logo { font-size: clamp(26px, 8vw, 36px); color: var(--accent); letter-spacing: 1px; }
#stage .sub, #stage .line { margin: 0; text-align: center; font-size: 14px; opacity: .92; }
#stage .goal { color: var(--gold); font-weight: 700; }
#stage .gain { font-weight: 800; font-size: 17px; color: var(--gold); }
#stage .trophy { color: #9dffb0; }
#stage .chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
#stage .chip { padding: 4px 10px; border-radius: 999px; background: #0d1530; font-size: 12px; font-weight: 700; }
#stage .row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
#stage .row > .lm-btn { flex: 1 1 70px; }
#stage .lm-btn { min-height: 46px; min-width: 46px; padding: 8px 12px; border-radius: 12px; border: 2px solid rgba(255,255,255,.22); background: var(--panel2); font-size: 15px; font-weight: 700; }
#stage .lm-btn.big { min-height: 52px; font-size: 16px; }
#stage .lm-btn.primary { background: #2f7bff; border-color: #8fc0ff; }
#stage .lm-btn.danger { background: #5a2030; border-color: #ff8a9a; }
#stage .lm-btn.back { background: transparent; }
#stage .lm-btn:disabled { opacity: .45; }
#stage .mhead { display: flex; flex-direction: column; gap: 6px; }
#stage .stars { display: flex; justify-content: center; gap: 6px; font-size: 38px; color: #6a7396; }
#stage .star.on { color: var(--gold); text-shadow: 0 0 12px rgba(255,210,74,.8); animation: lmpop .35s ease-out; }
@keyframes lmpop { 0% { transform: scale(.3); } 70% { transform: scale(1.3); } 100% { transform: scale(1); } }
#stage .world { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; text-align: left; padding: 10px 12px; min-height: 64px; border-radius: 14px; border: 2px solid rgba(255,255,255,.2); background: var(--panel2); }
#stage .world span { font-size: 12px; opacity: .85; grid-column: 1; } #stage .world em { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-style: normal; font-weight: 700; color: var(--gold); }
#stage .world.locked { opacity: .55; }
#stage .lgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
#stage .lvl { min-height: 62px; border-radius: 12px; border: 2px solid rgba(255,255,255,.22); background: var(--panel2); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; }
#stage .lvl b { font-size: 18px; } #stage .lvl.done { border-color: var(--gold); } #stage .lvl.locked { opacity: .45; }
#stage .theme { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px; min-height: 52px; padding: 8px 12px; border-radius: 12px; border: 2px solid rgba(255,255,255,.2); background: var(--panel2); text-align: left; }
#stage .theme.on { border-color: var(--accent); } #stage .swatch { width: 24px; height: 24px; border-radius: 50%; display: block; }
#stage .alist { display: flex; flex-direction: column; gap: 6px; }
#stage .ach { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 10px; background: #0d1530; opacity: .7; } #stage .ach span { font-size: 12px; } #stage .ach.done { opacity: 1; border-left: 4px solid var(--gold); }

#stage.is-big .panel { max-width: 460px; }
@media (orientation: landscape) and (max-height: 520px) { #stage .tray { padding-bottom: 4px; } #stage .tool { min-height: 48px; } #stage .tip { bottom: 84px; } }
@media (prefers-reduced-motion: reduce) { #stage .star.on, #stage .spinner { animation: none; } }

.lm-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.lm-bar .btn { min-height: 44px; min-width: 44px; }
.lm-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
html.pip-immersive .lm-keys { display: none; }
.lm-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.lm-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.lm-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.lm-guide p { margin-bottom: .5rem; font-size: .95rem; }

/* status pips, star forecast, hint nudge, safe areas */
#stage .hud-status { display: flex; align-items: center; justify-content: center; gap: 12px; white-space: normal; }
#stage .pips { display: inline-flex; gap: 5px; align-items: center; }
#stage .pip { width: 13px; height: 13px; border-radius: 50%; border: 2px solid rgba(255,255,255,.55); background: rgba(10,16,34,.6); display: block; }
#stage .pip.on { background: #ffe08a; border-color: #fff4c2; box-shadow: 0 0 10px rgba(255,224,138,.9); }
#stage .pip.pop { animation: lmpop .4s ease-out; }
#stage .pcount { padding: 2px 9px; border-radius: 999px; background: rgba(10,16,34,.65); white-space: nowrap; }
#stage .pcount.s3 { color: #ffd24a; } #stage .pcount.s2 { color: #e8eefc; } #stage .pcount.s1 { color: #ff9aa8; }
#stage .pcount.bump { animation: lmbump .22s ease-out; }
@keyframes lmbump { 0% { transform: scale(1.18); } 100% { transform: scale(1); } }
#stage .hud-btn.nudge { animation: lmnudge 1.1s ease-in-out infinite; background: #4a3a10; }
@keyframes lmnudge { 0%,100% { box-shadow: 0 0 0 0 rgba(255,210,74,.7); } 50% { box-shadow: 0 0 0 8px rgba(255,210,74,0); } }
#stage .line.best { color: var(--gold); font-weight: 800; }
#stage .line.tipline { opacity: .85; font-size: 13px; }
#stage .hud-top { padding-top: max(8px, env(safe-area-inset-top, 0px)); padding-left: max(8px, env(safe-area-inset-left, 0px)); padding-right: max(8px, env(safe-area-inset-right, 0px)); }
#stage .tray { padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)); }
@media (prefers-reduced-motion: reduce) { #stage .pip.pop, #stage .pcount.bump, #stage .hud-btn.nudge { animation: none; } }

/* Full screen pass 3: stage fills the area below the dock, native and immersive; duplicate Play big hidden. */
html.pip-immersive .lm-bar, html.pip-native .lm-bar, .game-wrap:fullscreen .lm-bar { display: none; }
html.pip-native .lm-keys, .game-wrap:fullscreen .lm-keys { display: none; }
html.pip-immersive .game-wrap.pip-stage, html.pip-native .game-wrap.pip-stage, .game-wrap:fullscreen { display: flex; flex-direction: column; padding: 0; margin: 0; max-width: none; overflow: hidden; }
html.pip-immersive .game-wrap.pip-stage #stage, html.pip-native .game-wrap.pip-stage #stage, .game-wrap:fullscreen #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 .game-title, html.pip-native .game-wrap.pip-stage .game-title { display: none; }
#stage #app::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 55%, rgba(6,10,24,.38) 100%); }
