v0.7.0 cli client with readline added, directory structure updated

This commit is contained in:
2025-11-13 08:55:06 -05:00
parent 52868af4ea
commit 6bdc061508
52 changed files with 2260 additions and 157 deletions

View File

@ -0,0 +1,750 @@
// FILE: lixenwraith/chess/internal/server/webserver/web/app.js
// Game state management
let gameState = {
gameId: null,
fen: null,
turn: 'w',
isPlayerWhite: true,
isLocked: false,
pollInterval: null,
apiUrl: '',
selectedSquare: null,
healthCheckInterval: null,
networkError: false,
moveList: [],
};
// Chess piece Unicode: all black pieces for better fill, white pawn due to inability to override emoji variant display
const pieceMap = {
'p': '♙', 'r': '♜', 'n': '♞', 'b': '♝', 'q': '♛', 'k': '♚',
'P': '♙', 'R': '♜', 'N': '♞', 'B': '♝', 'Q': '♛', 'K': '♚'
};
// Initialize on page load
document.addEventListener('DOMContentLoaded', async () => {
const config = await getConfig();
gameState.apiUrl = config.apiUrl;
document.getElementById('new-game-btn').addEventListener('click', showNewGameModal);
document.getElementById('undo-btn').addEventListener('click', undoMoves);
document.getElementById('start-game-btn').addEventListener('click', startNewGame);
document.getElementById('cancel-btn').addEventListener('click', hideNewGameModal);
document.getElementById('copy-history').addEventListener('click', copyHistory);
const levelSlider = document.getElementById('computer-level');
const levelValue = document.getElementById('level-value');
levelSlider.addEventListener('input', () => { levelValue.textContent = levelSlider.value; });
const timeSlider = document.getElementById('search-time');
const timeValue = document.getElementById('time-value');
timeSlider.addEventListener('input', () => { timeValue.textContent = timeSlider.value; });
startHealthCheck();
// Don't auto-show modal on load
});
async function getConfig() {
try {
const response = await fetch('/config');
return await response.json();
} catch (error) {
console.error('Failed to get config:', error);
return { apiUrl: 'http://localhost:8080' };
}
}
function startHealthCheck() {
const checkHealth = async () => {
try {
const response = await fetch(`${gameState.apiUrl}/health`);
if (response.ok) {
const health = await response.json();
updateServerIndicator(health.status === 'healthy' ? 'healthy' : 'degraded');
updateStorageIndicator(health.storage || 'unknown');
gameState.networkError = false;
} else {
handleApiError('health check', null, response);
updateStorageIndicator('unknown');
}
} catch (error) {
handleApiError('health check', error);
updateStorageIndicator('unknown');
}
};
checkHealth();
gameState.healthCheckInterval = setInterval(checkHealth, 10000);
}
function updateServerIndicator(status, message = null) {
const indicator = document.getElementById('server-indicator');
const light = indicator.querySelector('.light');
light.setAttribute('data-status', status);
// Set custom tooltip if message provided
if (message) {
indicator.setAttribute('data-status', message);
} else {
// Default messages
const defaultMessages = {
'healthy': 'healthy',
'degraded': 'degraded',
'unknown': 'unknown'
};
indicator.setAttribute('data-status', defaultMessages[status] || status);
}
}
function updateStorageIndicator(status) {
const indicator = document.getElementById('storage-indicator');
const light = indicator.querySelector('.light');
light.setAttribute('data-status', status);
indicator.setAttribute('data-status', status);
}
function updateTurnIndicator(state, turn) {
const indicator = document.getElementById('turn-indicator');
const light = indicator.querySelector('.light');
let status = '';
let tooltipText = '';
if (state === 'pending' || gameState.isLocked) {
status = 'thinking';
tooltipText = 'Computer Thinking';
} else if (state && isGameOver(state)) {
switch(state) {
case 'white wins':
status = 'white-wins';
tooltipText = 'White Wins';
break;
case 'black wins':
status = 'black-wins';
tooltipText = 'Black Wins';
break;
case 'stalemate':
status = 'stalemate';
tooltipText = 'Stalemate';
break;
case 'draw':
status = 'draw';
tooltipText = 'Draw';
break;
default:
status = 'unknown';
tooltipText = 'Game Over';
}
} else if (turn === 'w') {
status = 'white';
tooltipText = 'White';
} else if (turn === 'b') {
status = 'black';
tooltipText = 'Black';
} else {
status = 'unknown';
tooltipText = 'Unknown';
}
light.setAttribute('data-status', status);
indicator.setAttribute('data-status', tooltipText);
}
function showNewGameModal() {
const modal = document.getElementById('modal-overlay');
modal.classList.add('show');
setupModalKeyboardNav();
}
function hideNewGameModal() {
const modal = document.getElementById('modal-overlay');
modal.classList.remove('show');
teardownModalKeyboardNav();
}
function setupModalKeyboardNav() {
document.addEventListener('keydown', handleModalKeydown);
}
function teardownModalKeyboardNav() {
document.removeEventListener('keydown', handleModalKeydown);
}
function handleModalKeydown(e) {
const modal = document.getElementById('modal-overlay');
if (!modal.classList.contains('show')) return;
switch(e.key) {
case 'Enter':
e.preventDefault();
startNewGame();
break;
case 'Escape':
e.preventDefault();
hideNewGameModal();
break;
case 'w':
case 'W':
e.preventDefault();
document.querySelector('input[name="player-color"][value="white"]').checked = true;
break;
case 'b':
case 'B':
e.preventDefault();
document.querySelector('input[name="player-color"][value="black"]').checked = true;
break;
case 'l':
case 'L':
e.preventDefault();
document.getElementById('computer-level').focus();
break;
case 's':
case 'S':
e.preventDefault();
document.getElementById('search-time').focus();
break;
case 'ArrowLeft':
handleSliderNav(e, -1);
break;
case 'ArrowRight':
handleSliderNav(e, 1);
break;
}
}
function handleSliderNav(e, direction) {
const activeEl = document.activeElement;
if (activeEl.id === 'computer-level') {
e.preventDefault();
activeEl.value = Math.max(0, Math.min(20, parseInt(activeEl.value) + direction));
activeEl.dispatchEvent(new Event('input'));
} else if (activeEl.id === 'search-time') {
e.preventDefault();
activeEl.value = Math.max(100, Math.min(10000, parseInt(activeEl.value) + direction * 100));
activeEl.dispatchEvent(new Event('input'));
}
}
function copyHistory() {
const moves = gameState.moveList;
let pgn = '';
for (let i = 0; i < moves.length; i++) {
if (i % 2 === 0) {
pgn += `${Math.floor(i / 2) + 1}. `;
}
pgn += moves[i] + ' ';
}
if (gameState.fen) {
pgn += `\n\n[FEN "${gameState.fen}"]`;
}
navigator.clipboard.writeText(pgn.trim()).then(() => {
const btn = document.getElementById('copy-history');
btn.classList.add('copied');
setTimeout(() => {
btn.classList.remove('copied');
}, 2000);
});
}
async function startNewGame() {
const playerColor = document.querySelector('input[name="player-color"]:checked').value;
const computerLevel = parseInt(document.getElementById('computer-level').value);
const searchTime = parseInt(document.getElementById('search-time').value);
const startingFEN = document.getElementById('starting-fen').value.trim();
gameState.isPlayerWhite = (playerColor === 'white');
const whiteConfig = gameState.isPlayerWhite ? { type: 1 } : { type: 2, level: computerLevel, searchTime: searchTime };
const blackConfig = gameState.isPlayerWhite ? { type: 2, level: computerLevel, searchTime: searchTime } : { type: 1 };
const requestBody = {
white: whiteConfig,
black: blackConfig
};
const defaultFEN = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1';
if (startingFEN && startingFEN !== defaultFEN) {
requestBody.fen = startingFEN;
}
try {
const response = await fetch(`${gameState.apiUrl}/api/v1/games`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(requestBody)
});
if (!response.ok) throw new Error('Failed to create game');
if (!response.ok) {
const errorInfo = handleApiError('create game', null, response);
throw new Error(errorInfo.statusMessage);
}
const game = await response.json();
gameState.gameId = game.gameId;
gameState.moveList = [];
hideNewGameModal();
initializeBoard();
updateGameDisplay(game);
document.getElementById('undo-btn').disabled = true;
if (!gameState.isPlayerWhite) triggerComputerMove();
} catch (error) {
if (error.message === 'Failed to fetch') {
handleApiError('create game', error);
} else {
flashErrorMessage(error.message);
}
updateTurnIndicator('', '');
}
}
function initializeBoard() {
const boardEl = document.getElementById('board');
boardEl.innerHTML = '';
const isBlackPov = !gameState.isPlayerWhite;
// Update coordinate labels based on perspective
const topCoords = document.querySelector('.coordinates.top');
const leftCoords = document.querySelector('.coordinates.left');
if (isBlackPov) {
topCoords.innerHTML = '<span>h</span><span>g</span><span>f</span><span>e</span><span>d</span><span>c</span><span>b</span><span>a</span>';
leftCoords.innerHTML = '<span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span><span>8</span>';
} else {
topCoords.innerHTML = '<span>a</span><span>b</span><span>c</span><span>d</span><span>e</span><span>f</span><span>g</span><span>h</span>';
leftCoords.innerHTML = '<span>8</span><span>7</span><span>6</span><span>5</span><span>4</span><span>3</span><span>2</span><span>1</span>';
}
for (let i = 0; i < 64; i++) {
const square = document.createElement('div');
const rank = 7 - Math.floor(i / 8);
const file = i % 8;
const squareName = `${String.fromCharCode(97 + file)}${rank + 1}`;
const displayRank = isBlackPov ? 7 - rank : rank;
const displayFile = isBlackPov ? 7 - file : file;
square.className = `square ${(displayRank + displayFile) % 2 === 0 ? 'dark' : 'light'}`;
square.dataset.square = squareName;
square.addEventListener('click', handleSquareClick);
boardEl.appendChild(square);
}
}
function renderBoardFromFEN(fen) {
const fenBoard = fen.split(' ')[0];
// Clear board and remove checkmate indicators
document.querySelectorAll('.square').forEach(s => {
s.textContent = '';
s.classList.remove('white-piece', 'black-piece', 'mated-king');
delete s.dataset.pieceColor;
});
let rank = 7, file = 0;
for (const char of fenBoard) {
if (char === '/') {
rank--; file = 0;
} else if (/\d/.test(char)) {
file += parseInt(char, 10);
} else {
const squareName = `${String.fromCharCode(97 + file)}${rank + 1}`;
const squareEl = document.querySelector(`[data-square="${squareName}"]`);
if (squareEl) {
const pieceColor = (char === char.toUpperCase()) ? 'w' : 'b';
squareEl.textContent = pieceMap[char === 'P' ? 'P' : char.toLowerCase()] || '';
squareEl.classList.add(pieceColor === 'w' ? 'white-piece' : 'black-piece');
squareEl.dataset.pieceColor = pieceColor;
squareEl.dataset.pieceType = char.toLowerCase();
}
file++;
}
}
}
function handleSquareClick(e) {
if (gameState.isLocked) return;
// Block moves after game over
if (isGameOver(gameState.state)) return;
const squareEl = e.currentTarget;
const { square, pieceColor } = squareEl.dataset;
const playerTurnColor = gameState.isPlayerWhite ? 'w' : 'b';
if (gameState.turn !== playerTurnColor) return;
if (gameState.selectedSquare) {
const from = gameState.selectedSquare;
const fromEl = document.querySelector(`[data-square="${from}"]`);
fromEl.classList.remove('selected');
gameState.selectedSquare = null;
if (from !== square) {
handleHumanMove(from, square);
}
} else if (pieceColor === playerTurnColor) {
gameState.selectedSquare = square;
squareEl.classList.add('selected');
} else {
flashErrorMessage('Invalid Piece Selection');
// Flash red for invalid piece selection
flashSquare(squareEl, false);
}
}
function flashSquare(element, success = true) {
const className = success ? 'flash-green' : 'flash-red';
element.classList.add(className);
setTimeout(() => element.classList.remove(className), 400);
}
async function handleHumanMove(from, to) {
const move = from + to;
const fromEl = document.querySelector(`[data-square="${from}"]`);
const toEl = document.querySelector(`[data-square="${to}"]`);
try {
const response = await fetch(`${gameState.apiUrl}/api/v1/games/${gameState.gameId}/moves`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ move })
});
const game = await response.json();
if (!response.ok) {
// Handle client errors differently - these aren't network issues
if (response.status === 400) {
// Invalid move - flash message and squares
// Handled early, not shown as server error, and bypasses handleApiError
flashErrorMessage('Invalid Move');
flashSquare(fromEl, false);
flashSquare(toEl, false);
renderBoardFromFEN(gameState.fen);
return;
}
// Other errors use error handler
handleApiError('move', null, response);
return;
}
flashSquare(fromEl, true);
flashSquare(toEl, true);
updateGameDisplay(game);
if (!isGameOver(game.state)) {
triggerComputerMove();
}
} catch (error) {
handleApiError('move', error);
}
}
async function triggerComputerMove() {
lockBoard();
try {
const response = await fetch(`${gameState.apiUrl}/api/v1/games/${gameState.gameId}/moves`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ move: 'cccc' })
});
if (!response.ok) {
handleApiError('trigger computer move', null, response);
unlockBoard();
return;
}
gameState.networkError = false;
startPolling();
} catch (error) {
handleApiError('trigger computer move', error);
unlockBoard();
}
}
function startPolling() {
gameState.pollInterval = setInterval(async () => {
try {
const response = await fetch(`${gameState.apiUrl}/api/v1/games/${gameState.gameId}`);
if (!response.ok) {
// Use error handler but continue polling for 404 (game might be deleted)
const errorInfo = handleApiError('poll game state', null, response);
if (response.status === 404) {
stopPolling();
unlockBoard();
flashErrorMessage('Game no longer exists');
gameState.gameId = null;
return;
}
// For other errors, display but keep polling
handleApiError('poll game state', null, response);
return;
}
const game = await response.json();
if (game.state !== 'pending') {
stopPolling();
updateGameDisplay(game);
unlockBoard();
}
gameState.networkError = false;
updateServerIndicator('healthy');
} catch (error) {
handleApiError('poll game state', error);
stopPolling();
unlockBoard();
}
}, 1500);
}
function stopPolling() {
clearInterval(gameState.pollInterval);
gameState.pollInterval = null;
}
function lockBoard() {
gameState.isLocked = true;
updateTurnIndicator('pending', gameState.turn);
}
function unlockBoard() {
gameState.isLocked = false;
updateTurnIndicator('', gameState.turn);
}
async function undoMoves() {
if (gameState.isLocked) return;
if (!gameState.moveList || gameState.moveList.length < 2) {
console.log('No moves to undo');
return;
}
try {
const response = await fetch(`${gameState.apiUrl}/api/v1/games/${gameState.gameId}/undo`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ count: 2 })
});
if (!response.ok) {
const errorInfo = handleApiError('undo', null, response);
// For client errors like "no moves to undo", don't throw
if (errorInfo.isClientError) {
console.log('Undo failed:', errorInfo.statusMessage);
return;
}
throw new Error(errorInfo.statusMessage);
}
const game = await response.json();
gameState.state = game.state;
updateGameDisplay(game);
} catch (error) {
if (error.message === 'Failed to fetch') {
handleApiError('undo', error);
}
}
}
function renderMoveHistory(moves) {
const grid = document.getElementById('move-grid');
grid.innerHTML = '';
let startsWithBlack = false;
if (gameState.fen) {
const fenParts = gameState.fen.split(' ');
const moveNum = parseInt(fenParts[5]) || 1;
const activeColor = fenParts[1];
startsWithBlack = (moveNum === 1 && activeColor === 'b' && moves.length === 0);
}
for (let i = 0; i < moves.length; i++) {
const isWhiteMove = (i % 2 === 0);
const moveNumber = Math.floor(i / 2) + 1;
if (i === 0 || i % 2 === 0) {
const numEl = document.createElement('div');
numEl.className = 'move-number';
numEl.textContent = moveNumber + '.';
grid.appendChild(numEl);
const whiteEl = document.createElement('div');
if (isWhiteMove && !startsWithBlack) {
whiteEl.className = 'move-white';
whiteEl.textContent = moves[i];
} else if (!isWhiteMove && startsWithBlack) {
whiteEl.className = 'move-empty';
whiteEl.textContent = '...';
} else {
whiteEl.className = 'move-empty';
whiteEl.textContent = '';
}
grid.appendChild(whiteEl);
const blackEl = document.createElement('div');
if (i + 1 < moves.length && !startsWithBlack) {
blackEl.className = 'move-black';
blackEl.textContent = moves[i + 1];
i++;
} else if (isWhiteMove && startsWithBlack) {
blackEl.className = 'move-black';
blackEl.textContent = moves[i];
} else {
blackEl.className = 'move-empty';
blackEl.textContent = '';
}
grid.appendChild(blackEl);
}
}
const historyContainer = document.getElementById('move-history');
historyContainer.scrollTop = historyContainer.scrollHeight;
}
function updateGameDisplay(game) {
gameState.fen = game.fen;
gameState.turn = game.turn;
gameState.state = game.state;
gameState.moveList = game.moves || [];
renderBoardFromFEN(game.fen);
updateTurnIndicator(game.state, game.turn);
// Clear previous checkmate indicators
document.querySelectorAll('.mated-king').forEach(el => {
el.classList.remove('mated-king');
});
// Highlight last move
document.querySelectorAll('.last-move-from, .last-move-to').forEach(el => {
el.classList.remove('last-move-from', 'last-move-to');
});
if (game.lastMove && game.lastMove.move) {
const from = game.lastMove.move.substring(0, 2);
const to = game.lastMove.move.substring(2, 4);
const fromEl = document.querySelector(`[data-square="${from}"]`);
const toEl = document.querySelector(`[data-square="${to}"]`);
if (fromEl) fromEl.classList.add('last-move-from');
if (toEl) toEl.classList.add('last-move-to');
}
// Update move history
renderMoveHistory(game.moves || []);
// Update undo button
document.getElementById('undo-btn').disabled = !game.moves || game.moves.length < 2;
// Handle checkmate visually
if (game.state === 'white wins' || game.state === 'black wins') {
markMatedKing(game);
}
}
function markMatedKing(game) {
// Find and mark the mated king
const matedColor = game.state === 'white wins' ? 'b' : 'w';
document.querySelectorAll('.square').forEach(square => {
if (square.dataset.pieceType === 'k' && square.dataset.pieceColor === matedColor) {
square.classList.add('mated-king');
}
});
}
function isGameOver(state) {
return ['white wins', 'black wins', 'stalemate', 'draw'].includes(state);
}
function handleApiError(action, error, response = null) {
let serverStatus = 'degraded';
let statusMessage = 'Server Error';
let isNetworkError = !response;
if (isNetworkError) {
// Network/connection error
statusMessage = 'Connection Failed';
console.error(`Network error during ${action}:`, error);
} else if (response) {
const status = response.status;
// Map status codes to user-friendly messages
switch (status) {
case 400:
// Bad request - not a server issue, game logic error
serverStatus = 'healthy'; // Server is fine, request was invalid
if (action === 'undo') {
statusMessage = 'No Moves to Undo';
} else if (action === 'move') {
statusMessage = 'Invalid Move';
} else {
statusMessage = 'Invalid Request';
}
break;
case 404:
serverStatus = 'healthy'; // Server is fine, game doesn't exist
statusMessage = 'Game Not Found';
break;
case 429:
serverStatus = 'degraded';
statusMessage = 'Rate Limited';
break;
case 415:
serverStatus = 'healthy';
statusMessage = 'Invalid Content Type';
break;
case 500:
case 502:
case 503:
serverStatus = 'degraded';
statusMessage = status === 503 ? 'Service Unavailable' : 'Server Error';
break;
default:
if (status >= 500) {
serverStatus = 'degraded';
statusMessage = `Server Error (${status})`;
} else if (status >= 400) {
serverStatus = 'healthy';
statusMessage = `Request Failed (${status})`;
}
}
console.error(`API error during ${action}: ${status} - ${statusMessage}`);
}
flashErrorMessage(statusMessage);
// Update indicators based on error type
if (isNetworkError || (response && response.status >= 500)) {
updateServerIndicator(serverStatus, statusMessage);
gameState.networkError = true;
} else {
// For client errors (4xx), server is healthy but request failed
updateServerIndicator('healthy');
gameState.networkError = false;
}
return {
serverStatus,
statusMessage,
isNetworkError,
isClientError: response && response.status >= 400 && response.status < 500,
isServerError: response && response.status >= 500
};
}
function flashErrorMessage(message) {
const overlay = document.getElementById('error-flash-overlay');
const messageEl = document.getElementById('error-flash-message');
// Set message text
messageEl.textContent = message;
// Show overlay
overlay.classList.add('show');
// Auto-hide after animation completes
setTimeout(() => {
overlay.classList.remove('show');
}, 500);
}

