/* ============================================================================
 * POKÉSPIRE · Over-the-Shoulder 2D Animated Pokémon Battle Stage
 * Sunlit 3D-perspective battle arenas + 100% authentic 2D animated Pokémon:
 *   - Foreground Bottom-Left: Player Partner + Summons + Power Pokémon
 *     (2D animated BACK-VIEW facing diagonally up-right toward enemy)
 *   - Midground Upper-Right: Enemy Pokémon(s) (2D animated FRONT-VIEW facing player)
 *     + Enemy Trainer standing slightly behind-right
 * ============================================================================ */

/* 1. Crisp Sunlit Battle Arena Backdrop & Per-Arena Ground Calibration */
#bg-stage[data-screen="battle"] .bg-plate {
  filter: saturate(1.06) contrast(1.02) brightness(1.02) !important;
  background-position: center var(--arena-bg-pos-y, 46%) !important;
  background-size: cover !important;
}
#bg-stage[data-screen="battle"][data-arena="academy"] .bg-plate { --arena-bg-pos-y: 46%; }
#bg-stage[data-screen="battle"][data-arena="forest"]  .bg-plate { --arena-bg-pos-y: 52%; }
#bg-stage[data-screen="battle"][data-arena="coast"]   .bg-plate { --arena-bg-pos-y: 54%; }
#bg-stage[data-screen="battle"][data-arena="desert"]  .bg-plate { --arena-bg-pos-y: 50%; }
#bg-stage[data-screen="battle"][data-arena="glacier"] .bg-plate { --arena-bg-pos-y: 48%; }
#bg-stage[data-screen="battle"][data-arena="horde"]   .bg-plate { --arena-bg-pos-y: 56%; }

#bg-stage[data-screen="battle"] .bg-vignette {
  background: radial-gradient(
    ellipse 86% 78% at 50% 46%,
    transparent 58%,
    rgba(15, 23, 42, 0.16) 100%
  ) !important;
  opacity: 0.72 !important;
}

#app[data-screen="battle"] .battle-bg-layer {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.06) 0%,
    transparent 16%,
    transparent 74%,
    rgba(248, 251, 255, 0.36) 91%,
    rgba(248, 251, 255, 0.76) 100%
  ) !important;
}

/* 2. Diagonal Over-the-Shoulder Stage Container & Unified Perspective Scale */
#app[data-screen="battle"] .stage-area {
  /* Reference visible height for foreground Trainer (~1.7m = 1.00x) */
  --stage-ref-h: clamp(164px, 23vh, 232px);
  /* Balanced stage height ratios (large/legendary Pokémon stay commanding without crowding) */
  --tier-xs: 0.50;
  --tier-s:  0.68;
  --tier-m:  0.86;
  --tier-l:  1.04;
  --tier-xl: 1.16;
  /* Default ground-plane anchors (measured from bottom of stage-area ≈ 84vh) */
  --arena-player-pb: clamp(98px, 14vh, 142px);
  --arena-enemy-pb: clamp(188px, 26vh, 276px);
  --arena-enemy-trainer-dy: -8px;

  position: relative !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  display: flex !important;
  align-items: flex-end !important;
  justify-content: space-between !important;
  padding: clamp(6px, 1.5vh, 18px) clamp(20px, 5vw, 86px) clamp(8px, 1.8vh, 22px) !important;
  gap: clamp(12px, 3vw, 48px) !important;
  overflow: visible !important;
}

