/* Raids: candy-plum dialog over the real illustrated village, toffee mounds, gold coins. */
#raidDialog { --raid-toffee: #c98a52; --raid-earth: #5b3517; --raid-gold: #ffd447; --raid-gold-deep: #b97a06; }
#raidDialog.is-raid-scene { width: min(580px, calc(100vw - .5rem)); }
#raidDialog .raid-head { background: radial-gradient(120% 140% at 0% 0%, #ffe6b8 0%, #ffc7dc 45%, #c9f5e8 100%); }
#raidDialog .raid-body { overscroll-behavior: contain; }
#raidDialog :is(.battle-btn, .battle-back, .raid-site, summary):focus-visible { outline: 3px solid var(--battle-cherry); outline-offset: 3px; }

.raid-intro { text-align: center; justify-items: center; }
.raid-intro-art { width: 64px; height: 64px; transform: rotate(-8deg); filter: drop-shadow(0 4px 4px rgba(74, 40, 66, .25)); }
.raid-empty-art { width: 110px; }
.raid-help { width: 100%; text-align: left; font-size: .88rem; }
.raid-help summary { cursor: pointer; font-weight: 800; color: var(--battle-cherry-deep); min-height: 32px; }
.raid-targets { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.raid-kind { font-weight: 800; }
.raid-kind.is-computer { color: var(--battle-mint-deep); }
.raid-kind.is-player { color: var(--battle-cherry-deep); }
.raid-max { color: var(--raid-gold-deep) !important; font-weight: 800; }
.raid-go { background: linear-gradient(180deg, #ffcf6e, #c9781a); box-shadow: 0 3px 0 #7a4a0c; }

/* HUD */
.raid-card { gap: .6rem; padding: .7rem; }
.raid-hud { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; }
.raid-counter, .raid-total {
  display: flex; align-items: center; gap: .35rem; padding: .35rem .75rem; border-radius: 16px; border: 2px solid #fff;
  background: linear-gradient(180deg, #fff8e8, #ffe9c4); box-shadow: 0 3px 0 rgba(122, 74, 12, .35); font-variant-numeric: tabular-nums;
}
.raid-counter b { white-space: nowrap; flex-shrink: 0; }
.raid-counter { flex-wrap: wrap; }
.raid-counter small { white-space: nowrap; }
.raid-counter b, .raid-total b { font-size: 1.6rem; line-height: 1; font-weight: 900; }
.raid-counter small, .raid-total small { font-size: .72rem; font-weight: 800; color: var(--battle-plum-soft); }
.raid-total b { color: var(--raid-gold-deep); }
.raid-pip { width: 26px; height: 26px; transition: opacity .3s, transform .3s; }
.raid-pip.is-used { opacity: .25; transform: rotate(30deg) scale(.85); filter: grayscale(1); }
.raid-who { margin: 0; display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; overflow-wrap: anywhere; }

/* Stage: the real village behind four mound buttons */
.raid-stage { position: relative; border-radius: 18px; overflow: hidden; min-height: 300px; background: linear-gradient(180deg, #cdeffd 0 50%, #bfeaa0 50%); }
.raid-village { pointer-events: none; }
.raid-village .candy-village { padding: 0; min-height: 0; max-width: 100%; }
.raid-village .village-stagewrap { --v-stage-min: 380px; flex: none; height: calc(var(--v-stage-min) + var(--v-frame-bottom, 0px)); }
.raid-village :is(.village-head, .village-back, .village-next, .village-status, .village-note, .village-done, .village-lockveil, .village-plaque, .village-hammer, .village-battleaxe, .village-repair-tag) { display: none !important; }
.raid-village.is-fallback { position: absolute; inset: 0; background: radial-gradient(60% 40% at 50% 100%, #9bd67a, transparent), linear-gradient(180deg, #cdeffd 0 50%, #bfeaa0 50%); }
.raid-sites { position: absolute; inset: 0; }
.raid-site {
  position: absolute; left: var(--x); top: var(--y); transform: translate(-50%, -70%);
  width: clamp(78px, 22%, 122px); min-height: 44px; padding: 0; border: 0; background: none; cursor: pointer;
  display: grid; justify-items: center; font: inherit; color: var(--battle-plum);
  transition: transform .18s cubic-bezier(.3, 1.6, .5, 1);
}
.raid-site-art { width: 100%; display: block; filter: drop-shadow(0 4px 0 rgba(91, 53, 23, .35)); }
.raid-site-label {
  margin-top: -10px; padding: .1rem .55rem; border-radius: 999px; background: #fff8e8; border: 2px solid var(--raid-earth);
  font-weight: 900; font-size: .82rem; white-space: nowrap; box-shadow: 0 2px 0 var(--raid-earth);
}
.raid-site:not([aria-disabled="true"]):hover { transform: translate(-50%, -74%) scale(1.06); }
.raid-site:not([aria-disabled="true"]) .raid-site-art { animation: raid-bob 2.4s ease-in-out infinite; }
.raid-site:nth-child(2) .raid-site-art { animation-delay: -.6s; } .raid-site:nth-child(3) .raid-site-art { animation-delay: -1.2s; } .raid-site:nth-child(4) .raid-site-art { animation-delay: -1.8s; }
.raid-site[aria-disabled="true"] { cursor: default; }
.raid-site[aria-disabled="true"]:not(.is-coins):not(.is-empty):not(.is-digging) { opacity: .72; }
.raid-site.is-coins .raid-site-label { background: var(--raid-gold); color: #5b3517; }
.raid-site.is-empty .raid-site-label { background: #e9dfe8; }
.raid-site.is-digging .raid-site-art { animation: raid-shake .14s linear infinite; }
.raid-site.is-digging::after {
  content: ""; position: absolute; top: -18%; left: 55%; width: 44%; aspect-ratio: 1;
  background: url("raid-assets/shovel.svg") center / contain no-repeat; animation: raid-dig .45s ease-in-out infinite alternate;
}
.raid-site.is-fresh .raid-site-art { animation: raid-pop .5s cubic-bezier(.3, 1.8, .5, 1); }
.raid-site.is-fresh .raid-site-label { animation: raid-pop .5s .15s cubic-bezier(.3, 1.8, .5, 1) both; }
.raid-coin {
  position: absolute; left: 50%; top: 40%; width: 16px; height: 16px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 35% 30%, #fff7c2, #f2c94c 55%, #b98a10); border: 2px solid #8a5a14;
  animation: raid-fly .9s calc(var(--k) * 60ms) cubic-bezier(.2, .7, .4, 1) both; --dx: calc((var(--k) - 2.5) * 16px);
}
@keyframes raid-bob { 50% { transform: translateY(-3px); } }
@keyframes raid-shake { 25% { transform: translateX(-2px) rotate(-1deg); } 75% { transform: translateX(2px) rotate(1deg); } }
@keyframes raid-dig { from { transform: rotate(-20deg) translateY(-6px); } to { transform: rotate(10deg) translateY(6px); } }
@keyframes raid-pop { from { transform: scale(.6); opacity: 0; } }
@keyframes raid-fly { 0% { transform: translate(-50%, 0) scale(.4); opacity: 0; } 30% { opacity: 1; } 100% { transform: translate(calc(-50% + var(--dx)), -90px) scale(1); opacity: 0; } }

.raid-finale {
  display: grid; justify-items: center; text-align: center; gap: .35rem; padding: .8rem; border-radius: 18px;
  background: linear-gradient(180deg, #fff4d1, #ffe2a8); border: 2px dashed var(--raid-gold-deep); animation: raid-pop .5s cubic-bezier(.3, 1.6, .5, 1);
}
.raid-finale.is-abandoned, .raid-finale.is-unavailable { background: #f6eef5; border-color: var(--battle-plum-soft); }
.raid-finale-art { width: 96px; }
.raid-finale-total { font-size: 2rem; font-weight: 900; color: var(--raid-gold-deep); font-variant-numeric: tabular-nums; }

@media (max-width: 480px) {
  .raid-stage { min-height: 260px; }
  .raid-village .village-stagewrap { --v-stage-min: 300px; }
  .raid-site { width: clamp(64px, 24%, 96px); }
  .raid-site-label { font-size: .72rem; }
}
@media (prefers-reduced-motion: reduce) {
  #raidDialog *, #raidDialog *::after { animation: none !important; transition: none !important; }
  .raid-site.is-digging .raid-site-art { opacity: .6; }
}
@media (forced-colors: active) {
  .raid-site-label, .raid-counter, .raid-total { forced-color-adjust: none; border-color: CanvasText; }
  .raid-site[aria-disabled="true"] { outline: 1px dashed CanvasText; }
}

/* Reliability: waiting mounds stay visibly present but inert; scene errors are explicit. */
.raid-site.is-waiting { cursor: progress; }
.raid-scene-error { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .5rem .7rem; border-radius: 12px; background: #fff0f3; color: #8f1238; font-weight: 700; font-size: .85rem; }
.raid-site-label { max-width: 100%; white-space: normal; text-align: center; overflow-wrap: anywhere; line-height: 1.15; }
/* Narrow or enlarged text: the village sits above a 2x2 dig field so all four mounds stay tappable. */
@media (max-width: 520px), (min-width: 0) and (max-width: 32em) {
  .raid-stage { min-height: 0; display: flex; flex-direction: column; background: linear-gradient(180deg, #bfeaa0, #a9d98a); }
  .raid-village .village-stagewrap { --v-stage-min: 230px; }
  .raid-sites { position: static; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; padding: .5rem; }
  .raid-site { position: relative; left: auto; top: auto; transform: none; width: 100%; padding: .3rem; border-radius: 14px; background: rgba(255, 248, 232, .55); }
  .raid-site:not([aria-disabled="true"]):hover { transform: none; }
  .raid-site-art { width: min(100%, 110px); }
  .raid-site-label { margin-top: -6px; font-size: .8rem; }
}