View File

@ -0,0 +1,100 @@
<!-- FILE: lixenwraith/chess/internal/server/webserver/web/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chess Game</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="outer-container">
<div class="container">
<main>
<div class="game-area">
<div class="board-container">
<div class="board-wrapper">
<div class="coordinates top">
<span>a</span><span>b</span><span>c</span><span>d</span>
<span>e</span><span>f</span><span>g</span><span>h</span>
</div>
<div class="coordinates left">
<span>8</span><span>7</span><span>6</span><span>5</span>
<span>4</span><span>3</span><span>2</span><span>1</span>
</div>
<div id="board"></div>
</div>
</div>
</div>
<aside class="info-panel">
<div class="status-indicators">
<div class="indicator" id="server-indicator" data-tooltip="Server">
<span class="light" data-status="unknown"></span>
</div>
<div class="indicator" id="storage-indicator" data-tooltip="Storage">
<span class="light" data-status="unknown"></span>
</div>
<div class="indicator" id="turn-indicator" data-tooltip="Turn">
<span class="light turn-light" data-status="white"></span>
</div>
<div class="error-flash-overlay" id="error-flash-overlay">
<div class="error-flash-message" id="error-flash-message"></div>
</div>
</div>
<div class="controls">
<button id="new-game-btn" class="btn btn-primary">New Game</button>
<button id="undo-btn" class="btn btn-secondary" disabled>Undo</button>
</div>
<div class="move-history-container">
<button class="copy-btn" id="copy-history" title="Copy PGN">
<svg viewBox="0 0 24 24" width="16" height="16">
<rect x="9" y="9" width="13" height="13" rx="2" fill="none" stroke="currentColor" stroke-width="2"/>
<path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1" fill="none" stroke="currentColor" stroke-width="2"/>
</svg>
</button>
<div id="move-history" class="move-history">
<div class="move-grid" id="move-grid"></div>
</div>
</div>
</aside>
</main>
</div>
</div>
<div id="modal-overlay" class="modal-overlay">
<div class="modal">
<h2>New Game</h2>
<div class="form-group">
<label class="group-label">Your Color</label>
<div class="radio-group">
<label><input type="radio" name="player-color" value="white" checked><span>White</span></label>
<label><input type="radio" name="player-color" value="black"><span>Black</span></label>
</div>
</div>
<div class="form-group">
<label for="computer-level">Computer Level: <span id="level-value">10</span></label>
<input type="range" id="computer-level" min="0" max="20" value="10">
</div>
<div class="form-group">
<label for="search-time">Search Time (ms): <span id="time-value">1000</span></label>
<input type="range" id="search-time" min="100" max="10000" step="100" value="1000">
</div>
<div class="form-group">
<label for="starting-fen">Starting Position (FEN)</label>
<textarea id="starting-fen" class="fen-input" rows="2"
placeholder="Enter FEN notation">rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1</textarea>
</div>
<div class="modal-buttons">
<button id="start-game-btn" class="btn btn-primary">Start Game</button>
<button id="cancel-btn" class="btn btn-secondary">Cancel</button>
</div>
</div>
</div>
<script src="app.js"></script>
</body>
</html>

