/* Powder Run 3D - stage + in-game UI. Everything is scoped under #stage so site styles never leak in. */
html.pip-big, html.pip-big body { overflow: hidden; }
#stage { --ice:#2b7fd8; --ice-d:#1a56a3; --sun:#ffc21a; --org:#ff7a3d; --green:#33c46a; --ink:#16284d; --cream:#f4f9ff;
  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(#2b7fd8 0%, #8fd0ff 60%, #eaf6ff 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; }
#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 select { 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(#2b7fd8 0%, #8fd0ff 60%, #eaf6ff 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: 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: sbspin .8s linear infinite; }
@keyframes sbspin { 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,70,.85); color: #fff; font-weight: 700; }
#stage #fade { position: absolute; inset: 0; z-index: 30; background: #fff; pointer-events: none; opacity: .0; }

/* HUD */
#stage .hud { position: absolute; inset: 0; padding: max(8px, env(safe-area-inset-top)) 10px 8px; pointer-events: none; }
#stage .hud-top { display: flex; gap: 6px; padding-right: 54px; }
#stage .stat { background: rgba(14,32,80,.6); color: #fff; border-radius: 12px; padding: 4px 10px; display: flex; align-items: baseline; gap: 5px; min-height: 32px; }
#stage .stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
#stage .stat .lbl { font-size: 10px; opacity: .8; letter-spacing: 1px; }
#stage .pausebtn { position: absolute; top: max(8px, env(safe-area-inset-top)); right: 8px; width: 44px; height: 44px; border-radius: 12px; border: 0; background: rgba(14,32,80,.7); color: #fff; font-size: 16px; font-weight: 800; }
#stage .chainchip { position: absolute; left: 10px; top: 52px; background: var(--sun); color: #4a3200; font-weight: 800; padding: 3px 10px; border-radius: 99px; font-size: 14px; }
#stage .meters { position: absolute; left: 10px; right: 10px; top: calc(max(8px, env(safe-area-inset-top)) + 42px); display: none; }
#stage .meter, #stage .prog { height: 7px; border-radius: 4px; background: rgba(14,32,80,.35); overflow: hidden; margin-top: 4px; }
#stage .meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ff9a3d, #ffd23a); }
#stage .prog i { display: block; height: 100%; width: 0; background: #fff; }
#stage .meters { display: block; top: auto; bottom: calc(max(8px, env(safe-area-inset-bottom)) + 160px); left: 10px; right: auto; width: 40%; }
#stage .hint-bubble { position: absolute; left: 50%; top: 30%; transform: translateX(-50%); max-width: 86%; background: rgba(255,255,255,.96); color: var(--ink); font-weight: 800; font-size: 15px; text-align: center; padding: 8px 14px; border-radius: 14px; animation: sbfloat 1s ease-in-out infinite alternate; }
@keyframes sbfloat { to { transform: translate(-50%, -6px); } }
#stage .count { position: absolute; left: 0; right: 0; top: 34%; text-align: center; font-size: 72px; font-weight: 900; color: #fff; text-shadow: 0 4px 0 rgba(14,32,80,.5); }
#stage .feed { position: absolute; left: 0; right: 0; top: 24%; display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; }
#stage .feed .f { background: rgba(255,255,255,.93); color: var(--ink); font-weight: 800; font-size: 14px; padding: 4px 12px; border-radius: 99px; animation: sbfeed 1.9s ease-out forwards; }
#stage .feed .f.good { background: var(--sun); color: #4a3200; }
#stage .feed .f.bad { background: #ff6b5a; color: #fff; }
@keyframes sbfeed { 0% { opacity: 0; transform: translateY(8px); } 12% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }
#stage .act { position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); width: 92px; height: 92px; border-radius: 50%; border: 0; color: #fff; font-weight: 900; font-size: 15px; letter-spacing: 1px; box-shadow: 0 5px 0 rgba(10,24,60,.5); touch-action: none; }
#stage .act:active, #stage .act.on { transform: translateY(3px); box-shadow: 0 2px 0 rgba(10,24,60,.5); }
#stage .act-jump { right: 12px; background: var(--org); }
#stage .act-grab { right: 112px; width: 76px; height: 76px; background: var(--ice); bottom: max(20px, env(safe-area-inset-bottom)); }
#stage.lefty .act-jump { right: auto; left: 12px; }
#stage.lefty .act-grab { right: auto; left: 112px; }
#stage.lefty .meters { left: auto; right: 10px; }
#stage.zones .act-jump { bottom: max(120px, calc(env(safe-area-inset-bottom) + 112px)); }

/* screens */
#stage #screen { position: absolute; inset: 0; pointer-events: none; }
#stage .screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom)); pointer-events: none; }
#stage .screen > * { pointer-events: auto; }
#stage .dim { background: rgba(10,24,60,.55); }
#stage .panel { background: var(--cream); border-radius: 18px; padding: 14px; box-shadow: 0 6px 0 rgba(10,24,60,.3); }
#stage .scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
#stage h2.ttl { font-size: 24px; font-weight: 900; color: #fff; text-shadow: 0 3px 0 rgba(14,32,80,.45); text-align: center; margin: 4px 0 8px; }
#stage .logo { font-size: clamp(34px, 11vw, 52px); font-weight: 900; color: #fff; text-align: center; text-shadow: 0 4px 0 rgba(14,32,80,.5); line-height: 1; margin-top: 8%; }
#stage .logo small { display: block; font-size: 14px; letter-spacing: 3px; margin-top: 6px; color: #dff1ff; }
#stage .bigbtn { display: block; width: 100%; min-height: 54px; border: 0; border-radius: 16px; background: var(--org); color: #fff; font-size: 22px; font-weight: 900; letter-spacing: 1px; box-shadow: 0 5px 0 #b34a17; margin: 6px 0; }
#stage .bigbtn:active { transform: translateY(3px); box-shadow: 0 2px 0 #b34a17; }
#stage .btn2 { min-height: 46px; padding: 8px 14px; border: 0; border-radius: 14px; background: var(--ice); color: #fff; font-size: 16px; font-weight: 800; box-shadow: 0 4px 0 var(--ice-d); }
#stage .btn2.alt { background: #fff; color: var(--ice-d); box-shadow: 0 4px 0 #b9cde8; }
#stage .btn2.green { background: var(--green); box-shadow: 0 4px 0 #1f8a49; }
#stage .btn2[disabled] { opacity: .5; }
#stage .row { display: flex; gap: 8px; }
#stage .row > * { flex: 1; }
#stage .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#stage .chip { display: inline-block; background: rgba(14,32,80,.6); color: #fff; border-radius: 99px; padding: 3px 10px; font-weight: 800; font-size: 13px; }
#stage .topbar { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
#stage .xpbar { height: 8px; background: rgba(255,255,255,.35); border-radius: 4px; overflow: hidden; margin: 4px 0; }
#stage .xpbar i { display: block; height: 100%; background: var(--sun); }
#stage .card { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 14px; padding: 8px 10px; margin-bottom: 8px; border: 2px solid #d5e6fb; text-align: left; width: 100%; color: var(--ink); min-height: 56px; }
#stage button.card:active { background: #eaf3ff; }
#stage .card.locked { opacity: .55; }
#stage .card .t { font-weight: 800; font-size: 15px; }
#stage .card .s { font-size: 12px; color: #4b6288; }
#stage .card .grow { flex: 1; }
#stage .medal { display: inline-block; width: 18px; height: 18px; border-radius: 50%; margin-left: 2px; background: #cfd9e8; vertical-align: middle; }
#stage .medal.m1 { background: #c98a4b; } #stage .medal.m2 { background: #c4ccd8; } #stage .medal.m3 { background: #ffc21a; }
#stage .tabs { display: flex; gap: 6px; margin-bottom: 8px; }
#stage .tab { flex: 1; min-height: 44px; border: 0; border-radius: 12px; background: rgba(255,255,255,.7); color: var(--ink); font-weight: 800; font-size: 13px; }
#stage .tab.on { background: var(--ink); color: #fff; }
#stage .bar { height: 8px; border-radius: 4px; background: #d5e6fb; overflow: hidden; }
#stage .bar i { display: block; height: 100%; background: var(--ice); }
#stage .stats4 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; font-size: 10px; margin-top: 4px; }
#stage .res-big { font-size: 40px; font-weight: 900; text-align: center; line-height: 1; margin: 6px 0; }
#stage .res-medal { width: 64px; height: 64px; border-radius: 50%; margin: 4px auto; display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: 900; color: #fff; background: #cfd9e8; box-shadow: inset 0 -5px 0 rgba(0,0,0,.18); }
#stage .res-medal.m1 { background: #c98a4b; } #stage .res-medal.m2 { background: #aeb8c8; } #stage .res-medal.m3 { background: #ffc21a; color: #4a3200; }
#stage .kv { display: flex; justify-content: space-between; font-size: 14px; padding: 2px 0; }
#stage .goal { background: #fff3d6; border-radius: 12px; padding: 8px 10px; font-weight: 700; font-size: 14px; margin: 8px 0; }
#stage .note { font-size: 12px; color: #4b6288; margin: 4px 0; }
#stage label.opt { display: flex; justify-content: space-between; align-items: center; min-height: 48px; font-weight: 800; border-bottom: 1px solid #d5e6fb; gap: 8px; }
#stage select { min-height: 44px; font-size: 16px; border-radius: 10px; border: 2px solid #b9cde8; padding: 0 8px; background: #fff; color: var(--ink); }
#stage .toggle { min-width: 84px; }

.sb-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.sb-bar .btn { min-height: 44px; min-width: 44px; }
.sb-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.sb-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.sb-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.sb-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.sb-guide p { margin-bottom: .5rem; font-size: .95rem; }
@media (max-height: 520px) and (orientation: landscape) { #stage { width: min(100%, calc(150vh * 0.5625)); } }

#stage .goal-chip { background: rgba(255,194,26,.92); color: #4a3200; font-weight: 800; font-size: 13px; font-variant-numeric: tabular-nums; padding: 4px 10px; align-items: center; }
#stage .goal-chip[hidden] { display: none; }
#stage .ladder { display: flex; gap: 6px; margin: 6px 0; }
#stage .ladder .rung { flex: 1; text-align: center; font-size: 11px; border-radius: 10px; padding: 4px 2px; background: #e8eef7; color: #5b6b86; opacity: .75; }
#stage .ladder .rung b { display: block; font-size: 13px; font-variant-numeric: tabular-nums; }
#stage .ladder .rung.got { opacity: 1; color: #16284d; box-shadow: inset 0 0 0 2px #ffc21a; background: #fff6d6; }
@keyframes medalpop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.18); } 100% { transform: scale(1); opacity: 1; } }
#stage .res-medal { animation: medalpop .5s ease-out both; }
@media (max-width: 420px) { #stage .hud-top { flex-wrap: wrap; } }
@media (prefers-reduced-motion: reduce) { #stage .res-medal { animation: none; } }

/* ---- full screen (shell native + immersive): the stage fills the area under the dock, canvas resizes via ResizeObserver ---- */
html.pip-immersive .game-wrap.pip-stage { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }
html.pip-immersive .game-wrap.pip-stage > .game-title,
html.pip-immersive .game-wrap.pip-stage > .sb-bar,
html.pip-immersive .game-wrap.pip-stage > .sb-keys,
html.pip-immersive #bigbtn { display: none !important; }
html.pip-immersive #stage { flex: 1 1 auto; min-height: 0; width: 100%; max-width: none; aspect-ratio: auto; margin: 0; border-radius: 0; }
html.pip-immersive #stage .hud { padding-bottom: 0; }
html.pip-immersive #stage .act { bottom: 14px; }
html.pip-immersive #stage .act-grab { bottom: 20px; }
html.pip-immersive #stage .screen { padding-bottom: 10px; }
html.pip-immersive #stage.zones .act-jump { bottom: 112px; }
html.pip-immersive #stage .meters { bottom: 160px; }
/* 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% 55%, rgba(0,0,0,0) 62%, rgba(10,24,70,.28) 100%); }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .act { width: 76px; height: 76px; bottom: 10px; }
  html.pip-immersive #stage .act-grab { width: 66px; height: 66px; right: 100px; bottom: 12px; }
  html.pip-immersive #stage.lefty .act-grab { right: auto; left: 100px; }
  html.pip-immersive #stage .meters { bottom: 100px; }
  html.pip-immersive #stage.zones .act-jump { bottom: 90px; }
  html.pip-immersive #stage .logo { margin-top: 2%; font-size: 34px; }
  html.pip-immersive #stage .logo small { margin-top: 2px; }
  html.pip-immersive #stage .screen { padding-top: 6px; padding-bottom: 6px; }
  html.pip-immersive #stage h2.ttl { font-size: 20px; margin: 2px 0 4px; }
  html.pip-immersive #stage .bigbtn { min-height: 48px; font-size: 19px; margin: 3px 0; }
}
