/* Cairnwatch 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 { --moss:#2f8a5b; --moss-d:#1f6140; --ink:#1d2a2a; --paper:#f6f1e2; --gold:#ffc83d; --ember:#ff8a3d; --bad:#e5534b;
  position: relative; width: min(100%, calc(78vh * 0.5625)); width: min(100%, calc(78svh * 0.5625)); aspect-ratio: 9 / 16; min-width: min(100%, 320px); margin: 0 auto; overflow: hidden;
  border-radius: 14px; background: #bfe3f5; color: #fff; 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; color: inherit; }
#stage button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
#stage [hidden] { display: none !important; }
#stage.hurt::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 60px 14px rgba(229,83,75,.55); z-index: 30; }

#stage #loader { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: linear-gradient(#2f8a5b, #bfe3f5); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; text-shadow: 0 2px 0 rgba(0,0,0,.35); 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: 40px; height: 40px; border-radius: 50%; border: 6px solid rgba(255,255,255,.35); border-top-color: var(--gold); animation: tdspin .8s linear infinite; }
@keyframes tdspin { 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(20,32,30,.9); color: #fff; font-weight: 700; }

/* HUD */
#stage .hud { position: absolute; inset: 0; pointer-events: none; }
#stage .hud-top { position: absolute; left: 0; right: 0; top: 0; display: flex; flex-wrap: wrap; row-gap: 2px; align-items: center; justify-content: space-between; gap: 6px; padding: max(6px, env(safe-area-inset-top)) 8px 4px; min-height: 52px; }
#stage .hud-l, #stage .hud-r { display: flex; gap: 6px; align-items: center; }
#stage .chip { display: inline-flex; align-items: center; gap: 4px; background: rgba(20,40,34,.72); border-radius: 12px; padding: 4px 9px; min-height: 32px; font-size: 14px; }
#stage .chip b { font-variant-numeric: tabular-nums; font-size: 15px; }
#stage .chip.lives.low { background: rgba(160,40,34,.85); }
#stage .chip.wave { flex-direction: column; gap: 0; order: 3; margin: 0 auto; font-size: 12px; font-weight: 700; padding: 4px 8px; text-align: center; }
#stage .hbtn { pointer-events: auto; min-width: 44px; min-height: 44px; border: 0; border-radius: 12px; background: rgba(20,40,34,.8); font-weight: 800; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; }
#stage .hbtn:active { background: rgba(47,138,91,.95); }

#stage .tbar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 6px; padding: 6px 6px max(8px, env(safe-area-inset-bottom)); pointer-events: none; background: linear-gradient(transparent, rgba(16,32,28,.55) 40%); }
#stage .tbtn { pointer-events: auto; flex: 1 1 0; min-width: 46px; min-height: 64px; border: 2px solid rgba(255,255,255,.18); border-radius: 12px; background: rgba(24,46,40,.92); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 4px 2px; touch-action: none; }
#stage .tbtn .sw { display: block; width: 20px; height: 20px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); }
#stage .tbtn b { font-size: 12px; }
#stage .tbtn .cost { font-size: 13px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
#stage .tbtn.poor .cost { color: #ff9a92; }
#stage .tbtn.poor { opacity: .72; }
#stage .tbtn.on { border-color: var(--gold); background: rgba(47,138,91,.95); opacity: 1; }
#stage .tbtn.call { background: var(--moss); touch-action: manipulation; }
#stage .tbtn.call span { font-size: 11px; font-weight: 700; }
#stage .tbtn.call.off { opacity: .45; }

