/* Foldwing Glide 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 { --ink:#1f2a44; --paper:#fff7e8; --sky:#3a86d9; --sky-d:#2a64a8; --orange:#ff8a3d; --gold:#ffc21a; --green:#3fb37f;
  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(#3a86d9 0%, #9fd0f0 60%, #f4ead6 100%); color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif; 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 [hidden] { display: none !important; }
#stage #app { position: absolute; inset: 0; touch-action: none; }
#stage #app canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#stage .play-surface { position: absolute; inset: 0; touch-action: none; }
#stage #ui { position: absolute; inset: 0; pointer-events: none; }
#stage button { font-family: inherit; cursor: pointer; touch-action: manipulation; color: var(--ink); }
#stage button:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
#stage #loader { position: absolute; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: linear-gradient(#3a86d9 0%, #9fd0f0 60%, #f4ead6 100%); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-shadow: 0 3px 0 rgba(20,40,90,.4); text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(22px, 7vw, 34px); 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,.4); border-top-color: var(--paper); animation: ppspin .8s linear infinite; }
@keyframes ppspin { 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,32,70,.88); color: #fff; font-weight: 700; }

/* buttons */
#stage .btn { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 44px; min-width: 44px; padding: 8px 12px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; color: var(--ink); font-weight: 800; font-size: 14px; box-shadow: 0 3px 0 var(--ink); text-decoration: none; }
#stage .btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
#stage .btn small { font-size: 11px; font-weight: 600; opacity: .75; }
#stage .btn.primary { background: var(--orange); color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,.25); }
#stage .btn.primary small { opacity: .95; }
#stage .btn.sel { background: var(--sky); color: #fff; }
#stage .btn.ghost { background: transparent; box-shadow: none; border-color: transparent; }
#stage .btn.danger { background: #fff0ee; border-color: #b3261e; color: #b3261e; box-shadow: 0 3px 0 #b3261e; }
#stage .btn.big { width: 100%; min-height: 56px; font-size: 17px; }
#stage .btn.locked { opacity: .55; }
#stage .btn[disabled] { opacity: .5; cursor: default; }
#stage .btn.pulse { animation: pppulse 1.2s ease-in-out infinite; }
@keyframes pppulse { 50% { transform: scale(1.05); } }
#stage .row3 { display: flex; gap: 8px; } #stage .row3 > * { flex: 1; }

