/* Sky Pirates 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 { --navy:#14305c; --sky:#2b7bd8; --gold:#ffc83a; --cream:#fff6df; --ink:#23304f; --red:#ff5a4a; --green:#4fe27a;
  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(#3b78d8 0%, #7db8f2 55%, #fff1d2 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: 100%; height: calc(100vh - 64px); height: calc(100svh - 64px); max-height: calc(100svh - 64px); aspect-ratio: auto; }
#stage *, #stage *::before, #stage *::after { box-sizing: border-box; }
#stage #app { position: absolute; inset: 0; }
#stage #app canvas { display: block; width: 100%; height: 100%; }
#stage #ui { position: absolute; inset: 0; pointer-events: none; }
#stage #ui button, #stage #ui .panel, #stage #ui input, #stage #ui .stick-zone { 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 #loader { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: linear-gradient(#3b78d8 0%, #7db8f2 55%, #fff1d2 100%); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-shadow: 0 3px 0 rgba(20,40,110,.45); text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 32px); letter-spacing: 3px; }
#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(--gold); animation: spspin .8s linear infinite; }
@keyframes spspin { to { transform: rotate(360deg); } }
#stage #ctxlost { position: absolute; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; background: rgba(20,32,70,.88); color: #fff; font-weight: 700; }
#stage [hidden] { display: none !important; }

/* ---- HUD */
#stage .hud { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
#stage .hud-top { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; gap: 8px; padding: 8px; padding-top: max(8px, env(safe-area-inset-top)); z-index: 4; }
#stage .iconbtn { width: 46px; height: 46px; flex: none; border-radius: 12px; border: 2px solid rgba(255,255,255,.8); background: rgba(20,48,92,.7); color: #fff; font-weight: 800; font-size: 16px; letter-spacing: 1px; }
#stage .hud-mid { flex: 1; min-width: 0; padding-top: 4px; }
#stage .hullbar { position: relative; height: 20px; border-radius: 10px; background: rgba(10,25,50,.65); border: 2px solid rgba(255,255,255,.75); overflow: hidden; }
#stage .hullbar i { display: block; height: 100%; width: 100%; background: linear-gradient(#7dff9a, #2fbf5a); transition: width .15s; }
#stage .hullbar i.mid { background: linear-gradient(#ffe27a, #e8a020); }
#stage .hullbar i.low { background: linear-gradient(#ff8a7a, #d02a1a); }
#stage .hulltxt { position: absolute; inset: 0; text-align: center; font-size: 12px; font-weight: 800; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.8); line-height: 16px; }
#stage .obj { margin-top: 5px; font-size: 13px; font-weight: 800; color: #fff; text-shadow: 0 2px 3px rgba(0,30,80,.8); }
#stage #radar { width: 78px; height: 78px; flex: none; }
#stage .lootline { position: absolute; left: 12px; top: 92px; z-index: 3; font-size: 12px; font-weight: 800; color: #fff; text-shadow: 0 2px 3px rgba(0,30,80,.8); white-space: pre; }
#stage .hint { position: absolute; left: 50%; top: 120px; transform: translateX(-50%); width: min(88%, 320px); text-align: center; padding: 10px 14px; border-radius: 14px; background: rgba(255,246,223,.95); color: var(--ink); font-weight: 700; font-size: 14px; box-shadow: 0 4px 0 rgba(20,48,92,.35); z-index: 4; }
#stage .warn { position: absolute; left: 50%; top: 44%; transform: translateX(-50%); padding: 6px 14px; border-radius: 12px; background: rgba(208,42,26,.9); color: #fff; font-weight: 800; font-size: 14px; z-index: 4; white-space: nowrap; }
#stage .banner { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: clamp(22px, 7vw, 34px); font-weight: 900; color: #fff; text-shadow: 0 3px 0 rgba(20,48,92,.8), 0 0 14px rgba(0,0,0,.35); z-index: 4; padding: 0 12px; }
#stage .flash { position: absolute; inset: 0; z-index: 3; box-shadow: inset 0 0 70px 18px rgba(255,40,20,.55); opacity: 0; }
#stage .flash.go { animation: spflash .4s ease-out; }
@keyframes spflash { 0% { opacity: 1; } 100% { opacity: 0; } }

