/* Crumblekeep Siege 3D - stage + 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:#3a2a20; --cream:#fff3d6; --ter:#c2552b; --ter-d:#8f3a1a; --sun:#ffc21a; --green:#5cbf4a; --paper:#fff8e8;
  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(#6ec6ff, #e8f7ff); 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; }
#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 button:disabled { cursor: default; }

#stage #loader { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: linear-gradient(#6ec6ff, #e8f7ff); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-shadow: 0 3px 0 rgba(60,40,20,.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,.4); border-top-color: var(--sun); animation: csspin .8s linear infinite; }
@keyframes csspin { 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(40,28,20,.88); color: #fff; font-weight: 700; }
#stage #ctxlost[hidden], #stage #loader[hidden], #stage .hud[hidden], #stage .aimread[hidden], #stage .hintbub[hidden], #stage .act[hidden] { display: none; }

/* HUD */
#stage .hud { position: absolute; inset: 0; pointer-events: none; }
#stage .hud button { pointer-events: auto; }
#stage .hud-top { position: absolute; left: 0; right: 0; top: 0; padding: max(8px, env(safe-area-inset-top)) 8px 0; display: flex; align-items: flex-start; gap: 8px; }
#stage .ib { width: 44px; height: 44px; flex: none; border: 0; border-radius: 12px; background: rgba(58,42,32,.78); color: #fff; font-size: 17px; font-weight: 800; box-shadow: 0 3px 0 rgba(0,0,0,.25); }
#stage .hud-mid { flex: 1; min-width: 0; text-align: center; background: rgba(255,248,232,.88); border-radius: 12px; padding: 4px 8px; box-shadow: 0 2px 0 rgba(0,0,0,.15); }
#stage .hud-name { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#stage .hud-sub { display: block; font-size: 12px; font-weight: 700; color: var(--ter-d); }
#stage .aimread { position: absolute; left: 50%; top: 62px; transform: translateX(-50%); background: rgba(58,42,32,.82); color: #fff; font-weight: 800; font-size: 14px; padding: 4px 12px; border-radius: 99px; white-space: nowrap; }
#stage .hintbub { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); width: min(86%, 300px); background: rgba(255,255,255,.96); color: var(--ink); font-weight: 800; font-size: 14px; text-align: center; padding: 8px 12px; border-radius: 14px; box-shadow: 0 3px 0 rgba(0,0,0,.2); animation: csfloat 1.2s ease-in-out infinite alternate; }
@keyframes csfloat { to { transform: translate(-50%, -5px); } }
#stage .hud-bottom { position: absolute; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 6px; }
#stage .shotinfo { background: rgba(58,42,32,.78); color: #fff; font-weight: 800; font-size: 13px; padding: 3px 12px; border-radius: 99px; }
#stage .tray { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
#stage .ammo { position: relative; width: 58px; min-height: 58px; border: 3px solid transparent; border-radius: 14px; background: rgba(255,248,232,.9); color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 3px 2px; box-shadow: 0 3px 0 rgba(0,0,0,.25); }
#stage .ammo.sel { border-color: var(--ter); background: #fff; transform: translateY(-4px); }
#stage .ammo:disabled { opacity: .4; }
#stage .ammo .dot { width: 20px; height: 20px; border-radius: 50%; box-shadow: inset -3px -3px 0 rgba(0,0,0,.25); }
#stage .ammo .an { font-size: 10px; font-weight: 800; }
#stage .ammo .ct { position: absolute; right: -4px; top: -6px; min-width: 20px; height: 20px; border-radius: 10px; background: var(--ter); color: #fff; font-size: 12px; font-weight: 800; line-height: 20px; text-align: center; padding: 0 4px; }
#stage .act { min-height: 52px; min-width: 150px; border: 0; border-radius: 16px; background: var(--sun); color: #4a2e00; font-size: 18px; font-weight: 900; letter-spacing: 1px; box-shadow: 0 4px 0 #b57f00; animation: cspulse .6s ease-in-out infinite alternate; }
@keyframes cspulse { to { transform: scale(1.06); } }
#stage .feed { position: absolute; left: 0; right: 0; top: 70px; display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; }
#stage .toast { background: rgba(255,255,255,.95); color: var(--ink); font-weight: 800; font-size: 13px; padding: 4px 12px; border-radius: 99px; animation: csfeed 2.4s ease-out forwards; }
@keyframes csfeed { 0% { opacity: 0; transform: translateY(8px); } 12% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
#stage .floater { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 20px; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.55); pointer-events: none; animation: csrise 1.05s ease-out forwards; }
#stage .floater.good { color: #b8ff7a; }
@keyframes csrise { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.7); } 15% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -190%) scale(1.1); } }
#stage .flash { position: absolute; inset: 0; pointer-events: none; z-index: 5; animation: csflash .3s ease-out forwards; }
@keyframes csflash { to { opacity: 0; } }

