:root {
  --sky-top: #7ec8e3;
  --sky-bot: #cdeefb;
  --sand: #e9cf8f;
  --sand-dark: #d9b86a;
  --hole: #5a3d23;
  --hole-light: #6f4c2c;
  --good: #2faa4f;
  --good-bright: #5ce07e;
  --bad: #e23b3b;
  --bad-bright: #ff6b6b;
  --gold: #ffcf3f;
  --ink: #2a1c0e;
  --hud-bg: rgba(28, 18, 9, 0.86);
}

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

/* BADMAN GAMES studio splash — plays on every load (removed from the DOM by JS afterward) */
#splash { position: fixed; inset: 0; z-index: 1000; background: #07060d; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#splash img { width: min(76vw, 470px); max-height: 64vh; height: auto; image-rendering: pixelated; opacity: 0; transform: scale(0.94); transition: opacity 0.9s ease, transform 1s ease; filter: drop-shadow(0 0 24px rgba(150,90,220,0.35)); }
#splash.in img { opacity: 1; transform: scale(1); }
#splash.out { opacity: 0; transition: opacity 0.6s ease; pointer-events: none; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #07151c;
  overflow: hidden;
  user-select: none;
}

#game {
  position: relative;
  width: 100%;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bot) 42%, var(--sand) 42%, var(--sand-dark) 100%);
  overflow: hidden;
  touch-action: none;            /* instant taps: no scroll, no double-tap zoom, no 300ms delay */
  /* coconut crosshair, drawn inline so there's no asset to ship */
  cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><circle cx="32" cy="32" r="20" fill="%237a4a24" stroke="%233a2110" stroke-width="3.5"/><circle cx="32" cy="32" r="20" fill="none" stroke="%23a9743f" stroke-width="1.5" opacity="0.6"/><circle cx="25" cy="28" r="3.1" fill="%233a2110"/><circle cx="39" cy="27" r="3.1" fill="%233a2110"/><circle cx="32" cy="37" r="3.5" fill="%233a2110"/></svg>') 32 32, crosshair;
}

/* shaking play layer over the static backdrop */
#world {
  position: absolute;
  top: 56px; left: 0; right: 0; bottom: 0;
  will-change: transform;
}
#fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 8;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 6px;
  padding: 10px 8px;
  height: 56px;
  background: var(--hud-bg);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 2px 0 rgba(0,0,0,0.25);
}
.hud-item { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.hud-label { font-size: 10px; letter-spacing: 1px; opacity: 0.65; font-weight: 700; }
.hud-item span:last-child { font-size: 22px; font-variant-numeric: tabular-nums; }
.good { color: var(--good-bright); }
.bad  { color: var(--bad-bright); }
.combo-word { color: var(--gold); }
#time.warn { color: var(--bad-bright); animation: timePulse 1s steps(2) infinite; }
@keyframes timePulse { 50% { opacity: 0.45; } }

/* ---------- Board ---------- */
#board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 2vh 4vw;
  padding: 4vh 6vw 6vh;
  align-items: end;
  justify-items: center;
  z-index: 2;
}

.hole {
  position: relative;
  width: 100%;
  max-width: 150px;
  aspect-ratio: 3 / 2;
  align-self: end;
}

