/* =====================
   Unit Portrait Grid View
   Compact icon-based view for units
   ===================== */

.view-toggle-button {
  position: absolute;
  top: 16px;
  right: 150px;
  cursor: pointer;
  padding: 6px 8px;
  background: linear-gradient(135deg, rgba(0, 217, 255, 0.15) 0%, rgba(0, 150, 200, 0.1) 100%);
  border: 2px solid rgba(0, 217, 255, 0.4);
  border-radius: 6px;
  color: #00d9ff;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  z-index: 100;
}

.view-toggle-button:hover {
  background: linear-gradient(135deg, rgba(0, 217, 255, 0.3) 0%, rgba(0, 150, 200, 0.2) 100%);
  border-color: rgba(0, 217, 255, 0.7);
  transform: translateY(-2px);
  box-shadow: 0 0 20px rgba(0, 217, 255, 0.6), 0 4px 16px rgba(0, 0, 0, 0.5);
}

.view-toggle-button svg {
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.6));
  flex-shrink: 0;
}

body.light-theme .view-toggle-button {
  background: linear-gradient(135deg, rgba(0, 150, 200, 0.2) 0%, rgba(0, 100, 150, 0.15) 100%);
  border-color: rgba(0, 150, 200, 0.5);
  color: #006b96;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

body.light-theme .view-toggle-button:hover {
  background: linear-gradient(135deg, rgba(0, 150, 200, 0.35) 0%, rgba(0, 100, 150, 0.25) 100%);
  border-color: rgba(0, 150, 200, 0.7);
  box-shadow: 0 0 16px rgba(0, 150, 200, 0.5), 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* View toggle positioning for team games */
.team-player-block > .view-toggle-button {
  top: 12px;
  right: 12px;
}

.unit-portraits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  margin-top: 8px;
}

/* Unit Card - Hero-style layout */
.unit-card {
  background: linear-gradient(135deg, rgba(20, 30, 45, 0.85) 0%, rgba(15, 25, 40, 0.9) 100%);
  border: 1.5px solid rgba(0, 217, 255, 0.25);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
  min-height: 140px;
  height: 100%;
  justify-content: space-between;
}

.unit-card:hover {
  border-color: rgba(0, 217, 255, 0.5);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5), 0 0 16px rgba(0, 217, 255, 0.25);
}

.unit-card-portrait {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  overflow: visible;
  border: 1.5px solid rgba(0, 217, 255, 0.3);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.unit-card-portrait::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 6px;
  overflow: hidden;
  z-index: 1;
}

.unit-card-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 6px;
  position: relative;
  z-index: 1;
}

.unit-card-count {
  position: absolute;
  bottom: -6px;
  right: -6px;
  background: radial-gradient(circle at 35% 35%, rgba(60, 100, 140, 0.9) 0%, rgba(30, 60, 90, 0.95) 50%, rgba(15, 35, 55, 1) 100%);
  color: #ffffff;
  font-weight: 900;
  font-size: 0.9rem;
  min-width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid rgba(20, 40, 60, 0.9);
  box-shadow: 
    0 0 0 1.5px rgba(100, 160, 200, 0.6),
    0 2px 6px rgba(0, 0, 0, 0.7),
    inset 0 3px 6px rgba(255, 255, 255, 0.3),
    inset 0 -4px 8px rgba(0, 0, 0, 0.5);
  text-shadow: 
    0 1px 0 rgba(255, 255, 255, 0.3),
    0 -1px 0 rgba(0, 0, 0, 0.8),
    0 2px 4px rgba(0, 0, 0, 0.9),
    0 0 8px rgba(120, 180, 220, 0.4);
  font-family: 'Cinzel', serif;
  letter-spacing: 0.5px;
  padding: 0 4px;
  z-index: 10;
}

.unit-card-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  flex: 1;
  justify-content: flex-start;
}

.unit-card-resources {
  display: flex;
  gap: 1px;
  justify-content: center;
  align-items: center;
  width: 100%;
  flex-wrap: nowrap;
}

.unit-card-name {
  color: rgba(255, 255, 255, 0.95);
  font-family: 'Cinzel', serif;
  font-size: 0.7rem;
  font-weight: 600;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8), 0 0 8px rgba(0, 0, 0, 0.4);
  letter-spacing: 0.3px;
  line-height: 1.1;
  width: 100%;
  min-height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.unit-resource-badge {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 1px 3px;
  border-radius: 8px;
  font-size: 0.5rem;
  font-weight: 600;
  line-height: 1;
  background: rgba(20, 30, 50, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
}

.unit-resource-badge .resource-icon {
  font-size: 0.6rem;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
  flex-shrink: 0;
  line-height: 1;
}

.unit-resource-badge.gold {
  background: linear-gradient(135deg, rgba(60, 50, 30, 0.7) 0%, rgba(80, 65, 40, 0.75) 100%);
  color: rgba(255, 223, 130, 0.95);
  border-color: rgba(255, 215, 0, 0.25);
}

.unit-resource-badge.wood {
  background: linear-gradient(135deg, rgba(20, 45, 30, 0.7) 0%, rgba(30, 60, 40, 0.75) 100%);
  color: rgba(150, 230, 170, 0.95);
  border-color: rgba(124, 255, 157, 0.25);
}

.unit-resource-badge.food {
  background: linear-gradient(135deg, rgba(90, 50, 30, 0.7) 0%, rgba(110, 65, 40, 0.75) 100%);
  color: rgba(210, 150, 100, 0.95);
  border-color: rgba(160, 100, 60, 0.35);
}

/* Hide resources when cost toggle is off */
.unit-card-resources.cost-hidden {
  display: none;
}

/* Unit card totals section */
.unit-card-totals {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 0 2px;
  margin-top: 2px;
}

.unit-card-total {
  display: flex;
  align-items: center;
  gap: 3px;
  width: 100%;
  font-size: 0.65rem;
  font-weight: 600;
}

.unit-card-total .total-value {
  min-width: 28px;
  text-align: right;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  flex-shrink: 0;
}

.unit-card-total .total-bar {
  flex: 1;
  height: 8px;
  background: rgba(20, 30, 50, 0.6);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

.unit-card-total .total-bar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--bar-width, 0%);
  border-radius: 2px;
  transition: width 0.4s ease;
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 0 4px currentColor;
}

