:root {
  --ui: #c2f970;
  --bg: #1a2f1a;
  --hud: #132;
  --accent: #ffcf40;
  --danger: #ff6161;
  --good: #66ffcc;
  --blue-team: #3366aa;
  --blue-team-light: #5588cc;
  --red-team: #aa3333;
  --red-team-light: #cc5555;
  font-family: "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
.app-shell {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: #f5ffe5;
  user-select: none;
}

.canvas-wrap {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.pixi-container {
  width: 100vw;
  height: 100vh;
}

/* Main HUD container */
.hud {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  justify-content: space-between;
  padding: 0.4rem;
  align-items: flex-start;
  pointer-events: none;
  z-index: 1000;
}

.hud-section,
.team-section,
.controls-section,
.battle-status,
.team-status {
  display: flex;
  gap: 0.5rem;
  pointer-events: auto;
}

/* Team sections on sides */
.team-section {
  flex-direction: column;
  min-width: 200px;
  max-width: 480px;
  padding: 0.4rem;
  border-radius: 6px;
}

.team-section.team-blue {
  background: rgba(51, 102, 170, 0.85);
  border: 2px solid var(--blue-team-light);
}

.team-section.team-red {
  background: rgba(170, 51, 51, 0.85);
  border: 2px solid var(--red-team-light);
}

.team-status {
  flex-direction: column;
  min-width: 160px;
}

.battle-status {
  flex-direction: column;
  align-items: center;
  background: rgba(0, 0, 0, 0.7);
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  border: 2px solid #555;
}

.controls-section {
  flex-direction: column;
  align-items: center;
  background: transparent;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  gap: 0.25rem;
}

.controls-section .setup-title {
  font-size: 1.5rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
  margin-bottom: 0.2rem;
}

/* Card row for unit selection */
.card-row {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: flex-start;
}

/* Unit cards with sprite previews */
.card {
  background: rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  padding: 0.25rem;
  width: 58px;
  text-align: center;
  cursor: grab;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.6);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.card:active {
  cursor: grabbing;
  transform: scale(0.95);
}

.card-sprite {
  width: 48px;
  height: 48px;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  margin-bottom: 0.15rem;
}

.card-name {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

/* Team header styling */
.team-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.3rem;
}

.team-name {
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.team-counter {
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.4);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

/* Battle title */
.battle-title {
  font-size: 1.4rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  margin-bottom: 0.3rem;
}

.battle-subtitle {
  font-size: 0.75rem;
  opacity: 0.8;
}

.battle-timer {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 0.3rem;
}

/* Buttons */
.button {
  background: linear-gradient(180deg, var(--ui), #9ad050);
  color: #1a3310;
  border: 0;
  border-radius: 5px;
  padding: 0.35rem 0.8rem;
  font-weight: 700;
  font-size: 0.75rem;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.button:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(1px);
}

.button.secondary {
  background: linear-gradient(180deg, #666, #444);
  color: #fff;
}

/* Tooltip */
.tooltip {
  position: fixed;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  font-size: 0.8rem;
  white-space: pre-line;
  border: 1px solid #444;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  z-index: 2000;
  max-width: 200px;
}

.tooltip.hidden,
.toast.hidden {
  display: none;
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  letter-spacing: 0.03em;
  border: 1px solid #555;
  z-index: 2000;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.hint {
  font-size: 0.75rem;
  opacity: 0.7;
}

/* Stats grid for results */
.table {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.5rem;
}

.table .row {
  background: rgba(0, 0, 0, 0.35);
  padding: 0.5rem;
  border-radius: 6px;
}

.table .row .label {
  font-size: 0.75rem;
  opacity: 0.6;
}

.table .row .value {
  font-weight: 600;
}

/* Team alive counters during battle */
.team-alive {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  min-width: 120px;
}

.team-alive.blue {
  background: linear-gradient(135deg, rgba(51, 102, 170, 0.8), rgba(40, 80, 140, 0.7));
  border: 2px solid var(--blue-team-light);
}

.team-alive.red {
  background: linear-gradient(135deg, rgba(170, 51, 51, 0.8), rgba(140, 40, 40, 0.7));
  border: 2px solid var(--red-team-light);
}

.team-alive .team-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  opacity: 0.9;
}

.team-alive .alive-count {
  font-size: 1.2rem;
  font-weight: 700;
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .hud {
    flex-direction: column;
    align-items: stretch;
  }
  .controls-section {
    flex-wrap: wrap;
  }
  .team-section {
    min-width: auto;
  }
  .card {
    width: 56px;
  }
  .card-sprite {
    width: 40px;
    height: 40px;
  }
}

/* Results screen */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.8);
  padding: 1rem;
  border-radius: 8px;
  max-width: 600px;
  margin: 0 auto;
}

.results-title {
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 0.5rem;
}

.results-title.victory {
  color: var(--good);
}

.results-title.defeat {
  color: var(--danger);
}

.results-table {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.result-row {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
}

.result-row .label {
  opacity: 0.7;
}

.result-row .value {
  font-weight: 600;
}

.results-history {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0.5rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  font-size: 0.8rem;
}

/* Button row in results */
.results-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.5rem;
}

/* Setup scene specific */
.setup-hint {
  text-align: center;
  margin-top: 0.15rem;
  font-size: 0.65rem;
  opacity: 0.7;
}