View File

@ -0,0 +1,800 @@
/* FILE: lixenwraith/chess/internal/server/webserver/web/style.css */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
/* Host-site dark theme colors */
--host-bg: #11111b;
--host-surface: #1a1b26;
--host-royal: #5f57f5;
--host-royal-secondary: #38348f;
--host-blue-primary: #2563eb;
--host-blue-secondary: #1e40af;
--host-white: #ffffff;
--blue-accent: #dbeafe;
--host-gray-muted: #64748b;
--host-gray-light: #f8fafc;
/* Tokyo Night colors */
--tokyo-cyan: #7dcfff;
--tokyo-green: #9ece6a;
--tokyo-yellow: #e0af68;
--tokyo-red: #f7768e;
--tokyo-border: #3b4261;
--tokyo-fg: #a9b1d6;
/* Board colors */
--square-light: #f0d9b5;
--square-dark: #b58863;
--square-selected: #6a994e;
--move-from: #5090d3;
--move-to: #81b3f0;
--checkmated-king: #8b0000;
}
/* Base Layout */
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
background: var(--host-bg);
height: 100vh;
width: 100vw;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.outer-container {
width: 100%;
height: 100vh;
padding: 8px;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.container {
background: var(--host-surface);
border-radius: 12px;
box-shadow: 0 20px 40px rgba(0,0,0,0.4);
padding: 1.5rem;
width: calc(100% - 16px);
height: calc(100% - 16px);
color: var(--tokyo-fg);
display: flex;
flex-direction: column;
overflow: hidden;
}
main {
display: grid;
grid-template-columns: 1fr 340px;
gap: 2rem;
flex: 1;
min-height: 0;
overflow: hidden;
height: 100%;
max-width: 980px;
margin: 0 auto;
align-items: center;
}
.game-area {
display: flex;
align-items: center;
justify-content: center;
min-width: 440px;
overflow: visible;
height: 100%;
}
.board-container {
display: flex;
align-items: center;
justify-content: center;
width: 440px;
height: 440px;
padding: 20px;
position: relative;
}
.board-wrapper {
position: relative;
width: 400px;
height: 400px;
margin: 0;
}
.coordinates {
position: absolute;
display: flex;
color: var(--tokyo-border);
font-size: 0.75rem;
font-weight: 500;
user-select: none;
}
.coordinates.top {
top: -18px;
left: 0;
right: 0;
justify-content: space-around;
padding: 0 2px;
}
.coordinates.left {
left: -18px;
top: 0;
bottom: 0;
flex-direction: column;
justify-content: space-around;
padding: 2px 0;
}
#board {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: grid;
grid-template-columns: repeat(8, 1fr);
grid-template-rows: repeat(8, 1fr);
border: 3px solid var(--tokyo-border);
border-radius: 4px;
}
.square {
display: flex;
justify-content: center;
align-items: center;
font-size: clamp(24px, 5vw, 36px);
cursor: pointer;
user-select: none;
position: relative;
aspect-ratio: 1;
overflow: hidden;
}
.square.light { background-color: var(--square-light); }
.square.dark { background-color: var(--square-dark); }
.square.selected { background-color: var(--square-selected) !important; }
.square.last-move-from { background-color: var(--move-from) !important; }
.square.last-move-to { background-color: var(--move-to) !important; }
.square.white-piece { color: var(--host-white); text-shadow: 1px 1px 2px rgba(0,0,0,0.5); }
.square.black-piece { color: var(--host-bg); text-shadow: 1px 1px 2px rgba(255,255,255,0.2); }
/* Move feedback animations */
@keyframes flashGreen {
0%, 100% { background-color: inherit; }
50% { background-color: rgba(154, 206, 106, 0.8); }
}
@keyframes flashRed {
0%, 100% { background-color: inherit; }
50% { background-color: rgba(247, 118, 142, 0.8); }
}
.square.flash-green {
animation: flashGreen 0.4s ease-out;
}
.square.flash-red {
animation: flashRed 0.4s ease-out;
position: relative;
z-index: 2;
}
.square.flash-red::before {
content: '';
position: absolute;
inset: 0;
background-color: rgba(247, 118, 142, 0.8);
animation: flashFade 0.4s ease-out;
pointer-events: none;
}
@keyframes flashFade {
0% { opacity: 0; }
50% { opacity: 1; }
100% { opacity: 0; }
}
/* Checkmate indicator */
.square.mated-king::after {
content: '';
position: absolute;
inset: 4px;
border: 3px solid var(--tokyo-red);
border-radius: 2px;
pointer-events: none;
z-index: 1;
}
.square.mated-king.white-piece,
.square.mated-king.black-piece {
color: var(--checkmated-king) !important;
}
/* Copy Buttons */
.copy-btn {
position: absolute;
right: 8px;
top: 50%;
transform: translateY(-50%);
width: 24px;
height: 24px;
padding: 4px;
background: var(--tokyo-border);
border: none;
border-radius: 4px;
color: var(--tokyo-fg);
cursor: pointer;
opacity: 0;
transition: opacity 0.2s, background 0.2s;
display: flex;
align-items: center;
justify-content: center;
}
.move-history-container:hover .copy-btn {
opacity: 0.7;
}
.copy-btn:hover {
opacity: 1 !important;
background: var(--host-royal);
}
.copy-btn.copied {
background: var(--tokyo-green);
opacity: 1;
}
.copy-btn.copied svg {
display: none;
}
.copy-btn.copied::after {
content: '✓';
font-size: 14px;
}
/* Info Panel */
.info-panel {
background: var(--host-bg);
border-radius: 8px;
padding: 1rem;
display: flex;
flex-direction: column;
gap: 1rem;
overflow: hidden;
width: 340px;
height: 440px;
align-self: center;
}
/* Status Indicators */
.status-indicators {
display: flex;
padding: 0.75rem;
justify-content: space-evenly;
align-items: center;
background: var(--host-gray-muted);
border: none;
border-radius: 6px;
cursor: pointer;
height: auto;
position: relative;
}
.indicator {
position: relative;
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.indicator .light {
font-size: 2rem;
font-weight: 500;
transition: all 0.2s;
line-height: 1;
display: flex;
align-items: center;
justify-content: center;
}
.indicator .light[data-status="white-wins"] { color: var(--tokyo-red); }
.indicator .light[data-status="black-wins"] { color: var(--tokyo-red); }
/* Status colors */
.indicator .light[data-status="healthy"] { color: var(--tokyo-green); }
.indicator .light[data-status="disabled"] { color: var(--tokyo-yellow); }
.indicator .light[data-status="degraded"] { color: var(--tokyo-red); }
.indicator .light[data-status="unknown"] { color: var(--tokyo-border); }
.indicator .light[data-status="white"] { color: var(--host-white); }
.indicator .light[data-status="black"] { color: var(--host-bg); }
.indicator .light[data-status="thinking"] {
color: var(--tokyo-yellow);
animation: pulse 1.5s infinite;
}
.indicator .light[data-status="network-error"] { color: var(--tokyo-red); }
.indicator .light[data-status="draw"],
.indicator .light[data-status="stalemate"] {
color: var(--tokyo-yellow);
}
@keyframes pulse {
0%, 100% { opacity: 1; transform: scale(1); }
50% { opacity: 0.6; transform: scale(0.95); }
}
.indicator:hover::after {
content: attr(data-tooltip) ": " attr(data-status);
position: absolute;
bottom: -30px;
left: 50%;
transform: translateX(-50%);
background: var(--tokyo-border);
color: var(--tokyo-fg);
padding: 0.25rem 0.5rem;
border-radius: 4px;
font-size: 0.75rem;
white-space: nowrap;
z-index: 10;
pointer-events: none;
}
/* Error Flash Overlay */
.error-flash-overlay {
position: absolute;
inset: 0;
background: var(--host-bg);
border-radius: 6px;
display: none;
align-items: center;
justify-content: center;
z-index: 100;
pointer-events: none;
}
.error-flash-overlay.show {
display: flex;
animation: none;
}
.error-flash-message {
color: var(--tokyo-red);
font-size: 0.85rem;
font-weight: 500;
text-align: center;
padding: 0.5rem;
}
/* Move History */
.move-history-container {
flex: 1 1 auto;
min-height: 0;
max-height: 100%;
position: relative;
background: var(--host-surface);
border-radius: 6px;
border: 1px solid var(--tokyo-border);
overflow: hidden;
}
.move-history-container .copy-btn {
right: 8px;
top: 8px;
transform: none;
}
.move-history {
height: 100%;
overflow-y: auto;
overflow-x: auto;
padding: 0.75rem;
}
.move-history::-webkit-scrollbar {
width: 6px;
height: 6px;
}
.move-history::-webkit-scrollbar-track {
background: transparent;
}
.move-history::-webkit-scrollbar-thumb {
background: var(--tokyo-border);
border-radius: 3px;
}
.move-grid {
display: grid;
grid-template-columns: 2.5rem 1fr 1fr;
gap: 0.25rem 0.5rem;
font-family: 'Courier New', monospace;
font-size: 0.9rem;
align-items: center;
}
.move-number {
color: var(--tokyo-yellow);
text-align: right;
font-weight: 600;
}
.move-white,
.move-black {
padding: 0.25rem 0.5rem;
border-radius: 3px;
}
.move-white:hover,
.move-black:hover {
background: var(--host-royal);
}
.move-white { color: var(--host-gray-light); }
.move-black { color: var(--tokyo-cyan); }
/* Controls */
.controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.5rem;
flex-shrink: 0;
}
.btn {
padding: 0.75rem;
border: none;
border-radius: 6px;
font-size: 0.9rem;
font-weight: 500;
cursor: pointer;
color: var(--host-white);
transition: all 0.2s;
}
.btn-primary {
background: var(--host-blue-primary);
color: var(--host-white);
}
.btn-primary:hover {
background: var(--host-royal);
transform: translateY(-1px);
}
.btn-secondary {
background: var(--host-blue-secondary);
color: var(--host-white);
}
.btn-secondary:hover:not(:disabled) {
background: var(--host-royal);
transform: translateY(-1px);
}
.btn:disabled {
opacity: 0.4;
cursor: not-allowed;
}
/* Modal */
.modal-overlay {
display: none;
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.7);
z-index: 2000;
justify-content: center;
align-items: center;
backdrop-filter: blur(4px);
}
.modal-overlay.show {
display: flex;
}
.modal {
background: var(--host-surface);
border: 1px solid var(--tokyo-border);
border-radius: 12px;
padding: 2rem;
width: 90%;
max-width: 400px;
color: var(--tokyo-fg);
}
.modal h2 {
margin-bottom: 1.5rem;
color: var(--host-royal);
text-align: center;
}
.form-group {
margin-bottom: 1.5rem;
}
.form-group label {
display: block;
margin-bottom: 0.5rem;
color: var(--tokyo-cyan);
}
.form-group .group-label {
text-align: center;
}
.radio-group {
display: flex;
gap: 1.5rem;
justify-content: center;
}
.radio-group label {
display: flex;
align-items: center;
gap: 0.5rem;
margin: 0;
color: var(--tokyo-fg);
}
input[type="range"] {
width: 100%;
height: 4px;
background: var(--tokyo-border);
border-radius: 2px;
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
appearance: none;
width: 16px;
height: 16px;
background: var(--host-gray-muted);
border-radius: 50%;
cursor: pointer;
}
/* Modal FEN input */
.fen-input {
width: 100%;
padding: 0.5rem;
background: var(--host-bg);
border: 1px solid var(--tokyo-border);
border-radius: 4px;
color: var(--tokyo-fg);
font-family: 'Courier New', monospace;
font-size: 0.85rem;
resize: none;
white-space: pre-wrap;
word-wrap: break-word;
}
.fen-input:focus {
outline: none;
border-color: var(--host-royal);
}
.modal-buttons {
display: flex;
justify-content: center;
gap: 1rem;
margin-top: 2rem;
}
/* Mobile/Responsiveness */
@media (max-width: 978px) {
body {
height: auto;
min-height: 100vh;
overflow-y: auto;
overflow-x: hidden;
scrollbar-gutter: stable;
}
.outer-container {
padding: 8px;
min-height: 100vh;
height: auto;
display: flex;
justify-content: center;
align-items: flex-start;
overflow: visible;
}
.container {
border-radius: 12px;
width: calc(100% - 16px);
min-height: calc(100vh - 16px);
height: auto;
padding: 1rem;
margin: 0;
display: flex;
flex-direction: column;
justify-content: center;
overflow: visible;
}
main {
grid-template-columns: 1fr;
grid-template-rows: auto auto;
gap: 0.5rem;
height: auto;
max-width: none;
margin: 0 auto;
align-items: center;
justify-items: center;
overflow: visible;
flex-shrink: 0;
}
.game-area {
min-width: auto;
height: auto;
display: flex;
justify-content: center;
align-items: center;
}
.board-container {
width: 440px;
height: 440px;
padding: 20px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
flex-shrink: 0;
}
.board-wrapper {
width: 400px;
height: 400px;
position: relative;
margin: 0;
}
.coordinates.top {
top: -18px;
left: 0;
right: 0;
}
.coordinates.left {
left: -18px;
top: 0;
bottom: 0;
}
#board {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.info-panel {
width: 440px;
height: 200px;
display: grid;
grid-template-columns: 180px 1fr;
grid-template-rows: min-content min-content 1fr;
gap: 0.5rem 1rem;
padding: 1rem;
align-self: center;
overflow: hidden;
flex-shrink: 0;
margin-bottom: 1rem;
}
.status-indicators {
grid-column: 1;
grid-row: 1;
display: flex;
padding: 0.25rem;
justify-content: space-evenly;
align-items: center;
background: var(--host-gray-muted);
border: none;
border-radius: 6px;
height: auto;
margin: 0;
}
.controls {
grid-column: 1;
grid-row: 2 / 4;
grid-template-columns: 1fr;
grid-template-rows: 1fr 1fr;
gap: 0.5rem;
align-self: stretch;
height: auto;
min-height: 80px;
}
.btn {
padding: 0.5rem;
font-size: 0.85rem;
min-height: 35px;
height: 100%;
width: 100%;
}
.move-history-container {
grid-column: 2;
grid-row: 1 / 4;
height: 100%;
min-height: 0;
max-height: 100%;
align-self: stretch;
}
.move-grid {
grid-template-columns: 2rem 1fr 1fr;
gap: 0.25rem 0.5rem;
font-size: 0.85rem;
}
.move-history {
padding: 0.5rem;
}
.square {
font-size: clamp(24px, 5vw, 36px);
}
}
@media (max-width: 530px) {
body {
overflow-y: auto;
overflow-x: auto;
min-width: 530px;
}
.outer-container {
width: 530px;
min-width: 530px;
padding: 8px;
min-height: 100vh;
height: auto;
display: flex;
justify-content: center;
align-items: flex-start;
overflow: visible;
}
.container {
width: 514px;
min-width: 514px;
border-radius: 12px;
min-height: calc(100vh - 16px);
height: auto;
padding: 1rem;
margin: 0;
display: flex;
flex-direction: column;
justify-content: center;
overflow: visible;
}
.board-container,
.info-panel {
width: 440px;
min-width: 440px;
}
}