.unit-card-total.gold .total-value {
  color: rgba(255, 223, 130, 0.95);
}

.unit-card-total.gold .total-bar::before {
  background: linear-gradient(90deg, 
    rgba(255, 215, 0, 0.8) 0%, 
    rgba(255, 223, 130, 0.9) 50%,
    rgba(255, 215, 0, 0.8) 100%);
  color: rgba(255, 215, 0, 0.6);
}

.unit-card-total.wood .total-value {
  color: rgba(150, 230, 170, 0.95);
}

.unit-card-total.wood .total-bar::before {
  background: linear-gradient(90deg, 
    rgba(124, 255, 157, 0.8) 0%, 
    rgba(150, 230, 170, 0.9) 50%,
    rgba(124, 255, 157, 0.8) 100%);
  color: rgba(124, 255, 157, 0.6);
}

.unit-card-total.food .total-value {
  color: rgba(210, 150, 100, 0.95);
}

.unit-card-total.food .total-bar::before {
  background: linear-gradient(90deg, 
    rgba(160, 100, 60, 0.8) 0%, 
    rgba(180, 120, 75, 0.9) 50%,
    rgba(160, 100, 60, 0.8) 100%);
  color: rgba(160, 100, 60, 0.6);
}

/* Hide totals when resource columns are toggled off */
.resource-columns-hidden .unit-card-totals {
  display: none;
}

/* Grid summary header */
.grid-summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  margin-top: 16px;
  background: rgba(15, 25, 40, 0.5);
  border-left: 3px solid rgba(0, 217, 255, 0.6);
  border-radius: 4px;
}

