/* Fuente que soporta caracteres de ajedrez */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Symbols:wght@400;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', 'Noto Sans Symbols', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.container {
    text-align: center;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.main-content {
    display: flex;
    gap: 20px;
    width: 100%;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: nowrap;
}

.game-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.right-sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 300px;
    flex-shrink: 0;
}

.captured-area {
    background: white;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.captured-area h3 {
    margin: 0 0 15px 0;
    color: #2c3e50;
    font-size: 1.2em;
    text-align: center;
}

.captured-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.captured-section h4 {
    margin: 0;
    color: #34495e;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.captured-row {
    display: flex;
    overflow-x: auto;
    gap: 10px;
    padding: 10px;
    background: #f7f9fc;
    border-radius: 8px;
}

.captured-pieces {
    display: flex;
    gap: 5px;
}

.captured-pieces span {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: transform 0.1s ease;
}

.captured-pieces span:hover {
    transform: scale(1.1);
}

.captured-pieces .piece-white {
    background: #2c3e50;
    color: #ffffff;
    border-radius: 4px;
}

.captured-pieces .piece-black {
    background: #ecf0f1;
    color: #2c3e50;
}

/* Contenedor principal del chat */
.chat-container {
    flex: 1;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 500px;
    max-height: 70vh;
}

/* Área de mensajes con scroll */
.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f8f9fa;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Barra de desplazamiento */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f3f5;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #ced4da;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #adb5bd;
}

/* Estilo base para todos los mensajes */
.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.95em;
    line-height: 1.4;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    word-wrap: break-word;
    transition: all 0.2s ease-in-out;
}

/* Mensajes del sistema (informativos) */
.message.info {
    width: 100%;
    max-width: 100%;
    background-color: #e9ecef;
    color: #495057;
    font-size: 0.85em;
    padding: 10px 16px;
    text-align: center;
    border-radius: 8px;
    margin: 4px 0;
}

/* Mensajes del usuario */
.message.user {
    background-color: #007bff;
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

/* Mensajes del asistente */
.message.assistant {
    background-color: #f1f3f5;
    color: #212529;
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

/* Contenido del mensaje */
.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Texto del mensaje */
.message-text {
    word-break: break-word;
}

/* Hora del mensaje */
.message-time {
    font-size: 0.75em;
    opacity: 0.8;
    text-align: right;
    margin-top: 4px;
}

/* Ajuste para mensajes del usuario */
.message.user .message-time {
    color: rgba(255, 255, 255, 0.8);
}

/* Ajuste para mensajes del asistente */
.message.assistant .message-time {
    color: #6c757d;
}

/* Efecto hover para mensajes informativos */
.message.info:hover {
    background-color: #dee2e6;
}

/* Mensajes del usuario */
.message.user {
    background-color: #007bff;
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
    text-align: right;
}

/* Mensajes del asistente */
.message.assistant {
    background-color: #f1f3f5;
    color: #212529;
    margin-right: auto;
    border-bottom-left-radius: 4px;
    text-align: left;
}

/* Contenido del mensaje */
.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Texto del mensaje */
.message-text {
    margin: 0;
    padding: 0;
}

/* Hora del mensaje */
.message-time {
    font-size: 0.7em;
    opacity: 0.8;
    margin-top: 4px;
}

/* Efecto hover */
.message.user:hover,
.message.assistant:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Contenedor del área de entrada */
.chat-input-container {
    padding: 16px;
    background: white;
    border-top: 1px solid #e9ecef;
}

/* Contenedor del input y botón */
.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: #f8f9fa;
    border-radius: 24px;
    padding: 8px 8px 8px 16px;
    transition: all 0.2s ease;
}

.input-wrapper:focus-within {
    background: white;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* Área de texto */
#chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 0.95em;
    line-height: 1.4;
    padding: 8px 0;
    margin: 0;
    outline: none;
    color: #212529;
    min-height: 24px;
    max-height: 120px;
    overflow-y: auto;
}

#chat-input::placeholder {
    color: #adb5bd;
}

/* Botón de enviar */
#send-button {
    background: #007bff;
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

#send-button:disabled {
    background: #cccccc;
    cursor: not-allowed;
    opacity: 0.7;
}

#send-button:not(:disabled):hover {
    background: #0056b3;
    transform: translateY(-1px);
}

#send-button:active {
    transform: translateY(0);
}

#send-button svg {
    width: 18px;
    height: 18px;
}


.chat-input-container {
    padding: 12px;
    background: #f0f2f5;
    border-top: 1px solid #e1e4e8;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: white;
    border-radius: 20px;
    padding: 6px 6px 6px 16px;
    border: 1px solid #e1e4e8;
    transition: all 0.2s ease;
}

