/* Rooftop Runner 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 { --ink:#2a2438; --acc:#e0702a; --acc-d:#a8481a; --sun:#ffc21a; --green:#3fcf6a; --cream:#fff4e0; --line:#e7d3b8;
  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(#f6b36b 0%, #f2c892 60%, #7a3b2c 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; }
.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; }
#stage #app canvas { display: block; width: 100%; height: 100%; }
#stage #ui { position: absolute; inset: 0; pointer-events: none; }
#stage #ui button, #stage #ui .panel { 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 #loader { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: linear-gradient(#f6b36b 0%, #e0702a 100%); }
#stage #loader[hidden], #stage #ctxlost[hidden], #stage .hud[hidden], #stage .screen[hidden], #stage .pad[hidden], #stage .hint-bubble[hidden], #stage .pwi[hidden], #stage .trialbar[hidden] { display: none; }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-shadow: 0 3px 0 rgba(90,40,10,.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(--sun); animation: rrspin .8s linear infinite; }
@keyframes rrspin { 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(30,20,40,.88); color: #fff; font-weight: 700; }

/* 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; justify-content: flex-start; align-items: center; gap: 6px; padding-right: 52px; flex-wrap: wrap; }
#stage .stat { background: rgba(35,24,48,.6); color: #fff; border-radius: 12px; padding: 4px 9px; display: flex; align-items: baseline; gap: 4px; min-height: 30px; }
#stage .stat b { font-size: 17px; font-variant-numeric: tabular-nums; }
#stage .stat .lbl { font-size: 11px; opacity: .85; }
#stage .stat.coins { align-items: center; }
#stage .cdot { display: inline-block; width: 15px; height: 15px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff2a8, #ffc21a 60%, #c88a00); border: 2px solid #b97d00; flex: none; }
#stage .trialbar { height: 6px; margin: 6px 52px 0 0; background: rgba(255,255,255,.35); border-radius: 4px; overflow: hidden; }
#stage .trialbar i { display: block; height: 100%; background: var(--sun); transform-origin: left; transform: scaleX(0); }
#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(35,24,48,.65); color: #fff; font-weight: 800; font-size: 16px; pointer-events: auto; }
#stage .pw { display: flex; gap: 6px; margin-top: 8px; }
#stage .pwi { min-width: 62px; background: rgba(255,255,255,.88); border-radius: 10px; padding: 3px 6px 4px; font-size: 11px; font-weight: 800; text-align: center; }
#stage .pwi.mag { border-bottom: 3px solid #e44b4b; } #stage .pwi.shd { border-bottom: 3px solid #4aa8ff; } #stage .pwi.rkt { border-bottom: 3px solid #ffc21a; }
#stage .pwi.low { animation: rrblink .5s infinite alternate; }
@keyframes rrblink { to { opacity: .45; } }
#stage .pwi .bar { height: 5px; margin-top: 2px; background: rgba(0,0,0,.15); border-radius: 3px; overflow: hidden; }
#stage .pwi .bar i { display: block; height: 100%; background: var(--green); transform-origin: left; }
#stage .hint-bubble { position: absolute; left: 50%; top: 32%; transform: translateX(-50%); max-width: 86%; background: rgba(255,255,255,.95); color: var(--ink); font-weight: 800; font-size: 15px; text-align: center; padding: 8px 14px; border-radius: 14px; box-shadow: 0 3px 0 rgba(0,0,0,.2); animation: rrfloat .9s ease-in-out infinite alternate; }
@keyframes rrfloat { to { transform: translate(-50%, -6px); } }
#stage .pad { position: absolute; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
#stage .pad button { height: 64px; min-width: 56px; border: 0; border-radius: 16px; background: rgba(255,255,255,.82); color: var(--acc-d); font-size: 26px; box-shadow: 0 4px 0 rgba(40,20,10,.4); touch-action: none; }
#stage .pad button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(40,20,10,.4); }
#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,.92); color: var(--ink); font-weight: 800; font-size: 13px; padding: 4px 12px; border-radius: 99px; animation: rrfeed 1.8s ease-out forwards; }
#stage .feed .f.mission { background: var(--green); color: #063; }
#stage .feed .f.pw { background: var(--sun); color: #4a3200; }
@keyframes rrfeed { 0% { opacity: 0; transform: translateY(8px); } 12% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }
#stage .banner { position: absolute; left: 0; right: 0; top: 16%; text-align: center; pointer-events: none; opacity: 0; transform: scale(.8); transition: opacity .25s, transform .25s; color: #fff; text-shadow: 0 3px 0 rgba(60,25,10,.55); }
#stage .banner.show { opacity: 1; transform: none; }
#stage .b-main { font-size: clamp(26px, 9vw, 40px); font-weight: 900; letter-spacing: 2px; }
#stage .b-sub { font-size: 14px; font-weight: 700; }
#stage .flash { position: absolute; inset: 0; opacity: 0; pointer-events: none; background: #fff; transition: opacity .12s; }

/* screens */
#stage .screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: 10px; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; pointer-events: none; }
#stage .screen .panel { pointer-events: auto; touch-action: pan-y; margin-top: auto; width: 100%; background: rgba(255,247,232,.97); border-radius: 20px; padding: 14px 14px 12px; display: flex; flex-direction: column; gap: 9px; box-shadow: 0 6px 0 rgba(60,30,10,.35); text-align: center; }
#stage .panel h2 { margin: 0; font-size: 22px; color: var(--acc-d); letter-spacing: 1px; }
#stage .panel h3 { margin: 4px 0 0; font-size: 14px; color: var(--acc-d); text-align: left; }
#stage .logo { display: flex; flex-direction: column; align-items: center; line-height: 1; }
#stage .logo span { font-size: 15px; letter-spacing: 8px; color: var(--acc-d); font-weight: 800; }
#stage .logo b { font-size: clamp(30px, 10vw, 42px); color: var(--acc); letter-spacing: 2px; text-shadow: 0 3px 0 rgba(90,40,10,.22); }
#stage .toprow { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#stage .rankbar { display: flex; align-items: center; gap: 8px; flex: 1; font-weight: 800; font-size: 13px; }
#stage .rankbar .bar { flex: 1; height: 10px; background: rgba(40,30,50,.15); border-radius: 6px; overflow: hidden; }
#stage .rankbar .bar i { display: block; height: 100%; background: var(--acc); }
#stage .coinpill { display: inline-flex; align-items: center; gap: 5px; background: #fff; border-radius: 99px; padding: 3px 10px 3px 7px; font-weight: 800; color: #6a4a00; font-size: 14px; }
#stage .chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
#stage .chips.d4 { grid-template-columns: repeat(2, 1fr); }
#stage .chip { min-height: 48px; padding: 6px 8px; border-radius: 12px; border: 2px solid var(--line); background: #fff; color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 13px; }
#stage .chip small { font-size: 10px; opacity: .75; font-weight: 600; }
#stage .chip .sw { width: 22px; height: 6px; border-radius: 3px; display: block; }
#stage .chip.on { border-color: var(--acc); background: #ffe9d4; }
#stage .chip.locked { opacity: .55; }
#stage .info { background: #fff; border-radius: 12px; padding: 8px 10px; font-size: 13px; font-weight: 600; text-align: left; }
#stage .info.ok { background: #e2f8e8; color: #0b5a26; }
#stage .goal { margin: 0; font-size: 12px; font-weight: 700; color: #6b5a4a; }
#stage .note { margin: 0; font-size: 12px; color: #6b5a4a; text-align: left; }
#stage .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 8px 14px; border: 0; border-radius: 14px; background: var(--acc); color: #fff; font-weight: 800; font-size: 15px; box-shadow: 0 4px 0 var(--acc-d); }
#stage .btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--acc-d); }
#stage .btn.big { min-height: 58px; font-size: 24px; letter-spacing: 3px; background: #2fb25a; box-shadow: 0 5px 0 #1b7a3a; }
#stage .btn.small { min-height: 44px; font-size: 13px; padding: 6px 10px; }
#stage .btn.ghost { background: #fff; color: var(--acc-d); box-shadow: 0 4px 0 var(--line); }
#stage .btn.danger { background: #c8402f; box-shadow: 0 4px 0 #8a2a1e; }
#stage .btn.on { background: #8d8a98; box-shadow: none; }
#stage .btn.buy { background: #2f7bd8; box-shadow: 0 4px 0 #1d4f93; }
#stage .btn:disabled { opacity: .5; cursor: default; box-shadow: none; }
#stage .row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
#stage .row4.two { grid-template-columns: repeat(2, 1fr); }
#stage .list, #stage .mlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; text-align: left; }
#stage .item { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 14px; padding: 8px; }
#stage .item .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 14px; }
#stage .item small { font-size: 11px; color: #6b5a4a; }
#stage .swatch { width: 44px; height: 44px; border-radius: 12px; flex: none; border: 4px solid; }
#stage .pips { display: flex; gap: 3px; margin-top: 3px; }
#stage .pips i { width: 16px; height: 6px; border-radius: 3px; background: #ddd2c4; }
#stage .pips i.on { background: var(--green); }
#stage .mlist li { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: #fff; border-radius: 10px; padding: 8px 10px; font-size: 13px; font-weight: 700; }
#stage .mlist .mp { font-size: 12px; color: #6b5a4a; white-space: nowrap; }
#stage .mlist.ach li { font-size: 12px; font-weight: 600; }
#stage .mlist.ach li.done { background: #e2f8e8; }
#stage .seg { display: flex; gap: 4px; }
#stage .seg button { min-height: 44px; min-width: 56px; padding: 6px 10px; border: 2px solid var(--line); background: #fff; border-radius: 12px; font-weight: 800; font-size: 13px; color: var(--ink); }
#stage .seg button.on { border-color: var(--acc); background: #ffe9d4; color: var(--acc-d); }
#stage .setrow { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 800; font-size: 14px; }
#stage .stars { font-size: 34px; color: var(--sun); letter-spacing: 6px; text-shadow: 0 2px 0 rgba(90,60,0,.3); }
#stage .newbest { font-weight: 900; color: var(--acc-d); }
#stage .results .mlist li b { font-variant-numeric: tabular-nums; }

