3761 lines
107 KiB
Vue
3761 lines
107 KiB
Vue
<script setup lang="ts">
|
||
import { deckValidation, loadDecks, type SavedDeck } from '~/utils/decks'
|
||
import { loadPlaymatChoice, savePlaymatChoice, type PlaymatSelection } from '~/utils/playmat'
|
||
import { cardBackVars } from '~/utils/cardBack'
|
||
import { diffGameState, type GameAnimations } from '~/utils/gameAnimations'
|
||
|
||
interface TargetChoice {
|
||
kind: 'player' | 'object' | 'spell'
|
||
id: string
|
||
}
|
||
|
||
interface AbilityView {
|
||
index: number
|
||
kind: string
|
||
text?: string
|
||
/** Offered when the ability can produce more than one mana color. */
|
||
manaColors?: string[]
|
||
/** Legal targets for an activated ability. */
|
||
targets?: TargetChoice[]
|
||
}
|
||
|
||
interface CardView {
|
||
id: string
|
||
oracleId: string
|
||
name: string
|
||
typeLine: string
|
||
manaCost?: string
|
||
manaValue?: number
|
||
colors: string[]
|
||
colorIdentity: string[]
|
||
oracleText?: string
|
||
power?: number
|
||
toughness?: number
|
||
tapped: boolean
|
||
damage: number
|
||
counters: Record<string, number>
|
||
isToken: boolean
|
||
isCommander: boolean
|
||
zone: string
|
||
controller: string
|
||
owner: string
|
||
position?: { x: number; y: number }
|
||
attacking?: string
|
||
blockedBy: string[]
|
||
blocking?: string
|
||
chosenType?: string
|
||
hiddenCards?: number
|
||
faceDown?: boolean
|
||
/** Legal targets for a card in hand or the command zone. */
|
||
targets?: TargetChoice[]
|
||
abilities: AbilityView[]
|
||
playable?: boolean
|
||
}
|
||
|
||
interface PlayerView {
|
||
id: string
|
||
name: string
|
||
commander?: { oracleId: string; name: string }
|
||
playmat?: PlaymatView
|
||
life?: number
|
||
lost?: boolean
|
||
handCount?: number
|
||
libraryCount?: number
|
||
battlefield?: CardView[]
|
||
graveyard?: CardView[]
|
||
exile?: CardView[]
|
||
command?: CardView[]
|
||
commanderId?: string
|
||
commanderDamage?: { commanderId: string; commanderName: string; amount: number }[]
|
||
commanderCasts?: Record<string, number>
|
||
landPlayedThisTurn?: boolean
|
||
}
|
||
|
||
interface MatchView {
|
||
id: string
|
||
status: 'lobby' | 'active' | 'finished'
|
||
version: number
|
||
viewerId: string
|
||
hostId: string
|
||
maxPlayers: number
|
||
players: PlayerView[]
|
||
game?: {
|
||
turn: number
|
||
activePlayer: string
|
||
phase: string
|
||
step: string
|
||
priority: string
|
||
status: string
|
||
winner?: string
|
||
mulligans?: { player: string; count: number; kept: boolean; bottom: number }[]
|
||
stack: { id: string; kind: string; label: string; controller: string }[]
|
||
log: string[]
|
||
hand: CardView[]
|
||
manaPool: Record<string, number>
|
||
pendingChoice?: {
|
||
player: string
|
||
what: string
|
||
sourceId: string
|
||
sourceName: string
|
||
amount?: number
|
||
options: string[]
|
||
cards?: CardView[]
|
||
}
|
||
pendingSearch?: {
|
||
player: string
|
||
remaining: number
|
||
destination: string
|
||
cards: CardView[]
|
||
library?: CardView[]
|
||
}
|
||
}
|
||
}
|
||
|
||
interface MatchSummary {
|
||
id: string
|
||
hostName: string
|
||
status: 'lobby' | 'active' | 'finished'
|
||
playerCount: number
|
||
maxPlayers: number
|
||
players: string[]
|
||
}
|
||
|
||
interface Point {
|
||
x: number
|
||
y: number
|
||
}
|
||
|
||
interface Box {
|
||
center: Point
|
||
halfWidth: number
|
||
halfHeight: number
|
||
}
|
||
|
||
interface CombatArrow {
|
||
key: string
|
||
from: Point
|
||
to: Point
|
||
tone: 'attack' | 'block'
|
||
}
|
||
|
||
interface FloatingLabel {
|
||
id: number
|
||
targetId: string
|
||
text: string
|
||
tone: 'damage' | 'heal'
|
||
}
|
||
|
||
interface ManaBurst {
|
||
id: number
|
||
color: string
|
||
amount: number
|
||
}
|
||
|
||
type PlaymatView = { kind: 'card'; oracleId: string } | { kind: 'upload'; id: string }
|
||
|
||
definePageMeta({ middleware: 'auth' })
|
||
|
||
const { public: { apiBase } } = useRuntimeConfig()
|
||
const route = useRoute()
|
||
const gameId = computed(() => String(route.params.id))
|
||
const SESSION_PREFIX = 'commander-session-'
|
||
|
||
const state = ref<MatchView | null>(null)
|
||
const token = ref('')
|
||
const error = ref('')
|
||
const notice = ref('')
|
||
const busy = ref(false)
|
||
const autoPassInstants = ref(false)
|
||
const connection = ref<'connecting' | 'live' | 'reconnecting' | 'offline'>('connecting')
|
||
const castCardId = ref('')
|
||
const selectedTarget = ref('')
|
||
const castX = ref(0)
|
||
const castOverload = ref(false)
|
||
const pendingAbility = ref<{ card: CardView; ability: AbilityView; color?: string } | null>(null)
|
||
const abilityTarget = ref('')
|
||
const selectedAttackers = ref<string[]>([])
|
||
const attackTargets = reactive<Record<string, string>>({})
|
||
const attackDropId = ref('')
|
||
const blockSelection = reactive<Record<string, string>>({})
|
||
const blockDragLine = ref<{ from: Point; to: Point } | null>(null)
|
||
const blockDragId = ref('')
|
||
const blockHoverId = ref('')
|
||
const combatArrows = ref<CombatArrow[]>([])
|
||
const selectedCardId = ref('')
|
||
const menu = ref<{ cardId: string; x: number; y: number } | null>(null)
|
||
const menuEl = ref<HTMLElement | null>(null)
|
||
let menuTrigger: HTMLElement | null = null
|
||
const browsingZone = ref<{ playerId: string; zone: 'graveyard' | 'exile' } | null>(null)
|
||
const playmatOpen = ref(false)
|
||
const playmatBusy = ref(false)
|
||
let events: EventSource | undefined
|
||
|
||
const cardEnterAnimations = reactive<Record<string, number>>({})
|
||
const cardDamageAnimations = reactive<Record<string, number>>({})
|
||
const cardAttackAnimations = reactive<Record<string, number>>({})
|
||
const playerHitAnimations = reactive<Record<string, number>>({})
|
||
const playerHealAnimations = reactive<Record<string, number>>({})
|
||
const floatingLabels = ref<FloatingLabel[]>([])
|
||
const manaBursts = ref<ManaBurst[]>([])
|
||
const animationTimers = new Set<ReturnType<typeof setTimeout>>()
|
||
let previousState: MatchView | null = null
|
||
let animationCounter = 0
|
||
|
||
const tableEl = ref<HTMLElement | null>(null)
|
||
const canvasEl = ref<HTMLElement | null>(null)
|
||
const sidebarEl = ref<HTMLElement | null>(null)
|
||
const panning = ref(false)
|
||
const showLog = ref(true)
|
||
const menuOpen = ref(false)
|
||
const view = reactive({ x: 0, y: 0, scale: 1 })
|
||
const MIN_ZOOM = 0.5
|
||
const MAX_ZOOM = 2.5
|
||
const PILE_SIZE = 6
|
||
let panOrigin = { x: 0, y: 0, viewX: 0, viewY: 0 }
|
||
const dragPreview = ref<{ cardId: string; x: number; y: number } | null>(null)
|
||
let cardDrag: {
|
||
cardId: string
|
||
pointerId: number
|
||
board: HTMLElement
|
||
startX: number
|
||
startY: number
|
||
grabX: number
|
||
grabY: number
|
||
halfWidth: number
|
||
halfHeight: number
|
||
moved: boolean
|
||
} | null = null
|
||
let blockDrag: {
|
||
blockerId: string
|
||
pointerId: number
|
||
startX: number
|
||
startY: number
|
||
moved: boolean
|
||
} | null = null
|
||
let suppressCardClick = ''
|
||
|
||
const canvasStyle = computed(() => ({
|
||
transform: `translate(${view.x}px, ${view.y}px) scale(${view.scale})`,
|
||
}))
|
||
|
||
const decks = ref<SavedDeck[]>([])
|
||
const joinName = ref('')
|
||
const deckId = ref('')
|
||
const joining = ref(false)
|
||
const joinError = ref('')
|
||
const summary = ref<MatchSummary | null>(null)
|
||
|
||
const game = computed(() => state.value?.game)
|
||
const me = computed(() => state.value?.players.find(player => player.id === state.value?.viewerId))
|
||
const myPlaymat = computed(() => {
|
||
const playmat = me.value?.playmat
|
||
if (!playmat) return null
|
||
return playmat.kind === 'card'
|
||
? { kind: 'card' as const, oracleId: playmat.oracleId }
|
||
: { kind: 'upload' as const, url: `${apiBase}/playmats/${encodeURIComponent(playmat.id)}` }
|
||
})
|
||
const viewerId = computed(() => state.value?.viewerId ?? '')
|
||
const mulligan = computed(() => game.value?.status === 'mulligan'
|
||
? game.value.mulligans?.find(entry => entry.player === viewerId.value)
|
||
: undefined)
|
||
const mulliganBottom = computed(() => mulligan.value?.bottom ?? 0)
|
||
const mulliganWaiting = computed(() => (game.value?.mulligans ?? [])
|
||
.filter(entry => !entry.kept
|
||
&& !state.value?.players.find(player => player.id === entry.player)?.lost)
|
||
.map(entry => playerName(entry.player))
|
||
.join(', '))
|
||
const isHost = computed(() => state.value?.hostId === viewerId.value)
|
||
const emptySeats = computed(() => state.value ? state.value.maxPlayers - state.value.players.length : 0)
|
||
const opponents = computed(() => (state.value?.players ?? []).filter(player => player.id !== viewerId.value && !player.lost))
|
||
const canAct = computed(() => Boolean(state.value?.status === 'active'
|
||
&& game.value
|
||
&& !game.value.pendingSearch
|
||
&& !game.value.pendingChoice
|
||
&& game.value.priority === viewerId.value))
|
||
const isActive = computed(() => game.value?.activePlayer === viewerId.value)
|
||
const priorityName = computed(() => playerName(game.value?.priority))
|
||
const phaseLabel = computed(() => game.value
|
||
? `${game.value.phase.replaceAll('_', ' ')} · ${game.value.step.replaceAll('_', ' ')}`
|
||
: '')
|
||
const winnerName = computed(() => playerName(game.value?.winner))
|
||
const myBattlefield = computed(() => me.value?.battlefield ?? [])
|
||
const myUntappedCreatures = computed(() => myBattlefield.value.filter(card => /creature/i.test(card.typeLine) && !card.tapped))
|
||
const menuCard = computed(() => myBattlefield.value.find(card => card.id === menu.value?.cardId))
|
||
const incomingAttackers = computed(() => (state.value?.players ?? []).flatMap(player => (player.battlefield ?? [])
|
||
.filter(card => card.attacking === viewerId.value)
|
||
.map(card => ({ card, player }))))
|
||
const attackWindow = computed(() => Boolean(state.value?.status === 'active'
|
||
&& game.value
|
||
&& isActive.value
|
||
&& canAct.value
|
||
&& !game.value.stack.length
|
||
&& (game.value.phase === 'precombat_main'
|
||
|| (game.value.phase === 'combat' && game.value.step === 'declare_attackers'))))
|
||
const draggingAttackerId = computed(() => {
|
||
const cardId = dragPreview.value?.cardId
|
||
if (!attackWindow.value || !cardId) return ''
|
||
return myUntappedCreatures.value.some(card => card.id === cardId) ? cardId : ''
|
||
})
|
||
const blockWindow = computed(() => Boolean(state.value?.status === 'active'
|
||
&& game.value
|
||
&& !game.value.pendingSearch
|
||
&& !game.value.pendingChoice
|
||
&& game.value.step === 'declare_blockers'
|
||
&& game.value.priority === viewerId.value))
|
||
const instantWindow = computed(() => {
|
||
const current = game.value
|
||
if (!current || !canAct.value) return false
|
||
const mainPhase = current.phase === 'precombat_main' || current.phase === 'postcombat_main'
|
||
if (mainPhase && !current.stack.length) return false
|
||
if (!current.stack.length && attackWindow.value && myUntappedCreatures.value.length) return false
|
||
if (!current.stack.length && blockWindow.value && incomingAttackers.value.length
|
||
&& myUntappedCreatures.value.length) return false
|
||
return true
|
||
})
|
||
const castCard = computed(() => {
|
||
if (!state.value || !castCardId.value) return undefined
|
||
return state.value.game?.hand.find(card => card.id === castCardId.value)
|
||
?? me.value?.command?.find(card => card.id === castCardId.value)
|
||
?? me.value?.exile?.find(card => card.id === castCardId.value)
|
||
})
|
||
const overloadAbility = computed(() => castCard.value?.abilities.find(ability => ability.kind === 'overload'))
|
||
const castTargetOptions = computed(() => targetOptionsFor(castCard.value?.targets))
|
||
const castNeedsTarget = computed(() => Boolean(castCard.value?.targets?.length) && !castOverload.value)
|
||
const abilityTargetOptions = computed(() => targetOptionsFor(pendingAbility.value?.ability.targets))
|
||
const pendingSearch = computed(() => game.value?.pendingSearch)
|
||
const searchFilter = ref('')
|
||
const searchInput = ref<HTMLInputElement | null>(null)
|
||
const searchLegalIds = computed(() => new Set(pendingSearch.value?.cards.map(card => card.id) ?? []))
|
||
const searchLibrary = computed(() => pendingSearch.value?.library ?? pendingSearch.value?.cards ?? [])
|
||
const filteredSearchLibrary = computed(() => {
|
||
const query = searchFilter.value.trim().toLowerCase()
|
||
return query
|
||
? searchLibrary.value.filter(card => card.name.toLowerCase().includes(query))
|
||
: searchLibrary.value
|
||
})
|
||
const pendingChoice = computed(() => game.value?.pendingChoice)
|
||
const pendingCostLabel = computed(() => pendingChoice.value?.amount === undefined
|
||
? 'the cost'
|
||
: `${pendingChoice.value.amount} life`)
|
||
const choiceFilter = ref('')
|
||
const choiceInput = ref<HTMLInputElement | null>(null)
|
||
const filteredChoiceOptions = computed(() => {
|
||
const query = choiceFilter.value.trim().toLowerCase()
|
||
return query
|
||
? (pendingChoice.value?.options ?? []).filter(option => option.toLowerCase().includes(query))
|
||
: (pendingChoice.value?.options ?? [])
|
||
})
|
||
const browseView = computed(() => {
|
||
const zone = browsingZone.value
|
||
const player = state.value?.players.find(entry => entry.id === zone?.playerId)
|
||
if (!zone || !player) return null
|
||
return {
|
||
zone: zone.zone,
|
||
title: `${player.name}'s ${zone.zone}`,
|
||
cards: (zone.zone === 'graveyard' ? player.graveyard : player.exile) ?? [],
|
||
}
|
||
})
|
||
const sidebarOpen = computed(() => Boolean((pendingSearch.value && pendingSearch.value.player !== viewerId.value)
|
||
|| (pendingChoice.value && pendingChoice.value.player !== viewerId.value)
|
||
|| castCard.value
|
||
|| pendingAbility.value
|
||
|| browseView.value
|
||
|| playmatOpen.value
|
||
|| attackWindow.value
|
||
|| blockWindow.value
|
||
|| showLog.value))
|
||
const searchDestination = computed(() => {
|
||
switch (pendingSearch.value?.destination) {
|
||
case 'hand': return 'into your hand'
|
||
case 'graveyard': return 'into your graveyard'
|
||
case 'top': return 'on top of your library'
|
||
case 'bottom': return 'on the bottom of your library'
|
||
default: return 'onto the battlefield'
|
||
}
|
||
})
|
||
const targetOptions = computed(() => {
|
||
const options = [{ value: '', label: 'Auto (first legal target)' }]
|
||
for (const player of state.value?.players ?? []) {
|
||
options.push({ value: `player:${player.id}`, label: player.name })
|
||
}
|
||
for (const player of state.value?.players ?? []) {
|
||
for (const card of player.battlefield ?? []) {
|
||
options.push({ value: `object:${card.id}`, label: `${card.name} (${player.name})` })
|
||
}
|
||
}
|
||
for (const item of game.value?.stack ?? []) {
|
||
options.push({ value: `spell:${item.id}`, label: `Spell: ${item.label}` })
|
||
}
|
||
return options
|
||
})
|
||
|
||
function visibleCard(id: string): CardView | undefined {
|
||
for (const player of state.value?.players ?? []) {
|
||
const card = player.battlefield?.find(entry => entry.id === id)
|
||
?? player.graveyard?.find(entry => entry.id === id)
|
||
?? player.exile?.find(entry => entry.id === id)
|
||
?? player.command?.find(entry => entry.id === id)
|
||
if (card) return card
|
||
}
|
||
return state.value?.game?.hand.find(entry => entry.id === id)
|
||
}
|
||
|
||
function targetLabel(target: TargetChoice): string {
|
||
if (target.kind === 'player') return playerName(target.id)
|
||
if (target.kind === 'spell') {
|
||
const item = game.value?.stack.find(entry => entry.id === target.id)
|
||
return item ? `Spell: ${item.label}` : 'Spell'
|
||
}
|
||
const card = visibleCard(target.id)
|
||
return card ? `${card.name} (${playerName(card.controller)})` : 'Card'
|
||
}
|
||
|
||
function targetOptionsFor(targets: TargetChoice[] | undefined): { value: string; label: string }[] {
|
||
if (!targets) return targetOptions.value
|
||
const options = [{ value: '', label: 'Auto (first legal target)' }]
|
||
for (const target of targets) {
|
||
options.push({ value: `${target.kind}:${target.id}`, label: targetLabel(target) })
|
||
}
|
||
return options
|
||
}
|
||
const connectionClass = computed(() => connection.value === 'live' ? 'good' : connection.value === 'offline' ? 'bad' : '')
|
||
|
||
function playerName(id?: string): string {
|
||
if (!id) return 'nobody'
|
||
return state.value?.players.find(player => player.id === id)?.name ?? id
|
||
}
|
||
|
||
function isLand(card: CardView): boolean {
|
||
return /\bland\b/i.test(card.typeLine)
|
||
}
|
||
|
||
function activatedAbilities(card: CardView): AbilityView[] {
|
||
return card.abilities.filter(ability => ability.kind === 'activated')
|
||
}
|
||
|
||
const MANA_COLOR_NAMES: Record<string, string> = {
|
||
W: 'white',
|
||
U: 'blue',
|
||
B: 'black',
|
||
R: 'red',
|
||
G: 'green',
|
||
C: 'colorless',
|
||
}
|
||
|
||
function toggleCard(card: CardView, event?: MouseEvent | KeyboardEvent) {
|
||
if (suppressCardClick === card.id) {
|
||
suppressCardClick = ''
|
||
return
|
||
}
|
||
// While choosing a target, clicking a legal creature picks it.
|
||
const targets = castCard.value ? castCard.value.targets : pendingAbility.value?.ability.targets
|
||
if (targets?.some(target => target.kind === 'object' && target.id === card.id)) {
|
||
if (castCard.value) selectedTarget.value = `object:${card.id}`
|
||
else abilityTarget.value = `object:${card.id}`
|
||
return
|
||
}
|
||
const open = selectedCardId.value !== card.id
|
||
selectedCardId.value = open ? card.id : ''
|
||
if (!open || card.controller !== viewerId.value || !activatedAbilities(card).length) {
|
||
menu.value = null
|
||
return
|
||
}
|
||
const rect = (event?.currentTarget as HTMLElement | null)?.getBoundingClientRect()
|
||
const x = event instanceof MouseEvent ? event.clientX : (rect?.left ?? 0) + (rect?.width ?? 0) / 2
|
||
const y = event instanceof MouseEvent ? event.clientY : rect?.bottom ?? 0
|
||
menuTrigger = event?.currentTarget as HTMLElement ?? null
|
||
menu.value = {
|
||
cardId: card.id,
|
||
x: Math.max(8, Math.min(x, window.innerWidth - 280)),
|
||
y: Math.max(8, Math.min(y, window.innerHeight - 56 - activatedAbilities(card).length * 34)),
|
||
}
|
||
nextTick(() => menuEl.value?.querySelector('button:not(:disabled)')?.focus())
|
||
}
|
||
|
||
function closeMenu() {
|
||
const trigger = menuTrigger
|
||
menuTrigger = null
|
||
menu.value = null
|
||
selectedCardId.value = ''
|
||
trigger?.focus()
|
||
}
|
||
|
||
function onKeydown(event: KeyboardEvent) {
|
||
if (event.key === 'Escape' && menu.value) closeMenu()
|
||
}
|
||
|
||
function toggleZone(player: PlayerView, zone: 'graveyard' | 'exile') {
|
||
const current = browsingZone.value
|
||
const same = current?.playerId === player.id && current.zone === zone
|
||
browsingZone.value = same ? null : { playerId: player.id, zone }
|
||
if (!same) nextTick(() => sidebarEl.value?.scrollTo({ top: 0 }))
|
||
}
|
||
|
||
function playmatUrl(player: PlayerView): string | undefined {
|
||
const playmat = player.playmat
|
||
if (!playmat) return undefined
|
||
return playmat.kind === 'card'
|
||
? `${apiBase}/cards/${encodeURIComponent(playmat.oracleId)}/art`
|
||
: `${apiBase}/playmats/${encodeURIComponent(playmat.id)}`
|
||
}
|
||
|
||
function playmatStyle(player: PlayerView) {
|
||
const url = playmatUrl(player)
|
||
return url ? { '--playmat': `url("${url}")` } : undefined
|
||
}
|
||
|
||
const cardBackStyle = computed(() =>
|
||
cardBackVars(decks.value.find(deck => deck.id === deckId.value)?.cardBack),
|
||
)
|
||
|
||
function togglePlaymat() {
|
||
playmatOpen.value = !playmatOpen.value
|
||
if (playmatOpen.value) nextTick(() => sidebarEl.value?.scrollTo({ top: 0 }))
|
||
}
|
||
|
||
async function savePlaymat(playmat: PlaymatSelection): Promise<boolean> {
|
||
playmatBusy.value = true
|
||
error.value = ''
|
||
try {
|
||
await $fetch(`${apiBase}/games/${gameId.value}/playmat`, {
|
||
method: 'POST',
|
||
body: { token: token.value, playmat },
|
||
})
|
||
if (playmat.kind === 'card') await savePlaymatChoice(apiBase, { kind: 'card', oracleId: playmat.oracleId })
|
||
else if (playmat.kind === 'upload') await savePlaymatChoice(apiBase, { kind: 'upload', data: playmat.data })
|
||
else await savePlaymatChoice(apiBase, undefined)
|
||
playmatOpen.value = false
|
||
return true
|
||
} catch (caught) {
|
||
error.value = errorMessage(caught)
|
||
return false
|
||
} finally {
|
||
playmatBusy.value = false
|
||
}
|
||
}
|
||
|
||
function commanderTax(player: PlayerView, card: CardView): number {
|
||
return (player.commanderCasts?.[card.id] ?? 0) * 2
|
||
}
|
||
|
||
function blockerName(blockerId: string): string {
|
||
return myBattlefield.value.find(card => card.id === blockerId)?.name ?? 'Creature'
|
||
}
|
||
|
||
function assignBlock(attackerId: string, blockerId: string) {
|
||
for (const [attacker, blocker] of Object.entries(blockSelection)) {
|
||
if (blocker === blockerId) delete blockSelection[attacker]
|
||
}
|
||
blockSelection[attackerId] = blockerId
|
||
}
|
||
|
||
function removeBlock(attackerId: string) {
|
||
delete blockSelection[attackerId]
|
||
}
|
||
|
||
function blockTargetAt(x: number, y: number): string {
|
||
for (const element of document.elementsFromPoint(x, y)) {
|
||
const id = element.closest<HTMLElement>('.perm')?.dataset.cardId
|
||
if (id && incomingAttackers.value.some(entry => entry.card.id === id)) return id
|
||
}
|
||
return ''
|
||
}
|
||
|
||
/** Board-space box (the canvas is transformed, the SVG inside it is not). */
|
||
function elementBox(element: Element | null | undefined): Box | null {
|
||
const canvas = canvasEl.value
|
||
if (!canvas || !element) return null
|
||
const rect = element.getBoundingClientRect()
|
||
const base = canvas.getBoundingClientRect()
|
||
const scale = view.scale || 1
|
||
return {
|
||
center: {
|
||
x: (rect.left + rect.width / 2 - base.left) / scale,
|
||
y: (rect.top + rect.height / 2 - base.top) / scale,
|
||
},
|
||
halfWidth: rect.width / 2 / scale,
|
||
halfHeight: rect.height / 2 / scale,
|
||
}
|
||
}
|
||
|
||
function cardBox(cardId: string): Box | null {
|
||
const cards = canvasEl.value?.querySelectorAll<HTMLElement>('[data-card-id]') ?? []
|
||
return elementBox([...cards].find(element => element.dataset.cardId === cardId))
|
||
}
|
||
|
||
function playerHeadBox(playerId: string): Box | null {
|
||
const players = canvasEl.value?.querySelectorAll<HTMLElement>('.player[data-player-id]') ?? []
|
||
const player = [...players].find(element => element.dataset.playerId === playerId)
|
||
return elementBox(player?.querySelector('.player-head'))
|
||
}
|
||
|
||
/** Point on the box border facing `toward`, with a small gap so the arrowhead stays visible. */
|
||
function edgePoint(box: Box, toward: Point): Point {
|
||
const dx = toward.x - box.center.x
|
||
const dy = toward.y - box.center.y
|
||
const length = Math.hypot(dx, dy)
|
||
if (!length) return { ...box.center }
|
||
const ux = dx / length
|
||
const uy = dy / length
|
||
const reach = Math.min(
|
||
ux ? box.halfWidth / Math.abs(ux) : Infinity,
|
||
uy ? box.halfHeight / Math.abs(uy) : Infinity,
|
||
)
|
||
return {
|
||
x: box.center.x + ux * (reach + 8),
|
||
y: box.center.y + uy * (reach + 8),
|
||
}
|
||
}
|
||
|
||
function pointerPoint(x: number, y: number): Point | null {
|
||
const canvas = canvasEl.value
|
||
if (!canvas) return null
|
||
const rect = canvas.getBoundingClientRect()
|
||
const scale = view.scale || 1
|
||
return { x: (x - rect.left) / scale, y: (y - rect.top) / scale }
|
||
}
|
||
|
||
function refreshCombatArrows() {
|
||
if (!blockWindow.value) {
|
||
combatArrows.value = []
|
||
return
|
||
}
|
||
const arrows: CombatArrow[] = []
|
||
const head = playerHeadBox(viewerId.value)
|
||
for (const { card } of incomingAttackers.value) {
|
||
const attacker = cardBox(card.id)
|
||
if (!attacker || !head) continue
|
||
arrows.push({
|
||
key: `attack-${card.id}`,
|
||
from: edgePoint(attacker, head.center),
|
||
to: edgePoint(head, attacker.center),
|
||
tone: 'attack',
|
||
})
|
||
}
|
||
for (const [attackerId, blockerId] of Object.entries(blockSelection)) {
|
||
if (!blockerId) continue
|
||
const attacker = cardBox(attackerId)
|
||
const blocker = cardBox(blockerId)
|
||
if (!attacker || !blocker) continue
|
||
arrows.push({
|
||
key: `block-${attackerId}-${blockerId}`,
|
||
from: edgePoint(blocker, attacker.center),
|
||
to: edgePoint(attacker, blocker.center),
|
||
tone: 'block',
|
||
})
|
||
}
|
||
combatArrows.value = arrows
|
||
}
|
||
|
||
function arrowPath(from: Point, to: Point): string {
|
||
const dx = to.x - from.x
|
||
const dy = to.y - from.y
|
||
const length = Math.hypot(dx, dy) || 1
|
||
const bend = Math.min(80, length * 0.12)
|
||
const mx = (from.x + to.x) / 2 - (dy / length) * bend
|
||
const my = (from.y + to.y) / 2 + (dx / length) * bend
|
||
return `M ${from.x.toFixed(1)} ${from.y.toFixed(1)} Q ${mx.toFixed(1)} ${my.toFixed(1)} ${to.x.toFixed(1)} ${to.y.toFixed(1)}`
|
||
}
|
||
|
||
function parseTarget(value: string): { kind: 'player' | 'object' | 'spell'; id: string } | null {
|
||
const separator = value.indexOf(':')
|
||
if (separator < 0) return null
|
||
const kind = value.slice(0, separator)
|
||
const id = value.slice(separator + 1)
|
||
if (!id || (kind !== 'player' && kind !== 'object' && kind !== 'spell')) return null
|
||
return { kind, id }
|
||
}
|
||
|
||
async function act(action: Record<string, unknown>): Promise<boolean> {
|
||
if (!token.value) return false
|
||
busy.value = true
|
||
error.value = ''
|
||
try {
|
||
await $fetch(`${apiBase}/games/${gameId.value}/actions`, {
|
||
method: 'POST',
|
||
body: { token: token.value, action },
|
||
})
|
||
return true
|
||
} catch (caught) {
|
||
error.value = errorMessage(caught)
|
||
return false
|
||
} finally {
|
||
busy.value = false
|
||
}
|
||
}
|
||
|
||
let autoPassedVersion = -1
|
||
|
||
async function maybeAutoPass() {
|
||
if (busy.value || !autoPassInstants.value || !instantWindow.value) return
|
||
const version = state.value?.version ?? -1
|
||
if (version === autoPassedVersion) return
|
||
autoPassedVersion = version
|
||
await act({ type: 'pass' })
|
||
}
|
||
|
||
watch(autoPassInstants, enabled => {
|
||
if (enabled) autoPassedVersion = -1
|
||
void maybeAutoPass()
|
||
})
|
||
watch([() => state.value?.version, busy], () => { void maybeAutoPass() })
|
||
|
||
async function loadSummary() {
|
||
try {
|
||
const data = await $fetch<{ games: MatchSummary[] }>(`${apiBase}/games`)
|
||
summary.value = data.games.find(entry => entry.id === gameId.value) ?? null
|
||
} catch {
|
||
summary.value = null
|
||
}
|
||
}
|
||
|
||
async function connect() {
|
||
if (!token.value) return
|
||
connection.value = 'connecting'
|
||
try {
|
||
const next = await $fetch<MatchView>(`${apiBase}/games/${gameId.value}/state`, {
|
||
query: { token: token.value },
|
||
})
|
||
applyState(next, false)
|
||
} catch (caught) {
|
||
error.value = errorMessage(caught)
|
||
token.value = ''
|
||
connection.value = 'offline'
|
||
return
|
||
}
|
||
const seated = state.value?.players.find(player => player.id === state.value?.viewerId)
|
||
const seatedDeck = decks.value.find(deck => deck.commander.oracleId === seated?.commander?.oracleId)
|
||
if (seatedDeck) deckId.value = seatedDeck.id
|
||
|
||
events?.close()
|
||
events = new EventSource(`${apiBase}/games/${gameId.value}/events?token=${encodeURIComponent(token.value)}`)
|
||
events.onopen = () => { connection.value = 'live' }
|
||
events.onmessage = (event) => {
|
||
try {
|
||
const next = JSON.parse(event.data) as MatchView
|
||
applyState(next)
|
||
connection.value = 'live'
|
||
} catch {
|
||
// Ignore malformed keepalive frames.
|
||
}
|
||
}
|
||
events.onerror = () => { connection.value = 'reconnecting' }
|
||
}
|
||
|
||
function deckPayload(deck: SavedDeck) {
|
||
return {
|
||
commander: deck.commander.oracleId,
|
||
cards: deck.cards.map(card => card.oracleId),
|
||
}
|
||
}
|
||
|
||
async function joinGame() {
|
||
const deck = decks.value.find(entry => entry.id === deckId.value)
|
||
if (!deck) {
|
||
joinError.value = 'Choose a deck.'
|
||
return
|
||
}
|
||
joining.value = true
|
||
joinError.value = ''
|
||
try {
|
||
const data = await $fetch<{ matchId: string; playerId: string; token: string }>(
|
||
`${apiBase}/games/${gameId.value}/join`,
|
||
{
|
||
method: 'POST',
|
||
body: {
|
||
name: joinName.value,
|
||
deck: deckPayload(deck),
|
||
playmat: await loadPlaymatChoice(apiBase),
|
||
},
|
||
},
|
||
)
|
||
sessionStorage.setItem(`${SESSION_PREFIX}${gameId.value}`, JSON.stringify(data))
|
||
token.value = data.token
|
||
await connect()
|
||
} catch (caught) {
|
||
joinError.value = errorMessage(caught)
|
||
} finally {
|
||
joining.value = false
|
||
}
|
||
}
|
||
|
||
async function changeDeck() {
|
||
const deck = decks.value.find(entry => entry.id === deckId.value)
|
||
if (!deck) return
|
||
busy.value = true
|
||
error.value = ''
|
||
notice.value = ''
|
||
try {
|
||
await $fetch(`${apiBase}/games/${gameId.value}/deck`, {
|
||
method: 'POST',
|
||
body: { token: token.value, deck: deckPayload(deck) },
|
||
})
|
||
notice.value = `Deck changed to ${deck.name}.`
|
||
} catch (caught) {
|
||
error.value = errorMessage(caught)
|
||
} finally {
|
||
busy.value = false
|
||
}
|
||
}
|
||
|
||
async function startGame() {
|
||
busy.value = true
|
||
error.value = ''
|
||
try {
|
||
await $fetch(`${apiBase}/games/${gameId.value}/start`, {
|
||
method: 'POST',
|
||
body: { token: token.value },
|
||
})
|
||
} catch (caught) {
|
||
error.value = errorMessage(caught)
|
||
} finally {
|
||
busy.value = false
|
||
}
|
||
}
|
||
|
||
function menuAction(action: () => void) {
|
||
menuOpen.value = false
|
||
action()
|
||
}
|
||
|
||
async function leaveGame() {
|
||
busy.value = true
|
||
error.value = ''
|
||
const forfeited = state.value?.status === 'active'
|
||
try {
|
||
await $fetch(`${apiBase}/games/${gameId.value}/leave`, {
|
||
method: 'POST',
|
||
body: { token: token.value },
|
||
})
|
||
sessionStorage.removeItem(`${SESSION_PREFIX}${gameId.value}`)
|
||
events?.close()
|
||
events = undefined
|
||
resetAnimations()
|
||
state.value = null
|
||
token.value = ''
|
||
connection.value = 'offline'
|
||
if (forfeited) {
|
||
await navigateTo('/')
|
||
return
|
||
}
|
||
notice.value = 'You left the game.'
|
||
await loadSummary()
|
||
} catch (caught) {
|
||
error.value = errorMessage(caught)
|
||
} finally {
|
||
busy.value = false
|
||
}
|
||
}
|
||
|
||
async function playLand(card: CardView) {
|
||
await act({ type: 'play_land', cardId: card.id })
|
||
}
|
||
|
||
async function keepHand() {
|
||
await act({ type: 'keep_hand' })
|
||
}
|
||
|
||
async function takeMulligan() {
|
||
await act({ type: 'mulligan' })
|
||
}
|
||
|
||
/** Cards with choices need the cast panel; everything else plays on click. */
|
||
function needsCastOptions(card: CardView): boolean {
|
||
return Boolean(card.manaCost?.includes('X') || /\btarget|choose (one|two|three)/i.test(card.oracleText ?? ''))
|
||
}
|
||
|
||
async function playCard(card: CardView) {
|
||
if (busy.value) return
|
||
if (mulliganBottom.value > 0) {
|
||
await act({ type: 'mulligan_bottom', cardId: card.id })
|
||
return
|
||
}
|
||
if (!card.playable) return
|
||
cancelCast()
|
||
if (isLand(card)) {
|
||
await playLand(card)
|
||
return
|
||
}
|
||
if (needsCastOptions(card) || card.targets?.length) {
|
||
openCast(card)
|
||
return
|
||
}
|
||
await act({ type: 'cast', cardId: card.id, targets: [], x: 0 })
|
||
}
|
||
|
||
/** Impulse cards are cast or played from the exile browser. */
|
||
async function playExiled(card: CardView) {
|
||
browsingZone.value = null
|
||
await playCard(card)
|
||
}
|
||
|
||
/** Place a hand card on the fan: spread, tilt and arc drop around the middle card. */
|
||
function fanStyle(index: number, total: number) {
|
||
const offset = index - (total - 1) / 2
|
||
const step = Math.min(3.4, 30 / Math.max(total, 1))
|
||
const angle = offset * Math.min(5, 36 / Math.max(total, 1))
|
||
const drop = Math.min(2.5, Math.abs(offset) ** 1.7 * 0.18)
|
||
return {
|
||
'--angle': `${angle.toFixed(2)}deg`,
|
||
transform: `translateX(calc(-50% + ${(offset * step).toFixed(3)}em)) translateY(${drop.toFixed(3)}em) rotate(${angle.toFixed(2)}deg)`,
|
||
}
|
||
}
|
||
|
||
function startPan(event: PointerEvent) {
|
||
// Touch keeps native scrolling; drag-to-pan is for mice and pens.
|
||
if (event.pointerType === 'touch' || event.button !== 0) return
|
||
if ((event.target as HTMLElement).closest('button, a, input, select, textarea, [role="button"]')) return
|
||
panOrigin = { x: event.clientX, y: event.clientY, viewX: view.x, viewY: view.y }
|
||
panning.value = true
|
||
tableEl.value?.setPointerCapture(event.pointerId)
|
||
}
|
||
|
||
function movePan(event: PointerEvent) {
|
||
if (!panning.value) return
|
||
view.x = panOrigin.viewX + event.clientX - panOrigin.x
|
||
view.y = panOrigin.viewY + event.clientY - panOrigin.y
|
||
}
|
||
|
||
function endPan(event: PointerEvent) {
|
||
if (!panning.value) return
|
||
panning.value = false
|
||
const el = tableEl.value
|
||
if (el?.hasPointerCapture(event.pointerId)) el.releasePointerCapture(event.pointerId)
|
||
}
|
||
|
||
/** Zoom toward the cursor, so the card under the pointer stays put. */
|
||
function zoomTable(event: WheelEvent) {
|
||
const el = tableEl.value
|
||
if (!el) return
|
||
const delta = event.deltaY * (event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? 100 : 1)
|
||
const scale = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, view.scale * Math.exp(-delta * 0.0015)))
|
||
if (scale === view.scale) return
|
||
const rect = el.getBoundingClientRect()
|
||
const x = event.clientX - rect.left
|
||
const y = event.clientY - rect.top
|
||
view.x = x - (x - view.x) * (scale / view.scale)
|
||
view.y = y - (y - view.y) * (scale / view.scale)
|
||
view.scale = scale
|
||
}
|
||
|
||
function resetView() {
|
||
view.x = 0
|
||
view.y = 0
|
||
view.scale = 1
|
||
}
|
||
|
||
function isPositioned(card: CardView): boolean {
|
||
return dragPreview.value?.cardId === card.id || Boolean(card.position)
|
||
}
|
||
|
||
function permStyle(card: CardView) {
|
||
const position = dragPreview.value?.cardId === card.id ? dragPreview.value : card.position
|
||
if (!position) return undefined
|
||
return { left: `${position.x * 100}%`, top: `${position.y * 100}%` }
|
||
}
|
||
|
||
/** Drag a permanent you control; positions are stored as a normalized board center. */
|
||
function startCardMove(card: CardView, event: PointerEvent) {
|
||
if (event.button !== 0 || card.controller !== viewerId.value || state.value?.status !== 'active') return
|
||
const perm = event.currentTarget as HTMLElement
|
||
const board = perm.closest('.battlefield') as HTMLElement | null
|
||
if (!board) return
|
||
event.stopPropagation()
|
||
perm.setPointerCapture(event.pointerId)
|
||
if (blockWindow.value
|
||
&& incomingAttackers.value.length
|
||
&& myUntappedCreatures.value.some(entry => entry.id === card.id)) {
|
||
blockDrag = {
|
||
blockerId: card.id,
|
||
pointerId: event.pointerId,
|
||
startX: event.clientX,
|
||
startY: event.clientY,
|
||
moved: false,
|
||
}
|
||
blockDragId.value = card.id
|
||
return
|
||
}
|
||
const rect = perm.getBoundingClientRect()
|
||
cardDrag = {
|
||
cardId: card.id,
|
||
pointerId: event.pointerId,
|
||
board,
|
||
startX: event.clientX,
|
||
startY: event.clientY,
|
||
grabX: event.clientX - (rect.left + rect.width / 2),
|
||
grabY: event.clientY - (rect.top + rect.height / 2),
|
||
halfWidth: rect.width / 2,
|
||
halfHeight: rect.height / 2,
|
||
moved: false,
|
||
}
|
||
}
|
||
|
||
function moveCardPreview(event: PointerEvent) {
|
||
if (blockDrag) {
|
||
if (blockDrag.pointerId !== event.pointerId) return
|
||
if (!blockDrag.moved && Math.hypot(event.clientX - blockDrag.startX, event.clientY - blockDrag.startY) < 4) return
|
||
blockDrag.moved = true
|
||
const to = pointerPoint(event.clientX, event.clientY)
|
||
const box = cardBox(blockDrag.blockerId)
|
||
const from = box && to ? edgePoint(box, to) : null
|
||
blockDragLine.value = from && to ? { from, to } : null
|
||
blockHoverId.value = blockTargetAt(event.clientX, event.clientY)
|
||
return
|
||
}
|
||
const drag = cardDrag
|
||
if (!drag || drag.pointerId !== event.pointerId) return
|
||
if (!drag.moved && Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY) < 4) return
|
||
drag.moved = true
|
||
const rect = drag.board.getBoundingClientRect()
|
||
const marginX = Math.min(0.49, drag.halfWidth / rect.width)
|
||
const marginY = Math.min(0.49, drag.halfHeight / rect.height)
|
||
const clamp = (value: number, margin: number) => Math.min(1 - margin, Math.max(margin, value))
|
||
const x = (event.clientX - drag.grabX - rect.left) / rect.width
|
||
const y = (event.clientY - drag.grabY - rect.top) / rect.height
|
||
const attackDrag = Boolean(attackWindow.value && myUntappedCreatures.value.some(card => card.id === drag.cardId))
|
||
dragPreview.value = {
|
||
cardId: drag.cardId,
|
||
x: attackDrag ? x : clamp(x, marginX),
|
||
y: attackDrag ? y : clamp(y, marginY),
|
||
}
|
||
attackDropId.value = attackDropTargetAt(drag.cardId, event.clientX, event.clientY)
|
||
}
|
||
|
||
/** Topmost opponent panel under the pointer, ignoring the card being dragged. */
|
||
function attackDropTargetAt(cardId: string, x: number, y: number): string {
|
||
if (!attackWindow.value || !myUntappedCreatures.value.some(card => card.id === cardId)) return ''
|
||
for (const element of document.elementsFromPoint(x, y)) {
|
||
const panel = element.closest<HTMLElement>('.player')
|
||
const id = panel?.dataset.playerId
|
||
if (id && opponents.value.some(player => player.id === id)) return id
|
||
}
|
||
return ''
|
||
}
|
||
|
||
async function endCardMove(event: PointerEvent) {
|
||
if (blockDrag) {
|
||
if (blockDrag.pointerId !== event.pointerId) return
|
||
const drag = blockDrag
|
||
blockDrag = null
|
||
blockDragId.value = ''
|
||
blockDragLine.value = null
|
||
blockHoverId.value = ''
|
||
if (!drag.moved) return
|
||
// The click that follows a drag must not open the ability menu.
|
||
suppressCardClick = drag.blockerId
|
||
setTimeout(() => { suppressCardClick = '' }, 0)
|
||
const attackerId = blockTargetAt(event.clientX, event.clientY)
|
||
if (attackerId) assignBlock(attackerId, drag.blockerId)
|
||
return
|
||
}
|
||
const drag = cardDrag
|
||
if (!drag || drag.pointerId !== event.pointerId) return
|
||
cardDrag = null
|
||
const preview = dragPreview.value
|
||
dragPreview.value = null
|
||
const attackTarget = attackDropTargetAt(drag.cardId, event.clientX, event.clientY)
|
||
attackDropId.value = ''
|
||
if (!drag.moved || !preview) return
|
||
|
||
// The click that follows a drag must not open the ability menu.
|
||
suppressCardClick = drag.cardId
|
||
setTimeout(() => { suppressCardClick = '' }, 0)
|
||
|
||
if (attackTarget) {
|
||
if (!selectedAttackers.value.includes(drag.cardId)) selectedAttackers.value.push(drag.cardId)
|
||
attackTargets[drag.cardId] = attackTarget
|
||
return
|
||
}
|
||
|
||
const target = myBattlefield.value.find(card => card.id === drag.cardId)
|
||
if (!target) return
|
||
const rect = drag.board.getBoundingClientRect()
|
||
const marginX = Math.min(0.49, drag.halfWidth / rect.width)
|
||
const marginY = Math.min(0.49, drag.halfHeight / rect.height)
|
||
const previous = target.position
|
||
target.position = {
|
||
x: Math.min(1 - marginX, Math.max(marginX, preview.x)),
|
||
y: Math.min(1 - marginY, Math.max(marginY, preview.y)),
|
||
}
|
||
const ok = await act({
|
||
type: 'move_permanent',
|
||
cardId: drag.cardId,
|
||
position: target.position,
|
||
})
|
||
if (!ok) target.position = previous
|
||
}
|
||
|
||
function cancelCardMove(event: PointerEvent) {
|
||
if (blockDrag?.pointerId === event.pointerId) {
|
||
blockDrag = null
|
||
blockDragId.value = ''
|
||
blockDragLine.value = null
|
||
blockHoverId.value = ''
|
||
return
|
||
}
|
||
if (cardDrag?.pointerId !== event.pointerId) return
|
||
cardDrag = null
|
||
dragPreview.value = null
|
||
attackDropId.value = ''
|
||
}
|
||
|
||
function openCast(card: CardView) {
|
||
pendingAbility.value = null
|
||
abilityTarget.value = ''
|
||
castCardId.value = card.id
|
||
selectedTarget.value = ''
|
||
castX.value = 0
|
||
castOverload.value = false
|
||
error.value = ''
|
||
}
|
||
|
||
function cancelCast() {
|
||
castCardId.value = ''
|
||
selectedTarget.value = ''
|
||
castOverload.value = false
|
||
}
|
||
|
||
async function confirmCast() {
|
||
if (!castCard.value) return
|
||
const target = parseTarget(selectedTarget.value)
|
||
const ok = await act({
|
||
type: 'cast',
|
||
cardId: castCard.value.id,
|
||
targets: target ? [target] : [],
|
||
x: castX.value,
|
||
overload: castOverload.value,
|
||
})
|
||
if (ok) cancelCast()
|
||
}
|
||
|
||
async function activate(card: CardView, ability: AbilityView, color?: string) {
|
||
cancelCast()
|
||
if (ability.targets?.length) {
|
||
pendingAbility.value = { card, ability, color }
|
||
abilityTarget.value = ''
|
||
return
|
||
}
|
||
await act({ type: 'activate', sourceId: card.id, abilityIndex: ability.index, color })
|
||
}
|
||
|
||
async function activateFromMenu(card: CardView, ability: AbilityView, color?: string) {
|
||
closeMenu()
|
||
await activate(card, ability, color)
|
||
}
|
||
|
||
function cancelActivation() {
|
||
pendingAbility.value = null
|
||
abilityTarget.value = ''
|
||
}
|
||
|
||
async function confirmActivation() {
|
||
const pending = pendingAbility.value
|
||
if (!pending) return
|
||
const target = parseTarget(abilityTarget.value)
|
||
const ok = await act({
|
||
type: 'activate',
|
||
sourceId: pending.card.id,
|
||
abilityIndex: pending.ability.index,
|
||
color: pending.color,
|
||
targets: target ? [target] : [],
|
||
})
|
||
if (ok) cancelActivation()
|
||
}
|
||
|
||
async function chooseSearchCard(card: CardView) {
|
||
if (busy.value || !searchLegalIds.value.has(card.id)) return
|
||
await act({ type: 'choose_search', cardId: card.id })
|
||
}
|
||
|
||
async function chooseCreatureType(type: string) {
|
||
if (busy.value) return
|
||
await act({ type: 'choose_type', choice: type })
|
||
}
|
||
|
||
async function chooseCost(pay: boolean) {
|
||
if (busy.value) return
|
||
await act({ type: 'choose_cost', pay })
|
||
}
|
||
|
||
async function chooseHideawayCard(card: CardView) {
|
||
if (busy.value) return
|
||
await act({ type: 'choose_hideaway', cardId: card.id })
|
||
}
|
||
|
||
async function attack() {
|
||
const attackers = selectedAttackers.value
|
||
.filter(attackerId => attackTargets[attackerId])
|
||
.map(attackerId => ({ attackerId, defenderId: attackTargets[attackerId] }))
|
||
if (!attackers.length) return
|
||
const ok = await act({ type: 'attack', attackers })
|
||
if (ok) {
|
||
selectedAttackers.value = []
|
||
for (const key of Object.keys(attackTargets)) delete attackTargets[key]
|
||
}
|
||
}
|
||
|
||
function removeAttacker(cardId: string) {
|
||
selectedAttackers.value = selectedAttackers.value.filter(id => id !== cardId)
|
||
delete attackTargets[cardId]
|
||
}
|
||
|
||
function attackerName(cardId: string): string {
|
||
return myUntappedCreatures.value.find(card => card.id === cardId)?.name ?? 'Creature'
|
||
}
|
||
|
||
async function declareBlocks() {
|
||
const blocks = Object.entries(blockSelection)
|
||
.filter(([, blockerId]) => blockerId)
|
||
.map(([attackerId, blockerId]) => ({ blockerId, attackerId }))
|
||
if (!blocks.length) {
|
||
await act({ type: 'pass' })
|
||
return
|
||
}
|
||
const ok = await act({ type: 'block', blocks })
|
||
if (ok) {
|
||
for (const key of Object.keys(blockSelection)) delete blockSelection[key]
|
||
}
|
||
}
|
||
|
||
async function copyLink() {
|
||
try {
|
||
await navigator.clipboard.writeText(window.location.href)
|
||
notice.value = 'Game link copied. Anyone opening it can take an open seat.'
|
||
} catch {
|
||
notice.value = 'Copy failed.'
|
||
}
|
||
}
|
||
|
||
function errorMessage(caught: unknown): string {
|
||
const data = (caught as { data?: { error?: string } })?.data
|
||
return data?.error ?? (caught instanceof Error ? caught.message : String(caught))
|
||
}
|
||
|
||
const MANA_COLORS: Record<string, string> = {
|
||
W: '#f5f2d6',
|
||
U: '#7aa2f7',
|
||
B: '#b6a2d8',
|
||
R: '#e07a7a',
|
||
G: '#7dd3a0',
|
||
C: '#c4c8d4',
|
||
}
|
||
|
||
function manaColor(color: string): string {
|
||
return MANA_COLORS[color] ?? 'var(--accent)'
|
||
}
|
||
|
||
function scheduleAnimation(callback: () => void, delay: number) {
|
||
const timer = setTimeout(() => {
|
||
animationTimers.delete(timer)
|
||
callback()
|
||
}, delay)
|
||
animationTimers.add(timer)
|
||
}
|
||
|
||
/** Flash a keyed CSS animation, then let it be applied again next time. */
|
||
function pulse(map: Record<string, number>, id: string, duration: number) {
|
||
const token = ++animationCounter
|
||
map[id] = token
|
||
scheduleAnimation(() => {
|
||
if (map[id] === token) delete map[id]
|
||
}, duration)
|
||
}
|
||
|
||
function addFloatingLabel(targetId: string, text: string, tone: FloatingLabel['tone']) {
|
||
const id = ++animationCounter
|
||
floatingLabels.value.push({ id, targetId, text, tone })
|
||
scheduleAnimation(() => {
|
||
floatingLabels.value = floatingLabels.value.filter(label => label.id !== id)
|
||
}, 1100)
|
||
}
|
||
|
||
function addManaBurst(color: string, amount: number) {
|
||
const id = ++animationCounter
|
||
manaBursts.value.push({ id, color, amount })
|
||
scheduleAnimation(() => {
|
||
manaBursts.value = manaBursts.value.filter(burst => burst.id !== id)
|
||
}, 1100)
|
||
}
|
||
|
||
function labelsFor(targetId: string): FloatingLabel[] {
|
||
return floatingLabels.value.filter(label => label.targetId === targetId)
|
||
}
|
||
|
||
function playAnimations(animations: GameAnimations) {
|
||
for (const id of animations.enteringCardIds) pulse(cardEnterAnimations, id, 520)
|
||
for (const id of animations.attackingCardIds) pulse(cardAttackAnimations, id, 540)
|
||
for (const damage of animations.damagedCards) {
|
||
pulse(cardDamageAnimations, damage.cardId, 500)
|
||
addFloatingLabel(damage.cardId, `−${damage.amount}`, 'damage')
|
||
}
|
||
for (const change of animations.lifeChanges) {
|
||
if (change.amount < 0) {
|
||
pulse(playerHitAnimations, change.playerId, 700)
|
||
addFloatingLabel(change.playerId, `−${Math.abs(change.amount)}`, 'damage')
|
||
} else {
|
||
pulse(playerHealAnimations, change.playerId, 700)
|
||
addFloatingLabel(change.playerId, `+${change.amount}`, 'heal')
|
||
}
|
||
}
|
||
for (const gain of animations.manaGains) addManaBurst(gain.color, gain.amount)
|
||
}
|
||
|
||
function applyState(next: MatchView, animate = true) {
|
||
if (animate) playAnimations(diffGameState(previousState, next))
|
||
previousState = next
|
||
state.value = next
|
||
}
|
||
|
||
function resetAnimations() {
|
||
previousState = null
|
||
for (const timer of animationTimers) clearTimeout(timer)
|
||
animationTimers.clear()
|
||
for (const map of [
|
||
cardEnterAnimations,
|
||
cardDamageAnimations,
|
||
cardAttackAnimations,
|
||
playerHitAnimations,
|
||
playerHealAnimations,
|
||
]) {
|
||
for (const key of Object.keys(map)) delete map[key]
|
||
}
|
||
floatingLabels.value = []
|
||
manaBursts.value = []
|
||
}
|
||
|
||
watch(() => game.value?.step, () => {
|
||
selectedAttackers.value = []
|
||
attackDropId.value = ''
|
||
blockDrag = null
|
||
blockDragId.value = ''
|
||
blockDragLine.value = null
|
||
blockHoverId.value = ''
|
||
for (const key of Object.keys(attackTargets)) delete attackTargets[key]
|
||
for (const key of Object.keys(blockSelection)) delete blockSelection[key]
|
||
})
|
||
|
||
watch([blockWindow, () => state.value?.version], refreshCombatArrows, { flush: 'post' })
|
||
watch(blockSelection, refreshCombatArrows, { flush: 'post' })
|
||
|
||
watch(() => Boolean(pendingSearch.value), async active => {
|
||
if (!active) return
|
||
searchFilter.value = ''
|
||
await nextTick()
|
||
searchInput.value?.focus()
|
||
})
|
||
|
||
watch(() => pendingChoice.value?.sourceId, async sourceId => {
|
||
if (!sourceId) return
|
||
choiceFilter.value = ''
|
||
await nextTick()
|
||
choiceInput.value?.focus()
|
||
})
|
||
|
||
onMounted(async () => {
|
||
window.addEventListener('keydown', onKeydown)
|
||
window.addEventListener('resize', refreshCombatArrows)
|
||
decks.value = (await loadDecks(apiBase)).sort((a, b) => b.updatedAt - a.updatedAt)
|
||
joinName.value = localStorage.getItem('commander-player-name') ?? ''
|
||
deckId.value = decks.value.find(deck => !deckValidation(deck).length)?.id
|
||
?? decks.value[0]?.id
|
||
?? ''
|
||
|
||
const raw = sessionStorage.getItem(`${SESSION_PREFIX}${gameId.value}`)
|
||
if (raw) {
|
||
try {
|
||
token.value = (JSON.parse(raw) as { token?: string }).token ?? ''
|
||
} catch {
|
||
token.value = ''
|
||
}
|
||
}
|
||
|
||
await loadSummary()
|
||
if (token.value) {
|
||
await connect()
|
||
} else {
|
||
connection.value = 'offline'
|
||
}
|
||
})
|
||
|
||
onUnmounted(() => {
|
||
window.removeEventListener('keydown', onKeydown)
|
||
window.removeEventListener('resize', refreshCombatArrows)
|
||
events?.close()
|
||
for (const timer of animationTimers) clearTimeout(timer)
|
||
animationTimers.clear()
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<main class="fill-page" :class="{ 'game-page': game }">
|
||
<header class="game-head">
|
||
<div>
|
||
<h1>{{ summary ? `${summary.hostName}'s game` : 'Commander game' }}</h1>
|
||
<p v-if="game?.status === 'mulligan'" class="muted">Opening hands · keep or mulligan</p>
|
||
<p v-else-if="game" class="muted">
|
||
Turn {{ game.turn }} · {{ phaseLabel }} · priority: {{ priorityName }}
|
||
</p>
|
||
<p v-else class="muted">{{ state?.status ?? summary?.status ?? 'Loading…' }}</p>
|
||
</div>
|
||
<div class="row wrap">
|
||
<button
|
||
type="button"
|
||
class="mini hamburger"
|
||
:aria-expanded="menuOpen"
|
||
aria-label="Game menu"
|
||
@click="menuOpen = !menuOpen"
|
||
>☰</button>
|
||
</div>
|
||
</header>
|
||
|
||
<p v-if="error" class="error">{{ error }}</p>
|
||
<p v-else-if="notice" class="ok">{{ notice }}</p>
|
||
|
||
<section v-if="!token" class="panel join-panel">
|
||
<h2>Join this game</h2>
|
||
<p v-if="summary" class="muted">
|
||
Host: {{ summary.hostName }} · {{ summary.playerCount }}/{{ summary.maxPlayers }}
|
||
· {{ summary.status }}
|
||
</p>
|
||
<p v-if="summary?.status === 'active'" class="warn">
|
||
This game has already started. You can only join games in the lobby.
|
||
</p>
|
||
<p v-if="!decks.length" class="warn">
|
||
No saved decks. <NuxtLink to="/decks">Create or import one first</NuxtLink>.
|
||
</p>
|
||
<label class="field">
|
||
<span class="muted">Your name</span>
|
||
<input v-model="joinName" maxlength="30" placeholder="Player">
|
||
</label>
|
||
<label class="field">
|
||
<span class="muted">Deck</span>
|
||
<select v-model="deckId">
|
||
<option v-for="deck in decks" :key="deck.id" :value="deck.id">
|
||
{{ deck.name }} ({{ deck.cards.length + 1 }})
|
||
</option>
|
||
</select>
|
||
</label>
|
||
<p v-if="joinError" class="error">{{ joinError }}</p>
|
||
<button
|
||
type="button"
|
||
class="primary"
|
||
:disabled="joining || !joinName.trim() || !deckId || summary?.status === 'active'"
|
||
@click="joinGame"
|
||
>{{ joining ? 'Joining…' : 'Join game' }}</button>
|
||
</section>
|
||
|
||
<template v-else-if="state">
|
||
<section v-if="state.status === 'lobby'" class="panel lobby-panel">
|
||
<header class="lobby-head">
|
||
<h2>Lobby</h2>
|
||
<p class="muted">
|
||
{{ state.players.length }}/{{ state.maxPlayers }} players · Waiting for players.
|
||
Share the link or use the Play page.
|
||
</p>
|
||
</header>
|
||
|
||
<div class="lobby-seats">
|
||
<article
|
||
v-for="player in state.players"
|
||
:key="player.id"
|
||
class="lobby-seat"
|
||
:class="{ self: player.id === viewerId }"
|
||
>
|
||
<div class="lobby-commander">
|
||
<GameCard
|
||
v-if="player.commander"
|
||
:oracle-id="player.commander.oracleId"
|
||
:name="player.commander.name"
|
||
/>
|
||
<div v-else class="lobby-commander-empty">{{ player.name.charAt(0) }}</div>
|
||
</div>
|
||
<strong>{{ player.name }}</strong>
|
||
<span v-if="player.commander" class="lobby-commander-name">{{ player.commander.name }}</span>
|
||
<div class="lobby-badges">
|
||
<span v-if="player.id === state.hostId" class="tag">host</span>
|
||
<span v-if="player.id === viewerId" class="tag good">you</span>
|
||
</div>
|
||
</article>
|
||
|
||
<article v-for="seat in emptySeats" :key="`empty-${seat}`" class="lobby-seat empty">
|
||
<div class="lobby-commander">
|
||
<div class="lobby-commander-empty">?</div>
|
||
</div>
|
||
<span class="muted">Waiting for a player…</span>
|
||
</article>
|
||
</div>
|
||
|
||
<div class="lobby-actions">
|
||
<label v-if="decks.length" class="field lobby-deck">
|
||
<span class="muted">Your deck</span>
|
||
<select v-model="deckId" :disabled="busy" @change="changeDeck">
|
||
<option v-for="deck in decks" :key="deck.id" :value="deck.id">
|
||
{{ deck.name }} ({{ deck.cards.length + 1 }})
|
||
</option>
|
||
</select>
|
||
</label>
|
||
<button
|
||
v-if="isHost"
|
||
type="button"
|
||
class="primary"
|
||
:disabled="busy || state.players.length < 2"
|
||
@click="startGame"
|
||
>{{ state.players.length < 2 ? 'Need at least two players' : 'Start game' }}</button>
|
||
<p v-else class="muted">Waiting for the host to start.</p>
|
||
<button type="button" :disabled="busy" @click="leaveGame">Leave game</button>
|
||
</div>
|
||
</section>
|
||
|
||
<template v-else-if="game">
|
||
<p v-if="game.status === 'finished'" class="winner">
|
||
{{ winnerName }} wins!
|
||
<NuxtLink to="/">Back to games</NuxtLink>
|
||
</p>
|
||
|
||
<div class="game-layout">
|
||
<section
|
||
ref="tableEl"
|
||
class="players"
|
||
:class="{ panning }"
|
||
@pointerdown="startPan"
|
||
@pointermove="movePan"
|
||
@pointerup="endPan"
|
||
@pointercancel="endPan"
|
||
@wheel.prevent="zoomTable"
|
||
>
|
||
<div ref="canvasEl" class="table-canvas" :style="canvasStyle">
|
||
<svg v-if="blockWindow" class="combat-arrows" aria-hidden="true">
|
||
<defs>
|
||
<marker
|
||
id="combat-arrow-attack"
|
||
markerWidth="8"
|
||
markerHeight="8"
|
||
refX="6"
|
||
refY="4"
|
||
orient="auto"
|
||
markerUnits="userSpaceOnUse"
|
||
>
|
||
<path d="M0,0 L8,4 L0,8 Z" fill="var(--bad)" />
|
||
</marker>
|
||
<marker
|
||
id="combat-arrow-block"
|
||
markerWidth="8"
|
||
markerHeight="8"
|
||
refX="6"
|
||
refY="4"
|
||
orient="auto"
|
||
markerUnits="userSpaceOnUse"
|
||
>
|
||
<path d="M0,0 L8,4 L0,8 Z" fill="var(--accent)" />
|
||
</marker>
|
||
</defs>
|
||
<path
|
||
v-for="arrow in combatArrows"
|
||
:key="arrow.key"
|
||
:d="arrowPath(arrow.from, arrow.to)"
|
||
:class="arrow.tone"
|
||
:marker-end="`url(#combat-arrow-${arrow.tone})`"
|
||
/>
|
||
<path
|
||
v-if="blockDragLine"
|
||
:d="arrowPath(blockDragLine.from, blockDragLine.to)"
|
||
class="pending"
|
||
marker-end="url(#combat-arrow-block)"
|
||
/>
|
||
</svg>
|
||
<article
|
||
v-for="(player, playerIndex) in state.players"
|
||
:key="player.id"
|
||
class="panel player"
|
||
:data-player-id="player.id"
|
||
:class="{
|
||
current: game.activePlayer === player.id,
|
||
dead: player.lost,
|
||
'anim-hit': playerHitAnimations[player.id],
|
||
'anim-heal': playerHealAnimations[player.id],
|
||
'attack-ready': draggingAttackerId && player.id !== viewerId && !player.lost,
|
||
'drop-hover': attackDropId === player.id,
|
||
}"
|
||
>
|
||
<header class="player-head">
|
||
<strong class="grow">{{ player.name }}</strong>
|
||
<span v-if="player.id === viewerId" class="tag">you</span>
|
||
<span
|
||
class="life"
|
||
:class="{
|
||
'life-hit': playerHitAnimations[player.id],
|
||
'life-heal': playerHealAnimations[player.id],
|
||
}"
|
||
>{{ player.life }}</span>
|
||
<span class="tag">hand {{ player.handCount ?? 0 }}</span>
|
||
<span class="tag">library {{ player.libraryCount ?? 0 }}</span>
|
||
<span v-if="game.priority === player.id" class="tag good">priority</span>
|
||
<span v-if="player.lost" class="tag bad">lost</span>
|
||
<button
|
||
v-if="player.id === viewerId"
|
||
type="button"
|
||
class="mini"
|
||
:class="{ active: playmatOpen }"
|
||
title="Change your playmat"
|
||
@click="togglePlaymat"
|
||
>Playmat</button>
|
||
<span
|
||
v-for="label in labelsFor(player.id)"
|
||
:key="label.id"
|
||
class="float-text player-float"
|
||
:class="label.tone"
|
||
aria-hidden="true"
|
||
>{{ label.text }}</span>
|
||
</header>
|
||
|
||
<p v-if="player.commanderDamage?.length" class="damage">
|
||
<span v-for="damage in player.commanderDamage" :key="damage.commanderId" class="tag bad">
|
||
☠ {{ damage.commanderName }} {{ damage.amount }}/21
|
||
</span>
|
||
</p>
|
||
|
||
<div class="play-area" :class="{ 'command-right': playerIndex % 2 === 1 }">
|
||
<div v-if="player.command?.length || player.graveyard?.length || player.libraryCount" class="side-zones">
|
||
<div v-if="player.libraryCount" class="zone">
|
||
<span class="zone-label">Library {{ player.libraryCount }}</span>
|
||
<div class="library-stack" :style="cardBackStyle">
|
||
<span
|
||
v-for="layer in Math.min(3, player.libraryCount ?? 1)"
|
||
:key="layer"
|
||
class="library-back"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="player.command?.length" class="zone">
|
||
<span class="zone-label">Command</span>
|
||
<div v-for="card in player.command" :key="card.id" class="command-card" :title="card.oracleText">
|
||
<CardHover :oracle-id="card.oracleId" :name="card.name">
|
||
<GameCard :oracle-id="card.oracleId" :name="card.name">
|
||
<span v-if="card.isCommander" class="overlay-tag commander" title="Commander">♛</span>
|
||
</GameCard>
|
||
</CardHover>
|
||
<span v-if="commanderTax(player, card)" class="tag">tax {{ commanderTax(player, card) }}</span>
|
||
<button
|
||
v-if="player.id === viewerId && canAct"
|
||
type="button"
|
||
class="mini"
|
||
:disabled="busy"
|
||
@click="openCast(card)"
|
||
>Cast</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="player.graveyard?.length" class="zone graveyard-zone">
|
||
<span class="zone-label">Graveyard {{ player.graveyard.length }}</span>
|
||
<div class="graveyard-stack">
|
||
<CardHover
|
||
v-for="card in player.graveyard.slice(-PILE_SIZE)"
|
||
:key="card.id"
|
||
:oracle-id="card.oracleId"
|
||
:name="card.name"
|
||
>
|
||
<GameCard :oracle-id="card.oracleId" :name="card.name" />
|
||
</CardHover>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="battlefield" :class="{ 'has-playmat': player.playmat }" :style="playmatStyle(player)">
|
||
<div
|
||
v-for="card in player.battlefield"
|
||
:key="card.id"
|
||
class="perm"
|
||
:data-card-id="card.id"
|
||
:class="{
|
||
selected: selectedCardId === card.id,
|
||
positioned: isPositioned(card),
|
||
dragging: dragPreview?.cardId === card.id,
|
||
movable: card.controller === viewerId,
|
||
'block-source': blockDragId === card.id,
|
||
'block-hover': blockHoverId === card.id,
|
||
'pending-attack': attackTargets[card.id],
|
||
'anim-enter': cardEnterAnimations[card.id],
|
||
'anim-damage': cardDamageAnimations[card.id],
|
||
'anim-attack': cardAttackAnimations[card.id],
|
||
'has-hidden': card.hiddenCards,
|
||
}"
|
||
:style="permStyle(card)"
|
||
:title="card.oracleText"
|
||
role="button"
|
||
tabindex="0"
|
||
@pointerdown="startCardMove(card, $event)"
|
||
@pointermove="moveCardPreview"
|
||
@pointerup="endCardMove"
|
||
@pointercancel="cancelCardMove"
|
||
@click="toggleCard(card, $event)"
|
||
@keydown.enter.prevent="toggleCard(card, $event)"
|
||
@keydown.space.prevent="toggleCard(card, $event)"
|
||
>
|
||
<div
|
||
v-if="card.hiddenCards"
|
||
class="hidden-exile"
|
||
:style="cardBackStyle"
|
||
:title="`${card.hiddenCards} card${card.hiddenCards === 1 ? '' : 's'} exiled face down with hideaway`"
|
||
>
|
||
<span
|
||
v-for="layer in card.hiddenCards"
|
||
:key="layer"
|
||
class="hidden-exile-card face-down-card"
|
||
:style="{ translate: `${(layer - 1) * 2}px ${(layer - 1) * 2}px` }"
|
||
/>
|
||
</div>
|
||
<CardHover :oracle-id="card.oracleId" :name="card.name">
|
||
<GameCard :oracle-id="card.oracleId" :name="card.name" :tapped="card.tapped">
|
||
<span v-if="card.isCommander" class="overlay-tag commander" title="Commander">♛</span>
|
||
<span
|
||
v-if="card.chosenType"
|
||
class="overlay-tag chosen"
|
||
:title="`Chosen creature type: ${card.chosenType}`"
|
||
>{{ card.chosenType }}</span>
|
||
<span
|
||
v-if="card.attacking || attackTargets[card.id]"
|
||
class="overlay-tag attacking"
|
||
:title="`Attacking ${playerName(card.attacking || attackTargets[card.id])}`"
|
||
>⚔</span>
|
||
<span v-if="card.damage" class="overlay-tag card-damage" title="Damage">−{{ card.damage }}</span>
|
||
<span v-if="card.power !== undefined" class="stats">{{ card.power }}/{{ card.toughness }}</span>
|
||
<div v-if="Object.keys(card.counters).length" class="overlay-counters">
|
||
<span
|
||
v-for="(amount, counter) in card.counters"
|
||
:key="counter"
|
||
class="overlay-tag counter"
|
||
>{{ amount }} {{ counter }}</span>
|
||
</div>
|
||
</GameCard>
|
||
</CardHover>
|
||
<span
|
||
v-for="label in labelsFor(card.id)"
|
||
:key="label.id"
|
||
class="float-text card-float"
|
||
:class="label.tone"
|
||
aria-hidden="true"
|
||
>{{ label.text }}</span>
|
||
</div>
|
||
<p v-if="!player.battlefield?.length" class="muted">No permanents.</p>
|
||
</div>
|
||
</div>
|
||
|
||
<p class="muted small zone-bar">
|
||
<button
|
||
type="button"
|
||
class="zone-link"
|
||
:class="{ active: browsingZone?.playerId === player.id && browsingZone.zone === 'graveyard' }"
|
||
@click="toggleZone(player, 'graveyard')"
|
||
>Graveyard {{ player.graveyard?.length ?? 0 }}</button>
|
||
<span aria-hidden="true">·</span>
|
||
<button
|
||
type="button"
|
||
class="zone-link"
|
||
:class="{ active: browsingZone?.playerId === player.id && browsingZone.zone === 'exile' }"
|
||
@click="toggleZone(player, 'exile')"
|
||
>Exile {{ player.exile?.length ?? 0 }}</button>
|
||
</p>
|
||
</article>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="stack-pile" :class="{ empty: !game.stack.length }" aria-live="polite" aria-label="Stack">
|
||
<h2 v-if="game.stack.length" class="stack-heading">
|
||
Stack <span class="muted">{{ game.stack.length }}</span>
|
||
</h2>
|
||
<TransitionGroup name="stack" tag="ol" class="stack-pile-list">
|
||
<li
|
||
v-for="(item, index) in [...game.stack].reverse()"
|
||
:key="item.id"
|
||
class="stack-card"
|
||
:class="[`kind-${item.kind}`, { 'is-top': index === 0 }]"
|
||
:style="{ zIndex: game.stack.length - index }"
|
||
:title="item.label"
|
||
>
|
||
<span class="stack-glyph" aria-hidden="true">{{ item.kind === 'spell' ? '✦' : '⟳' }}</span>
|
||
<span class="stack-copy">
|
||
<strong><SymbolText :text="item.label" /></strong>
|
||
<span class="muted">{{ playerName(item.controller) }}</span>
|
||
</span>
|
||
</li>
|
||
</TransitionGroup>
|
||
</section>
|
||
|
||
<div v-if="game.status === 'mulligan'" class="mulligan-backdrop" aria-hidden="true" />
|
||
<section class="hand-panel" :class="{ 'mulligan-mode': game.status === 'mulligan' }">
|
||
<div v-if="mulligan" class="mulligan-bar">
|
||
<template v-if="mulligan.kept">
|
||
<span class="muted">Hand kept. Waiting for {{ mulliganWaiting || 'the other players' }}.</span>
|
||
</template>
|
||
<template v-else-if="mulligan.bottom">
|
||
<span>Click {{ mulligan.bottom }} card{{ mulligan.bottom === 1 ? '' : 's' }} in your hand to put
|
||
{{ mulligan.bottom === 1 ? 'it' : 'them' }} on the bottom of your library.</span>
|
||
</template>
|
||
<template v-else>
|
||
<span>Mulligans: {{ mulligan.count }}.</span>
|
||
<button type="button" class="primary" :disabled="busy" @click="keepHand">Keep hand</button>
|
||
<button type="button" :disabled="busy" @click="takeMulligan">Mulligan</button>
|
||
</template>
|
||
</div>
|
||
<div class="row wrap hand-head">
|
||
<h2>Your hand</h2>
|
||
<span class="tag">{{ game.hand.length }}</span>
|
||
<div class="mana-row">
|
||
<span v-for="(amount, color) in game.manaPool" :key="color" class="tag">
|
||
<ManaCost :cost="`{${color}}`" /> {{ amount }}
|
||
</span>
|
||
<span
|
||
v-for="burst in manaBursts"
|
||
:key="burst.id"
|
||
class="mana-burst"
|
||
:style="{ color: manaColor(burst.color) }"
|
||
aria-hidden="true"
|
||
>
|
||
<ManaCost :cost="`{${burst.color}}`" /> +{{ burst.amount }}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
<p v-if="!game.hand.length" class="muted">No cards in hand.</p>
|
||
<TransitionGroup v-else name="hand" tag="div" class="hand-fan">
|
||
<div
|
||
v-for="(card, index) in game.hand"
|
||
:key="card.id"
|
||
class="hand-card"
|
||
:class="{ playable: card.playable || mulliganBottom > 0 }"
|
||
:style="fanStyle(index, game.hand.length)"
|
||
:title="mulliganBottom > 0
|
||
? `Put ${card.name} on the bottom of your library`
|
||
: card.playable
|
||
? `Click to ${isLand(card) ? 'play' : 'cast'} ${card.name}`
|
||
: card.oracleText"
|
||
role="button"
|
||
:tabindex="card.playable || mulliganBottom > 0 ? 0 : -1"
|
||
:aria-disabled="!card.playable && !mulliganBottom"
|
||
@click="playCard(card)"
|
||
@keydown.enter.prevent="playCard(card)"
|
||
@keydown.space.prevent="playCard(card)"
|
||
>
|
||
<div class="hand-lift">
|
||
<CardHover :oracle-id="card.oracleId" :name="card.name">
|
||
<GameCard :oracle-id="card.oracleId" :name="card.name">
|
||
<span v-if="card.isCommander" class="overlay-tag commander" title="Commander">♛</span>
|
||
</GameCard>
|
||
</CardHover>
|
||
<button
|
||
v-if="!isLand(card) && needsCastOptions(card)"
|
||
type="button"
|
||
class="mini hand-options"
|
||
:disabled="!card.playable || busy"
|
||
@click.stop="openCast(card)"
|
||
@keydown.stop
|
||
>Options</button>
|
||
</div>
|
||
</div>
|
||
</TransitionGroup>
|
||
</section>
|
||
|
||
<aside v-if="sidebarOpen" ref="sidebarEl" class="sidebar">
|
||
<section v-if="playmatOpen" class="panel side">
|
||
<div class="row">
|
||
<h2 class="grow">Playmat</h2>
|
||
<button type="button" class="mini" @click="playmatOpen = false">Close</button>
|
||
</div>
|
||
<p class="muted">Only you can change your mat.</p>
|
||
<PlaymatPicker :current="myPlaymat" :busy="playmatBusy" @select="savePlaymat" />
|
||
</section>
|
||
|
||
<section v-if="browseView" class="panel side browse-panel">
|
||
<div class="row">
|
||
<h2 class="grow">{{ browseView.title }}</h2>
|
||
<button type="button" class="mini" @click="browsingZone = null">Close</button>
|
||
</div>
|
||
<p v-if="!browseView.cards.length" class="muted">Empty.</p>
|
||
<div v-else class="zone-cards">
|
||
<template v-for="card in browseView.cards" :key="card.id">
|
||
<span
|
||
v-if="card.faceDown"
|
||
class="face-down-card"
|
||
:style="cardBackStyle"
|
||
title="Face-down card"
|
||
/>
|
||
<div v-else class="zone-card">
|
||
<CardHover :oracle-id="card.oracleId" :name="card.name">
|
||
<GameCard :oracle-id="card.oracleId" :name="card.name" :title="card.oracleText" />
|
||
</CardHover>
|
||
<button
|
||
v-if="card.playable"
|
||
type="button"
|
||
class="mini"
|
||
:disabled="busy"
|
||
@click="playExiled(card)"
|
||
>Play</button>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</section>
|
||
|
||
<section v-if="pendingSearch && pendingSearch.player !== viewerId" class="panel side search-panel">
|
||
<h2>Search</h2>
|
||
<p class="muted">{{ playerName(pendingSearch.player) }} is searching their library.</p>
|
||
</section>
|
||
|
||
<section v-if="pendingChoice && pendingChoice.player !== viewerId" class="panel side search-panel">
|
||
<h2>{{ pendingChoice.what === 'pay_cost' ? 'Pay a cost' : pendingChoice.what === 'hideaway' ? 'Hideaway' : 'Choose a type' }}</h2>
|
||
<p class="muted">
|
||
{{ playerName(pendingChoice.player) }}
|
||
{{ pendingChoice.what === 'pay_cost'
|
||
? `is deciding whether to pay ${pendingCostLabel} for ${pendingChoice.sourceName}.`
|
||
: pendingChoice.what === 'hideaway'
|
||
? 'is looking at the top cards of their library.'
|
||
: `is choosing a creature type for ${pendingChoice.sourceName}.` }}
|
||
</p>
|
||
</section>
|
||
|
||
<section v-if="castCard" class="panel side cast-panel">
|
||
<div class="row">
|
||
<h2 class="grow">Cast {{ castCard.name }}</h2>
|
||
<button type="button" class="mini" @click="cancelCast">Cancel</button>
|
||
</div>
|
||
<p class="muted">
|
||
{{ castCard.typeLine }}
|
||
<ManaCost v-if="castCard.manaCost" :cost="castCard.manaCost" />
|
||
</p>
|
||
<p v-if="castCard.oracleText" class="oracle small"><SymbolText :text="castCard.oracleText" /></p>
|
||
<label v-if="overloadAbility" class="row">
|
||
<input v-model="castOverload" type="checkbox">
|
||
<span>{{ overloadAbility.text ?? 'Overload' }}</span>
|
||
</label>
|
||
<label v-if="castNeedsTarget" class="field">
|
||
<span class="muted">Target</span>
|
||
<select v-model="selectedTarget">
|
||
<option v-for="option in castTargetOptions" :key="option.value" :value="option.value">
|
||
{{ option.label }}
|
||
</option>
|
||
</select>
|
||
</label>
|
||
<label v-if="castCard.manaCost?.includes('X')" class="field">
|
||
<span class="muted">X</span>
|
||
<input v-model.number="castX" type="number" min="0">
|
||
</label>
|
||
<button type="button" class="primary" :disabled="busy || Boolean(pendingSearch)" @click="confirmCast">Cast</button>
|
||
</section>
|
||
|
||
<section v-if="pendingAbility" class="panel side cast-panel">
|
||
<div class="row">
|
||
<h2 class="grow">Activate {{ pendingAbility.card.name }}</h2>
|
||
<button type="button" class="mini" @click="cancelActivation">Cancel</button>
|
||
</div>
|
||
<p class="oracle small">
|
||
<SymbolText :text="pendingAbility.ability.text || 'Activate'" />
|
||
</p>
|
||
<label class="field">
|
||
<span class="muted">Target</span>
|
||
<select v-model="abilityTarget">
|
||
<option v-for="option in abilityTargetOptions" :key="option.value" :value="option.value">
|
||
{{ option.label }}
|
||
</option>
|
||
</select>
|
||
</label>
|
||
<button type="button" class="primary" :disabled="busy" @click="confirmActivation">Activate</button>
|
||
</section>
|
||
|
||
<section v-if="attackWindow" class="panel side">
|
||
<h2>Attack</h2>
|
||
<p class="muted">Drag an untapped creature onto a player to attack them.</p>
|
||
<div v-if="selectedAttackers.length" class="attack-list">
|
||
<button
|
||
v-for="attackerId in selectedAttackers"
|
||
:key="attackerId"
|
||
type="button"
|
||
class="attack-pick"
|
||
:title="`Remove ${attackerName(attackerId)} from the attack`"
|
||
@click="removeAttacker(attackerId)"
|
||
>
|
||
<span>{{ attackerName(attackerId) }}</span>
|
||
<span class="muted">⚔ {{ playerName(attackTargets[attackerId]) }} ✕</span>
|
||
</button>
|
||
</div>
|
||
<p v-else class="muted">No attackers chosen yet.</p>
|
||
<button type="button" :disabled="busy || !selectedAttackers.length" @click="attack">
|
||
Attack with {{ selectedAttackers.length }}
|
||
</button>
|
||
</section>
|
||
|
||
<section v-if="blockWindow" class="panel side">
|
||
<h2>Block</h2>
|
||
<p v-if="!incomingAttackers.length" class="muted">No creatures are attacking you.</p>
|
||
<template v-else>
|
||
<p class="muted">Drag one of your untapped creatures onto an attacking creature to block it.</p>
|
||
<div class="block-list">
|
||
<div v-for="entry in incomingAttackers" :key="entry.card.id" class="block-row">
|
||
<span class="grow">⚔ {{ entry.card.name }} ({{ entry.card.power }}/{{ entry.card.toughness }})</span>
|
||
<span v-if="blockSelection[entry.card.id]" class="block-pick">
|
||
<span class="muted">← {{ blockerName(blockSelection[entry.card.id]) }}</span>
|
||
<button
|
||
type="button"
|
||
class="mini"
|
||
:title="`Remove ${blockerName(blockSelection[entry.card.id])}`"
|
||
@click="removeBlock(entry.card.id)"
|
||
>✕</button>
|
||
</span>
|
||
<span v-else class="muted">unblocked</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
<button type="button" :disabled="busy" @click="declareBlocks">
|
||
{{ Object.values(blockSelection).some(Boolean) ? 'Declare blockers' : 'Pass (no blocks)' }}
|
||
</button>
|
||
</section>
|
||
|
||
<section v-if="showLog" class="panel side log-panel">
|
||
<h2>Log</h2>
|
||
<ul class="log-list">
|
||
<li v-for="(line, index) in [...game.log].reverse()" :key="index">{{ line }}</li>
|
||
</ul>
|
||
</section>
|
||
</aside>
|
||
</div>
|
||
</template>
|
||
</template>
|
||
|
||
<div v-if="state?.status === 'active' && game?.status === 'active'" class="turn-actions">
|
||
<label
|
||
class="turn-toggle"
|
||
:class="{ on: autoPassInstants }"
|
||
title="Automatically pass priority when only instants could be cast"
|
||
>
|
||
<input v-model="autoPassInstants" type="checkbox">
|
||
<span>Auto-pass</span>
|
||
</label>
|
||
<button
|
||
type="button"
|
||
class="turn-button"
|
||
:disabled="!canAct || busy"
|
||
@click="act({ type: 'pass' })"
|
||
>Pass</button>
|
||
<button
|
||
type="button"
|
||
class="turn-button end"
|
||
:disabled="!canAct || !isActive || busy || Boolean(game.stack.length)"
|
||
@click="act({ type: 'end_turn' })"
|
||
>End turn</button>
|
||
</div>
|
||
|
||
<Teleport to="body">
|
||
<div v-if="pendingChoice?.player === viewerId" class="search-backdrop">
|
||
<section class="search-modal" role="dialog" aria-modal="true" aria-labelledby="choice-title">
|
||
<header class="search-head">
|
||
<div class="grow">
|
||
<h2 id="choice-title">{{ pendingChoice.what === 'pay_cost'
|
||
? `Pay ${pendingCostLabel}?`
|
||
: pendingChoice.what === 'hideaway' ? 'Hideaway' : 'Choose a creature type' }}</h2>
|
||
<p class="muted">{{ pendingChoice.what === 'hideaway'
|
||
? 'Look at the top cards of your library and exile one face down.'
|
||
: `${pendingChoice.sourceName} enters.` }}</p>
|
||
</div>
|
||
<span v-if="pendingChoice.what === 'creature_type'" class="tag">{{ filteredChoiceOptions.length }} types</span>
|
||
<span v-else-if="pendingChoice.what === 'hideaway'" class="tag">{{ pendingChoice.cards?.length ?? 0 }} cards</span>
|
||
</header>
|
||
<template v-if="pendingChoice.what === 'pay_cost'">
|
||
<p class="muted">If you don't, it enters tapped.</p>
|
||
<div class="choice-grid">
|
||
<button
|
||
type="button"
|
||
class="choice-option"
|
||
:disabled="busy || (pendingChoice.amount !== undefined && (me?.life ?? 0) < pendingChoice.amount)"
|
||
@click="chooseCost(true)"
|
||
>Pay {{ pendingCostLabel }}</button>
|
||
<button
|
||
type="button"
|
||
class="choice-option"
|
||
:disabled="busy"
|
||
@click="chooseCost(false)"
|
||
>Enter tapped</button>
|
||
</div>
|
||
</template>
|
||
<template v-else-if="pendingChoice.what === 'hideaway'">
|
||
<div class="search-library">
|
||
<button
|
||
v-for="card in pendingChoice.cards"
|
||
:key="card.id"
|
||
type="button"
|
||
class="search-card legal"
|
||
:disabled="busy"
|
||
:title="`Exile ${card.name} face down`"
|
||
@click="chooseHideawayCard(card)"
|
||
>
|
||
<CardHover :oracle-id="card.oracleId" :name="card.name">
|
||
<GameCard :oracle-id="card.oracleId" :name="card.name" />
|
||
</CardHover>
|
||
<span class="search-name">{{ card.name }}</span>
|
||
</button>
|
||
</div>
|
||
<p class="muted small">The rest go to the bottom of your library in a random order.</p>
|
||
</template>
|
||
<template v-else>
|
||
<input
|
||
ref="choiceInput"
|
||
v-model="choiceFilter"
|
||
class="search-filter"
|
||
type="search"
|
||
placeholder="Search creature types"
|
||
autocomplete="off"
|
||
>
|
||
<p v-if="!filteredChoiceOptions.length" class="muted">No creature types match “{{ choiceFilter }}”.</p>
|
||
<div v-else class="choice-grid">
|
||
<button
|
||
v-for="type in filteredChoiceOptions"
|
||
:key="type"
|
||
type="button"
|
||
class="choice-option"
|
||
:disabled="busy"
|
||
@click="chooseCreatureType(type)"
|
||
>{{ type }}</button>
|
||
</div>
|
||
</template>
|
||
</section>
|
||
</div>
|
||
</Teleport>
|
||
|
||
<Teleport to="body">
|
||
<div v-if="pendingSearch?.player === viewerId" class="search-backdrop">
|
||
<section class="search-modal" role="dialog" aria-modal="true" aria-labelledby="search-title">
|
||
<header class="search-head">
|
||
<div class="grow">
|
||
<h2 id="search-title">Search your library</h2>
|
||
<p class="muted">
|
||
Choose a card to put {{ searchDestination }}.
|
||
<template v-if="pendingSearch.remaining > 1">({{ pendingSearch.remaining }} picks left)</template>
|
||
</p>
|
||
</div>
|
||
<span class="tag">{{ searchLegalIds.size }} can be chosen</span>
|
||
</header>
|
||
<input
|
||
ref="searchInput"
|
||
v-model="searchFilter"
|
||
class="search-filter"
|
||
type="search"
|
||
placeholder="Search by card name"
|
||
autocomplete="off"
|
||
>
|
||
<p v-if="!filteredSearchLibrary.length" class="muted">No cards match “{{ searchFilter }}”.</p>
|
||
<div v-else class="search-library">
|
||
<button
|
||
v-for="card in filteredSearchLibrary"
|
||
:key="card.id"
|
||
type="button"
|
||
class="search-card"
|
||
:class="{ legal: searchLegalIds.has(card.id) }"
|
||
:disabled="!searchLegalIds.has(card.id) || busy"
|
||
:title="searchLegalIds.has(card.id) ? `Choose ${card.name}` : `${card.name} does not match this search`"
|
||
@click="chooseSearchCard(card)"
|
||
>
|
||
<CardHover :oracle-id="card.oracleId" :name="card.name">
|
||
<GameCard :oracle-id="card.oracleId" :name="card.name" />
|
||
</CardHover>
|
||
<span class="search-name">{{ card.name }}</span>
|
||
</button>
|
||
</div>
|
||
<p class="muted small">Cards that do not match this search are dimmed.</p>
|
||
</section>
|
||
</div>
|
||
</Teleport>
|
||
|
||
<Teleport to="body">
|
||
<template v-if="menuOpen">
|
||
<div class="menu-backdrop" @pointerdown="menuOpen = false" />
|
||
<div class="game-menu" role="menu" aria-label="Game menu">
|
||
<div class="game-menu-head">
|
||
<span class="tag" :class="connectionClass">{{ connection }}</span>
|
||
<span class="muted small">Connection</span>
|
||
</div>
|
||
<button type="button" role="menuitem" class="menu-item" @click="menuAction(copyLink)">
|
||
Copy link
|
||
</button>
|
||
<button
|
||
v-if="game"
|
||
type="button"
|
||
role="menuitem"
|
||
class="menu-item"
|
||
@click="menuAction(() => { showLog = !showLog })"
|
||
>{{ showLog ? 'Hide log' : 'Show log' }}</button>
|
||
<button
|
||
v-if="game"
|
||
type="button"
|
||
role="menuitem"
|
||
class="menu-item"
|
||
@click="menuAction(resetView)"
|
||
>Reset view</button>
|
||
<template v-if="token">
|
||
<div class="game-menu-divider" />
|
||
<button
|
||
type="button"
|
||
role="menuitem"
|
||
class="menu-item leave"
|
||
:disabled="busy"
|
||
@click="menuAction(leaveGame)"
|
||
>Forfeit</button>
|
||
</template>
|
||
</div>
|
||
</template>
|
||
</Teleport>
|
||
|
||
<Teleport to="body">
|
||
<template v-if="menuCard">
|
||
<div class="menu-backdrop" @pointerdown="closeMenu" />
|
||
<div
|
||
ref="menuEl"
|
||
class="context-menu"
|
||
role="menu"
|
||
:aria-label="`${menuCard.name} actions`"
|
||
:style="{ left: `${menu?.x ?? 0}px`, top: `${menu?.y ?? 0}px` }"
|
||
>
|
||
<template v-for="ability in activatedAbilities(menuCard)" :key="ability.index">
|
||
<div v-if="ability.manaColors?.length" class="menu-choice">
|
||
<span class="menu-choice-label"><SymbolText :text="ability.text || 'Activate'" /></span>
|
||
<div class="menu-choice-colors">
|
||
<button
|
||
v-for="color in ability.manaColors"
|
||
:key="color"
|
||
type="button"
|
||
role="menuitem"
|
||
class="menu-color"
|
||
:disabled="!canAct || busy"
|
||
:aria-label="`Add ${MANA_COLOR_NAMES[color] ?? color} mana`"
|
||
:title="`Add ${MANA_COLOR_NAMES[color] ?? color} mana`"
|
||
@click="activateFromMenu(menuCard, ability, color)"
|
||
>
|
||
<ManaCost :cost="`{${color}}`" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<button
|
||
v-else
|
||
type="button"
|
||
role="menuitem"
|
||
class="menu-item"
|
||
:disabled="!canAct || busy"
|
||
@click="activateFromMenu(menuCard, ability)"
|
||
>
|
||
<SymbolText :text="ability.text || 'Activate'" />
|
||
</button>
|
||
</template>
|
||
</div>
|
||
</template>
|
||
</Teleport>
|
||
</main>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.game-head {
|
||
display: flex;
|
||
align-items: start;
|
||
justify-content: space-between;
|
||
gap: 1rem;
|
||
}
|
||
|
||
.game-page {
|
||
position: relative;
|
||
padding: 0;
|
||
gap: 0;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.game-page > .game-head {
|
||
position: absolute;
|
||
inset: 0 0 auto;
|
||
z-index: 40;
|
||
padding: 0.85rem 1rem 1.5rem;
|
||
background: linear-gradient(to bottom, rgb(15 17 23 / 94%), rgb(15 17 23 / 0%));
|
||
pointer-events: none;
|
||
}
|
||
|
||
.game-page > .game-head .row {
|
||
pointer-events: auto;
|
||
}
|
||
|
||
.game-page > .error,
|
||
.game-page > .ok,
|
||
.game-page > .winner {
|
||
position: absolute;
|
||
top: 4.6rem;
|
||
left: 1rem;
|
||
z-index: 41;
|
||
max-width: min(42rem, calc(100% - 2rem));
|
||
padding: 0.4rem 0.65rem;
|
||
border: 1px solid var(--line);
|
||
border-radius: 6px;
|
||
background: rgb(15 17 23 / 94%);
|
||
}
|
||
|
||
.turn-actions {
|
||
position: fixed;
|
||
right: 1.25rem;
|
||
bottom: 1rem;
|
||
z-index: 40;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0.6rem;
|
||
}
|
||
|
||
.turn-button {
|
||
font-size: 1rem;
|
||
padding: 0.75rem 1.4rem;
|
||
border-radius: 10px;
|
||
background: var(--panel);
|
||
box-shadow: 0 8px 24px rgb(0 0 0 / 45%);
|
||
}
|
||
|
||
.turn-toggle {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0.4rem;
|
||
padding: 0.5rem 0.7rem;
|
||
border: 1px solid var(--line);
|
||
border-radius: 10px;
|
||
background: rgb(15 17 23 / 94%);
|
||
box-shadow: 0 8px 24px rgb(0 0 0 / 45%);
|
||
color: var(--muted);
|
||
font-size: 0.8rem;
|
||
cursor: pointer;
|
||
user-select: none;
|
||
}
|
||
|
||
.turn-toggle.on {
|
||
border-color: var(--accent);
|
||
color: var(--text);
|
||
}
|
||
|
||
.turn-toggle input {
|
||
flex: none;
|
||
margin: 0;
|
||
accent-color: var(--accent);
|
||
}
|
||
|
||
.turn-button.end {
|
||
font-size: 1.1rem;
|
||
font-weight: 700;
|
||
padding: 0.85rem 1.6rem;
|
||
border-color: var(--accent);
|
||
background: var(--accent);
|
||
color: #0b1020;
|
||
}
|
||
|
||
.turn-button.end:not(:disabled):hover {
|
||
filter: brightness(1.1);
|
||
}
|
||
|
||
.mini {
|
||
font-size: 0.75rem;
|
||
padding: 0.2rem 0.45rem;
|
||
}
|
||
|
||
.field {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.25rem;
|
||
}
|
||
|
||
.field select,
|
||
.field input {
|
||
width: 100%;
|
||
}
|
||
|
||
.join-panel {
|
||
max-width: 30rem;
|
||
}
|
||
|
||
.lobby-panel {
|
||
flex: 1;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 1.75rem;
|
||
padding: 2rem 1rem;
|
||
text-align: center;
|
||
background:
|
||
radial-gradient(ellipse at 50% 0%, rgb(122 162 247 / 10%), transparent 60%),
|
||
var(--panel);
|
||
}
|
||
|
||
.lobby-head {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.3rem;
|
||
}
|
||
|
||
.lobby-actions {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 0.75rem;
|
||
}
|
||
|
||
.lobby-deck select {
|
||
min-width: 14rem;
|
||
}
|
||
|
||
.lobby-seats {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
justify-content: center;
|
||
gap: clamp(1rem, 3vw, 2rem);
|
||
width: 100%;
|
||
}
|
||
|
||
.lobby-seat {
|
||
width: clamp(9.5rem, 20vw, 14rem);
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
gap: 0.45rem;
|
||
}
|
||
|
||
.lobby-commander {
|
||
width: 100%;
|
||
transition: transform 160ms ease;
|
||
}
|
||
|
||
.lobby-seat:not(.empty):hover .lobby-commander {
|
||
transform: translateY(-4px);
|
||
}
|
||
|
||
.lobby-seat.self .lobby-commander {
|
||
border-radius: 6px;
|
||
outline: 2px solid var(--accent);
|
||
outline-offset: 3px;
|
||
}
|
||
|
||
.lobby-commander-empty {
|
||
display: grid;
|
||
place-items: center;
|
||
width: 100%;
|
||
aspect-ratio: 488 / 680;
|
||
border: 1px dashed var(--line);
|
||
border-radius: 6px;
|
||
background: rgb(17 21 29 / 45%);
|
||
color: var(--muted);
|
||
font-size: 2rem;
|
||
}
|
||
|
||
.lobby-commander-name {
|
||
font-size: 0.8rem;
|
||
color: var(--muted);
|
||
line-height: 1.2;
|
||
}
|
||
|
||
.lobby-badges {
|
||
display: flex;
|
||
gap: 0.3rem;
|
||
min-height: 1.3rem;
|
||
}
|
||
|
||
.game-layout {
|
||
position: absolute;
|
||
inset: 0;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.players {
|
||
position: absolute;
|
||
inset: 0;
|
||
overflow: hidden;
|
||
cursor: grab;
|
||
user-select: none;
|
||
touch-action: none;
|
||
background:
|
||
radial-gradient(ellipse at 50% 0%, rgb(60 110 82 / 22%), transparent 65%),
|
||
#121c17;
|
||
}
|
||
|
||
.players.panning {
|
||
cursor: grabbing;
|
||
}
|
||
|
||
.table-canvas {
|
||
position: relative;
|
||
min-width: 180rem;
|
||
display: grid;
|
||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||
align-content: start;
|
||
gap: 1.5rem;
|
||
/* Always reserve the sidebar column so toggling panels never reflows the board. */
|
||
padding: 5rem 24rem 15rem 1rem;
|
||
transform-origin: 0 0;
|
||
will-change: transform;
|
||
}
|
||
|
||
.player {
|
||
gap: 0.5rem;
|
||
min-height: 50rem;
|
||
background: rgb(17 21 29 / 76%);
|
||
border-color: #2e4437;
|
||
}
|
||
|
||
.combat-arrows {
|
||
position: absolute;
|
||
inset: 0;
|
||
width: 100%;
|
||
height: 100%;
|
||
overflow: visible;
|
||
pointer-events: none;
|
||
}
|
||
|
||
.combat-arrows > path {
|
||
fill: none;
|
||
stroke-width: 4;
|
||
stroke-linecap: round;
|
||
filter: drop-shadow(0 0 3px rgb(0 0 0 / 75%));
|
||
}
|
||
|
||
.combat-arrows > path.attack {
|
||
stroke: var(--bad);
|
||
}
|
||
|
||
.combat-arrows > path.block {
|
||
stroke: var(--accent);
|
||
}
|
||
|
||
.combat-arrows > path.pending {
|
||
stroke: var(--accent);
|
||
stroke-dasharray: 10 8;
|
||
opacity: 0.85;
|
||
}
|
||
|
||
.player.current {
|
||
border-color: var(--accent);
|
||
}
|
||
|
||
.player.attack-ready {
|
||
border-style: dashed;
|
||
border-color: var(--bad);
|
||
}
|
||
|
||
.player.drop-hover {
|
||
border-color: var(--bad);
|
||
box-shadow: inset 0 0 0 3px var(--bad), 0 0 24px rgb(224 122 122 / 35%);
|
||
}
|
||
|
||
.player.dead {
|
||
opacity: 0.6;
|
||
}
|
||
|
||
.player-head {
|
||
position: relative;
|
||
display: flex;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
gap: 0.4rem;
|
||
}
|
||
|
||
.player-head .mini.active {
|
||
border-color: var(--accent);
|
||
color: var(--accent);
|
||
}
|
||
|
||
.life {
|
||
display: inline-block;
|
||
font-size: 1.2rem;
|
||
font-weight: 700;
|
||
}
|
||
|
||
.player.anim-hit {
|
||
animation: player-hit 700ms ease-out;
|
||
}
|
||
|
||
.player.anim-heal {
|
||
animation: player-heal 700ms ease-out;
|
||
}
|
||
|
||
.life.life-hit {
|
||
animation: life-hit 700ms ease-out;
|
||
}
|
||
|
||
.life.life-heal {
|
||
animation: life-heal 700ms ease-out;
|
||
}
|
||
|
||
.float-text {
|
||
position: absolute;
|
||
top: -0.2rem;
|
||
left: 50%;
|
||
z-index: 35;
|
||
font-size: 1rem;
|
||
font-weight: 800;
|
||
line-height: 1;
|
||
pointer-events: none;
|
||
text-shadow: 0 1px 3px #000, 0 0 8px currentColor;
|
||
animation: float-up 1.05s ease-out forwards;
|
||
}
|
||
|
||
.float-text.damage {
|
||
color: var(--bad);
|
||
}
|
||
|
||
.float-text.heal {
|
||
color: var(--ok);
|
||
}
|
||
|
||
.player-float {
|
||
top: 0.15rem;
|
||
}
|
||
|
||
.card-float {
|
||
top: 22%;
|
||
font-size: 1.15rem;
|
||
transform: translateX(-50%);
|
||
}
|
||
|
||
@keyframes player-hit {
|
||
0%, 100% {
|
||
box-shadow: none;
|
||
}
|
||
18% {
|
||
box-shadow: inset 0 0 0 2px var(--bad), 0 0 26px rgb(224 122 122 / 55%);
|
||
}
|
||
55% {
|
||
box-shadow: inset 0 0 0 1px var(--bad), 0 0 12px rgb(224 122 122 / 30%);
|
||
}
|
||
}
|
||
|
||
@keyframes player-heal {
|
||
0%, 100% {
|
||
box-shadow: none;
|
||
}
|
||
18% {
|
||
box-shadow: inset 0 0 0 2px var(--ok), 0 0 26px rgb(125 211 160 / 45%);
|
||
}
|
||
55% {
|
||
box-shadow: inset 0 0 0 1px var(--ok), 0 0 12px rgb(125 211 160 / 25%);
|
||
}
|
||
}
|
||
|
||
@keyframes life-hit {
|
||
0%, 100% {
|
||
color: var(--text);
|
||
transform: scale(1);
|
||
}
|
||
28% {
|
||
color: var(--bad);
|
||
transform: scale(1.35);
|
||
}
|
||
}
|
||
|
||
@keyframes life-heal {
|
||
0%, 100% {
|
||
color: var(--text);
|
||
transform: scale(1);
|
||
}
|
||
28% {
|
||
color: var(--ok);
|
||
transform: scale(1.3);
|
||
}
|
||
}
|
||
|
||
@keyframes float-up {
|
||
0% {
|
||
opacity: 0;
|
||
transform: translate(-50%, 0.45rem) scale(0.75);
|
||
}
|
||
18% {
|
||
opacity: 1;
|
||
transform: translate(-50%, 0) scale(1.15);
|
||
}
|
||
72% {
|
||
opacity: 1;
|
||
}
|
||
100% {
|
||
opacity: 0;
|
||
transform: translate(-50%, -1.5rem) scale(0.95);
|
||
}
|
||
}
|
||
|
||
.damage {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 0.3rem;
|
||
}
|
||
|
||
.play-area {
|
||
flex: 1;
|
||
display: flex;
|
||
align-items: stretch;
|
||
gap: 0.6rem;
|
||
min-height: 0;
|
||
}
|
||
|
||
.play-area.command-right {
|
||
flex-direction: row-reverse;
|
||
}
|
||
|
||
.zone {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: stretch;
|
||
gap: 0.25rem;
|
||
border: 1px dashed var(--line);
|
||
border-radius: 6px;
|
||
padding: 0.3rem;
|
||
}
|
||
|
||
.side-zones {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.4rem;
|
||
flex: 0 0 7rem;
|
||
}
|
||
|
||
.graveyard-stack {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: stretch;
|
||
}
|
||
|
||
/* overlap card faces into a pile; the last (newest) card sits on top */
|
||
.graveyard-stack > * {
|
||
margin-top: -122%;
|
||
}
|
||
|
||
.graveyard-stack > :first-child {
|
||
margin-top: 0;
|
||
}
|
||
|
||
.library-stack {
|
||
position: relative;
|
||
width: 100%;
|
||
aspect-ratio: 488 / 680;
|
||
}
|
||
|
||
.library-back {
|
||
position: absolute;
|
||
inset: 0;
|
||
border: 1px solid #3a4660;
|
||
border-radius: 6px;
|
||
background-color: var(--card-back-color, #26304a);
|
||
background-image: var(--card-back-image, none);
|
||
background-position: center;
|
||
background-size: cover;
|
||
box-shadow: 0 3px 10px rgb(0 0 0 / 45%);
|
||
}
|
||
|
||
.face-down-card {
|
||
display: block;
|
||
width: 100%;
|
||
aspect-ratio: 488 / 680;
|
||
border: 1px solid #3a4660;
|
||
border-radius: 6px;
|
||
background-color: var(--card-back-color, #26304a);
|
||
background-image: var(--card-back-image, none);
|
||
background-position: center;
|
||
background-size: cover;
|
||
box-shadow: 0 3px 10px rgb(0 0 0 / 45%);
|
||
}
|
||
|
||
/* Tuck face-down hideaway cards under their permanent. */
|
||
.hidden-exile {
|
||
position: absolute;
|
||
z-index: -1;
|
||
top: 50%;
|
||
left: 50%;
|
||
width: 86%;
|
||
aspect-ratio: 488 / 680;
|
||
transform: translateX(-50%);
|
||
pointer-events: none;
|
||
}
|
||
|
||
.hidden-exile-card {
|
||
position: absolute;
|
||
inset: 0;
|
||
}
|
||
|
||
/* Offset the back layers down-right to read as a pile. */
|
||
.library-back:nth-child(1) { z-index: 3; }
|
||
.library-back:nth-child(2) { z-index: 2; translate: 3px 3px; }
|
||
.library-back:nth-child(3) { z-index: 1; translate: 6px 6px; }
|
||
|
||
.zone-label {
|
||
font-size: 0.7rem;
|
||
text-align: center;
|
||
text-transform: uppercase;
|
||
letter-spacing: 0.04em;
|
||
color: var(--muted);
|
||
}
|
||
|
||
.command-card {
|
||
width: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: stretch;
|
||
gap: 0.25rem;
|
||
font-size: 0.7rem;
|
||
}
|
||
|
||
.battlefield {
|
||
--perm-width: 7rem;
|
||
position: relative;
|
||
flex: 1;
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fill, minmax(var(--perm-width), 1fr));
|
||
align-content: start;
|
||
gap: 0.5rem;
|
||
min-height: 40rem;
|
||
padding: 0.4rem;
|
||
border: 1px solid transparent;
|
||
border-radius: 8px;
|
||
background-position: center;
|
||
background-size: cover;
|
||
}
|
||
|
||
.battlefield.has-playmat {
|
||
border-color: #2e4437;
|
||
background-image:
|
||
linear-gradient(rgb(8 10 14 / 48%), rgb(8 10 14 / 48%)),
|
||
var(--playmat);
|
||
}
|
||
|
||
.perm {
|
||
position: relative;
|
||
isolation: isolate;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.25rem;
|
||
min-width: 0;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.perm.anim-enter .game-card {
|
||
animation: perm-enter 520ms cubic-bezier(0.2, 0.8, 0.2, 1);
|
||
}
|
||
|
||
.perm.anim-damage .game-card {
|
||
animation: perm-damage 500ms ease-in-out;
|
||
}
|
||
|
||
.perm.anim-attack .game-card {
|
||
animation: perm-attack 540ms cubic-bezier(0.2, 0.8, 0.2, 1);
|
||
}
|
||
|
||
@keyframes perm-enter {
|
||
0% {
|
||
opacity: 0;
|
||
filter: brightness(1.8);
|
||
transform: translateY(-1.6rem) scale(0.65) rotate(-5deg);
|
||
}
|
||
65% {
|
||
opacity: 1;
|
||
filter: brightness(1.15);
|
||
transform: translateY(0.15rem) scale(1.04) rotate(1deg);
|
||
}
|
||
100% {
|
||
opacity: 1;
|
||
filter: none;
|
||
transform: none;
|
||
}
|
||
}
|
||
|
||
@keyframes perm-damage {
|
||
0%, 100% {
|
||
filter: none;
|
||
transform: translateX(0);
|
||
}
|
||
16% {
|
||
filter: brightness(1.5) drop-shadow(0 0 0.5rem var(--bad));
|
||
transform: translateX(-0.32rem) rotate(-1deg);
|
||
}
|
||
38% {
|
||
transform: translateX(0.3rem) rotate(1deg);
|
||
}
|
||
60% {
|
||
transform: translateX(-0.2rem);
|
||
}
|
||
80% {
|
||
transform: translateX(0.12rem);
|
||
}
|
||
}
|
||
|
||
@keyframes perm-attack {
|
||
0%, 100% {
|
||
filter: none;
|
||
transform: translateY(0) scale(1);
|
||
}
|
||
42% {
|
||
filter: brightness(1.25) drop-shadow(0 0 0.5rem var(--bad));
|
||
transform: translateY(-0.45rem) scale(1.06);
|
||
}
|
||
}
|
||
|
||
.perm.movable {
|
||
cursor: grab;
|
||
}
|
||
|
||
.perm.has-hidden {
|
||
z-index: 1;
|
||
}
|
||
|
||
.perm.positioned {
|
||
position: absolute;
|
||
width: var(--perm-width);
|
||
z-index: 3;
|
||
transform: translate(-50%, -50%);
|
||
transition: left 120ms ease, top 120ms ease;
|
||
}
|
||
|
||
.perm.dragging {
|
||
z-index: 20;
|
||
cursor: grabbing;
|
||
transition: none;
|
||
}
|
||
|
||
.perm.selected .game-card,
|
||
.perm:focus-visible .game-card {
|
||
border-radius: 6px;
|
||
outline: 2px solid var(--accent);
|
||
outline-offset: 2px;
|
||
}
|
||
|
||
.perm.pending-attack .game-card {
|
||
border-radius: 6px;
|
||
outline: 2px solid var(--bad);
|
||
outline-offset: 2px;
|
||
}
|
||
|
||
.perm:focus-visible {
|
||
outline: none;
|
||
}
|
||
|
||
.stats {
|
||
position: absolute;
|
||
right: 0.2rem;
|
||
bottom: 0.2rem;
|
||
z-index: 2;
|
||
padding: 0 0.25rem;
|
||
border: 1px solid var(--line);
|
||
border-radius: 4px;
|
||
background: rgb(8 10 14 / 84%);
|
||
font-size: 0.72rem;
|
||
font-weight: 700;
|
||
color: var(--warn);
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.overlay-tag {
|
||
position: absolute;
|
||
z-index: 2;
|
||
padding: 0 0.3rem;
|
||
border: 1px solid var(--line);
|
||
border-radius: 4px;
|
||
background: rgb(8 10 14 / 84%);
|
||
font-size: 0.6rem;
|
||
line-height: 1.4;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.overlay-tag.commander {
|
||
top: 0.2rem;
|
||
left: 0.2rem;
|
||
color: var(--warn);
|
||
}
|
||
|
||
.overlay-tag.chosen {
|
||
bottom: 0.2rem;
|
||
left: 50%;
|
||
transform: translateX(-50%);
|
||
max-width: 80%;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
color: var(--accent);
|
||
}
|
||
|
||
.overlay-tag.attacking {
|
||
top: 0.2rem;
|
||
right: 0.2rem;
|
||
color: var(--bad);
|
||
}
|
||
|
||
.overlay-tag.card-damage {
|
||
top: 0.2rem;
|
||
left: 50%;
|
||
transform: translateX(-50%);
|
||
color: var(--bad);
|
||
}
|
||
|
||
.overlay-counters {
|
||
position: absolute;
|
||
left: 0.2rem;
|
||
bottom: 0.2rem;
|
||
z-index: 2;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: flex-start;
|
||
gap: 0.15rem;
|
||
}
|
||
|
||
.overlay-counters .overlay-tag {
|
||
position: static;
|
||
}
|
||
|
||
.menu-backdrop {
|
||
position: fixed;
|
||
inset: 0;
|
||
z-index: 60;
|
||
}
|
||
|
||
.hamburger {
|
||
font-size: 1rem;
|
||
line-height: 1;
|
||
padding: 0.3rem 0.55rem;
|
||
}
|
||
|
||
.game-menu {
|
||
position: fixed;
|
||
top: 3.5rem;
|
||
right: 1rem;
|
||
z-index: 61;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.1rem;
|
||
min-width: 12rem;
|
||
padding: 0.3rem;
|
||
border: 1px solid var(--line);
|
||
border-radius: 8px;
|
||
background: var(--panel);
|
||
box-shadow: 0 12px 28px rgb(0 0 0 / 55%);
|
||
}
|
||
|
||
.game-menu-head {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0.4rem;
|
||
padding: 0.3rem 0.5rem 0.45rem;
|
||
}
|
||
|
||
.game-menu-divider {
|
||
height: 1px;
|
||
margin: 0.3rem 0.2rem;
|
||
background: var(--line);
|
||
}
|
||
|
||
.menu-item.leave {
|
||
color: var(--bad);
|
||
}
|
||
|
||
.context-menu {
|
||
position: fixed;
|
||
z-index: 61;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.1rem;
|
||
width: 16rem;
|
||
max-width: calc(100vw - 1rem);
|
||
padding: 0.3rem;
|
||
border: 1px solid var(--line);
|
||
border-radius: 8px;
|
||
background: var(--panel);
|
||
box-shadow: 0 12px 28px rgb(0 0 0 / 55%);
|
||
}
|
||
|
||
.menu-item {
|
||
padding: 0.4rem 0.5rem;
|
||
border: 0;
|
||
border-radius: 5px;
|
||
background: transparent;
|
||
text-align: left;
|
||
font-size: 0.8rem;
|
||
line-height: 1.35;
|
||
}
|
||
|
||
.menu-item:not(:disabled):hover {
|
||
border-color: transparent;
|
||
background: var(--panel-2);
|
||
}
|
||
|
||
.menu-choice {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.3rem;
|
||
padding: 0.4rem 0.5rem;
|
||
}
|
||
|
||
.menu-choice-label {
|
||
color: var(--muted);
|
||
font-size: 0.8rem;
|
||
line-height: 1.35;
|
||
}
|
||
|
||
.menu-choice-colors {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 0.25rem;
|
||
}
|
||
|
||
.menu-color {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 0.25rem;
|
||
border: 1px solid var(--line);
|
||
border-radius: 5px;
|
||
background: transparent;
|
||
}
|
||
|
||
.menu-color:not(:disabled):hover {
|
||
border-color: transparent;
|
||
background: var(--panel-2);
|
||
}
|
||
|
||
.small {
|
||
font-size: 0.72rem;
|
||
}
|
||
|
||
.zone-bar {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0.3rem;
|
||
}
|
||
|
||
.zone-link {
|
||
padding: 0;
|
||
border: 0;
|
||
background: none;
|
||
color: inherit;
|
||
text-decoration: underline dotted;
|
||
text-underline-offset: 0.2em;
|
||
}
|
||
|
||
.zone-link.active {
|
||
color: var(--accent);
|
||
}
|
||
|
||
.zone-cards {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
|
||
gap: 0.5rem;
|
||
}
|
||
|
||
.zone-card {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.25rem;
|
||
}
|
||
|
||
.sidebar {
|
||
position: absolute;
|
||
top: 4.6rem;
|
||
right: 0.75rem;
|
||
z-index: 20;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.75rem;
|
||
width: min(22rem, calc(100% - 1.5rem));
|
||
max-height: calc(100% - 5.35rem);
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.side {
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.cast-panel .oracle {
|
||
max-height: 8rem;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.search-backdrop {
|
||
position: fixed;
|
||
inset: 0;
|
||
z-index: 70;
|
||
display: grid;
|
||
place-items: center;
|
||
padding: 1rem;
|
||
background: rgb(0 0 0 / 65%);
|
||
}
|
||
|
||
.search-modal {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.75rem;
|
||
width: min(60rem, 100%);
|
||
max-height: calc(100vh - 2rem);
|
||
padding: 1rem;
|
||
background: var(--panel);
|
||
border: 1px solid var(--line);
|
||
border-radius: 12px;
|
||
}
|
||
|
||
.search-head {
|
||
display: flex;
|
||
align-items: flex-start;
|
||
gap: 0.75rem;
|
||
}
|
||
|
||
.search-head h2,
|
||
.search-head p {
|
||
margin: 0;
|
||
}
|
||
|
||
.search-filter {
|
||
width: 100%;
|
||
flex: 0 0 auto;
|
||
}
|
||
|
||
.search-library {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fill, minmax(6.2rem, 1fr));
|
||
gap: 0.5rem;
|
||
min-height: 0;
|
||
flex: 1 1 auto;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.search-card {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.25rem;
|
||
padding: 0.25rem;
|
||
border-color: transparent;
|
||
opacity: 0.35;
|
||
text-align: center;
|
||
}
|
||
|
||
.search-card.legal {
|
||
border-color: var(--line);
|
||
opacity: 1;
|
||
}
|
||
|
||
.search-card.legal:hover:not(:disabled) {
|
||
border-color: var(--accent);
|
||
}
|
||
|
||
.search-card:disabled {
|
||
cursor: not-allowed;
|
||
}
|
||
|
||
.search-name {
|
||
overflow: hidden;
|
||
font-size: 0.72rem;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.choice-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
|
||
gap: 0.35rem;
|
||
min-height: 0;
|
||
flex: 1 1 auto;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.choice-option {
|
||
font-size: 0.78rem;
|
||
}
|
||
|
||
.attack-list {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.3rem;
|
||
}
|
||
|
||
.attack-pick {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 0.5rem;
|
||
width: 100%;
|
||
font-size: 0.8rem;
|
||
text-align: left;
|
||
}
|
||
|
||
.attack-pick:hover {
|
||
border-color: var(--bad);
|
||
}
|
||
|
||
.block-list {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.3rem;
|
||
}
|
||
|
||
.block-row {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 0.5rem;
|
||
font-size: 0.85rem;
|
||
}
|
||
|
||
.block-pick {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 0.3rem;
|
||
}
|
||
|
||
.perm.block-source .game-card {
|
||
border-radius: 6px;
|
||
outline: 2px dashed var(--accent);
|
||
outline-offset: 2px;
|
||
}
|
||
|
||
.perm.block-hover .game-card {
|
||
border-radius: 6px;
|
||
outline: 2px solid var(--accent);
|
||
outline-offset: 2px;
|
||
}
|
||
|
||
.mulligan-backdrop {
|
||
position: fixed;
|
||
inset: 0;
|
||
z-index: 65;
|
||
background: rgb(0 0 0 / 82%);
|
||
}
|
||
|
||
.hand-panel {
|
||
position: absolute;
|
||
bottom: 0;
|
||
left: 50%;
|
||
z-index: 25;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.25rem;
|
||
width: min(100%, 60rem);
|
||
padding: 0 0.5rem;
|
||
font-size: 1rem;
|
||
pointer-events: none;
|
||
transform: translateX(-50%);
|
||
}
|
||
|
||
.hand-panel.mulligan-mode {
|
||
position: fixed;
|
||
top: 50%;
|
||
bottom: auto;
|
||
z-index: 66;
|
||
width: min(100%, 60rem);
|
||
padding: 0 0.5rem;
|
||
transform: translate(-50%, -50%);
|
||
}
|
||
|
||
.hand-head {
|
||
justify-content: center;
|
||
padding: 0 0.25rem;
|
||
pointer-events: auto;
|
||
}
|
||
|
||
.mulligan-bar {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 0.5rem;
|
||
margin: 0 0.5rem;
|
||
padding: 0.45rem 0.7rem;
|
||
border: 1px solid var(--line);
|
||
border-radius: 0.5rem;
|
||
background: var(--panel);
|
||
font-size: 0.9rem;
|
||
pointer-events: auto;
|
||
}
|
||
|
||
.hand-head h2 {
|
||
font-size: 0.95rem;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.mana-row {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 0.25rem;
|
||
}
|
||
|
||
.mana-burst {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 0.1rem;
|
||
font-size: 0.85rem;
|
||
font-weight: 700;
|
||
text-shadow: 0 0 8px currentColor;
|
||
animation: mana-burst 1.05s ease-out forwards;
|
||
}
|
||
|
||
@keyframes mana-burst {
|
||
0% {
|
||
opacity: 0;
|
||
transform: translateY(0.45rem) scale(0.7);
|
||
}
|
||
20% {
|
||
opacity: 1;
|
||
transform: translateY(0) scale(1.12);
|
||
}
|
||
70% {
|
||
opacity: 1;
|
||
transform: translateY(-0.2rem) scale(1);
|
||
}
|
||
100% {
|
||
opacity: 0;
|
||
transform: translateY(-0.8rem) scale(0.95);
|
||
}
|
||
}
|
||
|
||
.hand-fan {
|
||
position: relative;
|
||
height: 12em;
|
||
pointer-events: none;
|
||
}
|
||
|
||
.hand-card {
|
||
position: absolute;
|
||
bottom: 3em;
|
||
left: 50%;
|
||
width: 6.5em;
|
||
user-select: none;
|
||
pointer-events: auto;
|
||
transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
|
||
will-change: transform;
|
||
}
|
||
|
||
.hand-card.playable {
|
||
cursor: pointer;
|
||
}
|
||
|
||
.hand-card.playable .hand-lift {
|
||
outline: 2px solid #58a6ff;
|
||
outline-offset: 2px;
|
||
border-radius: 8px;
|
||
}
|
||
|
||
.hand-card:hover,
|
||
.hand-card:focus-within {
|
||
z-index: 30;
|
||
}
|
||
|
||
.hand-lift {
|
||
position: relative;
|
||
display: flex;
|
||
flex-direction: column;
|
||
transform-origin: 50% 100%;
|
||
transition: transform 180ms cubic-bezier(0.2, 0.9, 0.3, 1.15), filter 180ms ease;
|
||
}
|
||
|
||
.hand-card:hover .hand-lift,
|
||
.hand-card:focus-within .hand-lift {
|
||
transform: translateY(-3.25em) rotate(calc(var(--angle, 0deg) * -1)) scale(1.08);
|
||
filter: drop-shadow(0 14px 22px rgb(0 0 0 / 55%));
|
||
}
|
||
|
||
.hand-options {
|
||
position: absolute;
|
||
bottom: 0.4em;
|
||
left: 50%;
|
||
z-index: 3;
|
||
transform: translateX(-50%);
|
||
white-space: nowrap;
|
||
}
|
||
|
||
@media (hover: hover) {
|
||
.hand-options {
|
||
opacity: 0;
|
||
pointer-events: none;
|
||
transition: opacity 120ms ease;
|
||
}
|
||
|
||
.hand-card:hover .hand-options,
|
||
.hand-card:focus-within .hand-options {
|
||
opacity: 1;
|
||
pointer-events: auto;
|
||
}
|
||
}
|
||
|
||
.hand-leave-active {
|
||
pointer-events: none;
|
||
}
|
||
|
||
.hand-enter-active .hand-lift,
|
||
.hand-leave-active .hand-lift {
|
||
transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 180ms ease;
|
||
}
|
||
|
||
.hand-enter-from .hand-lift,
|
||
.hand-leave-to .hand-lift {
|
||
opacity: 0;
|
||
transform: translateY(2.5em) scale(0.7);
|
||
}
|
||
|
||
.stack-pile {
|
||
position: absolute;
|
||
top: 5rem;
|
||
right: 24rem;
|
||
z-index: 22;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.35rem;
|
||
width: min(15rem, calc(100% - 2rem));
|
||
pointer-events: none;
|
||
transition: opacity 160ms ease;
|
||
}
|
||
|
||
.stack-pile.empty {
|
||
opacity: 0;
|
||
}
|
||
|
||
.stack-heading {
|
||
display: flex;
|
||
gap: 0.4rem;
|
||
align-items: baseline;
|
||
margin: 0;
|
||
font-size: 0.72rem;
|
||
letter-spacing: 0.08em;
|
||
text-transform: uppercase;
|
||
color: var(--muted);
|
||
}
|
||
|
||
.stack-pile-list {
|
||
list-style: none;
|
||
margin: 0;
|
||
padding: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.stack-pile-list > li + li {
|
||
margin-top: -2.9rem;
|
||
}
|
||
|
||
.stack-card {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0.5rem;
|
||
min-height: 4.4rem;
|
||
padding: 0.5rem 0.65rem;
|
||
border: 1px solid #3c4d64;
|
||
border-left: 3px solid var(--accent);
|
||
border-radius: 8px;
|
||
background: #141a24;
|
||
box-shadow: 0 8px 18px rgb(0 0 0 / 50%);
|
||
transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 220ms ease;
|
||
}
|
||
|
||
.stack-card.kind-ability {
|
||
border-left-color: #c9a86a;
|
||
}
|
||
|
||
.stack-card.is-top {
|
||
border-color: rgb(122 162 247 / 65%);
|
||
box-shadow:
|
||
0 0 0 1px rgb(122 162 247 / 25%),
|
||
0 0 20px rgb(122 162 247 / 25%),
|
||
0 10px 24px rgb(0 0 0 / 55%);
|
||
}
|
||
|
||
.stack-card.kind-ability.is-top {
|
||
border-color: rgb(201 168 106 / 60%);
|
||
box-shadow:
|
||
0 0 0 1px rgb(201 168 106 / 22%),
|
||
0 0 20px rgb(201 168 106 / 20%),
|
||
0 10px 24px rgb(0 0 0 / 55%);
|
||
}
|
||
|
||
.stack-glyph {
|
||
flex: 0 0 auto;
|
||
font-size: 1.05rem;
|
||
color: var(--accent);
|
||
}
|
||
|
||
.kind-ability .stack-glyph {
|
||
color: #c9a86a;
|
||
}
|
||
|
||
.stack-copy {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.1rem;
|
||
min-width: 0;
|
||
line-height: 1.2;
|
||
}
|
||
|
||
.stack-copy strong {
|
||
display: -webkit-box;
|
||
overflow: hidden;
|
||
font-size: 0.8rem;
|
||
-webkit-box-orient: vertical;
|
||
-webkit-line-clamp: 2;
|
||
}
|
||
|
||
.stack-copy .muted {
|
||
overflow: hidden;
|
||
font-size: 0.68rem;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.stack-enter-active {
|
||
transition: transform 300ms cubic-bezier(0.2, 0.9, 0.25, 1.15), opacity 200ms ease, filter 300ms ease;
|
||
}
|
||
|
||
.stack-leave-active {
|
||
transition: transform 200ms ease-in, opacity 180ms ease-in;
|
||
}
|
||
|
||
.stack-enter-from {
|
||
opacity: 0;
|
||
filter: brightness(1.9);
|
||
transform: translate(4rem, -1.2rem) rotate(6deg) scale(0.82);
|
||
}
|
||
|
||
.stack-leave-to {
|
||
opacity: 0;
|
||
transform: translate(3rem, -0.8rem) rotate(3deg) scale(0.9);
|
||
}
|
||
|
||
.stack-move {
|
||
transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
|
||
}
|
||
|
||
.log-panel {
|
||
max-height: 16rem;
|
||
}
|
||
|
||
.log-list {
|
||
list-style: none;
|
||
margin: 0;
|
||
padding: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.2rem;
|
||
font-size: 0.78rem;
|
||
color: var(--muted);
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.winner {
|
||
font-size: 1.1rem;
|
||
color: var(--ok);
|
||
display: flex;
|
||
gap: 0.75rem;
|
||
align-items: center;
|
||
}
|
||
|
||
@media (prefers-reduced-motion: reduce) {
|
||
.perm.anim-enter .game-card,
|
||
.perm.anim-damage .game-card,
|
||
.perm.anim-attack .game-card,
|
||
.player.anim-hit,
|
||
.player.anim-heal,
|
||
.life.life-hit,
|
||
.life.life-heal,
|
||
.float-text,
|
||
.mana-burst {
|
||
animation: none;
|
||
}
|
||
|
||
.stack-enter-active,
|
||
.stack-leave-active,
|
||
.stack-move {
|
||
transition: none;
|
||
}
|
||
}
|
||
|
||
@media (max-width: 1000px) {
|
||
.game-page {
|
||
height: auto;
|
||
min-height: calc(100vh - 3rem);
|
||
padding: 1rem 1.25rem 5.5rem;
|
||
gap: 1rem;
|
||
overflow: visible;
|
||
}
|
||
|
||
.game-page > .game-head {
|
||
position: static;
|
||
padding: 0;
|
||
background: none;
|
||
pointer-events: auto;
|
||
}
|
||
|
||
.game-page > .error,
|
||
.game-page > .ok,
|
||
.game-page > .winner {
|
||
position: static;
|
||
max-width: none;
|
||
padding: 0;
|
||
border: 0;
|
||
background: none;
|
||
}
|
||
|
||
.game-layout {
|
||
position: relative;
|
||
inset: auto;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.75rem;
|
||
overflow: visible;
|
||
}
|
||
|
||
.players {
|
||
position: relative;
|
||
inset: auto;
|
||
min-height: 24rem;
|
||
overflow: visible;
|
||
border: 1px solid #24372c;
|
||
border-radius: 12px;
|
||
cursor: auto;
|
||
touch-action: auto;
|
||
}
|
||
|
||
.table-canvas {
|
||
min-width: 0;
|
||
grid-template-columns: 1fr;
|
||
padding: 0.6rem;
|
||
transform: none !important;
|
||
}
|
||
|
||
.player {
|
||
min-height: 32rem;
|
||
}
|
||
|
||
.battlefield {
|
||
--perm-width: 6rem;
|
||
min-height: 24rem;
|
||
}
|
||
|
||
.side-zones {
|
||
flex-basis: 6rem;
|
||
}
|
||
|
||
.sidebar {
|
||
position: static;
|
||
width: auto;
|
||
max-height: none;
|
||
overflow: visible;
|
||
}
|
||
|
||
.stack-pile {
|
||
position: static;
|
||
width: auto;
|
||
}
|
||
|
||
.stack-pile.empty {
|
||
display: none;
|
||
}
|
||
|
||
.hand-panel {
|
||
position: static;
|
||
width: auto;
|
||
padding: 0;
|
||
pointer-events: auto;
|
||
transform: none;
|
||
}
|
||
}
|
||
|
||
@media (max-width: 700px) {
|
||
.hand-panel {
|
||
font-size: 0.78rem;
|
||
}
|
||
}
|
||
|
||
@media (max-width: 480px) {
|
||
.hand-panel {
|
||
font-size: 0.62rem;
|
||
}
|
||
}
|
||
</style>
|