/* ==========================================================================
   KINGDOMS AT WAR ⚔️ — BATTLEGROUND CSS
   HUD, health bars, ability cooldowns, minimap, overlays
   ========================================================================== */

/* ── Screen container ────────────────────────────────────────────────── */
#screen-battleground {
  background: #070a0f;
  overflow: hidden;
}

#bg-canvas-container {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 1;
}

/* ── Loading overlay ─────────────────────────────────────────────────── */
#bg-loading {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(7, 10, 15, 0.97);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  font-family: 'Cinzel', sans-serif;
  color: #ffd700;
}
#bg-loading-spinner {
  width: 64px; height: 64px;
  border: 4px solid rgba(0,204,255,0.2);
  border-top: 4px solid #00ccff;
  border-radius: 50%;
  animation: bg-spin 0.9s linear infinite;
}
#bg-load-text { font-size: 14px; color: #a0b2c6; letter-spacing: 1px; }
@keyframes bg-spin { to { transform: rotate(360deg); } }

/* ── Character select overlay ────────────────────────────────────────── */
#bg-char-select {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: radial-gradient(ellipse at top, #0d1b2e 0%, #070a0f 100%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  font-family: 'Cinzel', sans-serif;
}
#bg-char-select h2 {
  font-size: 28px;
  color: #ffd700;
  font-weight: 900;
  text-shadow: 0 0 20px rgba(255,215,0,0.5);
  letter-spacing: 3px;
}
.bg-char-grid {
  display: flex;
  gap: 28px;
  align-items: center;
  justify-content: center;
}
.bg-char-card {
  width: 200px;
  background: rgba(10, 16, 26, 0.95);
  border: 2px solid rgba(212, 175, 55, 0.5);
  border-radius: 14px;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.bg-char-card:hover {
  transform: translateY(-6px) scale(1.03);
  border-color: #ffd700;
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.35);
}
.bg-char-card.selected {
  border-color: #00ccff;
  box-shadow: 0 0 25px rgba(0, 204, 255, 0.4);
}
.bg-char-icon { font-size: 64px; }
.bg-char-name { font-size: 16px; font-weight: 900; color: #fff; }
.bg-char-desc { font-size: 11px; color: #a0b2c6; text-align: center; line-height: 1.5; }
.bg-char-tag {
  background: rgba(0,204,255,0.15);
  border: 1px solid #00ccff;
  color: #00ccff;
  font-size: 10px;
  font-weight: 900;
  padding: 2px 10px;
  border-radius: 10px;
}
#bg-enter-btn {
  background: linear-gradient(180deg, #e5a93b 0%, #a66e14 100%);
  border: 2px solid #fff0a5;
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  padding: 14px 48px;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 2px;
  font-family: 'Cinzel', sans-serif;
  box-shadow: 0 6px 24px rgba(0,0,0,0.6);
  transition: transform 0.15s, box-shadow 0.15s;
}
#bg-enter-btn:hover {
  transform: scale(1.04);
  box-shadow: 0 8px 32px rgba(255,215,0,0.3);
}
#bg-back-btn {
  background: rgba(28,61,90,0.8);
  border: 1px solid #3a6a92;
  color: #a0b2c6;
  font-size: 13px;
  font-weight: 800;
  padding: 8px 24px;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'Cinzel', sans-serif;
}

/* ── In-game HUD ─────────────────────────────────────────────────────── */
#bg-hud {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 10;
  pointer-events: none;
  font-family: 'Cinzel', sans-serif;
}

/* Player health + stamina */
#bg-hud-bottom-left {
  position: absolute;
  bottom: 28px;
  left: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bg-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.bg-bar-icon { font-size: 18px; }
.bg-bar-bg {
  width: 200px;
  height: 12px;
  background: rgba(0,0,0,0.7);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  overflow: hidden;
}
.bg-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.15s ease-out;
}
#bg-hp-fill   { background: #2ecc71; }
#bg-stam-fill { background: #3a86ef; }

/* Character name chip */
#bg-char-chip {
  position: absolute;
  bottom: 95px;
  left: 24px;
  background: rgba(10,16,26,0.9);
  border: 1.5px solid rgba(212,175,55,0.5);
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 12px;
  font-weight: 800;
  color: #ffd700;
  letter-spacing: 1px;
}

