* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

:root {
  --bg: #07111f;
  --card: #0f1d31;
  --card-2: #15253d;
  --text: #f8fafc;
  --muted: #9fb0c7;
  --accent: #22c55e;
  --danger: #ef4444;
  --yellow: #facc15;
  --gold: #fbbf24;
  --hole: #07101c;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, #15345b 0, transparent 38%),
    var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

body {
  min-height: 100svh;
  display: flex;
  justify-content: center;
  padding: 16px;
  user-select: none;
}

button {
  font: inherit;
}

.game-shell {
  width: min(680px, 100%);
  margin: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #60a5fa;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1, h2, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 6vw, 2.3rem);
  line-height: 1;
}

.restart-btn,
.icon-btn {
  border: 1px solid #334155;
  background: #16243a;
  color: var(--text);
  border-radius: 12px;
  cursor: pointer;
}

.restart-btn {
  padding: 10px 14px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.05rem;
  display: grid;
  place-items: center;
  line-height: 1;
}

.icon-btn:disabled {
  opacity: .4;
  cursor: default;
}

.icon-btn[aria-pressed="false"] {
  color: var(--muted);
}

.restart-btn:active,
.icon-btn:active:not(:disabled),
.start-btn:active {
  transform: scale(0.94);
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.stat {
  background: rgba(15, 29, 49, 0.88);
  border: 1px solid #213551;
  border-radius: 14px;
  padding: 10px 6px;
  text-align: center;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  margin-bottom: 2px;
}

.stat strong {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

#best {
  color: var(--gold);
}

.game-card {
  position: relative;
  background: linear-gradient(145deg, rgba(21, 37, 61, 0.98), rgba(9, 20, 35, 0.98));
  border: 1px solid #263d5b;
  border-radius: 22px;
  padding: clamp(12px, 3vw, 20px);
  box-shadow: 0 18px 50px rgba(0,0,0,.28);
  transform: translate3d(0,0,0);
}

.game-card.shake {
  animation: shake .32s ease;
}

@keyframes shake {
  10% { transform: translate3d(-6px, 0, 0); }
  30% { transform: translate3d(5px, 0, 0); }
  50% { transform: translate3d(-4px, 0, 0); }
  70% { transform: translate3d(3px, 0, 0); }
  90% { transform: translate3d(-2px, 0, 0); }
  100% { transform: translate3d(0, 0, 0); }
}

.message {
  min-height: 28px;
  text-align: center;
  color: #dbeafe;
  font-size: 0.88rem;
  font-weight: 650;
  margin-bottom: 10px;
  transition: color .15s ease;
}

.message.warn {
  color: #fca5a5;
}

.message.gold {
  color: var(--gold);
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(9px, 2.5vw, 16px);
  aspect-ratio: 1 / 1;
  position: relative;
}

.hole {
  position: relative;
  overflow: hidden;
  border: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 42%, #14253b 0 46%, #091321 47% 69%, #030810 70% 100%);
  box-shadow:
    inset 0 8px 16px rgba(0,0,0,.55),
    0 3px 0 rgba(255,255,255,.03);
  cursor: pointer;
  touch-action: manipulation;
  padding: 0;
}

.hole::after {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  border: 1px solid rgba(148,163,184,.06);
  pointer-events: none;
}

.virus {
  position: absolute;
  width: 48%;
  aspect-ratio: 1;
  left: 26%;
  top: 110%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #fecaca 0 8%, transparent 9%),
    radial-gradient(circle at 62% 62%, #991b1b 0 5%, transparent 6%),
    radial-gradient(circle, #ef4444 0 55%, #b91c1c 56% 100%);
  box-shadow: 0 8px 18px rgba(239,68,68,.35);
  transition: top .12s ease-out, transform .1s ease;
  pointer-events: none;
}

.virus::before,
.virus::after {
  content: "";
  position: absolute;
  inset: -14%;
  border-radius: 50%;
  border: 5px dotted #f87171;
  transform: rotate(12deg);
}

.virus::after {
  inset: -22%;
  border-width: 3px;
  border-color: #fca5a5;
  transform: rotate(-20deg);
}

.hole.active .virus {
  top: 24%;
  animation: wobble .55s ease-in-out infinite alternate;
}

.hole.hit .virus {
  transform: scale(.72) rotate(18deg);
  filter: brightness(1.7);
}

/* Golden bonus virus */
.virus.type-golden {
  background:
    radial-gradient(circle at 35% 30%, #fff7cc 0 10%, transparent 11%),
    radial-gradient(circle at 62% 62%, #b45309 0 5%, transparent 6%),
    radial-gradient(circle, #fde68a 0 55%, var(--gold) 56% 100%);
  box-shadow: 0 0 22px rgba(251,191,36,.65), 0 8px 18px rgba(180,83,9,.35);
}

.virus.type-golden::before,
.virus.type-golden::after {
  border-color: #fde68a;
}

.hole.active .virus.type-golden {
  animation: wobble .55s ease-in-out infinite alternate, sparkle 1s ease-in-out infinite;
}

@keyframes sparkle {
  0%, 100% { filter: brightness(1) drop-shadow(0 0 0 rgba(251,191,36,0)); }
  50% { filter: brightness(1.35) drop-shadow(0 0 10px rgba(251,191,36,.8)); }
}


/* =========================
   GOOD TARGET - WHITE BLOOD CELL
   ========================= */

.virus.type-good {
  background:
    radial-gradient(
      circle at 50% 50%,
      #ffffff 0%,
      #f8fafc 55%,
      #cbd5e1 100%
    );

  box-shadow:
    0 8px 18px rgba(255, 255, 255, 0.25),
    inset 0 0 12px rgba(148, 163, 184, 0.45);
}

/* Purple nucleus */
.virus.type-good::before {
  content: "";
  position: absolute;

  width: 42%;
  height: 38%;

  left: 29%;
  top: 31%;

  background: #8b5cf6;

  border-radius: 45% 55% 50% 45%;

  box-shadow:
    inset 3px 2px 5px rgba(255, 255, 255, 0.45),
    0 2px 5px rgba(76, 29, 149, 0.35);

  transform: rotate(-12deg);
}

/* Small cell granules */
.virus.type-good::after {
  content: "";

  position: absolute;
  inset: 0;

  border: none;

  background:
    radial-gradient(circle at 20% 35%, #cbd5e1 0 3%, transparent 4%),
    radial-gradient(circle at 75% 30%, #cbd5e1 0 3%, transparent 4%),
    radial-gradient(circle at 75% 70%, #cbd5e1 0 3%, transparent 4%),
    radial-gradient(circle at 25% 75%, #cbd5e1 0 3%, transparent 4%);
}

/* Friendly dragonfly — do NOT tap */
/* 
.virus.type-good {
  background: none;
  box-shadow: none;
}

.virus.type-good::before,
.virus.type-good::after {
  border: none;
}

.virus.type-good .bug-icon {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.9rem;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.35));
} */

.hole.active .virus.type-good {
  animation: wobble .55s ease-in-out infinite alternate;
}

.hole.hit.wrong .virus {
  filter: brightness(1.3) saturate(0.4);
  transform: scale(.8) rotate(-14deg);
}

@keyframes wobble {
  from { margin-left: -2px; }
  to { margin-left: 2px; }
}

/* Floating score / miss popups */
.pop {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translate(-50%, 0);
  font-weight: 900;
  font-size: 1rem;
  pointer-events: none;
  animation: popRise .6s ease-out forwards;
  z-index: 2;
  text-shadow: 0 2px 6px rgba(0,0,0,.5);
}

.pop.good { color: #4ade80; }
.pop.gold { color: var(--gold); }
.pop.bad { color: #f87171; }

@keyframes popRise {
  0% { opacity: 0; transform: translate(-50%, 6px) scale(.8); }
  20% { opacity: 1; transform: translate(-50%, -4px) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -34px) scale(1); }
}

/* Hit particles */
.particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  left: 50%;
  top: 45%;
  pointer-events: none;
  animation: burst .45s ease-out forwards;
}

@keyframes burst {
  from { opacity: 1; transform: translate(-50%, -50%) translate(0, 0) scale(1); }
  to { opacity: 0; transform: translate(-50%, -50%) translate(var(--dx), var(--dy)) scale(.3); }
}

.controls {
  display: flex;
  justify-content: center;
  margin-top: 14px;
}

.start-btn {
  width: min(300px, 100%);
  border: 0;
  border-radius: 14px;
  padding: 14px 20px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #052e16;
  font-weight: 900;
  letter-spacing: .04em;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(34,197,94,.22);
}

.start-btn:disabled {
  opacity: .45;
  cursor: default;
}

.tip {
  color: var(--muted);
  text-align: center;
  font-size: .78rem;
  margin: 12px 8px 0;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 8, 23, .72);
  backdrop-filter: blur(7px);
  z-index: 10;
}

.hidden {
  display: none;
}

.modal {
  width: min(390px, 100%);
  text-align: center;
  background: #102039;
  border: 1px solid #2c4567;
  border-radius: 24px;
  padding: 30px 22px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}

.modal-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.modal h2 {
  margin-bottom: 8px;
  font-size: 1.8rem;
}

.modal p:not(.eyebrow) {
  color: var(--muted);
  margin-bottom: 10px;
}

.modal p.best-line {
  margin-bottom: 22px;
  font-size: .9rem;
}

.modal p.best-line strong {
  color: var(--gold);
}

.modal p.best-line.new-best strong::after {
  content: " 🎉 NEW BEST!";
  color: var(--accent);
}

@media (max-width: 420px) {
  body {
    padding: 10px;
  }

  .game-card {
    border-radius: 18px;
  }

  .board {
    gap: 8px;
  }

  .hud {
    gap: 6px;
  }

  .stat {
    padding: 8px 4px;
  }

  .stat strong {
    font-size: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .virus,
  .game-card.shake,
  .pop,
  .particle {
    transition: none;
    animation: none !important;
  }
}
