@font-face { font-family: Fredoka; font-style: normal; font-weight: 300 700; font-display: swap; src: url("fonts/fredoka-latin.woff2") format("woff2"); }
:root {
  --ink: #1f3b18; --dark: #182e21; --dark2: #10241a; --panel: #1d3a28; --line: rgba(255,255,255,.14);
  --lime1: #e2ff8a; --lime2: #9be04a; --gold: #ffd84a; --pink: #ff6fa0; --text: #f4ffe8; --muted: #b9d4a8;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--dark2); color: var(--text);
  font-family: Fredoka, 'Baloo 2', 'Nunito', 'Arial Rounded MT Bold', system-ui, sans-serif; user-select: none; -webkit-user-select: none;
  overscroll-behavior: none; touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; }
img { -webkit-user-drag: none; user-select: none; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------------------------------------------------------------- scene */
#scene { position: relative; flex: 0 0 46%; min-height: 260px; overflow: hidden; background: #8fd3ff; touch-action: none; cursor: pointer; }
#scene .bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 100%; pointer-events: none; transition: opacity 1.2s ease; }
#bg2 { opacity: 0; }
#glow { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .6s;
  background: radial-gradient(circle at 50% 62%, rgba(255,226,100,.55), rgba(255,200,40,.18) 38%, transparent 64%); }
#scene.king #glow { opacity: 1; animation: glowPulse 1.6s ease-in-out infinite alternate; }
#scene.tornado #glow { opacity: 1; background: radial-gradient(circle at 50% 62%, rgba(255,111,160,.5), rgba(255,111,160,.12) 40%, transparent 66%); }
@keyframes glowPulse { from { filter: brightness(1); } to { filter: brightness(1.35); } }
#fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#frogwrap { position: absolute; left: 35%; top: 30%; width: 30%; aspect-ratio: 1; pointer-events: none; }
#frog { position: absolute; inset: 0; transform-origin: 50% 95%; transition: transform .45s cubic-bezier(.3,1.6,.5,1); }
#frog svg { width: 100%; height: 100%; display: block; overflow: visible; }
#frog.squash { transition: transform .06s; transform: scale(1.08, .9); }
#frog #frog-root { transition: transform .12s; }
#crown { position: absolute; left: 50%; top: 2%; width: 34%; transform: translate(-50%, -40%) rotate(-6deg); opacity: 0; transition: opacity .3s, transform .4s cubic-bezier(.3,1.8,.5,1); filter: drop-shadow(0 4px 6px rgba(0,0,0,.3)); }
#scene.king #crown { opacity: 1; transform: translate(-50%, -55%) rotate(-6deg); }
#sprites { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.sprite { position: absolute; left: 0; top: 0; width: 56px; height: 56px; margin: -28px 0 0 -28px; pointer-events: auto; cursor: pointer; will-change: transform; filter: drop-shadow(0 3px 4px rgba(0,0,0,.3)); }
.sprite.golden { width: 64px; height: 64px; margin: -32px 0 0 -32px; filter: drop-shadow(0 0 10px #ffe066) drop-shadow(0 0 22px rgba(255,210,60,.8)); }
.sprite.golden::after { content: ''; }
.sprite.fade { transition: opacity .25s; opacity: 0; }
#pops { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.pop { position: absolute; font-weight: 700; color: #fff; font-size: 22px; white-space: nowrap; transform: translate(-50%, -50%);
  -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; animation: popUp .9s ease-out forwards; }
.pop.big { font-size: 30px; color: var(--gold); }
.pop.gold { font-size: 34px; color: #fff3a0; -webkit-text-stroke: 5px #6b4100; }
@keyframes popUp { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -230%) scale(1); } }

/* HUD over the scene */
#hud { position: absolute; left: 0; right: 0; top: 0; padding: calc(8px + var(--safe-t)) 64px 0; text-align: center; pointer-events: none;
  text-shadow: 0 2px 0 rgba(0,0,0,.35); }
#bank { display: inline-flex; align-items: center; gap: 8px; padding: 4px 16px 4px 8px; border-radius: 999px; background: rgba(16,36,26,.72);
  border: 2px solid rgba(255,255,255,.18); font-size: clamp(22px, 4.4vh, 36px); font-weight: 700; font-variant-numeric: tabular-nums; }
