/* Gemrail Rush 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 { --amber:#ffb02e; --amber-d:#c97d10; --ink:#2a1c12; --cream:#fff2d8; --cyan:#4de3ff; --panel:rgba(26,18,14,.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: #1a1210; color: var(--cream);
  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, #stage #ui input { pointer-events: auto; }
#stage button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
#stage button:focus-visible, #stage input:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
#stage button:disabled { opacity: .45; cursor: default; }

#stage #loader { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: #1a1210; }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--amber); 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; color: var(--cream); }
#stage .spinner { width: 42px; height: 42px; border-radius: 50%; border: 6px solid rgba(255,255,255,.2); border-top-color: var(--amber); animation: mcspin .8s linear infinite; }
@keyframes mcspin { 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(20,12,8,.88); color: #fff; font-weight: 700; }
#stage #ctxlost[hidden], #stage .hud[hidden], #stage .screen[hidden], #stage .pad[hidden], #stage .hint[hidden], #stage .banner[hidden], #stage .streak[hidden], #stage .prog[hidden], #stage .pip[hidden] { display: none; }

/* gem icon */
#stage .gi { display: inline-block; width: 14px; height: 18px; margin-right: 4px; vertical-align: -3px; background: linear-gradient(135deg, #fff3b0, var(--amber) 55%, var(--amber-d)); clip-path: polygon(50% 0, 100% 35%, 80% 100%, 20% 100%, 0 35%); }

/* 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; align-items: flex-start; gap: 6px; }
#stage .stat { background: rgba(20,12,8,.62); color: #fff; border-radius: 12px; padding: 4px 10px; display: flex; align-items: center; gap: 4px; min-height: 34px; }
#stage .stat b { font-size: 17px; font-variant-numeric: tabular-nums; }
#stage .stat .lbl { font-size: 11px; opacity: .8; }
#stage #hud-power { flex: 1; background: none; padding: 0; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
#stage .pip { background: #ffd36a; color: #3a2400; border-radius: 10px; padding: 4px 8px; font-size: 12px; font-weight: 800; }
#stage .pip.mag { background: #ff6a5a; color: #fff; }
#stage .icon-btn { width: 44px; height: 44px; min-width: 44px; border-radius: 12px; border: 0; background: rgba(20,12,8,.7); color: #fff; font-weight: 800; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; pointer-events: auto; }
#stage .prog { margin-top: 8px; height: 6px; border-radius: 4px; background: rgba(0,0,0,.4); overflow: hidden; }
#stage #hud-prog-fill { height: 100%; width: 0; background: var(--amber); }
#stage .hint { position: absolute; left: 12px; right: 12px; top: 22%; text-align: center; background: rgba(20,12,8,.78); border: 2px solid var(--amber); color: #fff; padding: 10px 12px; border-radius: 14px; font-weight: 700; font-size: 15px; pointer-events: none; }
#stage .streak { position: absolute; left: 0; right: 0; top: 24%; text-align: center; color: #ffd36a; font-size: clamp(18px, 6vw, 26px); font-weight: 900; text-shadow: 0 2px 0 rgba(0,0,0,.6); pointer-events: none; }
#stage .streak.pop { animation: streakpop .35s ease-out; }
@keyframes streakpop { from { transform: scale(1.5); opacity: .3; } to { transform: scale(1); opacity: 1; } }
#stage .banner { position: absolute; left: 0; right: 0; top: 14%; text-align: center; color: #fff; font-size: clamp(24px, 8vw, 38px); font-weight: 900; text-shadow: 0 3px 0 rgba(0,0,0,.55); pointer-events: none; }
#stage .pad { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; padding: 0 10px max(14px, env(safe-area-inset-bottom)); gap: 10px; }
#stage .pad > div { display: flex; gap: 10px; }
#stage .pad button { min-width: 70px; height: 64px; border-radius: 16px; border: 3px solid rgba(255,255,255,.6); background: rgba(20,12,8,.55); color: #fff; font-size: 18px; font-weight: 800; pointer-events: auto; touch-action: none; }
#stage .pad button.down { background: rgba(255,176,46,.7); }

/* screens */
#stage .screen { position: absolute; inset: 0; display: flex; align-items: stretch; justify-content: center; background: linear-gradient(rgba(10,6,4,.35), rgba(10,6,4,.7)); z-index: 20; }
#stage .screen[hidden] { display: none; }
#stage .panel { width: 100%; max-height: 100%; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; -webkit-overflow-scrolling: touch; padding: max(14px, env(safe-area-inset-top)) 14px 18px; display: flex; flex-direction: column; gap: 10px; }
#stage .screen.pause .panel, #stage .screen.results .panel, #stage .screen.error .panel, #stage .screen.loading .panel { justify-content: center; }
#stage h2 { font-size: 24px; text-align: center; color: var(--amber); letter-spacing: .5px; }
#stage h2.logo { font-size: clamp(30px, 10vw, 44px); margin-top: 4px; text-shadow: 0 3px 0 rgba(0,0,0,.5); }
#stage h3 { font-size: 15px; color: var(--c, var(--amber)); margin-top: 6px; }
#stage .sub, #stage .note, #stage .goal { text-align: center; font-size: 13px; color: #e8d5b8; }
#stage .note.ok { color: #9be58a; } #stage .goal { color: #fff; font-weight: 700; }
#stage .center { text-align: center; }
#stage .topline { display: flex; justify-content: space-between; align-items: center; font-weight: 800; }
#stage .wallet b, #stage .stars-total { font-size: 16px; }
#stage .btn { display: block; width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 14px; border: 0; background: var(--amber); color: #3a2400; font-size: 17px; font-weight: 800; box-shadow: 0 4px 0 var(--amber-d); }
#stage .btn.big { min-height: 58px; font-size: 20px; }
#stage .btn.alt { background: var(--cyan); color: #06303a; box-shadow: 0 4px 0 #1b9ab5; }
#stage .btn.ghost { background: rgba(255,255,255,.14); color: #fff; box-shadow: none; border: 2px solid rgba(255,255,255,.25); font-size: 14px; }
#stage .btn.small { width: auto; min-width: 74px; min-height: 44px; font-size: 15px; padding: 6px 12px; }
#stage .btn.danger { background: #d9534f; color: #fff; box-shadow: none; }
#stage .row { display: flex; gap: 8px; } #stage .row .btn { flex: 1; padding: 8px 4px; }
#stage .mine-pick { display: flex; align-items: center; gap: 8px; }
#stage .mine-name { flex: 1; text-align: center; background: rgba(0,0,0,.4); border-radius: 12px; padding: 6px; border-bottom: 3px solid var(--c); }
#stage .mine-name b { display: block; font-size: 17px; } #stage .mine-name span { font-size: 12px; color: #e8d5b8; }
#stage .grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
#stage .lv { min-height: 78px; border-radius: 12px; border: 2px solid rgba(255,255,255,.2); background: rgba(255,255,255,.1); color: #fff; padding: 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; }
#stage .lv b { font-size: 20px; color: var(--amber); } #stage .lv em { font-size: 12px; opacity: .7; }
#stage .stars b { color: rgba(255,255,255,.25); font-size: 18px; } #stage .stars b.on { color: var(--amber); }
#stage .tabs, #stage .seg { display: flex; gap: 6px; }
#stage .tabs button, #stage .seg button { flex: 1; min-height: 44px; border-radius: 12px; border: 2px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: #fff; font-weight: 700; }
#stage .tabs button.on, #stage .seg button.on { background: var(--amber); color: #3a2400; border-color: var(--amber); }
#stage .card { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: rgba(255,255,255,.1); border-radius: 12px; padding: 10px; }
#stage .card.col { flex-direction: column; align-items: stretch; } #stage .card.got { border: 2px solid #9be58a; }
#stage .card p { font-size: 12px; color: #e8d5b8; margin-top: 2px; }
#stage .card > div { flex: 1; min-width: 0; }
#stage .lvl { font-size: 12px; color: var(--amber); } #stage .maxed { font-size: 13px; font-weight: 800; color: var(--amber); text-align: right; }
#stage .swatch { width: 34px; height: 34px; border-radius: 8px; border: 4px solid; flex: none; }
#stage .meter { height: 8px; border-radius: 4px; background: rgba(0,0,0,.4); margin-top: 6px; overflow: hidden; } #stage .meter i { display: block; height: 100%; background: var(--cyan); }
#stage .sl { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 700; }
#stage input[type=range] { width: 100%; height: 36px; accent-color: var(--amber); }
#stage .stats { display: flex; gap: 8px; } #stage .stats div { flex: 1; background: rgba(255,255,255,.1); border-radius: 12px; padding: 8px 4px; text-align: center; }
#stage .stats span { display: block; font-size: 11px; color: #e8d5b8; } #stage .stats b { font-size: 17px; }
#stage .flag { text-align: center; color: var(--cyan); font-weight: 800; } #stage .earn { text-align: center; font-size: 20px; font-weight: 900; color: var(--amber); }