#stage .stick-zone { position: absolute; left: 0; top: 22%; bottom: 0; width: 56%; z-index: 1; touch-action: none; }
#stage .hud.lefty .stick-zone { left: auto; right: 0; }
#stage .stick-base, #stage .stick-knob { position: absolute; left: 0; top: 0; display: none; border-radius: 50%; pointer-events: none; }
#stage .stick-base { width: 120px; height: 120px; border: 3px solid rgba(255,255,255,.55); background: rgba(255,255,255,.14); }
#stage .stick-knob { width: 48px; height: 48px; background: rgba(255,255,255,.8); box-shadow: 0 3px 0 rgba(20,48,92,.4); }
#stage .btnpad { position: absolute; right: 10px; bottom: max(12px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: auto auto; gap: 8px; z-index: 3; align-items: end; justify-items: end; }
#stage .hud.lefty .btnpad { right: auto; left: 10px; direction: rtl; }
#stage .hud.lefty .btnpad .act { direction: ltr; }
#stage .act { position: relative; border-radius: 50%; border: 3px solid rgba(255,255,255,.9); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; overflow: hidden; box-shadow: 0 4px 0 rgba(10,25,60,.45); text-shadow: 0 1px 2px rgba(0,0,0,.6);
  background-color: #d4402a; background-image: linear-gradient(to top, rgba(0,0,0,.5) calc(var(--cd, 0) * 100%), transparent 0); }
#stage .act b { font-size: 15px; letter-spacing: .5px; }
#stage .act small { font-size: 10px; opacity: .9; }
#stage .act.fire { width: 84px; height: 84px; }
#stage .act.hook { width: 62px; height: 62px; background-color: #2a8fd0; }
#stage .act.slow { width: 62px; height: 62px; background-color: #6a5ac8; }
#stage .act.ready { border-color: var(--green); box-shadow: 0 0 0 4px rgba(79,226,122,.55), 0 4px 0 rgba(10,25,60,.45); }
#stage .act.down { transform: translateY(3px) scale(.96); }