/* Ability buttons */
#bg-abilities-row {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.bg-ability-btn {
  width: 60px;
  height: 60px;
  background: rgba(10,16,26,0.92);
  border: 2px solid rgba(212,175,55,0.5);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.bg-ability-btn::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0;
  width: var(--cd, 0%);
  height: 100%;
  background: rgba(0,0,0,0.65);
  pointer-events: none;
  transition: width 0.1s linear;
}
.bg-ability-icon { font-size: 24px; z-index: 1; }
.cd-text {
  font-size: 10px;
  font-weight: 900;
  color: #ffd700;
  z-index: 1;
  letter-spacing: 0.5px;
}
.bg-ability-key {
  position: absolute;
  top: 3px; right: 5px;
  font-size: 9px;
  color: #a0b2c6;
  font-weight: 800;
}

/* Kill count + enemy count */
#bg-stats-top-right {
  position: absolute;
  top: 80px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}
.bg-stat-chip {
  background: rgba(10,16,26,0.88);
  border: 1.5px solid rgba(212,175,55,0.4);
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 800;
  color: #ffd700;
  display: flex;
  gap: 8px;
  align-items: center;
}
.bg-stat-chip span { color: #fff; font-size: 15px; }
#bg-kill-flash.flash { animation: killFlash 0.6s ease-out; }
@keyframes killFlash {
  0%   { color: #ffd700; text-shadow: 0 0 10px #ffd700; }
  50%  { color: #fff;    text-shadow: 0 0 20px #fff; }
  100% { color: #fff; }
}

/* Minimap */
#bg-minimap-wrap {
  position: absolute;
  top: 80px;
  left: 20px;
  background: rgba(10,16,26,0.88);
  border: 1.5px solid rgba(212,175,55,0.5);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#bg-minimap-canvas {
  border-radius: 4px;
  display: block;
}
#bg-minimap-label {
  font-size: 9px;
  font-weight: 800;
  color: #a0b2c6;
  text-align: center;
  letter-spacing: 1px;
}

/* Controls legend */
#bg-controls-hint {
  position: absolute;
  bottom: 105px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10,16,26,0.75);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 6px 18px;
  font-size: 11px;
  color: #a0b2c6;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
#bg-controls-hint strong { color: #ffd700; }

/* Enemy HP bars (absolute positioned via JS) */
#bg-enemy-hp-container {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 5;
}
.bg-enemy-hp {
  position: absolute;
  width: 60px;
  height: 6px;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 3px;
  transform: translateX(-50%);
}
.bg-enemy-hp-fill {
  height: 100%;
  border-radius: 3px;
  background: #2ecc71;
  transition: width 0.1s ease-out;
}

/* Float damage text */
.bg-float-text {
  position: absolute;
  font-size: 14px;
  font-weight: 900;
  color: #ffd700;
  text-shadow: 0 2px 6px rgba(0,0,0,0.9);
  pointer-events: none;
  animation: floatUp 1.5s ease-out forwards;
  white-space: nowrap;
  transform: translateX(-50%);
}
@keyframes floatUp {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0px); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-60px); }
}

/* Death overlay */
#bg-death-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(100, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 30;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  pointer-events: all;
  font-family: 'Cinzel', sans-serif;
}
#bg-death-overlay h2 {
  font-size: 56px;
  color: #e74c3c;
  font-weight: 900;
  text-shadow: 0 0 30px rgba(231,76,60,0.8);
  letter-spacing: 6px;
  animation: deathPulse 1.5s ease-in-out infinite;
}
@keyframes deathPulse {
  0%, 100% { text-shadow: 0 0 20px rgba(231,76,60,0.6); }
  50%       { text-shadow: 0 0 50px rgba(231,76,60,1); }
}
#bg-death-overlay p { color: #a0b2c6; font-size: 16px; }
#bg-respawn-btn {
  background: linear-gradient(180deg, #c0392b 0%, #7b241c 100%);
  border: 2px solid #e74c3c;
  color: #fff;
  font-size: 16px;
  font-weight: 900;
  padding: 12px 36px;
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Cinzel', sans-serif;
  letter-spacing: 1.5px;
  transition: transform 0.15s;
}
#bg-respawn-btn:hover { transform: scale(1.04); }
#bg-exit-btn-death {
  background: rgba(10,16,26,0.8);
  border: 1px solid #3a6a92;
  color: #a0b2c6;
  font-size: 13px;
  font-weight: 800;
  padding: 8px 24px;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'Cinzel', sans-serif;
}

/* Escape menu */
#bg-esc-btn {
  position: absolute;
  top: 80px;
  right: 20px;
  background: rgba(10,16,26,0.8);
  border: 1px solid rgba(212,175,55,0.4);
  color: #a0b2c6;
  font-size: 11px;
  font-weight: 800;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  pointer-events: all;
  margin-top: 90px;
}