/* dark pit BEHIND the character */
.hole::before {
  content: "";
  position: absolute;
  left: 50%; bottom: 0;
  transform: translateX(-50%);
  width: 100%; height: 62%;
  background: radial-gradient(ellipse at 50% 34%, #33200d 0 44%, #51371f 50% 64%, rgba(81,55,31,0) 72%);
  border-radius: 50%;
  z-index: 1;
}

/* clip layer: the character is only ever visible ABOVE the hole mouth.
   So its lower body is hidden inside the hole when up, and a ducked
   character slides below the mouth and disappears completely. */
.char-clip {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 112%;
  bottom: 20%;          /* clip's bottom edge sits at the hole mouth */
  top: -280%;           /* extends high so a popped head is never clipped */
  overflow: hidden;
  z-index: 2;
  pointer-events: none;
}

/* the character that rises out of the pit */
.char {
  position: absolute;
  left: 50%; bottom: 0;
  width: 76%;           /* ~85% of the hole (clip is 112% of the hole) */
  transform: translate(-50%, 116%);   /* ducked: fully below the mouth = out of sight */
  transition: transform 0.16s cubic-bezier(.34,1.56,.64,1);
  cursor: inherit;
  will-change: transform;
}
.char img, .char .placeholder {
  display: block;
  width: 100%; height: auto;
  image-rendering: pixelated;
  pointer-events: none;
}
.hole.up .char  { transform: translate(-50%, 24%); }   /* head + shoulders above the mouth */
.hole.bonk .char { transform: translate(-50%, 24%); }  /* hold position — the image does the shaking */

/* golden character */
.hole.golden .char img {
  filter: drop-shadow(0 0 7px var(--gold)) drop-shadow(0 0 14px rgba(255,207,63,0.6));
  animation: goldPulse 0.7s ease-in-out infinite alternate;
}
@keyframes goldPulse { from { filter: drop-shadow(0 0 5px var(--gold)); } to { filter: drop-shadow(0 0 13px var(--gold)) drop-shadow(0 0 20px rgba(255,207,63,0.7)); } }

/* HIT REACTION: the character shakes when bonked (defined after .golden so it wins on gold heads too) */
.hole.bonk .char img { animation: hitShake 0.34s ease-out; }
@keyframes hitShake {
  0%   { transform: scale(1.08) rotate(0deg); }
  12%  { transform: translateX(-6px) rotate(-7deg) scale(1.04); }
  26%  { transform: translateX(6px)  rotate(6deg); }
  40%  { transform: translateX(-5px) rotate(-4deg); }
  54%  { transform: translateX(4px)  rotate(3deg); }
  68%  { transform: translateX(-3px) rotate(-2deg); }
  82%  { transform: translateX(1.5px) rotate(1deg); }
  100% { transform: translateX(0) rotate(0deg); }
}

/* front dirt lip IN FRONT of the character */
.hole::after {
  content: "";
  position: absolute;
  left: 50%; bottom: 0;
  transform: translateX(-50%);
  width: 104%; height: 26%;
  background: linear-gradient(180deg, var(--sand) 0%, var(--sand-dark) 55%, var(--hole-light) 100%);
  border-radius: 50% / 88% 88% 0 0;
  box-shadow: inset 0 6px 8px rgba(0,0,0,0.20), 0 3px 4px rgba(0,0,0,0.18);
  z-index: 3;
}

/* emoji placeholder fallback */
.placeholder { font-size: 64px; text-align: center; line-height: 1; }

/* ---------- Floating verdicts ---------- */
#verdicts { position: absolute; inset: 0; pointer-events: none; z-index: 9; overflow: hidden; }
.verdict {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 900;
  font-size: 30px;
  letter-spacing: 1px;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0,0,0,0.35), 0 0 18px currentColor;
  animation: floatUp 0.85s cubic-bezier(.2,.8,.3,1) forwards;
}
.verdict.good { color: var(--good-bright); }
.verdict.bad  { color: var(--bad-bright); }
.verdict.gold { color: var(--gold); }
.verdict.big  { font-size: 44px; }
.verdict.huge { font-size: 58px; }
@keyframes floatUp {
  0%   { opacity: 0; transform: translate(-50%, 0) scale(0.4) rotate(-6deg); }
  18%  { opacity: 1; transform: translate(-50%, -16px) scale(1.18) rotate(2deg); }
  30%  { transform: translate(-50%, -22px) scale(1.0) rotate(0); }
  100% { opacity: 0; transform: translate(-50%, -82px) scale(0.95); }
}

/* ---------- Combo meter ---------- */
.combo {
  position: absolute;
  top: 66px; left: 50%;
  transform: translateX(-50%);
  z-index: 11;
  display: flex; align-items: center; gap: 9px;
  padding: 6px 14px 6px 8px;
  background: rgba(28,18,9,0.82);
  border: 1.5px solid var(--gold);
  border-radius: 999px;
  color: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35), 0 0 18px rgba(255,207,63,0.25);
  transition: opacity 0.2s, transform 0.2s;
}
.combo.hidden { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(-6px) scale(0.9); }
.combo.bump { animation: comboBump 0.22s ease-out; }
@keyframes comboBump { 0%{ transform: translateX(-50%) scale(1);} 40%{ transform: translateX(-50%) scale(1.16);} 100%{ transform: translateX(-50%) scale(1);} }
.combo-x { font-size: 26px; font-weight: 900; color: var(--gold); text-shadow: 0 0 10px rgba(255,207,63,0.6); line-height: 1; min-width: 44px; text-align: center; }
.combo-meta { display: flex; flex-direction: column; gap: 3px; }
.combo-count { font-size: 10px; letter-spacing: 1px; opacity: 0.8; font-weight: 800; }
.combo-bar { width: 96px; height: 6px; background: rgba(255,255,255,0.18); border-radius: 3px; overflow: hidden; }
.combo-bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--gold), #fff6c9); transform-origin: left; transition: transform 0.1s linear; }