/* Per-Arena Measured Ground Coordinates (all 6 battle arenas calibrated against 16:10 grid) */
#app[data-screen="battle"][data-arena="academy"] .stage-area {
  --arena-player-pb: clamp(104px, 15vh, 150px);
  --arena-enemy-pb:  clamp(224px, 31vh, 326px);
  --arena-enemy-trainer-dy: -14px;
}
#app[data-screen="battle"][data-arena="forest"] .stage-area {
  --arena-player-pb: clamp(98px, 13.5vh, 138px);
  --arena-enemy-pb:  clamp(150px, 21.5vh, 224px);
  --arena-enemy-trainer-dy: 0px;
}
#app[data-screen="battle"][data-arena="coast"] .stage-area {
  --arena-player-pb: clamp(98px, 14vh, 142px);
  --arena-enemy-pb:  clamp(158px, 22.5vh, 236px);
  --arena-enemy-trainer-dy: 6px;
}
#app[data-screen="battle"][data-arena="desert"] .stage-area {
  --arena-player-pb: clamp(98px, 14vh, 142px);
  --arena-enemy-pb:  clamp(172px, 24.5vh, 256px);
  --arena-enemy-trainer-dy: -4px;
}
#app[data-screen="battle"][data-arena="glacier"] .stage-area {
  --arena-player-pb: clamp(102px, 14.5vh, 146px);
  --arena-enemy-pb:  clamp(188px, 26.5vh, 276px);
  --arena-enemy-trainer-dy: -6px;
}
#app[data-screen="battle"][data-arena="horde"] .stage-area {
  --arena-player-pb: clamp(94px, 13vh, 132px);
  --arena-enemy-pb:  clamp(166px, 23.5vh, 246px);
  --arena-enemy-trainer-dy: -6px;
}

/* Unified size-tier ratio mapping across all battle Pokémon */
#app[data-screen="battle"] :is(.partner-on-field, .summon-sprite, .power-field-sprite, .enemy-sprite-2d) {
  --size-ratio: var(--tier-m);
}
#app[data-screen="battle"] :is(.partner-on-field, .summon-sprite, .power-field-sprite, .enemy-sprite-2d)[data-size="xs"] { --size-ratio: var(--tier-xs); }
#app[data-screen="battle"] :is(.partner-on-field, .summon-sprite, .power-field-sprite, .enemy-sprite-2d)[data-size="s"]  { --size-ratio: var(--tier-s); }
#app[data-screen="battle"] :is(.partner-on-field, .summon-sprite, .power-field-sprite, .enemy-sprite-2d)[data-size="m"]  { --size-ratio: var(--tier-m); }
#app[data-screen="battle"] :is(.partner-on-field, .summon-sprite, .power-field-sprite, .enemy-sprite-2d)[data-size="l"]  { --size-ratio: var(--tier-l); }
#app[data-screen="battle"] :is(.partner-on-field, .summon-sprite, .power-field-sprite, .enemy-sprite-2d)[data-size="xl"] { --size-ratio: var(--tier-xl); }

/* 3. Foreground Bottom-Left: Player Trainer + Partner + Summons + Powers */
#app[data-screen="battle"] .player-unit {
  position: relative;
  z-index: 4;
  align-self: flex-end !important;
  margin-inline-start: clamp(8px, 4vw, 72px) !important;
  margin-bottom: 0 !important;
  padding-bottom: var(--arena-player-pb, clamp(98px, 14vh, 142px)) !important;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

#app[data-screen="battle"] .player-stage-pair {
  display: flex;
  align-items: flex-end;
  gap: clamp(10px, 1.8vw, 24px) !important;
  position: relative;
}

/* Foreground Player Trainer (Closest to camera: depth = 1.00x, reference height anchor) */
#app[data-screen="battle"] .player-trainer-unit {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translate(-4px, 8px);
  transform-origin: bottom center;
  opacity: 1;
  z-index: 6;
}

#app[data-screen="battle"] .player-trainer-unit .battle-pad {
  min-width: clamp(128px, 12vw, 176px) !important;
  min-height: clamp(150px, 21vh, 218px) !important;
}

#app[data-screen="battle"] .player-trainer-unit .trainer-on-field {
  --depth-scale: 1.00;
  --size-ratio: 1.00;
  --target-vis-h: calc(var(--stage-ref-h) * var(--depth-scale) * var(--size-ratio));
  --sprite-h: calc(var(--target-vis-h) * var(--sprite-inv-fill, 1.16));
  height: var(--sprite-h) !important;
  width: auto !important;
  max-width: calc(var(--target-vis-h) * 1.25) !important;
  object-fit: contain;
  object-position: bottom center;
  image-rendering: pixelated !important;
  margin-bottom: calc(var(--ground-sink, 0) * var(--sprite-h) * -1 + 8px) !important;
  filter: drop-shadow(0 10px 14px rgba(15, 23, 42, 0.38));
}

