/* Battle — C&C Red Alert inspired UI */
:root {
  --bg: #0a0e14;
  --panel: #121820;
  --panel-2: #1a2330;
  --border: #2a3a4a;
  --border-hi: #4a6a8a;
  --text: #d8e4f0;
  --muted: #7a8a9a;
  --allies: #3d7ecf;
  --allies-hi: #6ab0ff;
  --soviets: #c23a3a;
  --soviets-hi: #ff6a6a;
  --gold: #d4a017;
  --gold-hi: #ffd24a;
  --power: #3ecf6a;
  --power-low: #e0a020;
  --power-off: #e04040;
  --sidebar-w: 200px;
  --top-h: 36px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Code", "Consolas", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
}
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

.screen { position: absolute; inset: 0; }

/* ===== MENU ===== */
#menu {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, #1a2838 0%, #0a0e14 55%, #05070a 100%);
}
.menu-bg {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(60,120,180,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(60,120,180,0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.7;
  pointer-events: none;
}
.menu-card {
  position: relative;
  width: min(440px, 94vw);
  background: linear-gradient(180deg, #161e28 0%, #0e141c 100%);
  border: 1px solid var(--border-hi);
  box-shadow: 0 0 0 1px #000, 0 20px 60px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05);
  padding: 28px 28px 18px;
}
.menu-brand { text-align: center; margin-bottom: 22px; position: relative; }
.menu-brand h1 {
  font-size: 2.6rem;
  letter-spacing: 0.35em;
  font-weight: 800;
  color: var(--gold-hi);
  text-shadow: 0 0 24px rgba(212,160,23,0.35), 2px 2px 0 #000;
  margin-left: 0.35em;
}
.tagline {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 6px;
  letter-spacing: 0.04em;
}
.radar-ring {
  width: 64px; height: 64px; margin: 0 auto 12px;
  border: 2px solid var(--allies);
  border-radius: 50%;
  position: relative;
  box-shadow: 0 0 20px rgba(61,126,207,0.35);
}
.radar-ring::before {
  content: "";
  position: absolute; inset: 8px;
  border: 1px solid rgba(61,126,207,0.5);
  border-radius: 50%;
}
.radar-ring::after {
  content: "";
  position: absolute; left: 50%; top: 50%;
  width: 2px; height: 28px;
  background: linear-gradient(var(--allies-hi), transparent);
  transform-origin: bottom center;
  transform: translate(-50%, -100%) rotate(0deg);
  animation: sweep 3s linear infinite;
}
@keyframes sweep { to { transform: translate(-50%, -100%) rotate(360deg); } }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
}
.field input, .field select {
  width: 100%;
  background: #0a1018;
  border: 1px solid var(--border);
  padding: 10px 12px;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--allies); }

.faction-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.faction {
  background: #0a1018;
  border: 1px solid var(--border);
  padding: 12px 10px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.faction .f-icon { display: block; font-size: 1.1rem; margin-bottom: 4px; }
.faction .f-name { display: block; font-weight: 700; letter-spacing: 0.08em; }
.faction .f-sub { display: block; font-size: 0.72rem; color: var(--muted); margin-top: 2px; }
.faction.allies.active { border-color: var(--allies-hi); background: rgba(61,126,207,0.12); color: var(--allies-hi); }
.faction.soviets.active { border-color: var(--soviets-hi); background: rgba(194,58,58,0.12); color: var(--soviets-hi); }

.btn {
  display: block; width: 100%;
  border: 1px solid var(--border-hi);
  background: #1a2838;
  padding: 12px 16px;
  cursor: pointer;
  letter-spacing: 0.12em;
  font-weight: 700;
  font-size: 0.85rem;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: #243448; border-color: var(--gold); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, #3a5a2a 0%, #2a4018 100%);
  border-color: #6a9a3a;
  color: #e8f8c8;
  margin-top: 6px;
}
.btn.primary:hover { background: linear-gradient(180deg, #4a7a32 0%, #355020 100%); }
.btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
  margin-top: 8px;
}
.btn.ghost:hover { color: var(--text); border-color: var(--border-hi); }

.howto {
  list-style: none;
  margin-top: 18px;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.55;
}
.howto li { padding-left: 12px; position: relative; margin-bottom: 4px; }
.howto li::before { content: "▸"; position: absolute; left: 0; color: var(--gold); }
kbd {
  font-family: var(--mono);
  font-size: 0.7rem;
  background: #0a1018;
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 2px;
  color: var(--text);
}
.menu-foot {
  text-align: center;
  margin-top: 16px;
  font-size: 0.7rem;
  color: #4a5a6a;
  letter-spacing: 0.08em;
}

/* ===== GAME LAYOUT ===== */
#game {
  display: grid;
  /* Sidebar on the LEFT (classic-ish command panel) */
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--top-h) 1fr;
  grid-template-areas:
    "top top"
    "side view";
  background: #000;
}
#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background: linear-gradient(180deg, #1a2430 0%, #121820 100%);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  z-index: 5;
}
.top-left, .top-right { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.top-right { justify-content: flex-end; }
.top-mid { flex: 1; text-align: center; color: var(--gold-hi); font-size: 0.78rem; letter-spacing: 0.04em; }
.badge {
  font-weight: 800;
  letter-spacing: 0.1em;
  font-size: 0.72rem;
  padding: 2px 8px;
  border: 1px solid;
}
.badge.allies { color: var(--allies-hi); border-color: var(--allies); background: rgba(61,126,207,0.15); }
.badge.soviets { color: var(--soviets-hi); border-color: var(--soviets); background: rgba(194,58,58,0.15); }
.sep { color: var(--border); }
.tiny {
  background: #0a1018;
  border: 1px solid var(--border);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.75rem;
}
.tiny:hover { border-color: var(--border-hi); }

#viewport {
  grid-area: view;
  position: relative;
  overflow: hidden;
  background: #1a2a18;
  cursor: crosshair;
}
#world {
  display: block;
  width: 100%;
  height: 100%;
}
#selection-box {
  position: absolute;
  border: 1px solid #6f6;
  background: rgba(100, 255, 100, 0.08);
  pointer-events: none;
  z-index: 2;
}
#toast {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: rgba(10,14,20,0.88);
  border: 1px solid var(--border-hi);
  padding: 8px 16px;
  font-size: 0.85rem;
  color: var(--gold-hi);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 4;
  max-width: 80%;
  text-align: center;
}
#toast.show { opacity: 1; }