.grid-summary-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.grid-summary-label {
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.6);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.grid-summary-value {
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.grid-summary-resources {
  display: flex;
  gap: 20px;
}

.grid-summary-icon {
  font-size: 0.9rem;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.grid-summary-item.gold .grid-summary-value {
  color: rgba(255, 223, 130, 0.95);
}

.grid-summary-item.wood .grid-summary-value {
  color: rgba(150, 230, 170, 0.95);
}

.grid-summary-item.food .grid-summary-value {
  color: rgba(210, 150, 100, 0.95);
}

/* Hide resource items when toggle is off */
.resource-columns-hidden .grid-summary-resources {
  display: none;
}

/* Race-specific summary header styling */
.grid-summary-header.human {
  border-left-color: rgba(255, 215, 0, 0.7);
  background: rgba(40, 35, 20, 0.4);
}

.grid-summary-header.human .grid-summary-label {
  color: rgba(255, 215, 0, 0.7);
}

.grid-summary-header.orc {
  border-left-color: rgba(244, 67, 54, 0.7);
  background: rgba(40, 20, 20, 0.4);
}

.grid-summary-header.orc .grid-summary-label {
  color: rgba(244, 67, 54, 0.7);
}

.grid-summary-header.undead {
  border-left-color: rgba(96, 125, 139, 0.7);
  background: rgba(20, 30, 35, 0.4);
}

.grid-summary-header.undead .grid-summary-label {
  color: rgba(96, 125, 139, 0.7);
}

.grid-summary-header.nightelf {
  border-left-color: rgba(156, 39, 176, 0.7);
  background: rgba(35, 20, 40, 0.4);
}

.grid-summary-header.nightelf .grid-summary-label {
  color: rgba(156, 39, 176, 0.7);
}

/* Totals summary card */
.unit-card.totals-card {
  background: linear-gradient(135deg, rgba(30, 45, 65, 0.95) 0%, rgba(20, 35, 55, 0.98) 100%);
  border: 2px solid rgba(0, 217, 255, 0.4);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.6),
    0 0 20px rgba(0, 217, 255, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  min-height: auto;
  padding: 8px;
}

.unit-card.totals-card:hover {
  transform: translateY(-2px);
  border-color: rgba(0, 217, 255, 0.6);
  box-shadow: 
    0 6px 20px rgba(0, 0, 0, 0.7),
    0 0 24px rgba(0, 217, 255, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.totals-card-header {
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  color: rgba(0, 217, 255, 0.95);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 8px;
  text-shadow: 
    0 0 8px rgba(0, 217, 255, 0.6),
    0 2px 4px rgba(0, 0, 0, 0.8);
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(0, 217, 255, 0.3);
}

.totals-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.totals-card-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 6px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.totals-card-label {
  font-family: 'Cinzel', serif;
  font-size: 0.7rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.totals-card-icon {
  font-size: 0.9rem;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}

.totals-card-value {
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.totals-card-stat.gold .totals-card-value {
  color: rgba(255, 223, 130, 0.95);
}

.totals-card-stat.wood .totals-card-value {
  color: rgba(150, 230, 170, 0.95);
}

.totals-card-stat.food .totals-card-value {
  color: rgba(255, 210, 160, 0.95);
}

.totals-card-divider {
  height: 1px;
  background: linear-gradient(90deg, 
    transparent 0%, 
    rgba(0, 217, 255, 0.3) 50%, 
    transparent 100%);
  margin: 2px 0;
}

/* Race-specific totals card styling */
.unit-card.totals-card.human {
  border-color: rgba(255, 215, 0, 0.5);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.6),
    0 0 20px rgba(255, 215, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.unit-card.totals-card.human:hover {
  border-color: rgba(255, 215, 0, 0.7);
  box-shadow: 
    0 6px 20px rgba(0, 0, 0, 0.7),
    0 0 24px rgba(255, 215, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.unit-card.totals-card.human .totals-card-header {
  color: rgba(255, 215, 0, 0.95);
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.6), 0 2px 4px rgba(0, 0, 0, 0.8);
  border-bottom-color: rgba(255, 215, 0, 0.3);
}

.unit-card.totals-card.orc {
  border-color: rgba(244, 67, 54, 0.5);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.6),
    0 0 20px rgba(244, 67, 54, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.unit-card.totals-card.orc:hover {
  border-color: rgba(244, 67, 54, 0.7);
  box-shadow: 
    0 6px 20px rgba(0, 0, 0, 0.7),
    0 0 24px rgba(244, 67, 54, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.unit-card.totals-card.orc .totals-card-header {
  color: rgba(244, 67, 54, 0.95);
  text-shadow: 0 0 8px rgba(244, 67, 54, 0.6), 0 2px 4px rgba(0, 0, 0, 0.8);
  border-bottom-color: rgba(244, 67, 54, 0.3);
}

.unit-card.totals-card.undead {
  border-color: rgba(96, 125, 139, 0.5);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.6),
    0 0 20px rgba(96, 125, 139, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.unit-card.totals-card.undead:hover {
  border-color: rgba(96, 125, 139, 0.7);
  box-shadow: 
    0 6px 20px rgba(0, 0, 0, 0.7),
    0 0 24px rgba(96, 125, 139, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.unit-card.totals-card.undead .totals-card-header {
  color: rgba(96, 125, 139, 0.95);
  text-shadow: 0 0 8px rgba(96, 125, 139, 0.6), 0 2px 4px rgba(0, 0, 0, 0.8);
  border-bottom-color: rgba(96, 125, 139, 0.3);
}

.unit-card.totals-card.nightelf {
  border-color: rgba(156, 39, 176, 0.5);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.6),
    0 0 20px rgba(156, 39, 176, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.unit-card.totals-card.nightelf:hover {
  border-color: rgba(156, 39, 176, 0.7);
  box-shadow: 
    0 6px 20px rgba(0, 0, 0, 0.7),
    0 0 24px rgba(156, 39, 176, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.unit-card.totals-card.nightelf .totals-card-header {
  color: rgba(156, 39, 176, 0.95);
  text-shadow: 0 0 8px rgba(156, 39, 176, 0.6), 0 2px 4px rgba(0, 0, 0, 0.8);
  border-bottom-color: rgba(156, 39, 176, 0.3);
}

/* Race-specific card borders */
.unit-card.human .unit-card-portrait { border-color: rgba(255, 215, 0, 0.5); }
.unit-card.orc .unit-card-portrait { border-color: rgba(244, 67, 54, 0.5); }
.unit-card.undead .unit-card-portrait { border-color: rgba(96, 125, 139, 0.5); }
.unit-card.nightelf .unit-card-portrait { border-color: rgba(156, 39, 176, 0.5); }

.unit-card.human:hover .unit-card-portrait { border-color: rgba(255, 215, 0, 0.8); }
.unit-card.orc:hover .unit-card-portrait { border-color: rgba(244, 67, 54, 0.8); }
.unit-card.undead:hover .unit-card-portrait { border-color: rgba(96, 125, 139, 0.8); }
.unit-card.nightelf:hover .unit-card-portrait { border-color: rgba(156, 39, 176, 0.8); }

/* Light theme adjustments */
body.light-theme .unit-card {
  background: linear-gradient(135deg, rgba(245, 250, 255, 0.95) 0%, rgba(235, 245, 255, 0.98) 100%);
  border-color: rgba(0, 150, 200, 0.3);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

body.light-theme .unit-card:hover {
  border-color: rgba(0, 150, 200, 0.6);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2), 0 0 16px rgba(0, 150, 200, 0.2);
}

/* Race-specific backgrounds for unit cards */
body.light-theme .unit-card.human {
  background: linear-gradient(135deg, rgba(255, 237, 185, 0.96) 0%, rgba(255, 245, 212, 0.99) 55%, rgba(255, 250, 228, 0.98) 100%);
  border-color: rgba(200, 160, 0, 0.45);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16), 0 0 18px rgba(200, 160, 0, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

body.light-theme .unit-card.orc {
  background: linear-gradient(135deg, rgba(255, 220, 210, 0.96) 0%, rgba(255, 237, 232, 0.99) 55%, rgba(255, 246, 244, 0.98) 100%);
  border-color: rgba(200, 50, 40, 0.45);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16), 0 0 18px rgba(200, 50, 40, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

body.light-theme .unit-card.undead {
  background: linear-gradient(135deg, rgba(178, 223, 230, 0.96) 0%, rgba(200, 235, 240, 0.99) 55%, rgba(220, 245, 248, 0.98) 100%);
  border-color: rgba(0, 120, 130, 0.5);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16), 0 0 18px rgba(0, 130, 140, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

body.light-theme .unit-card.nightelf {
  background: linear-gradient(135deg, rgba(235, 214, 246, 0.96) 0%, rgba(245, 232, 252, 0.99) 55%, rgba(252, 246, 255, 0.98) 100%);
  border-color: rgba(130, 30, 150, 0.45);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16), 0 0 18px rgba(130, 30, 150, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

body.light-theme .unit-card-name {
  color: rgba(0, 0, 0, 0.9);
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

body.light-theme .unit-card-footer {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.62) 0%, rgba(255, 255, 255, 0.38) 100%);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 6px;
  padding: 4px 4px 5px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92), inset 0 -10px 14px rgba(0, 0, 0, 0.05);
}

body.light-theme .unit-card.human .unit-card-footer {
  background: linear-gradient(180deg, rgba(255, 210, 100, 0.52) 0%, rgba(255, 243, 200, 0.30) 100%);
  border-color: rgba(200, 160, 0, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92), inset 0 -12px 16px rgba(200, 160, 0, 0.12);
}

body.light-theme .unit-card.orc .unit-card-footer {
  background: linear-gradient(180deg, rgba(244, 67, 54, 0.24) 0%, rgba(255, 232, 225, 0.30) 100%);
  border-color: rgba(200, 50, 40, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92), inset 0 -12px 16px rgba(200, 50, 40, 0.12);
}

body.light-theme .unit-card.undead .unit-card-footer {
  background: linear-gradient(180deg, rgba(0, 150, 160, 0.28) 0%, rgba(200, 235, 240, 0.35) 100%);
  border-color: rgba(0, 120, 130, 0.28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92), inset 0 -12px 16px rgba(0, 130, 140, 0.15);
}

body.light-theme .unit-card.nightelf .unit-card-footer {
  background: linear-gradient(180deg, rgba(156, 39, 176, 0.22) 0%, rgba(245, 235, 250, 0.30) 100%);
  border-color: rgba(130, 30, 150, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92), inset 0 -12px 16px rgba(130, 30, 150, 0.12);
}

body.light-theme .unit-resource-badge {
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(0, 0, 0, 0.15);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  text-shadow: 0 0 2px rgba(255, 255, 255, 0.8);
}

body.light-theme .unit-resource-badge .resource-icon {
  filter: drop-shadow(0 1px 1px rgba(255, 255, 255, 0.5));
}

body.light-theme .unit-resource-badge.gold {
  background: linear-gradient(135deg, rgba(255, 243, 200, 0.95) 0%, rgba(255, 235, 180, 1) 100%);
  color: rgb(60, 45, 5);
  border-color: rgba(200, 160, 50, 0.5);
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.9), 0 1px 2px rgba(255, 255, 255, 0.5);
  font-weight: 700;
}

body.light-theme .unit-resource-badge.wood {
  background: linear-gradient(135deg, rgba(220, 250, 230, 0.95) 0%, rgba(200, 245, 215, 1) 100%);
  color: rgb(10, 55, 25);
  border-color: rgba(80, 180, 100, 0.5);
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.9), 0 1px 2px rgba(255, 255, 255, 0.5);
  font-weight: 700;
}

body.light-theme .unit-resource-badge.food {
  background: linear-gradient(135deg, rgba(255, 240, 220, 0.95) 0%, rgba(255, 230, 200, 1) 100%);
  color: rgb(60, 30, 5);
  border-color: rgba(200, 140, 80, 0.5);
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.9), 0 1px 2px rgba(255, 255, 255, 0.5);
  font-weight: 700;
}

body.light-theme .unit-card-total .total-bar {
  background: rgba(220, 230, 240, 0.8);
  border-color: rgba(0, 0, 0, 0.15);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

body.light-theme .unit-card-total.gold .total-value {
  color: rgb(80, 60, 10);
}

body.light-theme .unit-card-total.gold .total-bar::before {
  background: linear-gradient(90deg, 
    rgba(180, 140, 0, 0.95) 0%, 
    rgba(200, 160, 20, 1) 50%,
    rgba(180, 140, 0, 0.95) 100%);
}

body.light-theme .unit-card-total.wood .total-value {
  color: rgb(15, 70, 35);
}

body.light-theme .unit-card-total.wood .total-bar::before {
  background: linear-gradient(90deg, 
    rgba(30, 120, 50, 0.95) 0%, 
    rgba(40, 140, 65, 1) 50%,
    rgba(30, 120, 50, 0.95) 100%);
}

body.light-theme .unit-card-total.food .total-value {
  color: rgb(75, 40, 10);
}

body.light-theme .unit-card-total.food .total-bar::before {
  background: linear-gradient(90deg, 
    rgba(140, 80, 30, 0.95) 0%, 
    rgba(160, 95, 40, 1) 50%,
    rgba(140, 80, 30, 0.95) 100%);
}

/* Light theme totals card */
body.light-theme .unit-card.totals-card {
  background: linear-gradient(135deg, rgba(250, 252, 255, 0.98) 0%, rgba(240, 245, 252, 1) 100%);
  border: 2px solid rgba(0, 150, 200, 0.4);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.2),
    0 0 20px rgba(0, 150, 200, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

body.light-theme .unit-card.totals-card:hover {
  border-color: rgba(0, 150, 200, 0.6);
  box-shadow: 
    0 6px 20px rgba(0, 0, 0, 0.25),
    0 0 24px rgba(0, 150, 200, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

body.light-theme .totals-card-header {
  color: rgba(0, 120, 180, 0.95);
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
  border-bottom-color: rgba(0, 150, 200, 0.3);
}

body.light-theme .totals-card-stat {
  background: rgba(255, 255, 255, 0.6);
  border-color: rgba(0, 0, 0, 0.08);
}

body.light-theme .totals-card-label {
  color: rgba(0, 0, 0, 0.7);
}

body.light-theme .totals-card-value {
  color: rgba(0, 0, 0, 0.9);
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.6);
}

body.light-theme .totals-card-stat.gold .totals-card-value {
  color: rgb(80, 60, 10);
}

body.light-theme .totals-card-stat.wood .totals-card-value {
  color: rgb(15, 70, 35);
}

body.light-theme .totals-card-stat.food .totals-card-value {
  color: rgb(75, 40, 10);
}

body.light-theme .totals-card-divider {
  background: linear-gradient(90deg, 
    transparent 0%, 
    rgba(0, 150, 200, 0.2) 50%, 
    transparent 100%);
}

/* Light theme grid summary header */
body.light-theme .grid-summary-header {
  background: rgba(30, 50, 70, 0.85);
  border-left-color: rgba(0, 180, 230, 0.8);
  border-left-width: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

body.light-theme .grid-summary-label {
  color: rgba(255, 255, 255, 0.85);
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

body.light-theme .grid-summary-value {
  color: rgba(255, 255, 255, 0.98);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

body.light-theme .grid-summary-item.gold .grid-summary-value {
  color: rgb(255, 220, 100);
}

body.light-theme .grid-summary-item.wood .grid-summary-value {
  color: rgb(130, 230, 150);
}

body.light-theme .grid-summary-item.food .grid-summary-value {
  color: rgb(230, 170, 120);
}

body.light-theme .grid-summary-header.human {
  border-left-color: rgba(255, 215, 0, 0.9);
  background: linear-gradient(135deg, rgba(70, 55, 20, 0.92) 0%, rgba(50, 40, 15, 0.95) 100%);
}

body.light-theme .grid-summary-header.human .grid-summary-label {
  color: rgba(255, 215, 0, 0.95);
}

body.light-theme .grid-summary-header.orc {
  border-left-color: rgba(244, 67, 54, 0.9);
  background: linear-gradient(135deg, rgba(70, 25, 20, 0.92) 0%, rgba(50, 18, 15, 0.95) 100%);
}

body.light-theme .grid-summary-header.orc .grid-summary-label {
  color: rgba(255, 100, 90, 0.95);
}

body.light-theme .grid-summary-header.undead {
  border-left-color: rgba(0, 230, 210, 0.9);
  background: linear-gradient(135deg, rgba(25, 45, 55, 0.92) 0%, rgba(18, 35, 42, 0.95) 100%);
}

body.light-theme .grid-summary-header.undead .grid-summary-label {
  color: rgba(100, 220, 210, 0.95);
}

body.light-theme .grid-summary-header.nightelf {
  border-left-color: rgba(180, 100, 210, 0.9);
  background: linear-gradient(135deg, rgba(55, 25, 65, 0.92) 0%, rgba(40, 18, 50, 0.95) 100%);
}

body.light-theme .grid-summary-header.nightelf .grid-summary-label {
  color: rgba(200, 150, 230, 0.95);
}

/* Light theme race-specific totals cards */
body.light-theme .unit-card.totals-card.human {
  border-color: rgba(200, 160, 0, 0.5);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.2),
    0 0 20px rgba(200, 160, 0, 0.1);
}

body.light-theme .unit-card.totals-card.human .totals-card-header {
  color: rgba(150, 120, 0, 0.95);
  border-bottom-color: rgba(200, 160, 0, 0.3);
}

body.light-theme .unit-card.totals-card.orc {
  border-color: rgba(200, 50, 40, 0.5);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.2),
    0 0 20px rgba(200, 50, 40, 0.1);
}

body.light-theme .unit-card.totals-card.orc .totals-card-header {
  color: rgba(180, 40, 30, 0.95);
  border-bottom-color: rgba(200, 50, 40, 0.3);
}

body.light-theme .unit-card.totals-card.undead {
  border-color: rgba(0, 120, 130, 0.5);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.2),
    0 0 20px rgba(0, 130, 140, 0.15);
}

body.light-theme .unit-card.totals-card.undead .totals-card-header {
  color: rgba(0, 100, 110, 0.95);
  border-bottom-color: rgba(0, 120, 130, 0.3);
}

body.light-theme .unit-card.totals-card.nightelf {
  border-color: rgba(120, 30, 140, 0.5);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.2),
    0 0 20px rgba(120, 30, 140, 0.1);
}

body.light-theme .unit-card.totals-card.nightelf .totals-card-header {
  color: rgba(110, 25, 130, 0.95);
  border-bottom-color: rgba(120, 30, 140, 0.3);
}

/* Legacy styles - keep for backwards compatibility but hide */
.unit-portrait-item {
  display: none;
}

.unit-portrait-wrapper {
  display: none;
}

.unit-portrait-cost-bubbles {
  display: none;
}

.unit-portrait-icon {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 2px solid rgba(0, 217, 255, 0.3);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: all 0.3s ease;
  position: relative;
}

.unit-portrait-item:hover .unit-portrait-icon {
  border-color: rgba(0, 217, 255, 0.5);
  box-shadow: 0 0 8px rgba(0, 217, 255, 0.3);
}

/* Race-specific borders */
.unit-portrait-icon.human {
  border-color: rgba(255, 215, 0, 0.6);
}

.unit-portrait-icon.orc {
  border-color: rgba(244, 67, 54, 0.6);
}

.unit-portrait-icon.undead {
  border-color: rgba(96, 125, 139, 0.6);
}

.unit-portrait-icon.nightelf {
  border-color: rgba(156, 39, 176, 0.6);
}

.unit-portrait-item:hover .unit-portrait-icon.human {
  border-color: rgba(255, 215, 0, 0.8);
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

.unit-portrait-item:hover .unit-portrait-icon.orc {
  border-color: rgba(244, 67, 54, 0.8);
  box-shadow: 0 0 10px rgba(244, 67, 54, 0.4);
}

.unit-portrait-item:hover .unit-portrait-icon.undead {
  border-color: rgba(96, 125, 139, 0.8);
  box-shadow: 0 0 10px rgba(96, 125, 139, 0.4);
}

.unit-portrait-item:hover .unit-portrait-icon.nightelf {
  border-color: rgba(156, 39, 176, 0.8);
  box-shadow: 0 0 10px rgba(156, 39, 176, 0.4);
}

/* Preserve race colors on hover */
.unit-portrait-item.human:hover .unit-portrait-count,
.unit-portrait-item.orc:hover .unit-portrait-count,
.unit-portrait-item.nightelf:hover .unit-portrait-count,
.unit-portrait-item.undead:hover .unit-portrait-count {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.unit-portrait-count {
  position: absolute;
  bottom: -3px;
  right: -3px;
  background: radial-gradient(60% 60% at 50% 50%, #0f3050 0%, #0b2035 65%, #081728 100%);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.85rem;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2.2px solid rgba(10, 18, 35, 0.95);
  box-shadow: 
    0 0 0 1.1px rgba(0, 153, 204, 0.3),
    0 4px 10px rgba(0, 0, 0, 0.55),
    inset 0 8px 12px rgba(255, 255, 255, 0.16),
    inset 0 -10px 16px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  text-shadow: 
    0 1px 2px rgba(0, 0, 0, 0.65),
    0 0 8px rgba(0, 153, 204, 0.6);
  transition: all 0.3s ease;
  font-family: 'Orbitron', 'Inter', sans-serif;
  letter-spacing: -0.2px;
  overflow: hidden;
  background-size: 150% 150%;
  will-change: transform, background-position;
  z-index: 4;
}

/* Animated background effects for count badges - matching hero styling */
.unit-portrait-count::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -2;
  opacity: 0.9;
  border-radius: 50%;
}

.unit-portrait-count::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
  border-radius: 50%;
  opacity: 0.82;
}

/* Human: Arcane energy patterns */
.unit-portrait-item.human .unit-portrait-count {
  background: radial-gradient(55% 55% at 50% 50%, #ffe066 0%, #ffd700 50%, transparent 75%),
              linear-gradient(125deg, #ffe066 0%, #ffd700 50%, #bfa100 100%) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 0 2px #6a5a0a99 inset, inset 0 0 10px rgba(191, 161, 0, 0.25);
  border: 1.5px solid #6a5a0a;
  filter: none;
  color: #fffbe6 !important;
  text-shadow: 0 1px 4px #6a5a0a, 0 0 2px #000, 0 0 1px #ffd700;
}

.unit-portrait-item.human .unit-portrait-count::before {
  background: radial-gradient(50% 50% at 45% 45%, rgba(0, 0, 0, 0.38) 0%, rgba(0, 0, 0, 0.24) 28%, rgba(255, 215, 0, 0.22) 58%, transparent 82%);
  background-size: 220% 220%;
  opacity: 0.82;
  animation: human-smoke 9s ease-in-out infinite alternate, badge-arcane-pulse 5s ease-in-out infinite;
}

.unit-portrait-item.human .unit-portrait-count::after {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0.18) 26%, rgba(255, 255, 255, 0.05) 42%, transparent 58%),
    radial-gradient(125% 125% at 28% 22%, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0.08) 40%, transparent 58%),
    conic-gradient(from -35deg, rgba(255, 255, 255, 0.28) 0deg, rgba(255, 255, 255, 0.08) 24deg, transparent 46deg, transparent 320deg, rgba(255, 255, 255, 0.18) 342deg, rgba(255, 255, 255, 0.32) 360deg),
    conic-gradient(from 0deg, rgba(255, 224, 102, 0.6), rgba(255, 215, 0, 0.15) 25%, transparent 45%, rgba(255, 215, 0, 0.35) 65%, rgba(255, 224, 102, 0.55) 85%, transparent);
  background-blend-mode: screen, screen, screen, normal;
  opacity: 0.8;
  animation: badge-conic-rotate 9s linear infinite;
}

/* Orc: Fire patterns */
.unit-portrait-item.orc .unit-portrait-count {
  background: radial-gradient(55% 55% at 50% 50%, #ffb347 0%, #ff512f 48%, transparent 72%),
              linear-gradient(125deg, #ffb347 0%, #ff512f 55%, #7c1d00 100%) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 0 2px #7c1d00aa inset, inset 0 0 10px rgba(255, 81, 47, 0.22);
  border: 1.5px solid #7c1d00;
  filter: none;
  color: #fff8f0 !important;
  text-shadow: 0 1px 4px #7c1d00, 0 0 2px #000, 0 0 1px #ffb347;
}

.unit-portrait-item.orc .unit-portrait-count::before {
  background: radial-gradient(circle at 50% 50%, rgba(255, 179, 71, 0.5) 0%, rgba(255, 81, 47, 0.35) 40%, transparent 75%);
  animation: badge-fire-burst 4s ease-in-out infinite;
}

.unit-portrait-item.orc .unit-portrait-count::after {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.32) 0%, rgba(255, 255, 255, 0.16) 26%, rgba(255, 255, 255, 0.05) 42%, transparent 58%),
    radial-gradient(125% 125% at 28% 22%, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0.08) 40%, transparent 58%),
    conic-gradient(from -35deg, rgba(255, 255, 255, 0.22) 0deg, rgba(255, 255, 255, 0.08) 24deg, transparent 46deg, transparent 320deg, rgba(255, 255, 255, 0.14) 342deg, rgba(255, 255, 255, 0.24) 360deg),
    conic-gradient(from 0deg, rgba(255, 179, 71, 0.55), rgba(255, 81, 47, 0.2) 25%, transparent 45%, rgba(255, 81, 47, 0.35) 65%, rgba(255, 179, 71, 0.5) 85%, transparent);
  background-blend-mode: screen, screen, screen, normal;
  opacity: 0.72;
  animation: badge-conic-rotate 8.5s linear infinite;
}

/* Night Elf: Wisp patterns */
.unit-portrait-item.nightelf .unit-portrait-count {
  background: radial-gradient(55% 55% at 50% 50%, #7c4dff 0%, #4e2fae 55%, transparent 74%),
              linear-gradient(125deg, #7c4dff 0%, #4e2fae 55%, #00e6d8 100%) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 0 2px #24134caa inset, inset 0 0 10px rgba(124, 77, 255, 0.24);
  border: 1.5px solid #24134c;
  filter: none;
  color: #b794ff !important;
  text-shadow: 0 1px 4px #24134c, 0 0 2px #000, 0 0 1px #7c4dff, 0 0 8px #7c4dff;
}

.unit-portrait-item.nightelf .unit-portrait-count::before {
  background: radial-gradient(circle at 50% 50%, rgba(124, 77, 255, 0.5) 0%, rgba(78, 47, 174, 0.35) 40%, rgba(0, 230, 216, 0.2) 65%, transparent 85%);
  animation: badge-wisp-pulse 4.8s ease-in-out infinite;
}

.unit-portrait-item.nightelf .unit-portrait-count::after {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.36) 0%, rgba(255, 255, 255, 0.18) 26%, rgba(255, 255, 255, 0.06) 42%, transparent 58%),
    radial-gradient(125% 125% at 28% 22%, rgba(255, 255, 255, 0.38) 0%, rgba(255, 255, 255, 0.1) 40%, transparent 58%),
    conic-gradient(from -35deg, rgba(255, 255, 255, 0.26) 0deg, rgba(255, 255, 255, 0.1) 24deg, transparent 46deg, transparent 320deg, rgba(255, 255, 255, 0.16) 342deg, rgba(255, 255, 255, 0.26) 360deg),
    conic-gradient(from 0deg, rgba(124, 77, 255, 0.55), rgba(78, 47, 174, 0.2) 25%, transparent 45%, rgba(0, 230, 216, 0.2) 65%, rgba(124, 77, 255, 0.5) 85%, transparent);
  background-blend-mode: screen, screen, screen, normal;
  opacity: 0.8;
  transform: scale(1.05);
  filter: drop-shadow(0 0 8px #7c4dff77);
  animation: badge-conic-rotate 9.2s linear infinite;
}

/* Undead: Soul mist patterns */
.unit-portrait-item.undead .unit-portrait-count {
  background: radial-gradient(55% 55% at 50% 50%, #b0bec5 0%, #607d8b 52%, transparent 74%),
              linear-gradient(125deg, #b0bec5 0%, #607d8b 55%, #00ffe7 100%) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 0 2px #1f2b32aa inset, inset 0 0 10px rgba(0, 255, 231, 0.2);
  border: 1.5px solid #1f2b32;
  filter: none;
  color: #e9faff !important;
  text-shadow: 0 1px 4px #1f2b32, 0 0 2px #000, 0 0 1px #00ffe7;
}

.unit-portrait-item.undead .unit-portrait-count::before {
  background: radial-gradient(circle at 50% 50%, rgba(176, 190, 197, 0.5) 0%, rgba(96, 125, 139, 0.35) 40%, rgba(0, 255, 231, 0.2) 65%, transparent 85%);
  animation: badge-soul-pulse 5.2s ease-in-out infinite;
}

.unit-portrait-item.undead .unit-portrait-count::after {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.34) 0%, rgba(255, 255, 255, 0.16) 26%, rgba(255, 255, 255, 0.05) 42%, transparent 58%),
    radial-gradient(125% 125% at 28% 22%, rgba(255, 255, 255, 0.32) 0%, rgba(255, 255, 255, 0.08) 40%, transparent 58%),
    conic-gradient(from -35deg, rgba(255, 255, 255, 0.24) 0deg, rgba(255, 255, 255, 0.08) 24deg, transparent 46deg, transparent 320deg, rgba(255, 255, 255, 0.14) 342deg, rgba(255, 255, 255, 0.24) 360deg),
    conic-gradient(from 0deg, rgba(0, 255, 231, 0.5), rgba(96, 125, 139, 0.2) 25%, transparent 45%, rgba(0, 255, 231, 0.25) 65%, rgba(176, 190, 197, 0.4) 85%, transparent);
  background-blend-mode: screen, screen, screen, normal;
  opacity: 0.78;
  animation: badge-conic-rotate 9.6s linear infinite;
}

/* Randomized delays to desync orb effects per slot */
.unit-portraits-grid .unit-portrait-item:nth-child(4n+1) .unit-portrait-count::before { animation-delay: -0.6s; }
.unit-portraits-grid .unit-portrait-item:nth-child(4n+1) .unit-portrait-count::after  { animation-delay: -0.9s; }
.unit-portraits-grid .unit-portrait-item:nth-child(4n+2) .unit-portrait-count::before { animation-delay: -1.1s; }
.unit-portraits-grid .unit-portrait-item:nth-child(4n+2) .unit-portrait-count::after  { animation-delay: -1.5s; }
.unit-portraits-grid .unit-portrait-item:nth-child(4n+3) .unit-portrait-count::before { animation-delay: -1.7s; }
.unit-portraits-grid .unit-portrait-item:nth-child(4n+3) .unit-portrait-count::after  { animation-delay: -1.9s; }
.unit-portraits-grid .unit-portrait-item:nth-child(4n)   .unit-portrait-count::before { animation-delay: -2.1s; }
.unit-portraits-grid .unit-portrait-item:nth-child(4n)   .unit-portrait-count::after  { animation-delay: -2.3s; }

/* Animations for badge effects */
@keyframes badge-arcane-scroll {
  0% { background-position-x: 0; }
  100% { background-position-x: -40px; }
}

@keyframes badge-shimmer {
  0% { opacity: 0.5; }
  50% { opacity: 0.85; }
  100% { opacity: 0.5; }
}

@keyframes badge-fire-scroll {
  0% { background-position-x: 0; }
  100% { background-position-x: -40px; }
}

@keyframes badge-fire-flicker {
  0%, 100% { opacity: 0.45; }
  10% { opacity: 0.52; }
  20% { opacity: 0.55; }
  30% { opacity: 0.50; }
  40% { opacity: 0.48; }
  50% { opacity: 0.53; }
  60% { opacity: 0.47; }
  70% { opacity: 0.51; }
  80% { opacity: 0.46; }
  90% { opacity: 0.54; }
}

@keyframes badge-wisp-scroll {
  0% { background-position-x: 0; }
  100% { background-position-x: -40px; }
}

@keyframes badge-wisp-shimmer {
  0% { opacity: 0.5; }
  50% { opacity: 0.85; }
  100% { opacity: 0.5; }
}

@keyframes badge-breath {
  0%, 100% {
    transform: scale(1);
    background-position: 0% 50%;
  }
  50% {
    transform: scale(1.06);
    background-position: 100% 50%;
  }
}

@keyframes badge-shift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes badge-conic-rotate {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes human-smoke {
  0% {
    background-position: 45% 40%;
    filter: blur(0px) saturate(1);
  }
  50% {
    background-position: 57% 63%;
    filter: blur(0.8px) saturate(0.9);
  }
  100% {
    background-position: 60% 45%;
    filter: blur(0px) saturate(1);
  }
}

/* Radial pulse animations for circular badges */
@keyframes badge-arcane-pulse {
  0%, 100% { 
    transform: scale(1);
    opacity: 0.75;
  }
  50% { 
    transform: scale(1.15);
    opacity: 0.95;
  }
}

@keyframes badge-arcane-ring {
  0% { 
    transform: scale(0.8) rotate(0deg);
    opacity: 0.6;
  }
  50% { 
    transform: scale(1.2) rotate(180deg);
    opacity: 0.9;
  }
  100% { 
    transform: scale(0.8) rotate(360deg);
    opacity: 0.6;
  }
}

@keyframes badge-fire-burst {
  0%, 100% { 
    transform: scale(0.9);
    opacity: 0.8;
  }
  25% { 
    transform: scale(1.2);
    opacity: 1;
  }
  50% { 
    transform: scale(0.85);
    opacity: 0.75;
  }
  75% { 
    transform: scale(1.15);
    opacity: 0.95;
  }
}

@keyframes badge-fire-flicker-radial {
  0%, 100% { 
    opacity: 0.65;
    transform: scale(1);
  }
  15% { opacity: 0.85; transform: scale(1.1); }
  30% { opacity: 0.7; transform: scale(0.95); }
  45% { opacity: 0.9; transform: scale(1.08); }
  60% { opacity: 0.75; transform: scale(0.98); }
  80% { opacity: 0.88; transform: scale(1.05); }
}

@keyframes badge-wisp-pulse {
  0%, 100% { 
    transform: scale(1) rotate(0deg);
    opacity: 0.7;
  }
  33% { 
    transform: scale(1.12) rotate(120deg);
    opacity: 0.9;
  }
  66% { 
    transform: scale(0.95) rotate(240deg);
    opacity: 0.8;
  }
}

@keyframes badge-wisp-shimmer-radial {
  0% { 
    transform: scale(0.85);
    opacity: 0.7;
  }
  50% { 
    transform: scale(1.15);
    opacity: 0.95;
  }
  100% { 
    transform: scale(0.85);
    opacity: 0.7;
  }
}

@keyframes badge-soul-pulse {
  0%, 100% { 
    transform: scale(1);
    opacity: 0.75;
    filter: blur(0px);
  }
  50% { 
    transform: scale(1.1);
    opacity: 0.92;
    filter: blur(0.5px);
  }
}

@keyframes badge-soul-shimmer-radial {
  0% { 
    transform: scale(0.9) rotate(0deg);
    opacity: 0.75;
  }
  50% { 
    transform: scale(1.2) rotate(180deg);
    opacity: 0.95;
  }
  100% { 
    transform: scale(0.9) rotate(360deg);
    opacity: 0.75;
  }
}

.unit-portrait-item:hover .unit-portrait-count {
  transform: scale(1.2);
  background: linear-gradient(135deg, rgba(var(--race-rgb, 0, 255, 204), 1) 0%, rgba(var(--race-rgb-dark, 0, 217, 255), 1) 100%);
  border-color: rgba(10, 18, 35, 0.95);
  box-shadow: 
    0 0 0 2px rgba(var(--race-rgb, 0, 255, 204), 1),
    0 4px 18px rgba(var(--race-rgb, 0, 217, 255), 0.9),
    0 0 24px rgba(var(--race-rgb, 0, 255, 204), 0.8),
    inset 0 2px 6px rgba(255, 255, 255, 0.6),
    inset 0 -2px 3px rgba(0, 0, 0, 0.3);
  text-shadow: 
    0 1px 2px rgba(255, 255, 255, 0.7),
    0 -1px 1px rgba(0, 0, 0, 0.5),
    0 0 10px rgba(var(--race-rgb, 255, 255, 255), 0.7);
}

/* Light theme adjustments */
body.light-theme .unit-portraits-grid {
  background: rgba(255, 255, 255, 0.6);
}

body.light-theme .unit-portrait-icon {
  border-color: rgba(0, 150, 200, 0.4);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

body.light-theme .unit-portrait-item:hover .unit-portrait-icon {
  border-color: rgba(0, 150, 200, 0.8);
  box-shadow: 0 0 12px rgba(0, 150, 200, 0.5);
}

body.light-theme .unit-portrait-count {
  background: linear-gradient(135deg, rgba(var(--race-rgb, 0, 150, 220), 1) 0%, rgba(var(--race-rgb-dark, 0, 120, 180), 1) 100%);
  border-color: rgba(255, 255, 255, 0.95);
  box-shadow: 
    0 0 0 2px rgba(var(--race-rgb, 0, 150, 220), 0.7),
    0 3px 12px rgba(0, 0, 0, 0.4),
    0 0 12px rgba(var(--race-rgb, 0, 150, 220), 0.5),
    inset 0 2px 6px rgba(255, 255, 255, 0.6),
    inset 0 -2px 4px rgba(0, 0, 0, 0.25);
}

body.light-theme .unit-portrait-item:hover .unit-portrait-count {
  background: linear-gradient(135deg, rgba(var(--race-rgb, 0, 180, 240), 1) 0%, rgba(var(--race-rgb-dark, 0, 150, 220), 1) 100%);
  box-shadow: 
    0 0 0 3px rgba(var(--race-rgb, 0, 180, 240), 0.9),
    0 6px 20px rgba(var(--race-rgb, 0, 150, 220), 0.9),
    0 0 28px rgba(var(--race-rgb, 0, 180, 240), 0.8),
    inset 0 2px 8px rgba(255, 255, 255, 0.7),
    inset 0 -2px 4px rgba(0, 0, 0, 0.25);
}

/* Light theme race-specific text colors */
body.light-theme .unit-portrait-icon.human ~ .unit-portrait-count {
  color: #1a1a1a;
  text-shadow: 
    0 1px 3px rgba(0, 0, 0, 0.6),
    0 0 8px rgba(255, 215, 0, 0.6);
}

body.light-theme .unit-portrait-icon.orc ~ .unit-portrait-count {
  color: #ffffff;
  text-shadow: 
    0 1px 3px rgba(0, 0, 0, 0.9),
    0 0 8px rgba(244, 67, 54, 0.6);
}

body.light-theme .unit-portrait-icon.undead ~ .unit-portrait-count {
  color: #ffffff;
  text-shadow: 
    0 1px 3px rgba(0, 0, 0, 0.9),
    0 0 8px rgba(96, 125, 139, 0.6);
}

body.light-theme .unit-portrait-icon.nightelf ~ .unit-portrait-count {
  color: #ffffff;
  text-shadow: 
    0 1px 3px rgba(0, 0, 0, 0.9),
    0 0 8px rgba(156, 39, 176, 0.6);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .unit-portraits-grid {
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 8px;
    padding: 12px;
  }
  
  .unit-portrait-icon {
    width: 56px;
    height: 56px;
  }
  
  .unit-portrait-count {
    font-size: 0.85rem;
    width: 26px;
    height: 26px;
  }
}