#app[data-screen="battle"] .player-trainer-plate {
  position: absolute !important;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  margin-top: 0 !important;
  white-space: nowrap;
  padding: 2px 10px !important;
  border-radius: 999px !important;
  font-size: 11.5px !important;
  font-weight: 800;
  color: #1e293b !important;
  background: rgba(255, 255, 255, 0.92) !important;
  border: 1px solid rgba(255, 255, 255, 0.96) !important;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.16);
}

/* Foreground Partner Pokémon (depth = 0.90x, slightly forward into the court) */
#app[data-screen="battle"] .player-partner-unit {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 5;
  cursor: pointer;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease;
}

#app[data-screen="battle"] .player-partner-unit:hover {
  transform: translateY(-5px) scale(1.03);
}

#app[data-screen="battle"] .battle-screen.is-aiming .player-partner-unit:hover {
  transform: none;
}

#app[data-screen="battle"] .partner-battle-pad {
  position: relative;
  min-width: clamp(164px, 17vw, 236px) !important;
  min-height: clamp(128px, 17vh, 184px) !important;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

#app[data-screen="battle"] .player-plate {
  position: absolute !important;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: clamp(192px, 17vw, 228px) !important;
  min-width: 0 !important;
  max-width: none !important;
  margin-top: 0 !important;
}

#app[data-screen="battle"] .player-plate .pk-bar-track {
  width: 100% !important;
}

#app[data-screen="battle"] .player-plate .buff-row {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 4px;
  justify-content: flex-start;
}

#app[data-screen="battle"] .partner-on-field {
  --depth-scale: 0.88;
  --target-vis-h: calc(var(--stage-ref-h) * var(--depth-scale) * var(--size-ratio, var(--tier-m)));
  --sprite-h: calc(var(--target-vis-h) * var(--sprite-inv-fill, 1.11));
  position: relative;
  z-index: 2;
  height: var(--sprite-h) !important;
  width: auto !important;
  max-width: calc(var(--target-vis-h) * 1.65) !important;
  object-fit: contain;
  object-position: bottom center;
  image-rendering: pixelated !important;
  margin-bottom: calc(var(--ground-sink, 0) * var(--sprite-h) * -1 + 4px) !important;
  filter: drop-shadow(0 10px 12px rgba(15, 23, 42, 0.36));
}

/* ALL Player-side Back-View Pokémon naturally face up-right toward enemy — NEVER flip! */
#app[data-screen="battle"] .partner-on-field.is-back-view,
#app[data-screen="battle"] .summon-sprite.is-back-view,
#app[data-screen="battle"] .power-field-sprite.is-back-view {
  transform: none;
  image-rendering: pixelated !important;
}

/* Dedicated back-view animations so back-view sprites never flip horizontally */
#app[data-screen="battle"] .summon-sprite.is-back-view.summon-pop {
  animation: summonPopBack 0.28s cubic-bezier(0.2, 1.25, 0.4, 1);
}
#app[data-screen="battle"] .partner-on-field.is-back-view.cast-charge,
#app[data-screen="battle"] .summon-sprite.is-back-view.cast-charge {
  animation: castChargeBack 0.38s ease-out;
}
#app[data-screen="battle"] .summon-sprite.is-back-view.summon-recall {
  animation: summonRecallBack 0.36s cubic-bezier(0.32, 0, 0.67, 0.2) forwards;
}
#app[data-screen="battle"] .summon-sprite:not(.is-back-view).summon-recall {
  animation: summonRecallFront 0.36s cubic-bezier(0.32, 0, 0.67, 0.2) forwards;
}

