/* Kaiju Smash 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: #1d1530; --pur: #7a3cff; --pur-d: #4f1fc0; --grn: #3fd16a; --org: #ff9a1f; --red: #ff4d5a; --cream: #fff4dc;
  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(#9fd8ff, #dff2ff); 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; }
/* inside the site's own game shell (native or immersive full screen) keep the 9:16 stage fitting under the dock; it must never be taller than the shell's scroll area */
.game-wrap.pip-stage #stage { width: min(100%, calc((100vh - 64px) * 0.5625)); width: min(100%, calc((100svh - 64px) * 0.5625)); }
.game-wrap.pip-stage .er-bar, .game-wrap.pip-stage .er-keys { display: none; }
#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; }
#stage button: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(#7a3cff, #b79bff); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-shadow: 0 3px 0 rgba(40,10,110,.5); text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 32px); 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: #ffd23f; animation: kspin .8s linear infinite; }
@keyframes kspin { to { transform: rotate(360deg); } }
#stage #ctxlost { position: absolute; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; background: rgba(29,21,48,.92); 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; gap: 8px; align-items: flex-start; }
#stage .bars { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
#stage .bar { position: relative; height: 18px; border-radius: 9px; background: rgba(29,21,48,.6); overflow: hidden; border: 2px solid rgba(255,255,255,.7); }
#stage .bar i { display: block; height: 100%; width: 100%; background: var(--grn); transition: width .12s; }
#stage .bar.en { height: 12px; } #stage .bar.en i { background: #38b6ff; }
#stage .bar span { position: absolute; inset: 0; text-align: center; font-size: 11px; font-weight: 800; color: #fff; text-shadow: 0 1px 2px #000; line-height: 14px; }
#stage .sc { text-align: right; color: #fff; text-shadow: 0 2px 0 rgba(29,21,48,.7); min-width: 74px; }
#stage .sc b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
#stage .sc span { display: block; font-size: 11px; font-weight: 800; color: #ffe27a; min-height: 13px; white-space: nowrap; }
#stage .k-icon { pointer-events: auto; width: 44px; height: 44px; border-radius: 12px; border: 3px solid #fff; background: rgba(29,21,48,.7); color: #fff; font-weight: 900; font-size: 16px; letter-spacing: 2px; flex: 0 0 auto; }
#stage .goalbar { position: relative; margin-top: 6px; height: 16px; border-radius: 8px; background: rgba(29,21,48,.55); overflow: hidden; border: 2px solid rgba(255,255,255,.6); }
#stage .goalbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffb02e, #ff4d5a); transition: width .15s; }
#stage .goalbar span { position: absolute; inset: 0; text-align: center; font-size: 10px; font-weight: 800; color: #fff; text-shadow: 0 1px 2px #000; line-height: 12px; }
#stage .bossbar { position: relative; margin-top: 5px; height: 14px; border-radius: 7px; background: rgba(29,21,48,.6); overflow: hidden; border: 2px solid #ff4d5a; }
#stage .bossbar i { display: block; height: 100%; background: #ff4d5a; width: 100%; }
#stage .bossbar span { position: absolute; inset: 0; text-align: center; font-size: 9px; font-weight: 900; color: #fff; letter-spacing: 2px; line-height: 10px; }
#stage .feed { position: absolute; left: 0; right: 0; top: 118px; text-align: center; font-weight: 900; font-size: 18px; color: #fff; text-shadow: 0 2px 0 rgba(29,21,48,.8); min-height: 24px; padding: 0 10px; }
#stage .feed.chain { color: #ffe27a; } #stage .feed.mission { color: #9cffb0; }
#stage .hint { position: absolute; left: 12px; right: 12px; bottom: 214px; text-align: center; background: rgba(29,21,48,.8); color: #fff; border-radius: 14px; padding: 8px 12px; font-weight: 700; font-size: 14px; border: 2px solid #ffe27a; }
#stage .popups { position: absolute; inset: 0; overflow: hidden; }
#stage .pop { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 18px; color: #fff; text-shadow: 0 2px 0 #4f1fc0, 0 0 6px rgba(0,0,0,.4); animation: kpop .9s ease-out forwards; white-space: nowrap; }
#stage .pop.big { font-size: 26px; color: #ffe27a; }
@keyframes kpop { 0% { opacity: 1; margin-top: 0; } 100% { opacity: 0; margin-top: -46px; } }