#win-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.win-card {
  background: linear-gradient(180deg, #161e28, #0e141c);
  border: 1px solid var(--gold);
  padding: 28px 32px;
  width: min(380px, 90%);
  text-align: center;
  box-shadow: 0 0 40px rgba(212,160,23,0.2);
}
.win-card h2 {
  font-size: 1.8rem;
  letter-spacing: 0.2em;
  color: var(--gold-hi);
  margin-bottom: 8px;
}
.win-card h2.defeat { color: var(--soviets-hi); }
#win-sub { color: var(--muted); margin-bottom: 16px; font-size: 0.9rem; }
.win-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
  font-size: 0.8rem;
}
.win-stats div {
  background: #0a1018;
  border: 1px solid var(--border);
  padding: 8px;
}
.win-stats strong { display: block; font-size: 1.1rem; color: var(--text); }
.win-stats span { color: var(--muted); font-size: 0.7rem; }

/* ===== SIDEBAR (left) ===== */
#sidebar {
  grid-area: side;
  background: linear-gradient(180deg, #1a222c 0%, #121820 40%, #0e141c 100%);
  border-right: 2px solid #3a4a5a;
  border-left: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 5;
  box-shadow: 4px 0 16px rgba(0,0,0,0.4);
}
.side-top {
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--border);
  background: #0e141c;
}
.credits-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.credits-row .label {
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  color: var(--muted);
}
#credits {
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--gold-hi);
  text-shadow: 0 0 8px rgba(255,210,74,0.25);
}
.power-row { display: flex; gap: 8px; align-items: stretch; }
.power-bar-wrap {
  flex: 1;
  height: 36px;
  background: #05080c;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
#power-fill {
  position: absolute;
  left: 0; bottom: 0; width: 100%;
  background: linear-gradient(0deg, #1a6a30, var(--power));
  transition: height 0.15s;
}
#power-use {
  position: absolute;
  left: 0; bottom: 0; width: 100%;
  border-top: 2px solid #fff;
  box-shadow: 0 0 6px #fff;
  pointer-events: none;
}
.power-nums {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;
  min-width: 52px;
}
#power-text { font-family: var(--mono); font-size: 0.72rem; }
.power-nums .label { font-size: 0.58rem; letter-spacing: 0.1em; color: var(--muted); }

