:root {
    --primary: #ff0000;
    --secondary: #ff3333;
    --bg-dark: #050505;

    /* Piezas Estándar */
    --piece-white: #ffffff;
    --piece-black: #000000;

    /* Tablero Blanco y Negro (Opaco) */
    --board-light: #ffffff;
    --board-dark: #000000;

    --highlight: rgba(255, 255, 0, 0.7);
    --text-ui: #ffffff;
}

#matrix {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Orbitron', sans-serif;
    background-color: var(--bg-dark);
    color: var(--primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: hidden;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    z-index: 10;
}

h1 {
    font-size: 2.5rem;
    color: #fff;
    text-shadow: 0 0 10px var(--primary);
    margin-bottom: 10px;
}

.main-game-area {
    display: flex;
    gap: 20px;
    align-items: stretch;
    justify-content: center;
}

.captured-panel {
    width: 200px;
    /* Igualado al historial para simetría */
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid var(--primary);
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.3);
}

.side-header {
    background: var(--primary);
    color: #000;
    font-weight: bold;
    padding: 5px 2px;
    text-align: center;
    font-size: 0.75rem;
    letter-spacing: 1px;
}

.captured-area {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    /* Alineado a la izquierda para mejor lectura en bloque ancho */
    align-content: flex-start;
    padding: 10px;
    gap: 8px;
    /* Más espacio entre piezas capturadas */
    overflow-y: auto;
}

.captured-piece {
    font-size: 28px;
    /* Ligeramente más grandes */
    opacity: 0.9;
}

.board {
    display: grid;
    grid-template-columns: repeat(8, 60px);
    grid-template-rows: repeat(8, 60px);
    border: 2px solid var(--primary);
    box-shadow: 0 0 20px var(--primary);
    user-select: none;
    background: #000;
}

.history-panel {
    width: 200px;
    /* Igualado a capturas para simetría */
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid var(--primary);
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.3);
}

.history-header {
    background: var(--primary);
    color: #000;
    font-weight: bold;
    padding: 5px;
    text-align: center;
    font-size: 0.8rem;
    letter-spacing: 2px;
}

.history-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    font-family: 'monospace';
    font-size: 0.85rem;
    color: #fff;
    max-height: 480px;
}

/* Scrollbar Estilo Matrix */
.history-content::-webkit-scrollbar {
    width: 5px;
}

.history-content::-webkit-scrollbar-track {
    background: #050505;
}

.history-content::-webkit-scrollbar-thumb {
    background: var(--primary);
    box-shadow: 0 0 5px var(--primary);
}

.history-line {
    padding: 5px 0;
    border-bottom: 1px solid rgba(255, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    /* Cambiado a vertical para legibilidad humana */
    gap: 2px;
}

.history-move {
    display: block;
    margin-left: 10px;
}

.white-move {
    color: #fff;
}

.black-move {
    color: var(--secondary);
}

.move-num {
    color: var(--primary);
    font-weight: bold;
    font-size: 0.75rem;
    border-bottom: 1px dashed rgba(255, 0, 0, 0.3);
    margin-bottom: 3px;
}

.square {
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 40px;
    cursor: pointer;
    transition: background 0.2s;
}

.square.light {
    background-color: var(--board-light);
}

.square.dark {
    background-color: var(--board-dark);
}

.square.selected {
    background-color: var(--highlight);
    box-shadow: inset 0 0 10px var(--primary);
}

.square.last-move {
    background-color: rgba(255, 255, 0, 0.3);
    /* Resaltar último movimiento */
}

.piece {
    cursor: grab;
    transition: all 0.3s ease-in-out;
    /* Animación suave */
    animation: pieceSpawn 0.3s ease-out;
}

@keyframes pieceSpawn {
    from {
        transform: scale(0.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.piece:hover {
    transform: scale(1.1);
}

.piece.white {
    color: var(--piece-white);
    text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
}

.piece.black {
    color: var(--piece-black);
    text-shadow: 1px 1px 0 #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff;
}

.controls {
    display: flex;
    gap: 20px;
    margin-top: 20px;
}

.btn-neon {
    background: transparent;
    border: 2px solid var(--primary);
    color: #fff;
    padding: 10px 20px;
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
    cursor: pointer;
    text-shadow: 0 0 5px var(--primary);
    box-shadow: 0 0 10px var(--primary);
    transition: 0.3s;
}

.btn-neon:hover {
    background: var(--primary);
    color: var(--bg-dark);
    box-shadow: 0 0 20px var(--primary);
}

.btn-back {
    color: var(--secondary);
    text-decoration: none;
    border: 2px solid var(--secondary);
    padding: 10px 20px;
    font-weight: bold;
    text-shadow: 0 0 5px var(--secondary);
    box-shadow: 0 0 10px var(--secondary);
    transition: 0.3s;
    display: flex;
    align-items: center;
}

.btn-back:hover {
    background: var(--secondary);
    color: var(--bg-dark);
    box-shadow: 0 0 20px var(--secondary);
}

.status {
    font-size: 1.2rem;
    height: 30px;
    color: #fff;
    text-shadow: 0 0 5px var(--primary);
}

.square {
    position: relative;
}

.coordinate {
    position: absolute;
    font-size: 10px;
    color: #fff;
    font-weight: bold;
    pointer-events: none;
}

.coordinate.rank {
    left: 2px;
    top: 2px;
}

.coordinate.file {
    right: 2px;
    bottom: 2px;
}

@media (max-width: 950px) {
    .main-game-area {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }

    .captured-panel,
    .history-panel {
        width: 100%;
        max-width: 480px;
        /* Ancho del tablero */
        height: auto;
        min-height: 100px;
    }

    .captured-area {
        flex-direction: row;
        justify-content: center;
        height: 80px;
    }

    .history-content {
        max-height: 150px;
    }

    .board {
        grid-template-columns: repeat(8, 50px);
        grid-template-rows: repeat(8, 50px);
    }

    .square {
        width: 50px;
        height: 50px;
        font-size: 32px;
    }
}

@media (max-width: 600px) {
    .board {
        grid-template-columns: repeat(8, 40px);
        grid-template-rows: repeat(8, 40px);
    }

    .square {
        width: 40px;
        height: 40px;
        font-size: 28px;
    }

    .captured-panel,
    .history-panel {
        max-width: 320px;
    }
}