Index: trunk/src/org/openstreetmap/josm/gui/mappaint/Environment.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/Environment.java	(revision 8205)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/Environment.java	(revision 8206)
@@ -38,4 +38,9 @@
      */
     public Integer index = null;
+
+    /**
+     * count of nodes in parent way or members in parent relation. Must be != null in LINK context.
+     */
+    public Integer count = null;
 
     /**
@@ -69,4 +74,5 @@
         this.source = other.source;
         this.index = other.index;
+        this.count = other.count;
         this.context = other.getContext();
     }
@@ -99,4 +105,5 @@
      * @param parent the matching parent object
      * @param index index of node in parent way or member in parent relation
+     * @param count count of nodes in parent way or members in parent relation
      * @return A clone of this environment, with the specified parent, index, and context set to {@link Context#LINK}
      * @since 6175
@@ -104,8 +111,9 @@
      * @see #index
      */
-    public Environment withParentAndIndexAndLinkContext(OsmPrimitive parent, int index) {
+    public Environment withParentAndIndexAndLinkContext(OsmPrimitive parent, int index, int count) {
         Environment e = new Environment(this);
         e.parent = parent;
         e.index = index;
+        e.count = count;
         e.context = Context.LINK;
         return e;
@@ -128,4 +136,5 @@
      * @param child the matching child object
      * @param index index of node in parent way or member in parent relation
+     * @param count count of nodes in parent way or members in parent relation
      * @return A clone of this environment, with the specified child, index, and context set to {@code Context#LINK}
      * @since 6175
@@ -133,8 +142,9 @@
      * @see #index
      */
-    public Environment withChildAndIndexAndLinkContext(OsmPrimitive child, int index) {
+    public Environment withChildAndIndexAndLinkContext(OsmPrimitive child, int index, int count) {
         Environment e = new Environment(this);
         e.child = child;
         e.index = index;
+        e.count = count;
         e.context = Context.LINK;
         return e;
@@ -144,10 +154,12 @@
      * Creates a clone of this environment, with the specified index.
      * @param index index of node in parent way or member in parent relation
+     * @param count count of nodes in parent way or members in parent relation
      * @return A clone of this environment, with the specified index
      * @see #index
      */
-    public Environment withIndex(int index) {
+    public Environment withIndex(int index, int count) {
         Environment e = new Environment(this);
         e.index = index;
+        e.count = count;
         return e;
     }
@@ -214,4 +226,5 @@
         child = null;
         index = null;
+        count = null;
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java	(revision 8205)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java	(revision 8206)
@@ -271,5 +271,9 @@
         public boolean applies(Environment env) {
             if (env.index == null) return false;
-            return op.eval(Integer.toString(env.index + 1), index);
+            if (index.startsWith("-")) {
+                return env.count != null && op.eval(Integer.toString(env.index - env.count), index);
+            } else {
+                return op.eval(Integer.toString(env.index + 1), index);
+            }
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java	(revision 8205)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java	(revision 8206)
@@ -150,7 +150,8 @@
                     Node n = w.getNode(i);
                     if (n.equals(e.osm)) {
-                        if (link.matches(e.withParentAndIndexAndLinkContext(w, i))) {
+                        if (link.matches(e.withParentAndIndexAndLinkContext(w, i, w.getNodesCount()))) {
                             e.parent = w;
                             e.index = i;
+                            e.count = w.getNodesCount();
                             return;
                         }
@@ -172,7 +173,8 @@
                     RelationMember m = r.getMember(i);
                     if (m.getMember().equals(e.osm)) {
-                        if (link.matches(e.withParentAndIndexAndLinkContext(r, i))) {
+                        if (link.matches(e.withParentAndIndexAndLinkContext(r, i, r.getMembersCount()))) {
                             e.parent = r;
                             e.index = i;
+                            e.count = r.getMembersCount();
                             return;
                         }
@@ -329,4 +331,5 @@
                                 e.child = n;
                                 e.index = i;
+                                e.count = w.getNodesCount();
                                 e.parent = w;
                                 return true;
@@ -346,7 +349,9 @@
                         Node n = wayNodes.get(i);
                         if (left.matches(e.withPrimitive(n))) {
-                            if (link.matches(e.withChildAndIndexAndLinkContext(n, i))) {
+                            if (link.matches(e.withChildAndIndexAndLinkContext(n, i, wayNodes.size()))) {
+                                e = e.withChildAndIndexAndLinkContext(n, i, wayNodes.size());
                                 e.child = n;
                                 e.index = i;
+                                e.count = wayNodes.size();
                                 return true;
                             }
@@ -359,7 +364,8 @@
                         OsmPrimitive member = members.get(i).getMember();
                         if (left.matches(e.withPrimitive(member))) {
-                            if (link.matches(e.withChildAndIndexAndLinkContext(member, i))) {
+                            if (link.matches(e.withChildAndIndexAndLinkContext(member, i, members.size()))) {
                                 e.child = member;
                                 e.index = i;
+                                e.count = members.size();
                                 return true;
                             }