/* screens */
#stage .screen { position: absolute; inset: 0; z-index: 20; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; touch-action: pan-y; pointer-events: auto; background: linear-gradient(rgba(255,247,232,.93), rgba(255,247,232,.97)); padding: max(10px, env(safe-area-inset-top)) 12px 16px; overscroll-behavior: contain; }
#stage .screen[data-name="home"] { background: linear-gradient(rgba(255,247,232,.15), rgba(255,247,232,.7) 55%, rgba(255,247,232,.95)); display: flex; align-items: flex-end; }
#stage .screen[data-name="pause"], #stage .screen[data-name="results"] { display: flex; align-items: center; justify-content: center; background: rgba(31,42,68,.55); }
#stage .home { width: 100%; display: flex; flex-direction: column; gap: 10px; padding-bottom: 6px; }
#stage .logo { text-align: center; margin-bottom: 8px; }
#stage .logo h1 { font-size: clamp(30px, 11vw, 46px); letter-spacing: 4px; color: var(--ink); text-shadow: 0 3px 0 #fff; line-height: 1; }
#stage .logo p { font-size: 12px; font-weight: 700; margin-top: 6px; color: var(--ink); }
#stage .logo-plane { width: 0; height: 0; margin: 0 auto 6px; border-left: 34px solid transparent; border-right: 34px solid transparent; border-bottom: 22px solid #fff; filter: drop-shadow(0 3px 0 var(--ink)); transform: rotate(-12deg); }
#stage .panel { width: 100%; max-height: 100%; overflow-y: auto; background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 6px 0 rgba(0,0,0,.25); touch-action: pan-y; }
#stage .panel h2 { text-align: center; font-size: 24px; }
#stage .panel .sub { text-align: center; font-size: 13px; opacity: .8; margin-top: -6px; }
#stage .panel .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#stage .panel .grid > div { background: #fff; border: 2px solid var(--ink); border-radius: 10px; padding: 6px 8px; display: flex; flex-direction: column; }
#stage .panel .grid small { font-size: 11px; opacity: .7; } #stage .panel .grid b { font-size: 17px; }
#stage .earn { text-align: center; font-weight: 800; font-size: 18px; color: var(--sky-d); }
#stage .goal, #stage .tip, #stage .ach { font-size: 13px; text-align: center; }
#stage .scr { display: flex; flex-direction: column; gap: 10px; }
#stage .scr-head { display: flex; align-items: center; gap: 6px; position: sticky; top: -10px; padding: 6px 0; background: rgba(255,247,232,.97); z-index: 2; }
#stage .scr-head h2 { flex: 1; font-size: 20px; text-align: center; }
#stage .scr-head .back { min-width: 44px; padding: 6px 6px; font-size: 13px; }
#stage .clips { font-weight: 800; font-size: 12px; background: var(--gold); border: 2px solid var(--ink); border-radius: 999px; padding: 4px 8px; white-space: nowrap; }
#stage .scr h3 { font-size: 15px; margin-top: 4px; }
#stage .cards { display: flex; flex-direction: column; gap: 8px; }
#stage .card { display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 8px 10px; border: 2px solid var(--ink); border-radius: 14px; background: #fff; text-align: left; box-shadow: 0 3px 0 var(--ink); position: relative; }
#stage .card.locked { opacity: .5; }
#stage .card .num { width: 34px; height: 34px; border-radius: 50%; background: var(--sky); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; flex: none; }
#stage .card .nm { flex: 1; display: flex; flex-direction: column; min-width: 0; } #stage .card .nm small { font-size: 11px; opacity: .7; }
#stage .card .lock { position: absolute; right: 10px; bottom: 4px; font-size: 10px; font-weight: 800; }
#stage .st { color: #c9c2b0; font-size: 18px; } #stage .st.on { color: var(--gold); text-shadow: 0 1px 0 var(--ink); }
#stage .stars.big { text-align: center; } #stage .stars.big .st { font-size: 40px; margin: 0 2px; }
#stage .rows { display: flex; flex-direction: column; gap: 8px; }
#stage .row { display: flex; align-items: center; gap: 8px; background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 8px 10px; }
#stage .row.done { background: #e9f8ef; }
#stage .row .grow { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; } #stage .row small { font-size: 11px; opacity: .75; }
#stage .rw { font-weight: 800; font-size: 12px; color: var(--sky-d); }
#stage .pips { display: flex; gap: 4px; margin-top: 3px; } #stage .pips i { width: 16px; height: 8px; border-radius: 4px; background: #d8d1bd; border: 1px solid var(--ink); } #stage .pips i.on { background: var(--orange); }
#stage .bar { height: 8px; border-radius: 4px; background: #e2dcc9; border: 1px solid var(--ink); overflow: hidden; } #stage .bar i { display: block; height: 100%; background: var(--green); }
#stage .chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
#stage .chip { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 66px; padding: 6px 4px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; font-size: 11px; font-weight: 700; }
#stage .chip.sel { background: #dbeafd; box-shadow: 0 0 0 3px var(--sky); } #stage .chip em { font-style: normal; font-size: 10px; opacity: .8; }
#stage .chip .sw { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--ink); }
#stage .set { display: flex; flex-direction: column; gap: 6px; background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 8px 10px; font-weight: 700; font-size: 14px; }
#stage .seg { display: flex; gap: 6px; } #stage .seg .btn { flex: 1; padding: 6px 4px; font-size: 12px; }

