:root {
  --bg: #070b16;
  --panel: #121a30;
  --panel-2: #18233f;
  --line: #3a4b73;
  --accent: #4dd0e1;
  --accent-2: #ffb74d;
  --text: #e8eefc;
  --muted: #9fb0d6;
  --danger: #ff6b6b;
  --good: #7bd88f;
  --t2: #7bd88f;
  --t3: #64b5f6;
  --t4: #ba68c8;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Menlo", "Consolas", "Courier New", monospace;
  background: linear-gradient(180deg, #05080f 0%, #0a1020 100%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.phone {
  width: 420px;
  height: min(860px, 96vh);
  background: #0d1427;
  border: 2px solid #31405f;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---------- top bar ---------- */

.topbar {
  flex: 0 0 46px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  display: grid;
  grid-template-columns: 1.6fr 0.85fr 0.7fr 1fr;
  gap: 6px;
  align-items: center;
}

.pill {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 4px;
  padding: 5px 4px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill.gold { color: var(--accent-2); }
.pill.overheat { color: var(--danger); border-color: var(--danger); }

/* ---------- battle area ---------- */

.battle-area {
  flex: 0 0 33%;
  border-bottom: 1px solid var(--line);
  background: #0d1730;
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
}

.battle-header,
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 9px;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin-bottom: 6px;
  gap: 8px;
  white-space: nowrap;
}

#battle-status { overflow: hidden; text-overflow: ellipsis; }

.battle-stage {
  flex: 1;
  min-height: 0;
  border: 1px solid #2f4268;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(77, 208, 225, 0.08), transparent 55%),
    radial-gradient(ellipse at 80% 0%, rgba(255, 107, 107, 0.07), transparent 55%),
    linear-gradient(180deg, #0b142b 0%, #0e1a38 78%, #131f42 78%, #0d1633 100%);
}

/* scanlines for a cheap pixel/CRT feel */
.battle-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.14) 0 1px, transparent 1px 3px);
  pointer-events: none;
  z-index: 8;
}

.ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 20%;
  height: 2px;
  background: #2c3d66;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.hp-group {
  position: absolute;
  top: 8px;
  width: 42%;
  z-index: 6;
}

.hp-group.player { left: 8px; }
.hp-group.enemy { right: 8px; text-align: right; }

.hp-label {
  font-size: 8px;
  letter-spacing: 0.4px;
  color: var(--muted);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hpbar {
  height: 8px;
  border: 1px solid #3a4b73;
  border-radius: 2px;
  background: #1c2337;
  overflow: hidden;
}

.hpbar > span {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #58d68d, #7bd88f);
  transition: width 0.15s linear;
}

.hpbar.enemybar > span { background: linear-gradient(90deg, #ff8a80, #ff5252); }

.sprite {
  position: absolute;
  image-rendering: pixelated;
  z-index: 3;
}

.player-mech { left: 7%; bottom: 21%; animation: bob 2.2s ease-in-out infinite; }
.enemy-mech { right: 7%; bottom: 21%; animation: bob 2.6s ease-in-out infinite; }
.enemy-mech.boss { transform: scale(1.25); transform-origin: bottom right; }

.drone { z-index: 2; animation: hover 1.8s ease-in-out infinite; }
.drone.d1 { left: 24%; bottom: 52%; }
.drone.d2 { left: 27%; bottom: 30%; animation-delay: 0.6s; }
.drone.e1 { right: 26%; bottom: 54%; animation-delay: 0.3s; }
.drone.e2 { right: 29%; bottom: 32%; animation-delay: 0.9s; }

@keyframes bob { 0%, 100% { margin-bottom: 0; } 50% { margin-bottom: 3px; } }
@keyframes hover { 0%, 100% { margin-bottom: 0; } 50% { margin-bottom: 6px; } }

.sprite.hit { animation: shake 0.18s linear; filter: brightness(1.9); }
@keyframes shake {
  0%, 100% { margin-left: 0; }
  25% { margin-left: -3px; }
  75% { margin-left: 3px; }
}

.fx-layer { position: absolute; inset: 0; z-index: 5; pointer-events: none; }

.fx { position: absolute; will-change: transform; }

.fx-tracer {
  width: 10px;
  height: 3px;
  background: var(--accent-2);
  box-shadow: 0 0 6px rgba(255, 183, 77, 0.9);
  transition: transform 0.22s linear;
}

.fx-missile {
  width: 12px;
  height: 5px;
  border-radius: 2px;
  background: #ff6b6b;
  box-shadow: -6px 0 8px rgba(255, 183, 77, 0.8);
  transition: transform 0.5s cubic-bezier(0.3, -0.4, 0.7, 1.2);
}

.fx-tracer.enemyfire {
  background: #ff8a80;
  box-shadow: 0 0 6px rgba(255, 107, 107, 0.9);
}

.fx-beam {
  height: 3px;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(77, 208, 225, 1);
  transform-origin: left center;
  animation: beam 0.22s linear forwards;
}

@keyframes beam { 0% { opacity: 1; } 70% { opacity: 0.9; } 100% { opacity: 0; } }

.fx-muzzle {
  width: 8px;
  height: 8px;
  background: #fff6d8;
  box-shadow: 0 0 8px #ffd166;
  animation: pop 0.1s linear forwards;
}

.fx-impact {
  width: 16px;
  height: 16px;
  border: 2px solid #ffd166;
  border-radius: 999px;
  box-shadow: 0 0 14px rgba(255, 209, 102, 0.6);
  animation: pop 0.28s ease-out forwards;
}

@keyframes pop {
  0% { opacity: 1; transform: scale(0.4); }
  100% { opacity: 0; transform: scale(1.5); }
}

.banner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 9;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #ffd166;
  text-shadow: 0 0 14px rgba(255, 209, 102, 0.6), 2px 2px 0 #000;
  background: rgba(5, 8, 15, 0.45);
  animation: bannerpulse 0.9s ease-in-out infinite;
}

@keyframes bannerpulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.82; } }