.minimap-wrap {
  padding: 6px;
  background: #05080c;
  border-bottom: 1px solid var(--border);
}
#minimap {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border: 1px solid var(--border-hi);
  background: #0a1808;
  cursor: pointer;
  image-rendering: pixelated;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  border-bottom: 1px solid var(--border);
}
.tab {
  background: #0e141c;
  border: none;
  border-right: 1px solid var(--border);
  padding: 8px 4px;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.tab:last-child { border-right: none; }
.tab.active {
  background: var(--panel-2);
  color: var(--gold-hi);
  box-shadow: inset 0 -2px 0 var(--gold);
}
.tab:hover:not(.active) { color: var(--text); }

.panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 6px 6px 4px;
}
.panel.active { display: block; }
.panel-title {
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 6px 2px 4px;
  text-transform: uppercase;
}
.icon-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.icon-btn {
  position: relative;
  aspect-ratio: 1.15;
  background: linear-gradient(180deg, #1e2a38 0%, #121a24 100%);
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 60px;
  overflow: hidden;
}
.icon-btn:hover { border-color: var(--border-hi); background: #243040; }
.icon-btn.locked { opacity: 0.42; filter: grayscale(0.4); }
.icon-btn.locked:hover { opacity: 0.7; }
.icon-btn.selected { border-color: var(--gold-hi); box-shadow: inset 0 0 0 1px var(--gold); }
.icon-btn.building { border-color: var(--allies); }
.icon-btn .ib-short {
  position: absolute;
  top: 2px; left: 3px;
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--gold-hi);
  opacity: 0.9;
}
.icon-btn .ib-icon {
  font-size: 1.15rem;
  line-height: 1;
  filter: drop-shadow(0 1px 1px #000);
}
.icon-btn .ib-name {
  font-size: 0.58rem;
  letter-spacing: 0.02em;
  text-align: center;
  line-height: 1.15;
  color: var(--text);
}
.icon-btn .ib-cost {
  font-family: var(--mono);
  font-size: 0.58rem;
  color: var(--gold);
}
.panel-note {
  font-size: 0.65rem;
  color: var(--muted);
  padding: 6px 4px 2px;
  line-height: 1.35;
}

/* Selection card */
.sel-card {
  border-bottom: 1px solid var(--border);
  background: #0a1018;
  min-height: 88px;
  max-height: 200px;
  overflow-y: auto;
  padding: 6px 8px;
}
.sel-empty {
  color: var(--muted);
  font-size: 0.72rem;
  padding: 14px 4px;
  text-align: center;
  line-height: 1.4;
}
.sel-body.hidden, .sel-empty.hidden { display: none; }
.sel-title-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}
.sel-icon {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #121a24;
  border: 1px solid var(--border-hi);
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--gold-hi);
  flex-shrink: 0;
}
.sel-name {
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  line-height: 1.15;
}
.sel-sub {
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 2px;
}
.sel-hp-wrap {
  height: 8px;
  background: #05080c;
  border: 1px solid var(--border);
  margin-bottom: 2px;
}
.sel-hp-fill {
  height: 100%;
  width: 100%;
  background: #3ecf6a;
  transition: width 0.1s;
}
.sel-hp-text {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.sel-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 6px;
  font-size: 0.68rem;
}
.sel-stat {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  border-bottom: 1px solid rgba(42,58,74,0.45);
  padding: 2px 0;
}
.sel-stat.full { grid-column: 1 / -1; }
.sel-stat span { color: var(--muted); }
.sel-stat b { font-weight: 600; color: var(--text); font-family: var(--mono); font-size: 0.65rem; }
.sel-stat.muted b, .sel-stat.full.muted {
  font-weight: 400;
  font-family: var(--font);
  color: var(--muted);
  font-size: 0.65rem;
  line-height: 1.35;
}