/* page below the game */
.rr-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.rr-bar .btn { min-height: 44px; min-width: 44px; }
.rr-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.rr-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.rr-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.rr-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.rr-guide p { margin-bottom: .5rem; font-size: .95rem; }
@media (prefers-reduced-motion: reduce) { #stage .hint-bubble, #stage .pwi.low { animation: none; } }
#stage .bestchip { position: absolute; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top, 0px) + 56px); background: rgba(20,24,40,.62); color: #fff; font-weight: 800; font-size: 12px; padding: 3px 10px; border-radius: 99px; pointer-events: none; z-index: 3; }
#stage .bestchip[hidden] { display: none; }
#stage .bestchip.near { background: rgba(224,112,42,.9); }
#stage .bestchip.hit { background: #2fae62; animation: rrbest .5s ease-out 2; }
@keyframes rrbest { 50% { transform: translateX(-50%) scale(1.18); } }
@media (prefers-reduced-motion: reduce) { #stage .bestchip.hit { animation: none; } }

/* Full screen on phones: the shell makes .game-wrap the stage; the 3D view fills it. */
html.pip-immersive .game-wrap.pip-stage, .game-wrap.pip-stage:fullscreen, .game-wrap.pip-stage:-webkit-full-screen { display: flex; flex-direction: column; align-items: stretch; justify-content: stretch; padding: 0; margin: 0; max-width: none; overflow: hidden; }
html.pip-immersive .game-wrap.pip-stage #stage, .game-wrap.pip-stage:fullscreen #stage, .game-wrap.pip-stage:-webkit-full-screen #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 .rr-bar, html.pip-immersive .rr-keys, html.pip-immersive .rr-guide, html.pip-immersive .ad-well,
.game-wrap.pip-stage:fullscreen .rr-bar, .game-wrap.pip-stage:fullscreen .rr-keys { display: none; }
html.pip-immersive #stage .pausebtn, html.pip-immersive #stage .pad { padding-left: 0; }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .pad { left: auto; right: max(8px, env(safe-area-inset-right)); width: min(46%, 340px); }
  html.pip-immersive #stage .bestchip { top: calc(env(safe-area-inset-top, 0px) + 8px); }
}
