/* Marble Maze 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; }
.mm-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.mm-bar .btn { min-height: 44px; min-width: 44px; }
.mm-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.mm-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.mm-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.mm-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.mm-guide p { margin-bottom: .5rem; font-size: .95rem; }

#stage { --teal:#1f8f7a; --teal-d:#146a5a; --gold:#ffc21a; --ink:#1d2b3a; --cream:#fff6e0; --red:#e8483c;
  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(#bfe8ff, #eaf9d8); 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.shell-fs { width: min(100%, calc(100vh * 0.5625)); width: min(100%, calc(100svh * 0.5625)); }
#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 [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 #ui { position: absolute; inset: 0; pointer-events: none; }
#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(#1f8f7a, #7fd6c2); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-shadow: 0 3px 0 rgba(10,60,50,.45); text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 30px); 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(--gold); animation: mmspin .8s linear infinite; }
@keyframes mmspin { 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(15,35,45,.88); color: #fff; font-weight: 700; }

/* HUD */
#stage .hud { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; padding: max(8px, env(safe-area-inset-top)) 8px 4px; pointer-events: none; }
#stage .hbtn { pointer-events: auto; width: 46px; height: 46px; border-radius: 14px; border: 0; background: rgba(20,50,60,.65); color: #fff; font-weight: 800; font-size: 18px; letter-spacing: 1px; }
#stage .hud-mid { text-align: center; color: #fff; text-shadow: 0 2px 0 rgba(10,40,50,.55); flex: 1; padding-top: 2px; }
#stage .hl { font-size: 13px; font-weight: 700; opacity: .95; }
#stage .ht { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
#stage .hud-r { display: flex; flex-direction: column; gap: 3px; align-items: flex-end; }
#stage .hs { background: rgba(20,50,60,.65); color: #fff; border-radius: 10px; padding: 3px 9px; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
#stage .rushbar { position: absolute; left: 62px; right: 96px; top: calc(max(8px, env(safe-area-inset-top)) + 52px); height: 7px; background: rgba(20,50,60,.5); border-radius: 5px; overflow: hidden; }
#stage .rushbar i { display: block; height: 100%; width: 100%; background: var(--gold); transition: width .1s linear; }
#stage .joy { position: absolute; left: 0; top: 0; width: 80px; height: 80px; pointer-events: none; opacity: .75; }
#stage .joy i { position: absolute; border-radius: 50%; }
#stage #joy-ring { inset: 0; border: 3px solid rgba(255,255,255,.85); background: rgba(255,255,255,.18); }
#stage #joy-knob { left: 26px; top: 26px; width: 28px; height: 28px; background: rgba(255,255,255,.95); box-shadow: 0 2px 6px rgba(0,0,0,.3); }
#stage .hint { position: absolute; left: 12px; right: 12px; bottom: 16px; padding: 10px 14px; border-radius: 14px; background: rgba(20,50,60,.82); color: #fff; font-size: 14px; font-weight: 700; text-align: center; pointer-events: none; }
#stage .banner { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: 34px; font-weight: 800; color: #fff; text-shadow: 0 3px 0 rgba(10,60,50,.6); pointer-events: none; }
#stage .toast { position: absolute; left: 50%; top: 72px; transform: translateX(-50%); padding: 6px 14px; border-radius: 12px; background: rgba(20,50,60,.85); color: #fff; font-weight: 700; font-size: 13px; pointer-events: none; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis; }
#stage .flash { position: absolute; inset: 0; pointer-events: none; }

