/* Hearthmoor 3D - stage + in-game UI, scoped under #stage so site styles never leak in. */
html.kb-big, html.kb-big body { overflow: hidden; }
#stage { --leaf:#4c8c3f; --leaf-d:#2f6a2a; --gold:#ffcc4d; --ink:#2a2a24; --cream:#fff6dc; --red:#e0483a; --wood:#8a5a34;
  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: #bfe6c8; color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; line-height: 1.25; }
/* inside the site shell's full screen the stage may use the whole height */
.game-wrap.pip-stage #stage { width: min(100%, calc((100vh - 64px) * 0.5625)); width: min(100%, calc((100svh - 64px) * 0.5625)); }
#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 #ui button, #stage #ui .panel, #stage #ui input, #stage #ui .pal, #stage #ui .info { pointer-events: auto; }
#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: 60; display: flex; align-items: center; justify-content: center; background: linear-gradient(#7dc27a, #cfe9b5); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-shadow: 0 3px 0 rgba(30,70,30,.45); text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 30px); letter-spacing: 3px; }
#stage .spinner { width: 40px; height: 40px; border-radius: 50%; border: 6px solid rgba(255,255,255,.4); border-top-color: var(--gold); animation: kbspin .8s linear infinite; }
@keyframes kbspin { to { transform: rotate(360deg); } }
#stage #ctxlost, #stage #nogl { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; background: rgba(30,50,30,.9); color: #fff; font-weight: 700; }

/* HUD */
#stage .hud { position: absolute; left: 0; right: 0; top: 0; padding: max(6px, env(safe-area-inset-top)) 6px 4px; pointer-events: none; background: linear-gradient(rgba(20,40,20,.55), rgba(20,40,20,0)); }
#stage .hud-top, #stage .hud-mid { display: flex; gap: 4px; align-items: center; }
#stage .hud-mid { margin-top: 4px; }
#stage .chip { background: rgba(30,50,25,.72); color: #fff; border-radius: 10px; padding: 3px 7px; display: flex; align-items: baseline; gap: 3px; min-height: 28px; font-size: 12px; font-weight: 700; white-space: nowrap; }
#stage .chip.res { flex: 1 1 0; min-width: 0; align-items: center; }
#stage .chip.res b { font-size: 15px; font-variant-numeric: tabular-nums; }
#stage .chip.res small { font-size: 9px; opacity: .8; font-weight: 600; }
#stage .chip.bad { background: rgba(190,40,30,.85); }
#stage .chip.full b { color: var(--gold); }
#stage .ic { width: 12px; height: 12px; border-radius: 3px; flex: none; align-self: center; }
#stage .ic.wood { background: #b98a55; } #stage .ic.stone { background: #aab2bd; } #stage .ic.food { background: #d9553b; border-radius: 50%; } #stage .ic.gold { background: #ffcc4d; border-radius: 50%; }
#stage .ibtn { min-width: 44px; height: 44px; border: 0; border-radius: 12px; background: rgba(30,50,25,.8); color: #fff; font-weight: 800; font-size: 15px; pointer-events: auto; flex: none; }
#stage .ibtn { position: relative; }
#stage .ibtn.sm::after { content: ''; position: absolute; inset: -4px -6px -8px -6px; }
#stage .ibtn.sm { height: 32px; min-height: 32px; min-width: 44px; margin-left: auto; font-size: 13px; }
#stage .goals { margin-top: 3px; font-size: 11px; color: #fff; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,.6); padding: 0 2px; }
#stage .raidbar { margin-top: 3px; background: #e8a33a; color: #3a2400; font-weight: 800; font-size: 13px; text-align: center; border-radius: 8px; padding: 3px 6px; }
#stage .raidbar.live { background: var(--red); color: #fff; animation: kbpulse .7s ease-in-out infinite alternate; }
@keyframes kbpulse { to { filter: brightness(1.25); } }

