/* Lanternfall Fair 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 { --pump:#e8772e; --pump-d:#b4531a; --plum:#3b2a52; --cream:#fff4dc; --ink:#3a2418; --green:#5b8c3a; --red:#b83a2d; --gold:#f2b84b;
  position: relative; width: min(100%, calc(78vh * 0.5625)); width: min(100%, calc(78svh * 0.5625)); min-width: min(300px, 100%); aspect-ratio: 9 / 16; margin: 0 auto; overflow: hidden;
  border-radius: 14px; background: linear-gradient(#6fa2d6, #f7dcae); 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 button { font-family: inherit; cursor: pointer; touch-action: manipulation; color: inherit; }
#stage button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
#stage button:disabled { opacity: .45; cursor: default; }
#stage [hidden] { display: none !important; }

#stage #loader { position: absolute; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: linear-gradient(#3b2a52, #e8772e); color: #fff; text-align: center; }
#stage #loader[hidden] { display: none; }
#stage .load-in { display: flex; flex-direction: column; gap: 8px; align-items: center; }
#stage .load-in b { letter-spacing: 3px; font-size: 20px; }
#stage .spinner { width: 34px; height: 34px; border: 4px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: tpspin 1s linear infinite; }
@keyframes tpspin { to { transform: rotate(360deg); } }
#stage #ctxlost { position: absolute; left: 10px; right: 10px; top: 40%; z-index: 70; background: rgba(40,20,10,.92); color: #fff; padding: 14px; border-radius: 12px; text-align: center; font-size: 14px; }
#stage .nogl { position: absolute; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; background: var(--plum); color: #fff; font-size: 16px; line-height: 1.4; }

/* buttons */
#stage .b { min-height: 44px; min-width: 44px; padding: 0 12px; border: 0; border-radius: 12px; background: rgba(255,244,220,.95); color: var(--ink); font-size: 14px; font-weight: 700; box-shadow: 0 2px 0 rgba(58,36,24,.35); pointer-events: auto; }
#stage .b:active { transform: translateY(1px); box-shadow: none; }
#stage .b.sq { padding: 0 6px; font-size: 13px; }
#stage .b.sm { min-height: 44px; font-size: 13px; }
#stage .b.ok { background: var(--pump); color: #fff; }
#stage .b.warn { background: var(--red); color: #fff; }
#stage .b.big { width: 100%; min-height: 50px; font-size: 16px; }
#stage .b.link { background: none; box-shadow: none; text-decoration: underline; min-height: 44px; }
#stage .b.tab { flex: 1 1 0; padding: 0 4px; font-size: 13px; background: rgba(58,36,24,.12); box-shadow: none; }
#stage .b.tab.on { background: var(--pump); color: #fff; }