@keyframes summonPopBack {
  0%   { transform: scale(0.15); filter: brightness(3.6) drop-shadow(0 0 22px #ef4444); opacity: 0.4; }
  65%  { transform: scale(1.12); filter: brightness(1.6) drop-shadow(0 0 16px #fff); opacity: 1; }
  100% { transform: scale(1); filter: drop-shadow(0 8px 10px rgba(15, 23, 42, 0.36)); opacity: 1; }
}
@keyframes castChargeBack {
  0%   { transform: translate(0, 0) scale(1); filter: drop-shadow(0 8px 10px rgba(15, 23, 42, 0.36)); }
  36%  { transform: translate(16px, -6px) scale(1.13); filter: brightness(1.75) drop-shadow(0 0 18px #fff); }
  100% { transform: translate(0, 0) scale(1); filter: drop-shadow(0 8px 10px rgba(15, 23, 42, 0.36)); }
}
@keyframes summonRecallBack {
  0%   { transform: translate(0, 0) scale(1); filter: drop-shadow(0 8px 10px rgba(15, 23, 42, 0.36)); opacity: 1; }
  28%  { transform: translate(-18px, -30px) scale(1.06); filter: brightness(1.85) drop-shadow(0 0 16px rgba(248, 113, 113, 0.9)); opacity: 1; }
  100% { transform: translate(-96px, -10px) scale(0.12); filter: brightness(3.4) drop-shadow(0 0 24px #ef4444); opacity: 0; }
}
@keyframes summonRecallFront {
  0%   { transform: scaleX(-1) translate(0, 0) scale(1); filter: drop-shadow(0 8px 10px rgba(15, 23, 42, 0.36)); opacity: 1; }
  28%  { transform: scaleX(-1) translate(18px, -30px) scale(1.06); filter: brightness(1.85) drop-shadow(0 0 16px rgba(248, 113, 113, 0.9)); opacity: 1; }
  100% { transform: scaleX(-1) translate(96px, -10px) scale(0.12); filter: brightness(3.4) drop-shadow(0 0 24px #ef4444); opacity: 0; }
}

/* Only mirror if a rare Pokémon had no back sprite and fell back to front view */
#app[data-screen="battle"] .partner-on-field:not(.is-back-view) {
  transform: scaleX(-1);
}

/* Keep Gen5 pixel sprites crisp when pixel fallback or pixel style is active */
#app[data-screen="battle"] :is(.partner-on-field, .summon-sprite, .power-field-sprite, .enemy-sprite-2d).is-pixel-sprite,
html[data-sprite-style="gen5"] #app[data-screen="battle"] :is(.partner-on-field, .summon-sprite, .power-field-sprite, .enemy-sprite-2d),
html[data-sprite-style="gen5ani"] #app[data-screen="battle"] :is(.partner-on-field, .summon-sprite, .power-field-sprite, .enemy-sprite-2d) {
  image-rendering: pixelated !important;
}

/* Summon Squad & Power Field flanking foreground partner in back-view */
#app[data-screen="battle"] .power-field-formation {
  position: relative;
  z-index: 4;
  overflow: visible;
  transform: translateY(-4px);
  transform-origin: bottom left;
}

#app[data-screen="battle"] .summon-squad {
  position: relative;
  display: block !important;
  z-index: 4;
  width: 0 !important;
  flex: 0 0 0 !important;
  height: 220px !important;
  margin-left: -76px !important;
  overflow: visible !important;
  transform: none !important;
  transform-origin: bottom left;
  pointer-events: none;
}

#app[data-screen="battle"] .summon-slot-item {
  pointer-events: auto;
  cursor: pointer;
  transform: scale(var(--summon-depth, 1));
  transform-origin: center bottom;
  transition:
    left 0.36s cubic-bezier(0.22, 1, 0.36, 1),
    bottom 0.36s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.22s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.28s ease;
}

#app[data-screen="battle"] .summon-slot-item:hover {
  transform: translateY(-5px) scale(calc(var(--summon-depth, 1) * 1.03));
  z-index: 60 !important;
}

#app[data-screen="battle"] .battle-screen.is-aiming .summon-slot-item:hover {
  transform: scale(var(--summon-depth, 1));
}

#app[data-screen="battle"] .summon-slot-item.is-recalling {
  pointer-events: none;
}

#app[data-screen="battle"] .summon-slot-item.is-recalling .ground-ring {
  opacity: 0;
}

/* Out-of-sync living idle motion per summoned Pokémon */
#app[data-screen="battle"] .summon-sprite.field-idle {
  animation-duration: var(--idle-dur, 1.6s);
  animation-delay: var(--idle-delay, 0s);
}