/* controls */
#stage .controls { position: absolute; inset: 0; pointer-events: none; }
#stage .stick-base { display: none; position: absolute; left: 0; top: 0; width: 104px; height: 104px; border-radius: 50%; background: rgba(255,255,255,.22); border: 3px solid rgba(255,255,255,.7); pointer-events: none; }
#stage .stick-knob { position: absolute; left: 26px; top: 26px; width: 52px; height: 52px; border-radius: 50%; background: rgba(255,255,255,.85); box-shadow: 0 2px 6px rgba(0,0,0,.3); }
#stage .btns { position: absolute; right: 0; bottom: 0; width: 100%; height: 0; }
#stage .ab { position: absolute; pointer-events: auto; border-radius: 50%; border: 4px solid #fff; color: #fff; font-weight: 900; letter-spacing: .5px; text-shadow: 0 2px 0 rgba(0,0,0,.35); box-shadow: 0 5px 0 rgba(29,21,48,.5); touch-action: none; padding: 0; font-size: 12px; }
#stage .ab.down { transform: translateY(3px); box-shadow: 0 2px 0 rgba(29,21,48,.5); filter: brightness(1.15); }
#stage .ab.stomp { right: 14px; bottom: 22px; width: 88px; height: 88px; background: #ff5a3d; font-size: 15px; }
#stage .ab.tail { right: 112px; bottom: 28px; width: 66px; height: 66px; background: #ff9a1f; }
#stage .ab.throw { right: 16px; bottom: 124px; width: 66px; height: 66px; background: #3a86ff; }
#stage .ab.breath { right: 92px; bottom: 112px; width: 66px; height: 66px; background: #5a5f78; }
#stage .ab.breath.ready { background: #ff7a1a; animation: kglow 1s infinite alternate; }
#stage .ab.breath.lock { background: #3a3d52; opacity: .7; }
@keyframes kglow { to { box-shadow: 0 5px 0 rgba(29,21,48,.5), 0 0 16px 4px rgba(255,170,40,.9); } }

/* flash overlays always clear by timer */
#stage .flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .2s; }
#stage .flash.on { opacity: .35; } #stage .flash.hurt { background: #ff2030; } #stage .flash.win { background: #ffffff; }

/* screens */
#stage .screen { position: absolute; inset: 0; z-index: 20; pointer-events: auto; display: flex; align-items: center; justify-content: center; padding: 10px; background: rgba(79,31,192,.35); touch-action: pan-y; }
#stage .panel { width: 100%; max-height: 100%; background: var(--cream); border: 4px solid var(--ink); border-radius: 18px; padding: 14px 14px 16px; box-shadow: 0 8px 0 rgba(29,21,48,.35); text-align: center; }
#stage .panel.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; overscroll-behavior: contain; }
#stage .panel h3 { font-size: 22px; margin: 4px 0 8px; color: var(--pur-d); }
#stage .panel h3.win { color: #1c9b45; } #stage .panel h3.lose { color: var(--red); }
#stage .panel p { margin: 6px 0; font-size: 14px; } #stage .panel .sub { color: #5a4d78; font-size: 13px; } #stage .panel .sm { font-size: 12px; color: #5a4d78; margin: 2px 0; }
#stage .logo { font-size: 46px; line-height: .95; margin: 8px 0 4px; color: var(--pur); text-shadow: 0 3px 0 #fff, 0 6px 0 rgba(29,21,48,.25); letter-spacing: 1px; text-transform: uppercase; }
#stage .goal { font-size: 13px; font-weight: 700; color: var(--pur-d); background: #efe6ff; border-radius: 10px; padding: 8px; margin: 10px 0 2px; }
#stage .tip { font-size: 13px; background: #fff0c9; border-radius: 10px; padding: 6px 8px; }
#stage .rew { font-weight: 800; color: #c76a00; } #stage .ok { color: #1c7a3a; font-weight: 700; font-size: 13px; }
#stage .score b { font-size: 28px; color: var(--pur-d); }
#stage .menu { display: flex; flex-direction: column; gap: 9px; margin-top: 10px; }
#stage .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#stage .k-btn { min-height: 46px; min-width: 46px; padding: 8px 12px; border-radius: 14px; border: 3px solid var(--ink); background: #fff; color: var(--ink); font-weight: 800; font-size: 15px; box-shadow: 0 4px 0 rgba(29,21,48,.4); }
#stage .k-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(29,21,48,.4); }
#stage .k-btn small { font-weight: 600; font-size: 11px; display: block; opacity: .85; }
#stage .k-btn.big { min-height: 56px; font-size: 19px; background: var(--grn); }
#stage .k-btn.big.alt { background: #ffb02e; } #stage .k-btn.big.alt2 { background: #5ac8ff; }
#stage .k-btn.alt { background: #ffd23f; } #stage .k-btn.ghost { background: #efe6ff; } #stage .k-btn.dim { opacity: .55; } #stage .k-btn.danger { background: var(--red); color: #fff; }
#stage .k-btn:disabled { opacity: .5; cursor: default; }
#stage .panel > .k-btn.ghost { margin-top: 10px; width: 100%; }
#stage .topbar { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 4px; }
#stage .chip { background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 3px 9px; font-weight: 800; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
#stage .chip.dna { color: #0a8f6a; } #stage .rbar { display: inline-block; width: 44px; height: 8px; border-radius: 4px; background: #ddd; overflow: hidden; } #stage .rbar b { display: block; height: 100%; background: var(--pur); }
#stage .lv-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
#stage .lv { position: relative; min-height: 84px; border-radius: 14px; border: 3px solid var(--ink); background: #fff; padding: 6px 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; box-shadow: 0 4px 0 rgba(29,21,48,.35); color: var(--ink); }
#stage .lv b { font-size: 20px; color: var(--pur); } #stage .lv span { font-size: 10px; font-weight: 700; line-height: 1.1; } #stage .lv em { font-size: 9px; color: var(--red); font-style: normal; font-weight: 900; }
#stage .lv.locked { opacity: .5; box-shadow: none; } #stage .lock { color: #777; }
#stage .stars { color: #ffb02e; font-size: 14px; letter-spacing: 1px; } #stage .stars i { color: #cfc6e0; font-style: normal; } #stage .bigstars .stars { font-size: 36px; }
#stage .card, #stage .row { display: flex; align-items: center; gap: 8px; text-align: left; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 8px; margin: 8px 0; }
#stage .card.sel { border-color: var(--grn); background: #eaffef; } #stage .row.done { opacity: .6; }
#stage .card .sw { flex: 0 0 38px; height: 38px; border-radius: 50%; border: 3px solid var(--ink); }
#stage .ct { flex: 1 1 auto; min-width: 0; font-size: 14px; } #stage .ct p { margin: 2px 0; text-align: left; }
#stage .ca { display: flex; flex-direction: column; gap: 5px; flex: 0 0 auto; } #stage .ca .k-btn { min-height: 44px; font-size: 13px; padding: 4px 8px; }
#stage .row .k-btn { flex: 0 0 auto; min-width: 74px; }
#stage .need { font-size: 12px; font-weight: 800; color: #5a4d78; }
#stage .pips { display: inline-flex; gap: 3px; } #stage .pips u { width: 12px; height: 8px; border-radius: 3px; background: #ddd; } #stage .pips u.on { background: var(--pur); }
#stage .seg { display: flex; gap: 4px; } #stage .seg .k-btn { min-width: 0; padding: 4px 8px; font-size: 12px; }