.mc-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.mc-bar .btn { min-height: 44px; min-width: 44px; }
.mc-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.mc-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.mc-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.mc-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.mc-guide p { margin-bottom: .5rem; font-size: .95rem; }
@media (prefers-reduced-motion: reduce) { #stage .spinner { animation-duration: 2s; } #stage .streak.pop { animation: none; } }

/* Full screen on phones (shell immersive on iPhone, native Fullscreen API on Android): the board fills the stage under the dock. */
html.pip-immersive .game-wrap, html.pip-native .game-wrap, .game-wrap:fullscreen { display: flex; flex-direction: column; align-items: stretch; padding: 0; margin: 0; max-width: none; }
html.pip-immersive .game-wrap #stage, html.pip-native .game-wrap #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 .mc-bar, html.pip-immersive .mc-keys, html.pip-native .mc-bar, html.pip-native .mc-keys, .game-wrap:fullscreen .mc-bar, .game-wrap:fullscreen .mc-keys { display: none; }
html.pip-immersive #stage .pad, html.pip-native #stage .pad { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .panel, html.pip-native #stage .panel { padding-top: 10px; padding-bottom: 10px; }
}
/* Depth: a soft vignette over the 3D view, drawn by CSS so it costs no frame time. */
#stage #app::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 55%, rgba(0,0,0,0) 55%, rgba(10,6,4,.38) 100%); }
/* Full screen: keep the Back button pinned inside the scrolling panel so it is always on screen. */
html.pip-immersive #stage .panel > .btn.ghost[data-act="home"], html.pip-native #stage .panel > .btn.ghost[data-act="home"] { position: sticky; bottom: 0; z-index: 2; flex: 0 0 auto; min-height: 48px; background: #3b2a1f; margin-bottom: max(0px, env(safe-area-inset-bottom)); }