/* ---- screens */
#stage .screen { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 10px; background: rgba(12,36,76,.38); pointer-events: auto; }
#stage .panel { width: 100%; max-width: 400px; max-height: 100%; display: flex; flex-direction: column; background: var(--cream); border-radius: 18px; border: 3px solid #fff; box-shadow: 0 6px 0 rgba(20,48,92,.45); overflow: hidden; }
#stage .panel.small { padding: 18px; gap: 10px; align-items: stretch; width: min(100%, 300px); }
#stage .panel.small h2 { text-align: center; margin-bottom: 4px; }
#stage .phead { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; background: var(--navy); color: #fff; }
#stage .phead h2 { font-size: 18px; letter-spacing: .5px; }
#stage .back { min-width: 64px; min-height: 44px; background: none; border: 0; color: #fff; font-weight: 800; font-size: 14px; text-align: left; }
#stage .back.ghost { visibility: hidden; }
#stage .pscroll { padding: 12px; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
#stage .btn { display: block; width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px; border: 0; background: #e6edf8; color: var(--ink); font-weight: 800; font-size: 15px; box-shadow: 0 3px 0 rgba(20,48,92,.3); text-align: center; text-decoration: none; }
#stage .btn.primary { background: linear-gradient(#ffd75a, #f5a623); color: #3a2200; }
#stage .btn.big { min-height: 54px; font-size: 17px; }
#stage .btn.danger { background: #ffd9d4; color: #8a1a10; }
#stage .btn.off, #stage .btn.locked { opacity: .55; }
#stage .row2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
#stage .menu { width: 100%; max-width: 400px; max-height: 100%; overflow-y: auto; touch-action: pan-y; padding: 6px 12px 12px; display: flex; flex-direction: column; gap: 10px; }
#stage .logo { text-align: center; color: #fff; text-shadow: 0 3px 0 rgba(20,48,92,.85), 0 0 18px rgba(0,0,0,.3); margin-top: 6px; }
#stage .logo small { display: block; font-size: 11px; letter-spacing: 3px; font-weight: 800; }
#stage .logo h1 { font-size: clamp(30px, 10vw, 44px); letter-spacing: 3px; line-height: 1; }
#stage .logo .tag { display: inline-block; margin-top: 2px; padding: 0 10px; border-radius: 8px; background: var(--gold); color: #3a2200; font-weight: 900; text-shadow: none; }
#stage .menubtns { display: flex; flex-direction: column; gap: 8px; }
#stage .modebtn { text-align: left; display: flex; flex-direction: column; gap: 2px; }
#stage .modebtn small { font-size: 12px; font-weight: 600; opacity: .85; }
#stage .strip { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
#stage .chip { padding: 4px 10px; border-radius: 999px; background: rgba(20,48,92,.82); color: #fff; font-weight: 800; font-size: 12px; }
#stage .chip.gold { color: var(--gold); } #stage .chip.parts { color: #8fd0ff; }
#stage .panel .chip { background: var(--navy); }
#stage .xpbar { height: 8px; border-radius: 4px; background: rgba(255,255,255,.5); overflow: hidden; }
#stage .xpbar i { display: block; height: 100%; background: var(--gold); }
#stage .fine { font-size: 12px; color: #4a5a78; text-align: center; }
#stage .menu .fine { color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
#stage .brief { font-size: 15px; font-weight: 600; }
#stage .rows { display: flex; flex-direction: column; gap: 4px; }
#stage .rowkv { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 6px 8px; background: rgba(20,48,92,.07); border-radius: 8px; }
#stage .rowkv b { text-align: right; }
#stage .region h3 { font-size: 13px; letter-spacing: 1px; color: var(--navy); margin: 4px 0; text-transform: uppercase; }
#stage .stagecard { width: 100%; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 10px; margin-bottom: 6px; background: #fff; border: 2px solid #d6dff0; border-radius: 12px; text-align: left; color: var(--ink); }
#stage .stagecard.boss { border-color: #e8a020; }
#stage .stagecard.locked { opacity: .55; }
#stage .stagecard .num { width: 30px; height: 30px; border-radius: 50%; background: var(--navy); color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; flex: none; }
#stage .stagecard .nm { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#stage .stagecard small { font-size: 12px; color: #5a6a88; }
#stage .stagecard .stars { color: #e8a020; font-size: 16px; letter-spacing: 1px; }
#stage .tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
#stage .tab { min-height: 44px; border-radius: 10px; border: 2px solid #c8d4ea; background: #fff; font-weight: 800; color: var(--ink); }
#stage .tab.on { background: var(--navy); color: #fff; border-color: var(--navy); }
#stage .sum { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; font-weight: 700; color: #3a4a68; justify-content: center; }
#stage .card { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #fff; border: 2px solid #d6dff0; border-radius: 12px; }
#stage .card.sel { border-color: var(--green); }
#stage .cinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
#stage .cinfo small { font-size: 12px; color: #5a6a88; }
#stage .pips { font-size: 13px; color: #e8a020; letter-spacing: 2px; }
#stage .buy { width: auto; min-width: 96px; font-size: 13px; padding: 8px 10px; flex: none; }
#stage .maxed { font-weight: 900; color: #2a8a4a; padding: 0 10px; }
#stage .setrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; font-weight: 700; font-size: 14px; }
#stage .setrow input[type=range] { flex: 1; max-width: 190px; min-height: 44px; touch-action: pan-x; }
#stage .setrow .btn { width: auto; min-width: 90px; }
#stage .seg { display: flex; gap: 4px; }
#stage .segbtn { min-width: 56px; min-height: 44px; padding: 0 8px; border-radius: 10px; border: 2px solid #c8d4ea; background: #fff; font-weight: 800; font-size: 13px; color: var(--ink); }
#stage .segbtn.on { background: var(--navy); color: #fff; border-color: var(--navy); }
#stage .results { max-width: 400px; }
#stage .results h2 { text-align: center; padding: 12px; font-size: 26px; background: var(--navy); color: #fff; }
#stage .results h2.win { color: var(--gold); } #stage .results h2.lose { color: #ff9a8a; }
#stage .bigstars { text-align: center; font-size: 34px; color: #e8a020; letter-spacing: 6px; padding-top: 6px; }
#stage .goal { font-size: 14px; font-weight: 700; text-align: center; }
#stage .banner2 { font-size: 13px; font-weight: 800; text-align: center; background: #fff3c4; border-radius: 10px; padding: 6px; }
#stage .toast { position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%); max-width: 88%; padding: 10px 16px; border-radius: 12px; background: rgba(20,48,92,.95); color: #fff; font-weight: 700; font-size: 14px; z-index: 30; text-align: center; pointer-events: none; }