/* ---------- encounter intel ---------- */

.intel-area {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  padding: 7px 10px 8px;
  background: #0b1428;
}

.intel-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.intel-def {
  font-size: 9px;
  letter-spacing: 0.4px;
  color: var(--text);
}

.intel-rec {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.intel-good { color: var(--good); }
.intel-bad { color: var(--danger); }

.intel-hint {
  font-size: 8.5px;
  line-height: 1.3;
  color: var(--muted);
  border-left: 2px solid var(--line);
  padding-left: 6px;
  min-height: 11px;
}

.intel-hint.win { color: var(--good); border-color: var(--good); }
.intel-hint.lose { color: var(--danger); border-color: var(--danger); }

/* ---------- build area ---------- */

.build-area {
  flex: 0 0 33%;
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  background: #0c1325;
  display: flex;
  flex-direction: column;
}

.grid-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 86px;
  gap: 8px;
}

.grid {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 4px;
  background: linear-gradient(180deg, rgba(77, 208, 225, 0.04), rgba(255, 255, 255, 0.01));
}

.slot {
  border: 1px solid #232f4c;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 3px;
  min-height: 0;
}

.slot.droppable { border-color: var(--good); background: rgba(123, 216, 143, 0.08); }

.module {
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.3px;
  color: #06111c;
  cursor: pointer;
  z-index: 2;
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.m-ballistic { background: #ffb74d; }
.m-laser { background: #4dd0e1; }
.m-missile { background: #ef5350; color: #fff; }
.m-utility { background: #9ccc65; }
.m-core { background: #ba68c8; color: #fff; }

.mod-tier { font-size: 7px; opacity: 0.85; }

.module.t2 { outline: 2px solid var(--t2); }
.module.t3 { outline: 2px solid var(--t3); }
.module.t4 { outline: 2px solid var(--t4); box-shadow: 0 0 8px rgba(186, 104, 200, 0.8); }

/* A selected module is click-transparent and translucent so the droppable
   slots under its own footprint can be seen and tapped (nudge moves). */
.module.selected {
  outline: 2px dashed #fff;
  filter: brightness(1.15);
  opacity: 0.6;
  pointer-events: none;
}

.module.placed { animation: drop-in 0.25s ease-out; }
@keyframes drop-in {
  0% { transform: scale(1.35); opacity: 0.4; }
  100% { transform: scale(1); opacity: 1; }
}

.module.merge-flash { animation: mergeflash 1.1s ease-out; }
@keyframes mergeflash {
  0% { outline: 3px solid #fff; filter: brightness(2.4); transform: scale(1.28); }
  60% { filter: brightness(1.6); }
  100% { transform: scale(1); }
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 0;
}

.badge {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 4px;
  font-size: 7.5px;
  letter-spacing: 0.4px;
  padding: 4px 6px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  overflow: hidden;
}

.badge strong {
  color: var(--text);
  font-size: 9px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge.warn strong.alert { color: var(--danger); }
.badge strong.good { color: var(--good); }

/* ---------- shop ---------- */

.shop-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px 10px 10px;
  gap: 7px;
  background: #0b1120;
}

.shop-row {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.shop-item {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 5px;
  padding: 6px;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 9px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  letter-spacing: 0.2px;
}

.shop-item:hover:not(:disabled) { border-color: var(--accent); }
.shop-item .type { color: var(--muted); font-size: 8px; font-weight: 400; }
.shop-item .cost { color: var(--accent-2); }
.shop-item.sold { opacity: 0.35; cursor: default; }
.shop-item:disabled { opacity: 0.4; cursor: default; }
.shop-item .swatch { width: 14px; height: 8px; border-radius: 2px; margin-bottom: 2px; }

.controls {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 0.8fr 1.4fr;
  gap: 6px;
}

.mini-btn, .btn {
  font-family: inherit;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 5px;
  padding: 11px 4px;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.4);
}

.mini-btn:hover:not(:disabled), .btn:hover:not(:disabled) { filter: brightness(1.2); }
.mini-btn:active:not(:disabled), .btn:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.mini-btn:disabled, .btn:disabled { opacity: 0.4; cursor: default; }

.mini-btn.active { border-color: var(--accent-2); color: var(--accent-2); }

.btn {
  background: linear-gradient(180deg, #1e9fb3, #146877);
  border-color: #61d7e8;
  color: #fff;
}

.legend {
  flex: 0 0 auto;
  font-size: 9px;
  letter-spacing: 0.3px;
  color: var(--muted);
  min-height: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend.ok { color: var(--good); }
.legend.err { color: var(--danger); }

/* ---------- overlay ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(5, 8, 15, 0.82);
  display: grid;
  place-items: center;
}

.overlay-card {
  text-align: center;
  border: 2px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 26px 34px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.overlay-title {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 3px;
  color: #ffd166;
  text-shadow: 2px 2px 0 #000;
}

.overlay-sub { font-size: 11px; color: var(--muted); }
