:root {
  --brown: #5b3a1e; --brown2: #7a4f2a; --cream: #fff7e3; --green: #4caf50; --green2: #2f8a35; --gold: #ffd23f; --sky: #9fd8f5;
  font-family: 'Baloo 2', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #79c150; color: var(--brown); -webkit-tap-highlight-color: transparent; user-select: none; }
canvas#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font: inherit; cursor: pointer; }

/* ---------------------------------------------------------------- HUD */
.hud { position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left)); pointer-events: none; }
.hud > * { pointer-events: auto; }
.right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.pill { display: flex; align-items: center; gap: 8px; background: var(--cream); border: 3px solid var(--brown); border-radius: 999px;
  padding: 2px 16px 0 8px; height: 46px; box-shadow: 0 4px 0 rgba(60,35,10,.35); font-size: 26px; font-weight: 800; min-width: 130px; }
.pill b { flex: 1; text-align: right; }
.pill.small { height: 38px; font-size: 20px; min-width: 100px; }
.pill.full { background: #ffe3a1; animation: wiggle .5s ease-in-out infinite alternate; }
@keyframes wiggle { to { transform: rotate(-3deg); } }
.bill { display: inline-block; width: 34px; height: 22px; border-radius: 4px; background: linear-gradient(#6fd06f, #3f9a48);
  border: 2px solid #2b6f31; position: relative; flex: none; }
.bill::after { content: '$'; position: absolute; inset: 0; display: grid; place-items: center; color: #e9ffd9; font-size: 15px; font-weight: 800; line-height: 1; }
.basket { width: 30px; height: 30px; margin-left: -2px; }
.level-pill { display: flex; align-items: center; }
.star { width: 58px; height: 58px; display: grid; place-items: center; z-index: 1; color: var(--brown); font-weight: 800; font-size: 24px;
  background: var(--gold); clip-path: polygon(50% 0, 62% 33%, 98% 35%, 70% 57%, 80% 93%, 50% 72%, 20% 93%, 30% 57%, 2% 35%, 38% 33%);
  filter: drop-shadow(0 3px 0 rgba(60,35,10,.4)); }
.star span { margin-top: 8px; }
.xpbar { position: relative; margin-left: -14px; width: 190px; height: 28px; background: #4a3420; border: 3px solid var(--brown); border-radius: 999px; overflow: hidden;
  box-shadow: 0 4px 0 rgba(60,35,10,.35); }
#xpfill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(#9be86b, #4caf50); transition: width .3s; }
#xptext { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 15px; font-weight: 800; text-shadow: 0 1px 2px #0008; padding-top: 2px; }
.btns { display: flex; gap: 8px; }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; border: 3px solid var(--brown); background: var(--cream); color: var(--brown);
  display: grid; place-items: center; box-shadow: 0 3px 0 rgba(60,35,10,.35); padding: 0; }
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(60,35,10,.35); }
#sound .cross { display: none; }
#sound.off .wave { display: none; }
#sound.off .cross { display: block; }

.toast { position: fixed; left: 50%; top: 86px; transform: translate(-50%, -20px); opacity: 0; transition: .25s; pointer-events: none;
  background: var(--cream); border: 3px solid var(--brown); border-radius: 16px; padding: 8px 20px 4px; font-size: 22px; font-weight: 800;
  box-shadow: 0 4px 0 rgba(60,35,10,.35); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.gold { background: var(--gold); }

/* joystick */
.stick { position: fixed; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; background: rgba(255,255,255,.22);
  border: 3px solid rgba(255,255,255,.6); opacity: 0; pointer-events: none; transition: opacity .15s; }
.stick.on { opacity: 1; }
.knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; border-radius: 50%; background: rgba(255,255,255,.85);
  box-shadow: 0 3px 8px rgba(0,0,0,.25); transform: translate(-50%,-50%); }

/* ---------------------------------------------------------------- upgrades panel */
.panel { position: fixed; inset: auto 0 0 0; display: flex; justify-content: center; padding: 0 12px max(14px, env(safe-area-inset-bottom)); pointer-events: none; }
.panel[hidden] { display: none; }
.panel-card { pointer-events: auto; width: min(560px, 100%); background: var(--cream); border: 4px solid var(--brown); border-radius: 22px;
  box-shadow: 0 6px 0 rgba(60,35,10,.4); padding: 10px 14px 14px; animation: rise .25s ease-out; max-height: 62vh; display: flex; flex-direction: column; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 { margin: 0; font-size: 26px; }
.close { border: 0; background: none; font-size: 24px; color: var(--brown); width: 40px; height: 40px; }
.upgrades { display: grid; gap: 8px; overflow-y: auto; }
.up { display: flex; align-items: center; gap: 12px; background: #fff; border: 2px solid #e4cfa6; border-radius: 14px; padding: 6px 10px; }
.up.locked { opacity: .5; }
.up-icon { font-size: 30px; width: 44px; text-align: center; }
.up-text { flex: 1; display: flex; flex-direction: column; line-height: 1.15; }
.up-text b { font-size: 19px; }
.up-text span { font-size: 14px; color: var(--brown2); }
.pips { display: flex; gap: 4px; margin-top: 4px; }
.pips i { width: 16px; height: 8px; border-radius: 4px; background: #e8dcc2; }
.pips i.on { background: var(--green); }
.buy { display: flex; align-items: center; gap: 6px; min-width: 112px; justify-content: center; height: 44px; border: 3px solid var(--green2); border-radius: 12px;
  background: linear-gradient(#7fd66c, #4caf50); color: #fff; font-size: 20px; font-weight: 800; text-shadow: 0 1px 1px #0005; box-shadow: 0 3px 0 var(--green2); padding-top: 3px; }
.buy .bill { width: 26px; height: 17px; }
.buy .bill::after { font-size: 11px; }
.buy:disabled { filter: grayscale(.8); opacity: .7; cursor: default; }
.buy:not(:disabled):active { transform: translateY(2px); box-shadow: 0 1px 0 var(--green2); }

/* ---------------------------------------------------------------- title and loading */
.title { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 50% 40%, rgba(255,247,200,.35), rgba(60,120,40,.55));
  transition: opacity .4s; padding: 16px; }
.title.gone, .loading.gone { opacity: 0; pointer-events: none; }
.title-card { background: var(--cream); border: 4px solid var(--brown); border-radius: 26px; padding: 22px 26px 24px; width: min(460px, 100%);
  box-shadow: 0 8px 0 rgba(60,35,10,.4); text-align: center; }
.logo { display: flex; align-items: center; justify-content: center; gap: 10px; }
.logo h1 { margin: 0; font-size: clamp(40px, 9vw, 58px); line-height: 1; color: #e8742c; -webkit-text-stroke: 2px var(--brown); paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--brown); padding-top: 8px; }
.sun { width: 46px; height: 46px; border-radius: 50%; background: radial-gradient(circle, #ffe86a 55%, #ffb627 56%); box-shadow: 0 0 0 6px rgba(255,210,63,.35); flex: none; }
.title-card p { font-size: 18px; margin: 12px 0 10px; line-height: 1.3; }
.howto { list-style: none; padding: 0; margin: 0 0 18px; text-align: left; font-size: 16px; display: grid; gap: 4px; }
.howto li { background: #fff; border-radius: 10px; padding: 5px 10px 3px; border: 2px solid #ecdcb9; }
.howto b { color: #e8742c; }
.play { width: 100%; height: 64px; font-size: 32px; font-weight: 800; color: #fff; border: 4px solid var(--green2); border-radius: 18px;
  background: linear-gradient(#8ee07a, #4caf50); box-shadow: 0 5px 0 var(--green2); text-shadow: 0 2px 0 #0004; padding-top: 4px; }
.play:disabled { filter: grayscale(.7); }
.play:not(:disabled):hover { filter: brightness(1.05); }
.play:not(:disabled):active { transform: translateY(3px); box-shadow: 0 2px 0 var(--green2); }
.loading { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; background: var(--cream);
  border: 3px solid var(--brown); border-radius: 999px; padding: 6px 16px 4px 8px; font-weight: 800; transition: opacity .3s; }
.spinner { width: 24px; height: 24px; border-radius: 50%; border: 4px solid #e4cfa6; border-top-color: var(--green); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .pill { height: 40px; font-size: 22px; min-width: 110px; }
  .pill.small { height: 34px; font-size: 18px; min-width: 86px; }
  .xpbar { width: 130px; height: 24px; }
  .star { width: 50px; height: 50px; font-size: 21px; }
  .toast { font-size: 18px; top: 74px; }
  .icon-btn { width: 38px; height: 38px; }
}

/* off-screen goal pointer */
.pointer { position: fixed; left: 0; top: 0; width: 54px; height: 54px; pointer-events: none; animation: nudge .7s ease-in-out infinite alternate; }
.pointer svg { width: 100%; height: 100%; fill: #ffcf33; stroke: #8a4b00; stroke-width: 2.5; stroke-linejoin: round; filter: drop-shadow(0 3px 2px rgba(0,0,0,.3)); }
@keyframes nudge { to { scale: 1.15; } }

/* F3 performance overlay */
.perf { position: fixed; left: 12px; bottom: 12px; background: rgba(20,20,20,.78); color: #e8ffe0; border-radius: 10px; padding: 8px 10px; font: 12px/1.35 ui-monospace, Consolas, monospace; pointer-events: none; z-index: 50; }
.perf canvas { display: block; width: 240px; height: 60px; margin-bottom: 4px; }
.perf pre { margin: 0; white-space: pre; font: inherit; }
.icon-btn.text { width: auto; padding: 3px 8px 0; font-weight: 800; font-size: 14px; letter-spacing: .5px; }