/* HUD */
#stage .top { position: absolute; left: 6px; right: 6px; top: 6px; display: flex; gap: 5px; align-items: stretch; pointer-events: none; }
#stage .top .b { flex: 0 0 auto; }
#stage .stat { flex: 1 1 0; min-width: 0; background: rgba(255,244,220,.93); border-radius: 12px; padding: 3px 6px; display: flex; flex-direction: column; justify-content: center; min-height: 44px; text-align: center; pointer-events: none; }
#stage .stat i { font-style: normal; font-size: 10px; color: #7a5a3a; text-transform: uppercase; letter-spacing: .5px; }
#stage .stat b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#stage .stat b.neg { color: var(--red); }
#stage .goals { position: absolute; left: 6px; right: 62px; top: 56px; min-height: 44px; padding: 4px 10px; border: 0; border-radius: 12px; background: rgba(59,42,82,.88); color: #fff; font-size: 12px; text-align: left; pointer-events: auto; overflow: hidden; }
#stage .side { position: absolute; right: 6px; top: 56px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
#stage .side .b { width: 50px; padding: 0; }
#stage .b.warn.side, #stage .b.side.warn { background: var(--red); color: #fff; }
#stage .hint { position: absolute; left: 6px; right: 62px; top: 112px; padding: 8px 10px; border-radius: 12px; background: rgba(232,119,46,.96); color: #fff; font-size: 13px; font-weight: 700; pointer-events: auto; }
#stage .toasts { position: absolute; left: 8px; right: 8px; bottom: 132px; display: flex; flex-direction: column; gap: 4px; align-items: center; pointer-events: none; }
#stage .toast { max-width: 100%; padding: 7px 12px; border-radius: 10px; background: rgba(40,24,16,.9); color: #fff; font-size: 13px; animation: tpfade .3s ease-out; }
#stage .toast.bad { background: rgba(184,58,45,.95); }
#stage .toast.good { background: rgba(60,110,40,.95); }
@keyframes tpfade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
#stage .nav { position: absolute; left: 6px; right: 6px; bottom: 6px; display: flex; gap: 5px; pointer-events: none; }
#stage .nav .b { flex: 1 1 0; min-height: 50px; padding: 0 2px; font-size: 14px; }
#stage .nav .b.on { background: var(--pump); color: #fff; }
#stage .pbar { position: absolute; left: 6px; right: 6px; bottom: 62px; padding: 8px; border-radius: 14px; background: rgba(255,244,220,.97); display: flex; flex-direction: column; gap: 6px; pointer-events: auto; box-shadow: 0 3px 10px rgba(0,0,0,.25); }
#stage .ptext { font-size: 13px; font-weight: 700; }
#stage .ptext.bad { color: var(--red); }
#stage .prow { display: flex; gap: 6px; }
#stage .prow .b { flex: 1 1 0; }
#stage .prow.wide { margin: 8px 0; }

/* sheets */
#stage .sheet { position: absolute; left: 6px; right: 6px; bottom: 62px; max-height: 62%; display: flex; flex-direction: column; border-radius: 16px; background: rgba(255,244,220,.98); box-shadow: 0 -2px 14px rgba(0,0,0,.3); pointer-events: auto; z-index: 5; }
#stage .shead { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 2px 14px; }
#stage .shead h3 { margin: 0; font-size: 17px; color: var(--pump-d); }
#stage .sbody { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: 4px 10px 12px; }
#stage .tabs { display: flex; gap: 5px; margin: 4px 0 8px; }
#stage .list { display: flex; flex-direction: column; gap: 6px; }
#stage .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; padding: 6px 10px; border: 2px solid rgba(58,36,24,.12); border-radius: 12px; background: #fff; text-align: left; width: 100%; }
#stage .row.sel { border-color: var(--pump); }
#stage .row.lock { opacity: .55; }
#stage .row.poor .rc { color: var(--red); }
#stage .row.static { cursor: default; }
#stage .row.got { background: #eaf3d9; }
#stage .rn { display: flex; flex-direction: column; min-width: 0; }
#stage .rn b { font-size: 14px; }
#stage .rn small, #stage .card small, #stage .goal small { font-size: 11px; color: #6a5440; }
#stage .rc { font-weight: 800; font-size: 14px; white-space: nowrap; }
#stage .note, #stage .tag { margin: 4px 0; font-size: 12px; color: #5a4430; }
#stage h4 { margin: 10px 0 4px; font-size: 14px; color: var(--plum); }
#stage .card { background: #fff; border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
#stage .kv { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin: 6px 0; }
#stage .kv > div { display: flex; justify-content: space-between; gap: 6px; font-size: 13px; border-bottom: 1px dotted rgba(58,36,24,.2); padding: 2px 0; }
#stage .kv.small { grid-template-columns: 1fr 1fr; }
#stage .kv b.pos { color: var(--green); } #stage .kv b.neg { color: var(--red); }
#stage .stepper { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
#stage .stepper span { flex: 1; font-weight: 700; font-size: 14px; }
#stage .stepper .sv { min-width: 64px; text-align: center; }
#stage .meter { height: 8px; border-radius: 4px; background: rgba(58,36,24,.15); overflow: hidden; }
#stage .meter i { display: block; height: 100%; background: var(--pump); }
#stage .goal { display: flex; flex-direction: column; gap: 2px; margin: 5px 0; font-size: 13px; }
#stage .goal.done span { color: var(--green); font-weight: 700; }

