:root {
  --ink: #23324a;
  --ink-soft: #4d5f7a;
  --panel: rgba(255, 255, 255, 0.92);
  --accent: #e8892b;
  --accent-dark: #b8641a;
  --good: #2fb36b;
  --gold: #ffc23a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #9fd8ff; color: var(--ink); font-family: "Baloo 2", "Trebuchet MS", system-ui, sans-serif; user-select: none; touch-action: none; }
canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }
[hidden] { display: none !important; }

.panel {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(92vw, 460px); max-height: 92dvh; overflow: auto;
  padding: 20px 18px; border-radius: 26px; background: var(--panel);
  box-shadow: 0 14px 0 rgba(35, 50, 74, 0.18), 0 20px 40px rgba(35, 50, 74, 0.25);
  text-align: center; display: grid; gap: 12px; touch-action: manipulation;
}
h1 { margin: 0; font-size: clamp(2.2rem, 10vw, 3.2rem); line-height: 1; color: var(--ink); letter-spacing: 0.5px; }
h1 span { color: var(--accent); }
h2 { margin: 0; font-size: 1.8rem; }
.sub { margin: 0; color: var(--ink-soft); font-size: 1.05rem; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.btn {
  font: inherit; font-weight: 800; font-size: 1.15rem; color: #fff; cursor: pointer;
  background: var(--accent); border: 0; border-radius: 16px; padding: 10px 20px; min-height: 48px;
  box-shadow: 0 5px 0 var(--accent-dark); transition: transform 0.08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn.big { font-size: 1.5rem; padding: 12px 28px; }
.btn.alt { background: #4aa8ff; box-shadow: 0 5px 0 #2a7fd0; }
.btn.ghost { background: none; color: var(--ink-soft); box-shadow: none; text-decoration: underline; font-size: 1rem; min-height: 40px; }
.btn:disabled { background: #b8c2cf; box-shadow: 0 5px 0 #98a3b2; cursor: default; }

.animals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.animal {
  border: 3px solid transparent; border-radius: 18px; background: #eef7ff; padding: 6px 2px 4px;
  cursor: pointer; display: grid; justify-items: center; gap: 2px; font: inherit; color: var(--ink); font-weight: 800;
}
.animal canvas { position: static; width: 64px; height: 64px; }
.animal[aria-checked="true"] { border-color: var(--accent); background: #fff3ea; }
.power-text { margin: 0; min-height: 2.6em; color: var(--ink-soft); font-size: 1rem; }
.wallet { margin: 0; font-weight: 800; }

.upgrades { display: grid; gap: 8px; }
.upgrade { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; text-align: left; background: #eef7ff; border-radius: 16px; padding: 10px 12px; }
.upgrade b { font-size: 1.1rem; }
.upgrade small { color: var(--ink-soft); grid-column: 1; }
.pips { grid-column: 1; display: flex; gap: 4px; }
.pips i { width: 16px; height: 8px; border-radius: 4px; background: #c9d6e6; }
.pips i.on { background: var(--good); }
.upgrade .btn { grid-column: 2; grid-row: 1 / span 3; font-size: 1rem; padding: 8px 12px; }

.big-num { margin: 0; font-size: 3.4rem; font-weight: 800; line-height: 1; }
.earned { margin: 0; font-size: 1.6rem; font-weight: 800; color: #b07a00; }

#hud { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; justify-content: space-between; pointer-events: none; text-shadow: 0 2px 0 rgba(255, 255, 255, 0.7); }
.hud-dist { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.hud-best { color: var(--ink-soft); font-weight: 600; }
.hud-right { text-align: right; }
.hud-coins { font-size: 1.5rem; font-weight: 800; }
.hud-power { font-weight: 800; color: var(--accent-dark); }
.hint { position: fixed; left: 50%; bottom: calc(18% + env(safe-area-inset-bottom)); transform: translateX(-50%); margin: 0; padding: 8px 16px; border-radius: 999px; background: rgba(255, 255, 255, 0.9); font-weight: 800; font-size: 1.15rem; pointer-events: none; white-space: nowrap; }
.sound { position: fixed; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.85); font-size: 1.3rem; cursor: pointer; }

.coin { display: inline-block; width: 0.9em; height: 0.9em; margin-right: 0.25em; vertical-align: -0.1em; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffe38a, #ffc23a 55%, #d99a00); box-shadow: inset 0 0 0 2px #b07a00; }

.gem { display: inline-block; width: 0.8em; height: 0.8em; margin-right: 0.3em; vertical-align: -0.05em; transform: rotate(45deg); border-radius: 3px; background: linear-gradient(135deg, #b7ffd9, #2fd47f 55%, #149a55); box-shadow: inset 0 0 0 2px #0d7a42; }
.size-badge { font-weight: 800; color: #7a4a1d; }
.other-game { display: block; margin-top: 2px; color: var(--ink-soft); font-weight: 800; text-decoration: none; }
.other-game:hover { text-decoration: underline; }

/* Multiplayer */
.btn.friends { background: #2fb36b; box-shadow: 0 5px 0 #1e8a50; }
.field { display: grid; gap: 4px; text-align: left; font-weight: 800; }
.field input, .code-input { font: inherit; font-size: 1.15rem; padding: 10px 12px; border-radius: 14px; border: 2px solid #c9d6e6; background: #fff; color: var(--ink); min-height: 48px; }
.code-input { width: 7.5em; text-align: center; text-transform: uppercase; letter-spacing: 0.25em; font-weight: 800; }
.or { margin: 0; color: var(--ink-soft); }
.error { margin: 0; color: #d6334b; font-weight: 800; }
.room-code { color: var(--accent); letter-spacing: 0.12em; }
.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; text-align: left; }
.players li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 14px; background: #eef7ff; font-weight: 800; }
.players li .dot { width: 16px; height: 16px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 2px rgba(0,0,0,0.2); }
.players li .meta { margin-left: auto; color: var(--ink-soft); font-weight: 600; }
.countdown { position: fixed; inset: 0; display: grid; place-items: center; font-size: 30vmin; font-weight: 800; color: #fff; text-shadow: 0 6px 0 rgba(0,0,0,0.25); pointer-events: none; }
.race-board { position: fixed; left: 12px; top: calc(118px + env(safe-area-inset-top)); margin: 0; padding: 6px 10px; list-style: none; border-radius: 14px; background: rgba(255,255,255,0.85); font-weight: 800; font-size: 0.95rem; pointer-events: none; }
.race-board li { display: flex; gap: 6px; align-items: center; }
.race-board .dot { width: 10px; height: 10px; border-radius: 50%; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode { font: inherit; color: var(--ink); text-align: center; display: grid; gap: 2px; padding: 10px 8px; border-radius: 16px; border: 3px solid transparent; background: #eef7ff; cursor: pointer; }
.mode b { font-size: 1.15rem; }
.mode small { color: var(--ink-soft); font-size: 0.85rem; line-height: 1.2; }
.mode[aria-checked="true"] { border-color: var(--accent); background: #fff3e6; }
.goal { margin: 0; font-weight: 800; color: #7a4a1d; }

.cash { display: inline-grid; place-items: center; width: 1.05em; height: 1.05em; margin-right: 0.2em; vertical-align: -0.12em; border-radius: 50%; background: #2fb36b; color: #fff; font-style: normal; font-weight: 800; font-size: 0.85em; box-shadow: inset 0 0 0 2px #1e8a50; }

.level-line { margin: 0; font-weight: 800; color: #7a4a1d; }
/* Level passed: Preacher-style title card. Huge gritty western letters slam in one by one. */
.levelup { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; overflow: hidden;
  background: radial-gradient(ellipse at 50% 60%, #ff7b2e 0%, #b3261e 45%, #2a0805 100%); }
.lu-flash { position: absolute; inset: 0; background: #fff; opacity: 0; }
.lu-grain { position: absolute; inset: -50%; opacity: 0.09; pointer-events: none;
  background-image: repeating-radial-gradient(circle at 17% 32%, rgba(0,0,0,0.6) 0 1px, transparent 1px 3px), repeating-linear-gradient(90deg, rgba(0,0,0,0.25) 0 1px, transparent 1px 140px); }
.lu-stack { position: relative; display: grid; justify-items: center; gap: 2px; text-align: center; padding: 16px; }
.lu-line { margin: 0; opacity: 0; color: #fff3d6; font-family: "Rye", "Rockwell", Georgia, serif; line-height: 0.95; letter-spacing: 0.02em;
  text-shadow: 0 4px 0 #3a0a04, 0 8px 18px rgba(0,0,0,0.6), 0 0 40px rgba(255,170,60,0.55); }
.lu-l1 { font-size: clamp(3rem, 16vw, 7rem); }
.lu-l2 { font-size: clamp(4rem, 24vw, 10rem); color: #ffd23f; }
.lu-l3 { font-size: clamp(2.2rem, 12vw, 5.5rem); margin-top: 10px; color: #fff; }
.lu-by, .lu-next { font-family: "Anton", "Impact", sans-serif; font-size: clamp(1rem, 4.6vw, 1.5rem); letter-spacing: 0.08em; text-transform: uppercase; text-shadow: 0 2px 0 #3a0a04; }
.lu-btn { opacity: 0; margin-top: 16px; background: #1d0703; box-shadow: 0 5px 0 #000; font-family: "Anton", "Impact", sans-serif; letter-spacing: 0.06em; }
.levelup.go .lu-flash { animation: lu-flash 0.7s ease-out both; }
.levelup.go .lu-l1 { animation: lu-slam 0.45s cubic-bezier(.2,1.4,.4,1) 0.15s both; }
.levelup.go .lu-l2 { animation: lu-slam 0.45s cubic-bezier(.2,1.4,.4,1) 0.75s both; }
.levelup.go .lu-by { animation: lu-fade 0.4s ease-out 1.3s both; }
.levelup.go .lu-l3 { animation: lu-slam-big 0.6s cubic-bezier(.2,1.5,.4,1) 1.35s both; }
.levelup.go .lu-next { animation: lu-fade 0.4s ease-out 2.1s both; }
.levelup.go .lu-btn { animation: lu-fade 0.4s ease-out 2.3s both; }
.levelup.go .lu-stack { animation: lu-shake 0.35s ease-out 0.2s, lu-shake 0.35s ease-out 0.8s, lu-shake 0.5s ease-out 1.45s; }
@keyframes lu-flash { 0% { opacity: 0.95; } 100% { opacity: 0; } }
@keyframes lu-slam { 0% { opacity: 0; transform: scale(3.2) rotate(-4deg); filter: blur(6px); } 70% { opacity: 1; transform: scale(0.94); filter: blur(0); } 100% { opacity: 1; transform: scale(1); } }
@keyframes lu-slam-big { 0% { opacity: 0; transform: scale(4) translateY(-10%); filter: blur(8px); } 65% { opacity: 1; transform: scale(0.92); filter: blur(0); } 100% { opacity: 1; transform: scale(1); } }
@keyframes lu-fade { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes lu-shake { 0%, 100% { transform: none; } 20% { transform: translate(-10px, 6px) rotate(-1deg); } 45% { transform: translate(9px, -5px) rotate(1deg); } 70% { transform: translate(-5px, 3px); } }
@media (prefers-reduced-motion: reduce) {
  .levelup.go .lu-line, .levelup.go .lu-btn { animation: none; opacity: 1; }
  .levelup.go .lu-stack, .levelup.go .lu-flash { animation: none; }
}

/* Distance slam when the ball stops: huge, bottom centre, below the beetle */
.stop-yards { position: fixed; left: 0; right: 0; bottom: calc(28px + env(safe-area-inset-bottom, 0px)); z-index: 25; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; line-height: 0.9; text-align: center; }
.stop-yards .sy-num { font-family: "Anton", Impact, sans-serif; font-size: clamp(5rem, 26vw, 12rem); color: #fff3d6; letter-spacing: 0.02em;
  -webkit-text-stroke: 3px #3e230b; text-shadow: 0 6px 0 #3e230b, 0 0 40px rgba(255, 170, 40, 0.9), 0 0 90px rgba(255, 90, 0, 0.6); }
.stop-yards .sy-unit { font-family: "Rye", Georgia, serif; font-size: clamp(1.6rem, 7vw, 3rem); color: #ffcc33; letter-spacing: 0.25em;
  text-shadow: 0 3px 0 #3e230b, 0 0 20px rgba(255, 170, 40, 0.8); }
.stop-yards.best .sy-num { color: #ffe066; }
.stop-yards.go .sy-num { animation: sy-slam 0.55s cubic-bezier(.2, .9, .3, 1.2) both; }
.stop-yards.go .sy-unit { animation: sy-slam 0.45s 0.35s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes sy-slam { 0% { opacity: 0; transform: scale(3.4); } 70% { opacity: 1; transform: scale(0.94); } 100% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .stop-yards.go .sy-num, .stop-yards.go .sy-unit { animation: none; } }

/* Goal for this round: always visible, top centre */
.goal-box { width: 168px; margin-bottom: 4px; padding: 5px 12px 7px; text-align: left;
  background: rgba(62, 35, 11, 0.85); color: #fff3d6; border-radius: 14px; text-shadow: none; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2); }
.goal-label { font-family: "Anton", Impact, sans-serif; font-size: 1.35rem; letter-spacing: 0.06em; line-height: 1.1; }
.goal-label b { color: #ffcc33; font-weight: 400; font-size: 1.7rem; }
.goal-bar { height: 10px; margin: 4px 0 3px; border-radius: 6px; background: rgba(255, 255, 255, 0.2); overflow: hidden; }
.goal-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffcc33, #ff8a1f); border-radius: 6px; transition: width 0.15s linear; }
.goal-left { font-weight: 800; font-size: 0.95rem; }
.goal-box.done { background: rgba(30, 120, 70, 0.9); }
.goal-box.done .goal-bar i { background: #7dffb0; }
@media (max-width: 520px) { .goal-box { width: 140px; padding: 4px 9px 5px; } .goal-label { font-size: 1rem; } .goal-label b { font-size: 1.25rem; } .goal-left { font-size: 0.8rem; } }

/* Round start: slam the goal in the middle of the screen */
.goal-intro { position: fixed; inset: 0; z-index: 24; pointer-events: none; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; line-height: 0.95; }
.goal-intro .gi-big { font-family: "Anton", Impact, sans-serif; font-size: clamp(3.2rem, 15vw, 8rem); color: #fff3d6; -webkit-text-stroke: 2px #3e230b;
  text-shadow: 0 5px 0 #3e230b, 0 0 40px rgba(255, 170, 40, 0.9); }
.goal-intro .gi-big span { color: #ffcc33; }
.goal-intro .gi-small { font-family: "Rye", Georgia, serif; font-size: clamp(1.3rem, 5vw, 2.4rem); color: #fff3d6; letter-spacing: 0.15em; text-shadow: 0 3px 0 #3e230b; }
.goal-intro.go .gi-small:first-child { animation: sy-slam 0.4s both; }
.goal-intro.go .gi-big { animation: sy-slam 0.5s 0.2s cubic-bezier(.2, .9, .3, 1.2) both; }
.goal-intro.go .gi-small:last-child { animation: sy-slam 0.4s 0.55s both; }
.goal-intro.go { animation: gi-out 0.5s 2.1s both; }
@keyframes gi-out { to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .goal-intro.go, .goal-intro.go * { animation: none !important; } }

/* Chasing a bonus level after passing the goal */
.goal-box.bonus { background: rgba(120, 40, 140, 0.9); box-shadow: 0 0 18px rgba(255, 204, 51, 0.7), 0 4px 0 rgba(0, 0, 0, 0.2); }
.goal-box.bonus .goal-bar i { background: linear-gradient(90deg, #ffcc33, #ff4fd8); }
.levelup.multi #lu-passed { color: #ffe066; text-shadow: 0 4px 0 #3a0a04, 0 0 30px rgba(255, 220, 80, 0.9); }

/* Live yards under the push/flap hint */
.live-yd { position: fixed; left: 50%; bottom: calc(18% - 74px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); pointer-events: none; z-index: 5;
  font-family: "Anton", Impact, sans-serif; font-size: 1.6rem; letter-spacing: 0.08em; color: #fff3d6; white-space: nowrap;
  -webkit-text-stroke: 1px #3e230b; text-shadow: 0 3px 0 #3e230b; font-variant-numeric: tabular-nums; }
.live-yd b { font-weight: 400; font-size: 3.4rem; color: #ffcc33; text-shadow: 0 4px 0 #3e230b, 0 0 20px rgba(255, 170, 40, 0.6); }
@media (max-height: 520px) { .live-yd { bottom: calc(18% - 56px); } .live-yd b { font-size: 2.4rem; } }

/* Give big glowing text room so the browser never clips the glow into a visible box */
.stop-yards .sy-num, .stop-yards .sy-unit, .goal-intro .gi-big, .goal-intro .gi-small { padding: 40px 80px; margin: -40px -80px; }
.stop-yards .sy-num { text-shadow: 0 6px 0 #3e230b, 0 0 28px rgba(255, 170, 40, 0.85); }
.goal-intro .gi-big { text-shadow: 0 5px 0 #3e230b, 0 0 26px rgba(255, 170, 40, 0.8); }

/* Between multiplayer rounds */
.mp-next { display: grid; gap: 8px; justify-items: center; }
.mp-next .sub { margin: 0; }
.res-status { margin: 0; font-weight: 800; font-size: 1.15rem; color: var(--ink); }
.res-status.count { font-family: "Anton", Impact, sans-serif; font-weight: 400; font-size: 2.6rem; letter-spacing: 0.04em; color: #b8641a; }
#btn-vote[aria-pressed="true"] { background: #2fb36b; box-shadow: 0 5px 0 #1e8a50; }

/* Talk dung button (only shows for whoever is in the lead) */
.taunt { position: fixed; right: 12px; bottom: calc(64px + env(safe-area-inset-bottom, 0px)); z-index: 26; display: flex; align-items: center; gap: 6px;
  padding: 8px 14px 8px 8px; border: 0; border-radius: 999px; background: #7a4a1d; color: #fff3d6; font: 800 1.05rem "Baloo 2", sans-serif;
  box-shadow: 0 5px 0 #3e230b; cursor: pointer; animation: taunt-wiggle 1.6s ease-in-out infinite; }
.taunt:active { transform: translateY(3px); box-shadow: 0 2px 0 #3e230b; }
.taunt:disabled { opacity: 0.6; animation: none; cursor: default; }
.taunt .taunt-icon { width: 34px; height: 30px; }
@keyframes taunt-wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-6deg); } 90% { transform: rotate(6deg); } 95% { transform: rotate(-3deg); } }

/* Incoming dung: a pile splats onto the screen */
.dung-splat { position: fixed; inset: 0; z-index: 40; pointer-events: none; display: grid; place-items: center; }
.dung-splat .splat-pile { width: min(60vw, 340px); animation: splat-in 0.5s cubic-bezier(.3, 1.4, .5, 1) both, splat-out 0.5s 2.6s ease-in both; }
.dung-splat .splat-pile svg { width: 100%; height: auto; display: block; filter: drop-shadow(0 10px 0 rgba(62, 35, 11, 0.35)); }
.dung-splat .drop { position: absolute; left: 50%; top: 50%; width: 26px; height: 22px; border-radius: 50% 50% 46% 54%; background: #7a4a1d; border: 3px solid #3e230b; opacity: 0;
  animation: drop-fly 0.6s 0.35s ease-out both, splat-out 0.5s 2.6s ease-in both; }
.dung-splat .d1 { --dx: -34vw; --dy: -18vh; } .dung-splat .d2 { --dx: 30vw; --dy: -24vh; } .dung-splat .d3 { --dx: -26vw; --dy: 22vh; }
.dung-splat .d4 { --dx: 36vw; --dy: 16vh; width: 18px; height: 16px; } .dung-splat .d5 { --dx: 4vw; --dy: -34vh; width: 16px; height: 14px; }
.splat-text { position: absolute; left: 16px; right: 16px; top: calc(50% + min(26vw, 150px)); margin: 0; text-align: center; font-family: "Anton", Impact, sans-serif;
  font-size: clamp(1.4rem, 6vw, 2.6rem); letter-spacing: 0.03em; color: #fff3d6; text-shadow: 0 4px 0 #3e230b, 0 0 18px rgba(62, 35, 11, 0.6);
  animation: sy-slam 0.45s 0.25s both, splat-out 0.5s 2.6s ease-in both; }
@keyframes splat-in { 0% { transform: translateY(-80vh) scale(0.6) rotate(-20deg); } 70% { transform: translateY(0) scale(1.25, 0.8); } 100% { transform: scale(1); } }
@keyframes drop-fly { 0% { opacity: 1; transform: translate(-50%, -50%) scale(0.4); } 100% { opacity: 1; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1, 0.8); } }
@keyframes splat-out { to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .dung-splat *, .taunt { animation: none !important; opacity: 1; } }

.invite { margin: 0; padding: 10px 14px; border-radius: 14px; background: #fff3d6; border: 2px dashed #b8641a; font-weight: 600; color: #3e230b; }

/* Raining Frogs */
.shop-sub { margin: 6px 0 0; font-size: 1.1rem; text-align: left; }
.upgrade.item { background: #eaf8e4; }
.upgrade.item b { display: flex; align-items: center; gap: 6px; }
.upgrade .owned { grid-column: 1; font-weight: 600; color: var(--ink-soft); font-size: 0.9rem; }
.frog-icon { width: 30px; height: 24px; flex: none; }
.frogs-btn { position: fixed; right: 12px; bottom: calc(118px + env(safe-area-inset-bottom, 0px)); z-index: 26; display: flex; align-items: center; gap: 6px;
  padding: 8px 14px 8px 10px; border: 0; border-radius: 999px; background: #2fb36b; color: #fff; font: 800 1.05rem "Baloo 2", sans-serif;
  box-shadow: 0 5px 0 #1e8a50; cursor: pointer; }
.frogs-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #1e8a50; }
.frogs-btn b { display: inline-grid; place-items: center; min-width: 1.5em; height: 1.5em; margin-left: 2px; border-radius: 999px; background: rgba(0, 0, 0, 0.2); }
.goal-box { width: auto; min-width: 168px; max-width: 240px; white-space: nowrap; }
@media (max-width: 520px) { .goal-box { min-width: 140px; } }
