/* Meadow Menagerie 3D - stage and in-game UI. Everything is scoped under #stage so site styles never leak in. */
html.zoo-big, html.zoo-big body { overflow: hidden; }
#stage { --leaf:#2e9e5b; --leaf-d:#1f7a43; --sun:#ffc21a; --coral:#ff6b5a; --ink:#25323d; --cream:#fff8e6; --card:#ffffffee;
  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(#bfe6ff, #dff5d0); 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; }
html.pip-immersive .game-wrap #stage { position: absolute; inset: 0; width: 100%; height: 100%; aspect-ratio: auto; border-radius: 0; margin: 0; }
html.pip-immersive .zoo-bar, html.pip-immersive .zoo-keys { display: none; }
#stage *, #stage *::before, #stage *::after { box-sizing: border-box; }
#stage [hidden] { display: none !important; }
#stage #app { position: absolute; inset: 0; touch-action: none; }
#stage #app canvas { display: block; touch-action: none; }
#stage #ui { position: absolute; inset: 0; pointer-events: none; }
#stage #ui button, #stage #ui .sheet, #stage #ui .ov, #stage #ui .hint { pointer-events: auto; }
#stage button { font-family: inherit; cursor: pointer; touch-action: manipulation; color: inherit; }
#stage button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

#stage #loader { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: linear-gradient(#2e9e5b, #bfe6ff); color: #fff; text-align: center; }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .06em; }
#stage .load-in span { font-weight: 600; font-size: .85rem; letter-spacing: 0; }
#stage .spinner { width: 42px; height: 42px; border-radius: 50%; border: 6px solid rgba(255,255,255,.4); border-top-color: var(--sun); animation: zoospin .8s linear infinite; }
@keyframes zoospin { 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,40,30,.88); color: #fff; font-weight: 700; }

/* HUD */
#stage .hud { position: absolute; left: 0; right: 0; top: 0; padding: max(6px, env(safe-area-inset-top)) 8px 4px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
#stage .line1 { display: flex; align-items: center; gap: 6px; }
#stage .pill { display: flex; align-items: center; gap: 6px; background: var(--card); border-radius: 999px; padding: 4px 10px; min-height: 34px; font-weight: 800; box-shadow: 0 2px 0 rgba(0,0,0,.12); }
#stage .ic { width: 16px; height: 16px; border-radius: 50%; display: inline-block; }
#stage .ic.c { background: radial-gradient(circle at 35% 30%, #fff3a0, #ffc21a 60%, #d89a00); }
#stage .ic.g { background: linear-gradient(135deg, #9af0ff, #3aa6e8); border-radius: 4px; transform: rotate(45deg) scale(.8); }
#stage .inc { flex: 1; font-size: .8rem; font-weight: 800; color: #1f5a37; text-shadow: 0 1px 0 #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#stage .hbtn { pointer-events: auto; width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--card); font-weight: 900; box-shadow: 0 2px 0 rgba(0,0,0,.12); }
#stage .line2 { display: flex; align-items: center; gap: 8px; font-size: .75rem; font-weight: 800; color: #1f4a34; text-shadow: 0 1px 0 #ffffffcc; min-height: 18px; }
#stage .line2.goal { background: var(--card); border-radius: 10px; padding: 4px 8px; text-shadow: none; }
#stage .gbar { flex: 0 0 70px; height: 10px; background: #0001; border-radius: 6px; overflow: hidden; }
#stage .gbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffc21a, #ff8a1f); }
#stage .hint { position: absolute; left: 12px; right: 12px; top: 84px; background: #25323dee; color: #fff; padding: 8px 12px; border-radius: 12px; font-weight: 700; font-size: .85rem; text-align: center; pointer-events: none !important; }
#stage .quicks { position: absolute; right: 8px; top: 120px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
#stage .quick { min-width: 74px; min-height: 44px; border-radius: 14px; border: 0; padding: 6px 12px; background: var(--leaf); color: #fff; font-weight: 800; box-shadow: 0 3px 0 var(--leaf-d); }
#stage .quick.dim { background: #8fa396; box-shadow: 0 3px 0 #6b7d71; }
#stage .quick.crate { background: #ff8a1f; box-shadow: 0 3px 0 #b85a00; animation: zoopulse 1s ease-in-out infinite; }
#stage .quick.boost { background: #3aa6e8; box-shadow: 0 3px 0 #1e6fa8; }
@keyframes zoopulse { 50% { transform: scale(1.08); } }
#stage .toasts { position: absolute; left: 12px; right: 12px; top: 130px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
#stage .toast { background: #fffffff2; border-radius: 12px; padding: 6px 12px; font-weight: 800; font-size: .8rem; box-shadow: 0 2px 6px rgba(0,0,0,.2); max-width: 86%; text-align: center; }
#stage .toast.good { background: #e7fbe8; color: #145a2a; } #stage .toast.warn { background: #fff0d6; color: #7a3b00; }

/* nav + sheet */
#stage .nav { position: absolute; left: 0; right: 0; bottom: 0; display: flex; background: #25323d; padding-bottom: env(safe-area-inset-bottom); }
#stage .tab { flex: 1; min-height: 48px; border: 0; background: transparent; color: #cfe3d6; font-weight: 800; font-size: .72rem; position: relative; }
#stage .tab.on { background: var(--leaf); color: #fff; }
#stage .tab.badge::after { content: ""; position: absolute; top: 8px; right: 14px; width: 9px; height: 9px; border-radius: 50%; background: var(--coral); }
#stage .sheet { position: absolute; left: 0; right: 0; bottom: 48px; max-height: 46%; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; background: var(--cream); border-radius: 16px 16px 0 0; padding: 8px 10px 12px; box-shadow: 0 -4px 14px rgba(0,0,0,.25); }
#stage .panel { display: flex; flex-direction: column; gap: 6px; }
#stage .p-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .95rem; }
#stage .x { min-width: 64px; min-height: 44px; border-radius: 10px; border: 0; background: #e3e8e4; font-weight: 800; }
#stage .muted { font-size: .75rem; color: #5a6b60; }
#stage .sec { font-size: .8rem; margin-top: 4px; color: var(--leaf-d); text-transform: uppercase; letter-spacing: .05em; }
#stage .bar { height: 12px; border-radius: 8px; background: #0002; overflow: hidden; }
#stage .bar i { display: block; height: 100%; transition: width .2s; } #stage .bar i.hi { background: #4ad45a; } #stage .bar i.mid { background: #ffc21a; } #stage .bar i.lo { background: #ff5a4a; }
#stage .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 52px; padding: 6px 10px; border: 0; border-radius: 12px; background: #fff; text-align: left; box-shadow: 0 2px 0 #0002; }
#stage .row .r-l { display: flex; flex-direction: column; min-width: 0; }
#stage .row .r-t { font-size: .88rem; } #stage .row .r-s { font-size: .72rem; color: #5a6b60; }
#stage .row .r-r { font-weight: 900; font-size: .85rem; white-space: nowrap; }
#stage .row.go { background: #e3f8e6; box-shadow: 0 2px 0 #2e9e5b; } #stage .row.go .r-r { color: #1f7a43; }
#stage .row.dim { background: #f1f3f1; color: #6b7d71; } #stage .row.lock { background: #e6e6e6; color: #888; } #stage .row.info { background: #eef4ff; }
#stage .card { background: #fff; border-radius: 12px; padding: 8px 10px; font-size: .78rem; }
#stage .dex { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#stage .dx { background: #f1f3f1; border-radius: 10px; padding: 8px; font-size: .72rem; font-weight: 700; color: #7b8a80; min-height: 44px; }
#stage .dx.seen { background: #fff; color: var(--ink); } #stage .dx.t1 { box-shadow: inset 0 0 0 2px #7ec8ff; } #stage .dx.t2 { box-shadow: inset 0 0 0 2px #c58bff; } #stage .dx.t3 { box-shadow: inset 0 0 0 2px #ffc21a; }

/* overlays */
#stage .ov { position: absolute; inset: 0; z-index: 30; background: rgba(20,45,32,.78); overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; display: flex; }
#stage .ov-in { margin: auto; width: 100%; max-width: 360px; padding: 20px 18px; display: flex; flex-direction: column; gap: 10px; text-align: center; color: #fff; }
#stage .ttl { font-size: 1.5rem; font-weight: 900; text-shadow: 0 2px 0 rgba(0,0,0,.3); }
#stage .sub { font-size: .92rem; font-weight: 600; } #stage .tiny { font-size: .78rem; opacity: .9; } #stage .next { font-size: .85rem; font-weight: 800; color: #ffe08a; }
#stage .stars { font-size: 2rem; color: #ffc21a; letter-spacing: .15em; }
#stage .big { min-height: 52px; border-radius: 14px; border: 0; background: #fff; color: var(--ink); font-weight: 900; font-size: 1rem; padding: 8px 14px; box-shadow: 0 3px 0 rgba(0,0,0,.25); }
#stage .big.gold { background: linear-gradient(#ffd75a, #ffb300); }
#stage .lvl { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-height: 58px; border: 0; border-radius: 12px; background: #fff; color: var(--ink); padding: 6px 12px; text-align: left; position: relative; }
#stage .lvl span { font-size: .75rem; color: #5a6b60; } #stage .lvl em { position: absolute; right: 12px; top: 8px; font-style: normal; font-weight: 900; color: #e59a00; font-size: .85rem; }
#stage .lvl.lock { background: #cfd6d1; color: #667; }

@media (orientation: landscape) and (max-height: 520px) {
  #stage.is-big .sheet { max-width: 420px; left: auto; right: 0; max-height: 70%; }
  #stage.is-big .ov-in { max-width: 420px; }
}
@media (prefers-reduced-motion: reduce) { #stage .quick.crate, #stage .spinner { animation: none; } }
.game-wrap.pip-stage #stage { width: min(100%, calc((100vh - 64px) * 0.5625)); width: min(100%, calc((100svh - 64px) * 0.5625)); }
html.pip-immersive .game-wrap.pip-stage #stage { width: 100%; }

.zoo-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.zoo-bar .btn { min-height: 44px; min-width: 44px; }
.zoo-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.zoo-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.zoo-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.zoo-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.zoo-guide p { margin-bottom: .5rem; font-size: .95rem; }

/* wave2 polish: next goal chip, home goal, onboarding nudge, safe-area sheet */
#stage .sheet { bottom: calc(48px + env(safe-area-inset-bottom)); }
#stage .nextgoal { align-self: flex-start; background: #25323dcc; color: #fff; border-radius: 999px; padding: 3px 10px; font-size: .72rem; font-weight: 800; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#stage .homegoal { display: flex; flex-direction: column; gap: 4px; align-items: center; background: rgba(255,255,255,.14); border-radius: 14px; padding: 10px 12px; font-size: .8rem; }
#stage .homegoal b { font-size: .9rem; color: #ffe08a; }
#stage .homegoal:empty { display: none; }
#stage .mbar { display: block; width: 80%; height: 8px; border-radius: 6px; background: rgba(0,0,0,.3); overflow: hidden; }
#stage .mbar u { display: block; height: 100%; background: linear-gradient(90deg, #ffc21a, #ff8a1f); text-decoration: none; }
#stage .lvl small { position: absolute; right: 12px; bottom: 6px; font-size: .68rem; color: #5a6b60; }
#stage .hint { border: 2px solid #ffc21a; animation: zoonudge 1.8s ease-in-out infinite; }
#stage .tab.nudge { animation: zoonudgebg 1s ease-in-out infinite; }
#stage .toast { animation: zoopop .25s ease-out; }
@keyframes zoonudge { 50% { box-shadow: 0 0 0 5px rgba(255,194,26,.35); } }
@keyframes zoonudgebg { 50% { background: #3d7a55; color: #fff; } }
@keyframes zoopop { from { transform: translateY(-8px) scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #stage .hint, #stage .tab.nudge, #stage .toast { animation: none; } }

/* wave3: full screen on phones (native + immersive), landscape layout, depth finish */
#stage:fullscreen, #stage:-webkit-full-screen { width: 100%; height: 100%; max-width: none; aspect-ratio: auto; border-radius: 0; margin: 0; }
html.pip-native .zoo-bar, html.pip-native .zoo-keys, html.pip-immersive .zoo-guide, html.pip-immersive .game-header, html.pip-immersive .ad-well { display: none; }
html.pip-immersive #stage .hud, html.pip-native #stage .hud, #stage.is-big .hud { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
html.pip-immersive #stage .quicks, html.pip-native #stage .quicks, #stage.is-big .quicks { right: max(8px, env(safe-area-inset-right)); }
#stage::after { content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 62%, rgba(20,50,30,.22) 100%); }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .sheet, html.pip-native #stage .sheet { max-width: 420px; left: auto; right: 0; max-height: 70%; }
  html.pip-immersive #stage .quicks, html.pip-native #stage .quicks { top: 96px; flex-direction: row; flex-wrap: wrap; justify-content: flex-end; max-width: 60%; }
  html.pip-immersive #stage .toasts, html.pip-native #stage .toasts { top: 100px; }
}