#app[data-screen="battle"] .power-field-pokemon {
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

#app[data-screen="battle"] .power-field-pokemon:hover {
  transform: translateY(-5px) scale(1.03);
}

#app[data-screen="battle"] .summon-sprite {
  --depth-scale: 0.84;
  --target-vis-h: calc(var(--stage-ref-h) * var(--depth-scale) * var(--size-ratio, var(--tier-m)));
  --sprite-h: calc(var(--target-vis-h) * var(--sprite-inv-fill, 1.11));
  --clamped-h: min(var(--sprite-h), clamp(174px, 23.5vh, 232px));
  height: var(--clamped-h) !important;
  width: auto !important;
  max-width: min(calc(var(--target-vis-h) * 1.44), clamp(192px, 21vw, 268px)) !important;
  object-fit: contain;
  object-position: bottom center;
  margin-bottom: calc(var(--ground-sink, 0) * var(--clamped-h) * -1 + 2px) !important;
  filter: drop-shadow(0 10px 12px rgba(15, 23, 42, 0.36));
}

#app[data-screen="battle"] .power-field-sprite {
  --depth-scale: 0.62;
  --target-vis-h: calc(var(--stage-ref-h) * var(--depth-scale) * var(--size-ratio, var(--tier-m)));
  --sprite-h: calc(var(--target-vis-h) * var(--sprite-inv-fill, 1.11));
  height: var(--sprite-h) !important;
  width: auto !important;
  max-width: calc(var(--target-vis-h) * 1.65) !important;
  object-fit: contain;
  object-position: bottom center;
  margin-bottom: calc(var(--ground-sink, 0) * var(--sprite-h) * -1 + 6px) !important;
  filter: drop-shadow(0 6px 8px rgba(15, 23, 42, 0.34));
}

/* 4. Midground Upper-Right: Enemy Pokémon(s) & Enemy Trainer (bottom-anchored to per-arena ground plane) */
#app[data-screen="battle"] .enemy-stage-pair {
  position: relative;
  z-index: 4;
  align-self: flex-end !important;
  margin-top: 0 !important;
  padding-bottom: var(--arena-enemy-pb, clamp(188px, 26vh, 276px)) !important;
  margin-inline-end: clamp(8px, 4.5vw, 84px) !important;
  display: flex !important;
  align-items: flex-end !important;
  gap: clamp(10px, 2.2vw, 28px) !important;
}

#app[data-screen="battle"] .enemies-side {
  display: flex !important;
  align-items: flex-end !important;
  gap: clamp(12px, 2.4vw, 34px) !important;
}

#app[data-screen="battle"] .enemy-unit {
  position: relative;
  flex: 0 0 auto;
  width: clamp(164px, 15.5vw, 208px);
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease;
}

/* Gentle diagonal depth arc when facing 2 or 3 enemies (near-large, far-small) */
#app[data-screen="battle"] .enemies-side:has(.enemy-unit:nth-child(2)) .enemy-unit:nth-child(1) {
  transform: translateY(14px);
}
#app[data-screen="battle"] .enemies-side:has(.enemy-unit:nth-child(2)) .enemy-unit:nth-child(2) {
  transform: translateY(-10px) scale(0.93);
}
#app[data-screen="battle"] .enemies-side:has(.enemy-unit:nth-child(3)) .enemy-unit:nth-child(3) {
  transform: translateY(4px) scale(0.88);
}

#app[data-screen="battle"] .enemy-unit:hover {
  transform: translateY(-5px) scale(1.03);
}
#app[data-screen="battle"] .battle-screen.is-aiming .enemy-unit:hover {
  transform: none;
}

