:root {
    --bg: #f8fafc;
    --card: #ffffff;
    --board-l: #f1f5f9;
    --board-d: #64748b;
    --accent: #f59e0b;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --text: #0f172a;
    --glass: rgba(255, 255, 255, 0.9);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; margin: 0; padding: 0; }

body { 
    background: var(--bg); 
    color: var(--text); 
    font-family: 'Inter', system-ui, -apple-system, sans-serif; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    min-height: 100vh; 
    padding: env(safe-area-inset-top) 15px env(safe-area-inset-bottom) 15px;
}

.header { 
    text-align: center; 
    margin: 20px 0 10px 0; 
    width: 100%; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    max-width: 450px; 
}

.logo-img {
    height: 45px;
    width: auto;
    object-fit: contain;
}

.icon-btn { 
    background: var(--card); 
    border: 1px solid #e2e8f0; 
    color: var(--text); 
    width: 42px; 
    height: 42px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    border-radius: 12px; 
    cursor: pointer; 
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.icon-btn:active { transform: scale(0.9); background: #f1f5f9; }

#game-status-container {
    margin-bottom: 15px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.status-badge {
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    border: 1px solid rgba(0,0,0,0.05);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.status-user { background: #d1fae5; color: #065f46; }
.status-ia { background: #fef3c7; color: #92400e; }
.status-danger { background: #fee2e2; color: #991b1b; }

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: dot-pulse 1.5s infinite;
}

@keyframes dot-pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.5); opacity: 0.4; }
    100% { transform: scale(1); opacity: 1; }
}

#board-wrapper { 
    width: 100%; 
    max-width: 450px; 
    aspect-ratio: 1/1; 
    position: relative; 
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); 
    border-radius: 16px; 
    overflow: hidden; 
    border: 4px solid var(--card); 
}

#board { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; height: 100%; }
.square { display: flex; align-items: center; justify-content: center; position: relative; }
.light { background-color: var(--board-l); }
.dark { background-color: var(--board-d); }
.piece { width: 90%; height: 90%; cursor: pointer; z-index: 10; user-select: none; transition: transform 0.2s ease; }
.piece:active { transform: scale(1.1) translateY(-5px); }

.highlight { box-shadow: inset 0 0 0 5px var(--accent); }
.last-move { background-color: rgba(245, 158, 11, 0.25) !important; }
.in-check { background-color: rgba(239, 68, 68, 0.3) !important; animation: check-shake 0.4s ease-in-out; }

@keyframes check-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

@keyframes hint-pulse { 
    0%, 100% { background-color: rgba(239, 68, 68, 0.05); } 
    50% { background-color: rgba(239, 68, 68, 0.2); box-shadow: inset 0 0 0 6px var(--danger); } 
}
.hint-move { animation: hint-pulse 0.8s infinite; z-index: 5; }

#hint-overlay {
    position: absolute; 
    top: 50%; 
    left: 50%; 
    transform: translate(-50%, -50%) scale(0.9);
    width: 88%; 
    max-height: 85%; 
    background: var(--glass); 
    backdrop-filter: blur(20px); 
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 0, 0, 0.05); 
    border-radius: 28px; 
    z-index: 100; 
    display: none; 
    flex-direction: column; 
    align-items: center; 
    padding: 25px; 
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
    opacity: 0; 
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    pointer-events: none;
}

#hint-overlay.active { opacity: 1; display: flex; transform: translate(-50%, -50%) scale(1); pointer-events: auto; }

.hint-content { width: 100%; display: flex; flex-direction: column; align-items: center; overflow: hidden; }
.hint-header { text-align: center; margin-bottom: 12px; }
.hint-header .label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 2px; color: var(--accent); }
.hint-header .move { font-size: 2.2rem; font-weight: 900; color: var(--text); }

#explanation-container { 
    width: 100%; 
    overflow-y: auto; 
    padding-right: 5px; 
    margin: 15px 0; 
    border-top: 1px solid rgba(0,0,0,0.05); 
    max-height: 150px; 
}

#explanation-text { 
    font-size: 0.9rem; 
    color: #475569; 
    text-align: center; 
    line-height: 1.6; 
    padding-top: 15px; 
}

.overlay-footer { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.exp-toggle-btn { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; padding: 12px; border-radius: 14px; font-size: 0.8rem; font-weight: 700; cursor: pointer; }
.close-overlay-btn { background: var(--danger); color: white; border: none; padding: 14px; border-radius: 14px; font-size: 0.9rem; font-weight: 800; cursor: pointer; }

.controls { width: 100%; max-width: 450px; margin-top: 25px; display: flex; flex-direction: column; gap: 15px; }
.row { display: flex; gap: 12px; width: 100%; }

select, button.main-action { 
    background: var(--card); border: 1px solid #e2e8f0; color: var(--text); padding: 16px; border-radius: 16px; 
    font-size: 0.9rem; font-weight: 600; flex: 1; box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

button.hint-btn { 
    background: var(--accent); color: white; flex: 1; border-radius: 16px; font-weight: 700; border: none; 
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; transition: all 0.2s;
    box-shadow: 0 4px 6px -1px rgba(245, 158, 11, 0.4);
}

button.hint-btn:disabled { background: #cbd5e1; color: #94a3b8; opacity: 0.8; box-shadow: none; }

.btn-loader {
    width: 18px;
    height: 18px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.toggle-container { display: flex; align-items: center; justify-content: space-between; padding: 0 20px; background: var(--card); border-radius: 16px; border: 1px solid #e2e8f0; flex: 1.5; }
.toggle-container span { font-size: 0.75rem; font-weight: 800; text-transform: uppercase; color: #64748b; }

#console-container { width: 100%; max-width: 450px; max-height: 0; overflow: hidden; transition: max-height 0.4s ease; margin-top: 15px; }
#console-container.visible { max-height: 180px; }
#console { width: 100%; height: 140px; background: #0f172a; border-radius: 16px; padding: 15px; font-family: 'Fira Code', monospace; font-size: 10px; overflow-y: auto; border: 1px solid #1e293b; color: #38bdf8; }