:root {
  color-scheme: dark;
  --void: #07111e;
  --panel: rgba(7, 17, 30, 0.88);
  --line: rgba(121, 184, 218, 0.27);
  --ink: #edf8ff;
  --muted: #89a4b7;
  --cyan: #68e5ff;
  --amber: #ffc86b;
  --coral: #ff6577;
  --violet: #957cff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--void); }
body { color: var(--ink); font: 14px/1.25 Inter, ui-sans-serif, system-ui, sans-serif; user-select: none; }
button { color: inherit; font: inherit; }
#app { position: relative; width: 100%; height: 100%; overflow: hidden; isolation: isolate; }
#viewport { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(320px, 660px) minmax(50px, 1fr);
  align-items: start;
  gap: 14px;
  padding: 16px 18px;
  pointer-events: none;
}
.brand { display: grid; gap: 3px; text-shadow: 0 2px 10px #000; }
.brand b { font-size: 16px; letter-spacing: .17em; }
.brand span, .kicker { color: var(--cyan); font: 700 9px/1.2 ui-monospace, SFMono-Regular, monospace; letter-spacing: .18em; }
.objective {
  justify-self: stretch;
  padding: 11px 16px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(12, 30, 45, .94), rgba(5, 15, 25, .88));
  box-shadow: 0 12px 36px #0005;
  text-align: center;
}
.objective b { display: block; font: 800 11px ui-monospace, monospace; letter-spacing: .16em; color: var(--amber); }
.objective > span { display: block; margin: 4px 0 8px; color: #c7dce8; font-size: 12px; }
.steps { display: flex; justify-content: center; gap: 6px; }
.steps i {
  padding: 3px 6px;
  border: 1px solid #ffffff18;
  border-radius: 999px;
  color: #6e8798;
  font: 700 9px ui-monospace, monospace;
  font-style: normal;
}
.steps i.done { color: #061219; border-color: var(--cyan); background: var(--cyan); }
.iconButton {
  pointer-events: auto;
  justify-self: end;
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  font-weight: 900;
  cursor: pointer;
}

.statusRail, .threatRail {
  position: absolute;
  top: 112px;
  display: grid;
  gap: 8px;
  width: 174px;
}
.statusRail { left: 18px; }
.threatRail { right: 18px; }
.unitCard, .graceCard, .shieldCard {
  display: grid;
  gap: 3px;
  min-height: 68px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  box-shadow: 0 10px 30px #0004;
  text-align: left;
}
button.unitCard { width: 100%; cursor: pointer; }
.unitCard span, .graceCard span, .shieldCard span { color: var(--muted); font: 700 9px ui-monospace, monospace; letter-spacing: .1em; }
.unitCard strong, .graceCard strong, .shieldCard strong { font: 800 15px ui-monospace, monospace; }
.unitCard small, .shieldCard small { color: var(--muted); font: 700 9px ui-monospace, monospace; }
.unitCard.friendly { border-left: 3px solid var(--cyan); }
.unitCard.relay { border-left: 3px solid var(--amber); }
.unitCard.threat { border-right: 3px solid var(--coral); }
.graceCard { border-color: rgba(104, 229, 255, .45); color: var(--cyan); }
.shieldCard { border-right: 3px solid var(--violet); }
.bar { height: 3px; overflow: hidden; background: #ffffff12; border-radius: 99px; }
.bar i { display: block; width: 100%; height: 100%; background: var(--amber); transform-origin: left; }
.threat .bar i { background: var(--coral); }
.pulse { animation: pulse 1.25s ease-in-out infinite; }

.commandRail {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(5, 15, 25, .9);
  box-shadow: 0 18px 48px #0008;
}
.commandRail button {
  min-width: 62px;
  min-height: 46px;
  border: 1px solid #28465a;
  border-radius: 9px;
  background: #0d2030;
  cursor: pointer;
}
.commandRail button:hover, .commandRail button.active, .commandRail button.latched { border-color: var(--cyan); background: #15354a; color: var(--cyan); }
.commandRail button:disabled { opacity: .42; cursor: not-allowed; }
.commandRail kbd { display: block; color: var(--muted); font: 700 9px ui-monospace, monospace; }
.commandRail span { font: 800 11px ui-monospace, monospace; }
.altitudes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.altitudes button { min-width: 50px; font: 800 9px ui-monospace, monospace; }
.altitudes button.active { color: #c9c0ff; border-color: var(--violet); background: #1a1932; box-shadow: inset 0 -2px 0 var(--violet); }
.altitudes button.latched { background: #10293a; }

.orderReadout {
  position: absolute;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  padding: 7px 12px;
  border: 1px solid #ffffff18;
  border-radius: 999px;
  background: #06121ddd;
  color: #cce3ef;
  font: 800 10px ui-monospace, monospace;
  letter-spacing: .12em;
  pointer-events: none;
}
.cameraHelp { position: absolute; left: 18px; bottom: 19px; display: flex; gap: 12px; color: #607b8e; font: 700 8px ui-monospace, monospace; pointer-events: none; }
.modeBadge { position: absolute; right: 18px; bottom: 19px; color: #6f8b9e; font: 700 9px ui-monospace, monospace; pointer-events: none; }

#selectionBox {
  position: absolute;
  z-index: 5;
  border: 1px solid var(--cyan);
  background: rgba(104, 229, 255, .08);
  pointer-events: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(2, 8, 14, .72);
  backdrop-filter: blur(7px);
}
.overlay[hidden] { display: none; }
.overlay > div {
  width: min(460px, calc(100vw - 36px));
  padding: 36px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(150deg, #10263a, #07131f);
  box-shadow: 0 40px 100px #000a;
  text-align: center;
}
.overlay h1 { margin: 7px 0; font-size: clamp(40px, 8vw, 72px); line-height: .9; letter-spacing: -.06em; }
.overlay p { color: var(--muted); }
.overlay button {
  min-width: 180px;
  min-height: 48px;
  margin-top: 14px;
  border: 0;
  border-radius: 9px;
  background: var(--cyan);
  color: #05131a;
  font: 900 11px ui-monospace, monospace;
  letter-spacing: .1em;
  cursor: pointer;
}
.result dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 22px 0 4px; }
.result dl div { padding: 10px; border: 1px solid #ffffff12; border-radius: 9px; }
.result dt { color: var(--muted); font: 700 8px ui-monospace, monospace; }
.result dd { margin: 5px 0 0; font: 900 16px ui-monospace, monospace; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(104, 229, 255, 0); }
  45% { box-shadow: 0 0 0 6px rgba(104, 229, 255, .12), 0 0 24px rgba(104, 229, 255, .24); }
}

@media (max-width: 800px) {
  .topbar { grid-template-columns: 1fr auto; padding: 8px; }
  .brand { display: none; }
  .objective { grid-column: 1; padding: 7px 10px; text-align: left; }
  .objective > span { display: none; }
  .steps { justify-content: flex-start; }
  .iconButton { grid-column: 2; width: 44px; height: 44px; }
  .statusRail, .threatRail { top: 70px; width: 132px; }
  .statusRail { left: 7px; }
  .threatRail { right: 7px; }
  .unitCard, .graceCard, .shieldCard { min-height: 54px; padding: 7px; }
  .unitCard strong, .graceCard strong, .shieldCard strong { font-size: 12px; }
  .graceCard, .shieldCard { display: none; }
  .commandRail { bottom: 7px; width: calc(100% - 14px); justify-content: center; }
  .commandRail button { min-width: 49px; min-height: 44px; }
  .altitudes button { min-width: 43px; }
  .cameraHelp, .modeBadge { display: none; }
  .orderReadout { bottom: 65px; }
}

@media (orientation: portrait) and (max-width: 600px) {
  .commandRail { display: grid; grid-template-columns: repeat(4, 1fr); }
  .altitudes { grid-column: span 3; }
  .commandRail button { width: 100%; }
  .orderReadout { bottom: 118px; }
}