.input-wrapper:focus-within {
    border-color: #4a90e2;
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

#chat-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 0.95em;
    resize: none;
    background: transparent;
    padding: 8px 0;
    margin: 0;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.4;
    font-family: inherit;
}

#chat-input::placeholder {
    color: #999;
}

/* Ocultar scrollbar pero mantener funcionalidad */
#chat-input::-webkit-scrollbar {
    width: 4px;
}

#chat-input::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 2px;
}

#send-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: #4a90e2;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    padding: 0;
}

#send-button:hover {
    background: #3a7bc8;
    transform: translateY(-1px);
}

#send-button:active {
    transform: scale(0.95);
}

#send-button svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.5;
}

.chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-auto-rows: 1fr; /* Hace que cada fila mida lo mismo que las columnas */
    gap: 0;
    /* Mantener relación 1:1 y ajustarse al lado más pequeño del viewport */
    width: 90vmin;        /* 90% del lado menor de la pantalla */
    aspect-ratio: 1 / 1;  /* Garantiza cuadrado perfecto */
    max-width: 95vmin;    /* Pequeño margen para pantallas muy pequeñas */
    /* La altura la calcula el navegador con aspect-ratio */
    margin: 0 auto;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    border: 15px solid #5d4037;
}

.square {
    position: relative;
    width: 100%;
    height: 100%; /* Llenar completamente la celda */
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    overflow: hidden;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

/* Estilo para las piezas */
.square {
    font-size: min(5vw, 6vh);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    font-family: 'Segoe UI', 'Noto Sans Symbols', Tahoma, Geneva, Verdana, sans-serif;
}

/* Estilo para las piezas */
.square > span {
    pointer-events: none;
    font-size: min(5vw, 6vh);
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    line-height: 1;
    text-align: center;
    position: relative;
    z-index: 1;
    /* Ajuste fino para el centrado vertical */
    transform: translateY(0.05em);
}

/* Ajuste específico para peones */
.square[data-piece="♙"],
.square[data-piece="♟"] {
    padding-top: 0.2em; /* Pequeño ajuste vertical para peones */
}

/* Colores de las piezas */
.piece-white {
    color: #ffffff !important;
    text-shadow: 0 0 3px rgba(0,0,0,0.6); /* Mejora contraste */
    font-weight: bold;
}

/* Aumentar contraste cuando pieza blanca está sobre casilla clara */
.square-white .piece-white {
    text-shadow: 0 0 4px rgba(0,0,0,0.8);
}

/* Contraste para piezas negras sobre casilla oscura */
.square-black .piece-black {
    text-shadow: 0 0 4px rgba(255,255,255,0.8);
}

.piece-black {
    color: #000000 !important; /* Negro puro */
    text-shadow: none; /* Sin sombreado */
    font-weight: bold;
}

/* Asegurar que las piezas negras se vean en la parte superior */
.square-black .piece-black {
    color: #000000;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.5);
}

/* Fondo de las casillas */
.square-white {
    background-color: #f0d9b5; /* Color claro para casillas blancas */
}

.square-black {
    background-color: #b58863; /* Color oscuro para casillas negras */
}

/* Estilo para el debug */
.square::before {
    content: attr(data-debug);
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 8px;
    opacity: 0.6;
    z-index: 2;
    font-family: monospace;
    color: #333;
    pointer-events: none;
}

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

.square-black {
    background-color: #b58863;
    color: #fff;
}

.square.selected {
    background-color: rgba(52, 152, 219, 0.7) !important;
    transform: scale(0.95);
    z-index: 2;
}

.square.highlighted {
    animation: highlight 1.5s infinite alternate;
}

@keyframes highlight {
    from { box-shadow: inset 0 0 10px rgba(46, 204, 113, 0.5); }
    to { box-shadow: inset 0 0 20px rgba(46, 204, 113, 0.8); }
}

/* Estilos para movimientos válidos */
.valid-move {
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
}

.valid-move::after {
    content: '';
    position: absolute;
    width: 25%;
    height: 25%;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    transition: all 0.2s ease;
}

/* Estilo para movimientos de enroque */
.castle-move::after {
    content: '';
    position: absolute;
    width: 70%;
    height: 70%;
    border: 3px dashed rgba(46, 204, 113, 0.8);
    border-radius: 10px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-sizing: border-box;
    animation: pulse 1s infinite alternate;
}

/* Estilo para movimientos de captura */
.capture-move {
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
}

.capture-move::before {
    content: '';
    position: absolute;
    width: 80%;
    height: 80%;
    border: 3px solid rgba(231, 76, 60, 0.8);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-sizing: border-box;
    animation: pulse 1s infinite alternate;
}

.king-check {
    animation: pulse 0.6s infinite alternate;
    outline: 3px solid #e74c3c;
}

/* Alerta visual en el texto de estado cuando hay jaque */
@keyframes checkFlash {
    0%   { background-color: #e74c3c; color: #fff; }
    50%  { background-color: #c0392b; color: #fff; }
    100% { background-color: transparent; color: inherit; }
}

.check-alert {
    animation: checkFlash 0.8s ease-out;
}

/* Efecto hover para las casillas */
.square:not(.selected):hover {
    filter: brightness(1.1);
    transform: scale(1.02);
    z-index: 1;
}

/* Estilos para el estado del juego */
.game-status {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

#status {
    display: inline-block;
    padding: 0.8rem 1.5rem;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.status-white {
    background-color: #f8f9fa;
    color: #2c3e50;
    border: 2px solid #dee2e6;
}

.status-black {
    background-color: #2c3e50;
    color: #f8f9fa;
    border: 2px solid #1a252f;
}

#status-text {
    margin: 1rem 0;
    font-size: 1.1rem;
    color: #495057;
}

#reset-button {
    padding: 0.8rem 2rem;
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

#reset-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.15);
    background: linear-gradient(135deg, #2980b9, #3498db);
}

#reset-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Efecto de pieza movida */
@keyframes pieceMoved {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.piece-moved {
    animation: pieceMoved 0.3s ease;
}

/* Responsive */
.game-wrapper {
    display: flex;
    gap: 2rem;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
}

.captured-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 140px;
    padding: 0.8rem 1rem;
    background: #ffffff;
    border: 1px solid #dcdde1;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    color: #2c3e50;
}

.captured-area h3 {
    margin: 0.4rem 0 0.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: #34495e;
}

@media (max-width: 1000px) {
    .captured-area {
        flex-direction: row;
        justify-content: space-around;
        padding: 16px 12px;
    }
    .captured-section {
        flex: 1;
    }
    .main-content {
        flex-direction: column;
        align-items: center;
    }
    
    .right-sidebar {
        width: 100%;
        max-width: 600px;
        margin-top: 20px;
    }
    
    .chat-container {
        height: 400px;
    }
    
    .game-wrapper {
        order: 1;
    }
    
    .right-sidebar {
        order: 2;
    }
    
    .status {
        order: 3;
        margin-top: 20px;
    }
}

@media (max-width: 600px) {
    .container {
        padding: 1rem;
    }
    
    h1 {
        font-size: 1.8rem;
    }
    
    .chessboard {
        max-width: 100%;
        border-width: 6px;
    }
    
    .square {
        font-size: clamp(20px, 5vw, 30px);
    }
}

/* ============================
   EXPLOSIÓN DE CAPTURA
   ============================ */
@keyframes captureExplosion {
    0%   { transform: scale(0.6); opacity: 0.9; }
    50%  { transform: scale(1.4); opacity: 0.6; }
    100% { transform: scale(2);   opacity: 0;   }
}

.capture-explosion {
    position: relative;
}

.capture-explosion::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120%;
    height: 120%;
    transform: translate(-50%, -50%) scale(0.6);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 0, 0, 0.8) 0%, rgba(255, 140, 0, 0.6) 50%, rgba(255, 255, 0, 0) 70%);
    pointer-events: none;
    z-index: 4;
    animation: captureExplosion 0.6s ease-out forwards;
}

.event-log-container {
    background: #1e1e1e;
    color: #ffffff;
    border-radius: 8px;
    padding: 10px;
    height: 200px;
    overflow-y: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.event-log-container div {
    margin-bottom: 5px;
}

/* ==================== LOADING SCREEN ==================== */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease-out;
}

.loading-content {
    text-align: center;
    color: white;
}

.chess-piece {
    font-size: 120px;
    margin-bottom: 20px;
    animation: pulse 2s ease-in-out infinite;
    filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.3));
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

.loading-content h1 {
    font-size: 48px;
    margin-bottom: 30px;
    font-weight: 300;
    letter-spacing: 2px;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto 30px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loading-text {
    font-size: 18px;
    margin-bottom: 20px;
    opacity: 0.9;
}

.loading-bar {
    width: 300px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    margin: 0 auto;
    overflow: hidden;
}

.loading-progress {
    height: 100%;
    background: white;
    width: 0%;
    transition: width 0.3s ease;
    animation: loading-progress 2s ease-in-out infinite;
}

@keyframes loading-progress {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}