#bank img { width: 1.35em; height: 1.35em; }
#rate { display: inline-block; margin-top: 3px; padding: 1px 10px; border-radius: 999px; background: rgba(16,36,26,.6); font-size: clamp(12px, 2vh, 16px); font-weight: 600; color: #f5ffe0; }
#hud > #rate { display: table; margin-left: auto; margin-right: auto; }
#rate span { font-variant-numeric: tabular-nums; }
#stage-name { display: table; margin: 3px auto 0; padding: 0 8px; border-radius: 999px; background: rgba(16,36,26,.5); font-size: 10px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; }
#corner { position: absolute; right: calc(8px + var(--safe-r)); top: calc(8px + var(--safe-t)); display: flex; flex-direction: column; gap: 6px; }
.round { width: 42px; height: 42px; border-radius: 50%; border: 2px solid rgba(255,255,255,.2); background: rgba(16,36,26,.72); padding: 6px; display: grid; place-items: center; }
.round img { width: 100%; height: 100%; }
#buffs { position: absolute; left: calc(8px + var(--safe-l)); top: calc(96px + var(--safe-t)); display: flex; flex-direction: column; align-items: flex-start; gap: 4px; pointer-events: none; }
.buff { display: flex; align-items: center; gap: 6px; padding: 3px 9px 3px 4px; border-radius: 999px; font-size: 11px; font-weight: 700;
  background: rgba(80,52,8,.86); border: 2px solid #ffd84a; color: #fff3c4; white-space: nowrap; }
.buff img { width: 20px; height: 20px; }
.buff.tornado { background: rgba(110,20,60,.86); border-color: #ff8fb8; }
.buff.boost { background: rgba(20,60,110,.86); border-color: #8fd3ff; }
.buff span { font-variant-numeric: tabular-nums; opacity: .9; }
#streak { position: absolute; left: 50%; top: 34%; transform: translateX(-50%); pointer-events: none; text-align: center; font-weight: 800;
  font-size: clamp(22px, 5vh, 40px); color: #ffe08a; -webkit-text-stroke: 5px #3d2400; paint-order: stroke fill; opacity: 0; white-space: nowrap; }
#streak.on { animation: streakIn 1.1s ease-out both; }
@keyframes streakIn { 0% { opacity: 0; transform: translateX(-50%) scale(.5) rotate(-3deg); } 14% { opacity: 1; transform: translateX(-50%) scale(1.15) rotate(2deg); }
  30% { transform: translateX(-50%) scale(1) rotate(0); } 75% { opacity: 1; } 100% { opacity: 0; transform: translateX(-50%) translateY(-14px); } }
#ticker { position: absolute; left: 0; right: 0; bottom: 0; height: 26px; display: flex; align-items: center; gap: 8px; padding: 0 10px 0 calc(6px + var(--safe-l));
  background: rgba(16,36,26,.82); border-top: 1px solid var(--line); font-size: 12px; font-weight: 600; overflow: hidden; cursor: pointer; }
#ticker-tag { flex: none; padding: 1px 6px; border-radius: 5px; background: #e64553; color: #fff; font-size: 10px; letter-spacing: .08em; }
#ticker-text { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; transition: opacity .3s; }
#ticker-text .mq { display: inline-block; white-space: nowrap; }
#ticker-text .mq.go { animation: marquee var(--t, 6s) linear 2.5s forwards; }
@keyframes marquee { to { transform: translateX(var(--d, 0)); } }
#tap-hint { position: absolute; left: 50%; bottom: 13%; transform: translateX(-50%); padding: 4px 14px; border-radius: 999px; background: rgba(16,36,26,.8);
  font-weight: 700; font-size: 14px; pointer-events: none; animation: bob 1.2s ease-in-out infinite alternate; }
#tap-hint.gone { display: none; }
#scene:has(#toasts .toast) #tap-hint { visibility: hidden; }
@keyframes bob { from { transform: translate(-50%, 0); } to { transform: translate(-50%, -6px); } }

/* ---------------------------------------------------------------- panel */
#panel { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; background: var(--dark);
  border-top: 3px solid #2c5a3a; padding-bottom: var(--safe-b); }
#tabs { flex: none; display: flex; gap: 4px; padding: 6px calc(6px + var(--safe-r)) 0 calc(6px + var(--safe-l)); background: var(--dark2); }
#tabs button { position: relative; flex: 1; min-height: 40px; padding: 6px 4px; border: 0; border-radius: 12px 12px 0 0; background: #1a3324;
  color: var(--muted); font-weight: 700; font-size: 14px; }