#stage .hintbubble { position: absolute; left: 10px; right: 10px; top: 104px; pointer-events: auto; background: var(--paper); color: var(--ink); border-radius: 12px; padding: 10px 12px; font-size: 14px; font-weight: 600; box-shadow: 0 4px 14px rgba(0,0,0,.3); z-index: 5; }
#stage .banner { position: absolute; left: 0; right: 0; top: 24%; text-align: center; pointer-events: none; text-shadow: 0 3px 0 rgba(0,0,0,.4); animation: tdpop .35s ease-out; z-index: 5; }
#stage .banner b { display: block; font-size: 32px; letter-spacing: 1px; }
#stage .banner span { font-size: 15px; }
@keyframes tdpop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#stage .toast { position: absolute; left: 50%; transform: translateX(-50%); bottom: 96px; max-width: 90%; background: rgba(20,32,30,.9); border-radius: 18px; padding: 8px 14px; font-size: 14px; font-weight: 700; pointer-events: none; z-index: 6; text-align: center; }
#stage .toast.warn { background: rgba(160,40,34,.92); }
#stage .toast.good { background: rgba(31,97,64,.95); }
#stage .dragghost { position: fixed; transform: translate(-50%, -140%); background: var(--gold); color: #3a2a00; font-weight: 800; font-size: 13px; padding: 6px 10px; border-radius: 10px; pointer-events: none; z-index: 100000; }

#stage .tpanel { position: absolute; left: 6px; right: 6px; bottom: 82px; pointer-events: auto; background: rgba(20,36,32,.96); border: 2px solid rgba(255,255,255,.18); border-radius: 14px; padding: 8px; z-index: 7; }
#stage .tpanel.top { bottom: auto; top: 86px; }
#stage .prow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#stage .prow.btns { margin-top: 6px; align-items: stretch; flex-wrap: nowrap; }
#stage .pname { font-size: 15px; }
#stage .ptier { font-size: 12px; opacity: .85; flex: 1; }
#stage .pstats { font-size: 12px; opacity: .9; margin-top: 4px; }
#stage .pbtn { min-height: 44px; min-width: 44px; border: 0; border-radius: 10px; background: rgba(255,255,255,.14); font-size: 12px; font-weight: 700; padding: 4px 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#stage .pbtn.small { flex-direction: row; font-size: 12px; }
#stage .pbtn.x { font-size: 22px; }
#stage .pbtn.up { flex: 1 1 0; background: var(--moss); }
#stage .pbtn.up.poor { background: #5b6a66; }
#stage .pbtn.up span { color: var(--gold); font-size: 13px; }
#stage .pbtn.branch em { font-style: normal; font-size: 10px; font-weight: 500; opacity: .9; text-align: center; }
#stage .pbtn.sell { background: #8a4a2f; min-width: 64px; }
#stage .pmax { flex: 1; align-self: center; font-size: 13px; opacity: .85; }

