:root {
  --bg-deep: #040916;
  --bg-foundry: #091328;
  --bg-panel: rgba(7, 13, 30, 0.94);
  --bg-card: rgba(12, 22, 48, 0.96);
  --border-cyan: rgba(56, 189, 248, 0.42);
  --border-mint: rgba(52, 211, 153, 0.38);
  --border-amber: rgba(251, 191, 36, 0.38);
  --text-main: #f8fafc;
  --text-muted: #9eb3d4;
  --cyan: #38bdf8;
  --mint: #34d399;
  --amber: #fbbf24;
  --gold: #fde047;
  --rose: #f472b6;
  --font-sans: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, Menlo, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 15%, #11244f 0%, #040916 80%);
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: manipulation;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

.accent-gold { color: var(--gold); }
.accent-amber { color: var(--amber); }
.accent-cyan { color: var(--cyan); }
.accent-mint { color: var(--mint); }

#app-shell {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ================= TOP TELEMETRY BAR ================= */
.top-bar {
  flex-shrink: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(5, 10, 24, 0.96);
  border-bottom: 1px solid var(--border-cyan);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
  min-width: 0;
  flex-wrap: wrap;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-icon {
  flex-shrink: 0;
  border-radius: 7px;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.35);
}

.brand-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  line-height: 1.1;
  white-space: nowrap;
}

.title-accent {
  color: var(--cyan);
}

.brand-sub {
  font-size: 0.67rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-telemetry {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  justify-content: center;
  min-width: 0;
}

.tele-box,
.tele-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(15, 25, 52, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.22);
  min-width: 0;
}

.meter-box {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 108px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(15, 25, 52, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.22);
  min-width: 0;
}

.meter-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.tele-k {
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.tele-v {
  font-size: 0.78rem;
  font-weight: 800;
}

.bar-track {
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  transition: width 0.16s ease;
}

.bar-mint {
  background: linear-gradient(90deg, #10b981, #34d399);
}

.bar-cyan {
  background: linear-gradient(90deg, #0ea5e9, #38bdf8);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.hdr-btn,
.hdr-link {
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 25, 52, 0.9);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 5px 8px;
  border-radius: 7px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.hdr-btn:hover,
.hdr-link:hover {
  border-color: var(--cyan);
  background: rgba(24, 42, 86, 0.95);
}

/* ================= DIRECTIVE STRIP ================= */
.directive-strip {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: rgba(7, 13, 30, 0.94);
  border-bottom: 1px solid rgba(56, 189, 248, 0.2);
  overflow-x: auto;
  min-width: 0;
}

.dir-label {
  font-size: 0.67rem;
  color: var(--text-muted);
  font-weight: 700;
  white-space: nowrap;
}

.dir-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.26);
  background: rgba(15, 25, 52, 0.85);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.69rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.dir-pill .dir-meta {
  color: var(--text-muted);
  font-size: 0.65rem;
}

.dir-pill.is-active.dir-sync {
  border-color: var(--cyan);
  background: rgba(56, 189, 248, 0.2);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.28);
}

.dir-pill.is-active.dir-emp {
  border-color: var(--mint);
  background: rgba(52, 211, 153, 0.2);
  box-shadow: 0 0 10px rgba(52, 211, 153, 0.28);
}

.dir-pill.is-active.dir-relay {
  border-color: var(--amber);
  background: rgba(251, 191, 36, 0.2);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.28);
}

.ai-state-chip {
  margin-left: auto;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: var(--cyan);
  font-size: 0.67rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ================= ARENA STAGE ================= */
#arena-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 6px;
}

#canvas-wrap {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  border: 1px solid rgba(56, 189, 248, 0.32);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.58);
  background: #060d1f;
  cursor: crosshair;
}

.toast-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 22;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(6, 14, 34, 0.94);
  border: 1px solid var(--cyan);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-size: 0.74rem;
  pointer-events: none;
  max-width: calc(100% - 24px);
}

.toast-badge {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.22);
  color: var(--cyan);
  font-weight: 800;
  white-space: nowrap;
}

.toast-msg {
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ================= OVERLAYS ================= */
.overlay-screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(3, 7, 18, 0.76);
  backdrop-filter: blur(6px);
}

.overlay-card {
  width: min(760px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-cyan);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.compact-card {
  width: min(460px, 100%);
  text-align: center;
  align-items: center;
}

.eyebrow-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.chip-cyan {
  color: var(--cyan);
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.42);
}

.chip-mint {
  color: var(--mint);
  background: rgba(52, 211, 153, 0.14);
  border-color: rgba(52, 211, 153, 0.42);
}

.chip-amber {
  color: var(--amber);
  background: rgba(251, 191, 36, 0.14);
  border-color: rgba(251, 191, 36, 0.42);
}

.hero-title {
  margin: 0;
  font-size: clamp(1.32rem, 3.1vw, 1.95rem);
  font-weight: 900;
  letter-spacing: 0.03em;
  line-height: 1.1;
}

.modal-title {
  margin: 0;
  font-size: clamp(1.18rem, 2.5vw, 1.55rem);
  font-weight: 800;
}

