/* ── LLM Chess Engine — Web UI Styles ────────────────────── */

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #1a1a2e;
    color: #e0e0e0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Header ────────────────────────────────────────────────── */
header {
    background: linear-gradient(135deg, #16213e 0%, #0f3460 100%);
    padding: 1rem 2rem;
    text-align: center;
    border-bottom: 3px solid #e94560;
}

header h1 {
    font-size: 1.8rem;
    color: #ffffff;
    margin-bottom: 0.25rem;
}

header .subtitle {
    color: #a0a0b0;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

nav {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

nav a {
    color: #a0a0b0;
    text-decoration: none;
    padding: 0.5rem 1.25rem;
    border-radius: 6px;
    transition: all 0.2s;
    font-weight: 500;
}

nav a:hover {
    background: rgba(233, 69, 96, 0.2);
    color: #fff;
}

nav a.active {
    background: #e94560;
    color: #fff;
}

/* ── Main Content ──────────────────────────────────────────── */
main {
    flex: 1;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* ── Game Container (Play Page) ────────────────────────────── */
.game-container {
    display: flex;
    gap: 2rem;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
}

.board-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.board-header {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

.badge {
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.badge-engine {
    background: #16213e;
    border: 1px solid #0f3460;
    color: #53a8b6;
}

.badge-engine-llm {
    background: #0d2b1a;
    border: 1px solid #2a6b40;
    color: #4caf50;
}

.badge-engine-fallback {
    background: #2b1a0d;
    border: 1px solid #7a4f10;
    color: #f5a623;
}

.badge-turn {
    background: #16213e;
    border: 1px solid #0f3460;
    color: #f5c518;
}

/* ── Chess Board ───────────────────────────────────────────── */
.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 480px;
    height: 480px;
    border: 3px solid #333;
    border-radius: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    user-select: none;
}

.square {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    cursor: pointer;
    position: relative;
    transition: background-color 0.15s;
}

.square.light {
    background-color: #f0d9b5;
}

.square.dark {
    background-color: #b58863;
}

.square.selected {
    background-color: #baca44 !important;
}

.square.legal-target::after {
    content: '';
    position: absolute;
    width: 30%;
    height: 30%;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
}

.square.legal-target-capture {
    box-shadow: inset 0 0 0 4px rgba(0, 0, 0, 0.25);
}

.square.last-move {
    background-color: rgba(255, 255, 0, 0.35) !important;
}

.square:hover {
    filter: brightness(1.1);
}

.square .piece {
    z-index: 1;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    line-height: 1;
    pointer-events: none;
}

.square .piece.white-piece {
    color: #fff;
    text-shadow: 0 0 4px rgba(0,0,0,0.6), 0 1px 2px rgba(0,0,0,0.4);
}

.square .piece.black-piece {
    color: #1a1a1a;
    text-shadow: 0 0 2px rgba(255,255,255,0.15);
}

/* ── Board Controls ────────────────────────────────────────── */
.board-controls {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: #4CAF50;
    color: #fff;
}

.btn-primary:hover {
    background: #45a049;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #2a2a4a;
    color: #ccc;
    border: 1px solid #444;
}

.btn-secondary:hover {
    background: #3a3a5a;
    transform: translateY(-1px);
}

/* ── Info Panel ────────────────────────────────────────────── */
.info-panel {
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.panel-section {
    background: #16213e;
    border-radius: 10px;
    padding: 1rem 1.25rem;
    border: 1px solid #1a1a3e;
}

.panel-section h3 {
    color: #f5c518;
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-box {
    color: #b0b0c0;
    font-size: 0.9rem;
    line-height: 1.5;
}

.status-box .game-over {
    color: #e94560;
    font-weight: bold;
    font-size: 1.1rem;
}

.alert-box {
    background: #3e1621 !important;
    border-color: #e94560 !important;
    animation: pulse 1s ease-in-out 2;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.alert-box h3 {
    color: #e94560 !important;
}

.alert-box p {
    color: #f0a0a0;
    font-size: 0.85rem;
}

/* ── Move History ──────────────────────────────────────────── */
.move-history {
    max-height: 200px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: #b0b0c0;
    line-height: 1.6;
}

.move-history em {
    color: #666;
}

.move-pair {
    display: flex;
    gap: 0.5rem;
    padding: 0.15rem 0;
}

.move-number {
    color: #666;
    min-width: 2rem;
    text-align: right;
}

.move-white, .move-black {
    min-width: 4rem;
}

.about-text {
    color: #888;
    font-size: 0.8rem;
    line-height: 1.5;
    margin-bottom: 0.5rem;
}

/* ── Fallback Mode Banner ───────────────────────────────────── */
.fallback-banner {
    background: #2b1700;
    border: 1px solid #f5a623;
    border-radius: 8px;
    padding: 0.6rem 1rem;
    margin-bottom: 1rem;
    color: #f5c518;
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.fallback-banner strong {
    color: #f5a623;
}

/* ── Footer ────────────────────────────────────────────────── */
footer {
    background: #0f0f1a;
    padding: 1rem;
    text-align: center;
    color: #555;
    font-size: 0.8rem;
    border-top: 1px solid #222;
}

footer a {
    color: #e94560;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* ── Research Page ─────────────────────────────────────────── */
.research-section {
    background: #16213e;
    border-radius: 12px;
    padding: 1.5rem 2rem;
    margin-bottom: 1.5rem;
    border: 1px solid #1a1a3e;
}

.research-section h2 {
    color: #f5c518;
    font-size: 1.2rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #2a2a4e;
}

.research-question {
    color: #b0b0c0;
    font-size: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: rgba(233, 69, 96, 0.1);
    border-left: 3px solid #e94560;
    border-radius: 0 8px 8px 0;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: #1a1a3e;
    border-radius: 10px;
    padding: 1.25rem;
    text-align: center;
    border: 1px solid #2a2a4e;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: #fff;
}

.stat-label {
    font-size: 0.8rem;
    color: #888;
    margin-top: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-legal .stat-value { color: #4CAF50; }
.stat-illegal .stat-value { color: #e94560; }
.stat-rate .stat-value { color: #f5c518; }

/* ── Data Tables ───────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table th {
    background: #0f3460;
    color: #f5c518;
    padding: 0.6rem 0.75rem;
    text-align: left;
    font-weight: 600;
    position: sticky;
    top: 0;
}

.data-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #1a1a3e;
    color: #c0c0d0;
}

.data-table tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

.data-table .highlight-row td {
    background: rgba(76, 175, 80, 0.15);
    font-weight: 600;
}

.data-table .illegal-row td {
    background: rgba(233, 69, 96, 0.1);
}

.fen-cell {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.error-cell {
    color: #e94560;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-note {
    color: #888;
    font-size: 0.85rem;
    margin-top: 0.75rem;
    font-style: italic;
}

code {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.15rem 0.35rem;
    border-radius: 3px;
    font-size: 0.85rem;
}

/* ── Architecture Diagram ──────────────────────────────────── */
.architecture-diagram {
    background: #0f0f1a;
    padding: 1.5rem;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.8rem;
    line-height: 1.4;
    color: #8888aa;
    border: 1px solid #2a2a4e;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
    .game-container {
        flex-direction: column;
        align-items: center;
    }

    .chess-board {
        width: min(480px, 90vw);
        height: min(480px, 90vw);
    }

    .square {
        font-size: min(2.5rem, 5vw);
    }

    .info-panel {
        width: 100%;
        max-width: 480px;
    }

    main {
        padding: 1rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ── Loading Spinner ───────────────────────────────────────── */
.thinking {
    position: relative;
}

.thinking::after {
    content: '🤔';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    animation: bounce 0.8s ease-in-out infinite alternate;
    z-index: 10;
}

@keyframes bounce {
    from { transform: translate(-50%, -50%) scale(1); }
    to { transform: translate(-50%, -50%) scale(1.2); }
}
