                   (handle-access state side cards)
                   (resolve-ability state side (access-helper-remote cards) card nil)))})
 
-(defn access-helper-hq [cards]
+(defn access-helper-hq [from-hq from-root already-accessed]
   {:prompt "Select a card to access."
-   :choices (concat (when (some #(= (first (:zone %)) :hand) cards) ["Card from hand"])
-                    (map #(if (rezzed? %) (:title %) "Unrezzed upgrade in HQ")
-                         (filter #(= (last (:zone %)) :content) cards)))
+   :choices (concat (when (pos? from-hq) ["Card from hand"])
+                    (map #(if (rezzed? %) (:title %) "Unrezzed upgrade in HQ") from-root))
    :effect (req (case target
                   "Unrezzed upgrade in HQ"
                   ;; accessing an unrezzed upgrade

                      ;; only one unrezzed upgrade; access it and continue
                      (do (system-msg state side (str "accesses " (:title (first unrezzed))))
                          (handle-access state side unrezzed)
                          (when (< 1 (count cards))
                            (resolve-ability
                              state side (access-helper-hq (filter #(not= (:cid %) (:cid (first unrezzed))) cards))
                              card nil)))
                      ;; more than one unrezzed upgrade. allow user to select with mouse.
                      (resolve-ability state side
                                       {:prompt "Choose an upgrade in HQ to access."
                                        :choices {:req #(= (second (:zone %)) :hq)}
                                        :effect (effect (system-msg (str "accesses " (:title target)))
                                                        (handle-access [target])
                                                        (resolve-ability (access-helper-hq
                                                                           (remove-once #(not= (:cid %) (:cid target))
                                                                                        cards)) card nil))} card nil)))
                  ;; accessing a card in hand or a rezzed upgade
                  "Card from hand"
                  (do (system-msg state side (str "accesses " (:title (first cards))))
                      (handle-access state side [(first cards)])
                      (when (< 1 (count cards))
                        (resolve-ability state side (access-helper-hq (rest cards)) card nil)))
                  ;; accessing a rezzed upgrade
                  (do (system-msg state side (str "accesses " target))
                      (handle-access state side [(some #(when (= (:title %) target) %) cards)])
                      (when (< 1 (count cards))
                        (resolve-ability state side (access-helper-hq
                                                      (remove-once #(not= (:title %) target) cards)) card nil)))))})

(defmethod choose-access :hq [cards server]
  {:effect (req (if (pos? (count cards))
                  (if (= 1 (count cards))
                    (do (when (pos? (count cards)) (system-msg state side (str "accesses " (:title (first cards)))))
                        (handle-access state side cards))
                    (resolve-ability state side (access-helper-hq cards) card nil))))})

(defn access-helper-rd [cards]
  {:prompt "Select a card to access."


(defn access-count [state side kw]
  (let [run (:run @state)
        accesses (+ (get-in @state [:runner kw]) (:access-bonus run 0))]
    (if-let [max-access (:max-access run)]
      (min max-access accesses) accesses)))