/* ---------- Impact flash ---------- */
#flash {
  position: absolute; inset: 0; z-index: 7;
  pointer-events: none; opacity: 0;
  mix-blend-mode: screen;
}
#flash.good { background: radial-gradient(circle at 50% 60%, rgba(60,230,110,0.5), transparent 65%); animation: flashPop 0.28s ease-out; }
#flash.bad  { background: radial-gradient(circle at 50% 60%, rgba(255,60,60,0.55), transparent 60%); mix-blend-mode: normal; animation: flashPop 0.4s ease-out; }
@keyframes flashPop { 0% { opacity: 0; } 25% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Frenzy banner ---------- */
.frenzy {
  position: absolute; top: 38%; left: 50%;
  transform: translate(-50%,-50%);
  z-index: 12; pointer-events: none;
  font-size: 46px; font-weight: 900; letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 0 18px var(--bad-bright), 0 3px 0 rgba(0,0,0,0.4);
  animation: frenzyIn 1.4s ease-out forwards;
}
.frenzy.hidden { display: none; }
@keyframes frenzyIn {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(0.3) rotate(-8deg); }
  18%{ opacity: 1; transform: translate(-50%,-50%) scale(1.15) rotate(3deg); }
  35%{ transform: translate(-50%,-50%) scale(1) rotate(0); }
  80%{ opacity: 1; }
  100%{ opacity: 0; transform: translate(-50%,-58%) scale(1.05); }
}

/* ---------- Launch intro: characters jump in ---------- */
.intro {
  position: absolute; inset: 0; z-index: 19;
  display: flex; align-items: center; justify-content: center; gap: 7vw;
  pointer-events: none;
  background: rgba(7, 21, 28, 0.4);
}
.intro.hidden { display: none; }
.intro-char {
  width: clamp(115px, 32vw, 175px); height: auto;
  image-rendering: auto;                 /* smooth scaling so the feathered edges stay clean */
  /* edge glow: tight white rim + warm gold halo (drop-shadow hugs the silhouette), plus the ground shadow */
  filter:
    drop-shadow(0 0 4px rgba(255,255,255,0.95))
    drop-shadow(0 0 12px rgba(255,207,63,0.85))
    drop-shadow(0 0 24px rgba(255,176,40,0.55))
    drop-shadow(0 14px 16px rgba(0,0,0,0.5));
  opacity: 0;
}
.intro.show .intro-char { animation: introJump 2s ease-in-out both, introGlow 1.4s ease-in-out infinite; }
.intro.show .intro-char:nth-child(2) { animation-delay: 0.1s; }   /* stagger the two */
@keyframes introJump {
  0%   { opacity: 0; transform: translateY(180px) scale(0.7) rotate(-6deg); }
  9%   { opacity: 1; transform: translateY(0)      scale(1)   rotate(0deg); }
  20%  {              transform: translateY(-55px) scale(1.04); }   /* jump */
  31%  {              transform: translateY(0)     scale(1); }
  42%  {              transform: translateY(-38px) scale(1.02); }   /* jump again */
  52%  {              transform: translateY(0)     scale(1); }
  64%  {              transform: translateY(-8px)  scale(1.01); }   /* gentle bob */
  74%  {              transform: translateY(0)     scale(1); }
  86%  { opacity: 1;  transform: translateY(0)     scale(1); }      /* hold on screen */
  100% { opacity: 0;  transform: translateY(-70px) scale(0.9); }    /* leap up & vanish before the countdown */
}
/* gently pulse the edge glow while they're on screen */
@keyframes introGlow {
  0%, 100% {
    filter:
      drop-shadow(0 0 3px rgba(255,255,255,0.9))
      drop-shadow(0 0 9px rgba(255,207,63,0.7))
      drop-shadow(0 0 18px rgba(255,176,40,0.4))
      drop-shadow(0 14px 16px rgba(0,0,0,0.5));
  }
  50% {
    filter:
      drop-shadow(0 0 6px rgba(255,255,255,1))
      drop-shadow(0 0 18px rgba(255,207,63,0.95))
      drop-shadow(0 0 34px rgba(255,176,40,0.7))
      drop-shadow(0 14px 16px rgba(0,0,0,0.5));
  }
}

