/* ===========================================================================
   Comic "KA-POW" damage burst
   Shown over a castle or wall when it takes damage, with the amount + target.
   Spawned by particleSystem.triggerDamageKapow() into #particle-container
   (a fixed, full-screen overlay), positioned over the resource value element.
   =========================================================================== */

.cwl-kapow {
  position: fixed;
  z-index: 10002;
  width: 130px;
  height: 130px;
  /* center the box on the (left, top) anchor point */
  margin-left: -65px;
  margin-top: -65px;
  pointer-events: none;
  will-change: transform, opacity;
  animation: cwl-kapow-pop 1.15s cubic-bezier(0.18, 1.5, 0.4, 1) forwards;
}

/* inner holds the comic tilt so the pop/float animation transform stays clean */
.cwl-kapow-inner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transform: rotate(var(--kapow-rot, -8deg));
}

.cwl-kapow-burst {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    circle at 50% 42%,
    #fff6c2 0%,
    #ffe14d 28%,
    #ffc01a 55%,
    #ff7a16 80%,
    #e23b0c 100%
  );
  /* 8-point comic explosion star */
  clip-path: polygon(
    50% 0%, 63% 25%, 86% 17%, 78% 40%, 100% 50%, 78% 60%, 86% 83%, 63% 75%,
    50% 100%, 37% 75%, 14% 83%, 22% 60%, 0% 50%, 22% 40%, 14% 17%, 37% 25%
  );
  /* solid offset shadow = comic outline */
  filter: drop-shadow(3px 4px 0 rgba(40, 12, 2, 0.9));
}

.cwl-kapow-text {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.9;
  text-align: center;
  font-family: "Arial Black", "Impact", system-ui, sans-serif;
}

.cwl-kapow-amount {
  font-size: 2.5rem;
  font-weight: 900;
  color: #fff;
  -webkit-text-stroke: 2px #7a1500;
  text-shadow: 2px 2px 0 #7a1500, -1px -1px 0 #7a1500;
}

.cwl-kapow-label {
  margin-top: 2px;
  font-size: 0.85rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #fff3b0;
  -webkit-text-stroke: 1px #7a1500;
  text-shadow: 1px 1px 0 #7a1500;
}

/* castle hits read a touch redder + bigger than wall chips */
.cwl-kapow-castle .cwl-kapow-burst {
  background: radial-gradient(
    circle at 50% 42%,
    #ffd9c2 0%,
    #ff8a4d 30%,
    #ff3b1a 62%,
    #c20d0d 100%
  );
}
.cwl-kapow-castle .cwl-kapow-amount {
  font-size: 2.8rem;
}

/* The whole burst scales with damage via --kapow-scale (set per instance in JS:
   bigger hit -> bigger ka-pow). The pop/bounce multipliers are applied on top. */
@keyframes cwl-kapow-pop {
  0%   { transform: scale(0);                                       opacity: 0; }
  28%  { transform: scale(calc(1.25 * var(--kapow-scale, 1))) translateY(0);  opacity: 1; }
  44%  { transform: scale(calc(0.9 * var(--kapow-scale, 1)));       opacity: 1; }
  60%  { transform: scale(calc(1.06 * var(--kapow-scale, 1)));      opacity: 1; }
  100% { transform: scale(var(--kapow-scale, 1)) translateY(-46px); opacity: 0; }
}

@media (max-width: 720px) {
  .cwl-kapow {
    width: 96px;
    height: 96px;
    margin-left: -48px;
    margin-top: -48px;
  }
  .cwl-kapow-amount { font-size: 1.8rem; }
  .cwl-kapow-castle .cwl-kapow-amount { font-size: 2rem; }
  .cwl-kapow-label { font-size: 0.7rem; }
}

@media (prefers-reduced-motion: reduce) {
  .cwl-kapow {
    animation-duration: 0.85s;
  }
}

/* ===========================================================================
   DOUBLE-damage critical tier (Magic Weapons combo). Hotter palette + a
   "DOUBLE!" ribbon + an expanding shockwave ring + a brief screen shake.
   =========================================================================== */
.cwl-kapow-crit .cwl-kapow-burst {
  background: radial-gradient(
    circle at 50% 42%,
    #ffffff 0%,
    #fff1a8 22%,
    #ffd23a 42%,
    #ff6a1a 66%,
    #ff1e5a 86%,
    #b510e8 100%
  );
  filter: drop-shadow(3px 4px 0 rgba(40, 12, 2, 0.9))
    drop-shadow(0 0 14px rgba(120, 200, 255, 0.85));
}

.cwl-kapow-crit .cwl-kapow-amount {
  color: #fff;
  -webkit-text-stroke: 2px #7a0030;
  text-shadow: 2px 2px 0 #7a0030, 0 0 10px rgba(255, 255, 255, 0.85);
}

.cwl-kapow-ribbon {
  display: inline-block;
  margin-bottom: 3px;
  padding: 2px 10px;
  font-family: "Arial Black", "Impact", system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #fff;
  background: linear-gradient(180deg, #ff2d6a, #c20d3a);
  border: 2px solid #fff;
  border-radius: 4px;
  transform: rotate(-4deg);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
  text-shadow: 1px 1px 0 #5a0020;
  white-space: nowrap;
}

.cwl-shockwave {
  position: fixed;
  z-index: 10001;
  width: 64px;
  height: 64px;
  margin-left: -32px;
  margin-top: -32px;
  border-radius: 50%;
  border: 6px solid rgba(255, 240, 180, 0.9);
  box-shadow: 0 0 20px rgba(255, 200, 90, 0.85),
    inset 0 0 12px rgba(255, 210, 100, 0.6);
  pointer-events: none;
  animation: cwl-shockwave-expand 0.6s ease-out forwards;
}

@keyframes cwl-shockwave-expand {
  0% {
    transform: scale(0.2);
    opacity: 0.95;
  }
  100% {
    transform: scale(calc(3.4 * var(--shock-scale, 1)));
    opacity: 0;
    border-width: 1px;
  }
}

/* Brief, light screen shake applied to the game root on a crit. */
@keyframes cwl-crit-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-5px, 3px); }
  40% { transform: translate(6px, -2px); }
  60% { transform: translate(-4px, 2px); }
  80% { transform: translate(3px, -1px); }
}

@media (prefers-reduced-motion: reduce) {
  .cwl-shockwave { animation-duration: 0.4s; }
}
