
When a player middle-clicks a token to duplicate it, the clone is stacked locally but created as a free-floating entity on the remote peer's board. The remote sees the cloned token at coordinates 0px, 15px in #card-layer instead of nested inside the parent token.
Context
Token duplication via middle-click calls createToken(), which appends the new element to #card-layer and fires sendCreateMessage with coordinates 0px, 15px. Control then returns to the auxclick handler, which immediately re-parents the element into the parent token's DOM subtree. The remote peer processes the create-element message and places the clone in #card-layer at the transmitted coordinates — it never receives a stacking instruction. The result is a visual desync: the local player sees a neatly stacked token pile, while the remote player sees a stray token near the top-left corner of the board. This affects every token duplication in a two-player game.
Affected Files
src/scripts/token.js:64 — auxclick handler calls createToken then re-parents the returned element into the parent token, but sendCreateMessage already fired inside createToken with top-level coordinates
src/scripts/token.js:76 — createToken appends to #card-layer and sends P2P create message before the caller can relocate the element
src/scripts/p2p.js:159 — receiveMessage create-element for token places it in #card-layer — no stacking logic exists on the receive path
src/scripts/types.ts:31 — CreateElementMessage content payload has no field to express parent-child stacking relationships
Requirements

Verification
- npm test
- grep -n 'auxclick' src/scripts/token.js
- npm run typecheck
Not In Scope
Evidence
src/scripts/token.js:68-75 — auxclick handler calls createToken(tokenElement.firstElementChild.id, "0px", "15px"), which fires sendCreateMessage inside, then lastTokenInStack.appendChild(...) moves the element out of #card-layer — the remote never receives the re-parenting
src/scripts/token.js:76-83 — createToken unconditionally appends to #card-layer and calls sendCreateMessage with the raw x, y arguments before returning — no mechanism to defer or customize the P2P message
src/scripts/p2p.js:159-182 — receiveMessage create-element token handler calls createToken(...message.content) and places the result in #card-layer — no code path exists to nest the created token inside another token
Arasaka Queue Planning Division.

When a player middle-clicks a token to duplicate it, the clone is stacked locally but created as a free-floating entity on the remote peer's board. The remote sees the cloned token at coordinates
0px, 15pxin#card-layerinstead of nested inside the parent token.Context
Token duplication via middle-click calls
createToken(), which appends the new element to#card-layerand firessendCreateMessagewith coordinates0px, 15px. Control then returns to theauxclickhandler, which immediately re-parents the element into the parent token's DOM subtree. The remote peer processes thecreate-elementmessage and places the clone in#card-layerat the transmitted coordinates — it never receives a stacking instruction. The result is a visual desync: the local player sees a neatly stacked token pile, while the remote player sees a stray token near the top-left corner of the board. This affects every token duplication in a two-player game.Affected Files
src/scripts/token.js:64—auxclickhandler callscreateTokenthen re-parents the returned element into the parent token, butsendCreateMessagealready fired insidecreateTokenwith top-level coordinatessrc/scripts/token.js:76—createTokenappends to#card-layerand sends P2P create message before the caller can relocate the elementsrc/scripts/p2p.js:159—receiveMessagecreate-element for token places it in#card-layer— no stacking logic exists on the receive pathsrc/scripts/types.ts:31—CreateElementMessagecontent payload has no field to express parent-child stacking relationshipsRequirements
createTokencalls (from the token spawner panel) must continue to work without regressiontoken.test.jsmust verify that a middle-click clone sends a message containing the parent token referenceVerification
Not In Scope
sendCreateMessageecho-suppression problem (issue Suppress echosendCreateMessagewhen entities are created from incoming P2P messages #348)Evidence
src/scripts/token.js:68-75—auxclickhandler callscreateToken(tokenElement.firstElementChild.id, "0px", "15px"), which firessendCreateMessageinside, thenlastTokenInStack.appendChild(...)moves the element out of#card-layer— the remote never receives the re-parentingsrc/scripts/token.js:76-83—createTokenunconditionally appends to#card-layerand callssendCreateMessagewith the rawx, yarguments before returning — no mechanism to defer or customize the P2P messagesrc/scripts/p2p.js:159-182—receiveMessagecreate-element token handler callscreateToken(...message.content)and places the result in#card-layer— no code path exists to nest the created token inside another tokenArasaka Queue Planning Division.