/* screens */
#stage .screen { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom)); background: rgba(40,60,90,.28); pointer-events: auto; touch-action: pan-y; }
#stage .screen.dim { background: rgba(30,20,12,.55); }
#stage .panel { width: 100%; max-width: 380px; max-height: 100%; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; background: var(--paper); border-radius: 18px; padding: 14px; box-shadow: 0 6px 0 rgba(0,0,0,.25); text-align: center; position: relative; }
#stage .panel h2 { font-size: 22px; margin-bottom: 6px; }
#stage .panel h2.win { color: #2f8a1d; } #stage .panel h2.lose { color: var(--ter-d); }
#stage .panel h3 { font-size: 15px; margin: 8px 0 2px; }
#stage .tag { font-size: 13px; color: #6a5648; margin: 4px 0 8px; }
#stage .goal { font-size: 13px; font-weight: 700; color: var(--ter-d); margin: 10px 0 6px; }
#stage .logo { display: flex; flex-direction: column; align-items: center; margin: 4px 0; text-shadow: 0 3px 0 rgba(0,0,0,.18); }
#stage .logo b { font-size: clamp(26px, 8.5vw, 36px); letter-spacing: 2px; color: var(--ter); line-height: 1; }
#stage .logo span { font-size: clamp(16px, 5vw, 22px); letter-spacing: 6px; font-weight: 900; color: var(--ink); }
#stage .coins { position: absolute; right: 12px; top: 12px; background: var(--sun); color: #4a2e00; font-weight: 800; font-size: 13px; padding: 3px 10px; border-radius: 99px; }
#stage .panel h2 + .coins, #stage .logo ~ .coins { top: 10px; }
#stage .stack { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
#stage .row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 4px; }
#stage .btn { min-height: 48px; border: 0; border-radius: 14px; background: var(--ter); color: #fff; font-size: 16px; font-weight: 800; padding: 8px 14px; box-shadow: 0 4px 0 var(--ter-d); }
#stage .btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ter-d); }
#stage .btn.big { min-height: 56px; font-size: 19px; background: #e0701f; box-shadow: 0 4px 0 #9a4a0f; }
#stage .btn.sm { min-height: 44px; font-size: 14px; padding: 6px 8px; }
#stage .btn.ghost { background: #e9dcc4; color: var(--ink); box-shadow: 0 4px 0 #bba98a; }
#stage .btn.on { background: #3e8f2e; box-shadow: 0 4px 0 #276018; }
#stage .btn.danger { background: #a02323; box-shadow: 0 4px 0 #6a1212; }
#stage .btn.wide { width: 100%; margin-top: 8px; }
#stage .btn:disabled { opacity: .45; }
#stage .tabs { display: flex; gap: 6px; justify-content: center; margin: 8px 0; }
#stage .tab { width: 44px; height: 44px; border: 0; border-radius: 12px; background: #e9dcc4; color: var(--ink); font-weight: 800; font-size: 16px; }
#stage .tab.on { background: var(--ter); color: #fff; }
#stage .tab:disabled { opacity: .4; }
#stage .grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin: 8px 0; }
#stage .tile { min-height: 84px; border: 0; border-radius: 14px; background: #fff; color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 4px; box-shadow: 0 3px 0 #cdbb9a; }
#stage .tile b { font-size: 22px; color: var(--ter); }
#stage .tile .tn { font-size: 11px; font-weight: 700; line-height: 1.1; }
#stage .tile .st { font-size: 14px; color: #e0a800; letter-spacing: 1px; }
#stage .tile.new { outline: 3px solid var(--sun); }
#stage .tile.lock { opacity: .5; }
#stage .urow, #stage .arow { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 12px; padding: 6px 8px; text-align: left; }
#stage .uinfo { flex: 1; display: flex; flex-direction: column; font-size: 12px; min-width: 0; }
#stage .uinfo b { font-size: 14px; }
#stage .pips { color: var(--ter); letter-spacing: 2px; }
#stage .urow .btn { min-width: 84px; flex: none; }
#stage .arow.got { background: #e4f6d8; } #stage .rw { font-weight: 800; font-size: 12px; color: var(--ter-d); }
#stage .skins { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 6px 0; }
#stage .skin { width: 56px; min-height: 56px; border: 3px solid transparent; border-radius: 12px; background: #fff; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px; font-size: 11px; font-weight: 800; color: var(--ink); }
#stage .skin i { width: 26px; height: 18px; border-radius: 5px; display: block; }
#stage .skin.on { border-color: var(--ter); } #stage .skin:disabled { opacity: .5; }
#stage .seg { display: flex; align-items: center; gap: 6px; background: #fff; border-radius: 12px; padding: 4px 8px; }
#stage .seg span { font-weight: 800; font-size: 13px; min-width: 52px; text-align: left; }
#stage .seg .btn { flex: 1; padding: 4px 4px; }
#stage .stars { display: flex; gap: 6px; justify-content: center; margin: 4px 0 8px; font-size: 44px; color: #cfc2a6; }
#stage .stars span { display: inline-block; opacity: 0; animation: csstar .5s ease-out forwards; }
#stage .stars span.on { color: #f5b800; text-shadow: 0 3px 0 #b57f00; }
@keyframes csstar { 0% { opacity: 0; transform: scale(2.2) rotate(-20deg); } 100% { opacity: 1; transform: none; } }
#stage .rows { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; }
#stage .rrow b { animation: csrow .4s ease-out both; }
@keyframes csrow { from { transform: scale(1.35); opacity: 0; } to { transform: none; opacity: 1; } }
#stage .rrow { display: flex; justify-content: space-between; background: #fff; border-radius: 10px; padding: 5px 10px; font-size: 14px; }
#stage .ach { background: #fff1b8; color: #6a4a00; font-weight: 800; font-size: 13px; border-radius: 10px; padding: 5px 8px; margin: 4px 0; }

