/* Battlefront Simulator — Mobile-First 3D Tactical Battle Simulator UI */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: #08101c; color: #f1f5f9;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  touch-action: none;
}
#uw-root { position: fixed; inset: 0; overflow: hidden; }
.uw-boot {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; background: radial-gradient(circle at 50% 35%, #16263b, #08101c 70%); color: #e2e8f0; font-size: 16px;
}
.bs-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* HUD Layer */
.bs-hud { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
.bs-hud button, .bs-hud a, .bs-hud select { pointer-events: auto; }

/* Top Bar */
.bs-topbar {
  position: fixed;
  top: max(6px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.bs-top-group {
  display: flex; align-items: center; gap: 6px;
  background: rgba(9, 16, 28, 0.86); border: 1px solid rgba(148, 184, 224, 0.24);
  border-radius: 12px; padding: 5px 10px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  pointer-events: auto;
}
.bs-budget { font-size: 15px; font-weight: 900; color: #fbbf24; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 4px; }
.bs-budget-max { font-size: 11px; color: #94a3b8; font-weight: 700; }
.bs-pill { font-size: 12px; font-weight: 700; color: #cbd5e1; padding: 2px 7px; border-radius: 7px; background: rgba(30, 41, 59, 0.8); }
.bs-pill-ai { color: #fca5a5; background: rgba(127, 29, 29, 0.45); border: 1px solid rgba(248, 113, 113, 0.3); }
.bs-icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid rgba(148, 184, 224, 0.24);
  background: rgba(9, 16, 28, 0.88); color: #f1f5f9; font-size: 16px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; text-decoration: none;
}
.bs-icon-btn:active { transform: scale(0.94); }

/* Battle Live Strength Header */
.bs-battle-bar {
  flex: 1; max-width: 560px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 4px;
  background: rgba(9, 16, 28, 0.88); border: 1px solid rgba(148, 184, 224, 0.26);
  border-radius: 13px; padding: 6px 10px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  pointer-events: auto;
}
.bs-vs-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 800; }
.bs-side-blue { color: #38bdf8; }
.bs-side-red { color: #f87171; text-align: right; }
.bs-clock { font-size: 11px; color: #94a3b8; font-variant-numeric: tabular-nums; padding: 2px 7px; background: rgba(30, 41, 59, 0.8); border-radius: 999px; }
.bs-bars { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.bs-hp-track { height: 7px; background: rgba(255, 255, 255, 0.12); border-radius: 999px; overflow: hidden; }
.bs-hp-fill { height: 100%; border-radius: 999px; transition: width 0.14s linear; }
.bs-hp-blue { background: linear-gradient(90deg, #0284c7, #38bdf8); }
.bs-hp-red { background: linear-gradient(90deg, #f87171, #dc2626); margin-left: auto; }
.bs-cas-row { display: flex; justify-content: space-between; font-size: 11px; color: #94a3b8; font-weight: 600; }

/* Speed Controls during Battle */
.bs-speed-wrap {
  position: fixed;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
  background: rgba(9, 16, 28, 0.9); border: 1px solid rgba(148, 184, 224, 0.28);
  border-radius: 999px; padding: 5px 8px; backdrop-filter: blur(10px);
  pointer-events: auto;
}
.bs-spd-btn {
  min-width: 44px; height: 36px; border-radius: 999px; border: 1px solid transparent;
  background: rgba(30, 41, 59, 0.75); color: #cbd5e1; font-size: 13px; font-weight: 800; cursor: pointer;
}
.bs-spd-btn.active { background: #2563eb; color: #fff; border-color: #60a5fa; }

/* Toast */
.bs-toast {
  position: fixed; top: calc(max(8px, env(safe-area-inset-top)) + 56px); left: 50%; transform: translateX(-50%);
  background: rgba(12, 22, 38, 0.94); border: 1px solid rgba(56, 189, 248, 0.45); color: #f8fafc;
  padding: 7px 14px; border-radius: 999px; font-size: 12px; font-weight: 700;
  opacity: 0; transition: opacity 0.2s; z-index: 22; pointer-events: none;
  white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}
.bs-toast.show { opacity: 1; }

/* Selected Unit Floating Pill */
.bs-sel-pill {
  position: fixed; bottom: 186px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(12, 22, 38, 0.94); border: 1px solid rgba(56, 189, 248, 0.5);
  border-radius: 999px; padding: 5px 8px 5px 14px; font-size: 12px; font-weight: 700;
  pointer-events: auto; z-index: 18; box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
.bs-sel-rm {
  border: none; border-radius: 999px; padding: 6px 12px;
  background: #dc2626; color: #fff; font-size: 12px; font-weight: 800; cursor: pointer;
}

/* Bottom Prep Dock */
.bs-prep-dock {
  position: fixed;
  left: max(6px, env(safe-area-inset-left));
  right: max(6px, env(safe-area-inset-right));
  bottom: max(6px, env(safe-area-inset-bottom));
  max-width: 780px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 6px;
  background: rgba(9, 16, 28, 0.9); border: 1px solid rgba(148, 184, 224, 0.26);
  border-radius: 16px; padding: 8px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  pointer-events: auto; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}
.bs-tools-row {
  display: flex; align-items: center; gap: 5px; overflow-x: auto; scrollbar-width: none;
}
.bs-tools-row::-webkit-scrollbar { display: none; }
.bs-tool-btn {
  min-height: 36px; padding: 0 10px; border-radius: 9px; flex-shrink: 0;
  border: 1px solid rgba(148, 184, 224, 0.24); background: rgba(24, 37, 56, 0.9);
  color: #e2e8f0; font-size: 12px; font-weight: 800; cursor: pointer; white-space: nowrap;
}
.bs-tool-btn:active { transform: scale(0.95); }
.bs-tool-btn.active { background: rgba(37, 99, 235, 0.48); border-color: #38bdf8; color: #fff; }
.bs-tool-btn.danger.active { background: rgba(220, 38, 38, 0.55); border-color: #f87171; color: #fff; }
.bs-preset-sel {
  min-height: 36px; padding: 0 8px; border-radius: 9px; flex-shrink: 0;
  border: 1px solid rgba(148, 184, 224, 0.28); background: rgba(24, 37, 56, 0.95);
  color: #f1f5f9; font-size: 12px; font-weight: 800; outline: none; cursor: pointer;
}
.bs-battle-cta {
  margin-left: auto; min-height: 38px; padding: 0 18px; border-radius: 10px; border: none; flex-shrink: 0;
  background: linear-gradient(135deg, #10b981, #059669); color: #fff;
  font-size: 14px; font-weight: 900; letter-spacing: 0.05em; cursor: pointer;
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.42);
}
.bs-battle-cta:disabled { opacity: 0.42; cursor: not-allowed; box-shadow: none; }
.bs-battle-cta:active:not(:disabled) { transform: scale(0.96); }

/* 6 Large Touch-Friendly Unit Cards */
.bs-unit-cards {
  display: grid; grid-template-columns: repeat(6, minmax(104px, 1fr));
  gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 1px;
}
.bs-unit-cards::-webkit-scrollbar { display: none; }
.bs-ucard {
  position: relative; min-height: 76px; padding: 7px 8px; border-radius: 12px; text-align: left;
  border: 2px solid rgba(148, 184, 224, 0.22); background: rgba(20, 34, 54, 0.88);
  color: #f8fafc; cursor: pointer; display: flex; flex-direction: column; justify-content: space-between;
  transition: transform 0.1s, border-color 0.15s, background 0.15s;
}
.bs-ucard:active { transform: scale(0.96); }
.bs-ucard.active {
  border-color: #38bdf8; background: rgba(14, 65, 112, 0.92);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.55), inset 0 1px 0 rgba(255,255,255,0.12);
}
.bs-ucard.disabled { opacity: 0.42; }
.bs-ucard-top { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.bs-ucard-ico { font-size: 16px; line-height: 1; }
.bs-ucard-cost { font-size: 12px; font-weight: 900; color: #fbbf24; }
.bs-ucard-name { font-size: 12px; font-weight: 800; line-height: 1.15; margin-top: 2px; }
.bs-ucard-role { font-size: 10px; color: #94a3b8; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bs-ucard-cnt {
  position: absolute; top: -6px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 999px; background: #38bdf8; color: #08101c; font-size: 11px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
}

/* Results Modal */
.bs-modal {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: rgba(6, 11, 20, 0.82); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  pointer-events: auto; overflow-y: auto;
}
.bs-modal-card {
  width: min(620px, 100%); max-height: 92vh; overflow-y: auto;
  background: rgba(13, 22, 36, 0.96); border: 1px solid rgba(148, 184, 224, 0.28);
  border-radius: 18px; padding: 18px; box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}
.bs-res-title { margin: 0; font-size: 28px; font-weight: 900; letter-spacing: 0.08em; text-align: center; }
.bs-res-sub { margin: 4px 0 12px; font-size: 13px; color: #94a3b8; text-align: center; }
.bs-res-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.bs-kpi { background: rgba(20, 34, 54, 0.78); border: 1px solid rgba(148, 184, 224, 0.16); border-radius: 10px; padding: 8px; text-align: center; }
.bs-kpi-val { font-size: 16px; font-weight: 900; }
.bs-kpi-lbl { font-size: 11px; color: #94a3b8; margin-top: 2px; }
.bs-ai-note {
  background: rgba(127, 29, 29, 0.25); border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 10px; padding: 8px 12px; font-size: 12px; color: #fecaca; margin-bottom: 12px;
}
.bs-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 14px; }
.bs-table th, .bs-table td { padding: 6px 6px; border-bottom: 1px solid rgba(148, 184, 224, 0.14); text-align: left; }
.bs-table th { color: #94a3b8; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.bs-res-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 480px) { .bs-res-actions { grid-template-columns: 1fr; } }
.bs-btn {
  min-height: 44px; border-radius: 11px; border: none; font-size: 13px; font-weight: 800; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 12px;
}
.bs-btn-primary { background: linear-gradient(135deg, #10b981, #059669); color: #fff; }
.bs-btn-secondary { background: linear-gradient(135deg, #2563eb, #0284c7); color: #fff; }
.bs-btn-ghost { background: rgba(30, 41, 59, 0.9); color: #e2e8f0; border: 1px solid rgba(148, 184, 224, 0.26); }

@media (max-height: 460px) {
  .bs-ucard { min-height: 62px; padding: 5px 7px; }
  .bs-sel-pill { bottom: 146px; }
}
