@font-face { font-family: "Lilita"; src: url("fonts/LilitaOne-Regular.ttf") format("truetype"); font-display: block; }
:root {
  --u: clamp(11px, min(2.1vw, 3.3vh), 22px);   /* base unit: legible from 640x360 up to desktop */
  --ink: #1d1442;
}
html, body { margin: 0; height: 100%; overflow: hidden; background: #7cc8ff; }
body { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none;
  font-family: "Lilita", "Arial Black", system-ui, sans-serif; color: #fff; }
canvas#game { display: block; position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; touch-action: none; outline: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
.hidden { display: none !important; }
.ic { display: inline-block; width: 1.25em; height: 1.25em; background: center/contain no-repeat; vertical-align: middle; flex: none; }
.stroke { paint-order: stroke fill; -webkit-text-stroke: 0.18em var(--ink); }
.ic.coin { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Ccircle cx='20' cy='21' r='17' fill='%23b86a00'/%3E%3Ccircle cx='20' cy='19' r='17' fill='%23ffc928'/%3E%3Ccircle cx='20' cy='19' r='11.5' fill='%23ffe37a' stroke='%23e89a00' stroke-width='3'/%3E%3Cpath d='M16 13h6l-2 6h4l-8 9 2-7h-4z' fill='%23e89a00'/%3E%3C/svg%3E"); }
.ic.snd { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M6 15h7l9-8v26l-9-8H6z' fill='%23fff' stroke='%231d1442' stroke-width='3' stroke-linejoin='round'/%3E%3Cpath d='M27 13q5 7 0 14M31 9q9 11 0 22' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round'/%3E%3C/svg%3E"); }
.ic.mute { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M6 15h7l9-8v26l-9-8H6z' fill='%23fff' stroke='%231d1442' stroke-width='3' stroke-linejoin='round'/%3E%3Cpath d='M27 14l9 12M36 14l-9 12' stroke='%23ff5a6e' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E"); }
.ic.ad { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect x='4' y='8' width='32' height='24' rx='6' fill='%23fff'/%3E%3Cpath d='M17 14v12l10-6z' fill='%237a3cff'/%3E%3C/svg%3E"); }
/* pills */
.pill { display: inline-flex; align-items: center; gap: 0.35em; background: linear-gradient(#3b2a86, #241a5c); border: 0.2em solid #fff; border-radius: 2em;
  padding: 0.15em 0.8em 0.15em 0.35em; font-size: calc(var(--u) * 1.35); box-shadow: 0 0.25em 0 rgba(0,0,0,0.25); text-shadow: 0 0.12em 0 rgba(0,0,0,0.35); }
.pill .ic { width: 1.5em; height: 1.5em; }
.pill.power { font-size: calc(var(--u) * 1.9); background: linear-gradient(#ff8a2b, #e8491d); }

@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
#hud { position: absolute; inset: 0; padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
#hud .tl { position: absolute; left: max(10px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top)); }
#hud .tc { position: absolute; left: 50%; top: max(8px, env(safe-area-inset-top)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 0.3em; }
#hud .tr { position: absolute; right: max(10px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); display: flex; gap: 0.5em; pointer-events: auto; }
#hud .bottom { position: absolute; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 0.2em; }

/* buttons */
.btn { pointer-events: auto; font-family: inherit; color: #fff; border: 0; cursor: pointer; position: relative; border-radius: 0.8em;
  text-shadow: 0 0.1em 0 rgba(0,0,0,0.35); box-shadow: 0 0.3em 0 rgba(0,0,0,0.28), inset 0 -0.3em 0 rgba(0,0,0,0.18), inset 0 0.18em 0 rgba(255,255,255,0.35);
  border: 0.17em solid #fff; transition: transform 0.08s; display: inline-flex; align-items: center; justify-content: center; gap: 0.35em; }
.btn:active { transform: translateY(0.15em) scale(0.97); }
.btn.round { width: calc(var(--u) * 3.1); height: calc(var(--u) * 3.1); border-radius: 1em; font-size: var(--u); }
.btn.round .ic { width: 1.9em; height: 1.9em; }
.btn.green { background: linear-gradient(#6af06a, #26b14a); }
.btn.blue { background: linear-gradient(#5cc8ff, #2a7cf0); }
.btn.orange { background: linear-gradient(#ffb43a, #f06a1a); }
.btn.purple { background: linear-gradient(#b38bff, #7a3cff); }
.btn.gray { background: linear-gradient(#b9bfd0, #8a90a6); }
.btn.big { font-size: calc(var(--u) * 1.6); padding: 0.4em 1.6em; }
.btn.mid { font-size: calc(var(--u) * 1.15); padding: 0.45em 0.9em; }
.btn .dot { position: absolute; right: -0.3em; top: -0.3em; width: 1em; height: 1em; border-radius: 50%; background: #ff3b5c; border: 0.15em solid #fff; display: none; }
.btn.can .dot { display: block; }
.btn.can { animation: wiggle 1.4s infinite; }
@keyframes wiggle { 0%, 70%, 100% { transform: rotate(0); } 76% { transform: rotate(-9deg) scale(1.08); } 84% { transform: rotate(9deg) scale(1.08); } 92% { transform: rotate(-4deg); } }

/* logo shown at the start */
#logo { position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%) rotate(-4deg); text-align: center; line-height: 0.85; animation: logoIn 0.7s cubic-bezier(.2,1.5,.4,1); transition: opacity 0.6s, transform 0.6s; }
#logo div { paint-order: stroke fill; -webkit-text-stroke: 0.14em var(--ink); text-shadow: 0 0.1em 0 var(--ink); }
#logo .t1 { font-size: calc(var(--u) * 5.2); color: #ffd23f; }
#logo .t2 { font-size: calc(var(--u) * 6.4); color: #ff7a1a; }
#logo.out { opacity: 0; transform: translate(-50%, -90%) rotate(-4deg) scale(0.8); }
@keyframes logoIn { 0% { transform: translate(-50%, -50%) scale(0.3) rotate(-14deg); } 100% { transform: translate(-50%, -50%) scale(1) rotate(-4deg); } }

/* world-space popups */
#pops, #labels { position: absolute; inset: 0; overflow: hidden; }
.pop { position: absolute; left: 0; top: 0; display: none; will-change: transform; }
.pop > span { display: block; transform: translate(-50%, -100%); white-space: nowrap; paint-order: stroke fill; -webkit-text-stroke: 0.16em var(--ink); text-shadow: 0 0.08em 0 var(--ink); }
.pop.plus > span { font-size: calc(var(--u) * 1.5); color: #fff; }
.pop.full > span { font-size: calc(var(--u) * 1.4); color: #ffdd57; }
.pop.coin > span { font-size: calc(var(--u) * 1.3); color: #ffd23f; }
.pop.badge > span { font-size: calc(var(--u) * 1.25); -webkit-text-stroke: 0; text-shadow: none; padding: 0.1em 0.55em; border-radius: 1em; border: 0.16em solid #fff; box-shadow: 0 0.2em 0 rgba(0,0,0,0.3); }
.pop.heart > span { font-size: calc(var(--u) * 1.4); color: #ff6b9a; }
.pop.sad > span { font-size: calc(var(--u) * 1.4); color: #ff5a6e; }
@keyframes popUp { 0% { transform: translate(-50%, -60%) scale(0.3); opacity: 0; } 15% { transform: translate(-50%, -100%) scale(1.25); opacity: 1; } 30% { transform: translate(-50%, -110%) scale(1); } 75% { opacity: 1; } 100% { transform: translate(-50%, -190%) scale(0.95); opacity: 0; } }

/* modals */
.modal { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(20,12,50,0.55); pointer-events: auto; }
.panel { background: linear-gradient(#5a3fd1, #3a2697); border: 0.25em solid #fff; border-radius: 1.6em; padding: 1em 1.2em 1.2em; text-align: center; box-shadow: 0 0.5em 0 rgba(0,0,0,0.3);
  font-size: var(--u); max-width: 92vw; max-height: 92vh; box-sizing: border-box; display: flex; flex-direction: column; align-items: center; gap: 0.7em; animation: panelIn 0.35s cubic-bezier(.2,1.4,.4,1); }
@keyframes panelIn { 0% { transform: scale(0.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.ptitle { font-size: 2.6em; line-height: 1; paint-order: stroke fill; -webkit-text-stroke: 0.14em var(--ink); text-shadow: 0 0.1em 0 var(--ink); }
.ptitle.gold { color: #ffd23f; }
.pcoins, .rescoins { display: inline-flex; align-items: center; gap: 0.3em; font-size: 1.7em; background: rgba(0,0,0,0.25); padding: 0.1em 0.8em 0.1em 0.3em; border-radius: 1em; }
.pcoins .ic, .rescoins .ic { width: 1.4em; height: 1.4em; }
.row { display: flex; gap: 0.7em; }
.teaser { font-size: 0.9em; opacity: 0.85; color: #cfe8ff; }

#loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.2em; background: radial-gradient(circle at 50% 40%, #8fe0ff, #2f8fff); pointer-events: auto; font-size: var(--u); transition: opacity 0.4s; }
#loading.out { opacity: 0; pointer-events: none; }
.ltitle { display: flex; flex-direction: column; align-items: center; line-height: 0.85; transform: rotate(-4deg); }
.ltitle span { font-size: 5em; paint-order: stroke fill; -webkit-text-stroke: 0.14em var(--ink); text-shadow: 0 0.1em 0 var(--ink); color: #ffd23f; }
.ltitle span + span { font-size: 6.2em; color: #ff7a1a; }
.lbar { width: 16em; height: 1.2em; border-radius: 1em; background: rgba(29,20,66,0.5); border: 0.18em solid #fff; overflow: hidden; }
#lfill { height: 100%; width: 0; background: linear-gradient(90deg, #ffd23f, #49e06a); transition: width 0.15s; }

/* ---------- Sort the Herd additions ---------- */
html, body { background: #9fdc6e; }
.ic.undo { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M14 9 4 17l10 8v-5h9a6 6 0 0 1 0 12h-6v6h6a12 12 0 0 0 0-24h-9z' fill='%23fff' stroke='%231d1442' stroke-width='3' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.ic.restart { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M20 6a14 14 0 1 0 13 9' fill='none' stroke='%231d1442' stroke-width='9' stroke-linecap='round'/%3E%3Cpath d='M20 6a14 14 0 1 0 13 9' fill='none' stroke='%23fff' stroke-width='4.5' stroke-linecap='round'/%3E%3Cpath d='M19 0l9 6-9 7z' fill='%23fff' stroke='%231d1442' stroke-width='2.5' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.pill .sm { font-size: 0.62em; opacity: 0.85; margin-right: 0.1em; }
.pill.lvl { font-size: calc(var(--u) * 1.05); background: linear-gradient(#2f7fd8, #1d4f9a); padding-left: 0.7em; }
.pill.moves { font-size: calc(var(--u) * 1.2); background: linear-gradient(#ff9a3c, #e8601d); padding-left: 0.8em; }
#hud .tl { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
#hud .bottom { flex-direction: row; gap: 0.8em; font-size: var(--u); pointer-events: auto; }
#hud .bottom .btn { font-size: calc(var(--u) * 1.25); padding: 0.4em 0.9em; white-space: nowrap; }
.btn .cnt { position: absolute; right: -0.55em; top: -0.6em; min-width: 1.4em; height: 1.4em; line-height: 1.4em; border-radius: 1em; background: #ff3b5c; border: 0.14em solid #fff; font-weight: normal; font-size: 0.85em; }
.btn.off { background: linear-gradient(#c9cde0, #9aa0b8); }
.btn.off .cnt { background: #8a90a6; }
.btn.used { visibility: hidden; }
.btn:disabled { cursor: default; }
#logo { top: 30%; pointer-events: none; }
#logo .t1 { font-size: calc(var(--u) * 3.4); color: #fff; }
#logo .t2 { font-size: calc(var(--u) * 6.2); color: #ffd23f; }
#logo .sub { font-size: calc(var(--u) * 1.35); color: #fff; margin-top: 0.6em; -webkit-text-stroke: 0.16em var(--ink); }
#logo .sub { white-space: nowrap; }
#toast { position: absolute; left: 50%; bottom: calc(var(--u) * 5.2); transform: translateX(-50%); font-size: calc(var(--u) * 1.15); background: rgba(29,20,66,0.85); border: 0.16em solid #fff;
  border-radius: 1em; padding: 0.35em 0.9em; white-space: nowrap; animation: panelIn 0.3s cubic-bezier(.2,1.4,.4,1); }
/* tutorial hand: points at a pen (positioned in JS) */
#hand { position: absolute; left: 0; top: 0; width: calc(var(--u) * 3.6); height: calc(var(--u) * 3.6); margin-left: calc(var(--u) * -1.1); pointer-events: none; will-change: transform; }
#hand::before { content: ""; position: absolute; inset: 0; animation: tapHand 1s ease-in-out infinite;
  background: center/contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M15 4a3 3 0 0 1 6 0v12l2-1a3 3 0 0 1 4 2l1-.4a3 3 0 0 1 4 2.4l.5-.2a3 3 0 0 1 3.5 3V30a8 8 0 0 1-8 8h-6a8 8 0 0 1-6.5-3.3L8 27a3 3 0 0 1 4.5-4L15 26z' fill='%23fff' stroke='%231d1442' stroke-width='2.6' stroke-linejoin='round'/%3E%3C/svg%3E"); }
@keyframes tapHand { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-0.6em) scale(1.06); } }
/* result stars */
.stars { display: flex; gap: 0.3em; align-items: flex-end; }
.stars i { width: 3.4em; height: 3.4em; background: center/contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M20 3l5 10.5 11.5 1.5-8.4 8 2.1 11.4L20 29l-10.2 5.4L11.9 23 3.5 15 15 13.5z' fill='%23302070' stroke='%23fff' stroke-width='2.5' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.stars i:nth-child(2) { width: 4.2em; height: 4.2em; }
.stars i.on { animation: starIn 0.45s cubic-bezier(.2,1.8,.4,1) backwards;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M20 3l5 10.5 11.5 1.5-8.4 8 2.1 11.4L20 29l-10.2 5.4L11.9 23 3.5 15 15 13.5z' fill='%23ffd23f' stroke='%23fff' stroke-width='2.5' stroke-linejoin='round'/%3E%3Cpath d='M14 15l5-1' stroke='%23fff6c0' stroke-width='2.5' stroke-linecap='round'/%3E%3C/svg%3E"); }
@keyframes starIn { 0% { transform: scale(0) rotate(-40deg); } 100% { transform: scale(1) rotate(0); } }
.pop.done > span { font-size: calc(var(--u) * 1.4); color: #ffd23f; }
.pop.nope > span { font-size: calc(var(--u) * 1.2); color: #fff; }
.modal { background: rgba(20,12,50,0.4); }
@media (max-aspect-ratio: 4/5) {  /* phone portrait */
  :root { --u: clamp(11px, 3.6vw, 20px); }
  #hud .tc { top: calc(max(8px, env(safe-area-inset-top)) + 0.3em); }
  #logo { top: 25%; }
  #logo .t1 { font-size: calc(var(--u) * 2.6); } #logo .t2 { font-size: calc(var(--u) * 4.6); } #logo .sub { font-size: calc(var(--u) * 1.1); }
}
@media (max-height: 420px) { /* small landscape */
  .panel { padding: 0.5em 1em 0.7em; gap: 0.45em; }
  .ptitle { font-size: 2em; }
  .stars i { width: 2.6em; height: 2.6em; } .stars i:nth-child(2) { width: 3.2em; height: 3.2em; }
}