/* screens */
#stage .screen { position: absolute; inset: 0; z-index: 10; display: flex; flex-direction: column; background: linear-gradient(rgba(20,60,64,.9), rgba(26,90,86,.94)); color: #fff; pointer-events: auto; padding: max(8px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom)); }
#stage .scroll { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: 6px 2px 10px; min-height: 0; }
#stage .scroll.center { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; }
#stage .scroll.center > :first-child { margin-top: auto; } #stage .scroll.center > :last-child { margin-bottom: auto; } /* centred, but never clipped when short */
#stage .scroll-x { overflow-x: auto; touch-action: pan-x; }
#stage .topbar { display: flex; justify-content: space-between; gap: 8px; font-weight: 800; font-size: 14px; padding: 2px 2px 6px; }
#stage .coin { background: rgba(0,0,0,.28); border-radius: 12px; padding: 4px 10px; }
#stage .shead { display: flex; align-items: center; gap: 10px; padding-bottom: 6px; }
#stage .shead h2 { font-size: 20px; }
#stage .logo { font-size: clamp(34px, 11vw, 52px); line-height: 1; letter-spacing: 1px; color: var(--gold); text-shadow: 0 4px 0 rgba(0,0,0,.35); }
#stage .sub { font-size: 14px; opacity: .92; }
#stage .fine { font-size: 12px; opacity: .8; }
#stage .warn { background: rgba(0,0,0,.3); padding: 6px 10px; border-radius: 10px; font-size: 13px; margin: 6px 0; }
#stage .btn { display: inline-flex; align-items: center; justify-content: center; min-height: 46px; min-width: 46px; padding: 0 16px; border-radius: 14px; border: 0; background: #fff; color: var(--teal-d); font-weight: 800; font-size: 16px; box-shadow: 0 3px 0 rgba(0,0,0,.25); }
#stage .btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
#stage .btn.big { min-height: 56px; font-size: 20px; background: var(--gold); color: #4a3200; width: 100%; max-width: 280px; }
#stage .btn.sm { min-height: 44px; font-size: 14px; padding: 0 12px; }
#stage .btn.gold { background: var(--gold); color: #4a3200; }
#stage .btn.danger { background: #ffb3ab; color: #7a1208; }
#stage .btn.on { background: var(--gold); color: #4a3200; }
#stage .btn[disabled] { opacity: .55; cursor: default; }
#stage .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 300px; }
#stage .tabs { display: flex; gap: 6px; padding: 2px 0 6px; }
#stage .tab { min-width: 46px; min-height: 44px; border-radius: 12px; border: 0; background: rgba(255,255,255,.2); color: #fff; font-weight: 800; font-size: 16px; flex: 0 0 auto; }
#stage .tab.wide { flex: 1; }
#stage .tab.on { background: var(--gold); color: #4a3200; }
#stage .tab.lock { opacity: .55; }
#stage .wname { font-size: 20px; margin-top: 4px; }
#stage .levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
#stage .lv { min-height: 92px; border-radius: 16px; border: 0; background: rgba(255,255,255,.95); color: var(--teal-d); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; box-shadow: 0 3px 0 rgba(0,0,0,.25); }
#stage .lv b { font-size: 24px; }
#stage .lv.locked { background: rgba(255,255,255,.18); color: rgba(255,255,255,.8); box-shadow: none; }
#stage .stars { display: inline-flex; gap: 2px; }
#stage .st { width: 20px; height: 20px; fill: rgba(0,0,0,.22); }
#stage .st.on { fill: var(--gold); stroke: #b27a00; stroke-width: 1; }
#stage .results .st, #stage .screen[data-name="results"] .st { width: 44px; height: 44px; }
#stage .med { font-style: normal; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; }
#stage .med.gold { color: #b27a00; } #stage .med.silver { color: #6b7a8a; } #stage .med.bronze { color: #a0602a; }
#stage .screen[data-name="results"] .med.gold { color: #ffd54a; } #stage .screen[data-name="results"] .med.silver { color: #dfe8f0; } #stage .screen[data-name="results"] .med.bronze { color: #ffb070; }
#stage .cards { display: flex; flex-direction: column; gap: 8px; }
#stage .card { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.14); border-radius: 14px; padding: 8px 10px; }
#stage .card.sel { background: rgba(255,194,26,.25); }
#stage .ct { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#stage .ct b { font-size: 16px; } #stage .ct span { font-size: 12px; opacity: .88; }
#stage .swatch { width: 42px; height: 42px; border-radius: 50%; flex: 0 0 auto; box-shadow: inset -4px -5px 8px rgba(0,0,0,.3), 0 2px 4px rgba(0,0,0,.3); }
#stage .pips { display: flex; gap: 4px; margin-top: 3px; }
#stage .pip { width: 14px; height: 8px; border-radius: 4px; background: rgba(255,255,255,.25); }
#stage .pip.on { background: var(--gold); }
#stage .reward { font-weight: 800; font-size: 13px; color: var(--gold); }
#stage .stats { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; font-weight: 700; padding-bottom: 8px; }
#stage .stats span { background: rgba(0,0,0,.28); padding: 3px 8px; border-radius: 9px; }
#stage .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: rgba(255,255,255,.14); border-radius: 14px; padding: 8px 12px; margin-bottom: 8px; font-weight: 700; }
#stage .row.col { flex-direction: column; align-items: stretch; }
#stage .row input[type=range] { width: 100%; min-height: 44px; touch-action: pan-y; }
#stage .seg { display: inline-flex; gap: 6px; }
#stage .bigno { font-size: 64px; font-weight: 800; color: var(--gold); line-height: 1; }
#stage .gain { color: var(--gold); font-weight: 800; font-style: normal; }
#stage .ach { background: rgba(255,194,26,.25); padding: 4px 10px; border-radius: 10px; font-weight: 700; font-size: 13px; }
#stage .goal { font-size: 14px; font-weight: 700; opacity: .95; max-width: 280px; }
#stage .line { font-size: 16px; }
#stage h2 { font-size: 26px; }
@media (max-height: 560px) { #stage .logo { font-size: 30px; } #stage .st { width: 16px; height: 16px; } }
@media (prefers-reduced-motion: reduce) { #stage .spinner { animation: none; } }
#stage .hbtn2 { position: absolute; left: 8px; top: calc(max(8px, env(safe-area-inset-top)) + 54px); font-size: 22px; }
#stage .hbtn2[hidden] { display: none; }

/* vignette: soft depth over the 3D view, no per-frame cost */
#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(10,40,50,.22) 100%); }

/* Full screen on phones: the shell makes .game-wrap the fixed stage (native and immersive). Fill it with the board. */
html.pip-immersive .game-wrap { display: flex; flex-direction: column; overflow: hidden !important; }
html.pip-immersive .game-wrap > .mm-bar, html.pip-immersive .game-wrap > .mm-keys, html.pip-immersive .game-wrap > .game-title { display: none; }
html.pip-immersive #stage { flex: 1 1 auto; min-height: 0; width: 100% !important; max-width: none; aspect-ratio: auto; height: auto; border-radius: 0; margin: 0; }
html.pip-immersive #stage .hud { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