.hero-copy,
.modal-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.title-stats,
.debrief-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.debrief-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-pill {
  background: rgba(6, 12, 28, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stat-k {
  font-size: 0.62rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

.stat-v {
  font-size: 1rem;
  font-weight: 800;
}

.mechanics-trio {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.mech-card {
  background: rgba(7, 13, 30, 0.88);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 10px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.mech-tag {
  font-size: 0.62rem;
  color: var(--cyan);
  font-weight: 700;
}

.mech-card strong {
  font-size: 0.82rem;
}

.mech-card span:last-child {
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.upgrade-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.upg-card {
  background: rgba(7, 13, 30, 0.92);
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 11px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.upg-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.upg-name {
  font-weight: 800;
  font-size: 0.88rem;
}

.upg-rank {
  font-size: 0.7rem;
  color: var(--mint);
  font-weight: 700;
}

.upg-desc {
  margin: 0;
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.upg-btn {
  margin-top: auto;
  border: 1px solid var(--amber);
  background: rgba(251, 191, 36, 0.16);
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 800;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.upg-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  border-color: rgba(148, 163, 184, 0.3);
  color: var(--text-muted);
  background: rgba(15, 25, 52, 0.6);
}

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn-primary-lg,
.btn-secondary-lg {
  flex: 1 1 200px;
  border-radius: 10px;
  padding: 11px 16px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  border: none;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}

.btn-primary-lg {
  background: linear-gradient(135deg, #38bdf8, #34d399);
  color: #031522;
  box-shadow: 0 8px 20px rgba(56, 189, 248, 0.32);
}

.btn-secondary-lg {
  background: rgba(15, 27, 56, 0.96);
  color: var(--text-main);
  border: 1px solid rgba(56, 189, 248, 0.45);
}

.btn-primary-lg:hover,
.btn-secondary-lg:hover {
  transform: translateY(-1px);
}

.tiny-hint {
  margin: 0;
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
}

/* ================= FOOTERS ================= */
.desktop-controls-bar {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 5px 12px;
  background: rgba(5, 10, 24, 0.96);
  border-top: 1px solid rgba(56, 189, 248, 0.24);
  font-size: 0.68rem;
  color: var(--text-muted);
}

.desktop-controls-bar strong {
  color: var(--cyan);
}

.touch-dock {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  background: rgba(5, 10, 24, 0.98);
  border-top: 1px solid var(--border-cyan);
  min-width: 0;
}

.touch-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.dpad-mid {
  display: flex;
  gap: 4px;
}

.touch-btn {
  border: 1px solid rgba(56, 189, 248, 0.42);
  background: rgba(14, 27, 56, 0.95);
  color: var(--text-main);
  font-family: inherit;
  font-weight: 800;
  border-radius: 9px;
  cursor: pointer;
  touch-action: manipulation;
}

.dpad-up,
.dpad-down,
.dpad-lr {
  width: 38px;
  height: 32px;
  font-size: 0.78rem;
}

.touch-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  flex: 1 1 auto;
  max-width: 220px;
  min-width: 0;
}

.touch-cycle,
.touch-node,
.touch-pulse,
.touch-dash {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 6px;
  font-size: 0.72rem;
  line-height: 1.1;
}

.touch-node {
  border-color: var(--mint);
  background: rgba(16, 185, 129, 0.2);
}

.touch-pulse {
  border-color: var(--amber);
  background: rgba(251, 191, 36, 0.2);
}

.touch-sub {
  font-size: 0.56rem;
  color: var(--text-muted);
}

/* ================= RESPONSIVE BREAKPOINTS ================= */
@media (max-height: 560px), (max-width: 720px) {
  .top-bar {
    padding: 4px 10px;
    gap: 6px;
  }

  .directive-strip {
    padding: 3px 10px;
  }

  .overlay-card {
    padding: 10px 14px;
    gap: 7px;
  }

  .hero-title {
    font-size: 1.15rem;
  }

  .hero-copy {
    font-size: 0.76rem;
    line-height: 1.3;
  }

  .mechanics-trio,
  .tiny-hint {
    display: none;
  }

  .stat-pill {
    padding: 5px 8px;
  }

  .stat-v {
    font-size: 0.88rem;
  }

  .btn-primary-lg,
  .btn-secondary-lg {
    padding: 8px 12px;
    font-size: 0.74rem;
  }
}

@media (max-width: 820px) {
  .hide-md {
    display: none;
  }
  .meter-box {
    width: 96px;
  }
  .dir-pill .dir-meta {
    display: none;
  }
}

@media (max-width: 560px) {
  .hide-sm {
    display: none;
  }
  .desktop-controls-bar {
    display: none;
  }
  .touch-dock {
    display: flex;
  }
  .upgrade-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 460px) {
  .hide-xs {
    display: none;
  }
  .top-bar {
    padding: 5px 8px;
    gap: 6px;
  }
  .hud-telemetry {
    gap: 6px;
  }
  .meter-box {
    width: 92px;
    padding: 3px 6px;
  }
  .brand-title {
    font-size: 0.86rem;
  }
  .title-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }
  .stat-v {
    font-size: 0.86rem;
  }
}