#tabs button.on { background: var(--dark); color: #fff; box-shadow: inset 0 3px 0 var(--lime2); }
#tabs i { position: absolute; top: 6px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 6px var(--gold); display: none; }
#tabs i.on { display: block; }
.tab { display: none; flex: 1 1 auto; min-height: 0; flex-direction: column; }
.tab.on { display: flex; }
.bar { flex: none; display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 6px 10px; }
.bar .lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
#buyamt { display: flex; padding: 2px; border-radius: 10px; background: rgba(0,0,0,.25); }
#buyamt button { min-width: 46px; min-height: 30px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-weight: 700; font-size: 13px; }
#buyamt button.on { background: linear-gradient(180deg, var(--lime1), var(--lime2)); color: #1f3d10; }
.list, .grid, #meta { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px calc(8px + var(--safe-r)) 10px calc(8px + var(--safe-l)); -webkit-overflow-scrolling: touch; }
.row { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 64px; margin: 0 0 6px; padding: 6px 10px 6px 6px; border-radius: 14px;
  border: 2px solid transparent; background: var(--panel); text-align: left; transition: background .15s, transform .08s; }
.row:active { transform: scale(.985); }
.row.can { border-color: rgba(155,224,74,.55); background: #24492f; }
.row.locked { opacity: .55; }
.row .ic { flex: none; width: 52px; height: 52px; border-radius: 12px; background: rgba(255,255,255,.07); display: grid; place-items: center; }
.row .ic img { width: 46px; height: 46px; }
.row.secret .ic img { filter: brightness(0) opacity(.45); }
.row .mid { flex: 1; min-width: 0; }
.row .nm { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .cost { display: inline-flex; align-items: center; gap: 4px; margin-top: 2px; font-weight: 700; font-size: 14px; color: #ffb3b3; }
.row.can .cost { color: var(--lime1); }
.row .cost img { width: 16px; height: 16px; }
.row .own { flex: none; min-width: 40px; text-align: right; font-size: 26px; font-weight: 700; color: rgba(255,255,255,.85); font-variant-numeric: tabular-nums; }
.row .n { font-size: 12px; font-weight: 700; color: var(--gold); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; align-content: start; padding-top: 10px; }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
.tile { position: relative; aspect-ratio: 1; border-radius: 14px; border: 2px solid rgba(255,255,255,.1); background: var(--panel); padding: 6px; display: grid; place-items: center; }
.tile img { width: 100%; height: 100%; }
.tile.can { border-color: var(--lime2); background: #24492f; box-shadow: 0 0 10px rgba(155,224,74,.35); }
.tile.sel { outline: 3px solid var(--gold); }
.tile .k { position: absolute; right: 3px; bottom: 2px; font-size: 10px; font-weight: 800; color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
.tile.off img { filter: grayscale(1) brightness(.35); }
.tile.off { border-style: dashed; }
.empty { display: none; padding: 20px; text-align: center; color: var(--muted); font-size: 14px; }
.empty.on { display: block; }
#trophy-head, .metahead { flex: none; padding: 8px 12px 0; font-size: 13px; color: var(--muted); }
#trophy-head b, .metahead b { color: var(--gold); }
#detail { position: absolute; left: 8px; right: 8px; bottom: calc(8px + var(--safe-b)); z-index: 5; padding: 10px 12px; border-radius: 14px; background: #0d1f15;
  border: 2px solid var(--lime2); box-shadow: 0 6px 20px rgba(0,0,0,.5); display: flex; gap: 10px; align-items: center; }
#detail[hidden] { display: none; }
#detail.hover { pointer-events: none; }
#detail.top { bottom: auto; top: 52px; }
#panel.has-detail .list, #panel.has-detail .grid, #panel.has-detail #meta { padding-bottom: 120px; }
#detail img.ic { width: 48px; height: 48px; flex: none; }
#detail .mid { flex: 1; min-width: 0; }
#detail .nm { font-weight: 700; font-size: 15px; }
#detail .ef { font-size: 12.5px; color: var(--lime1); font-weight: 600; }
#detail .fl { font-size: 12px; color: var(--muted); font-style: italic; margin-top: 2px; }
#detail .rq { font-size: 11.5px; color: #ffb3b3; margin-top: 2px; }
.btn { min-height: 44px; padding: 6px 16px; border: 0; border-radius: 999px; font-weight: 700; font-size: 15px; color: #1f3d10;
  background: linear-gradient(180deg, var(--lime1), var(--lime2)); box-shadow: 0 3px 0 #3d7a1c; white-space: nowrap; }
.btn:disabled { filter: grayscale(.8) brightness(.7); box-shadow: none; cursor: default; }
.btn.ghost { color: #fff; background: rgba(255,255,255,.08); box-shadow: none; border: 2px solid rgba(255,255,255,.2); }
.btn.gold { background: linear-gradient(180deg, #fff3a0, #ffc93a); box-shadow: 0 3px 0 #a86a00; color: #4a2d00; }
.btn.big { min-height: 54px; font-size: 18px; padding: 8px 24px; }
#planet-cta { margin: 4px 8px 6px; padding: 10px; border-radius: 16px; text-align: center; background: linear-gradient(135deg, #2a1650, #10335a); border: 2px solid #8fd3ff; }
#planet-cta b { display: block; font-size: 17px; margin-bottom: 6px; }
/* Metamorphosis */
#meta .box { margin: 6px 0 10px; padding: 12px; border-radius: 16px; background: linear-gradient(160deg, #3d2c08, #1d3a28); border: 2px solid #c98a00; text-align: center; }
#meta .box h3 { margin: 0 0 4px; font-size: 18px; }
#meta .box p { margin: 4px 0; font-size: 13px; color: #f3e6bf; }
#meta .tp { display: inline-flex; align-items: center; gap: 6px; font-size: 22px; font-weight: 700; color: var(--gold); }
#meta .tp img { width: 34px; height: 34px; }
#meta h4 { margin: 12px 4px 6px; font-size: 14px; color: var(--muted); letter-spacing: .06em; }
.perk { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 6px; border-radius: 12px; background: var(--panel); border: 2px solid transparent; width: 100%; text-align: left; }
.perk.can { border-color: #c98a00; }
.perk.have { background: #2f4a1c; border-color: var(--lime2); }
.perk .mid { flex: 1; min-width: 0; }
.perk .nm { font-weight: 700; font-size: 14px; }
.perk .sub { font-size: 12px; color: var(--muted); }
.perk .pc { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--gold); white-space: nowrap; }
.perk .pc img { width: 20px; height: 20px; }

/* ---------------------------------------------------------------- overlays */
#toasts { position: absolute; left: calc(8px + var(--safe-l)); bottom: 32px; z-index: 6; display: flex; flex-direction: column; gap: 4px; pointer-events: none; width: min(70%, 300px); }
.toast { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 5px; border-radius: 12px; background: rgba(13,31,21,.9); border: 2px solid var(--gold);
  box-shadow: 0 4px 12px rgba(0,0,0,.35); animation: toastIn .35s ease-out; font-size: 11px; line-height: 1.2; }
.toast img { width: 26px; height: 26px; flex: none; }
.toast b { display: block; color: var(--gold); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast.out { transition: opacity .4s, transform .4s; opacity: 0; transform: translateY(-10px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px) scale(.96); } to { opacity: 1; transform: none; } }
#modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(5,14,9,.7); }
#modal[hidden] { display: none; }
#modal .card { width: min(100%, 440px); max-height: 100%; overflow-y: auto; padding: 18px; border-radius: 22px; background: var(--dark); border: 3px solid #2f6b40;
  box-shadow: 0 12px 40px rgba(0,0,0,.6); text-align: center; animation: toastIn .3s ease-out; }
#modal h2 { margin: 0 0 8px; font-size: 24px; }
#modal p { margin: 8px 0; font-size: 15px; line-height: 1.4; color: #e5f5d6; }
#modal .big-n { font-size: 30px; font-weight: 700; color: var(--gold); display: inline-flex; align-items: center; gap: 8px; }
#modal .big-n img { width: 38px; height: 38px; }
#modal .btns { position: sticky; bottom: 0; z-index: 1; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
  margin: 14px -18px -18px; padding: 14px 18px 18px; background: linear-gradient(180deg, rgba(24,46,33,0), var(--dark) 12px); }
#modal .err { min-height: 1.2em; margin: 6px 0 0; font-size: 13px; color: #ffb3b3; }
#modal .card.wide { width: min(100%, 440px); }
@media (min-width: 760px) and (min-aspect-ratio: 5/4) {
  #modal .card.wide { width: min(100%, 720px); }
  #modal .card.wide .stats { columns: 2; column-gap: 28px; }
  #modal .card.wide .stats div { break-inside: avoid; }
}
#modal .hero { width: 120px; height: 120px; margin: 0 auto 4px; display: block; }
.set { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.set input[type=range] { width: 50%; accent-color: var(--lime2); }
.stats { text-align: left; font-size: 14px; }
.stats div { display: flex; justify-content: space-between; gap: 10px; padding: 6px 2px; border-bottom: 1px solid var(--line); }
.stats b { color: var(--gold); font-variant-numeric: tabular-nums; }
textarea.save { width: 100%; height: 90px; font: 11px monospace; color: #dfe; background: #0b1a12; border: 1px solid var(--line); border-radius: 8px; user-select: text; -webkit-user-select: text; }
/* stage banner and the ending */
#banner { position: absolute; left: 50%; top: 38%; z-index: 7; transform: translate(-50%, -50%); width: min(92%, 480px); padding: 12px 16px; border-radius: 20px; text-align: center; pointer-events: none;
  background: linear-gradient(160deg, #24492f, #10241a); border: 3px solid var(--gold); box-shadow: 0 10px 40px rgba(0,0,0,.5); animation: bannerIn .6s cubic-bezier(.2,1.6,.4,1); }
#banner h2 { margin: 0; font-size: clamp(20px, 4.5vh, 30px); color: var(--gold); -webkit-text-stroke: 1px #3d2400; }
#banner p { margin: 5px 0 0; font-size: 14px; }
@keyframes bannerIn { from { opacity: 0; transform: translate(-50%, -50%) scale(.6); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
#ending { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: #050812; overflow: hidden; }
#ending img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 2s; }
#ending img.on { opacity: 1; }
#ending::after { content: ''; position: absolute; inset: 0; z-index: 1; pointer-events: none; background: radial-gradient(ellipse at 50% 50%, rgba(0,0,0,.6), rgba(0,0,0,.2) 75%); }
#ending .skip { position: absolute; right: calc(12px + var(--safe-r)); top: calc(12px + var(--safe-t)); z-index: 3; min-height: 38px; padding: 4px 16px; font-size: 14px; background: rgba(0,0,0,.45); }
#ending .lines { position: relative; z-index: 2; width: min(92vw, 600px); text-align: center; font-size: clamp(18px, 3.4vw, 26px); font-weight: 700;
  text-shadow: 0 3px 0 rgba(0,0,0,.6), 0 0 18px rgba(0,0,0,.8); }
#ending .lines p { margin: 10px 0; animation: toastIn .6s ease-out; }
#ending .btns { margin-top: 18px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; text-shadow: none; }
#ending .btns .btn { box-shadow: 0 3px 0 rgba(0,0,0,.35), 0 6px 18px rgba(0,0,0,.5); }
#ending.shake { animation: shake .5s linear 3; }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translate(6px, -4px); } 50% { transform: translate(-6px, 3px); } 75% { transform: translate(4px, 5px); } }
#dev { position: absolute; right: calc(8px + var(--safe-r)); top: calc(106px + var(--safe-t)); z-index: 8; display: flex; flex-direction: column; align-items: flex-end; gap: 3px;
  max-width: 46%; max-height: calc(100% - 140px - var(--safe-t)); overflow-y: auto; }
#dev button { font-size: 11px; padding: 4px 7px; border-radius: 6px; border: 1px solid #f0f; background: rgba(60,0,60,.88); color: #fff; text-align: right; }
#dev button:not(.tog) { display: none; }
#dev.open button { display: block; }
#dev .tog { font-weight: 700; }

/* ---------------------------------------------------------------- landscape: scene left, shop right */
@media (min-aspect-ratio: 5/4) {
  #app { flex-direction: row; }
  #scene { flex: 1 1 58%; min-height: 0; }
  #panel { flex: 0 0 42%; min-width: 0; max-width: 560px; border-top: 0; border-left: 3px solid #2c5a3a; }
  #detail { bottom: 10px; }
}
@media (max-height: 520px) and (min-aspect-ratio: 5/4) {
  .row { min-height: 54px; } .row .ic { width: 44px; height: 44px; } .row .ic img { width: 38px; height: 38px; }
  #tabs button { min-height: 34px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