/* full-screen menus */
#stage .screen { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 10px; background: rgba(40,20,10,.5); overflow-y: auto; pointer-events: auto; }
#stage .screen .panel { width: 100%; max-width: 400px; max-height: 100%; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; background: rgba(255,244,220,.97); border-radius: 20px; padding: 16px 14px 14px; display: flex; flex-direction: column; gap: 9px; margin: auto; }
#stage .panel h2 { margin: 0; font-size: 22px; color: var(--pump-d); letter-spacing: 1px; }
#stage .panel .scroll { max-height: 56vh; max-height: 56svh; overflow-y: auto; touch-action: pan-y; }
#stage .logo { display: flex; flex-direction: column; line-height: 1; text-align: center; }
#stage .logo span { font-size: 14px; letter-spacing: 6px; color: var(--plum); font-weight: 800; }
#stage .logo b { font-size: clamp(26px, 9vw, 38px); color: var(--pump); letter-spacing: 2px; text-shadow: 0 3px 0 rgba(90,40,10,.25); }
#stage .lvl { font-size: 12px; display: flex; flex-direction: column; gap: 4px; }
#stage .srow { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 700; }
#stage .srow.col { flex-direction: column; align-items: stretch; }
#stage .srow .b.tab { flex: 0 0 90px; }
#stage .how { margin: 0; padding-left: 18px; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
#stage .bigstars { font-size: 38px; color: var(--gold); text-align: center; letter-spacing: 6px; text-shadow: 0 2px 0 rgba(90,40,10,.3); }
#stage .reward { margin: 0; text-align: center; font-weight: 800; color: var(--pump-d); }
#stage .ach { margin: 0; text-align: center; font-size: 13px; color: var(--green); font-weight: 700; }

/* page chrome around the stage */
.tp-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.tp-bar .btn { min-height: 44px; min-width: 44px; }
.tp-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.tp-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.tp-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.tp-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.tp-guide p { margin-bottom: .5rem; font-size: .95rem; }

/* wide stages (landscape / full screen on desktop): keep controls reachable */
@media (min-aspect-ratio: 1/1) { #stage.is-big .sheet { left: auto; width: 420px; max-height: 70%; } #stage.is-big .pbar { left: auto; width: 420px; } }
@media (prefers-reduced-motion: reduce) { #stage .toast, #stage .spinner { animation: none; } }

/* tutorial pulse on the button to tap next, safe areas, reduced motion */
#stage .nav .b.tut { box-shadow: 0 0 0 3px #fff, 0 0 14px 4px var(--gold); animation: tppulse 1.1s ease-in-out infinite; }
@keyframes tppulse { 50% { transform: translateY(-3px); } }
#stage .nav { bottom: max(6px, env(safe-area-inset-bottom)); }
#stage .toast { font-size: 14px; }
@media (prefers-reduced-motion: reduce) { #stage .nav .b.tut { animation: none; } }

/* Full screen on phones (shell immersive and native): the park fills the stage under the dock, no extra chrome. */
#stage #app::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 70px rgba(59,42,82,.28); }
html.pip-immersive .game-wrap.pip-stage { display: flex; flex-direction: column; padding: 0; margin: 0; max-width: none; overflow: hidden; }
html.pip-immersive .game-wrap.pip-stage > .tp-bar,
html.pip-immersive .game-wrap.pip-stage > .tp-keys,
html.pip-immersive .game-wrap.pip-stage > .game-title { display: none; }
html.pip-immersive .game-wrap.pip-stage #stage { flex: 1 1 auto; min-height: 0; width: 100%; max-width: none; min-width: 0; height: auto; aspect-ratio: auto; border-radius: 0; margin: 0; }
html.pip-immersive .game-wrap.pip-stage #stage #app,
html.pip-immersive .game-wrap.pip-stage #stage #app canvas { width: 100%; height: 100%; }
:fullscreen #stage { border-radius: 0; }
