:root {
  --soil: #2a1a10;
  --ink: #2b2118;
  --panel: rgba(255, 248, 236, 0.92);
  --water: #46a8f0;
  --frog: #5fbf4a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--soil);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(#6fbf5a, #4f9a3f);
  box-shadow: 0 3px 0 #3c7a2f;
  position: relative;
  z-index: 2;
}

.brand {
  font-weight: 800;
  font-size: 20px;
  color: #fff;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
}

.pill {
  background: var(--panel);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}

.meter {
  position: relative;
  flex: 1;
  min-width: 70px;
  max-width: 220px;
  height: 22px;
  border-radius: 999px;
  background: rgba(20, 40, 60, 0.45);
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
#meterFill {
  height: 100%;
  width: 0;
  background: linear-gradient(#9bdcff, var(--water));
  border-radius: 999px;
  transition: width 0.2s ease-out;
}
#meterLabel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.flies { display: flex; gap: 4px; }
.flies.big { justify-content: center; gap: 14px; margin: 6px 0 4px; }

/* A fly icon: dark body, pale wings. */
.fly {
  position: relative;
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.18);
}
.fly::before, .fly::after { content: ""; position: absolute; }
.fly::before {
  left: 5px; top: 5px; width: 8px; height: 10px;
  border-radius: 50%;
  background: #1d2230;
  opacity: 0.25;
}
.fly::after {
  left: 1px; top: 1px; width: 16px; height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  opacity: 0.25;
}
.fly.got { background: #fff3a8; box-shadow: 0 0 8px #ffe76a; }
.fly.got::before, .fly.got::after { opacity: 1; }
.fly.dead { background: rgba(120, 50, 160, 0.35); }
.fly.big { width: 40px; height: 40px; transform: scale(1); }
.fly.big::before { left: 12px; top: 11px; width: 16px; height: 22px; }
.fly.big::after { left: 3px; top: 3px; width: 34px; height: 14px; }

.actions { margin-left: auto; display: flex; gap: 6px; }
.actions button {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 800;
}
.actions button svg { width: 20px; height: 20px; }
.actions button:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18); }
#soundBtn.off { opacity: 0.45; text-decoration: line-through; }

@media (max-width: 600px) {
  #bar { gap: 6px; padding: 8px; flex-wrap: wrap; }
  .brand { display: none; }
  .pill { max-width: 130px; font-size: 13px; }
  .actions button { width: 36px; height: 36px; }
  .fly { width: 15px; height: 15px; }
  .fly::before { left: 4px; top: 4px; width: 7px; height: 8px; }
  .fly::after { left: 1px; top: 1px; width: 13px; height: 6px; }
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
}
#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.tip {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  max-width: min(440px, calc(100% - 24px));
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--panel);
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
  pointer-events: none;
  transition: opacity 0.6s;
}
.tip.fade { opacity: 0; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(20, 12, 6, 0.55);
  padding: 20px;
}
.overlay[hidden] { display: none; }

.card {
  width: min(340px, 100%);
  background: #fff8ec;
  border-radius: 22px;
  padding: 22px 22px 18px;
  text-align: center;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: pop 0.25s ease-out;
}
.card.wide { width: min(520px, 100%); max-height: 100%; overflow: hidden; }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
.card h2 { margin: 0; font-size: 28px; color: #3c7a2f; }
#failTitle { color: #8a3cb8; }
.lede { margin: 0 0 6px; font-size: 16px; line-height: 1.4; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.primary, .soft {
  padding: 12px 16px;
  border-radius: 14px;
  font-weight: 800;
  font-size: 17px;
}
.primary { background: var(--frog); color: #fff; box-shadow: 0 4px 0 #3c7a2f; }
.soft { background: #efe2cc; box-shadow: 0 3px 0 #d3c0a0; }
.primary:active, .soft:active { transform: translateY(2px); box-shadow: none; }
.primary[hidden] { display: none; }

.levelGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
  /* Only the grid scrolls, so the title and Close stay put. */
  min-height: 0;
  overflow: auto;
  padding: 2px 2px 6px;
}
.levelBtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  border-radius: 14px;
  background: #e6f3d9;
  box-shadow: 0 3px 0 #b7d39c;
}
.levelBtn b { font-size: 20px; color: #3c7a2f; }
.levelBtn span { font-size: 12px; font-weight: 700; line-height: 1.2; min-height: 2.4em; display: flex; align-items: center; }
.levelBtn em { display: flex; gap: 3px; font-style: normal; }
.levelBtn .fly { width: 14px; height: 14px; }
.levelBtn .fly::before { left: 4px; top: 3px; width: 6px; height: 8px; }
.levelBtn .fly::after { left: 1px; top: 1px; width: 12px; height: 5px; }
.levelBtn.current { outline: 3px solid var(--frog); }
.levelBtn:disabled { opacity: 0.45; cursor: default; }
