.encounter {
  --battle-contact: 218ms;
}

.encounter-art {
  position: relative;
  isolation: isolate;
  --battle-gold: #ffd687;
  --battle-step: min(11vw, 98px);
  --battle-duration: 610ms;
}

.encounter-art > .combatants {
  position: relative;
  z-index: 1;
}

.encounter-art > .difficulty { z-index: 2; }

.battle-effects {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
  --impact-x: 68%;
  --impact-y: 57%;
  --impact-color: var(--battle-gold);
}

.encounter-art:is([data-motion="counter"], [data-motion="block"]) .battle-effects {
  --impact-x: 32%;
  --impact-color: #ffc0a0;
}

.encounter-art[data-motion="block"] .battle-effects {
  --impact-color: #a4e3ff;
}
.encounter-art[data-motion="spell-mend"] .battle-effects { --impact-x: 28%; --impact-color: #a2f7b3; }
.encounter-art[data-motion="spell-hint"] .battle-effects { --impact-x: 28%; --impact-color: #ffd58d; }

.battle-effects > * {
  position: absolute;
  opacity: 0;
}

.encounter-art[data-weapon-glow] .adventurer-weapon {
  filter: brightness(1.18) drop-shadow(0 0 2px #fff1b6) drop-shadow(0 0 6px #ffbc4ad9);
}

.encounter-art[data-pet-trick] .adventurer-pet {
  filter: drop-shadow(0 0 6px #ffde96bd);
}

.encounter-art[data-boss-move] {
  --boss-energy: #ffd180;
  --boss-halo: #f4a94b86;
  --boss-halo-outline: solid;
}

.encounter-art[data-boss-visual="mosswood"] {
  --boss-energy: #a8f1a8;
  --boss-halo: #78c76e87;
  --boss-halo-outline: dashed;
}

.encounter-art[data-boss-visual="frost"] {
  --boss-energy: #c6f4ff;
  --boss-halo: #64c4f29c;
  --boss-halo-outline: dotted;
}

.encounter-art[data-boss-visual="stormspire"] {
  --boss-energy: #d2c1ff;
  --boss-halo: #aa82f394;
  --boss-halo-outline: double;
}

.encounter-art[data-boss-visual="astral"] {
  --boss-energy: #ffd2ff;
  --boss-halo: #eb8cde86;
  --boss-halo-outline: dashed;
}

.encounter-art[data-boss-move] .foe {
  position: relative;
  isolation: isolate;
}

.boss-aura {
  position: absolute;
  z-index: -1;
  inset-inline-start: 50%;
  inset-block-start: calc(var(--portrait-size) * .55);
  inline-size: min(96%, var(--portrait-size));
  block-size: calc(var(--portrait-size) * .86);
  border: 3px var(--boss-halo-outline) var(--boss-energy);
  border-radius: 48%;
  background: radial-gradient(ellipse, transparent 38%, var(--boss-halo) 74%, transparent 100%);
  box-shadow: 0 0 13px var(--boss-halo), inset 0 0 12px var(--boss-halo);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%);
}

.encounter-art[data-boss-move="ready"] .boss-aura {
  opacity: .86;
}

.encounter-art[data-boss-move="fired"] .battle-effects {
  --impact-color: var(--boss-energy);
}

.health-trail {
  position: absolute;
  inset-block: 0;
  inset-inline-start: var(--hp-now);
  inline-size: var(--hp-loss);
  border-radius: 999px;
  background: #ffd088;
  pointer-events: none;
  opacity: 0;
}

.battle-effects::before {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 23% 75%, #ffddb6b0 1px, transparent 3px),
    radial-gradient(circle at 37% 32%, #fff2d37a 1px, transparent 3px),
    radial-gradient(circle at 76% 65%, #ffddb6a3 1px, transparent 3px),
    radial-gradient(circle at 84% 18%, #fff2d3a8 1px, transparent 2px),
    radial-gradient(circle at 94% 45%, #ffe2a875 1px, transparent 3px);
  content: "";
  opacity: .52;
}

.battle-slash {
  top: var(--impact-y);
  left: var(--impact-x);
  width: 25%;
  aspect-ratio: 1.15;
  border-radius: 50%;
  border: solid transparent;
  border-width: 4px 3px 0 0;
  border-top-color: #fff3cc;
  border-right-color: var(--impact-color);
  filter: drop-shadow(0 0 5px var(--impact-color));
}

.battle-slash::after {
  position: absolute;
  inset: 11%;
  border-radius: 50%;
  border: 1px solid transparent;
  border-top-color: var(--impact-color);
  border-right-color: var(--impact-color);
  content: "";
}

.battle-ring {
  top: var(--impact-y);
  left: var(--impact-x);
  width: 17%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--impact-color);
  background: radial-gradient(circle, #fffde852 0%, transparent 70%);
  box-shadow: 0 0 10px var(--impact-color), inset 0 0 11px var(--impact-color);
}

.battle-sparks {
  top: var(--impact-y);
  left: var(--impact-x);
  width: 28%;
  aspect-ratio: 1;
  background:
    radial-gradient(ellipse 6% 3% at 21% 45%, var(--impact-color) 70%, transparent 100%),
    radial-gradient(ellipse 3% 6% at 44% 18%, #fff8dd 70%, transparent 100%),
    radial-gradient(ellipse 4% 6% at 71% 63%, var(--impact-color) 70%, transparent 100%),
    radial-gradient(ellipse 4% 3% at 87% 37%, #fff8dd 70%, transparent 100%),
    radial-gradient(circle at 46% 80%, var(--impact-color) 3%, transparent 7%);
}

.battle-pop {
  top: 50%;
  left: var(--impact-x);
  white-space: nowrap;
  font-family: var(--display);
  font-size: clamp(1.05rem, 2.55vw, 1.7rem);
  font-weight: 800;
  line-height: 1;
  color: #fff0bd;
  text-shadow: 0 1px 3px #000, 0 2px 7px #000, 0 0 11px #2c130b;
}

.battle-pop--foe { left: 75%; }
.battle-pop--hero { left: 25%; color: #ffc8ac; }
.battle-pop--heal { top: 61%; left: 24%; color: #b7f6c8; }
.battle-pop--coins { top: 64%; left: 73%; color: #ffe49c; }

.battle-pop .icon,
.battle-callout .icon {
  vertical-align: -.14em;
  margin-right: .16em;
}

.battle-callout {
  top: 13%;
  left: 50%;
  width: max-content;
  max-width: 97%;
  padding: .35em .74em;
  border: 1px solid #f5d28aa6;
  border-radius: 8px;
  background: linear-gradient(105deg, #211a16f2, #3b2d1ce8, #211a16f2);
  box-shadow: 0 3px 12px #06080ba8;
  color: #ffedc7;
  font-family: var(--display);
  font-size: clamp(.75rem, 2vw, 1.12rem);
  font-weight: 700;
  line-height: 1.12;
  text-align: center;
  text-wrap: balance;
}

.encounter-art[data-motion="block"] .battle-callout {
  border-color: #b5e6f6b3;
  background: #172b38f2;
  color: #d9f5ff;
}

.encounter-art[data-motion="boss-entrance"] .battle-callout {
  border-color: #f0a397c7;
  background: #391d20f5;
  color: #ffe0d1;
}

@media (max-width: 700px) {
  .encounter-art {
    --battle-step: clamp(18px, 7vw, 43px);
  }

  .battle-callout {
    top: 3%;
    padding: .23em .48em;
    border-radius: 6px;
  }

  .battle-pop {
    font-size: .95rem;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .encounter-art:is([data-motion="spell-mend"], [data-motion="spell-hint"]) .battle-ring {
    width: 31%;
    animation: battle-wave 590ms ease-out both;
  }

  .encounter-art:is([data-motion="spell-mend"], [data-motion="spell-hint"]) .battle-sparks {
    animation: battle-scatter 680ms ease-out 70ms both;
  }

  [data-spell-effect="fifty-fifty"] .answer-eliminated {
    animation: dispel-choice 420ms ease-out both;
  }

  [data-spell-effect="hint"] .hint {
    animation: reveal-hint 360ms ease-out both;
  }

  .adventurer-pet {
    animation: pet-flight 2s ease-in-out 2;
  }

  .encounter-art:is([data-motion="strike"], [data-motion="clear"], [data-motion="boss-clear"], [data-motion="victory"]) .adventurer-pet {
    animation: pet-cheer 740ms ease-out;
  }

  .encounter-art[data-pet-trick] .adventurer-pet {
    animation: pet-loop 840ms 130ms ease-in-out both;
  }

  .encounter-art[data-boss-move="ready"] .boss-aura {
    animation: boss-aura-pulse 1600ms ease-in-out 2;
  }

  .encounter-art[data-boss-move="interrupted"][data-motion] .boss-aura {
    animation: boss-aura-disperse 460ms ease-out var(--battle-contact) both;
  }

  .encounter-art[data-boss-move="fired"][data-motion] .boss-aura {
    animation: boss-aura-release 560ms ease-out both;
  }

  .encounter-art[data-boss-move="fired"]:is([data-motion="counter"], [data-motion="block"]) .foe img {
    animation-name: boss-attack;
  }

  .encounter-art[data-boss-move="fired"] .battle-ring {
    width: 27%;
    animation: battle-wave 570ms ease-out var(--battle-contact) both;
  }

  .battle-effects::before {
    animation: battle-motes 3s ease-out both;
  }

  .encounter-art:is([data-motion="strike"], [data-motion="clear"], [data-motion="boss-clear"], [data-motion="victory"]) .hero .adventurer-portrait {
    animation: battle-lunge var(--battle-duration) both;
  }

  .encounter-art:is([data-motion="strike"], [data-motion="clear"], [data-motion="boss-clear"], [data-motion="victory"]) .hero .adventurer-weapon {
    transform-origin: 83% 19%;
    animation: battle-swing var(--battle-duration) both;
  }

  .encounter-art[data-motion="strike"] .foe img {
    animation: battle-foe-recoil 335ms var(--battle-contact) both;
  }

  .encounter-art:is([data-motion="clear"], [data-motion="boss-clear"], [data-motion="victory"]) .foe img {
    animation: battle-fall 610ms var(--battle-contact) both;
  }

  .encounter-art:is([data-motion="counter"], [data-motion="block"]) .foe img {
    animation: battle-counter var(--battle-duration) both;
  }

  .encounter-art[data-motion="counter"] .hero .adventurer-portrait {
    animation: battle-hero-recoil 375ms var(--battle-contact) both;
  }

  .encounter-art[data-motion="block"] .hero .adventurer-portrait {
    animation: battle-brace 440ms 90ms both;
  }

  .encounter-art[data-motion="block"] .adventurer-shield {
    animation: battle-guard 450ms 90ms both;
  }

  .encounter-art:is([data-motion="entrance"], [data-motion="boss-entrance"]) .foe img {
    animation: battle-arrival 500ms cubic-bezier(.15,.65,.38,1) both;
  }

  .encounter-art[data-motion="boss-entrance"] .foe img {
    animation-duration: 720ms;
  }

  .encounter-art[data-motion="rune-entrance"] .rune-seal {
    animation: battle-arrival 480ms ease-out both;
  }

  .encounter-art:is([data-motion="rune-hit"], [data-motion="rune-clear"]) .rune-seal i {
    animation: rune-charge 560ms ease-out;
  }

  .encounter-art:is([data-motion="rune-hit"], [data-motion="rune-clear"]) .battle-ring {
    --impact-color: #bbe4ff;
    animation: battle-wave 570ms ease-out 135ms both;
  }

  .encounter-art:is([data-motion="strike"], [data-motion="counter"], [data-motion="clear"], [data-motion="boss-clear"], [data-motion="victory"]) .battle-slash {
    animation: battle-slice 260ms ease-out var(--battle-contact) both;
  }

  .encounter-art[data-motion="counter"] .battle-slash {
    scale: -1 1;
    transform-origin: left center;
  }

  .encounter-art:is([data-motion="strike"], [data-motion="counter"], [data-motion="block"], [data-motion="clear"], [data-motion="boss-clear"], [data-motion="victory"]) .battle-sparks {
    animation: battle-scatter 470ms ease-out var(--battle-contact) both;
  }

  .encounter-art:is([data-motion="clear"], [data-motion="boss-clear"], [data-motion="victory"], [data-motion="block"]) .battle-ring {
    animation: battle-wave 480ms ease-out var(--battle-contact) both;
  }

  .encounter-art:is([data-motion="boss-clear"], [data-motion="victory"]) .battle-ring {
    width: 30%;
    animation-duration: 650ms;
  }

  .encounter-art[data-motion] .battle-pop {
    animation: battle-rise 660ms ease-out var(--battle-contact) both;
  }

  .health-trail {
    transform-origin: left center;
    animation: battle-hp-trail 300ms ease-out var(--battle-contact) both;
  }

  .encounter-art[data-motion] :is(.battle-pop--coins, .battle-pop--heal) {
    animation-delay: 380ms;
  }

  .encounter-art[data-motion] .battle-callout {
    animation: battle-banner 950ms ease-out 320ms both;
  }

  .encounter-art[data-motion="boss-entrance"] .battle-callout {
    animation-delay: 105ms;
  }

  .route li.newly-cleared {
    animation: battle-route-glow 750ms ease-out var(--battle-contact, 218ms) both;
  }

  .result[data-celebrate] .result-mark {
    position: relative;
    animation: battle-trophy 740ms cubic-bezier(.18,.74,.32,1.12) both;
  }

  .result[data-celebrate] .result-mark::after {
    position: absolute;
    inset: -4px;
    border: 1px solid #ffeab1;
    border-radius: 50%;
    box-shadow: 0 0 12px #ffe1979c;
    content: "";
    pointer-events: none;
    animation: battle-trophy-ring 870ms ease-out 240ms both;
  }

  .result[data-celebrate] .rescue-reward img {
    animation: pet-rescue 900ms 160ms cubic-bezier(.18,.65,.32,1) both;
  }

  .result[data-celebrate] .decoration-reward img {
    animation: battle-trophy 650ms 240ms cubic-bezier(.18,.74,.32,1.12) both;
  }
}

@keyframes dispel-choice {
  0% { background: #75568d; transform: scale(.97); }
  100% { background: #252631; transform: none; }
}

@keyframes reveal-hint {
  from { background: #524136; transform: translateY(4px); }
  to { transform: none; }
}

@keyframes pet-flight {
  0%, 100% { transform: none; }
  50% { transform: translateY(-13%) rotate(5deg); }
}

@keyframes rune-charge {
  32% { transform: scale(1.23) rotate(23deg); filter: brightness(1.4); }
  72% { transform: scale(.94) rotate(-6deg); }
}

@keyframes pet-cheer {
  0%, 100% { transform: none; }
  36% { transform: translate(11%, -31%) rotate(-12deg) scale(1.08); filter: drop-shadow(0 0 9px #ffe29dcc); }
  62% { transform: translate(4%, 3%) rotate(8deg); }
}

@keyframes pet-loop {
  0% { transform: none; }
  24% { transform: translate(32%, -33%) rotate(79deg) scale(1.08); }
  48% { transform: translate(73%, -24%) rotate(178deg) scale(1.18); }
  73% { transform: translate(48%, 12%) rotate(285deg) scale(1.06); }
  100% { transform: rotate(360deg); }
}

@keyframes pet-rescue {
  0% { opacity: 0; transform: translate(clamp(-44px, -9vw, -20px), 20%) rotate(-26deg) scale(.64); }
  39% { opacity: 1; transform: translate(-26%, -24%) rotate(16deg) scale(1.13); }
  72% { opacity: 1; transform: translate(10%, -11%) rotate(-9deg) scale(1.04); }
  100% { opacity: 1; transform: none; }
}

@keyframes boss-aura-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: .86; }
  50% { transform: translate(-50%, -50%) scale(1.1); opacity: .6; }
}

@keyframes boss-aura-disperse {
  0% { transform: translate(-50%, -50%) scale(1); opacity: .86; }
  100% { transform: translate(-50%, -50%) scale(1.3); opacity: 0; }
}

@keyframes boss-aura-release {
  0% { transform: translate(-50%, -50%) scale(1); opacity: .86; }
  38% { transform: translate(-50%, -50%) scale(.81); opacity: .99; }
  100% { transform: translate(-50%, -50%) scale(1.4); opacity: 0; }
}

@keyframes boss-attack {
  0% { transform: none; }
  20% { transform: translate(8%, -7%) rotate(9deg) scale(1.05); }
  38% { transform: translate(calc(-1.1 * var(--battle-step)), -9%) rotate(-12deg) scale(1.11); }
  61% { transform: translate(calc(-.73 * var(--battle-step)), 0) rotate(-6deg) scale(1.05); }
  100% { transform: none; }
}

@keyframes battle-motes {
  0% { transform: translateY(5%); opacity: .22; }
  30% { opacity: .58; }
  100% { transform: translateY(-9%); opacity: 0; }
}

@keyframes battle-lunge {
  0% { transform: none; }
  20% { transform: translateX(-6%) rotate(-7deg); animation-timing-function: cubic-bezier(.26,.57,.7,1); }
  36% { transform: translate(var(--battle-step), -6%) rotate(8deg); }
  50% { transform: translate(var(--battle-step), -4%) rotate(5deg); }
  100% { transform: none; }
}

@keyframes battle-swing {
  0% { transform: none; }
  20% { transform: rotate(30deg); }
  37% { transform: rotate(-137deg); }
  58% { transform: rotate(-106deg); }
  100% { transform: none; }
}

@keyframes battle-foe-recoil {
  0% { transform: none; }
  26% { transform: translate(13%, -5%) rotate(10deg); filter: brightness(1.32) drop-shadow(0 3px 7px #ecba87aa); }
  64% { transform: translate(4%, 2%) rotate(-3deg); }
  100% { transform: none; }
}

@keyframes battle-counter {
  0% { transform: none; }
  19% { transform: translate(8%, -4%) rotate(8deg); }
  36% { transform: translate(calc(-1 * var(--battle-step)), -7%) rotate(-8deg); }
  54% { transform: translate(calc(-.8 * var(--battle-step)), -2%) rotate(-5deg); }
  100% { transform: none; }
}

@keyframes battle-hero-recoil {
  0% { transform: none; }
  28% { transform: translate(-12%, 1%) rotate(-11deg); filter: brightness(1.2) sepia(.15) drop-shadow(0 4px 7px #f08260a6); }
  62% { transform: translate(-3%, 3%) rotate(4deg); }
  100% { transform: none; }
}

@keyframes battle-brace {
  0%, 100% { transform: none; }
  25% { transform: translate(4%, 2%) rotate(6deg); }
  40% { transform: translate(-7%, 4%) rotate(-4deg); }
  68% { transform: translate(-3%, 2%); }
}

@keyframes battle-guard {
  0%, 100% { filter: none; }
  39% { filter: brightness(1.42) drop-shadow(0 0 5px #a8e4fc); }
}

@keyframes battle-fall {
  0% { opacity: 1; transform: none; }
  22% { opacity: 1; transform: translate(12%, -7%) rotate(8deg); }
  63% { opacity: .7; transform: translate(12%, 8%) rotate(19deg) scale(.95); }
  100% { opacity: .55; transform: translate(12%, 7%) rotate(15deg) scale(.91); }
}

@keyframes battle-arrival {
  0% { opacity: 0; transform: translate(25%, 4%) scale(.93); }
  70% { opacity: 1; transform: translate(-3%, 0) scale(1.02); }
  100% { opacity: 1; transform: none; }
}

@keyframes battle-slice {
  0% { opacity: 0; transform: translate(-55%, -50%) rotate(-84deg) scale(.67); }
  25% { opacity: .94; }
  100% { opacity: 0; transform: translate(-45%, -51%) rotate(30deg) scale(1.12); }
}

@keyframes battle-wave {
  0% { opacity: .86; transform: translate(-50%, -50%) scale(.32); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.63); }
}

@keyframes battle-scatter {
  0% { opacity: .9; transform: translate(-50%, -50%) scale(.28) rotate(0); }
  100% { opacity: 0; transform: translate(-39%, -63%) scale(1.42) rotate(16deg); }
}

@keyframes battle-rise {
  0% { opacity: 0; transform: translate(-50%, 10%) scale(.72); }
  22% { opacity: 1; transform: translate(-50%, -42%) scale(1.05); }
  68% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -158%) scale(.93); }
}

@keyframes battle-banner {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(.83); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.03); }
  29% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  76% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -6px); }
}

@keyframes battle-hp-trail {
  0% { opacity: .8; transform: scaleX(1); }
  100% { opacity: 0; transform: scaleX(0); }
}

@keyframes battle-route-glow {
  0%, 100% { box-shadow: none; }
  28% { box-shadow: inset 0 0 11px #f8cf78ad, 0 0 9px #efc27466; }
}

@keyframes battle-trophy {
  0% { opacity: .8; transform: translateY(8px) scale(.82) rotate(-12deg); }
  47% { opacity: 1; transform: translateY(-4px) scale(1.17) rotate(7deg); }
  100% { opacity: 1; transform: none; }
}

@keyframes battle-trophy-ring {
  from { opacity: .8; transform: scale(.9); }
  to { opacity: 0; transform: scale(1.85); }
}