.sp-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.sp-bar .btn { min-height: 44px; min-width: 44px; }
.sp-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.sp-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.sp-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.sp-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.sp-guide p { margin-bottom: .5rem; font-size: .95rem; }
@media (max-height: 520px) { #stage .act.fire { width: 70px; height: 70px; } #stage .act.hook, #stage .act.slow { width: 52px; height: 52px; } #stage .hint { top: 90px; } }
@media (prefers-reduced-motion: reduce) { #stage .flash.go { animation: none; opacity: .5; } }

/* target pointer, kill chain, low hull edge */
#stage .compass { position: absolute; left: 50%; top: 74px; transform: translateX(-50%); z-index: 3; display: flex; align-items: center; gap: 6px; padding: 3px 10px 3px 6px; border-radius: 16px; background: rgba(10,25,50,.5); color: #fff; font-size: 12px; font-weight: 800; pointer-events: none; }
#stage .compass[hidden] { display: none; }
#stage .comp-arrow { width: 22px; height: 22px; display: block; position: relative; }
#stage .comp-arrow::before { content: ""; position: absolute; left: 3px; top: 1px; border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 18px solid #ff6a4a; }
#stage .chaintxt { position: absolute; right: 12px; top: 112px; z-index: 3; font-size: 20px; font-weight: 900; color: #ffd24a; text-shadow: 0 2px 0 rgba(20,48,92,.85); pointer-events: none; }
#stage .chaintxt[hidden] { display: none; }
#stage .chaintxt.pop { animation: spchain .3s ease-out; }
@keyframes spchain { 0% { transform: scale(1.6); } 100% { transform: scale(1); } }
#stage .lowvig { position: absolute; inset: 0; z-index: 2; pointer-events: none; box-shadow: inset 0 0 90px 14px rgba(255,40,20,.4); animation: splow 1.1s ease-in-out infinite alternate; }
#stage .lowvig[hidden] { display: none; }
@keyframes splow { 0% { opacity: .35; } 100% { opacity: 1; } }
#stage .rows .prevbest { font-size: 12px; opacity: .8; }
@media (prefers-reduced-motion: reduce) { #stage .chaintxt.pop, #stage .lowvig { animation: none; } }

/* Full screen on phones: the shell makes .game-wrap the fixed stage; fill it with the game and drop the page chrome. */
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 0; min-height: 0; width: 100%; height: auto; max-height: none; max-width: none; aspect-ratio: auto; border-radius: 0; }
html.pip-immersive .sp-bar, html.pip-immersive .sp-keys, html.pip-immersive .game-header, html.pip-immersive .ad-well { display: none; }
html.pip-immersive #stage .btnpad { right: max(10px, env(safe-area-inset-right)); }
html.pip-immersive #stage .hud-top { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
@media (orientation: landscape) and (max-height: 520px) { html.pip-immersive #stage .btnpad { bottom: max(8px, env(safe-area-inset-bottom)); } }