/* Midground perspective scale for enemy Pokémon (depth = 0.68x of foreground reference) */
#app[data-screen="battle"] .enemy-unit .battle-pad {
  position: relative;
  width: 100%;
  min-width: clamp(128px, 13.5vw, 186px) !important;
  min-height: clamp(104px, 14.5vh, 152px) !important;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

#app[data-screen="battle"] .enemy-plate {
  position: absolute !important;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: clamp(176px, calc(var(--enemy-health-width, 156px) * var(--health-track-scale, 1) + 28px), 212px) !important;
  min-width: 0 !important;
  max-width: 212px !important;
  margin-top: 0 !important;
}

#app[data-screen="battle"] .enemy-plate .pk-bar-track {
  width: 100% !important;
  max-width: 100% !important;
}

#app[data-screen="battle"] .enemy-plate .buff-row {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 4px;
  justify-content: center;
}

#app[data-screen="battle"] .enemy-sprite-2d {
  --depth-scale: 0.66;
  --target-vis-h: calc(var(--stage-ref-h) * var(--depth-scale) * var(--size-ratio, var(--tier-m)));
  --sprite-h: calc(var(--target-vis-h) * var(--sprite-inv-fill, 1.11));
  position: relative;
  z-index: 2;
  height: var(--sprite-h) !important;
  width: auto !important;
  max-width: calc(var(--target-vis-h) * 1.65) !important;
  object-fit: contain;
  object-position: bottom center;
  image-rendering: pixelated !important;
  margin-bottom: calc(var(--ground-sink, 0) * var(--sprite-h) * -1 + 10px) !important;
  filter: drop-shadow(0 8px 10px rgba(15, 23, 42, 0.36));
}

/* Background Enemy Trainer (furthest depth plane: depth = 0.62x of foreground trainer) */
#app[data-screen="battle"] .enemy-trainer-unit {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translate(6px, var(--arena-enemy-trainer-dy, -8px));
  transform-origin: bottom center;
}

#app[data-screen="battle"] .enemy-trainer-unit .battle-pad {
  min-width: 112px !important;
  min-height: 122px !important;
}

#app[data-screen="battle"] .enemy-trainer-on-field {
  --depth-scale: 0.62;
  --size-ratio: 1.00;
  --target-vis-h: calc(var(--stage-ref-h) * var(--depth-scale) * var(--size-ratio));
  --sprite-h: calc(var(--target-vis-h) * var(--sprite-inv-fill, 1.16));
  height: var(--sprite-h) !important;
  width: auto !important;
  max-width: calc(var(--target-vis-h) * 1.25) !important;
  object-fit: contain;
  object-position: bottom center;
  image-rendering: pixelated !important;
  margin-bottom: calc(var(--ground-sink, 0) * var(--sprite-h) * -1 + 8px) !important;
  filter: drop-shadow(0 8px 12px rgba(15, 23, 42, 0.38));
}

/* 5. Crisp Sunlit Readability for Plates, Intents, Lock Brackets & Speech Bubbles */
#app[data-screen="battle"] :is(.player-plate, .enemy-plate, .enemy-trainer-plate) {
  position: absolute !important;
  z-index: 8 !important;
  margin-top: 0 !important;
  padding: 6px 12px !important;
  background: rgba(255, 255, 255, 0.94) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(255, 255, 255, 0.98) !important;
  border-radius: 14px !important;
  box-shadow:
    0 12px 26px -8px rgba(15, 23, 42, 0.26),
    0 2px 6px rgba(15, 23, 42, 0.1) !important;
}

#app[data-screen="battle"] .enemy-trainer-plate {
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}

#app[data-screen="battle"] .enemy-unit.targeted .enemy-plate {
  border-color: #0ea5e9 !important;
  box-shadow:
    0 0 0 3px rgba(14, 165, 233, 0.24),
    0 14px 30px -8px rgba(14, 165, 233, 0.36) !important;
}

