/* Knight Arena 3D - stage, HUD, touch controls and menu screens. Everything is scoped under #stage. */
html.pip-big, html.pip-big body { overflow: hidden; }
#stage { --bronze:#c2762b; --gold:#ffc83d; --ink:#1d1a2e; --card:#2a2646; --card2:#383260; --txt:#f6efe0; --red:#e0503c; --green:#5fcf7a; --stam:#ffd23f;
  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: #2b2a44; color: var(--txt);
  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%; touch-action: none; }
#stage #ui { position: absolute; inset: 0; pointer-events: none; }
#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(#2b2a44, #5a3d34); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 0 22px; color: #fff; }
#stage .load-in b { font-size: clamp(20px, 6vw, 30px); letter-spacing: 3px; }
#stage .load-in span { font-size: 14px; opacity: .95; }
#stage .spinner { width: 40px; height: 40px; border-radius: 50%; border: 6px solid rgba(255,255,255,.3); border-top-color: var(--gold); animation: kaspin .8s linear infinite; }
@keyframes kaspin { 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,20,40,.88); font-weight: 700; }

/* HUD */
#stage .hud { position: absolute; inset: 0; pointer-events: none; }
#stage .hud.dim .btns, #stage .hud.dim #stickzone { pointer-events: none; }
#stage .hud-top { position: absolute; left: 8px; right: 8px; top: max(8px, env(safe-area-inset-top)); display: flex; gap: 8px; align-items: flex-start; }
#stage .bars { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
#stage .bar { position: relative; height: 18px; border-radius: 9px; background: rgba(10,8,25,.65); overflow: hidden; border: 1px solid rgba(255,255,255,.25); }
#stage .bar i { display: block; height: 100%; width: 100%; background: linear-gradient(#ff7a62, var(--red)); transition: width .12s linear; }
#stage .bar.st { height: 12px; }
#stage .bar.st i { background: linear-gradient(#ffe680, var(--stam)); }
#stage .bar.st.low i { background: #ff9a3c; animation: kablink .4s steps(2) infinite; }
@keyframes kablink { 50% { opacity: .45; } }
#stage .bar b { position: absolute; inset: 0; text-align: center; font-size: 12px; line-height: 18px; text-shadow: 0 1px 2px #000; }
#stage .info { display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; font-weight: 700; text-shadow: 0 1px 3px #000; min-width: 62px; }
#stage .iconbtn { pointer-events: auto; width: 44px; height: 44px; border-radius: 12px; border: 2px solid rgba(255,255,255,.4); background: rgba(10,8,25,.6); font-weight: 900; font-size: 16px; }
#stage .hud.lowhp .bar.hp { animation: kablink .6s steps(2) infinite; }
#stage .bossbar { position: absolute; left: 12px; right: 12px; top: 72px; text-align: center; font-size: 13px; font-weight: 800; text-shadow: 0 1px 3px #000; }
#stage .bossbar .bar { height: 12px; margin-top: 2px; }
#stage .bossbar .bar i { background: linear-gradient(#c78bff, #7b3fd1); }
#stage .chain { position: absolute; left: 0; right: 0; top: 104px; text-align: center; font-weight: 900; font-size: 18px; color: var(--gold); text-shadow: 0 2px 4px #000; }
#stage .hint { position: absolute; left: 14px; right: 14px; top: 38%; text-align: center; padding: 10px 14px; border-radius: 12px; background: rgba(10,8,25,.78); font-weight: 700; font-size: 15px; border: 1px solid rgba(255,255,255,.3); }

#stage #stickzone { position: absolute; left: 0; right: 46%; top: 70px; bottom: 0; pointer-events: auto; touch-action: none; }
#stage .hud.lefty #stickzone { left: 46%; right: 0; }
#stage #stickvis { position: absolute; inset: 0; pointer-events: none; }
#stage #stickvis .base { position: absolute; left: 0; top: 0; width: 110px; height: 110px; border-radius: 50%; border: 3px solid rgba(255,255,255,.4); background: rgba(255,255,255,.08); }
#stage #stickvis .knob { position: absolute; left: 0; top: 0; width: 48px; height: 48px; border-radius: 50%; background: rgba(255,255,255,.55); border: 2px solid #fff; }

