/* Creature Lab add-on: Battle Arena — all selectors scoped under .ba-root */
.ba-root {
  --ba-player: #2f80ff;
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 560px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: "Baloo 2", "Comic Sans MS", "Chalkboard SE", "Comic Neue", "Trebuchet MS", system-ui, sans-serif;
  color: #2b2350;
  background: radial-gradient(circle at 50% 0%, #fff6a8 0%, #ffcf4d 35%, #ff8c42 100%);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.ba-root *, .ba-root *::before, .ba-root *::after { box-sizing: border-box; }

/* buttons */
.ba-root .ba-btn {
  font: inherit;
  border: 5px solid #2b2350;
  border-radius: 28px;
  background: #fff;
  color: #2b2350;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 7px 0 #2b2350;
  transition: transform .08s, box-shadow .08s;
  min-height: 72px;
  min-width: 72px;
}
.ba-root .ba-btn:active { transform: translateY(6px); box-shadow: 0 1px 0 #2b2350; }
.ba-root .ba-btn-round { width: 76px; height: 76px; border-radius: 50%; font-size: 38px; padding: 0; line-height: 1; }
.ba-root .ba-green { background: #3ddc84; }
.ba-root .ba-yellow { background: #ffd93b; }
.ba-root .ba-blue { background: #5ab8ff; }

/* top bar */
.ba-root .ba-topbar { display: flex; align-items: center; gap: 14px; padding: 12px 16px; flex: 0 0 auto; }
.ba-root .ba-title {
  flex: 1; text-align: center; font-size: clamp(30px, 5vw, 50px); font-weight: 900;
  color: #fff; -webkit-text-stroke: 2px #2b2350; text-shadow: 0 5px 0 #2b2350; letter-spacing: 1px;
}

/* empty */
.ba-root .ba-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 32px; font-weight: 800; text-align: center; padding: 20px; }
.ba-root .ba-empty-emoji { font-size: 120px; animation: ba-bounce-loop 1.2s ease-in-out infinite; }

/* pick screen */
.ba-root .ba-pick-cols { flex: 1 1 auto; min-height: 0; display: flex; gap: 14px; padding: 0 14px; }
.ba-root .ba-pick-col {
  flex: 1 1 0; min-width: 0; display: flex; flex-direction: column;
  background: rgba(255,255,255,.75); border: 6px solid var(--ba-player); border-radius: 30px; overflow: hidden;
}
.ba-root .ba-pick-head { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--ba-player); flex-wrap: wrap; }
.ba-root .ba-player-badge { font-size: 34px; font-weight: 900; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.3); padding: 0 6px; }
.ba-root .ba-chips { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.ba-root .ba-chip {
  font: inherit; display: flex; align-items: center; gap: 6px; min-height: 60px; padding: 4px 14px 4px 6px;
  border-radius: 40px; border: 4px solid rgba(255,255,255,.6); background: rgba(255,255,255,.35); color: #fff;
  font-size: 22px; font-weight: 900; cursor: pointer;
}
.ba-root .ba-chip.ba-on { background: #fff; color: #2b2350; border-color: #ffd93b; box-shadow: 0 0 0 4px #ffd93b; }
.ba-root .ba-avatar-emoji { font-size: 34px; line-height: 1; }
.ba-root .ba-avatar-img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; }
.ba-root .ba-dice { margin-left: auto; width: 66px; height: 66px; min-height: 66px; min-width: 66px; font-size: 34px; }

.ba-root .ba-grid {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; align-content: start;
}
.ba-root .ba-card {
  font: inherit; position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: #fff; border: 5px solid #2b2350; border-radius: 24px; padding: 8px; cursor: pointer;
  box-shadow: 0 6px 0 #2b2350; transition: transform .1s;
}
.ba-root .ba-card:active { transform: scale(.95); }
.ba-root .ba-card.ba-on { background: #fff59d; border-color: var(--ba-player); box-shadow: 0 0 0 6px var(--ba-player), 0 6px 0 #2b2350; transform: scale(1.04) rotate(-2deg); }
.ba-root .ba-card.ba-on::after {
  content: "✔"; position: absolute; top: -14px; right: -12px; width: 48px; height: 48px; border-radius: 50%;
  background: var(--ba-player); color: #fff; font-size: 30px; line-height: 44px; text-align: center; border: 4px solid #fff;
}
.ba-root .ba-card .ba-art { width: 100%; aspect-ratio: 1; }
.ba-root .ba-card-name { font-size: 18px; font-weight: 900; text-align: center; line-height: 1.1; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ba-root .ba-card-type { position: absolute; top: 6px; left: 8px; font-size: 22px; }

.ba-root .ba-art { display: flex; align-items: center; justify-content: center; border-radius: 18px; overflow: hidden; background: #e9f6ff; }
.ba-root .ba-art img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.ba-root .ba-art-emoji { font-size: 64px; }
.ba-root .ba-flip img, .ba-root .ba-flip .ba-art-emoji { transform: scaleX(-1); }

.ba-root .ba-fight {
  flex: 0 0 auto; margin: 14px auto 18px; font-size: clamp(36px, 6vw, 56px); padding: 8px 48px; min-height: 96px;
  background: #ccc; color: #666; border-radius: 50px;
}
.ba-root .ba-fight.ba-ready { background: #ff3b5c; color: #fff; animation: ba-pulse 1s ease-in-out infinite; text-shadow: 0 3px 0 rgba(0,0,0,.3); }

/* battle stage */
.ba-root .ba-stage {
  position: relative; flex: 1; min-height: 0; margin: 0 14px 14px; border-radius: 34px; overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 115%, #8b5a2b 0 38%, transparent 39%),
    linear-gradient(#6fd3ff 0%, #b8ecff 55%, #7ed957 55%, #55b93a 100%);
  border: 6px solid #2b2350;
}
.ba-root .ba-crowd { position: absolute; top: 8px; left: 0; right: 0; text-align: center; font-size: 30px; letter-spacing: 6px; white-space: nowrap; animation: ba-crowd 0.6s ease-in-out infinite alternate; opacity: .9; }
.ba-root .ba-round-banner {
  position: absolute; top: 52px; left: 50%; transform: translateX(-50%); z-index: 4;
  font-size: clamp(32px, 6vw, 56px); font-weight: 900; color: #ffd93b; -webkit-text-stroke: 2px #2b2350; text-shadow: 0 5px 0 #2b2350; white-space: nowrap;
}
.ba-root .ba-stat-chip {
  position: absolute; top: 130px; left: 50%; transform: translateX(-50%) scale(0); z-index: 4;
  display: flex; align-items: center; gap: 10px; background: #fff; border: 5px solid #2b2350; border-radius: 40px; padding: 6px 24px 6px 14px;
  box-shadow: 0 6px 0 #2b2350; transition: transform .2s;
}
.ba-root .ba-stat-chip.ba-show { transform: translateX(-50%) scale(1); }
.ba-root .ba-stat-emoji { font-size: 52px; }
.ba-root .ba-stat-label { font-size: 32px; font-weight: 900; }

.ba-root .ba-fighter {
  position: absolute; bottom: 4%; width: 36%; max-width: 340px; display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 2;
}
.ba-root .ba-f1 { left: 4%; }
.ba-root .ba-f2 { right: 4%; }
.ba-root .ba-body { width: 100%; max-width: 260px; aspect-ratio: 1; }
.ba-root .ba-body .ba-art { width: 100%; height: 100%; background: transparent; border-radius: 0; overflow: visible; filter: drop-shadow(0 10px 0 rgba(0,0,0,.25)); }
.ba-root .ba-body .ba-art img { border-radius: 30px; border: 6px solid var(--ba-player); background: #fff; }
.ba-root .ba-body .ba-art-emoji { font-size: 150px; }
.ba-root .ba-stars { font-size: 40px; display: flex; gap: 4px; color: #fff; text-shadow: 0 3px 0 #2b2350; }
.ba-root .ba-star { display: inline-block; }
.ba-root .ba-nametag {
  display: flex; align-items: center; gap: 6px; max-width: 100%;
  background: var(--ba-player); color: #fff; font-weight: 900; font-size: clamp(18px, 2.6vw, 28px); padding: 4px 18px; border-radius: 30px; border: 4px solid #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 4px 0 rgba(0,0,0,.25);
}
.ba-root .ba-meter { position: relative; width: 100%; height: 40px; background: #fff; border: 4px solid #2b2350; border-radius: 22px; overflow: hidden; }
.ba-root .ba-meter-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, var(--ba-player), #ffd93b); transition: width 1s cubic-bezier(.3,1.4,.6,1); }
.ba-root .ba-meter-num { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 20px; text-shadow: 0 0 4px #fff, 0 0 4px #fff; white-space: nowrap; }
.ba-root .ba-winner-round .ba-nametag { animation: ba-pulse .6s ease-in-out 3; }
.ba-root .ba-loser-round .ba-body { filter: grayscale(.4); }

.ba-root .ba-kapow {
  position: absolute; left: 50%; top: 42%; z-index: 5; pointer-events: none; opacity: 0;
  font-size: clamp(60px, 12vw, 130px); font-weight: 900; color: #ffd93b; -webkit-text-stroke: 4px #ff3b5c; text-shadow: 6px 6px 0 #2b2350;
  transform: translate(-50%, -50%) rotate(var(--ba-rot, -8deg)) scale(0);
}
.ba-root .ba-kapow-show { animation: ba-kapow 1s ease-out forwards; }
.ba-root .ba-fx { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.ba-root .ba-particle { position: absolute; transform: translate(-50%, -50%); animation: ba-particle 1.2s ease-out forwards; }

/* result */
.ba-root .ba-result { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(43,35,80,.55); animation: ba-fade .3s ease-out; }
.ba-root .ba-confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
.ba-root .ba-result-card {
  position: relative; z-index: 1; background: #fff; border: 8px solid var(--ba-player); border-radius: 40px; padding: 20px 30px 26px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: 92%; max-height: 94%; overflow: auto;
  box-shadow: 0 12px 0 #2b2350; animation: ba-pop .6s cubic-bezier(.3,1.6,.5,1);
}
.ba-root .ba-crown { font-size: 80px; line-height: .8; animation: ba-bounce-loop 1s ease-in-out infinite; }
.ba-root .ba-result-art { width: min(240px, 40vh); height: min(240px, 40vh); background: transparent; }
.ba-root .ba-result-art img { border-radius: 30px; border: 6px solid var(--ba-player); }
.ba-root .ba-result-name { font-size: clamp(30px, 5vw, 48px); font-weight: 900; text-align: center; line-height: 1.05; }
.ba-root .ba-result-wins { font-size: clamp(34px, 6vw, 60px); font-weight: 900; color: #ff3b5c; -webkit-text-stroke: 1px #2b2350; }
.ba-root .ba-result-who { display: flex; align-items: center; gap: 8px; font-size: 28px; font-weight: 900; }
.ba-root .ba-result-catch { font-size: 22px; font-style: italic; text-align: center; color: #6a5acd; }
.ba-root .ba-result-btns { display: flex; gap: 18px; margin-top: 10px; }
.ba-root .ba-big { width: 120px; height: 120px; font-size: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; padding: 0; }
.ba-root .ba-btn-sub { font-size: 18px; margin-top: 6px; }

/* animations */
.ba-root .ba-bounce { animation: ba-bounce .7s ease-in-out 2; }
.ba-root .ba-shake { animation: ba-shake .6s ease-in-out; }
.ba-root .ba-stage-shake { animation: ba-shake-small .4s ease-in-out; }
.ba-root .ba-lunge-right { animation: ba-lunge-right .6s ease-in-out; }
.ba-root .ba-lunge-left { animation: ba-lunge-left .6s ease-in-out; }
.ba-root .ba-pop { animation: ba-pop .5s cubic-bezier(.3,1.6,.5,1); }
.ba-root .ba-wiggle { animation: ba-shake .5s; }
.ba-root .ba-enter-left { animation: ba-enter-left .8s cubic-bezier(.3,1.5,.5,1); }
.ba-root .ba-enter-right { animation: ba-enter-right .8s cubic-bezier(.3,1.5,.5,1); }
.ba-root .ba-stat-chip.ba-pop { animation: ba-pop-center .5s cubic-bezier(.3,1.6,.5,1); }
.ba-root .ba-round-banner.ba-pop { animation: ba-pop-center .5s cubic-bezier(.3,1.6,.5,1); }

@keyframes ba-bounce { 0%,100% { transform: translateY(0) scale(1,1); } 30% { transform: translateY(-40px) scale(.95,1.08); } 60% { transform: translateY(0) scale(1.1,.9); } }
@keyframes ba-bounce-loop { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
@keyframes ba-shake { 0%,100% { transform: translateX(0) rotate(0); } 15% { transform: translateX(-24px) rotate(-12deg); } 30% { transform: translateX(20px) rotate(10deg); } 45% { transform: translateX(-16px) rotate(-8deg); } 60% { transform: translateX(12px) rotate(6deg); } 80% { transform: translateX(-6px) rotate(-3deg); } }
@keyframes ba-shake-small { 0%,100% { transform: translate(0,0); } 25% { transform: translate(-8px,4px); } 50% { transform: translate(8px,-4px); } 75% { transform: translate(-4px,2px); } }
@keyframes ba-lunge-right { 0%,100% { transform: translateX(0) rotate(0); } 20% { transform: translateX(-30px) rotate(-8deg); } 55% { transform: translateX(45%) rotate(12deg) scale(1.1); } }
@keyframes ba-lunge-left { 0%,100% { transform: translateX(0) rotate(0); } 20% { transform: translateX(30px) rotate(8deg); } 55% { transform: translateX(-45%) rotate(-12deg) scale(1.1); } }
@keyframes ba-pop { 0% { transform: scale(0); } 70% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes ba-pop-center { 0% { transform: translateX(-50%) scale(0); } 70% { transform: translateX(-50%) scale(1.25); } 100% { transform: translateX(-50%) scale(1); } }
@keyframes ba-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.07); } }
@keyframes ba-crowd { from { transform: translateY(0); } to { transform: translateY(-6px); } }
@keyframes ba-kapow { 0% { opacity: 1; transform: translate(-50%,-50%) rotate(var(--ba-rot)) scale(0); } 25% { opacity: 1; transform: translate(-50%,-50%) rotate(var(--ba-rot)) scale(1.3); } 40% { transform: translate(-50%,-50%) rotate(var(--ba-rot)) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%,-50%) rotate(var(--ba-rot)) scale(1.1); } }
@keyframes ba-particle { 0% { opacity: 1; transform: translate(-50%,-50%) scale(.3); } 100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)) scale(1.2); } }
@keyframes ba-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ba-enter-left { from { transform: translateX(-120%) rotate(-30deg); } to { transform: translateX(0) rotate(0); } }
@keyframes ba-enter-right { from { transform: translateX(120%) rotate(30deg); } to { transform: translateX(0) rotate(0); } }

/* portrait tablets / phones: stack the pick columns */
@media (max-aspect-ratio: 4/5) {
  .ba-root .ba-pick-cols { flex-direction: column; }
  .ba-root .ba-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .ba-root .ba-fighter { width: 44%; }
}
@media (prefers-reduced-motion: reduce) {
  .ba-root *, .ba-root *::before, .ba-root *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
/* AI commentary (optional) */
.ba-root .ba-hidden { display: none !important; }
.ba-root .ba-commentary { max-width: 460px; margin: 4px auto 0; background: #f3f0ff; border: 3px dashed #7b5cff; border-radius: 16px; padding: 6px 12px; font-size: 17px; text-align: left; max-height: 30vh; overflow: auto; }
.ba-root .ba-commentary p { margin: 4px 0; }
.ba-root .ba-mic { background: linear-gradient(135deg, #f06595, #7b5cff); color: #fff; }