/* screens */
#stage .screen { position: absolute; inset: 0; pointer-events: auto; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; -webkit-overflow-scrolling: touch; padding: max(14px, env(safe-area-inset-top)) 14px 16px; display: flex; flex-direction: column; gap: 10px; background: linear-gradient(rgba(16,36,30,.72), rgba(16,36,30,.9)); z-index: 20; }
#stage .logo { text-align: center; margin: 6px 0 2px; }
#stage .logo h1 { font-size: clamp(28px, 9vw, 40px); letter-spacing: 2px; text-shadow: 0 3px 0 rgba(0,0,0,.4); }
#stage .logo p { font-size: 14px; opacity: .9; }
#stage .logo-mark { display: block; width: 46px; height: 40px; margin: 0 auto 4px; background: linear-gradient(#cfd4dc, #8d939e); clip-path: polygon(50% 0, 90% 38%, 100% 100%, 0 100%, 10% 38%); }
#stage .chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
#stage .stitle h2 { font-size: 24px; }
#stage .stitle p { font-size: 13px; opacity: .88; margin-top: 2px; }
#stage .sbtn { min-height: 48px; border: 0; border-radius: 12px; background: rgba(255,255,255,.16); padding: 8px 14px; font-size: 15px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
#stage .sbtn b { font-size: 17px; }
#stage .sbtn span { font-size: 12px; opacity: .9; font-weight: 500; }
#stage .sbtn.primary { background: var(--moss); }
#stage .sbtn.ghost { background: rgba(255,255,255,.08); }
#stage .sbtn.small { min-height: 44px; font-size: 14px; padding: 6px 10px; }
#stage .sbtn.small b { font-size: 15px; }
#stage .sbtn.poor { opacity: .6; }
#stage .sbtn.danger { background: #8a3a34; }
#stage .sbtn:disabled { opacity: .45; }
#stage .row2 { display: flex; gap: 8px; }
#stage .row2 > * { flex: 1 1 0; }
#stage .list { display: flex; flex-direction: column; gap: 8px; }
#stage .lcard { display: flex; align-items: center; gap: 10px; min-height: 56px; border: 0; border-radius: 12px; background: rgba(255,255,255,.14); padding: 8px 12px; text-align: left; width: 100%; }
#stage .lcard.locked { opacity: .5; }
#stage .lnum { width: 30px; height: 30px; border-radius: 50%; background: var(--moss); display: flex; align-items: center; justify-content: center; font-weight: 800; flex: none; }
#stage .linfo { flex: 1; display: flex; flex-direction: column; }
#stage .linfo em { font-style: normal; font-size: 12px; opacity: .85; }
#stage .lstars { color: var(--gold); font-size: 17px; letter-spacing: 1px; flex: none; }
#stage .wrow { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.1); border-radius: 12px; padding: 8px 10px; }
#stage .wrow.col { flex-direction: column; align-items: stretch; }
#stage .wrow.got { background: rgba(47,138,91,.35); }
#stage .winfo { flex: 1; display: flex; flex-direction: column; gap: 1px; }
#stage .winfo span { font-size: 12px; opacity: .85; }
#stage .pips { color: var(--gold); letter-spacing: 2px; font-style: normal; font-size: 12px; }
#stage .reward { color: var(--gold); font-weight: 800; }
#stage .seg { display: flex; gap: 6px; margin-top: 6px; }
#stage .seg .sbtn { flex: 1; }
#stage .sw { display: block; width: 22px; height: 22px; border-radius: 50%; flex: none; border: 2px solid rgba(255,255,255,.7); }
#stage .helptext p { font-size: 14px; margin-bottom: 6px; }
#stage .rbox { background: rgba(255,255,255,.1); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
#stage .rstars { color: var(--gold); font-size: 38px; letter-spacing: 4px; }
#stage .rline { font-size: 16px; display: flex; gap: 4px; align-items: center; }
#stage .rline.sm { font-size: 12px; opacity: .85; }
#stage .rach { font-size: 13px; color: #b9f3cf; }
#stage .goal { text-align: center; font-size: 14px; }

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

@media (orientation: landscape) and (max-height: 520px) {
  #stage .tbtn { min-height: 56px; }
  #stage .hintbubble { top: 76px; }
  #stage .tpanel { bottom: 72px; }
}
#stage .wnext { display: block; font-size: 11px; font-weight: 600; opacity: .85; max-width: 100%; }
@media (prefers-reduced-motion: reduce) { #stage .banner { animation: none; } #stage .spinner { animation-duration: 2s; } }

/* Full screen (shell immersive/native): the stage fills the area under the dock; page chrome is hidden, never removed. */
html.pip-immersive .game-wrap { display: flex; flex-direction: column; align-items: stretch; padding: 0; margin: 0; max-width: none; }
html.pip-immersive .game-wrap > #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 .td-bar, html.pip-immersive .td-keys, html.pip-immersive .game-wrap > .game-title { display: none; }
html.pip-immersive #stage .tbtn { min-height: 56px; }
@media (orientation: landscape) {
  html.pip-immersive #stage .hintbubble { top: 56px; }
  html.pip-immersive #stage .tpanel { bottom: 64px; }
}
