/* Flipstar Pinball 3D - stage, HUD and menu screens. Everything is scoped under #stage so site styles never leak in. */
html.pip-big, html.pip-big body { overflow: hidden; }
#stage { --ink:#e9eeff; --dim:#9aa6d0; --accent:#6c4dff; --acc2:#35e0ff; --gold:#ffd34d; --hot:#ff3d7f; --panel:rgba(14,18,40,.94);
  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: #101828; 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 #touch { position: absolute; inset: 0; z-index: 2; touch-action: none; pointer-events: none; }
#stage #ui { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
#stage #ui button, #stage #ui .panel, #stage #ui input, #stage #ui .plunger { pointer-events: auto; }
#stage button { font-family: inherit; cursor: pointer; touch-action: manipulation; color: inherit; }
#stage button:focus-visible, #stage input: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(#101828, #1b2750); text-align: center; padding: 20px; }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; font-weight: 700; }
#stage .load-in span { font-weight: 500; font-size: .9rem; color: var(--dim); max-width: 28ch; }
#stage .spinner { width: 42px; height: 42px; border-radius: 50%; border: 6px solid rgba(255,255,255,.2); border-top-color: var(--gold); animation: pbspin .8s linear infinite; }
@keyframes pbspin { 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(10,14,34,.88); color: #fff; 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; justify-content: space-between; align-items: flex-start; padding: 8px 10px; background: linear-gradient(rgba(6,10,26,.75), rgba(6,10,26,0)); }
#stage .hud-score { font-size: clamp(1.4rem, 7vw, 2.2rem); font-weight: 800; letter-spacing: .02em; font-variant-numeric: tabular-nums; text-shadow: 0 2px 6px #000; }
#stage .hud-sub { display: flex; gap: 10px; font-size: .75rem; font-weight: 700; color: var(--gold); }
#stage .ibtn { width: 44px; height: 44px; border-radius: 12px; border: 2px solid rgba(255,255,255,.35); background: rgba(14,18,40,.8); font-weight: 800; font-size: 1rem; }
#stage .hud-mode { position: absolute; top: 62px; left: 10px; right: 64px; background: rgba(14,18,40,.78); border: 1px solid rgba(255,255,255,.2); border-radius: 10px; padding: 5px 9px; display: flex; flex-direction: column; gap: 1px; }
#stage .hud-mode b { font-size: .8rem; color: var(--acc2); letter-spacing: .05em; }
#stage .hud-mode span { font-size: .72rem; color: var(--ink); }
#stage .bar { height: 6px; border-radius: 4px; background: rgba(255,255,255,.15); overflow: hidden; margin-top: 3px; flex: 1; min-width: 40px; }
#stage .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--acc2), var(--gold)); border-radius: 4px; }
#stage .hud-msg { position: absolute; left: 6%; right: 6%; top: 34%; text-align: center; display: flex; flex-direction: column; gap: 2px; animation: pbpop .35s ease-out; text-shadow: 0 2px 8px #000, 0 0 18px rgba(0,0,0,.8); }
#stage .hud-msg b { font-size: clamp(1.3rem, 7vw, 2rem); font-weight: 900; letter-spacing: .06em; color: #fff; }
#stage .hud-msg i { font-style: normal; font-size: clamp(.85rem, 4vw, 1.1rem); font-weight: 700; color: var(--gold); }
#stage .hud-msg.k-big b { font-size: clamp(1.8rem, 9vw, 2.8rem); color: var(--gold); }
#stage .hud-msg.k-jackpot b, #stage .hud-msg.k-super b { color: var(--hot); font-size: clamp(1.8rem, 9vw, 2.8rem); }
#stage .hud-msg.k-mission b { color: var(--acc2); }
#stage .hud-msg.k-warn b { color: #ff6a4a; }
@keyframes pbpop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#stage .hud-hint { position: absolute; left: 8%; right: 8%; top: 19%; text-align: center; font-size: .9rem; font-weight: 700; background: rgba(14,18,40,.85); border: 1px solid var(--acc2); border-radius: 12px; padding: 9px 12px; }
#stage .hud-bonus { position: absolute; left: 0; right: 0; top: 44%; text-align: center; font-size: 1.3rem; font-weight: 900; color: var(--gold); text-shadow: 0 2px 8px #000; }
#stage .nudge { position: absolute; left: 10px; bottom: 36%; min-width: 64px; height: 44px; border-radius: 12px; border: 2px solid rgba(255,255,255,.3); background: rgba(14,18,40,.7); font-weight: 800; font-size: .72rem; letter-spacing: .06em; }
#stage .plunger { position: absolute; right: 0; bottom: 8%; width: 20%; min-width: 72px; height: 34%; display: flex; flex-direction: column; align-items: center; touch-action: none; }
#stage .plunger span { position: absolute; bottom: 4px; font-size: .62rem; font-weight: 800; color: #fff; text-shadow: 0 1px 4px #000; letter-spacing: .06em; }
#stage .plrail { position: absolute; top: 6px; bottom: 22px; width: 10px; border-radius: 6px; background: rgba(255,255,255,.18); }
#stage .plknob { position: absolute; top: 6px; width: 46px; height: 46px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ff8a9a, #cc3344); border: 3px solid #fff; box-shadow: 0 3px 10px rgba(0,0,0,.6); animation: pbbob 1.4s ease-in-out infinite; }
@keyframes pbbob { 50% { margin-top: 10px; } }

/* ---- screens */
#stage .screens { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
#stage .panel { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; background: var(--panel); padding: 14px 14px 22px; display: flex; flex-direction: column; gap: 10px; outline: none; }
#stage .panel > * { flex: 0 0 auto; }
#stage .hero { text-align: center; padding-top: 4px; }
#stage .hero h1 { font-size: clamp(2rem, 11vw, 3rem); font-weight: 900; letter-spacing: .12em; color: #fff; text-shadow: 0 0 20px var(--accent); line-height: 1; }
#stage .hero p { color: var(--acc2); font-weight: 800; letter-spacing: .35em; font-size: .8rem; margin-top: 4px; }
#stage .hero.small h2 { font-size: 1.8rem; letter-spacing: .1em; }
#stage .hero.small p { letter-spacing: .1em; color: var(--dim); }
#stage .statrow { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: .85rem; }
#stage .stars-chip { background: rgba(255,211,77,.15); color: var(--gold); border: 1px solid rgba(255,211,77,.4); border-radius: 20px; padding: 3px 10px; font-weight: 800; white-space: nowrap; }
#stage .goal { font-size: .78rem; color: var(--ink); background: rgba(255,255,255,.06); border-radius: 10px; padding: 7px 10px; }
#stage .goal span { color: var(--acc2); font-weight: 800; margin-right: 4px; }
#stage .cards { display: flex; flex-direction: column; gap: 8px; }
#stage .tcard { text-align: left; padding: 10px 12px; border-radius: 12px; border: 2px solid rgba(255,255,255,.14); background: rgba(255,255,255,.05); display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; min-height: 64px; }
#stage .tcard b { font-size: 1rem; }
#stage .tcard em { font-style: normal; color: var(--gold); font-size: .7rem; align-self: center; }
#stage .tcard small { grid-column: 1 / -1; color: var(--dim); font-size: .72rem; }
#stage .tcard .trow { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 8px; font-size: .72rem; color: var(--ink); }
#stage .tcard.sel { border-color: var(--acc2); background: rgba(53,224,255,.1); }
#stage .tcard.locked { opacity: .65; }
#stage .medal { font-weight: 800; color: var(--dim); } #stage .medal.m1 { color: #d8955a; } #stage .medal.m2 { color: #cfd6e6; } #stage .medal.m3 { color: var(--gold); }
#stage .chips { display: flex; flex-wrap: wrap; gap: 6px; }
#stage .chips.tight { justify-content: flex-end; }
#stage .chip { min-height: 44px; padding: 6px 14px; border-radius: 22px; border: 2px solid rgba(255,255,255,.2); background: rgba(255,255,255,.05); font-weight: 700; font-size: .82rem; }
#stage .chip.sel { border-color: var(--gold); background: rgba(255,211,77,.14); color: var(--gold); }
#stage .chip.locked { opacity: .55; }
#stage .blurb, #stage .note { font-size: .78rem; color: var(--dim); }
#stage .daily { display: flex; flex-direction: column; gap: 2px; font-size: .78rem; background: rgba(255,255,255,.06); border-radius: 10px; padding: 8px 10px; }
#stage .daily b { color: var(--gold); }
#stage .bigbtn { min-height: 56px; border-radius: 16px; border: 0; background: linear-gradient(#8a6dff, #5b3df0); color: #fff; font-size: 1.3rem; font-weight: 900; letter-spacing: .12em; box-shadow: 0 4px 0 #3a22b0; }
#stage .bigbtn:active { transform: translateY(2px); box-shadow: 0 2px 0 #3a22b0; }
#stage .bigbtn:disabled { opacity: .5; }
#stage .navrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 8px; }
#stage .btn2 { min-height: 44px; border-radius: 12px; border: 2px solid rgba(255,255,255,.25); background: rgba(255,255,255,.07); font-weight: 700; font-size: .82rem; padding: 6px 10px; }
#stage .btn2.buy { color: var(--gold); border-color: rgba(255,211,77,.5); min-width: 84px; }
#stage .btn2.buy[data-poor] { opacity: .55; }
#stage .btn2.danger { border-color: #ff6a4a; color: #ff9a86; }
#stage .phead { display: flex; align-items: center; gap: 10px; } #stage .phead h2 { flex: 1; font-size: 1.2rem; }
#stage .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.08); min-height: 48px; }
#stage .rl { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; } #stage .rl small { color: var(--dim); font-size: .72rem; }
#stage .tag { font-size: .7rem; font-weight: 800; color: var(--acc2); white-space: nowrap; } #stage .row.done .tag { color: #9cff3a; } #stage .row.done b { opacity: .7; }
#stage h3 { font-size: .95rem; color: var(--acc2); margin-top: 6px; }
#stage .pips { display: inline-flex; gap: 4px; } #stage .pips i { width: 12px; height: 12px; border-radius: 3px; background: rgba(255,255,255,.18); } #stage .pips i.on { background: var(--gold); }
#stage .toggle { min-width: 64px; min-height: 44px; border-radius: 22px; border: 2px solid rgba(255,255,255,.25); background: rgba(255,255,255,.07); font-weight: 800; } #stage .toggle.on { background: rgba(53,224,255,.2); border-color: var(--acc2); color: var(--acc2); }
#stage .nameinp { width: 84px; min-height: 44px; text-align: center; font-size: 1.1rem; font-weight: 800; letter-spacing: .2em; border-radius: 10px; border: 2px solid rgba(255,255,255,.3); background: rgba(255,255,255,.08); color: #fff; }
#stage .ladder { list-style: none; display: flex; flex-direction: column; gap: 4px; }
#stage .ladder li { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; padding: 8px 10px; border-radius: 8px; background: rgba(255,255,255,.05); font-variant-numeric: tabular-nums; }
#stage .ladder li.you { background: rgba(255,211,77,.16); border: 1px solid rgba(255,211,77,.5); } #stage .ladder em { font-style: normal; font-weight: 700; }
#stage .finalscore { text-align: center; font-size: clamp(2rem, 11vw, 3rem); font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
#stage .badge { text-align: center; padding: 6px; border-radius: 10px; font-weight: 800; font-size: .85rem; background: rgba(255,61,127,.2); color: #ff9ab9; } #stage .badge.b2 { background: rgba(53,224,255,.16); color: var(--acc2); } #stage .badge.b3 { background: rgba(156,255,58,.16); color: #b9ff6a; }
#stage .grid2 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; } #stage .grid2 div { background: rgba(255,255,255,.06); border-radius: 10px; padding: 7px; text-align: center; display: flex; flex-direction: column; } #stage .grid2 small { color: var(--dim); font-size: .68rem; } #stage .grid2 b { font-size: 1.05rem; }
#stage .achlist { list-style: none; font-size: .8rem; display: flex; flex-direction: column; gap: 3px; color: #b9ff6a; }
#stage .toast { position: absolute; left: 8%; right: 8%; bottom: 12%; z-index: 9; text-align: center; font-size: .85rem; font-weight: 700; background: rgba(0,0,0,.88); border: 1px solid var(--gold); border-radius: 12px; padding: 10px 12px; pointer-events: none; }

@media (max-height: 520px) { #stage .hud-hint { top: 14%; } #stage .nudge { bottom: 30%; } }

.pb-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.pb-bar .btn { min-height: 44px; min-width: 44px; }
.pb-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.pb-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.pb-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.pb-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.pb-guide p { margin-bottom: .5rem; font-size: .95rem; }
@media (prefers-reduced-motion: reduce) { #stage .plknob, #stage .hud-msg { animation: none; } }

/* personal best chip, score pulse, safe areas */
#stage .hud-best { color: var(--acc2); opacity: .9; }
#stage .hud-best.beaten { color: var(--hot); opacity: 1; animation: pbbest 1s ease-in-out infinite alternate; }
#stage .hud-score.pulse { animation: pbscore .28s ease-out; }
@keyframes pbscore { 0% { transform: scale(1.18); color: var(--gold); } 100% { transform: scale(1); } }
@keyframes pbbest { from { opacity: .6; } to { opacity: 1; } }
#stage .hud-score { transform-origin: left center; }
#stage .hud-top { padding-top: max(8px, env(safe-area-inset-top)); padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
#stage.is-big .nudge { bottom: max(18%, calc(env(safe-area-inset-bottom) + 12%)); }
@media (prefers-reduced-motion: reduce) { #stage .hud-score.pulse, #stage .hud-best.beaten { animation: none; } }

/* Shell full screen (native or immersive): the table fills the stage, extra page copy and the duplicate button go away. */
html.pip-immersive .game-wrap, html.pip-native .game-wrap, .game-wrap:fullscreen { display: flex; flex-direction: column; padding: 0; }
html.pip-immersive .game-wrap > .pb-bar, html.pip-immersive .game-wrap > .pb-keys, html.pip-immersive .game-wrap > noscript,
html.pip-native .game-wrap > .pb-bar, html.pip-native .game-wrap > .pb-keys, .game-wrap:fullscreen > .pb-bar, .game-wrap:fullscreen > .pb-keys { display: none; }
html.pip-immersive #stage, html.pip-native #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 #stage .hud-top, html.pip-native #stage .hud-top { padding-left: max(10px, env(safe-area-inset-left, 0px)); padding-right: max(10px, env(safe-area-inset-right, 0px)); }
html.pip-immersive #stage .plunger, html.pip-native #stage .plunger { bottom: calc(8% + env(safe-area-inset-bottom, 0px)); right: env(safe-area-inset-right, 0px); }
html.pip-immersive #stage .nudge, html.pip-native #stage .nudge { left: max(10px, env(safe-area-inset-left, 0px)); }
@media (orientation: landscape) and (max-height: 500px) {
  html.pip-immersive #stage .hud-mode, html.pip-native #stage .hud-mode { top: 54px; right: 25%; }
  html.pip-immersive #stage .hud-hint, html.pip-native #stage .hud-hint { top: 24%; }
  html.pip-immersive #stage .plunger, html.pip-native #stage .plunger { height: 46%; }
}