@media (min-width: 700px) { #stage.is-big .panel { max-width: 460px; } #stage.is-big .ammo { width: 68px; min-height: 66px; } }
@media (max-height: 560px) { #stage .logo b { font-size: 24px; } #stage .stars { font-size: 32px; } }
@media (prefers-reduced-motion: reduce) { #stage * { animation: none !important; transition: none !important; } #stage .stars span { opacity: 1; } }

/* page chrome under the game */
.cs-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.cs-bar .btn { min-height: 44px; min-width: 44px; }
.cs-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.cs-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.cs-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.cs-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.cs-guide p { margin-bottom: .5rem; font-size: .95rem; }

/* inside the site's own game shell (native or immersive full screen) keep the 9:16 stage fitting the viewport */
.game-wrap.pip-stage #stage { width: min(100%, calc((100vh - 64px) * 0.5625)); width: min(100%, calc((100svh - 64px) * 0.5625)); }

/* ---- full screen on phones (shell immersive + native): the board fills the stage under the dock, no scrolling ---- */
html.pip-immersive .game-wrap.pip-stage, html.pip-native .game-wrap.pip-stage { display: flex; flex-direction: column; overflow: hidden; padding-left: 0; padding-right: 0; padding-bottom: 0; }
html.pip-immersive .game-wrap.pip-stage #stage, html.pip-native .game-wrap.pip-stage #stage { flex: 1 1 auto; min-height: 0; width: 100%; max-width: none; height: auto; aspect-ratio: auto; margin: 0; border-radius: 0; }
html.pip-immersive .game-wrap.pip-stage > .cs-bar, html.pip-immersive .game-wrap.pip-stage > .cs-keys,
html.pip-native .game-wrap.pip-stage > .cs-bar, html.pip-native .game-wrap.pip-stage > .cs-keys,
html.pip-immersive .ad-well, html.pip-immersive .game-header, html.pip-immersive .cs-guide,
html.pip-immersive #similar-games, html.pip-immersive footer { display: none; }
html.pip-immersive .game-wrap.pip-stage #stage .panel { max-height: 100%; }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .panel { max-width: 520px; padding: 10px 14px; }
  html.pip-immersive #stage .panel h2 { font-size: 19px; margin-bottom: 4px; }
  html.pip-immersive #stage .ammo { width: 54px; min-height: 52px; }
  html.pip-immersive #stage .hud-bottom { bottom: max(4px, env(safe-area-inset-bottom)); gap: 3px; }
}

/* ---- finish: soft vignette over the 3D view, under the HUD and menus ---- */
#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(40,25,10,.22) 100%); }