/* ---------- Get-ready countdown ---------- */
.countdown {
  position: absolute; inset: 0; z-index: 18;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  background: rgba(7, 21, 28, 0.4);
}
.countdown.hidden { display: none; }
.countdown span {
  font-size: clamp(96px, 30vw, 200px);
  font-weight: 900; line-height: 1; color: #fff;
  text-shadow: 0 7px 0 rgba(0,0,0,0.4), 0 0 44px rgba(255,255,255,0.45);
  animation: countPop 0.95s cubic-bezier(.2,1.3,.4,1) both;
}
.countdown span.go { color: var(--good-bright); text-shadow: 0 7px 0 rgba(0,0,0,0.4), 0 0 44px rgba(92,224,126,0.6); }
@keyframes countPop {
  0%   { opacity: 0; transform: scale(2.4) rotate(-6deg); }
  22%  { opacity: 1; transform: scale(0.88) rotate(2deg); }
  38%  { transform: scale(1.06) rotate(0deg); }
  52%  { transform: scale(1); }
  100% { opacity: 1; transform: scale(1); }
}

/* ---------- Streak taunt: comic-book pop-up ---------- */
.taunt {
  position: absolute;
  left: 50%; top: 47%;
  z-index: 16;
  pointer-events: none;
  display: flex; flex-direction: column; align-items: center;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity 0.22s ease;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,0.45));
}
.taunt.show { opacity: 1; }
/* the speech bubble pops, and the FACE spins a full 360° in from the left */
.taunt.show .taunt-bubble { animation: bubblePop 0.5s cubic-bezier(.2,1.5,.4,1) both; }
.taunt.show .taunt-img    { animation: faceSpinIn 0.75s cubic-bezier(.2,.75,.3,1) both; }
@keyframes bubblePop {
  0%   { opacity: 0; transform: scale(0.3) rotate(-8deg); }
  55%  { opacity: 1; transform: scale(1.12) rotate(4deg); }
  75%  { transform: scale(0.97) rotate(-1deg); }
  100% { transform: scale(1) rotate(0deg); }
}
@keyframes faceSpinIn {
  0%   { opacity: 0; transform: translateX(-190px) rotate(-358deg) scale(0.5); }
  25%  { opacity: 1; }
  100% { opacity: 1; transform: translateX(0)      rotate(2deg)    scale(1); }
}

.taunt-bubble {
  position: relative;
  background: #fff;
  border: 4px solid #111;
  border-radius: 24px;
  padding: 12px 22px 14px;
  margin-bottom: 16px;
  box-shadow: 5px 6px 0 #111;
}
.taunt-bubble span {
  display: block;
  font-family: "Bangers", "Chalkboard SE", "Comic Sans MS", "Marker Felt", Impact, system-ui, sans-serif;
  font-weight: 900;
  font-size: clamp(28px, 8vw, 40px);
  line-height: 1;
  letter-spacing: 1px;
  text-transform: uppercase;
  white-space: nowrap;
  color: #e23b3b;
  -webkit-text-stroke: 1.6px #111;
  text-shadow: 3px 3px 0 #ffd23f;          /* comic offset highlight */
  transform: rotate(-3deg);
}
/* speech-bubble tail (black outline + white fill) pointing down to the man */
.taunt-bubble::after {
  content: ""; position: absolute; bottom: -22px; left: 52%;
  transform: translateX(-50%);
  border-left: 16px solid transparent; border-right: 16px solid transparent;
  border-top: 24px solid #111;
}
.taunt-bubble::before {
  content: ""; position: absolute; bottom: -13px; left: 52%;
  transform: translateX(-50%); z-index: 1;
  border-left: 11px solid transparent; border-right: 11px solid transparent;
  border-top: 16px solid #fff;
}
.taunt-img {
  width: clamp(130px, 38vw, 170px); height: auto;
  image-rendering: pixelated;
  border: 4px solid #111;
  border-radius: 12px;
  background: #efe2c4;                       /* sandy backing behind the transparent-topped portrait */
  box-shadow: 5px 6px 0 #111;
  transform: rotate(2deg);
}

