:root {
  color-scheme: light;
  --ink: #243322;
  --muted: #63745d;
  --leaf: #408a4b;
  --lime: #dff08b;
  --sun: #ffd86b;
  --soil: #72523b;
}

* { box-sizing: border-box; }
html { min-width: 0; background: #eaf4c9; }
body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: ui-rounded, "Trebuchet MS", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% 4%, rgba(255, 230, 123, .85), transparent 26%),
    radial-gradient(circle at 92% 12%, rgba(127, 207, 129, .55), transparent 29%),
    linear-gradient(155deg, #eef8d2, #cce6ae);
}
button { font: inherit; }
.game-shell { width: min(100%, 780px); margin: 0 auto; padding: clamp(12px, 3vw, 26px); }
.game-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.eyebrow { margin: 0 0 3px; color: #617654; font-size: .7rem; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
h1, h2 { margin: 0; line-height: 1.05; }
h1 { font-size: clamp(1.55rem, 5.5vw, 2.45rem); letter-spacing: -.045em; }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.actions button, .primary {
  min-height: 44px;
  border: 1px solid rgba(49, 91, 45, .2);
  border-radius: 13px;
  padding: 9px 14px;
  color: #294128;
  background: rgba(255, 255, 255, .7);
  box-shadow: 0 7px 17px rgba(65, 94, 47, .12);
  cursor: pointer;
  font-weight: 850;
}
.actions button:hover { background: #fff; transform: translateY(-1px); }
button:focus-visible { outline: 3px solid #7650c7; outline-offset: 3px; }

.hud { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; margin-bottom: 8px; }
.hud div { min-width: 0; padding: 9px 5px; border: 1px solid rgba(55, 99, 50, .17); border-radius: 15px; text-align: center; background: rgba(255,255,255,.72); box-shadow: 0 8px 20px rgba(65, 94, 47, .1); }
.hud span { display: block; color: var(--muted); font-size: .67rem; font-weight: 700; }
.hud strong { display: block; overflow: hidden; font-size: clamp(1rem, 4vw, 1.25rem); text-overflow: ellipsis; white-space: nowrap; }
.hud strong.pop { animation: hud-pop .24s ease-out; }
.status { min-height: 1.4em; margin: 0 0 8px; color: #4d6547; font-size: .88rem; font-weight: 800; text-align: center; }
.status[data-mood="good"] { color: #257044; }
.status[data-mood="warning"] { color: #a33e38; }

.arena {
  position: relative;
  width: min(100%, 680px);
  height: clamp(430px, 68vh, 590px);
  min-height: 430px;
  margin: 0 auto;
  border: 3px solid rgba(78, 101, 45, .23);
  border-radius: 32px;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(ellipse at 18% 17%, rgba(255,255,255,.32), transparent 18%),
    repeating-linear-gradient(13deg, transparent 0 34px, rgba(63, 120, 59, .04) 35px 37px),
    linear-gradient(155deg, #a9d670, #72b86a 60%, #5da65e);
  box-shadow: inset 0 0 70px rgba(32, 95, 43, .18), 0 25px 50px rgba(47, 82, 35, .2);
  touch-action: manipulation;
  user-select: none;
}
.arena::after { content: ""; position: absolute; z-index: -1; inset: auto -7% -12% -7%; height: 32%; border-radius: 50% 50% 0 0; background: rgba(92, 65, 41, .23); }
.leaf { position: absolute; width: 120px; height: 55px; border-radius: 100% 0 100% 0; background: linear-gradient(145deg, #5ca658, #2e7740); box-shadow: inset 10px 8px rgba(255,255,255,.1); opacity: .42; transform: rotate(-22deg); pointer-events: none; }
.leaf::after { content: ""; position: absolute; left: 9%; right: 8%; top: 50%; height: 2px; background: rgba(25,78,35,.5); transform: rotate(-6deg); }
.leaf-one { left: -22px; top: 18%; }
.leaf-two { right: -27px; bottom: 18%; transform: rotate(153deg) scale(.8); }
.stone { position: absolute; left: 8%; bottom: 6%; width: 75px; height: 43px; border-radius: 55% 45% 40% 60%; background: linear-gradient(145deg, #c6bea5, #807b69); opacity: .48; transform: rotate(8deg); pointer-events: none; }

.insect {
  position: absolute;
  z-index: 2;
  width: var(--size);
  height: var(--size);
  margin: calc(var(--size) / -2);
  border: 0;
  padding: 0;
  border-radius: 50%;
  color: inherit;
  background: transparent;
  filter: drop-shadow(0 5px 4px rgba(30, 57, 25, .28));
  cursor: crosshair;
  animation: insect-arrive .2s cubic-bezier(.2,.9,.25,1.4), skitter var(--ttl) linear forwards;
  transform-origin: center;
}
.insect svg { display: block; width: 100%; height: 100%; overflow: visible; }
.insect:hover { filter: drop-shadow(0 7px 5px rgba(30,57,25,.35)) brightness(1.1); }
.insect:focus-visible { outline: 4px solid #fff4a9; outline-offset: 3px; }
.insect.is-hit { pointer-events: none; animation: squash .24s ease-out forwards; }
.insect.is-armored-hit { animation: armor-hit .28s ease-out, skitter var(--ttl) linear forwards; filter: drop-shadow(0 0 8px #fff19a); }
.insect.firefly { filter: drop-shadow(0 0 10px rgba(255, 241, 107, .9)); }

.effects { position: absolute; z-index: 3; inset: 0; pointer-events: none; overflow: hidden; }
.particle { position: absolute; width: 8px; height: 8px; margin: -4px; border-radius: 50%; background: var(--color); animation: particle-fly .48s ease-out forwards; }
.score-pop { position: absolute; z-index: 4; margin: -12px 0 0 -32px; width: 64px; color: #fffde0; font-size: 1.05rem; font-weight: 950; text-align: center; text-shadow: 0 2px 4px rgba(28,61,28,.55); animation: score-fly .72s ease-out forwards; pointer-events: none; }
.combo-banner { position: absolute; z-index: 5; left: 50%; top: 17%; color: #fff7a6; font-size: clamp(1.4rem, 7vw, 2.3rem); font-weight: 950; text-shadow: 0 4px 12px rgba(42,70,24,.45); transform: translateX(-50%); animation: combo-burst .75s ease both; pointer-events: none; }

.overlay { position: absolute; z-index: 10; inset: 0; display: grid; place-items: center; padding: 18px; background: rgba(33, 61, 28, .48); backdrop-filter: blur(5px); }
.overlay[hidden] { display: none; pointer-events: none; }
.overlay-card { width: min(100%, 365px); padding: 29px 25px; border: 1px solid rgba(255,255,255,.72); border-radius: 26px; text-align: center; background: rgba(255,255,246,.94); box-shadow: 0 25px 65px rgba(33,61,28,.32); }
.overlay-card h2 { font-size: clamp(1.65rem, 7vw, 2.25rem); }
.overlay-card > p:not(.eyebrow) { color: #52684d; line-height: 1.55; }
.primary { width: 100%; border: 0; color: #25351f; background: linear-gradient(135deg, var(--sun), var(--lime)); font-size: 1.05rem; }
.primary:hover { filter: brightness(1.05) saturate(1.1); transform: translateY(-2px); }

.legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 13px auto 0; color: #53694e; font-size: .8rem; }
.legend p { margin: 0; padding: 10px; border: 1px solid rgba(55,99,50,.14); border-radius: 13px; background: rgba(255,255,255,.57); }
.legend-dot { display: inline-block; width: 10px; height: 10px; margin-right: 5px; border-radius: 50%; }
.ant-dot { background: #59352b; }
.beetle-dot { background: #6948a9; }
.firefly-dot { background: #f2ce27; box-shadow: 0 0 6px #e9ba24; }

@keyframes insect-arrive { from { opacity: 0; transform: scale(.25) rotate(-25deg); } to { opacity: 1; } }
@keyframes skitter { 0% { translate: 0 0; rotate: -8deg; } 33% { translate: var(--dx1) var(--dy1); rotate: 9deg; } 66% { translate: var(--dx2) var(--dy2); rotate: -6deg; } 100% { translate: var(--dx3) var(--dy3); rotate: 6deg; } }
@keyframes squash { 35% { opacity: 1; scale: 1.24 .55; } 100% { opacity: 0; scale: 1.5 .2; rotate: 18deg; } }
@keyframes armor-hit { 25% { scale: 1.22; rotate: -10deg; } 65% { translate: 5px 0; rotate: 9deg; } }
@keyframes particle-fly { to { opacity: 0; translate: var(--px) var(--py); scale: .25; } }
@keyframes score-fly { 0% { opacity: 0; scale: .65; } 22% { opacity: 1; scale: 1.15; } 100% { opacity: 0; translate: 0 -48px; } }
@keyframes combo-burst { 0% { opacity: 0; scale: .5; } 25% { opacity: 1; scale: 1.17; } 100% { opacity: 0; translate: 0 -25px; } }
@keyframes hud-pop { 50% { color: #7346b2; scale: 1.23; } }

@media (max-width: 560px) {
  .game-shell { padding: 10px 8px 18px; }
  .game-header { align-items: flex-start; }
  .actions { gap: 4px; }
  .actions button { min-height: 40px; padding: 7px 9px; font-size: .7rem; }
  .hud { gap: 4px; }
  .hud div { padding: 7px 2px; border-radius: 10px; }
  .hud span { font-size: .57rem; }
  .arena { height: min(68vh, 530px); min-height: 420px; border-radius: 23px; }
  .legend { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
  .insect { animation: insect-arrive .01ms linear, skitter var(--ttl) linear forwards; }
  .particle, .score-pop, .combo-banner { animation-duration: .01ms !important; }
}
