:root {
  --bg-glass: rgba(13, 19, 33, 0.84);
  --bg-panel: rgba(19, 28, 46, 0.94);
  --border-subtle: rgba(255, 255, 255, 0.14);
  --border-gold: rgba(245, 196, 81, 0.65);
  --red-team: #e03a3c;
  --red-glow: rgba(224, 58, 60, 0.35);
  --blue-team: #2f74f5;
  --blue-glow: rgba(47, 116, 245, 0.35);
  --gold: #f5c451;
  --emerald: #27c27c;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --font-ui: system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

html,
body,
#app {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b101d;
  font-family: var(--font-ui);
  color: var(--text-main);
}

#battle-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#ui-root {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 10;
}

.pointer-auto {
  pointer-events: auto;
}

/* ==================== TOP COMMAND BAR ==================== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: linear-gradient(180deg, rgba(10, 15, 28, 0.92) 0%, rgba(10, 15, 28, 0.65) 100%);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  background: linear-gradient(135deg, var(--red-team), var(--blue-team));
  padding: 5px 10px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.nav-tabs {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: 1px solid var(--border-subtle);
  background: rgba(30, 41, 59, 0.85);
  color: var(--text-main);
  padding: 6px 11px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn:hover {
  background: rgba(51, 65, 85, 0.95);
  border-color: rgba(255, 255, 255, 0.32);
  transform: translateY(-1px);
}

.btn.active {
  background: rgba(245, 196, 81, 0.2);
  border-color: var(--gold);
  color: var(--gold);
}

.btn-battle {
  background: linear-gradient(135deg, #e03a3c, #d97706);
  border-color: #fbbf24;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  padding: 7px 18px;
  box-shadow: 0 0 18px rgba(224, 58, 60, 0.45);
}

.btn-battle:hover {
  filter: brightness(1.1);
}

.btn-red.active {
  background: var(--red-team);
  border-color: #fca5a5;
  color: #fff;
}

.btn-blue.active {
  background: var(--blue-team);
  border-color: #93c5fd;
  color: #fff;
}

/* ==================== ARMY POWER & BUDGET STATUS ==================== */
.battle-status-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-glass);
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
}

.team-pill {
  font-size: 12.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.team-pill.red {
  color: #ff7b7d;
}

.team-pill.blue {
  color: #7ab0ff;
}

.power-bar {
  width: 120px;
  height: 8px;
  background: var(--blue-team);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.power-bar-red {
  height: 100%;
  background: var(--red-team);
  transition: width 0.2s ease;
}

/* ==================== TELEMETRY & MIDDLE WORKSPACE ==================== */
.mid-layer {
  flex: 1;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 14px;
  overflow: hidden;
}

.info-banner {
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--gold);
  border-radius: 9px;
  padding: 9px 13px;
  max-width: 350px;
  font-size: 12px;
  line-height: 1.45;
}

.info-banner h3 {
  margin: 0 0 4px 0;
  font-size: 14px;
  color: var(--gold);
}

.telemetry-card {
  background: rgba(9, 14, 26, 0.84);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 11.5px;
  line-height: 1.5;
  min-width: 225px;
  font-variant-numeric: tabular-nums;
}

.tel-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.tel-val {
  font-weight: 700;
  color: #e2e8f0;
}

.tel-good {
  color: var(--emerald);
}

.tel-gold {
  color: var(--gold);
}

/* ==================== SIDE EDITOR DRAWER ==================== */
.editor-panel {
  width: 350px;
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-gold);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

.editor-panel h3 {
  margin: 0 0 10px 0;
  color: var(--gold);
  font-size: 15px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.form-field.full {
  grid-column: 1 / -1;
}

.form-field input,
.form-field select {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12px;
}

/* ==================== BOTTOM UNIT DOCK ==================== */
.bottom-dock {
  background: linear-gradient(0deg, rgba(10, 15, 28, 0.95) 0%, rgba(13, 20, 36, 0.84) 100%);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border-subtle);
  padding: 8px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.dock-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.faction-strip,
.brush-strip {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  align-items: center;
}

.unit-cards-scroll {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.unit-card {
  min-width: 124px;
  max-width: 138px;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  padding: 7px 9px;
  cursor: pointer;
  transition: all 0.14s ease;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.unit-card:hover {
  background: rgba(51, 65, 85, 0.92);
  transform: translateY(-2px);
}

.unit-card.selected {
  border-color: var(--gold);
  background: rgba(245, 196, 81, 0.16);
  box-shadow: 0 0 12px rgba(245, 196, 81, 0.28);
}

.unit-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  font-weight: 700;
}

.unit-cost {
  color: var(--gold);
  font-weight: 800;
  font-size: 12px;
}

.unit-stats-mini {
  font-size: 10.5px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* ==================== MODALS & OVERLAYS ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 9, 18, 0.76);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 18px;
}

.modal-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-gold);
  border-radius: 14px;
  max-width: 920px;
  width: 100%;
  max-height: 84vh;
  overflow-y: auto;
  padding: 18px 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  color: var(--gold);
}

.campaign-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(205px, 1fr));
  gap: 9px;
  margin-bottom: 16px;
}

.camp-card {
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  padding: 9px 11px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.camp-card:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
}

.camp-card.done {
  border-color: rgba(39, 194, 124, 0.55);
}

.outcome-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(12, 18, 34, 0.94);
  border: 2px solid var(--gold);
  border-radius: 16px;
  padding: 22px 34px;
  text-align: center;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.7);
}

.outcome-banner h1 {
  margin: 0 0 8px 0;
  font-size: 28px;
}

/* ==================== POSSESSION RETICLE & TOUCH CONTROLS ==================== */
.possession-reticle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 240, 150, 0.9);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.65);
}

.possession-reticle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  background: #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.possession-bar {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--gold);
  border-radius: 12px;
  padding: 10px 18px;
  text-align: center;
  min-width: 320px;
}

.hp-track {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px;
  overflow: hidden;
  margin: 6px 0;
}

.hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #ef4444, #22c55e);
  transition: width 0.1s linear;
}

/* Mobile Touch Controls */
.touch-controls {
  position: absolute;
  inset: auto 16px 96px 16px;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
}

@media (pointer: coarse), (max-width: 900px) {
  .touch-controls.visible-mobile {
    display: flex;
  }
}

.touch-stick {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.62);
  border: 2px solid rgba(255, 255, 255, 0.28);
  position: relative;
  touch-action: none;
}

.touch-knob {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(245, 196, 81, 0.85);
  position: absolute;
  top: 31px;
  left: 31px;
}

.bench-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  margin-top: 10px;
}

.bench-table th,
.bench-table td {
  border: 1px solid var(--border-subtle);
  padding: 7px 9px;
  text-align: right;
}

.bench-table th:first-child,
.bench-table td:first-child {
  text-align: left;
}

.bench-table th {
  background: rgba(30, 41, 59, 0.9);
  color: var(--gold);
}