#stage .btns { position: absolute; right: 8px; bottom: max(12px, env(safe-area-inset-bottom)); width: 200px; height: 200px; pointer-events: none; }
#stage .hud.lefty .btns { right: auto; left: 8px; }
#stage .cb { position: absolute; pointer-events: auto; touch-action: none; border-radius: 50%; border: 3px solid rgba(255,255,255,.55); font-weight: 900; font-size: 12px; letter-spacing: .5px; color: #fff; text-shadow: 0 1px 2px #000; box-shadow: 0 4px 0 rgba(0,0,0,.35); -webkit-touch-callout: none; padding: 0; }
#stage .cb span { pointer-events: none; }
#stage .cb.down { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.35); filter: brightness(1.25); }
#stage .cb.atk { right: 0; bottom: 0; width: 92px; height: 92px; background: #d9462f; font-size: 14px; }
#stage .cb.hvy { right: 14px; bottom: 104px; width: 66px; height: 66px; background: #8a45c9; }
#stage .cb.blk { right: 106px; bottom: 6px; width: 70px; height: 70px; background: #2f7fd1; }
#stage .cb.rol { right: 94px; bottom: 88px; width: 62px; height: 62px; background: #2f9d6a; }
#stage .hud.lefty .cb.atk { right: auto; left: 0; } #stage .hud.lefty .cb.hvy { right: auto; left: 14px; } #stage .hud.lefty .cb.blk { right: auto; left: 106px; } #stage .hud.lefty .cb.rol { right: auto; left: 94px; }

#stage .banner { position: absolute; left: 0; right: 0; top: 24%; text-align: center; opacity: 0; transform: scale(.85); pointer-events: none; }
#stage .banner.on { animation: kabanner 1.4s ease-out forwards; }
@keyframes kabanner { 0% { opacity: 0; transform: scale(.7); } 12% { opacity: 1; transform: scale(1.05); } 20% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }
#stage .b-main { font-size: clamp(24px, 8vw, 38px); font-weight: 900; letter-spacing: 2px; color: var(--gold); text-shadow: 0 3px 0 #5a2a00, 0 0 12px #000; }
#stage .b-sub { font-size: 14px; font-weight: 700; text-shadow: 0 1px 3px #000; }
#stage .flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
#stage .flash.on { opacity: 1; animation: kaflash .26s ease-out forwards; }
#stage .flash.hurt { background: radial-gradient(transparent 45%, rgba(220,30,20,.55)); }
#stage .flash.parry { background: radial-gradient(transparent 40%, rgba(255,255,255,.4)); }
@keyframes kaflash { from { opacity: 1; } to { opacity: 0; } }

