Versus mode: attack vs defend (sim, bots, server, client)

One player defends, the other plays the Internet: earns credits over time and
spends them on packets, upgrades and sabotage. Two rounds with swapped roles,
timed (the faster fall wins). Built end to end, NOT yet QA'd or balanced.

Sim (public/js/sim.js, TD.VS table): attacker economy (income, lifetime bonus,
leak payback), spawn / stage / launch convoys, 7 tech tracks, abilities (EMP,
decoy, surge, DDoS), defender tools (scan, patch, repair, quarantine), role-checked
commands, round result, role-private state. Co-op/solo unchanged (24 scripted
games replay identically).

Bots (public/js/bot.js, tools/versus.js): defender (maze + turrets) and attacker
(budgeted spender reading the tower mix); headless bot-vs-bot runner.

Server (server/versus.js, protocol doc): versus rooms with lobby / countdown /
playing / roundover / matchover, role stamping, cross-role refusal, role-private
priv messages at 4 Hz, computer seat, freeze/forfeit rules, no pause/speed.

Client (public/js/versus.js): setup dialog (role, length, vs computer or online),
countdown, defender tools row, attacker unit shop with convoy + launch, tech and
abilities, gateway choice, round/match screens, sounds, phone-first dock rows.

Status and next steps (balance: the attacker currently wins ~100% of bot rounds;
QA with two browsers; layout matrix rerun) are in docs/NEXT.md and docs/VERSUS.md.
The full planned workflow incl. balance/QA prompts is in docs/workflows/versus-full.js.

253 unit tests pass; one smoke e2e run; no other e2e per the user's request.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
This commit is contained in:
Claude 2026-10-11 10:22:29 +00:00
parent b4ae6cb57d
commit 2098d59c1f
23 changed files with 6166 additions and 90 deletions

View file