.er-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.er-bar .btn { min-height: 44px; min-width: 44px; }
.er-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.er-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.er-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.er-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.er-guide p { margin-bottom: .5rem; font-size: .95rem; }
@media (max-height: 560px) and (orientation: landscape) { #stage .logo { font-size: 30px; } }
@media (prefers-reduced-motion: reduce) { #stage .pop, #stage .ab.breath.ready, #stage .spinner { animation: none; } }

#stage .hud.lowhp::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 70px 14px rgba(255,32,48,.55); animation: lowpulse 1s ease-in-out infinite; }
@keyframes lowpulse { 0%,100% { opacity: .35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #stage .hud.lowhp::after { animation: none; opacity: .7; } }

/* full screen on phones: the 3D view fills everything under the dock (portrait and landscape); the renderer follows via the stage ResizeObserver */
html.pip-immersive .game-wrap.pip-stage #stage { width: 100%; height: 100%; max-width: none; aspect-ratio: auto; border-radius: 0; margin: 0; }
html.pip-immersive #bigbtn, html.pip-immersive .er-bar, html.pip-immersive .er-keys { display: none; }
#stage::after { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 5; background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 58%, rgba(30,10,70,.28) 100%); }
#stage .hud { 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 .feed { top: 62px; font-size: 16px; }
  html.pip-immersive #stage .hint { bottom: 8px; left: 140px; right: 210px; padding: 6px 10px; font-size: 13px; }
  html.pip-immersive #stage .ab.stomp { right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); }
  html.pip-immersive #stage .ab.tail { right: calc(max(14px, env(safe-area-inset-right)) + 98px); bottom: max(18px, env(safe-area-inset-bottom)); }
  html.pip-immersive #stage .ab.throw { right: calc(max(14px, env(safe-area-inset-right)) + 4px); bottom: 112px; }
  html.pip-immersive #stage .ab.breath { right: calc(max(14px, env(safe-area-inset-right)) + 80px); bottom: 100px; }
  html.pip-immersive #stage .panel { overflow-y: auto; max-height: 100%; padding: 8px 12px 10px; }
  html.pip-immersive #stage .logo { font-size: 28px; margin: 2px 0; }
  html.pip-immersive #stage .panel p { margin: 3px 0; }
}

/* full screen (iPhone immersive and Android native): every menu panel scrolls inside the stage so its last button (Back) is always reachable */
html.pip-immersive #stage .screen, html.pip-native #stage .screen { align-items: stretch; padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
html.pip-immersive #stage .panel, html.pip-native #stage .panel { overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; overscroll-behavior: contain; max-height: 100%; margin: auto 0; }
html.pip-native .game-wrap.pip-stage #stage { width: 100%; height: 100%; max-width: none; aspect-ratio: auto; border-radius: 0; margin: 0; }
html.pip-native #bigbtn, html.pip-native .er-bar, html.pip-native .er-keys { display: none; }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-native #stage .panel { padding: 8px 12px 10px; }
  html.pip-native #stage .logo { font-size: 28px; margin: 2px 0; }
  html.pip-native #stage .panel p { margin: 3px 0; }
}