/* screens */
#stage .screen { position: absolute; inset: 0; z-index: 20; pointer-events: auto; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; -webkit-overflow-scrolling: touch; padding: 10px 12px 18px; background: linear-gradient(rgba(24,20,44,.9), rgba(30,22,38,.94)); }
#stage .screen.overlay { background: rgba(14,10,28,.82); display: flex; flex-direction: column; justify-content: center; }
#stage .topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; min-height: 44px; }
#stage .pills { display: flex; gap: 6px; align-items: center; }
#stage .pill { background: rgba(255,255,255,.14); border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 800; white-space: nowrap; }
#stage .gold { background: rgba(255,200,61,.18); color: var(--gold); border-radius: 999px; padding: 4px 10px 4px 12px; font-size: 13px; font-weight: 900; display: inline-flex; align-items: center; gap: 5px; }
#stage .gold i { width: 12px; height: 12px; border-radius: 50%; background: var(--gold); display: inline-block; box-shadow: inset -2px -2px 0 #b9831a; }
#stage .title { text-align: center; margin: 4px 0 10px; }
#stage .title h2 { font-size: clamp(26px, 9vw, 40px); letter-spacing: 3px; color: var(--gold); text-shadow: 0 3px 0 #5a2a00; }
#stage .title p { font-size: 13px; opacity: .85; }
#stage h3 { font-size: 20px; margin: 4px 0 8px; text-align: center; letter-spacing: 1px; }
#stage .xp { margin: 0 0 10px; text-align: center; } #stage .xp small { font-size: 11px; opacity: .8; }
#stage .meter { height: 8px; border-radius: 4px; background: rgba(255,255,255,.14); overflow: hidden; margin: 4px 0; } #stage .meter i { display: block; height: 100%; background: linear-gradient(#ffd96a, var(--bronze)); }
#stage .b { display: block; width: 100%; min-height: 48px; margin: 6px 0; border-radius: 12px; border: 2px solid rgba(255,255,255,.28); background: var(--card2); font-weight: 800; font-size: 15px; padding: 8px 12px; }
#stage .b small { display: block; font-size: 11px; font-weight: 600; opacity: .85; }
#stage .b.big { background: linear-gradient(#e98b3c, #b85a1a); font-size: 20px; letter-spacing: 2px; min-height: 60px; border-color: #ffd7a0; }
#stage .b.small { display: inline-block; width: auto; min-width: 44px; margin: 4px 3px; font-size: 13px; min-height: 44px; }
#stage .b.ghost { background: transparent; } #stage .b.link { display: inline; width: auto; min-height: 44px; border: 0; background: none; text-decoration: underline; font-size: 13px; padding: 4px 6px; }
#stage .b.tab { display: inline-block; width: auto; min-height: 40px; margin: 2px; font-size: 13px; background: var(--card); } #stage .b.tab.on, #stage .b.on { background: #3d7c4f; }
#stage .b.buy { background: #3d7c4f; } #stage .b.poor { background: #5a3440; } #stage .b.locked { opacity: .55; }
#stage .grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin: 6px 0; }
#stage .card { border-radius: 12px; border: 2px solid rgba(255,255,255,.25); background: var(--card); padding: 8px 6px; min-height: 76px; display: flex; flex-direction: column; justify-content: center; gap: 3px; text-align: center; }
#stage .card b { font-size: 13px; } #stage .card span, #stage .card small { font-size: 11px; opacity: .85; } #stage .card.locked { opacity: .5; }
#stage .row { display: flex; flex-wrap: wrap; justify-content: center; }
#stage .note { font-size: 12px; text-align: center; opacity: .9; margin: 8px 0; }
#stage .list { display: flex; flex-direction: column; gap: 6px; }
#stage .item { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--card); border-radius: 12px; padding: 8px 10px; border: 1px solid rgba(255,255,255,.15); }
#stage .item.done { background: #25422f; } #stage .item > div { flex: 1; min-width: 0; } #stage .item b { font-size: 14px; display: block; } #stage .item small { display: block; font-size: 11px; opacity: .8; } #stage .item em { font-style: normal; font-size: 11px; opacity: .8; }
#stage .row-tier { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; border-radius: 12px; border: 2px solid rgba(255,255,255,.2); background: var(--card); padding: 6px 10px; text-align: left; }
#stage .row-tier.next { border-color: var(--gold); background: var(--card2); } #stage .row-tier.locked { opacity: .5; }
#stage .row-tier em { font-style: normal; font-weight: 900; font-size: 20px; width: 30px; text-align: center; color: var(--gold); } #stage .row-tier span { flex: 1; } #stage .row-tier b { display: block; font-size: 14px; } #stage .row-tier small { font-size: 11px; opacity: .8; }
#stage .stars { color: var(--gold); letter-spacing: 2px; } #stage .stars s { text-decoration: none; opacity: .25; } #stage .lock { font-size: 11px; opacity: .8; }
#stage .set { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px; padding: 8px 10px; font-size: 14px; font-weight: 700; } #stage .set span { width: 110px; } #stage .set input { flex: 1; min-height: 32px; touch-action: pan-y; }
#stage .seg { display: flex; } #stage .center { text-align: center; } #stage .center .b { max-width: 300px; margin-left: auto; margin-right: auto; }
#stage .perks { display: flex; flex-direction: column; gap: 8px; } #stage .card.perk { min-height: 70px; }
#stage .rew { display: flex; justify-content: center; gap: 8px; margin: 8px 0; }
#stage .stat, #stage .bonus { list-style: none; margin: 6px auto; max-width: 300px; font-size: 13px; text-align: left; } #stage .stat li { display: flex; justify-content: space-between; padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,.12); }
#stage .bonus li { color: var(--gold); font-weight: 700; padding: 1px 0; text-align: center; }
#stage .results.win h3 { color: var(--gold); font-size: 28px; } #stage .results.lose h3 { color: #ff8f7a; font-size: 26px; }
#stage .text p { font-size: 14px; line-height: 1.45; padding: 4px 4px; }

/* page chrome around the stage */
.ka-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.ka-bar .btn { min-height: 44px; min-width: 44px; }
.ka-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.ka-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.ka-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.ka-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.ka-guide p { margin-bottom: .5rem; font-size: .95rem; }
@media (max-width: 380px) { #stage .cb.atk { width: 84px; height: 84px; } #stage .grid { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { #stage .banner.on, #stage .flash.on { animation-duration: .01s; } }
/* inside the site game shell (native or immersive full screen) keep the 9:16 stage fitting the viewport */
/* full screen (shell): stage fills the area under the dock at any aspect; renderer resizes via PIPShell.onResize */
.game-wrap.pip-stage { display: flex; flex-direction: column; overflow: hidden; }
.game-wrap.pip-stage #stage { flex: 1 1 auto; min-height: 0; width: 100%; max-width: none; aspect-ratio: auto; border-radius: 0; margin: 0; }
.game-wrap.pip-stage .ka-bar, .game-wrap.pip-stage .ka-keys, html.pip-immersive .ka-bar, html.pip-immersive .ka-keys { display: none; }
html.pip-immersive .game-wrap.pip-stage { padding-bottom: 0 !important; }
html.pip-immersive .game-wrap.pip-stage #stage, html.pip-native .game-wrap.pip-stage #stage { padding-bottom: 0; }
#bigbtn[hidden], .ka-bar[hidden] { display: none; }

#stage .chain.pop { animation: kachain .22s ease-out; }
#stage .chain.hot { color: #ffb347; font-size: 22px; }
#stage .chain.max { color: #ff7a4d; font-size: 26px; }
#stage .iconbtn.off { opacity: .5; text-decoration: line-through; }
#stage .hud-top .iconbtn { min-width: 44px; min-height: 44px; }
@keyframes kachain { from { transform: scale(1.5); } to { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { #stage .chain.pop { animation: none; } }