/* hints and toasts */
#stage .hint { position: absolute; left: 8px; right: 8px; bottom: 150px; background: #fff9e6; color: var(--ink); border-radius: 14px; padding: 8px 10px; display: flex; gap: 8px; align-items: center; font-size: 13px; font-weight: 700; box-shadow: 0 3px 0 rgba(0,0,0,.25); pointer-events: auto; z-index: 5; }
#stage .hint span { flex: 1; }
#stage .hint button { min-height: 44px; min-width: 60px; border: 0; border-radius: 10px; background: var(--leaf); color: #fff; font-weight: 800; }
#stage .toasts { position: absolute; left: 0; right: 0; top: 140px; display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; }
#stage .toast { background: rgba(255,255,255,.94); color: var(--ink); font-weight: 700; font-size: 12px; padding: 5px 12px; border-radius: 99px; max-width: 92%; text-align: center; animation: kbfade 2.6s ease-out forwards; }
#stage .toast.good { background: #d8f5c8; } #stage .toast.warn { background: #ffe9b0; } #stage .toast.bad { background: #ffd0c8; }
@keyframes kbfade { 0% { opacity: 0; transform: translateY(-6px); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }

#stage .info:not([hidden]) ~ .hint { display: none; }
/* info card */
#stage .info { position: absolute; left: 8px; right: 8px; bottom: 134px; background: #fff9e6; border-radius: 14px; padding: 8px 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; box-shadow: 0 3px 0 rgba(0,0,0,.25); z-index: 4; }
#stage .info b { font-size: 14px; } #stage .info i { flex-basis: 100%; font-style: normal; color: #5b5a4e; }
#stage .info button { min-height: 44px; padding: 0 10px; border: 0; border-radius: 10px; background: var(--leaf); color: #fff; font-weight: 800; font-size: 12px; }
#stage .info button.cant, #stage .info button:disabled { background: #a9a99a; }

/* dock: actions + palette */
#stage .dock { position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 6px max(6px, env(safe-area-inset-bottom)); background: linear-gradient(rgba(20,40,20,0), rgba(20,40,20,.7) 30%); pointer-events: none; }
#stage .acts { display: flex; gap: 5px; margin-bottom: 5px; pointer-events: auto; }
#stage .acts button { flex: 1 1 0; min-height: 44px; border: 0; border-radius: 11px; background: #fff6dc; color: var(--ink); font-weight: 800; font-size: 12px; box-shadow: 0 3px 0 rgba(0,0,0,.3); padding: 0 4px; }
#stage .acts button:disabled { opacity: .5; }
#stage .acts button.on { background: var(--gold); }
#stage .acts button.ready { background: #9be27a; }
#stage .acts button.rally { background: var(--red); color: #fff; }
#stage .acts button.rally.cant { background: #8a5a55; }
#stage .pal { display: flex; gap: 5px; overflow-x: auto; overflow-y: hidden; touch-action: pan-x; -webkit-overflow-scrolling: touch; padding-bottom: 3px; scrollbar-width: none; }
#stage .pal::-webkit-scrollbar { display: none; }
#stage .pb { flex: none; width: 82px; min-height: 58px; border: 0; border-radius: 11px; background: #fff6dc; 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,.3); }
#stage .pb .sw { width: 22px; height: 12px; border-radius: 4px; border: 1px solid rgba(0,0,0,.25); }
#stage .pb .pn { font-size: 11px; font-weight: 800; }
#stage .pb .pc { font-size: 9px; color: #6a6552; text-align: center; line-height: 1.1; }
#stage .pb.on { background: var(--gold); outline: 3px solid #fff; }
#stage .pb.cant { opacity: .6; } #stage .pb.locked { opacity: .4; filter: grayscale(1); }

/* screens */
#stage .screen { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(25,45,25,.5); padding: 10px; pointer-events: auto; }
#stage .screen.menu { background: linear-gradient(rgba(25,45,25,.2), rgba(25,45,25,.6)); }
#stage .panel { width: 100%; max-height: 100%; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; -webkit-overflow-scrolling: touch; background: #fff9e6; border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 5px 0 rgba(0,0,0,.3); text-align: center; }
#stage .panel h2 { font-size: 22px; } #stage .panel h2.logo { font-size: 30px; letter-spacing: 2px; color: var(--leaf-d); }
#stage .panel p { font-size: 13px; color: #4f4d40; } #stage .sub { font-size: 13px; }
#stage .panel .crowns { font-weight: 800; font-size: 13px; } #stage .panel .crowns b { color: #b07a00; }
#stage .btn { display: block; width: 100%; min-height: 48px; padding: 10px 14px; border: 0; border-radius: 12px; background: var(--leaf); color: #fff; font-size: 15px; font-weight: 800; box-shadow: 0 3px 0 var(--leaf-d); text-decoration: none; }
#stage .btn.big { min-height: 56px; font-size: 18px; background: #e8892b; box-shadow: 0 4px 0 #a85d12; }
#stage .btn.ghost { background: #e9e3c8; color: var(--ink); box-shadow: 0 3px 0 #b9b290; }
#stage .btn.locked { opacity: .45; }
#stage .row { display: flex; gap: 8px; } #stage .row .btn { flex: 1; }
#stage .list { display: flex; flex-direction: column; gap: 6px; text-align: left; }
#stage .card { position: relative; display: block; width: 100%; min-height: 56px; border: 0; border-radius: 12px; background: #fff; padding: 8px 10px; text-align: left; box-shadow: 0 2px 0 rgba(0,0,0,.2); color: var(--ink); }
#stage .card b { font-size: 14px; } #stage .card small { display: block; font-size: 11px; color: #6a6552; margin-top: 2px; padding-right: 60px; }
#stage .card .st { position: absolute; right: 10px; top: 8px; font-size: 12px; font-weight: 800; color: #7a6a30; }
#stage .card.locked { opacity: .5; } #stage .card.dim { opacity: .65; } #stage .card.got { background: #e4f6d6; }
#stage .star { display: inline-block; width: 14px; height: 14px; margin-left: 2px; background: #c9c5b0; clip-path: polygon(50% 0, 62% 36%, 100% 38%, 70% 60%, 80% 100%, 50% 76%, 20% 100%, 30% 60%, 0 38%, 38% 36%); }
#stage .star.on { background: #ffb81c; }
#stage .stars .star { width: 34px; height: 34px; margin: 0 4px; }
#stage .goalsl { list-style: none; font-size: 13px; font-weight: 700; display: flex; flex-direction: column; gap: 3px; }
#stage .goalsl li { background: #f0ead0; border-radius: 8px; padding: 5px 8px; }
#stage .ach { color: #8a5a00; font-weight: 800; }
#stage label.set { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 700; text-align: left; }
#stage label.set input { width: 100%; min-height: 32px; accent-color: var(--leaf); }

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

/* results and briefing extras */
#stage .rec { font-size: 12px; font-weight: 700; color: #6a5a2a; }
#stage .tip { background: #fff0c2; border-left: 4px solid #e8892b; border-radius: 8px; padding: 7px 9px; font-size: 13px; }
#stage .goalsl.chks li { display: flex; align-items: center; gap: 8px; color: #8a8672; }
#stage .goalsl.chks li.yes { color: #2f6a2a; }
#stage .tick { flex: none; width: 16px; height: 16px; border-radius: 50%; background: #d8d2b4; position: relative; }
#stage .chk.yes .tick { background: #4c8c3f; }
#stage .chk.yes .tick::after { content: ""; position: absolute; left: 5px; top: 2px; width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(40deg); }
#stage .screen.win .panel, #stage .screen.lose .panel { animation: pop-in .28s ease-out; }
#stage .screen.win .stars .star.on { animation: star-pop .5s ease-out backwards; }
#stage .screen.win .stars .star.on:nth-child(2) { animation-delay: .18s; }
#stage .screen.win .stars .star.on:nth-child(3) { animation-delay: .36s; }
@keyframes pop-in { from { transform: translateY(14px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes star-pop { 0% { transform: scale(0); } 70% { transform: scale(1.35); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { #stage .screen .panel, #stage .stars .star { animation: none !important; } }

/* ---- full screen (shell native + immersive): the stage fills the shell's frame, the intro chrome steps aside ---- */
html.pip-immersive .game-wrap.pip-stage { display: flex; flex-direction: column; padding: 0; margin: 0; }
html.pip-immersive .game-wrap.pip-stage #stage,
.game-wrap.pip-stage #stage:fullscreen { 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 .kb-bar, html.pip-immersive .kb-keys, html.pip-immersive .game-header, html.pip-immersive .ad-well { display: none !important; }
/* landscape: keep the dock and HUD clear of the side notch and the shell rail */
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .hud { padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
  html.pip-immersive #stage .dock { padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
}
/* soft vignette over the scene for depth; no layout cost */
#stage #app::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 60%, rgba(10,30,10,.22) 100%); }

/* full screen landscape: menu panels scroll inside themselves, Back stays pinned and on screen */
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .screen, html.pip-native #stage .screen { padding: 6px max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left)); }
  html.pip-immersive #stage .panel, html.pip-native #stage .panel { padding: 8px 12px 0; gap: 6px; max-width: 560px; max-height: 100%; }
  html.pip-immersive #stage .panel > .btn.ghost:last-child, html.pip-native #stage .panel > .btn.ghost:last-child { position: sticky; bottom: 0; z-index: 2; min-height: 44px; padding: 6px 14px; margin-top: auto; box-shadow: 0 -6px 0 #fff9e6, 0 3px 0 #b9b290; flex: none; }
}