/* ── Aim Crosshair ───────────────────────────────────────────────────── */
#bg-crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  pointer-events: none;
  z-index: 15;
}
#bg-crosshair::before,
#bg-crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255,255,255,0.9);
  border-radius: 2px;
  box-shadow: 0 0 4px rgba(0,0,0,0.8);
}
#bg-crosshair::before {
  width: 2px; height: 100%;
  left: 50%; top: 0;
  transform: translateX(-50%);
}
#bg-crosshair::after {
  width: 100%; height: 2px;
  top: 50%; left: 0;
  transform: translateY(-50%);
}
#bg-crosshair.attacking::before,
#bg-crosshair.attacking::after {
  background: #ff4444;
  box-shadow: 0 0 8px rgba(255,68,68,0.8);
}
#bg-crosshair.shielding::before,
#bg-crosshair.shielding::after {
  background: #00ccff;
  box-shadow: 0 0 8px rgba(0,204,255,0.8);
}

/* ── Thunder Charge Bar ──────────────────────────────────────────────── */
#bg-thunder-wrap {
  position: absolute;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(10,16,26,0.88);
  border: 1.5px solid rgba(0,180,255,0.5);
  border-radius: 20px;
  padding: 5px 14px;
}
#bg-thunder-track {
  width: 140px;
  height: 8px;
  background: rgba(0,0,0,0.6);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(0,180,255,0.3);
}
#bg-thunder-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #0066ff, #00ccff, #ffffaa);
  border-radius: 4px;
  transition: width 0.1s linear;
  box-shadow: 0 0 6px rgba(0,204,255,0.6);
}
#bg-thunder-fill.depleted {
  background: #333;
  box-shadow: none;
}
#bg-thunder-fill.charging {
  animation: thunderPulse 0.8s ease-in-out infinite;
}
@keyframes thunderPulse {
  0%, 100% { box-shadow: 0 0 6px rgba(0,204,255,0.6); }
  50%       { box-shadow: 0 0 14px rgba(0,204,255,1); }
}

/* ── Ability Radial Wheel Overlay ────────────────────────────────────── */
#bg-ability-wheel {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(7, 10, 15, 0.75);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  opacity: 1;
  transition: opacity 0.15s ease-out;
}
#bg-ability-wheel.hidden {
  display: none !important;
  opacity: 0;
  pointer-events: none;
}

.wheel-container {
  position: relative;
  width: 380px;
  height: 380px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wheel-center {
  position: absolute;
  width: 155px;
  height: 155px;
  background: radial-gradient(circle, rgba(20,30,48,0.95) 0%, rgba(10,16,26,0.98) 100%);
  border: 2px solid #ffd700;
  border-radius: 50%;
  box-shadow: 0 0 35px rgba(255, 215, 0, 0.4), inset 0 0 15px rgba(255, 215, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  z-index: 10;
  pointer-events: none;
}

#wheel-char-title {
  font-size: 11px;
  font-weight: 900;
  color: #00ccff;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

#wheel-ability-name {
  font-size: 14px;
  font-weight: 900;
  color: #ffd700;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
  line-height: 1.2;
}

#wheel-ability-desc {
  font-size: 9px;
  color: #a0b2c6;
  margin-top: 4px;
  line-height: 1.3;
}

.wheel-slices-wrap {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.wheel-slice {
  position: absolute;
  top: 50%; left: 50%;
  width: 72px; height: 72px;
  margin-top: -36px; margin-left: -36px;
  background: rgba(16, 26, 42, 0.92);
  border: 2px solid rgba(212, 175, 55, 0.6);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), border-color 0.2s, box-shadow 0.2s, background 0.2s;
  box-shadow: 0 4px 15px rgba(0,0,0,0.6);
}

.wheel-slice:hover, .wheel-slice.active {
  transform: var(--base-transform) scale(1.25) !important;
  border-color: #00ccff !important;
  background: radial-gradient(circle, rgba(0,204,255,0.3) 0%, rgba(10,16,26,0.95) 100%) !important;
  box-shadow: 0 0 25px rgba(0, 204, 255, 0.8), 0 0 10px #ffd700 !important;
  z-index: 20;
}

.wheel-icon {
  font-size: 26px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
}

.wheel-slice-num {
  position: absolute;
  top: -4px; right: -4px;
  background: #ffd700;
  color: #000;
  font-size: 10px;
  font-weight: 900;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── MOBILE TOUCH CONTROLS OVERLAY ────────────────────────────────── */
#mobile-controls {
  display: none;
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 90;
}

/* Touch Joystick Zone */
#mobile-joystick-zone {
  position: absolute;
  bottom: 25px; left: 25px;
  width: 150px; height: 150px;
  pointer-events: auto;
  touch-action: none;
}