/* ---------- Desktop lock-on reticle (CSS-only, GPU-cheap) ---------- */
#reticle {
  position: absolute;
  left: 0; top: 0;
  width: 80px; height: 80px;            /* size + centering margin set from JS (≈0.92 hole) */
  border: 3px dashed rgba(92, 224, 126, 0.95);
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(92, 224, 126, 0.5), inset 0 0 8px rgba(92, 224, 126, 0.2);
  pointer-events: none;
  opacity: 0;
  z-index: 5;
  transition: opacity 0.08s ease;
  animation: reticlePulse 1.1s ease-in-out infinite;
}
#reticle.on { opacity: 1; }
@keyframes reticlePulse { 0%, 100% { transform: scale(0.9); } 50% { transform: scale(1.05); } }

/* ---------- Grit overlays ---------- */
.vignette { position: absolute; inset: 0; z-index: 6; pointer-events: none;
  background: radial-gradient(ellipse at 50% 42%, transparent 55%, rgba(0,0,0,0.34) 100%); }
.grain { position: absolute; inset: 0; z-index: 6; pointer-events: none; opacity: 0.05; mix-blend-mode: overlay;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="120" height="120"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2"/></filter><rect width="120" height="120" filter="url(%23n)"/></svg>'); }

/* ---------- Sound toggle ---------- */
.icon-btn {
  position: absolute; top: 64px; right: 10px; z-index: 13;
  width: 38px; height: 38px; border-radius: 50%;
  border: none; background: rgba(28,18,9,0.7); color: #fff;
  font-size: 17px; cursor: pointer; display: grid; place-items: center;
}
.icon-btn:active { transform: scale(0.92); }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 16px; padding: 24px;
  background: rgba(7, 21, 28, 0.82);
  backdrop-filter: blur(5px);
  color: #fff;
}
.overlay.hidden { display: none; }
.overlay h1 { font-size: clamp(30px, 8vw, 52px); margin: 0; line-height: 1.05; text-shadow: 0 3px 0 rgba(0,0,0,0.35); }
.overlay h1 .or { font-size: 0.5em; opacity: 0.8; font-style: italic; }
.overlay p { margin: 0; font-size: 15.5px; line-height: 1.6; max-width: 380px; opacity: 0.95; }
.best-line { font-weight: 800; letter-spacing: 2px; font-size: 13px; opacity: 0.7; }
.best-line span { color: var(--gold); }

.btn {
  margin-top: 6px;
  padding: 14px 40px;
  font-size: 20px; font-weight: 900; letter-spacing: 1px;
  color: var(--ink);
  background: linear-gradient(180deg, #ffd56b, #f0a93c);
  border: none; border-radius: 999px;
  box-shadow: 0 5px 0 #b9791f, 0 8px 14px rgba(0,0,0,0.35);
  cursor: pointer; transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #b9791f, 0 3px 8px rgba(0,0,0,0.35); }

/* ---------- End screen ---------- */
.new-best {
  font-size: 18px; font-weight: 900; letter-spacing: 3px; color: var(--gold);
  text-shadow: 0 0 14px rgba(255,207,63,0.7);
  animation: newBestFlash 0.8s steps(2) infinite;
}
.new-best.hidden { display: none; }
@keyframes newBestFlash { 50% { opacity: 0.4; } }
.rank-wrap { display: flex; flex-direction: column; align-items: center; gap: 0; }
.rank {
  font-size: 110px; font-weight: 900; line-height: 0.9;
  text-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 0 30px currentColor;
  animation: rankIn 0.5s cubic-bezier(.2,1.6,.4,1) both;
}
.rank.s { color: #ffd23f; } .rank.a { color: #5ce07e; } .rank.b { color: #58c6ff; }
.rank.c { color: #ffa64d; } .rank.d { color: #ff6b6b; }
@keyframes rankIn { 0% { opacity: 0; transform: scale(2.4) rotate(10deg); } 100% { opacity: 1; transform: scale(1) rotate(0); } }
.rank-sub { font-size: 16px; font-weight: 800; letter-spacing: 4px; opacity: 0.85; margin-top: 2px; }
.final-score { font-size: 60px; font-weight: 900; line-height: 1; }
.final-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 28px;
  font-weight: 800; font-size: 19px;
}
.final-grid > div { display: flex; flex-direction: column; gap: 1px; }
.fg-label { font-size: 10px; letter-spacing: 1px; opacity: 0.6; font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; }
}