/* HUD */
#stage .hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; padding: max(8px, env(safe-area-inset-top)) 10px 8px; }
#stage .hud-top { display: flex; align-items: center; gap: 6px; }
#stage .stat { background: rgba(31,42,68,.72); color: #fff; border-radius: 12px; padding: 4px 10px; display: flex; align-items: baseline; gap: 3px; min-height: 36px; align-items: center; }
#stage .stat b { font-size: 20px; font-variant-numeric: tabular-nums; } #stage .stat small { font-size: 11px; opacity: .85; }
#stage .stat.alt { margin-right: auto; }
#stage .pausebtn { pointer-events: auto; width: 44px; height: 44px; border-radius: 12px; border: 2px solid var(--ink); background: #fff; font-weight: 800; box-shadow: 0 3px 0 var(--ink); letter-spacing: 1px; }
#stage .prog { height: 8px; margin-top: 8px; border-radius: 4px; background: rgba(255,255,255,.55); border: 1px solid var(--ink); overflow: hidden; }
#stage .prog i { display: block; height: 100%; background: var(--orange); transition: width .2s linear; }
#stage .hud-sub { display: flex; gap: 10px; margin-top: 8px; align-items: center; font-weight: 800; }
#stage .chain { background: var(--gold); border: 2px solid var(--ink); border-radius: 999px; padding: 0 8px; font-size: 13px; } #stage .chain:empty { display: none; }
#stage .armor { color: #ffdf6b; text-shadow: 0 1px 0 var(--ink); font-size: 18px; letter-spacing: 3px; }
#stage .feed { position: absolute; left: 10px; top: 118px; display: flex; flex-direction: column; gap: 4px; }
#stage .feed-i { background: rgba(255,255,255,.88); border: 2px solid var(--ink); border-radius: 10px; padding: 3px 8px; font-weight: 800; font-size: 13px; animation: ppfeed 1.5s ease-out forwards; }
@keyframes ppfeed { 0% { transform: translateY(8px); opacity: 0; } 15% { transform: none; opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
#stage .hint { position: absolute; left: 12px; right: 12px; bottom: 14%; text-align: center; background: rgba(255,247,232,.96); border: 3px solid var(--ink); border-radius: 14px; padding: 10px 12px; font-weight: 800; font-size: 15px; box-shadow: 0 4px 0 rgba(0,0,0,.25); }
#stage .banner { position: absolute; left: 0; right: 0; top: 26%; text-align: center; font-size: clamp(22px, 7vw, 32px); font-weight: 900; color: #fff; text-shadow: 0 3px 0 var(--ink), 0 0 12px rgba(0,0,0,.35); animation: ppban 1.4s ease-out; }
@keyframes ppban { 0% { transform: scale(.7); opacity: 0; } 20% { transform: scale(1.05); opacity: 1; } 100% { transform: none; opacity: 1; } }
#stage .stick { position: absolute; left: 0; top: 0; width: 0; height: 0; }
#stage .stick .ring { position: absolute; left: -48px; top: -48px; width: 96px; height: 96px; border-radius: 50%; border: 3px solid rgba(255,255,255,.85); background: rgba(31,42,68,.18); }
#stage .stick .thumb { position: absolute; left: -22px; top: -22px; width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.92); border: 3px solid var(--ink); }
#stage .toast { position: absolute; left: 14px; right: 14px; bottom: 8%; z-index: 40; text-align: center; background: var(--ink); color: #fff; border-radius: 12px; padding: 10px; font-weight: 700; font-size: 14px; }

.pp-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.pp-bar .btn { min-height: 44px; min-width: 44px; }
.pp-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.pp-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.pp-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.pp-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.pp-guide p { margin-bottom: .5rem; font-size: .95rem; }
#stage .best { background: rgba(255,255,255,.8); border: 2px solid var(--ink); border-radius: 999px; padding: 0 8px; font-size: 13px; margin-left: auto; } #stage .best.beat { background: var(--gold); }
#stage .stat.alt b.low, #stage .stat.alt .low { color: #c0392b; animation: ppwarn .6s ease-in-out infinite alternate; } @keyframes ppwarn { to { opacity: .45; } }
#stage .gap { font-weight: 800; margin-top: 6px; }
@media (prefers-reduced-motion: reduce) { #stage .stat.alt .low { animation: none; } #stage .banner, #stage .feed-i, #stage .btn.pulse { animation: none; } }

#stage .pp-exit { position: absolute; z-index: 40; left: 50%; bottom: max(8px, env(safe-area-inset-bottom)); transform: translateX(-50%); min-height: 44px; min-width: 44px; padding: 0 16px; border-radius: 12px; border: 2px solid var(--ink); background: #fff; font-weight: 800; opacity: .9; }

/* Full screen on phones: the play area fills the whole stage, copy and buttons that duplicate the shell are hidden. */
html.pip-immersive #stage, html.pip-native #stage, #stage:fullscreen { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; aspect-ratio: auto; border-radius: 0; }
html.pip-immersive .game-wrap > .pp-bar, html.pip-native .game-wrap > .pp-bar, html.pip-immersive .game-wrap > .pp-keys, html.pip-native .game-wrap > .pp-keys, html.pip-immersive #stage .pp-exit, html.pip-native #stage .pp-exit { display: none; }
html.pip-native #stage .hud { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
html.pip-native #stage .toast, html.pip-immersive #stage .toast { bottom: max(8%, env(safe-area-inset-bottom)); }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .hint, html.pip-native #stage .hint { left: 20%; right: 20%; bottom: 8%; padding: 6px 10px; font-size: 14px; }
  html.pip-immersive #stage .banner, html.pip-native #stage .banner { top: 20%; }
  html.pip-immersive #stage .feed, html.pip-native #stage .feed { top: 96px; }
}
/* finish: soft vignette over the scene, under the HUD */
#stage #app::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 58%, rgba(20,32,70,.22) 100%); }
#stage .stat { box-shadow: 0 2px 0 rgba(0,0,0,.25); backdrop-filter: blur(2px); }

/* Full screen landscape: level list as a compact multi-column grid so more levels show without scrolling. */
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .screen, html.pip-native #stage .screen { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  html.pip-immersive #stage .cards, html.pip-native #stage .cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  html.pip-immersive #stage .card, html.pip-native #stage .card { min-height: 48px; padding: 4px 8px; }
  html.pip-immersive #stage .card .num, html.pip-native #stage .card .num { width: 30px; height: 30px; }
  html.pip-immersive #stage .scr, html.pip-native #stage .scr { gap: 6px; }
  html.pip-immersive #stage .logo-plane, html.pip-native #stage .logo-plane { display: none; }
}