.nuke-track {
  height: 4px;
  background: #1a1010;
  border: 1px solid #4a3020;
  margin-bottom: 4px;
  overflow: hidden;
}
.nuke-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8a4010, #ff8020);
  transition: width 0.2s;
}
.icon-btn .progress {
  position: absolute;
  left: 0; bottom: 0; height: 3px;
  background: var(--allies-hi);
  width: 0%;
}
.icon-btn .badge-q {
  position: absolute;
  top: 2px; right: 3px;
  font-size: 0.6rem;
  background: var(--gold);
  color: #000;
  font-weight: 800;
  min-width: 14px;
  text-align: center;
  border-radius: 2px;
  padding: 0 2px;
}
.icon-btn.low-power { border-color: var(--power-off); }

.info-body {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text);
  padding: 4px;
}
.info-body h3 {
  font-size: 0.85rem;
  color: var(--gold-hi);
  margin-bottom: 6px;
  letter-spacing: 0.06em;
}
.info-body .stat-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid rgba(42,58,74,0.6);
  padding: 3px 0;
  font-size: 0.72rem;
}
.info-body .stat-row span:last-child { color: var(--muted); font-family: var(--mono); }
.info-body .muted { color: var(--muted); }
.info-body .hp-bar {
  height: 8px;
  background: #05080c;
  border: 1px solid var(--border);
  margin: 8px 0;
  position: relative;
}
.info-body .hp-bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #8a2020, #3ecf6a);
}

.queue-bar {
  min-height: 28px;
  border-top: 1px solid var(--border);
  padding: 4px 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  background: #0a1018;
  font-size: 0.65rem;
  color: var(--muted);
}
.queue-item {
  background: #1a2838;
  border: 1px solid var(--border);
  padding: 2px 6px;
  color: var(--text);
}
.side-hint {
  padding: 5px 8px;
  font-size: 0.68rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: #0a0e14;
  min-height: 28px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-hint.warn { color: var(--power-low); }
.side-hint.bad { color: var(--power-off); }

.structure-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 6px 4px 4px;
}
.structure-actions.hidden { display: none; }
.act-btn {
  background: #1a2838;
  border: 1px solid var(--border-hi);
  padding: 8px 4px;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
}
.act-btn:hover { border-color: var(--gold); background: #243448; }
.act-btn.active { border-color: #3ecf6a; color: #3ecf6a; }
.act-btn.sell:hover { border-color: var(--soviets-hi); color: var(--soviets-hi); }

.super-bar {
  padding: 4px 6px;
  border-top: 1px solid var(--border);
  background: #0a1018;
}
.nuke-btn {
  width: 100%;
  background: linear-gradient(180deg, #3a2010, #1a1008);
  border: 1px solid #8a5020;
  color: #ffb060;
  padding: 8px 6px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  cursor: pointer;
}
.nuke-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  color: var(--muted);
  border-color: var(--border);
  background: #0e141c;
}
.nuke-btn.ready {
  border-color: #ff6020;
  color: #ffd080;
  box-shadow: 0 0 12px rgba(255, 80, 20, 0.35);
  animation: nuke-pulse 1.2s ease-in-out infinite;
}
.nuke-btn.armed {
  border-color: #ff2020;
  background: #401010;
  color: #fff;
}
@keyframes nuke-pulse {
  50% { box-shadow: 0 0 18px rgba(255, 100, 20, 0.55); }
}

/* Mobile: collapse sidebar slightly */
@media (max-width: 700px) {
  :root { --sidebar-w: 160px; --top-h: 32px; }
  .menu-card { padding: 18px; }
  .menu-brand h1 { font-size: 2rem; letter-spacing: 0.2em; }
  .icon-btn .ib-name { font-size: 0.52rem; }
  #topbar { font-size: 0.7rem; }
  .top-mid { display: none; }
}