@ -445,3 +445,134 @@ input.code { text-align: center; letter-spacing: .5em; font-family: var(--mono);
.overlay { background: Canvas; }
#side { border-color: CanvasText; }
}
/* ================================================================ versus (attack vs defend), see js/versus.js
* #app[data-mode="versus"] is set while a versus game runs, data-role="attacker|defender" for the current round. Nothing below applies to solo or co-op. */
.vs-only { display: none; }
#app[data-mode="versus"] #statTime { display: flex; }
#app[data-mode="versus"] #vIncome { display: inline; }
#app[data-mode="versus"] #statWave, #app[data-mode="versus"] #btnWave, #app[data-mode="versus"] #btnAuto, #app[data-mode="versus"] #btnSpeed,
#app[data-mode="versus"] #btnPause, #app[data-mode="versus"] #netChip { display: none !important; } /* no waves, no pause, no speed in versus; nobody to invite mid-match */
#statTime { font-variant-numeric: tabular-nums; }
#statTime.low { border-color: var(--red); color: var(--red); background: #2a0e18; animation: pulse 0.8s infinite; }
#vIncome { color: var(--green); font-size: 11px; margin-left: 2px; }
@media (max-width: 420px) { #app[data-mode="versus"] #vIncome { display: none; } }
#app[data-mode="versus"] #nextwave { display: none; }
/* stage overlays */
.vshud { position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 64px); padding: 3px 10px; border-radius: 999px; background: rgba(8, 13, 26, .82); border: 1px solid var(--line); font: 11.5px/1.4 var(--mono); color: var(--dim); pointer-events: none; z-index: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vsfx { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; pointer-events: none; z-index: 2; }
.fxchip { padding: 3px 10px; border-radius: 999px; font: 700 11px/1.4 var(--mono); background: rgba(8, 13, 26, .92); border: 1px solid; }
.fxchip.surge { color: var(--amber); border-color: #8a6a1a; } .fxchip.ddos { color: #c9a2ff; border-color: #5b3a8a; } .fxchip.freeze { color: #bfeaff; border-color: #3a7a9a; }
.vscount { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 2px; padding: 10px 14px; background: rgba(4, 7, 14, .6); pointer-events: none; z-index: 3; }
.vsc-top { font-size: 12px; letter-spacing: .22em; color: var(--dim); }
.vsc-role { font-size: clamp(22px, 6vw, 38px); font-weight: 800; letter-spacing: .12em; }
.vsc-role.att { color: var(--red); text-shadow: 0 0 22px rgba(255, 92, 122, .6); } .vsc-role.def { color: var(--cyan); text-shadow: 0 0 22px rgba(77, 227, 255, .6); }
.vsc-sub { max-width: 30em; font-size: 13px; color: #bcd3f5; margin: 2px 0 4px; }
.vsc-num { font: 800 clamp(40px, 12vw, 72px)/1 var(--mono); color: #fff; }
.vsc-big { font-size: clamp(22px, 6vw, 34px); font-weight: 800; letter-spacing: .2em; color: var(--amber); }
#vsNote { z-index: 4; }
/* the dock under the board: unit shop (the palette), convoy row, abilities / tools, tech */
.vsbar { display: flex; flex-direction: column; gap: 6px; }
.vsrow { display: flex; gap: 6px; align-items: stretch; }
.vsctlrow { flex-wrap: wrap; }
.vsctl { flex: 0 0 auto; min-height: 46px; padding: 0 7px; font: 700 13px var(--mono); white-space: nowrap; }
.vsctl.on { background: #0f3550; border-color: var(--cyan); color: var(--cyan); }
.vslaunch { flex: 1 1 112px; min-width: 0; min-height: 46px; padding: 0 10px; gap: 8px; font-size: 14px; justify-content: flex-start; }
.vslaunch .lt { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; line-height: 1.15; }
.vslaunch small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10.5px; font-weight: 500; opacity: .9; }
.vslaunch:not(:disabled) { animation: glow 1.6s infinite; }
.vslaunch:disabled, #vsSetup button.primary:disabled, #vsRoom button.primary:disabled, #vsEnd button.primary:disabled { background: #0c1426; border-color: #172540; color: #8da3c8; animation: none; }
.vsabil { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.vsbtn { position: relative; flex-direction: column; gap: 1px; padding: 4px 2px 3px; min-height: 48px; line-height: 1.1; overflow: hidden; }
.vsbtn .ic { width: 18px; height: 18px; }
.vsbtn .nm { font-size: 11px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.vsbtn .cost { font: 11.5px var(--mono); color: var(--amber); }
.vsbtn::after { content: ""; position: absolute; inset: 0; background: conic-gradient(rgba(4, 8, 16, .74) calc(var(--p, 0) * 1turn), transparent 0); pointer-events: none; }
.vsbtn .cd { position: absolute; inset: 0; z-index: 1; display: flex; align-items: center; justify-content: center; font: 700 15px var(--mono); color: #fff; text-shadow: 0 0 4px #000, 0 0 2px #000; pointer-events: none; }
.vsbtn.poor { color: #9fb2d4; } .vsbtn.poor .cost { color: #ff8fa3; } .vsbtn.idle { opacity: .55; }
.vsbtn.live { border-color: var(--amber); box-shadow: 0 0 0 2px rgba(255, 210, 77, .3); }
.vsbtn.armed { border-color: var(--cyan); background: #0f3550; box-shadow: inset 0 0 0 1px var(--cyan); }
.vsbtn.ready { border-color: var(--green); }
.vsbtn.confirm { border-color: var(--amber); background: #3a2c08; animation: glow 0.7s infinite; }
.vstech { display: block; }
.vshead { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; font-size: 11px; letter-spacing: .14em; color: var(--dim); text-transform: uppercase; font-weight: 600; }
.vshead small { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 11px; opacity: .85; }
.vstiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.techbtn { flex-direction: column; gap: 0; padding: 4px 2px 3px; min-height: 56px; }
.techbtn .ic { width: 18px; height: 18px; color: var(--cyan); }
.techbtn .nm { font-size: 11.5px; } .techbtn .pips { font-size: 9px; letter-spacing: 1px; color: var(--cyan); line-height: 1; min-height: 9px; }
.techbtn.maxed { border-color: #1c6a55; } .techbtn.maxed .cost { color: var(--green); }
.techbtn.poor .cost { color: #ff8fa3; } .techbtn.poor .ic { opacity: .6; }
.ubtn.hit { background: #0f3550; border-color: var(--cyan); }
#info .actions [data-act="emp"].poor .cost { color: #ff8fa3; }
/* a tower's panel for the attacker: just EMP and close */
#app[data-role="attacker"] #info .actions [data-act="emp"] { flex-grow: 2; }
/* stacked layouts: the dock is pinned to the bottom of the side panel (thumb reach), the tech row scrolls like the shop */
@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) {
#vsbar { position: sticky; bottom: 0; z-index: 2; margin: 0 -10px; padding: 6px 10px 8px; background: #0a101f; border-top: 1px solid var(--line); }
.vstiles { display: flex; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; margin: 0 -10px; padding: 0 10px; }
.vstiles::-webkit-scrollbar { display: none; }
.techbtn { flex: 0 0 76px; scroll-snap-align: start; }
#palette.shop .tbtn { flex: 0 0 72px; min-height: 66px; }
#palette.shop { padding-top: 6px; padding-bottom: 4px; }
#palette.shop .tbtn canvas { width: 30px; height: 30px; }
}
@media (min-width: 640px) and (orientation: portrait), (min-width: 640px) and (max-width: 760px) and (min-height: 521px) {
.vstiles { display: grid; overflow: visible; margin: 0; padding: 0; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
.techbtn { flex: none; }
}
/* short landscape: a 200 px column. Convoy controls wrap (Launch on its own row), abilities keep their four columns as icons + cost, the shop scrolls */
@media (orientation: landscape) and (max-height: 520px) {
#vsbar { position: sticky; bottom: 0; z-index: 2; margin: 0 -6px; padding: 5px 6px 6px; background: #0a101f; border-top: 1px solid var(--line); gap: 4px; }
.vsctlrow { flex-wrap: wrap; } .vsctl { min-height: 44px; flex: 1 1 0; padding: 0 4px; font-size: 12px; } .vslaunch { flex: 1 1 100%; min-height: 44px; }
.vsbtn { min-height: 44px; padding: 3px 1px; } .vsbtn .nm { display: none; } .vsbtn .cost { font-size: 11px; }
#palette.shop { max-height: calc(var(--tile-h) * 2.6 + 10px); }
.techbtn { min-height: 52px; padding: 3px 1px; } .techbtn .nm { font-size: 10px; } .vshead small { display: none; }
.vsfx { top: 4px; right: 4px; } .vshud { font-size: 10.5px; }
.vsc-sub { font-size: 12px; } .vsc-top { font-size: 10.5px; }
}
@media (max-width: 340px) { .vsctl { padding: 0 6px; font-size: 12px; } .vslaunch { padding: 0 8px; } }
/* dialogs */
.vsfield { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.vsfield .seg { flex: 1 1 auto; max-width: none; }
.flabel { flex: 0 0 104px; font-size: 12px; letter-spacing: .06em; color: var(--dim); }
@media (max-width: 480px) { .vsfield { flex-direction: column; align-items: stretch; gap: 3px; margin: 8px 0; } .flabel { flex: none; } }
.vsonline { margin-top: 12px; padding: 4px 12px 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, .02); }
.vsonline h3 { margin-top: 10px; }
@media (max-height: 640px) { .vsonline .field { margin: 6px 0; } #vsMapName { display: none; } .vsfield { margin: 6px 0; } } /* small phones: the map is the one picked in the menu (and visible behind) */
.vsroomhead { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; flex-wrap: wrap; }
.vsroomhead .rc { font: 800 22px var(--mono); letter-spacing: .2em; color: var(--cyan); }
.vsroomhead .link { margin-left: auto; }
.vsseat { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; margin-bottom: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.vsseat.empty { border-style: dashed; color: var(--dim); }
.vsseat .sn { flex: 1 1 80px; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.vsseat .you, #players .pl .you { color: var(--dim); font-size: 12px; } .vsseat .off { color: var(--red); font-size: 12px; }
.vsseat .rdy { font-size: 12px; color: var(--dim); } .vsseat .rdy.ok { color: var(--green); }
.rolebadge { font: 700 10.5px/1.5 var(--mono); letter-spacing: .1em; padding: 1px 7px; border-radius: 6px; border: 1px solid; margin-left: auto; }
.rolebadge.attacker { color: var(--red); border-color: #6a2336; } .rolebadge.defender { color: var(--cyan); border-color: #1c5a70; }
#players .pl .rolebadge { margin-left: auto; }
#btnVsReady.on { background: #0f3550; border-color: var(--cyan); color: var(--cyan); }
.vscols { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-top: 8px; }
.vsround { padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.vsround.pending { border-style: dashed; opacity: .75; }
.vsround h4, .vsscore h4 { margin: 0 0 6px; font-size: 11px; letter-spacing: .14em; color: var(--dim); text-transform: uppercase; font-weight: 600; }
.vsrow2 { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 3px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.vsrow2:last-child { border-bottom: 0; }
.vsrow2 > span { color: var(--dim); flex: none; } .vsrow2 > b { font-family: var(--mono); text-align: right; font-size: 12.5px; }
.vsrow2 .good { color: var(--green); } .vsrow2 .bad { color: var(--red); }
.vsrow2 .rolebadge { margin-left: 0; }
.vsscore { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
@media (orientation: landscape) and (max-height: 520px) { .vsfield { margin: 4px 0; } .vsonline { margin-top: 6px; padding: 2px 10px 8px; } .vsroomhead .rc { font-size: 18px; } .vsseat { padding: 5px 8px; margin-bottom: 4px; } }
@media (prefers-reduced-motion: reduce) { .vslaunch:not(:disabled), .vsbtn.confirm, #statTime.low { animation: none; } }
/* the menu's three modes: one row where it fits; on a phone Play solo has the row to itself and Co-op / Versus share the next one (the foot stays two rows tall) */
.row.modes > .big { flex: 1 1 150px; padding: 0 10px; white-space: nowrap; }
@media (max-width: 560px) {
.row.modes > #btnSolo { flex-basis: 100%; }
.row.modes > #btnCoop, .row.modes > #btnVersus { flex: 1 1 120px; font-size: 15px; }
.row.modes > #btnCoop .ic, .row.modes > #btnVersus .ic { display: none; }
}