/* High-contrast frosted dark pill so enemy damage intent pops against bright skies */
#app[data-screen="battle"] .battle-screen .intent-pill {
  position: absolute !important;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9 !important;
  margin-bottom: 0 !important;
  white-space: nowrap;
  width: max-content;
  padding: 4px 12px !important;
  border-radius: 999px !important;
  background: rgba(15, 23, 42, 0.8) !important;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid rgba(255, 255, 255, 0.28) !important;
  color: #ffffff !important;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.32) !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

#app[data-screen="battle"] .battle-lock-frame {
  z-index: 9 !important;
}

#app[data-screen="battle"] .enemy-speech-bubble {
  position: absolute !important;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 230px;
  z-index: 9 !important;
  margin-bottom: 0 !important;
}

/* Ground contact shadow + target ring */
#app[data-screen="battle"] .battle-screen .ground-ring {
  z-index: 1;
  border-radius: 50%;
  background: radial-gradient(
    ellipse at center,
    rgba(15, 23, 42, 0.44) 0%,
    rgba(15, 23, 42, 0.2) 52%,
    transparent 74%
  ) !important;
  transition: opacity 0.22s ease, box-shadow 0.22s ease;
}

#app[data-screen="battle"] .enemy-unit.targeted .ground-ring.enemy-ring {
  box-shadow:
    0 0 0 2.5px rgba(14, 165, 233, 0.85),
    0 0 22px rgba(14, 165, 233, 0.65) !important;
}

/* 6. Status Pill Hover Affordance & High-Priority Tooltip Stacking */
#tooltip.tooltip-box {
  z-index: 980 !important;
}

#app[data-screen="battle"] :is(.buff-pill, .field-badge, .intent-pill)[data-tip-title] {
  cursor: help !important;
  pointer-events: auto !important;
  transition: transform 0.14s ease, filter 0.14s ease, box-shadow 0.14s ease;
}

#app[data-screen="battle"] :is(.buff-pill, .field-badge)[data-tip-title]:hover {
  transform: translateY(-1px) scale(1.04);
  filter: brightness(1.12);
}

#tooltip .kw-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}

#tooltip .kw-card-head .kw-card-title {
  margin-bottom: 0;
}

#tooltip .kw-card.is-buff {
  border-left-color: #10b981 !important;
}

#tooltip .kw-card.is-debuff {
  border-left-color: #ef4444 !important;
}

#tooltip .kw-card.is-trait {
  border-left-color: #f59e0b !important;
}

#tooltip .tip-tone-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 800;
  line-height: 1.4;
  white-space: nowrap;
  flex-shrink: 0;
}

#tooltip .tip-tone-badge.is-buff {
  background: #dcfce7;
  color: #15803d;
}

#tooltip .tip-tone-badge.is-debuff {
  background: #fee2e2;
  color: #b91c1c;
}

#tooltip .tip-tone-badge.is-trait {
  background: #fef3c7;
  color: #b45309;
}

/* 7. Responsive Adjustments for Compact / Mobile Viewports */
@media (max-width: 960px) {
  #app[data-screen="battle"] .stage-area {
    padding: 6px 14px 8px !important;
  }
  #app[data-screen="battle"] .player-unit {
    margin-inline-start: 4px !important;
    padding-bottom: 84px !important;
  }
  #app[data-screen="battle"] .player-plate {
    width: clamp(148px, 34vw, 188px) !important;
  }
  #app[data-screen="battle"] .player-trainer-unit {
    display: none;
  }
  #app[data-screen="battle"] .enemy-stage-pair {
    padding-bottom: clamp(128px, 22vh, 196px) !important;
    margin-inline-end: 4px !important;
  }
  #app[data-screen="battle"] .enemy-unit {
    width: clamp(118px, 28vw, 168px);
  }
  #app[data-screen="battle"] .enemy-plate {
    width: clamp(132px, 30vw, 176px) !important;
  }
}

@media (max-height: 700px) {
  #app[data-screen="battle"] .player-unit {
    padding-bottom: 78px !important;
  }
  #app[data-screen="battle"] .partner-battle-pad {
    min-height: 132px !important;
  }
  #app[data-screen="battle"] .enemy-stage-pair {
    padding-bottom: clamp(122px, 20vh, 176px) !important;
  }
}