#mobile-joystick-base {
  position: relative;
  width: 110px; height: 110px;
  background: rgba(10, 16, 26, 0.65);
  border: 2px solid rgba(255, 215, 0, 0.5);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 15px rgba(0,0,0,0.6);
}

#mobile-joystick-stick {
  width: 46px; height: 46px;
  background: radial-gradient(circle, #ffd700 0%, #a66e14 100%);
  border: 2px solid #fff0a5;
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(255,215,0,0.8);
  transition: transform 0.05s linear;
}

/* Mobile Button Cluster - Arc Layout */
#mobile-btn-cluster {
  position: absolute;
  bottom: 25px; right: 25px;
  display: flex;
  flex-direction: row-reverse;
  flex-wrap: wrap-reverse;
  gap: 12px;
  max-width: 280px;
  justify-content: flex-start;
  pointer-events: auto;
}

.mob-touch-btn {
  width: 62px; height: 62px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 6px 20px rgba(0,0,0,0.8), inset 0 0 10px rgba(255,255,255,0.2);
  transition: transform 0.1s ease-out, box-shadow 0.1s ease-out;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.mob-touch-btn:active {
  transform: scale(0.88);
  box-shadow: 0 2px 8px rgba(0,0,0,0.9);
}

.mob-touch-btn span {
  font-size: 8px;
  letter-spacing: 0.6px;
  margin-top: 1px;
  font-weight: 900;
  text-shadow: 0 1px 3px #000;
  font-family: 'Cinzel', sans-serif;
}

.mob-btn-red    { background: linear-gradient(180deg, #ff2a2a 0%, #990000 100%); border: 2.5px solid #ff6666; width: 76px; height: 76px; font-size: 24px; box-shadow: 0 0 25px rgba(255,0,0,0.6); }
.mob-btn-blue   { background: linear-gradient(180deg, #0088cc 0%, #004466 100%); border: 2px solid #33ccff; box-shadow: 0 0 15px rgba(0,204,255,0.4); }
.mob-btn-dash   { background: linear-gradient(180deg, #27ae60 0%, #1e8449 100%); border: 2px solid #2ecc71; box-shadow: 0 0 15px rgba(46,204,113,0.4); }
.mob-btn-jump   { background: linear-gradient(180deg, #d35400 0%, #a04000 100%); border: 2px solid #e67e22; box-shadow: 0 0 15px rgba(230,126,34,0.4); }
.mob-btn-cyan   { background: linear-gradient(180deg, #00b4d8 0%, #0077b6 100%); border: 2px solid #90e0ef; box-shadow: 0 0 15px rgba(0,180,216,0.4); }
.mob-btn-gold   { background: linear-gradient(180deg, #ffb703 0%, #fb8500 100%); border: 2px solid #ffe600; box-shadow: 0 0 18px rgba(255,183,3,0.5); }
.mob-btn-purple { background: linear-gradient(180deg, #9d4edd 0%, #5a189a 100%); border: 2px solid #c77dff; box-shadow: 0 0 15px rgba(157,78,221,0.4); }

/* Show mobile touch controls whenever platform-mobile is active (Portrait or Landscape) */
body.platform-mobile #mobile-controls {
  display: block !important;
}
body.platform-mobile #bg-controls-hint,
body.platform-mobile #bg-abilities-row {
  display: none !important;
}

/* ── RESPONSIVE MEDIA QUERIES ─────────────────────────────────────── */
@media (max-width: 960px), (max-height: 600px) {
  body.platform-mobile #mobile-controls { display: block !important; }
  #bg-controls-hint { display: none !important; }
  #bg-abilities-row { display: none !important; }

  /* Compact button cluster on horizontal landscape screens */
  #mobile-btn-cluster {
    bottom: 15px !important;
    right: 15px !important;
    max-width: 320px !important;
    gap: 8px !important;
  }
  .mob-touch-btn {
    width: 52px !important;
    height: 52px !important;
    font-size: 16px !important;
  }
  .mob-btn-red {
    width: 64px !important;
    height: 64px !important;
    font-size: 20px !important;
  }

  /* Scale radial wheel on mobile */
  .wheel-container { width: 290px; height: 290px; }
  .wheel-center { width: 120px; height: 120px; padding: 6px; }
  #wheel-char-title { font-size: 9px; }
  #wheel-ability-name { font-size: 11px; }
  #wheel-ability-desc { font-size: 8px; }
  .wheel-slice { width: 56px; height: 56px; margin-top: -28px; margin-left: -28px; }
  .wheel-icon { font-size: 20px; }

  /* Selection cards on mobile */
  .bg-char-cards-wrap { flex-direction: column; gap: 10px; max-height: 50vh; overflow-y: auto; }
  .bg-char-card { width: 260px; padding: 12px; }
}


